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 switch (servicePathRpcResult.getNotificationType().getIntValue()) {
62 /* path-computation-request. */
64 onPathComputationResult(notification);
66 /* cancel-resource-reserve. */
68 onCancelResourceResult();
74 LOG.warn("ServicePathRpcResult already wired !");
79 * Process path computation request result.
80 * @param notification the result notification.
82 private void onPathComputationResult(ServicePathRpcResult notification) {
83 LOG.info("PCE '{}' Notification received : {}",servicePathRpcResult.getNotificationType().getName(),
85 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
86 LOG.info("PCE calculation done OK !");
87 if (servicePathRpcResult.getPathDescription() != null) {
88 PathDescription pathDescription = new PathDescriptionBuilder()
89 .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
90 .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection()).build();
91 LOG.info("PathDescription gets : {}", pathDescription);
92 if (!serviceFeasiblity) {
94 LOG.error("Input is null !");
96 OperationResult operationResult = null;
98 operationResult = this.serviceDataStoreOperations
99 .createTempService(input.getTempServiceCreateInput());
100 if (!operationResult.isSuccess()) {
101 LOG.error("Temp Service not created in datastore !");
104 operationResult = this.serviceDataStoreOperations
105 .createService(input.getServiceCreateInput());
106 if (!operationResult.isSuccess()) {
107 LOG.error("Service not created in datastore !");
110 ResponseParameters responseParameters = new ResponseParametersBuilder()
111 .setPathDescription(new org.opendaylight.yang.gen.v1.http.org
112 .transportpce.b.c._interface.service.types.rev200128
113 .response.parameters.sp.response.parameters
114 .PathDescriptionBuilder(pathDescription).build())
116 PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder()
117 .setResponseParameters(responseParameters).build();
118 OperationResult operationServicePathSaveResult = this.serviceDataStoreOperations
119 .createServicePath(input, pceResponse);
120 if (!operationServicePathSaveResult.isSuccess()) {
121 LOG.error("Service Path not created in datastore !");
123 ServiceImplementationRequestInput serviceImplementationRequest = ModelMappingUtils
124 .createServiceImplementationRequest(input, pathDescription);
125 LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest);
126 this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest);
129 LOG.warn("service-feasibility-check RPC ");
132 LOG.error("'PathDescription' parameter is null ");
134 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
135 LOG.error("PCE path computation failed !");
140 * Process cancel resource result.
142 private void onCancelResourceResult() {
143 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
144 LOG.info("PCE cancel resource done OK !");
145 OperationResult deleteServicePathOperationResult =
146 this.serviceDataStoreOperations.deleteServicePath(input.getServiceName());
147 if (!deleteServicePathOperationResult.isSuccess()) {
148 LOG.warn("Service path was not removed from datastore!");
150 OperationResult deleteServiceOperationResult = null;
152 deleteServiceOperationResult =
153 this.serviceDataStoreOperations.deleteTempService(input.getServiceName());
154 if (!deleteServiceOperationResult.isSuccess()) {
155 LOG.warn("Service was not removed from datastore!");
158 deleteServiceOperationResult =
159 this.serviceDataStoreOperations.deleteService(input.getServiceName());
160 if (!deleteServiceOperationResult.isSuccess()) {
161 LOG.warn("Service was not removed from datastore!");
165 * if it was an RPC serviceReconfigure, re-launch PCR.
167 if (this.serviceReconfigure) {
168 LOG.info("cancel resource reserve done, relaunching PCE path computation ...");
169 this.pceServiceWrapper.performPCE(input.getServiceCreateInput(), true);
170 this.serviceReconfigure = false;
172 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
173 LOG.info("PCE cancel resource failed !");
178 value = "ES_COMPARING_STRINGS_WITH_EQ",
179 justification = "false positives, not strings but real object references comparisons")
180 private Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
181 Boolean result = true;
182 if (servicePathRpcResult == null) {
185 if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
188 if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
191 if (servicePathRpcResult.getStatus() != notification.getStatus()) {
194 if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
201 public void setInput(ServiceInput serviceInput) {
202 this.input = serviceInput;
205 public void setServiceReconfigure(Boolean serv) {
206 this.serviceReconfigure = serv;
209 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
210 this.serviceDataStoreOperations = serviceData;
213 public void setTempService(Boolean tempService) {
214 this.tempService = tempService;
217 public void setServiceFeasiblity(Boolean serviceFeasiblity) {
218 this.serviceFeasiblity = serviceFeasiblity;