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 case 3 : /** service-implementation-request. */
56 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
57 LOG.info("Service implemented !");
58 OperationResult operationResult = null;
60 operationResult = this.serviceDataStoreOperations.modifyTempService(
61 serviceRpcResultSp.getServiceName(),
62 State.InService, State.InService);
63 if (!operationResult.isSuccess()) {
64 LOG.warn("Temp Service status not updated in datastore !");
67 operationResult = this.serviceDataStoreOperations.modifyService(
68 serviceRpcResultSp.getServiceName(),
69 State.InService, State.InService);
70 if (!operationResult.isSuccess()) {
71 LOG.warn("Service status not updated in datastore !");
74 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
75 LOG.error("Renderer implementation failed !");
76 OperationResult deleteServicePathOperationResult =
77 this.serviceDataStoreOperations.deleteServicePath(serviceName);
78 if (!deleteServicePathOperationResult.isSuccess()) {
79 LOG.warn("Service path was not removed from datastore!");
82 OperationResult deleteServiceOperationResult =
83 this.serviceDataStoreOperations.deleteTempService(serviceName);
84 if (!deleteServiceOperationResult.isSuccess()) {
85 LOG.warn("Temp Service was not removed from datastore!");
88 OperationResult deleteServiceOperationResult =
89 this.serviceDataStoreOperations.deleteService(serviceName);
90 if (!deleteServiceOperationResult.isSuccess()) {
91 LOG.warn("Service was not removed from datastore!");
97 case 4 : /** service-delete. */
98 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
99 LOG.info("Service '{}' deleted !", serviceName);
100 if (this.input != null) {
101 LOG.info("sending PCE cancel resource reserve for '{}'", this.input.getServiceName());
102 this.pceServiceWrapper.cancelPCEResource(this.input.getServiceName(),
103 ServiceNotificationTypes.ServiceDeleteResult);
105 LOG.error("ServiceInput parameter is null !");
107 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
108 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;