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;
11 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
12 import org.opendaylight.transportpce.common.OperationResult;
13 import org.opendaylight.transportpce.pce.service.PathComputationService;
14 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
15 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
16 import org.opendaylight.transportpce.servicehandler.ServiceInput;
17 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
18 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutputBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.ServicePathRpcResult;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.TransportpcePceListener;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.service.path.rpc.result.PathDescription;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.service.path.rpc.result.PathDescriptionBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceImplementationRequestInput;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.RpcStatusEx;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParameters;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParametersBuilder;
30 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationService;
31 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.PublishNotificationServiceBuilder;
32 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.notification.service.ServiceAEndBuilder;
33 import org.opendaylight.yang.gen.v1.nbi.notifications.rev201130.notification.service.ServiceZEndBuilder;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class PceListenerImpl implements TransportpcePceListener {
39 private static final Logger LOG = LoggerFactory.getLogger(PceListenerImpl.class);
40 private static final String TOPIC = "PceListener";
42 private ServicePathRpcResult servicePathRpcResult;
43 private RendererServiceOperations rendererServiceOperations;
44 private ServiceDataStoreOperations serviceDataStoreOperations;
45 private PCEServiceWrapper pceServiceWrapper;
46 private ServiceInput input;
47 private Boolean serviceReconfigure;
48 private Boolean tempService;
49 private Boolean serviceFeasiblity;
50 private NotificationPublishService notificationPublishService;
52 public PceListenerImpl(RendererServiceOperations rendererServiceOperations,
53 PathComputationService pathComputationService, NotificationPublishService notificationPublishService,
54 ServiceDataStoreOperations serviceDataStoreOperations) {
55 this.rendererServiceOperations = rendererServiceOperations;
56 this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
57 this.serviceDataStoreOperations = serviceDataStoreOperations;
58 setServiceReconfigure(false);
60 setTempService(false);
61 setServiceFeasiblity(false);
62 this.notificationPublishService = notificationPublishService;
66 public void onServicePathRpcResult(ServicePathRpcResult notification) {
67 if (compareServicePathRpcResult(notification)) {
68 LOG.warn("ServicePathRpcResult already wired !");
71 servicePathRpcResult = notification;
72 switch (servicePathRpcResult.getNotificationType().getIntValue()) {
73 /* path-computation-request. */
75 onPathComputationResult(notification);
77 /* cancel-resource-reserve. */
79 onCancelResourceResult();
87 * Process path computation request result.
88 * @param notification the result notification.
90 private void onPathComputationResult(ServicePathRpcResult notification) {
91 LOG.info("PCE '{}' Notification received : {}", servicePathRpcResult.getNotificationType().getName(),
93 if (!checkStatus(notification)) {
96 if (servicePathRpcResult.getPathDescription() == null) {
97 LOG.error("'PathDescription' parameter is null ");
100 PathDescription pathDescription = new PathDescriptionBuilder()
101 .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
102 .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection())
104 LOG.info("PathDescription gets : {}", pathDescription);
105 if (serviceFeasiblity) {
106 LOG.warn("service-feasibility-check RPC ");
110 LOG.error("Input is null !");
113 OperationResult operationResult = null;
115 operationResult = this.serviceDataStoreOperations.createTempService(input.getTempServiceCreateInput());
116 if (!operationResult.isSuccess()) {
117 LOG.error("Temp Service not created in datastore !");
120 operationResult = this.serviceDataStoreOperations.createService(input.getServiceCreateInput());
121 if (!operationResult.isSuccess()) {
122 LOG.error("Service not created in datastore !");
125 ResponseParameters responseParameters = new ResponseParametersBuilder()
126 .setPathDescription(new org.opendaylight.yang.gen.v1.http
127 .org.transportpce.b.c._interface.service.types.rev200128
128 .response.parameters.sp.response.parameters.PathDescriptionBuilder(pathDescription).build())
130 PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder()
131 .setResponseParameters(responseParameters).build();
132 OperationResult operationServicePathSaveResult = this.serviceDataStoreOperations
133 .createServicePath(input, pceResponse);
134 if (!operationServicePathSaveResult.isSuccess()) {
135 LOG.error("Service Path not created in datastore !");
137 ServiceImplementationRequestInput serviceImplementationRequest = ModelMappingUtils
138 .createServiceImplementationRequest(input, pathDescription);
139 LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest);
140 this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest);
144 * Check status of notification and send nbi notification.
145 * @param notification ServicePathRpcResult the notification to check.
146 * @return true is status is Successful, false otherwise.
148 private boolean checkStatus(ServicePathRpcResult notification) {
149 PublishNotificationService nbiNotification = getPublishNotificationService(notification);
150 PublishNotificationServiceBuilder publishNotificationServiceBuilder = new PublishNotificationServiceBuilder(
152 switch (servicePathRpcResult.getStatus()) {
154 LOG.error("PCE path computation failed !");
155 nbiNotification = publishNotificationServiceBuilder.setMessage("ServiceCreate request failed ...")
156 .setResponseFailed("PCE path computation failed !")
157 .setOperationalState(State.Degraded).build();
158 sendNbiNotification(nbiNotification);
161 LOG.warn("PCE path computation returned a Penging RpcStatusEx code!");
164 LOG.info("PCE calculation done OK !");
165 nbiNotification = publishNotificationServiceBuilder.setMessage("PCE calculation done OK !")
166 .setResponseFailed("").setOperationalState(State.OutOfService).build();
167 sendNbiNotification(nbiNotification);
170 LOG.error("PCE path computation returned an unknown RpcStatusEx code {}",
171 servicePathRpcResult.getStatus());
172 nbiNotification = publishNotificationServiceBuilder.setMessage("ServiceCreate request failed ...")
173 .setResponseFailed("PCE path computation returned an unknown RpcStatusEx code!")
174 .setOperationalState(State.Degraded).build();
175 sendNbiNotification(nbiNotification);
180 private PublishNotificationService getPublishNotificationService(ServicePathRpcResult notification) {
181 PublishNotificationServiceBuilder nbiNotificationBuilder = new PublishNotificationServiceBuilder();
183 nbiNotificationBuilder.setServiceName(input.getServiceName())
184 .setServiceAEnd(new ServiceAEndBuilder(input.getServiceAEnd()).build())
185 .setServiceZEnd(new ServiceZEndBuilder(input.getServiceZEnd()).build())
186 .setCommonId(input.getCommonId()).setConnectionType(input.getConnectionType());
188 nbiNotificationBuilder.setServiceName(notification.getServiceName());
190 nbiNotificationBuilder.setTopic(TOPIC);
191 return nbiNotificationBuilder.build();
195 * Process cancel resource result.
197 private void onCancelResourceResult() {
198 if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
199 LOG.info("PCE cancel resource failed !");
201 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Pending) {
202 LOG.warn("PCE cancel returned a Penging RpcStatusEx code!");
204 } else if (servicePathRpcResult.getStatus() != RpcStatusEx.Successful) {
205 LOG.error("PCE cancel returned an unknown RpcStatusEx code!");
208 LOG.info("PCE cancel resource done OK !");
209 OperationResult deleteServicePathOperationResult =
210 this.serviceDataStoreOperations.deleteServicePath(input.getServiceName());
211 if (!deleteServicePathOperationResult.isSuccess()) {
212 LOG.warn("Service path was not removed from datastore!");
214 OperationResult deleteServiceOperationResult = null;
216 deleteServiceOperationResult =
217 this.serviceDataStoreOperations.deleteTempService(input.getServiceName());
218 if (!deleteServiceOperationResult.isSuccess()) {
219 LOG.warn("Temp Service was not removed from datastore!");
222 deleteServiceOperationResult =
223 this.serviceDataStoreOperations.deleteService(input.getServiceName());
224 if (!deleteServiceOperationResult.isSuccess()) {
225 LOG.warn("Service was not removed from datastore!");
229 * if it was an RPC serviceReconfigure, re-launch PCR.
231 if (this.serviceReconfigure) {
232 LOG.info("cancel resource reserve done, relaunching PCE path computation ...");
233 this.pceServiceWrapper.performPCE(input.getServiceCreateInput(), true);
234 this.serviceReconfigure = false;
239 value = "ES_COMPARING_STRINGS_WITH_EQ",
240 justification = "false positives, not strings but real object references comparisons")
241 private Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
242 if (servicePathRpcResult == null) {
245 if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
248 if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
251 if (servicePathRpcResult.getStatus() != notification.getStatus()) {
254 if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
260 public void setInput(ServiceInput serviceInput) {
261 this.input = serviceInput;
264 public void setServiceReconfigure(Boolean serv) {
265 this.serviceReconfigure = serv;
268 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
269 this.serviceDataStoreOperations = serviceData;
272 public void setTempService(Boolean tempService) {
273 this.tempService = tempService;
276 public void setServiceFeasiblity(Boolean serviceFeasiblity) {
277 this.serviceFeasiblity = serviceFeasiblity;
281 * Send notification to NBI notification in order to publish message.
282 * @param service PublishNotificationService
284 private void sendNbiNotification(PublishNotificationService service) {
286 notificationPublishService.putNotification(service);
287 } catch (InterruptedException e) {
288 LOG.warn("Cannot send notification to nbi", e);
289 Thread.currentThread().interrupt();