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.opendaylight.transportpce.servicehandler.rev201125.ServiceRpcResultSh;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.ServiceRpcResultShBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceNotificationTypes;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev181130.AdminStates;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * Calls to listen to Renderer notifications.
30 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
33 public class RendererListenerImpl implements TransportpceRendererListener {
35 private static final Logger LOG = LoggerFactory.getLogger(RendererListenerImpl.class);
36 private RendererRpcResultSp serviceRpcResultSp;
37 private ServiceDataStoreOperations serviceDataStoreOperations;
38 private ServiceInput input;
39 private PCEServiceWrapper pceServiceWrapper;
40 private Boolean tempService;
41 private NotificationPublishService notificationPublishService;
43 public RendererListenerImpl(PathComputationService pathComputationService,
44 NotificationPublishService notificationPublishService) {
45 this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
46 setServiceInput(null);
47 setTempService(false);
48 this.notificationPublishService = notificationPublishService;
52 public void onRendererRpcResultSp(RendererRpcResultSp notification) {
53 if (compareServiceRpcResultSp(notification)) {
54 LOG.warn("ServiceRpcResultSp already wired !");
57 serviceRpcResultSp = notification;
58 int notifType = serviceRpcResultSp.getNotificationType().getIntValue();
59 LOG.info("Renderer '{}' Notification received : {}", serviceRpcResultSp.getNotificationType().getName(),
62 /* service-implementation-request. */
64 onServiceImplementationResult(notification);
68 onServiceDeleteResult(notification);
76 * Process service delete result for serviceName.
77 * @param notification RendererRpcResultSp
79 private void onServiceDeleteResult(RendererRpcResultSp notification) {
80 switch (serviceRpcResultSp.getStatus()) {
82 LOG.info("Service '{}' deleted !", notification.getServiceName());
85 LOG.error("Renderer service delete failed !");
88 LOG.warn("Renderer service delete returned a Penging RpcStatusEx code!");
91 LOG.error("Renderer service delete returned an unknown RpcStatusEx code!");
94 if (this.input == null) {
95 LOG.error("ServiceInput parameter is null !");
98 LOG.info("sending PCE cancel resource reserve for '{}'", this.input.getServiceName());
99 this.pceServiceWrapper.cancelPCEResource(this.input.getServiceName(),
100 ServiceNotificationTypes.ServiceDeleteResult);
101 sendServiceHandlerNotification(notification, ServiceNotificationTypes.ServiceDeleteResult);
105 * Process service implementation result for serviceName.
106 * @param notification RendererRpcResultSp
108 private void onServiceImplementationResult(RendererRpcResultSp notification) {
109 switch (serviceRpcResultSp.getStatus()) {
111 onSuccededServiceImplementation(notification);
114 onFailedServiceImplementation(notification.getServiceName());
117 LOG.warn("Service Implementation still pending according to RpcStatusEx");
120 LOG.warn("Service Implementation has an unknown RpcStatusEx code");
126 * Process succeeded service implementation for service.
127 * @param notification RendererRpcResultSp
129 private void onSuccededServiceImplementation(RendererRpcResultSp notification) {
130 LOG.info("Service implemented !");
131 if (serviceDataStoreOperations == null) {
132 LOG.debug("serviceDataStoreOperations is null");
135 OperationResult operationResult = null;
137 operationResult = this.serviceDataStoreOperations.modifyTempService(
138 serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
139 if (!operationResult.isSuccess()) {
140 LOG.warn("Temp Service status not updated in datastore !");
143 operationResult = this.serviceDataStoreOperations.modifyService(
144 serviceRpcResultSp.getServiceName(),
146 AdminStates.InService);
147 if (!operationResult.isSuccess()) {
148 LOG.warn("Service status not updated in datastore !");
150 sendServiceHandlerNotification(notification, ServiceNotificationTypes.ServiceCreateResult);
156 * Create and send service handler notification.
157 * @param notification RendererRpcResultSp
158 * @param type ServiceNotificationTypes
160 private void sendServiceHandlerNotification(RendererRpcResultSp notification, ServiceNotificationTypes type) {
162 ServiceRpcResultSh serviceHandlerNotification = new ServiceRpcResultShBuilder()
163 .setAToZDirection(notification.getAToZDirection())
164 .setZToADirection(notification.getZToADirection())
165 .setServiceName(notification.getServiceName())
166 .setStatus(notification.getStatus())
167 .setStatusMessage(notification.getStatusMessage())
168 .setNotificationType(type)
170 LOG.debug("Service update in datastore OK, sending notification {}", serviceHandlerNotification);
171 notificationPublishService.putNotification(
172 serviceHandlerNotification);
173 } catch (InterruptedException e) {
174 LOG.warn("Something went wrong while sending notification for sevice {}",
175 serviceRpcResultSp.getServiceName(), e);
176 Thread.currentThread().interrupt();
181 * Process failed service implementation for serviceName.
182 * @param serviceName String
184 private void onFailedServiceImplementation(String serviceName) {
185 LOG.error("Renderer implementation failed !");
186 OperationResult deleteServicePathOperationResult =
187 this.serviceDataStoreOperations.deleteServicePath(serviceName);
188 if (!deleteServicePathOperationResult.isSuccess()) {
189 LOG.warn("Service path was not removed from datastore!");
192 OperationResult deleteServiceOperationResult =
193 this.serviceDataStoreOperations.deleteTempService(serviceName);
194 if (!deleteServiceOperationResult.isSuccess()) {
195 LOG.warn("Temp Service was not removed from datastore!");
198 OperationResult deleteServiceOperationResult =
199 this.serviceDataStoreOperations.deleteService(serviceName);
200 if (!deleteServiceOperationResult.isSuccess()) {
201 LOG.warn("Service was not removed from datastore!");
207 value = "ES_COMPARING_STRINGS_WITH_EQ",
208 justification = "false positives, not strings but real object references comparisons")
209 private Boolean compareServiceRpcResultSp(RendererRpcResultSp notification) {
210 if (serviceRpcResultSp == null) {
213 if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) {
216 if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) {
219 if (serviceRpcResultSp.getStatus() != notification.getStatus()) {
222 if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
228 public void setServiceInput(ServiceInput serviceInput) {
229 this.input = serviceInput;
232 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
233 this.serviceDataStoreOperations = serviceData;
236 public void setTempService(Boolean tempService) {
237 this.tempService = tempService;