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.rev200520.ServiceImplementationRequestInput;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.RpcStatusEx;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParameters;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.response.parameters.sp.ResponseParametersBuilder;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class PceListenerImpl implements TransportpcePceListener {
34 private static final Logger LOG = LoggerFactory.getLogger(PceListenerImpl.class);
36 private ServicePathRpcResult servicePathRpcResult;
37 private RendererServiceOperations rendererServiceOperations;
38 private ServiceDataStoreOperations serviceDataStoreOperations;
39 private PCEServiceWrapper pceServiceWrapper;
40 private ServiceInput input;
41 private Boolean serviceReconfigure;
42 private Boolean tempService;
43 private Boolean serviceFeasiblity;
45 public PceListenerImpl(RendererServiceOperations rendererServiceOperations,
46 PathComputationService pathComputationService, NotificationPublishService notificationPublishService,
47 ServiceDataStoreOperations serviceDataStoreOperations) {
48 this.rendererServiceOperations = rendererServiceOperations;
49 this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
50 this.serviceDataStoreOperations = serviceDataStoreOperations;
51 setServiceReconfigure(false);
53 setTempService(false);
54 setServiceFeasiblity(false);
58 public void onServicePathRpcResult(ServicePathRpcResult notification) {
59 if (!compareServicePathRpcResult(notification)) {
60 servicePathRpcResult = notification;
61 PathDescription pathDescription = null;
62 switch (servicePathRpcResult.getNotificationType().getIntValue()) {
63 /* path-computation-request. */
65 LOG.info("PCE '{}' Notification received : {}",servicePathRpcResult.getNotificationType().getName(),
67 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
68 LOG.info("PCE calculation done OK !");
69 if (servicePathRpcResult.getPathDescription() != null) {
70 pathDescription = new PathDescriptionBuilder()
71 .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
72 .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection()).build();
73 LOG.info("PathDescription gets : {}", pathDescription);
74 if (!serviceFeasiblity) {
76 LOG.error("Input is null !");
79 OperationResult operationResult = null;
81 operationResult = this.serviceDataStoreOperations
82 .createTempService(input.getTempServiceCreateInput());
83 if (!operationResult.isSuccess()) {
84 LOG.error("Temp Service not created in datastore !");
87 operationResult = this.serviceDataStoreOperations
88 .createService(input.getServiceCreateInput());
89 if (!operationResult.isSuccess()) {
90 LOG.error("Service not created in datastore !");
93 ResponseParameters responseParameters = new ResponseParametersBuilder()
94 .setPathDescription(new org.opendaylight.yang.gen.v1.http.org
95 .transportpce.b.c._interface.service.types.rev200128
96 .response.parameters.sp.response.parameters
97 .PathDescriptionBuilder(pathDescription).build())
99 PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder()
100 .setResponseParameters(responseParameters).build();
101 OperationResult operationServicePathSaveResult =
102 this.serviceDataStoreOperations.createServicePath(input, pceResponse);
103 if (!operationServicePathSaveResult.isSuccess()) {
104 LOG.error("Service Path not created in datastore !");
106 ServiceImplementationRequestInput serviceImplementationRequest =
107 ModelMappingUtils.createServiceImplementationRequest(input, pathDescription);
108 LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest);
109 this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest);
111 LOG.warn("service-feasibility-check RPC ");
114 LOG.error("'PathDescription' parameter is null ");
117 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
118 LOG.error("PCE path computation failed !");
122 /* cancel-resource-reserve. */
124 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
125 LOG.info("PCE cancel resource done OK !");
126 OperationResult deleteServicePathOperationResult =
127 this.serviceDataStoreOperations.deleteServicePath(input.getServiceName());
128 if (!deleteServicePathOperationResult.isSuccess()) {
129 LOG.warn("Service path was not removed from datastore!");
131 OperationResult deleteServiceOperationResult = null;
133 deleteServiceOperationResult =
134 this.serviceDataStoreOperations.deleteTempService(input.getServiceName());
135 if (!deleteServiceOperationResult.isSuccess()) {
136 LOG.warn("Service was not removed from datastore!");
139 deleteServiceOperationResult =
140 this.serviceDataStoreOperations.deleteService(input.getServiceName());
141 if (!deleteServiceOperationResult.isSuccess()) {
142 LOG.warn("Service was not removed from datastore!");
146 * if it was an RPC serviceReconfigure, re-launch PCR.
148 if (this.serviceReconfigure) {
149 LOG.info("cancel resource reserve done, relaunching PCE path computation ...");
150 this.pceServiceWrapper.performPCE(input.getServiceCreateInput(), true);
151 this.serviceReconfigure = false;
153 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
154 LOG.info("PCE cancel resource failed !");
161 LOG.warn("ServicePathRpcResult already wired !");
166 value = "ES_COMPARING_STRINGS_WITH_EQ",
167 justification = "false positives, not strings but real object references comparisons")
168 private Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
169 Boolean result = true;
170 if (servicePathRpcResult == null) {
173 if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
176 if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
179 if (servicePathRpcResult.getStatus() != notification.getStatus()) {
182 if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
189 public void setInput(ServiceInput serviceInput) {
190 this.input = serviceInput;
193 public void setServiceReconfigure(Boolean serv) {
194 this.serviceReconfigure = serv;
197 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
198 this.serviceDataStoreOperations = serviceData;
201 public void setTempService(Boolean tempService) {
202 this.tempService = tempService;
205 public void setServiceFeasiblity(Boolean serviceFeasiblity) {
206 this.serviceFeasiblity = serviceFeasiblity;