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.stubrenderer.impl;
12 import com.google.common.util.concurrent.FutureCallback;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import com.google.common.util.concurrent.ListeningExecutorService;
16 import com.google.common.util.concurrent.MoreExecutors;
18 import java.util.concurrent.Executors;
19 import java.util.concurrent.Future;
21 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
22 import org.opendaylight.transportpce.stubrenderer.SendingRendererRPCs;
23 import org.opendaylight.transportpce.stubrenderer.StubrendererCompliancyCheck;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.TopologyBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.ServicePathNotificationTypes;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.CancelResourceReserveInput;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.CancelResourceReserveOutput;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.PathComputationRequestInput;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.PathComputationRequestOutput;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteInput;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteOutput;
34 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceDeleteOutputBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestInput;
36 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutput;
37 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceImplementationRequestOutputBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceRpcResultSp;
39 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.ServiceRpcResultSpBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.TransportpceServicepathService;
41 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.rpc.result.sp.PathTopology;
42 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.rpc.result.sp.PathTopologyBuilder;
43 import org.opendaylight.yangtools.yang.common.RpcResult;
44 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
51 * Class to implement StubrendererService.
52 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
55 public class StubrendererImpl implements TransportpceServicepathService {
57 private static final Logger LOG = LoggerFactory.getLogger(StubrendererImpl.class);
58 /** send notification. */
59 private NotificationPublishService notificationPublishService;
60 private ServiceRpcResultSp notification;
61 private final ListeningExecutorService executor = MoreExecutors
62 .listeningDecorator(Executors.newFixedThreadPool(10));
63 /** check service sdnc-request-header compliancy. */
64 private StubrendererCompliancyCheck compliancyCheck;
66 public StubrendererImpl(NotificationPublishService notificationPublishService) {
67 this.notificationPublishService = notificationPublishService;
71 public Future<RpcResult<ServiceImplementationRequestOutput>> serviceImplementationRequest(
72 ServiceImplementationRequestInput input) {
73 LOG.info("RPC serviceImplementationRequest request received");
74 String responseCode = "";
76 ConfigurationResponseCommonBuilder configurationResponseCommon = null;
78 compliancyCheck = new StubrendererCompliancyCheck(input.getServiceName(), input.getServiceHandlerHeader());
79 if (compliancyCheck.check(false, true)) {
80 LOG.info("Service compliant !");
82 * If compliant, service-request parameters are verified in order to
83 * check if there is no missing parameter that prevents calculating
84 * a path and implement a service.
87 notification = new ServiceRpcResultSpBuilder()
88 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
89 .setServiceName(input.getServiceName())
90 .setStatus(RpcStatusEx.Pending)
91 .setStatusMessage("Service compliant, submitting serviceImplementation Request ...")
94 notificationPublishService.putNotification(notification);
95 } catch (InterruptedException e) {
96 LOG.info("notification offer rejected : " + e);
99 SendingRendererRPCs sendingRenderer = new SendingRendererRPCs(executor);
100 FutureCallback<Boolean> rendererCallback =
101 new FutureCallback<Boolean>() {
103 ServiceRpcResultSp notification = null;
106 public void onFailure(Throwable arg0) {
107 LOG.error("Failure message : " + arg0.toString());
108 LOG.error("Service implementation failed !");
109 notification = new ServiceRpcResultSpBuilder()
110 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
111 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
112 .setStatusMessage("PCR Request failed : " + arg0.getMessage()).build();
114 notificationPublishService.putNotification(notification);
115 } catch (InterruptedException e) {
116 LOG.info("notification offer rejected : " + e);
121 public void onSuccess(Boolean response) {
122 LOG.info("response : " + response);
124 message = "Service implemented !";
125 TopologyBuilder topo = sendingRenderer.getTopology();
126 ServiceRpcResultSpBuilder tmp = new ServiceRpcResultSpBuilder()
127 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
128 .setServiceName(input.getServiceName())
129 .setStatus(RpcStatusEx.Successful)
130 .setStatusMessage(message);
132 PathTopology value = new PathTopologyBuilder()
133 .setAToZ(topo.getAToZ())
134 .setZToA(topo.getZToA())
136 tmp.setPathTopology(value);
138 notification = tmp.build();
140 message = "Service implementation failed : " + sendingRenderer.getError();
141 notification = new ServiceRpcResultSpBuilder()
142 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
144 .setStatus(RpcStatusEx.Failed).setStatusMessage(message)
147 LOG.info(notification.toString());
149 notificationPublishService.putNotification(notification);
150 } catch (InterruptedException e) {
151 LOG.info("notification offer rejected : " + e);
156 ListenableFuture<Boolean> renderer = sendingRenderer.serviceImplementation();
157 Futures.addCallback(renderer, rendererCallback, executor);
158 LOG.info("Service implmentation Request in progress ");
159 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
160 .setAckFinalIndicator("Yes")
161 .setRequestId(input.getServiceHandlerHeader().getRequestId())
162 .setResponseCode("200")
163 .setResponseMessage("Service implementation Request in progress ");
165 ServiceImplementationRequestOutput output = new ServiceImplementationRequestOutputBuilder()
166 .setConfigurationResponseCommon(configurationResponseCommon.build())
168 return RpcResultBuilder.success(output).buildFuture();
170 message = compliancyCheck.getMessage();
171 responseCode = "500";
172 LOG.info("Service not compliant caused by : " + message);
173 notification = new ServiceRpcResultSpBuilder()
174 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
175 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
176 .setStatusMessage("Service not compliant caused by : " + message)
179 notificationPublishService.putNotification(notification);
180 } catch (InterruptedException e) {
181 LOG.info("notification offer rejected : " + e);
184 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
185 .setAckFinalIndicator("yes")
186 .setRequestId(input.getServiceHandlerHeader().getRequestId())
187 .setResponseCode(responseCode)
188 .setResponseMessage(message);
189 ServiceImplementationRequestOutput output = new ServiceImplementationRequestOutputBuilder()
190 .setConfigurationResponseCommon(configurationResponseCommon.build())
193 return RpcResultBuilder.success(output).buildFuture();
197 public Future<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
199 LOG.info("RPC serviceDelete request received");
200 String responseCode = "";
201 ConfigurationResponseCommonBuilder configurationResponseCommon = null;
202 compliancyCheck = new StubrendererCompliancyCheck(input.getServiceName(), input.getServiceHandlerHeader());
203 if (compliancyCheck.check(false, true)) {
204 LOG.info("Service compliant !");
206 * If compliant, service-request parameters are verified in order to
207 * check if there is no missing parameter that prevents calculating
208 * a path and implement a service.
211 notification = new ServiceRpcResultSpBuilder()
212 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
213 .setServiceName(input.getServiceName())
214 .setStatus(RpcStatusEx.Pending)
215 .setStatusMessage("Service compliant, submitting serviceDelete Request ...")
218 notificationPublishService.putNotification(notification);
219 } catch (InterruptedException e) {
220 LOG.info("notification offer rejected : " + e);
222 SendingRendererRPCs sendingRenderer = new SendingRendererRPCs(executor);
223 FutureCallback<Boolean> rendererCallback = new FutureCallback<Boolean>() {
225 ServiceRpcResultSp notification = null;
228 public void onFailure(Throwable arg0) {
229 LOG.error("Failure message : " + arg0.toString());
230 LOG.error("Service delete failed !");
231 notification = new ServiceRpcResultSpBuilder()
232 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
233 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
234 .setStatusMessage("PCR Request failed : " + arg0.getMessage()).build();
236 notificationPublishService.putNotification(notification);
237 } catch (InterruptedException e) {
238 LOG.info("notification offer rejected : " + e);
243 public void onSuccess(Boolean response) {
244 LOG.info("response : " + response);
246 message = "Service deleted !";
247 notification = new ServiceRpcResultSpBuilder()
248 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
249 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Successful)
250 .setStatusMessage(message).build();
252 message = "Service delete failed : " + sendingRenderer.getError();
253 notification = new ServiceRpcResultSpBuilder()
254 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
256 .setStatus(RpcStatusEx.Failed).setStatusMessage(message)
259 LOG.info(notification.toString());
261 notificationPublishService.putNotification(notification);
262 } catch (InterruptedException e) {
263 LOG.info("notification offer rejected : " + e);
268 ListenableFuture<Boolean> renderer = sendingRenderer.serviceDelete();
269 Futures.addCallback(renderer, rendererCallback, executor);
270 message = "Service delete Request in progress ...";
272 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
273 .setAckFinalIndicator("Yes")
274 .setRequestId(input.getServiceHandlerHeader().getRequestId())
275 .setResponseCode("200")
276 .setResponseMessage(message);
277 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
278 .setConfigurationResponseCommon(configurationResponseCommon.build())
280 return RpcResultBuilder.success(output).buildFuture();
282 message = compliancyCheck.getMessage();
283 LOG.info("Service not compliant caused by : " + message);
284 responseCode = "500";
285 notification = new ServiceRpcResultSpBuilder()
286 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
287 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
288 .setStatusMessage("Service not compliant caused by : " + message)
291 notificationPublishService.putNotification(notification);
292 } catch (InterruptedException e) {
293 LOG.info("notification offer rejected : " + e);
296 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
297 .setAckFinalIndicator("yes")
298 .setRequestId(input.getServiceHandlerHeader().getRequestId())
299 .setResponseCode(responseCode)
300 .setResponseMessage(message);
301 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
302 .setConfigurationResponseCommon(configurationResponseCommon.build())
304 return RpcResultBuilder.success(output).buildFuture();
308 public Future<RpcResult<CancelResourceReserveOutput>> cancelResourceReserve(CancelResourceReserveInput input) {
309 // TODO Auto-generated method stub
314 public Future<RpcResult<PathComputationRequestOutput>> pathComputationRequest(PathComputationRequestInput input) {
315 // TODO Auto-generated method stub