2 * Copyright © 2017 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.transportpce.servicehandler.stub;
12 import com.google.common.base.Optional;
13 import com.google.common.util.concurrent.ListenableFuture;
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.TimeUnit;
17 import java.util.concurrent.TimeoutException;
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
20 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
21 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
22 import org.opendaylight.transportpce.common.ResponseCodes;
23 import org.opendaylight.transportpce.common.Timeouts;
24 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInput;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutputBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutput;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutputBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.path.PathDescription;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList;
34 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
35 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 import org.opendaylight.yangtools.yang.common.RpcResult;
38 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
45 * Class to implement StubrendererService.
46 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
49 public class StubrendererImpl {
51 private static final Logger LOG = LoggerFactory.getLogger(StubrendererImpl.class);
52 /** check service sdnc-request-header compliancy. */
53 private final NetworkModelWavelengthService networkModelWavelengthService;
54 private final DataBroker dataBroker;
56 public StubrendererImpl(NetworkModelWavelengthService networkModelWavelengthService, DataBroker dataBroker) {
57 this.networkModelWavelengthService = networkModelWavelengthService;
58 this.dataBroker = dataBroker;
61 public ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
62 LOG.info("ServiceDelete request ...");
63 String serviceName = input.getServiceName();
65 String responseCode = null;
67 LOG.info("Wait for 1s til beginning the Renderer serviceDelete request");
68 Thread.sleep(1000); //sleep for 1s
69 } catch (InterruptedException e) {
70 message = "deleting service failed !";
71 LOG.error("deleting service failed !", e);
72 responseCode = ResponseCodes.RESPONSE_FAILED;
74 // Obtain path description
75 Optional<PathDescription> pathDescriptionOpt = getPathDescriptionFromDatastore(serviceName);
76 PathDescription pathDescription;
77 if (pathDescriptionOpt.isPresent()) {
78 pathDescription = pathDescriptionOpt.get();
79 this.networkModelWavelengthService.freeWavelengths(pathDescription);
80 responseCode = ResponseCodes.RESPONSE_OK;
81 message = "service deleted !";
83 LOG.error("failed to get pathDescription for service : {}", serviceName);
84 responseCode = ResponseCodes.RESPONSE_FAILED;
85 message = "failed to get pathDescription for service : " + serviceName;
87 ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder()
88 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES)
89 .setRequestId(input.getServiceHandlerHeader().getRequestId())
90 .setResponseCode(responseCode)
91 .setResponseMessage(message);
92 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
93 .setConfigurationResponseCommon(configurationResponseCommon.build())
95 return RpcResultBuilder.success(output).buildFuture();
98 public ListenableFuture<RpcResult<ServiceImplementationRequestOutput>>
99 serviceImplementation(ServiceImplementationRequestInput input) {
100 LOG.info("serviceImplementation request ...");
102 String responseCode = null;
104 LOG.info("Wait for 1s til beginning the Renderer serviceDelete request");
105 Thread.sleep(1000); //sleep for 1s
106 } catch (InterruptedException e) {
107 message = "implementing service failed !";
109 responseCode = ResponseCodes.RESPONSE_FAILED;
111 this.networkModelWavelengthService.useWavelengths(input.getPathDescription());
112 message = "service implemented !";
113 responseCode = ResponseCodes.RESPONSE_OK;
114 ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder()
115 .setAckFinalIndicator(ResponseCodes.FINAL_ACK_YES)
116 .setRequestId(input.getServiceHandlerHeader().getRequestId())
117 .setResponseCode(responseCode)
118 .setResponseMessage(message);
119 ServiceImplementationRequestOutput output = new ServiceImplementationRequestOutputBuilder()
120 .setConfigurationResponseCommon(configurationResponseCommon.build())
122 return RpcResultBuilder.success(output).buildFuture();
125 private Optional<PathDescription> getPathDescriptionFromDatastore(String serviceName) {
126 InstanceIdentifier<PathDescription> pathDescriptionIID = InstanceIdentifier.create(ServicePathList.class)
127 .child(ServicePaths.class, new ServicePathsKey(serviceName)).child(PathDescription.class);
128 ReadOnlyTransaction pathDescReadTx = this.dataBroker.newReadOnlyTransaction();
130 LOG.debug("Getting path description for service {}", serviceName);
131 return pathDescReadTx.read(LogicalDatastoreType.OPERATIONAL, pathDescriptionIID)
132 .get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS);
133 } catch (InterruptedException | ExecutionException | TimeoutException e) {
134 LOG.warn("Exception while getting path description from datastore {} for service {}!", pathDescriptionIID,
136 return Optional.absent();