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.Failed) {
86 LOG.error("PCE path computation failed !");
88 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Pending) {
89 LOG.warn("PCE path computation returned a Penging RpcStatusEx code!");
91 } else if (servicePathRpcResult.getStatus() != RpcStatusEx.Successful) {
92 LOG.error("PCE path computation returned an unknown RpcStatusEx code!");
96 LOG.info("PCE calculation done OK !");
97 if (servicePathRpcResult.getPathDescription() == null) {
98 LOG.error("'PathDescription' parameter is null ");
101 PathDescription pathDescription = new PathDescriptionBuilder()
102 .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
103 .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection())
105 LOG.info("PathDescription gets : {}", pathDescription);
106 if (serviceFeasiblity) {
107 LOG.warn("service-feasibility-check RPC ");
111 LOG.error("Input is null !");
114 OperationResult operationResult = null;
116 operationResult = this.serviceDataStoreOperations.createTempService(input.getTempServiceCreateInput());
117 if (!operationResult.isSuccess()) {
118 LOG.error("Temp Service not created in datastore !");
121 operationResult = this.serviceDataStoreOperations.createService(input.getServiceCreateInput());
122 if (!operationResult.isSuccess()) {
123 LOG.error("Service not created in datastore !");
126 ResponseParameters responseParameters = new ResponseParametersBuilder()
127 .setPathDescription(new org.opendaylight.yang.gen.v1.http.org
128 .transportpce.b.c._interface.service.types.rev200128
129 .response.parameters.sp.response.parameters
130 .PathDescriptionBuilder(pathDescription).build())
132 PathComputationRequestOutput pceResponse = new PathComputationRequestOutputBuilder()
133 .setResponseParameters(responseParameters).build();
134 OperationResult operationServicePathSaveResult = this.serviceDataStoreOperations
135 .createServicePath(input, pceResponse);
136 if (!operationServicePathSaveResult.isSuccess()) {
137 LOG.error("Service Path not created in datastore !");
139 ServiceImplementationRequestInput serviceImplementationRequest = ModelMappingUtils
140 .createServiceImplementationRequest(input, pathDescription);
141 LOG.info("Sending serviceImplementation request : {}", serviceImplementationRequest);
142 this.rendererServiceOperations.serviceImplementation(serviceImplementationRequest);
146 * Process cancel resource result.
148 private void onCancelResourceResult() {
149 if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
150 LOG.info("PCE cancel resource failed !");
152 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Pending) {
153 LOG.warn("PCE cancel returned a Penging RpcStatusEx code!");
155 } else if (servicePathRpcResult.getStatus() != RpcStatusEx.Successful) {
156 LOG.error("PCE cancel returned an unknown RpcStatusEx code!");
159 LOG.info("PCE cancel resource done OK !");
160 OperationResult deleteServicePathOperationResult =
161 this.serviceDataStoreOperations.deleteServicePath(input.getServiceName());
162 if (!deleteServicePathOperationResult.isSuccess()) {
163 LOG.warn("Service path was not removed from datastore!");
165 OperationResult deleteServiceOperationResult = null;
167 deleteServiceOperationResult =
168 this.serviceDataStoreOperations.deleteTempService(input.getServiceName());
169 if (!deleteServiceOperationResult.isSuccess()) {
170 LOG.warn("Temp Service was not removed from datastore!");
173 deleteServiceOperationResult =
174 this.serviceDataStoreOperations.deleteService(input.getServiceName());
175 if (!deleteServiceOperationResult.isSuccess()) {
176 LOG.warn("Service was not removed from datastore!");
180 * if it was an RPC serviceReconfigure, re-launch PCR.
182 if (this.serviceReconfigure) {
183 LOG.info("cancel resource reserve done, relaunching PCE path computation ...");
184 this.pceServiceWrapper.performPCE(input.getServiceCreateInput(), true);
185 this.serviceReconfigure = false;
190 value = "ES_COMPARING_STRINGS_WITH_EQ",
191 justification = "false positives, not strings but real object references comparisons")
192 private Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
193 if (servicePathRpcResult == null) {
196 if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
199 if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
202 if (servicePathRpcResult.getStatus() != notification.getStatus()) {
205 if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
211 public void setInput(ServiceInput serviceInput) {
212 this.input = serviceInput;
215 public void setServiceReconfigure(Boolean serv) {
216 this.serviceReconfigure = serv;
219 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
220 this.serviceDataStoreOperations = serviceData;
223 public void setTempService(Boolean tempService) {
224 this.tempService = tempService;
227 public void setServiceFeasiblity(Boolean serviceFeasiblity) {
228 this.serviceFeasiblity = serviceFeasiblity;