remove dead code pointed out by sonar
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / openroadminterfaces / OpenRoadmInterfacesImpl.java
1 /*
2  * Copyright © 2017 AT&T 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.common.openroadminterfaces;
10
11 import static org.opendaylight.transportpce.common.StringConstants.OPENROADM_DEVICE_VERSION_1_2_1;
12 import static org.opendaylight.transportpce.common.StringConstants.OPENROADM_DEVICE_VERSION_2_2_1;
13
14 import java.util.Optional;
15 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
16 import org.opendaylight.transportpce.common.mapping.MappingUtils;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceBuilder;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21
22 public class OpenRoadmInterfacesImpl implements OpenRoadmInterfaces {
23
24     private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmInterfacesImpl.class);
25
26     OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
27     OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221;
28     MappingUtils mappingUtils;
29
30     public OpenRoadmInterfacesImpl(DeviceTransactionManager deviceTransactionManager, MappingUtils mappingUtils,
31                                    OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121,
32                                    OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221) {
33         this.mappingUtils = mappingUtils;
34         this.openRoadmInterfacesImpl121 = openRoadmInterfacesImpl121;
35         this.openRoadmInterfacesImpl221 = openRoadmInterfacesImpl221;
36     }
37
38     @Override
39     public <T> void postInterface(String nodeId, T ifBuilder) throws OpenRoadmInterfaceException {
40
41         String openRoadmVersion = mappingUtils.getOpenRoadmVersion(nodeId);
42         if (openRoadmVersion.equals(OPENROADM_DEVICE_VERSION_1_2_1)) {
43             LOG.info("postInterface for 1.2.1 device {}", nodeId);
44             InterfaceBuilder ifBuilder121 = convertInstanceOfInterface(ifBuilder, InterfaceBuilder.class);
45             openRoadmInterfacesImpl121.postInterface(nodeId,ifBuilder121);
46         }
47         else if (openRoadmVersion.equals(OPENROADM_DEVICE_VERSION_2_2_1)) {
48             LOG.info("postInterface for 2.2.1 device {}", nodeId);
49             org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceBuilder
50                 ifBuilder22 = convertInstanceOfInterface(ifBuilder, org.opendaylight.yang.gen.v1.http.org.openroadm
51                 .device.rev181019.interfaces.grp.InterfaceBuilder.class);
52             openRoadmInterfacesImpl221.postInterface(nodeId,ifBuilder22);
53         }
54     }
55
56     @Override
57     public <T> Optional<T>  getInterface(String nodeId, String interfaceName) throws OpenRoadmInterfaceException {
58
59         String openRoadmVersion = mappingUtils.getOpenRoadmVersion(nodeId);
60         LOG.info("Interface get request received for node {} with version {}",nodeId,openRoadmVersion);
61         if (openRoadmVersion.equals(OPENROADM_DEVICE_VERSION_1_2_1)) {
62             LOG.info("getInterface for 1.2.1 device {}", nodeId);
63             return (Optional<T>) openRoadmInterfacesImpl121.getInterface(nodeId,interfaceName);
64         }
65         else if (openRoadmVersion.equals(OPENROADM_DEVICE_VERSION_2_2_1)) {
66             LOG.info("getInterface for 2.2.1 device {}", nodeId);
67             return (Optional<T>) openRoadmInterfacesImpl221.getInterface(nodeId,interfaceName);
68         }
69         return null;
70     }
71
72     @Override
73     public void deleteInterface(String nodeId, String interfaceName)
74         throws OpenRoadmInterfaceException {
75
76         String openRoadmVersion = mappingUtils.getOpenRoadmVersion(nodeId);
77         LOG.info("Interface delete request received for node {} with version {}",nodeId,openRoadmVersion);
78         if (openRoadmVersion.equals(OPENROADM_DEVICE_VERSION_1_2_1)) {
79             LOG.info("Device Version is 1.2.1");
80             openRoadmInterfacesImpl121.deleteInterface(nodeId,interfaceName);
81         }
82         else if (openRoadmVersion.equals(OPENROADM_DEVICE_VERSION_2_2_1)) {
83             openRoadmInterfacesImpl221.deleteInterface(nodeId,interfaceName);
84         }
85     }
86
87     @Override
88     public void postEquipmentState(String nodeId, String circuitPackName, boolean activate)
89         throws OpenRoadmInterfaceException {
90         String openRoadmVersion = mappingUtils.getOpenRoadmVersion(nodeId);
91
92         LOG.info("Request received for node {} with version {} to change equipment-state of cp {}.",
93             nodeId,openRoadmVersion, circuitPackName);
94         if (openRoadmVersion.equals(OPENROADM_DEVICE_VERSION_1_2_1)) {
95             openRoadmInterfacesImpl121.postEquipmentState(nodeId, circuitPackName, activate);
96         }
97         else if (openRoadmVersion.equals(OPENROADM_DEVICE_VERSION_2_2_1)) {
98             openRoadmInterfacesImpl221.postEquipmentState(nodeId, circuitPackName, activate);
99         }
100
101     }
102
103     private <T> T convertInstanceOfInterface(Object object, Class<T> classToCast) {
104         try {
105             return classToCast.cast(object);
106         } catch (ClassCastException e) {
107             return null;
108         }
109     }
110 }