Networkmodel class renaming
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / listeners / ServiceHandlerListener.java
1 /*
2  * Copyright © 2020 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
9 package org.opendaylight.transportpce.networkmodel.listeners;
10
11 import org.opendaylight.transportpce.networkmodel.service.FrequenciesService;
12 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.ServiceRpcResultSh;
13 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.TransportpceServicehandlerListener;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceNotificationTypes;
15 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.RpcStatusEx;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class ServiceHandlerListener implements TransportpceServicehandlerListener {
20     private static final Logger LOG = LoggerFactory.getLogger(ServiceHandlerListener.class);
21     private final FrequenciesService service;
22
23     public ServiceHandlerListener(FrequenciesService service) {
24         LOG.info("Init service handler listener for network");
25         this.service = service;
26     }
27
28     @Override
29     public void onServiceRpcResultSh(ServiceRpcResultSh notification) {
30         if (notification.getStatus() != RpcStatusEx.Successful) {
31             LOG.info("RpcStatusEx of notification not equals successful. Nothing to do for notification {}",
32                     notification);
33             return;
34         }
35         ServiceNotificationTypes notificationType = notification.getNotificationType();
36         if (notificationType == null) {
37             LOG.warn("No information about the type of the notification for {}", notification);
38             return;
39         }
40         switch (notificationType) {
41             case ServiceCreateResult:
42             case ServiceReconfigureResult:
43             case ServiceRestorationResult:
44                 LOG.info("Service creation or reconfiguration or restoration notification received {}", notification);
45                 onServiceCreation(notification);
46                 break;
47             case ServiceDeleteResult:
48                 LOG.info("Service delete notification received {}", notification);
49                 onServiceDeletion(notification);
50                 break;
51             default:
52                 LOG.warn("This type of notification is not managed at this time {} for notification {}",
53                         notificationType, notification);
54                 break;
55
56         }
57     }
58
59     /**
60      * Allocate wavelength in topology.
61      * @param notification ServiceRpcResultSh
62      */
63     private void onServiceCreation(ServiceRpcResultSh notification) {
64         if (notification.getAToZDirection() != null || notification.getZToADirection() != null) {
65             LOG.info("Update topology with used frequency by service {}", notification.getServiceName());
66             service.allocateFrequencies(notification.getAToZDirection(), notification.getZToADirection());
67         }
68     }
69
70     /**
71      * Release wavelength in topology.
72      * @param notification ServiceRpcResultSh
73      */
74     private void onServiceDeletion(ServiceRpcResultSh notification) {
75         if (notification.getAToZDirection() != null || notification.getZToADirection() != null) {
76             LOG.info("Update topology with no more used frequency by deleted service {}",
77                     notification.getServiceName());
78             service.releaseFrequencies(notification.getAToZDirection(), notification.getZToADirection());
79         }
80     }
81
82 }