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;
17 import java.util.concurrent.Executors;
18 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
19 import org.opendaylight.transportpce.stubrenderer.SendingRendererRPCs;
20 import org.opendaylight.transportpce.stubrenderer.StubrendererCompliancyCheck;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteInput;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteOutput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteOutputBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestInput;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestOutput;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestOutputBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceRpcResultSp;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceRpcResultSpBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.StubrendererService;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.rpc.result.sp.PathTopology;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.rpc.result.sp.PathTopologyBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.TopologyBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx;
35 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.ServicePathNotificationTypes;
36 import org.opendaylight.yangtools.yang.common.RpcResult;
37 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
44 * Class to implement StubrendererService.
45 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
48 public class StubrendererImpl implements StubrendererService {
50 private static final Logger LOG = LoggerFactory.getLogger(StubrendererImpl.class);
51 /** send notification. */
52 private NotificationPublishService notificationPublishService;
53 private ServiceRpcResultSp notification;
54 private final ListeningExecutorService executor = MoreExecutors
55 .listeningDecorator(Executors.newFixedThreadPool(10));
56 /** check service sdnc-request-header compliancy. */
57 private StubrendererCompliancyCheck compliancyCheck;
59 public StubrendererImpl(NotificationPublishService notificationPublishService) {
60 this.notificationPublishService = notificationPublishService;
64 public ListenableFuture<RpcResult<ServiceImplementationRequestOutput>> serviceImplementationRequest(
65 ServiceImplementationRequestInput input) {
66 LOG.info("RPC serviceImplementationRequest request received");
67 String responseCode = "";
69 ConfigurationResponseCommonBuilder configurationResponseCommon = null;
71 this.compliancyCheck = new StubrendererCompliancyCheck(input.getServiceName(), input.getServiceHandlerHeader());
72 if (this.compliancyCheck.check(false, true)) {
73 LOG.info("Service compliant !");
75 * If compliant, service-request parameters are verified in order to
76 * check if there is no missing parameter that prevents calculating
77 * a path and implement a service.
80 this.notification = new ServiceRpcResultSpBuilder()
81 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
82 .setServiceName(input.getServiceName())
83 .setStatus(RpcStatusEx.Pending)
84 .setStatusMessage("Service compliant, submitting serviceImplementation Request ...")
87 this.notificationPublishService.putNotification(this.notification);
88 } catch (InterruptedException e) {
89 LOG.info("notification offer rejected : {}", e);
92 SendingRendererRPCs sendingRenderer = new SendingRendererRPCs(this.executor);
93 FutureCallback<Boolean> rendererCallback =
94 new FutureCallback<Boolean>() {
96 ServiceRpcResultSp notification = null;
99 public void onFailure(Throwable arg0) {
100 LOG.error("Failure message : {}", arg0.toString());
101 LOG.error("Service implementation failed !");
102 this.notification = new ServiceRpcResultSpBuilder()
103 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
104 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
105 .setStatusMessage("PCR Request failed : {}" + arg0.getMessage()).build();
107 StubrendererImpl.this.notificationPublishService.putNotification(this.notification);
108 } catch (InterruptedException e) {
109 LOG.info("notification offer rejected : {}", e);
114 public void onSuccess(Boolean response) {
115 LOG.info("response : {}", response);
117 this.message = "Service implemented !";
118 TopologyBuilder topo = sendingRenderer.getTopology();
119 ServiceRpcResultSpBuilder tmp = new ServiceRpcResultSpBuilder()
120 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
121 .setServiceName(input.getServiceName())
122 .setStatus(RpcStatusEx.Successful)
123 .setStatusMessage(this.message);
125 PathTopology value = new PathTopologyBuilder()
126 .setAToZ(topo.getAToZ())
127 .setZToA(topo.getZToA())
129 tmp.setPathTopology(value);
131 this.notification = tmp.build();
133 this.message = "Service implementation failed : " + sendingRenderer.getError();
134 this.notification = new ServiceRpcResultSpBuilder()
135 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
137 .setStatus(RpcStatusEx.Failed).setStatusMessage(this.message)
140 LOG.info(this.notification.toString());
142 StubrendererImpl.this.notificationPublishService.putNotification(this.notification);
143 } catch (InterruptedException e) {
144 LOG.info("notification offer rejected : {}", e);
146 LOG.info(this.message);
149 ListenableFuture<Boolean> renderer = sendingRenderer.serviceImplementation();
150 Futures.addCallback(renderer, rendererCallback, this.executor);
151 LOG.info("Service implmentation Request in progress ");
152 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
153 .setAckFinalIndicator("Yes")
154 .setRequestId(input.getServiceHandlerHeader().getRequestId())
155 .setResponseCode("200")
156 .setResponseMessage("Service implementation Request in progress ");
158 ServiceImplementationRequestOutput output = new ServiceImplementationRequestOutputBuilder()
159 .setConfigurationResponseCommon(configurationResponseCommon.build())
161 return RpcResultBuilder.success(output).buildFuture();
163 message = this.compliancyCheck.getMessage();
164 responseCode = "500";
165 LOG.info("Service not compliant caused by : {}", message);
166 this.notification = new ServiceRpcResultSpBuilder()
167 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
168 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
169 .setStatusMessage("Service not compliant caused by : " + message)
172 this.notificationPublishService.putNotification(this.notification);
173 } catch (InterruptedException e) {
174 LOG.info("notification offer rejected : {}", e);
177 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
178 .setAckFinalIndicator("yes")
179 .setRequestId(input.getServiceHandlerHeader().getRequestId())
180 .setResponseCode(responseCode)
181 .setResponseMessage(message);
182 ServiceImplementationRequestOutput output = new ServiceImplementationRequestOutputBuilder()
183 .setConfigurationResponseCommon(configurationResponseCommon.build())
186 return RpcResultBuilder.success(output).buildFuture();
190 public ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
192 LOG.info("RPC serviceDelete request received");
193 String responseCode = "";
194 ConfigurationResponseCommonBuilder configurationResponseCommon = null;
195 this.compliancyCheck = new StubrendererCompliancyCheck(input.getServiceName(), input.getServiceHandlerHeader());
196 if (this.compliancyCheck.check(false, true)) {
197 LOG.info("Service compliant !");
199 * If compliant, service-request parameters are verified in order to
200 * check if there is no missing parameter that prevents calculating
201 * a path and implement a service.
204 this.notification = new ServiceRpcResultSpBuilder()
205 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
206 .setServiceName(input.getServiceName())
207 .setStatus(RpcStatusEx.Pending)
208 .setStatusMessage("Service compliant, submitting serviceDelete Request ...")
211 this.notificationPublishService.putNotification(this.notification);
212 } catch (InterruptedException e) {
213 LOG.info("notification offer rejected : {}", e);
215 SendingRendererRPCs sendingRenderer = new SendingRendererRPCs(this.executor);
216 FutureCallback<Boolean> rendererCallback = new FutureCallback<Boolean>() {
218 ServiceRpcResultSp notification = null;
221 public void onFailure(Throwable arg0) {
222 LOG.error("Failure message : {}", arg0.toString());
223 LOG.error("Service delete failed !");
224 this.notification = new ServiceRpcResultSpBuilder()
225 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
226 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
227 .setStatusMessage("PCR Request failed : " + arg0.getMessage()).build();
229 StubrendererImpl.this.notificationPublishService.putNotification(this.notification);
230 } catch (InterruptedException e) {
231 LOG.info("notification offer rejected : {}", e);
236 public void onSuccess(Boolean response) {
237 LOG.info("response : {}", response);
239 this.message = "Service deleted !";
240 this.notification = new ServiceRpcResultSpBuilder()
241 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
242 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Successful)
243 .setStatusMessage(this.message).build();
245 this.message = "Service delete failed : " + sendingRenderer.getError();
246 this.notification = new ServiceRpcResultSpBuilder()
247 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
249 .setStatus(RpcStatusEx.Failed).setStatusMessage(this.message)
252 LOG.info(this.notification.toString());
254 StubrendererImpl.this.notificationPublishService.putNotification(this.notification);
255 } catch (InterruptedException e) {
256 LOG.info("notification offer rejected : {}", e);
258 LOG.info(this.message);
261 ListenableFuture<Boolean> renderer = sendingRenderer.serviceDelete();
262 Futures.addCallback(renderer, rendererCallback, this.executor);
263 message = "Service delete Request in progress ...";
265 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
266 .setAckFinalIndicator("Yes")
267 .setRequestId(input.getServiceHandlerHeader().getRequestId())
268 .setResponseCode("200")
269 .setResponseMessage(message);
270 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
271 .setConfigurationResponseCommon(configurationResponseCommon.build())
273 return RpcResultBuilder.success(output).buildFuture();
275 message = this.compliancyCheck.getMessage();
276 LOG.info("Service not compliant caused by : {}", message);
277 responseCode = "500";
278 this.notification = new ServiceRpcResultSpBuilder()
279 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
280 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
281 .setStatusMessage("Service not compliant caused by : " + message)
284 this.notificationPublishService.putNotification(this.notification);
285 } catch (InterruptedException e) {
286 LOG.info("notification offer rejected : {}", e);
289 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
290 .setAckFinalIndicator("yes")
291 .setRequestId(input.getServiceHandlerHeader().getRequestId())
292 .setResponseCode(responseCode)
293 .setResponseMessage(message);
294 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
295 .setConfigurationResponseCommon(configurationResponseCommon.build())
297 return RpcResultBuilder.success(output).buildFuture();