2 * Copyright © 2017 AT&T 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
9 package org.opendaylight.transportpce.common.openroadminterfaces;
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;
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;
22 public class OpenRoadmInterfacesImpl implements OpenRoadmInterfaces {
24 private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmInterfacesImpl.class);
26 OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
27 OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221;
28 MappingUtils mappingUtils;
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;
39 public <T> void postInterface(String nodeId, T ifBuilder) throws OpenRoadmInterfaceException {
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);
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);
57 public <T> Optional<T> getInterface(String nodeId, String interfaceName) throws OpenRoadmInterfaceException {
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);
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);
73 public void deleteInterface(String nodeId, String interfaceName)
74 throws OpenRoadmInterfaceException {
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);
82 else if (openRoadmVersion.equals(OPENROADM_DEVICE_VERSION_2_2_1)) {
83 openRoadmInterfacesImpl221.deleteInterface(nodeId,interfaceName);
88 public void postEquipmentState(String nodeId, String circuitPackName, boolean activate)
89 throws OpenRoadmInterfaceException {
90 String openRoadmVersion = mappingUtils.getOpenRoadmVersion(nodeId);
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);
97 else if (openRoadmVersion.equals(OPENROADM_DEVICE_VERSION_2_2_1)) {
98 openRoadmInterfacesImpl221.postEquipmentState(nodeId, circuitPackName, activate);
103 private <T> T convertInstanceOfInterface(Object object, Class<T> classToCast) {
105 return classToCast.cast(object);
106 } catch (ClassCastException e) {