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
8 package org.opendaylight.transportpce.servicehandler.listeners;
10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
13 import org.opendaylight.transportpce.common.OperationResult;
14 import org.opendaylight.transportpce.common.StringConstants;
15 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
16 import org.opendaylight.transportpce.pce.service.PathComputationService;
17 import org.opendaylight.transportpce.servicehandler.ServiceInput;
18 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
19 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.RendererRpcResultSp;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.TransportpceRendererListener;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.renderer.rpc.result.sp.Link;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.ServiceRpcResultSh;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.ServiceRpcResultShBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceNotificationTypes;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
29 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev210511.OtnLinkType;
30 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationService;
31 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.PublishNotificationServiceBuilder;
32 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.notification.service.ServiceAEndBuilder;
33 import org.opendaylight.yang.gen.v1.nbi.notifications.rev210628.notification.service.ServiceZEndBuilder;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 * Calls to listen to Renderer notifications.
40 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
43 public class RendererListenerImpl implements TransportpceRendererListener {
45 private static final String TOPIC = "RendererListener";
46 private static final Logger LOG = LoggerFactory.getLogger(RendererListenerImpl.class);
47 private RendererRpcResultSp serviceRpcResultSp;
48 private ServiceDataStoreOperations serviceDataStoreOperations;
49 private ServiceInput input;
50 private PCEServiceWrapper pceServiceWrapper;
51 private Boolean tempService;
52 private NotificationPublishService notificationPublishService;
53 private final NetworkModelService networkModelService;
56 public RendererListenerImpl(PathComputationService pathComputationService,
57 NotificationPublishService notificationPublishService, NetworkModelService networkModelService) {
58 this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
59 setServiceInput(null);
60 setTempService(false);
61 this.notificationPublishService = notificationPublishService;
62 this.networkModelService = networkModelService;
66 public void onRendererRpcResultSp(RendererRpcResultSp notification) {
67 if (compareServiceRpcResultSp(notification)) {
68 LOG.warn("ServiceRpcResultSp already wired !");
71 serviceRpcResultSp = notification;
72 int notifType = serviceRpcResultSp.getNotificationType().getIntValue();
73 LOG.info("Renderer '{}' Notification received : {}", serviceRpcResultSp.getNotificationType().getName(),
76 /* service-implementation-request. */
78 onServiceImplementationResult(notification);
82 onServiceDeleteResult(notification);
90 * Process service delete result for serviceName.
91 * @param notification RendererRpcResultSp
93 private void onServiceDeleteResult(RendererRpcResultSp notification) {
94 switch (serviceRpcResultSp.getStatus()) {
96 updateOtnTopology(notification, true);
99 LOG.error("Renderer service delete failed !");
100 Services service = serviceDataStoreOperations.getService(input.getServiceName()).get();
101 sendNbiNotification(new PublishNotificationServiceBuilder()
102 .setServiceName(service.getServiceName())
103 .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build())
104 .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build())
105 .setCommonId(service.getCommonId())
106 .setConnectionType(service.getConnectionType())
107 .setResponseFailed("Renderer service delete failed !")
108 .setMessage("ServiceDelete request failed ...")
109 .setOperationalState(service.getOperationalState())
114 LOG.warn("Renderer service delete returned a Pending RpcStatusEx code!");
117 LOG.error("Renderer service delete returned an unknown RpcStatusEx code!");
120 LOG.info("Service '{}' deleted !", notification.getServiceName());
121 if (this.input == null) {
122 LOG.error("ServiceInput parameter is null !");
125 LOG.info("sending PCE cancel resource reserve for '{}'", this.input.getServiceName());
126 this.pceServiceWrapper.cancelPCEResource(this.input.getServiceName(),
127 ServiceNotificationTypes.ServiceDeleteResult);
128 sendServiceHandlerNotification(notification, ServiceNotificationTypes.ServiceDeleteResult);
132 * Process service implementation result for serviceName.
133 * @param notification RendererRpcResultSp
135 private void onServiceImplementationResult(RendererRpcResultSp notification) {
136 switch (serviceRpcResultSp.getStatus()) {
138 onSuccededServiceImplementation(notification);
141 onFailedServiceImplementation(notification.getServiceName());
144 LOG.warn("Service Implementation still pending according to RpcStatusEx");
147 LOG.warn("Service Implementation has an unknown RpcStatusEx code");
153 * Process succeeded service implementation for service.
154 * @param notification RendererRpcResultSp
156 private void onSuccededServiceImplementation(RendererRpcResultSp notification) {
157 LOG.info("Service implemented !");
158 if (serviceDataStoreOperations == null) {
159 LOG.debug("serviceDataStoreOperations is null");
163 updateOtnTopology(notification, false);
165 PublishNotificationServiceBuilder nbiNotificationBuilder = new PublishNotificationServiceBuilder()
166 .setServiceName(input.getServiceName())
167 .setServiceAEnd(new ServiceAEndBuilder(input.getServiceAEnd()).build())
168 .setServiceZEnd(new ServiceZEndBuilder(input.getServiceZEnd()).build())
169 .setCommonId(input.getCommonId()).setConnectionType(input.getConnectionType())
171 OperationResult operationResult;
172 String serviceTemp = "";
174 operationResult = this.serviceDataStoreOperations.modifyTempService(
175 serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
176 serviceTemp = "Temp ";
178 operationResult = this.serviceDataStoreOperations.modifyService(
179 serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
181 if (operationResult.isSuccess()) {
182 sendNbiNotification(nbiNotificationBuilder
183 .setResponseFailed("")
184 .setMessage("Service implemented !")
185 .setOperationalState(org.opendaylight.yang.gen.v1.http
186 .org.openroadm.common.state.types.rev181130.State.InService)
189 sendServiceHandlerNotification(notification, ServiceNotificationTypes.ServiceCreateResult);
192 LOG.warn("{}Service status not updated in datastore !", serviceTemp);
193 sendNbiNotification(nbiNotificationBuilder
194 .setResponseFailed(serviceTemp + "Service status not updated in datastore !")
195 .setMessage("ServiceCreate request failed ...")
196 .setOperationalState(org.opendaylight.yang.gen.v1.http
197 .org.openroadm.common.state.types.rev181130.State.OutOfService)
203 * Create and send service handler notification.
204 * @param notification RendererRpcResultSp
205 * @param type ServiceNotificationTypes
207 private void sendServiceHandlerNotification(RendererRpcResultSp notification, ServiceNotificationTypes type) {
209 ServiceRpcResultSh serviceHandlerNotification = new ServiceRpcResultShBuilder()
210 .setAToZDirection(notification.getAToZDirection())
211 .setZToADirection(notification.getZToADirection())
212 .setServiceName(notification.getServiceName())
213 .setStatus(notification.getStatus())
214 .setStatusMessage(notification.getStatusMessage())
215 .setNotificationType(type)
217 LOG.debug("Service update in datastore OK, sending notification {}", serviceHandlerNotification);
218 notificationPublishService.putNotification(
219 serviceHandlerNotification);
220 } catch (InterruptedException e) {
221 LOG.warn("Something went wrong while sending notification for service {}",
222 serviceRpcResultSp.getServiceName(), e);
223 Thread.currentThread().interrupt();
228 * Process failed service implementation for serviceName.
229 * @param serviceName String
231 private void onFailedServiceImplementation(String serviceName) {
232 LOG.error("Renderer implementation failed !");
233 Services service = serviceDataStoreOperations.getService(input.getServiceName()).get();
234 sendNbiNotification(new PublishNotificationServiceBuilder()
235 .setServiceName(service.getServiceName())
236 .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build())
237 .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build())
238 .setCommonId(service.getCommonId())
239 .setConnectionType(service.getConnectionType())
240 .setResponseFailed("Renderer implementation failed !")
241 .setMessage("ServiceCreate request failed ...")
242 .setOperationalState(service.getOperationalState())
245 OperationResult deleteServicePathOperationResult =
246 this.serviceDataStoreOperations.deleteServicePath(serviceName);
247 if (!deleteServicePathOperationResult.isSuccess()) {
248 LOG.warn("Service path was not removed from datastore!");
250 OperationResult deleteServiceOperationResult;
251 String serviceType = "";
253 deleteServiceOperationResult = this.serviceDataStoreOperations.deleteTempService(serviceName);
254 serviceType = "Temp ";
256 deleteServiceOperationResult = this.serviceDataStoreOperations.deleteService(serviceName);
258 if (deleteServiceOperationResult.isSuccess()) {
259 LOG.warn("{}Service was not removed from datastore!", serviceType);
264 value = "ES_COMPARING_STRINGS_WITH_EQ",
265 justification = "false positives, not strings but real object references comparisons")
266 private Boolean compareServiceRpcResultSp(RendererRpcResultSp notification) {
267 if (serviceRpcResultSp == null
268 || serviceRpcResultSp.getNotificationType() != notification.getNotificationType()
269 || serviceRpcResultSp.getServiceName() != notification.getServiceName()
270 || serviceRpcResultSp.getStatus() != notification.getStatus()
271 || serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
277 public void setServiceInput(ServiceInput serviceInput) {
278 this.input = serviceInput;
281 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
282 this.serviceDataStoreOperations = serviceData;
285 public void setTempService(Boolean tempService) {
286 this.tempService = tempService;
290 * Send notification to NBI notification in order to publish message.
291 * @param service PublishNotificationService
293 private void sendNbiNotification(PublishNotificationService service) {
295 notificationPublishService.putNotification(service);
296 } catch (InterruptedException e) {
297 LOG.warn("Cannot send notification to nbi", e);
298 Thread.currentThread().interrupt();
303 private void updateOtnTopology(RendererRpcResultSp notification, boolean isDeletion) {
304 Link link = notification.getLink();
309 String serviceType = notification.getServiceType();
310 switch (serviceType) {
311 case StringConstants.SERVICE_TYPE_OTU4:
312 case StringConstants.SERVICE_TYPE_OTUC4:
313 case StringConstants.SERVICE_TYPE_ODU4:
314 case StringConstants.SERVICE_TYPE_ODUC4:
315 Map<String, OtnLinkType> otnLinkTypeMap = Map.of(
316 StringConstants.SERVICE_TYPE_OTU4, OtnLinkType.OTU4,
317 StringConstants.SERVICE_TYPE_OTUC4, OtnLinkType.OTUC4,
318 StringConstants.SERVICE_TYPE_ODU4, OtnLinkType.ODTU4,
319 StringConstants.SERVICE_TYPE_ODUC4, OtnLinkType.ODUC4);
321 LOG.info("updating otn-topology removing links");
322 this.networkModelService.deleteOtnLinks(link.getATermination().getNodeId(),
323 link.getATermination().getTpId(), link.getZTermination().getNodeId(),
324 link.getZTermination().getTpId(), otnLinkTypeMap.get(serviceType));
326 LOG.info("updating otn-topology adding links");
327 this.networkModelService.createOtnLinks(link.getATermination().getNodeId(),
328 link.getATermination().getTpId(), link.getZTermination().getNodeId(),
329 link.getZTermination().getTpId(), otnLinkTypeMap.get(serviceType));
332 case StringConstants.SERVICE_TYPE_1GE:
333 case StringConstants.SERVICE_TYPE_10GE:
334 case StringConstants.SERVICE_TYPE_100GE_M:
335 Short tribPort = Short.valueOf(notification.getAToZDirection().getMinTribSlot().getValue()
337 Short minTribSlot = Short.valueOf(notification.getAToZDirection().getMinTribSlot().getValue()
339 Short maxTribSlot = Short.valueOf(notification.getAToZDirection().getMaxTribSlot().getValue()
341 LOG.info("updating otn-topology node tps -tps and tpn pools");
342 this.networkModelService.updateOtnLinks(link, notification.getAToZDirection().getRate(),
343 tribPort, minTribSlot, maxTribSlot, isDeletion);