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.servicehandler.ServiceInput;
15 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
16 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceRpcResultSp;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.TransportpceRendererListener;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceNotificationTypes;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev181130.AdminStates;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.RpcStatusEx;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Calls to listen to Renderer notifications.
29 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
32 public class RendererListenerImpl implements TransportpceRendererListener {
34 private static final Logger LOG = LoggerFactory.getLogger(RendererListenerImpl.class);
35 private ServiceRpcResultSp serviceRpcResultSp;
36 private ServiceDataStoreOperations serviceDataStoreOperations;
37 private ServiceInput input;
38 private PCEServiceWrapper pceServiceWrapper;
39 private Boolean tempService;
41 public RendererListenerImpl(PathComputationService pathComputationService,
42 NotificationPublishService notificationPublishService) {
43 this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
44 setServiceInput(null);
45 setTempService(false);
49 public void onServiceRpcResultSp(ServiceRpcResultSp notification) {
50 if (!compareServiceRpcResultSp(notification)) {
51 serviceRpcResultSp = notification;
52 String serviceName = serviceRpcResultSp.getServiceName();
53 int notifType = serviceRpcResultSp.getNotificationType().getIntValue();
54 LOG.info("Renderer '{}' Notification received : {}", serviceRpcResultSp.getNotificationType().getName(),
57 /* service-implementation-request. */
59 onServiceImplementationResult(serviceName);
63 onServiceDeleteResult(serviceName);
69 LOG.warn("ServiceRpcResultSp already wired !");
74 * Process service delete result for serviceName.
75 * @param serviceName String
77 private void onServiceDeleteResult(String serviceName) {
78 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
79 LOG.info("Service '{}' deleted !", serviceName);
80 if (this.input != null) {
81 LOG.info("sending PCE cancel resource reserve for '{}'", this.input.getServiceName());
82 this.pceServiceWrapper.cancelPCEResource(this.input.getServiceName(),
83 ServiceNotificationTypes.ServiceDeleteResult);
85 LOG.error("ServiceInput parameter is null !");
87 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
88 LOG.error("Renderer service delete failed !");
93 * Process service implementation result for serviceName.
94 * @param serviceName String
95 * @param serviceName String
97 private void onServiceImplementationResult(String serviceName) {
98 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
99 onSuccededServiceImplementation();
100 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
101 onFailedServiceImplementation(serviceName);
106 * Process succeeded service implementation for service.
108 private void onSuccededServiceImplementation() {
109 LOG.info("Service implemented !");
110 if (serviceDataStoreOperations != null) {
111 OperationResult operationResult = null;
113 operationResult = this.serviceDataStoreOperations.modifyTempService(
114 serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
115 if (!operationResult.isSuccess()) {
116 LOG.warn("Temp Service status not updated in datastore !");
119 operationResult = this.serviceDataStoreOperations
120 .modifyService(serviceRpcResultSp.getServiceName(),
121 State.InService, AdminStates.InService);
122 if (!operationResult.isSuccess()) {
123 LOG.warn("Service status not updated in datastore !");
130 * Process failed service implementation for serviceName.
131 * @param serviceName String
133 private void onFailedServiceImplementation(String serviceName) {
134 LOG.error("Renderer implementation failed !");
135 OperationResult deleteServicePathOperationResult =
136 this.serviceDataStoreOperations.deleteServicePath(serviceName);
137 if (!deleteServicePathOperationResult.isSuccess()) {
138 LOG.warn("Service path was not removed from datastore!");
141 OperationResult deleteServiceOperationResult =
142 this.serviceDataStoreOperations.deleteTempService(serviceName);
143 if (!deleteServiceOperationResult.isSuccess()) {
144 LOG.warn("Temp Service was not removed from datastore!");
147 OperationResult deleteServiceOperationResult =
148 this.serviceDataStoreOperations.deleteService(serviceName);
149 if (!deleteServiceOperationResult.isSuccess()) {
150 LOG.warn("Service was not removed from datastore!");
156 value = "ES_COMPARING_STRINGS_WITH_EQ",
157 justification = "false positives, not strings but real object references comparisons")
158 private Boolean compareServiceRpcResultSp(ServiceRpcResultSp notification) {
159 Boolean result = true;
160 if (serviceRpcResultSp == null) {
163 if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) {
166 if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) {
169 if (serviceRpcResultSp.getStatus() != notification.getStatus()) {
172 if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
179 public void setServiceInput(ServiceInput serviceInput) {
180 this.input = serviceInput;
183 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
184 this.serviceDataStoreOperations = serviceData;
187 public void setTempService(Boolean tempService) {
188 this.tempService = tempService;