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.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteInput;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteOutput;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteOutputBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestInput;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestOutput;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestOutputBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceRpcResultSp;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceRpcResultSpBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.StubrendererService;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.rpc.result.sp.PathTopology;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.rpc.result.sp.PathTopologyBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.TopologyBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx;
38 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.ServicePathNotificationTypes;
39 import org.opendaylight.yangtools.yang.common.RpcResult;
40 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
47 * Class to implement StubrendererService.
48 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
51 public class StubrendererImpl implements StubrendererService {
53 private static final Logger LOG = LoggerFactory.getLogger(StubrendererImpl.class);
54 /** send notification. */
55 private NotificationPublishService notificationPublishService;
56 private ServiceRpcResultSp notification;
57 private final ListeningExecutorService executor = MoreExecutors
58 .listeningDecorator(Executors.newFixedThreadPool(10));
59 /** check service sdnc-request-header compliancy. */
60 private StubrendererCompliancyCheck compliancyCheck;
62 public StubrendererImpl(NotificationPublishService notificationPublishService) {
63 this.notificationPublishService = notificationPublishService;
67 public Future<RpcResult<ServiceImplementationRequestOutput>> serviceImplementationRequest(
68 ServiceImplementationRequestInput input) {
69 LOG.info("RPC serviceImplementationRequest request received");
70 String responseCode = "";
72 ConfigurationResponseCommonBuilder configurationResponseCommon = null;
74 compliancyCheck = new StubrendererCompliancyCheck(input.getServiceName(), input.getServiceHandlerHeader());
75 if (compliancyCheck.check(false, true)) {
76 LOG.info("Service compliant !");
78 * If compliant, service-request parameters are verified in order to
79 * check if there is no missing parameter that prevents calculating
80 * a path and implement a service.
83 notification = new ServiceRpcResultSpBuilder()
84 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
85 .setServiceName(input.getServiceName())
86 .setStatus(RpcStatusEx.Pending)
87 .setStatusMessage("Service compliant, submitting serviceImplementation Request ...")
90 notificationPublishService.putNotification(notification);
91 } catch (InterruptedException e) {
92 LOG.info("notification offer rejected : {}", e);
95 SendingRendererRPCs sendingRenderer = new SendingRendererRPCs(executor);
96 FutureCallback<Boolean> rendererCallback =
97 new FutureCallback<Boolean>() {
99 ServiceRpcResultSp notification = null;
102 public void onFailure(Throwable arg0) {
103 LOG.error("Failure message : {}", arg0.toString());
104 LOG.error("Service implementation failed !");
105 notification = new ServiceRpcResultSpBuilder()
106 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
107 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
108 .setStatusMessage("PCR Request failed : {}" + arg0.getMessage()).build();
110 notificationPublishService.putNotification(notification);
111 } catch (InterruptedException e) {
112 LOG.info("notification offer rejected : {}", e);
117 public void onSuccess(Boolean response) {
118 LOG.info("response : {}", response);
120 message = "Service implemented !";
121 TopologyBuilder topo = sendingRenderer.getTopology();
122 ServiceRpcResultSpBuilder tmp = new ServiceRpcResultSpBuilder()
123 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
124 .setServiceName(input.getServiceName())
125 .setStatus(RpcStatusEx.Successful)
126 .setStatusMessage(message);
128 PathTopology value = new PathTopologyBuilder()
129 .setAToZ(topo.getAToZ())
130 .setZToA(topo.getZToA())
132 tmp.setPathTopology(value);
134 notification = tmp.build();
136 message = "Service implementation failed : " + sendingRenderer.getError();
137 notification = new ServiceRpcResultSpBuilder()
138 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
140 .setStatus(RpcStatusEx.Failed).setStatusMessage(message)
143 LOG.info(notification.toString());
145 notificationPublishService.putNotification(notification);
146 } catch (InterruptedException e) {
147 LOG.info("notification offer rejected : {}", e);
152 ListenableFuture<Boolean> renderer = sendingRenderer.serviceImplementation();
153 Futures.addCallback(renderer, rendererCallback, executor);
154 LOG.info("Service implmentation Request in progress ");
155 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
156 .setAckFinalIndicator("Yes")
157 .setRequestId(input.getServiceHandlerHeader().getRequestId())
158 .setResponseCode("200")
159 .setResponseMessage("Service implementation Request in progress ");
161 ServiceImplementationRequestOutput output = new ServiceImplementationRequestOutputBuilder()
162 .setConfigurationResponseCommon(configurationResponseCommon.build())
164 return RpcResultBuilder.success(output).buildFuture();
166 message = compliancyCheck.getMessage();
167 responseCode = "500";
168 LOG.info("Service not compliant caused by : {}", message);
169 notification = new ServiceRpcResultSpBuilder()
170 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
171 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
172 .setStatusMessage("Service not compliant caused by : " + message)
175 notificationPublishService.putNotification(notification);
176 } catch (InterruptedException e) {
177 LOG.info("notification offer rejected : {}", e);
180 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
181 .setAckFinalIndicator("yes")
182 .setRequestId(input.getServiceHandlerHeader().getRequestId())
183 .setResponseCode(responseCode)
184 .setResponseMessage(message);
185 ServiceImplementationRequestOutput output = new ServiceImplementationRequestOutputBuilder()
186 .setConfigurationResponseCommon(configurationResponseCommon.build())
189 return RpcResultBuilder.success(output).buildFuture();
193 public Future<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
195 LOG.info("RPC serviceDelete request received");
196 String responseCode = "";
197 ConfigurationResponseCommonBuilder configurationResponseCommon = null;
198 compliancyCheck = new StubrendererCompliancyCheck(input.getServiceName(), input.getServiceHandlerHeader());
199 if (compliancyCheck.check(false, true)) {
200 LOG.info("Service compliant !");
202 * If compliant, service-request parameters are verified in order to
203 * check if there is no missing parameter that prevents calculating
204 * a path and implement a service.
207 notification = new ServiceRpcResultSpBuilder()
208 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
209 .setServiceName(input.getServiceName())
210 .setStatus(RpcStatusEx.Pending)
211 .setStatusMessage("Service compliant, submitting serviceDelete Request ...")
214 notificationPublishService.putNotification(notification);
215 } catch (InterruptedException e) {
216 LOG.info("notification offer rejected : {}", e);
218 SendingRendererRPCs sendingRenderer = new SendingRendererRPCs(executor);
219 FutureCallback<Boolean> rendererCallback = new FutureCallback<Boolean>() {
221 ServiceRpcResultSp notification = null;
224 public void onFailure(Throwable arg0) {
225 LOG.error("Failure message : {}", arg0.toString());
226 LOG.error("Service delete failed !");
227 notification = new ServiceRpcResultSpBuilder()
228 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
229 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
230 .setStatusMessage("PCR Request failed : " + arg0.getMessage()).build();
232 notificationPublishService.putNotification(notification);
233 } catch (InterruptedException e) {
234 LOG.info("notification offer rejected : {}", e);
239 public void onSuccess(Boolean response) {
240 LOG.info("response : {}", response);
242 message = "Service deleted !";
243 notification = new ServiceRpcResultSpBuilder()
244 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
245 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Successful)
246 .setStatusMessage(message).build();
248 message = "Service delete failed : " + sendingRenderer.getError();
249 notification = new ServiceRpcResultSpBuilder()
250 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
252 .setStatus(RpcStatusEx.Failed).setStatusMessage(message)
255 LOG.info(notification.toString());
257 notificationPublishService.putNotification(notification);
258 } catch (InterruptedException e) {
259 LOG.info("notification offer rejected : {}", e);
264 ListenableFuture<Boolean> renderer = sendingRenderer.serviceDelete();
265 Futures.addCallback(renderer, rendererCallback, executor);
266 message = "Service delete Request in progress ...";
268 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
269 .setAckFinalIndicator("Yes")
270 .setRequestId(input.getServiceHandlerHeader().getRequestId())
271 .setResponseCode("200")
272 .setResponseMessage(message);
273 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
274 .setConfigurationResponseCommon(configurationResponseCommon.build())
276 return RpcResultBuilder.success(output).buildFuture();
278 message = compliancyCheck.getMessage();
279 LOG.info("Service not compliant caused by : {}", message);
280 responseCode = "500";
281 notification = new ServiceRpcResultSpBuilder()
282 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
283 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
284 .setStatusMessage("Service not compliant caused by : " + message)
287 notificationPublishService.putNotification(notification);
288 } catch (InterruptedException e) {
289 LOG.info("notification offer rejected : {}", e);
292 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
293 .setAckFinalIndicator("yes")
294 .setRequestId(input.getServiceHandlerHeader().getRequestId())
295 .setResponseCode(responseCode)
296 .setResponseMessage(message);
297 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
298 .setConfigurationResponseCommon(configurationResponseCommon.build())
300 return RpcResultBuilder.success(output).buildFuture();