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.mdsal.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.rev190531.ServiceNotificationTypes;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev181130.AdminStates;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev191009.RpcStatusEx;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Calls to listen to Renderer notifications.
28 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
31 public class RendererListenerImpl implements TransportpceRendererListener {
33 private static final Logger LOG = LoggerFactory.getLogger(RendererListenerImpl.class);
34 private ServiceRpcResultSp serviceRpcResultSp;
35 private ServiceDataStoreOperations serviceDataStoreOperations;
36 private ServiceInput input;
37 private PCEServiceWrapper pceServiceWrapper;
38 private Boolean tempService;
40 public RendererListenerImpl(PathComputationService pathComputationService,
41 NotificationPublishService notificationPublishService) {
42 this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
43 setServiceInput(null);
44 setTempService(false);
48 public void onServiceRpcResultSp(ServiceRpcResultSp notification) {
49 if (!compareServiceRpcResultSp(notification)) {
50 serviceRpcResultSp = notification;
51 String serviceName = serviceRpcResultSp.getServiceName();
52 int notifType = serviceRpcResultSp.getNotificationType().getIntValue();
53 LOG.info("Renderer '{}' Notification received : {}", serviceRpcResultSp.getNotificationType().getName(),
56 /* service-implementation-request. */
58 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
59 LOG.info("Service implemented !");
60 OperationResult operationResult = null;
62 operationResult = this.serviceDataStoreOperations.modifyTempService(
63 serviceRpcResultSp.getServiceName(),
64 State.InService, AdminStates.InService);
65 if (!operationResult.isSuccess()) {
66 LOG.warn("Temp Service status not updated in datastore !");
69 operationResult = this.serviceDataStoreOperations.modifyService(
70 serviceRpcResultSp.getServiceName(),
71 State.InService, AdminStates.InService);
72 if (!operationResult.isSuccess()) {
73 LOG.warn("Service status not updated in datastore !");
76 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
77 LOG.error("Renderer implementation failed !");
78 OperationResult deleteServicePathOperationResult =
79 this.serviceDataStoreOperations.deleteServicePath(serviceName);
80 if (!deleteServicePathOperationResult.isSuccess()) {
81 LOG.warn("Service path was not removed from datastore!");
84 OperationResult deleteServiceOperationResult =
85 this.serviceDataStoreOperations.deleteTempService(serviceName);
86 if (!deleteServiceOperationResult.isSuccess()) {
87 LOG.warn("Temp Service was not removed from datastore!");
90 OperationResult deleteServiceOperationResult =
91 this.serviceDataStoreOperations.deleteService(serviceName);
92 if (!deleteServiceOperationResult.isSuccess()) {
93 LOG.warn("Service was not removed from datastore!");
100 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
101 LOG.info("Service '{}' deleted !", serviceName);
102 if (this.input != null) {
103 LOG.info("sending PCE cancel resource reserve for '{}'", this.input.getServiceName());
104 this.pceServiceWrapper.cancelPCEResource(this.input.getServiceName(),
105 ServiceNotificationTypes.ServiceDeleteResult);
107 LOG.error("ServiceInput parameter is null !");
109 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
110 LOG.error("Renderer service delete failed !");
118 LOG.warn("ServiceRpcResultSp already wired !");
122 private Boolean compareServiceRpcResultSp(ServiceRpcResultSp notification) {
123 Boolean result = true;
124 if (serviceRpcResultSp == null) {
127 if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) {
130 if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) {
133 if (serviceRpcResultSp.getStatus() != notification.getStatus()) {
136 if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
143 public void setServiceInput(ServiceInput serviceInput) {
144 this.input = serviceInput;
147 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
148 this.serviceDataStoreOperations = serviceData;
151 public void setTempService(Boolean tempService) {
152 this.tempService = tempService;