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 java.util.concurrent.Future;
14 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
15 import org.opendaylight.transportpce.stubrenderer.SendingRendererRPCs;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteInput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteOutput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceDeleteOutputBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestInput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestOutput;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestOutputBuilder;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceRpcResultSp;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceRpcResultSpBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.StubrendererService;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.rpc.result.sp.PathTopology;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.service.rpc.result.sp.PathTopologyBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.TopologyBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.ServicePathNotificationTypes;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
38 * Class to implement StubrendererService.
39 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
42 public class StubrendererImpl implements StubrendererService {
44 private static final Logger LOG = LoggerFactory.getLogger(StubrendererImpl.class);
45 /* send notification. */
46 private NotificationPublishService notificationPublishService;
47 private ServiceRpcResultSp notification;
49 public StubrendererImpl(NotificationPublishService notificationPublishService) {
50 this.notificationPublishService = notificationPublishService;
54 public Future<RpcResult<ServiceImplementationRequestOutput>> serviceImplementationRequest(
55 ServiceImplementationRequestInput input) {
57 LOG.info("RPC serviceImplementationRequest request received");
59 notification = new ServiceRpcResultSpBuilder()
60 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
61 .setServiceName(input.getServiceName())
62 .setStatus(RpcStatusEx.Pending)
63 .setStatusMessage("Service compliant, submitting serviceImplementation Request ...")
66 notificationPublishService.putNotification(notification);
67 } catch (InterruptedException e) {
68 LOG.info("notification offer rejected : " + e);
71 SendingRendererRPCs sendingRenderer = new SendingRendererRPCs();
72 sendingRenderer.serviceImplementation();
73 if (sendingRenderer.getSuccess()) {
74 message = "Service implemented !";
75 ServiceRpcResultSpBuilder tmp = new ServiceRpcResultSpBuilder()
76 .setNotificationType(ServicePathNotificationTypes.ServiceImplementationRequest)
77 .setServiceName(input.getServiceName())
78 .setStatus(RpcStatusEx.Successful)
79 .setStatusMessage(message);
80 TopologyBuilder topo = sendingRenderer.getTopology();
82 PathTopology path = new PathTopologyBuilder()
83 .setAToZ(topo.getAToZ())
84 .setZToA(topo.getZToA())
86 tmp.setPathTopology(path);
88 notification = tmp.build();
90 notificationPublishService.putNotification(notification);
91 } catch (InterruptedException e) {
92 LOG.info("notification offer rejected : " + e);
96 message = "Service not implemented !";
99 ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder()
100 .setAckFinalIndicator("Yes")
101 .setRequestId(input.getServiceHandlerHeader().getRequestId())
102 .setResponseCode("200")
103 .setResponseMessage(message);
105 ServiceImplementationRequestOutput output = new ServiceImplementationRequestOutputBuilder()
106 .setConfigurationResponseCommon(configurationResponseCommon.build())
109 return RpcResultBuilder.success(output).buildFuture();
113 public Future<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
115 LOG.info("RPC serviceDelete request received");
117 notification = new ServiceRpcResultSpBuilder()
118 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
119 .setServiceName(input.getServiceName())
120 .setStatus(RpcStatusEx.Pending)
121 .setStatusMessage("Service compliant, submitting ServiceDelete Request ...")
124 notificationPublishService.putNotification(notification);
125 } catch (InterruptedException e) {
126 LOG.info("notification offer rejected : " + e);
129 SendingRendererRPCs sendingRenderer = new SendingRendererRPCs();
130 sendingRenderer.serviceDelete();
131 if (sendingRenderer.getSuccess()) {
132 message = "Service deleted ! ";
134 ServiceRpcResultSpBuilder tmp = new ServiceRpcResultSpBuilder()
135 .setNotificationType(ServicePathNotificationTypes.ServiceDelete)
136 .setServiceName(input.getServiceName())
137 .setStatus(RpcStatusEx.Successful)
138 .setStatusMessage(message);
139 notification = tmp.build();
141 notificationPublishService.putNotification(notification);
142 } catch (InterruptedException e) {
143 LOG.info("notification offer rejected : " + e);
146 message = "Service not deleted !";
149 ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder()
150 .setAckFinalIndicator("yes")
151 .setRequestId(input.getServiceHandlerHeader().getRequestId())
152 .setResponseCode("200")
153 .setResponseMessage(message);
154 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
155 .setConfigurationResponseCommon(configurationResponseCommon.build())
158 return RpcResultBuilder.success(output).buildFuture();