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 org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
11 import org.opendaylight.transportpce.common.OperationResult;
12 import org.opendaylight.transportpce.pce.service.PathComputationService;
13 import org.opendaylight.transportpce.servicehandler.ServiceInput;
14 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
15 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceRpcResultSp;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.TransportpceRendererListener;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceNotificationTypes;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.RpcStatusEx;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Calls to listen to Renderer notifications.
27 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
30 public class RendererListenerImpl implements TransportpceRendererListener {
32 private static final Logger LOG = LoggerFactory.getLogger(RendererListenerImpl.class);
33 private ServiceRpcResultSp serviceRpcResultSp;
34 private ServiceDataStoreOperations serviceDataStoreOperations;
35 private ServiceInput input;
36 private PCEServiceWrapper pceServiceWrapper;
37 private Boolean tempService;
39 public RendererListenerImpl(PathComputationService pathComputationService,
40 NotificationPublishService notificationPublishService) {
41 this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
42 setServiceInput(null);
43 setTempService(false);
47 public void onServiceRpcResultSp(ServiceRpcResultSp notification) {
48 if (!compareServiceRpcResultSp(notification)) {
49 serviceRpcResultSp = notification;
50 String serviceName = serviceRpcResultSp.getServiceName();
51 int notifType = serviceRpcResultSp.getNotificationType().getIntValue();
52 LOG.info("Renderer '{}' Notification received : {}", serviceRpcResultSp.getNotificationType().getName(),
55 /* service-implementation-request. */
57 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
58 LOG.info("Service implemented !");
59 OperationResult operationResult = null;
61 operationResult = this.serviceDataStoreOperations.modifyTempService(
62 serviceRpcResultSp.getServiceName(),
63 State.InService, State.InService);
64 if (!operationResult.isSuccess()) {
65 LOG.warn("Temp Service status not updated in datastore !");
68 operationResult = this.serviceDataStoreOperations.modifyService(
69 serviceRpcResultSp.getServiceName(),
70 State.InService, State.InService);
71 if (!operationResult.isSuccess()) {
72 LOG.warn("Service status not updated in datastore !");
75 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
76 LOG.error("Renderer implementation failed !");
77 OperationResult deleteServicePathOperationResult =
78 this.serviceDataStoreOperations.deleteServicePath(serviceName);
79 if (!deleteServicePathOperationResult.isSuccess()) {
80 LOG.warn("Service path was not removed from datastore!");
83 OperationResult deleteServiceOperationResult =
84 this.serviceDataStoreOperations.deleteTempService(serviceName);
85 if (!deleteServiceOperationResult.isSuccess()) {
86 LOG.warn("Temp Service was not removed from datastore!");
89 OperationResult deleteServiceOperationResult =
90 this.serviceDataStoreOperations.deleteService(serviceName);
91 if (!deleteServiceOperationResult.isSuccess()) {
92 LOG.warn("Service was not removed from datastore!");
99 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
100 LOG.info("Service '{}' deleted !", serviceName);
101 if (this.input != null) {
102 LOG.info("sending PCE cancel resource reserve for '{}'", this.input.getServiceName());
103 this.pceServiceWrapper.cancelPCEResource(this.input.getServiceName(),
104 ServiceNotificationTypes.ServiceDeleteResult);
106 LOG.error("ServiceInput parameter is null !");
108 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
109 LOG.error("Renderer service delete failed !");
117 LOG.warn("ServiceRpcResultSp already wired !");
121 private Boolean compareServiceRpcResultSp(ServiceRpcResultSp notification) {
122 Boolean result = true;
123 if (serviceRpcResultSp == null) {
126 if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) {
129 if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) {
132 if (serviceRpcResultSp.getStatus() != notification.getStatus()) {
135 if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
142 public void setServiceInput(ServiceInput serviceInput) {
143 this.input = serviceInput;
146 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
147 this.serviceDataStoreOperations = serviceData;
150 public void setTempService(Boolean tempService) {
151 this.tempService = tempService;