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 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
60 LOG.info("Service implemented !");
61 if (serviceDataStoreOperations == null) {
64 OperationResult operationResult = null;
66 operationResult = this.serviceDataStoreOperations.modifyTempService(
67 serviceRpcResultSp.getServiceName(),
68 State.InService, AdminStates.InService);
69 if (!operationResult.isSuccess()) {
70 LOG.warn("Temp Service status not updated in datastore !");
73 operationResult = this.serviceDataStoreOperations.modifyService(
74 serviceRpcResultSp.getServiceName(),
75 State.InService, AdminStates.InService);
76 if (!operationResult.isSuccess()) {
77 LOG.warn("Service status not updated in datastore !");
80 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
81 LOG.error("Renderer implementation failed !");
82 OperationResult deleteServicePathOperationResult =
83 this.serviceDataStoreOperations.deleteServicePath(serviceName);
84 if (!deleteServicePathOperationResult.isSuccess()) {
85 LOG.warn("Service path was not removed from datastore!");
88 OperationResult deleteServiceOperationResult =
89 this.serviceDataStoreOperations.deleteTempService(serviceName);
90 if (!deleteServiceOperationResult.isSuccess()) {
91 LOG.warn("Temp Service was not removed from datastore!");
94 OperationResult deleteServiceOperationResult =
95 this.serviceDataStoreOperations.deleteService(serviceName);
96 if (!deleteServiceOperationResult.isSuccess()) {
97 LOG.warn("Service was not removed from datastore!");
102 /* service-delete. */
104 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
105 LOG.info("Service '{}' deleted !", serviceName);
106 if (this.input != null) {
107 LOG.info("sending PCE cancel resource reserve for '{}'", this.input.getServiceName());
108 this.pceServiceWrapper.cancelPCEResource(this.input.getServiceName(),
109 ServiceNotificationTypes.ServiceDeleteResult);
111 LOG.error("ServiceInput parameter is null !");
113 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
114 LOG.error("Renderer service delete failed !");
122 LOG.warn("ServiceRpcResultSp already wired !");
127 value = "ES_COMPARING_STRINGS_WITH_EQ",
128 justification = "false positives, not strings but real object references comparisons")
129 private Boolean compareServiceRpcResultSp(ServiceRpcResultSp notification) {
130 Boolean result = true;
131 if (serviceRpcResultSp == null) {
134 if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) {
137 if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) {
140 if (serviceRpcResultSp.getStatus() != notification.getStatus()) {
143 if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
150 public void setServiceInput(ServiceInput serviceInput) {
151 this.input = serviceInput;
154 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
155 this.serviceDataStoreOperations = serviceData;
158 public void setTempService(Boolean tempService) {
159 this.tempService = tempService;