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.rev201125.RendererRpcResultSp;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.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 RendererRpcResultSp 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 onRendererRpcResultSp(RendererRpcResultSp notification) {
50 if (compareServiceRpcResultSp(notification)) {
51 LOG.warn("ServiceRpcResultSp already wired !");
54 serviceRpcResultSp = notification;
55 String serviceName = serviceRpcResultSp.getServiceName();
56 int notifType = serviceRpcResultSp.getNotificationType().getIntValue();
57 LOG.info("Renderer '{}' Notification received : {}", serviceRpcResultSp.getNotificationType().getName(),
60 /* service-implementation-request. */
62 onServiceImplementationResult(serviceName);
66 onServiceDeleteResult(serviceName);
74 * Process service delete result for serviceName.
75 * @param serviceName String
77 private void onServiceDeleteResult(String serviceName) {
78 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
79 LOG.error("Renderer service delete failed !");
81 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Pending) {
82 LOG.warn("Renderer service delete returned a Penging RpcStatusEx code!");
84 } else if (serviceRpcResultSp.getStatus() != RpcStatusEx.Successful) {
85 LOG.error("Renderer service delete returned an unknown RpcStatusEx code!");
88 LOG.info("Service '{}' deleted !", serviceName);
89 if (this.input == null) {
90 LOG.error("ServiceInput parameter is null !");
93 LOG.info("sending PCE cancel resource reserve for '{}'", this.input.getServiceName());
94 this.pceServiceWrapper.cancelPCEResource(this.input.getServiceName(),
95 ServiceNotificationTypes.ServiceDeleteResult);
99 * Process service implementation result for serviceName.
100 * @param serviceName String
101 * @param serviceName String
103 private void onServiceImplementationResult(String serviceName) {
104 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
105 onSuccededServiceImplementation();
106 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
107 onFailedServiceImplementation(serviceName);
108 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Pending) {
109 LOG.warn("Service Implementation still pending according to RpcStatusEx");
111 LOG.warn("Service Implementation has an unknown RpcStatusEx code");
117 * Process succeeded service implementation for service.
119 private void onSuccededServiceImplementation() {
120 LOG.info("Service implemented !");
121 if (serviceDataStoreOperations == null) {
122 LOG.debug("serviceDataStoreOperations is null");
125 OperationResult operationResult = null;
127 operationResult = this.serviceDataStoreOperations.modifyTempService(
128 serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
129 if (!operationResult.isSuccess()) {
130 LOG.warn("Temp Service status not updated in datastore !");
133 operationResult = this.serviceDataStoreOperations.modifyService(
134 serviceRpcResultSp.getServiceName(),
136 AdminStates.InService);
137 if (!operationResult.isSuccess()) {
138 LOG.warn("Service status not updated in datastore !");
144 * Process failed service implementation for serviceName.
145 * @param serviceName String
147 private void onFailedServiceImplementation(String serviceName) {
148 LOG.error("Renderer implementation failed !");
149 OperationResult deleteServicePathOperationResult =
150 this.serviceDataStoreOperations.deleteServicePath(serviceName);
151 if (!deleteServicePathOperationResult.isSuccess()) {
152 LOG.warn("Service path was not removed from datastore!");
155 OperationResult deleteServiceOperationResult =
156 this.serviceDataStoreOperations.deleteTempService(serviceName);
157 if (!deleteServiceOperationResult.isSuccess()) {
158 LOG.warn("Temp Service was not removed from datastore!");
161 OperationResult deleteServiceOperationResult =
162 this.serviceDataStoreOperations.deleteService(serviceName);
163 if (!deleteServiceOperationResult.isSuccess()) {
164 LOG.warn("Service was not removed from datastore!");
170 value = "ES_COMPARING_STRINGS_WITH_EQ",
171 justification = "false positives, not strings but real object references comparisons")
172 private Boolean compareServiceRpcResultSp(RendererRpcResultSp notification) {
173 if (serviceRpcResultSp == null) {
176 if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) {
179 if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) {
182 if (serviceRpcResultSp.getStatus() != notification.getStatus()) {
185 if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
191 public void setServiceInput(ServiceInput serviceInput) {
192 this.input = serviceInput;
195 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
196 this.serviceDataStoreOperations = serviceData;
199 public void setTempService(Boolean tempService) {
200 this.tempService = tempService;