ServiceHandler update for new PCE compatibility
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / listeners / PceListenerImpl.java
1 /*
2  * Copyright © 2017 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.servicehandler.listeners;
9
10 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.PceListener;
11 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev170426.ServicePathRpcResult;
12 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx;
13 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.ServicePathNotificationTypes;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 @Deprecated
18 public class PceListenerImpl implements PceListener {
19
20     private static final Logger LOG = LoggerFactory.getLogger(PceListenerImpl.class);
21
22     private ServicePathRpcResult servicePathRpcResult = null;
23
24     @Override
25     public void onServicePathRpcResult(ServicePathRpcResult notification) {
26         if (!compareServicePathRpcResult(notification)) {
27             servicePathRpcResult = notification;
28             StringBuilder build = new StringBuilder();
29             build.append(
30                     "Received '" + notification.getNotificationType() + "' StubPce notification " + "from service '"
31                             + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
32             build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
33             if (notification.getStatus() == RpcStatusEx.Successful && notification.getNotificationType()
34                     .getIntValue() == ServicePathNotificationTypes.PathComputationRequest.getIntValue()) {
35                 build.append(" PathDescription : " + notification.getPathDescription().toString());
36                 /*
37                  * switch (action.getIntValue()) { case 1: //service-create case
38                  * 3: //service-delete case 8: //service-reconfigure case 9:
39                  * //service-restoration case 10://service-reversion case
40                  * 11://service-reroute break;
41                  *
42                  * default: break; }
43                  */
44             }
45
46             LOG.info(build.toString());
47         } else {
48             LOG.info("ServicePathRpcResult already wired !");
49         }
50     }
51
52     @Deprecated
53     private Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
54         Boolean result = true;
55         if (servicePathRpcResult == null) {
56             result = false;
57         } else {
58             if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
59                 result = false;
60             }
61             if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
62                 result = false;
63             }
64             if (servicePathRpcResult.getStatus() != notification.getStatus()) {
65                 result = false;
66             }
67             if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
68                 result = false;
69             }
70         }
71         return result;
72     }
73
74 }