From 7ae2c86917502cc945e765fdafe5cea7e424abb2 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Wed, 1 Aug 2018 16:37:57 +0200 Subject: [PATCH] Remove the inventory feature The inventory feature needs to be rethought and also requires an external DB that will not be shipped in the formal release. Change-Id: I1eae9a429592151bc1faedb3473f9029b9dfc800 Signed-off-by: guillaume.lambert --- features/features-transportpce/pom.xml | 7 - features/odl-transportpce-inventory/pom.xml | 96 ------- .../src/main/feature/feature.xml | 14 - .../org.opendaylight.transportpce.job.cfg | 6 - .../org.ops4j.datasource-transporpce.cfg | 6 - features/pom.xml | 1 - inventory/pom.xml | 82 ------ .../inventory/DeviceInventory.java | 109 -------- .../transportpce/inventory/INode.java | 254 ----------------- .../inventory/ListenerProvider.java | 87 ------ .../inventory/dto/InvDevInfo.java | 256 ------------------ .../job/PeriodicDeviceBackupJob.java | 247 ----------------- .../listener/ClliNetworkChangeListener.java | 26 -- .../inventory/listener/DeviceListener.java | 146 ---------- .../OverlayNetworkChangeListener.java | 26 -- .../inventory/listener/ServiceListener.java | 160 ----------- .../UnderlayNetworkChangeListener.java | 26 -- .../transportpce/inventory/query/Queries.java | 132 --------- .../inventory/query/QueryUtils.java | 205 -------------- .../inventory/query/StatementBuilder.java | 48 ---- .../inventory/utils/StringUtils.java | 80 ------ .../blueprint/inventory-blueprint.xml | 65 ----- pom.xml | 1 - 23 files changed, 2080 deletions(-) delete mode 100644 features/odl-transportpce-inventory/pom.xml delete mode 100644 features/odl-transportpce-inventory/src/main/feature/feature.xml delete mode 100644 features/odl-transportpce-inventory/src/main/resources/org.opendaylight.transportpce.job.cfg delete mode 100644 features/odl-transportpce-inventory/src/main/resources/org.ops4j.datasource-transporpce.cfg delete mode 100644 inventory/pom.xml delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/DeviceInventory.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/INode.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/ListenerProvider.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/dto/InvDevInfo.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/job/PeriodicDeviceBackupJob.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/ClliNetworkChangeListener.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/OverlayNetworkChangeListener.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/ServiceListener.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/UnderlayNetworkChangeListener.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/query/Queries.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/query/QueryUtils.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/query/StatementBuilder.java delete mode 100644 inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/StringUtils.java delete mode 100644 inventory/src/main/resources/org/opendaylight/blueprint/inventory-blueprint.xml diff --git a/features/features-transportpce/pom.xml b/features/features-transportpce/pom.xml index e05558d05..0b995d0b2 100644 --- a/features/features-transportpce/pom.xml +++ b/features/features-transportpce/pom.xml @@ -50,12 +50,5 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL features xml - diff --git a/features/odl-transportpce-inventory/pom.xml b/features/odl-transportpce-inventory/pom.xml deleted file mode 100644 index c7d527a16..000000000 --- a/features/odl-transportpce-inventory/pom.xml +++ /dev/null @@ -1,96 +0,0 @@ - - - - 4.0.0 - - - org.opendaylight.odlparent - single-feature-parent - 3.1.2 - - - - org.opendaylight.transportpce - odl-transportpce-inventory - 0.2.0-SNAPSHOT - feature - - - localhost:3306 - tpce - root - root - data/transportpce/devicebackup - - 600 - - true - - - OpenDaylight :: transportpce :: Inventory - - - org.opendaylight.transportpce - transportpce-inventory - ${project.version} - - - - - - - maven-resources-plugin - - - copy-resources - validate - - copy-resources - - - ${basedir}/target/resources - - - - src/main/resources - - true - - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-db-artifact - package - - attach-artifact - - - - - target/resources/org.ops4j.datasource-transporpce.cfg - cfg - datasource - - - target/resources/org.opendaylight.transportpce.job.cfg - cfg - config - - - - - - - - - diff --git a/features/odl-transportpce-inventory/src/main/feature/feature.xml b/features/odl-transportpce-inventory/src/main/feature/feature.xml deleted file mode 100644 index f95a75539..000000000 --- a/features/odl-transportpce-inventory/src/main/feature/feature.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - scheduler - pax-jdbc-mysql - pax-jdbc-pool-dbcp2 - - mvn:${project.groupId}/${project.artifactId}/${project.version}/cfg/datasource - - - mvn:${project.groupId}/${project.artifactId}/${project.version}/cfg/config - - - \ No newline at end of file diff --git a/features/odl-transportpce-inventory/src/main/resources/org.opendaylight.transportpce.job.cfg b/features/odl-transportpce-inventory/src/main/resources/org.opendaylight.transportpce.job.cfg deleted file mode 100644 index c3505840d..000000000 --- a/features/odl-transportpce-inventory/src/main/resources/org.opendaylight.transportpce.job.cfg +++ /dev/null @@ -1,6 +0,0 @@ -#folder where backup files are stored -deviceBackupFolder=${transporpce.device.backup.folder} -#prefix for the generated files -deviceBackupPrefix=${transporpce.device.backup.prefix} -#period of storing the device info is seconds -deviceBackupPeriod=${transporpce.device.backup.period} diff --git a/features/odl-transportpce-inventory/src/main/resources/org.ops4j.datasource-transporpce.cfg b/features/odl-transportpce-inventory/src/main/resources/org.ops4j.datasource-transporpce.cfg deleted file mode 100644 index c10ae34fb..000000000 --- a/features/odl-transportpce-inventory/src/main/resources/org.ops4j.datasource-transporpce.cfg +++ /dev/null @@ -1,6 +0,0 @@ -osgi.jdbc.driver.name=mysql -url=jdbc:mysql://${transportpce.db.host}/${transportpce.db.database}?useUnicode=true&characterEncoding=utf8 -pool=dbcp2 -user=${transportpce.db.username} -password=${transportpce.db.password} -dataSourceName=transportpce diff --git a/features/pom.xml b/features/pom.xml index 23242338a..fed6f17b9 100644 --- a/features/pom.xml +++ b/features/pom.xml @@ -28,7 +28,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL odl-transportpce-ordmodels odl-transportpce-stubmodels odl-transportpce - odl-transportpce-inventory diff --git a/inventory/pom.xml b/inventory/pom.xml deleted file mode 100644 index 0539a2062..000000000 --- a/inventory/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - 4.0.0 - - - org.opendaylight.odlparent - bundle-parent - 3.1.2 - - - - org.opendaylight.transportpce - transportpce-inventory - 0.2.0-SNAPSHOT - bundle - - - - - org.opendaylight.controller - mdsal-artifacts - 1.8.0-SNAPSHOT - import - pom - - - org.opendaylight.netconf - netconf-artifacts - 1.5.0-SNAPSHOT - import - pom - - - - - - - ${project.groupId} - transportpce-api - ${project.version} - - - ${project.groupId}.ordmodels - transportpce-ordmodels-device - ${project.version} - - - ${project.groupId} - transportpce-common - ${project.version} - - - ${project.groupId} - transportpce-renderer - ${project.version} - - - org.opendaylight.controller.model - model-topology - - - org.opendaylight.netconf - sal-netconf-connector - - - com.fasterxml.jackson.core - jackson-databind - - - org.apache.karaf.scheduler - org.apache.karaf.scheduler.core - ${karaf.version} - provided - - - - diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/DeviceInventory.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/DeviceInventory.java deleted file mode 100644 index 63e0d41cb..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/DeviceInventory.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.inventory; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Optional; -import java.util.concurrent.ExecutionException; -import java.util.regex.Pattern; - -import javax.sql.DataSource; - -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.transportpce.common.Timeouts; -import org.opendaylight.transportpce.common.device.DeviceTransactionManager; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DeviceInventory { - private static final String INSERT_ALARM_STRING = - "insert into inv_alarm_info(nodeid, probablecause, direction,extension,location," - + "notificationid,type,raisetime,severity,circuitid,circuitpack,connection,degree,iface," - + "internallink,physicallink,service,shelf,sharedriskgroup,port,portcircuitpack, create_date, update_date) " - + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - - private static final Logger LOG = LoggerFactory.getLogger(DeviceInventory.class); - - private final DataSource dataSource; - private final INode inode; - private final DeviceTransactionManager deviceTransactionManager; - - public DeviceInventory(DataSource dataSource, INode inode, - DeviceTransactionManager deviceTransactionManager) { - this.dataSource = dataSource; - this.inode = inode; - this.deviceTransactionManager = deviceTransactionManager; - } - - public void init() { - LOG.info("Initializing {}", DeviceInventory.class.getName()); - } - - public void initializeDevice(String deviceId) throws InterruptedException, ExecutionException { - InstanceIdentifier infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class); - Optional infoOpt = - this.deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.OPERATIONAL, infoIID, - Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); - - Info deviceInfo; - if (infoOpt.isPresent()) { - deviceInfo = infoOpt.get(); - } else { - LOG.warn("Could not get device info from DataBrooker"); - return; - } - LOG.info("Creating Device Inventory {}", deviceInfo); - if (!this.inode.nodeExists(deviceId)) { - LOG.info("Adding node {} to inventory", deviceId); - this.inode.addNode(deviceInfo); - this.inode.getRoadmShelves(deviceId); - this.inode.getCircuitPacks(deviceId); - } - } - - /** - * Stores the alarm into DB using {@link PreparedStatement}. - * - * @param alarmString an alarm string - * @return number of rows inserted - */ - public int storeAlarm(String alarmString) { - String delimiter = "|"; - String[] splitAlarmString = alarmString.split(Pattern.quote(delimiter)); - int count = 0; - try (Connection connection = this.dataSource.getConnection(); - PreparedStatement statement = connection.prepareStatement(INSERT_ALARM_STRING)) { - LOG.debug("Inserting prepared stmt for {} query", INSERT_ALARM_STRING); - SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - java.util.Date startTimetamp = new Date(); - String startTimetampStr = simpleDate.format(startTimetamp); - - for (int i = 0; i < 21; i++) { - String value = (splitAlarmString.length >= (i + 1)) ? splitAlarmString[i] : ""; - LOG.debug("Setting parameter {}, to {} in the insert alarm query", i + 1, value); - statement.setString(i + 1, value); - } - statement.setString(22, startTimetampStr); - statement.setString(23, startTimetampStr); - LOG.debug("Setting current time and edited time to {}", startTimetampStr); - count = statement.executeUpdate(); - LOG.debug("Statment {}, returned {}", INSERT_ALARM_STRING, count); - statement.clearParameters(); - } catch (SQLException e) { - LOG.error(e.getMessage(), e); - } - return count; - } -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode.java deleted file mode 100644 index 37c9ce7e7..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/INode.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.inventory; - -import static org.opendaylight.transportpce.inventory.utils.StringUtils.getCurrentTimestamp; -import static org.opendaylight.transportpce.inventory.utils.StringUtils.prepareDashString; -import static org.opendaylight.transportpce.inventory.utils.StringUtils.prepareEmptyString; - -import com.google.common.base.Preconditions; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.concurrent.ExecutionException; -import javax.sql.DataSource; - -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.transportpce.common.Timeouts; -import org.opendaylight.transportpce.common.device.DeviceTransactionManager; -import org.opendaylight.transportpce.inventory.query.Queries; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.Slots; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.Shelves; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class INode { - private static final Logger LOG = LoggerFactory.getLogger(INode.class); - - private final DataSource dataSource; - private final DeviceTransactionManager deviceTransactionManager; - - public INode(DataSource dataSource, DeviceTransactionManager deviceTransactionManager) { - this.dataSource = dataSource; - this.deviceTransactionManager = deviceTransactionManager; - } - - public boolean addNode(Info deviceInfo) { - boolean sqlResult = false; - String query = Queries.getQuery().deviceInfoInsert().get(); - LOG.debug("Running {} query ", query); - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement(query)) { - String[] prepareParameters = prepareDeviceInfoParameters(deviceInfo); - for (int i = 0; i < prepareParameters.length; i++) { - LOG.debug("Parameter {} has value {}", i + 1, prepareParameters[i]); - preparedStatement.setString(i + 1, prepareParameters[i]); - } - int executeUpdate = preparedStatement.executeUpdate(); - LOG.info("#{} entries were added", executeUpdate); - sqlResult = true; - } catch (SQLException e) { - LOG.error(e.getMessage(), e); - } - return sqlResult; - } - - public boolean nodeExists(String nodeId) { - String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?"; - int nodeExists = 0; - LOG.info("Checking if {} exists in DB", nodeId); - try (Connection connection = dataSource.getConnection(); - PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) { - preparedStmt.setString(1, nodeId); - try (ResultSet rs = preparedStmt.executeQuery()) { - while (rs.next()) { - nodeExists = rs.getInt("node_exists"); - LOG.debug("Found {} devices matching {}", nodeExists, nodeId); - } - } - } catch (SQLException e) { - LOG.error(e.getMessage(), e); - } - return nodeExists == 0 ? false : true; - } - - public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException { - InstanceIdentifier deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class); - java.util.Optional deviceObject = deviceTransactionManager.getDataFromDevice(nodeId, - LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT, - Timeouts.DEVICE_READ_TIMEOUT_UNIT); - - LOG.info("Shelves size {}", deviceObject.get().getShelves().size()); - try (Connection connection = dataSource.getConnection()) { - Preconditions.checkNotNull(connection); - for (int i = 0; i < deviceObject.get().getShelves().size(); i++) { - Shelves shelve = deviceObject.get().getShelves().get(i); - String shelfName = shelve.getShelfName(); - - LOG.info("Getting Shelve Details of {}", shelfName); - LOG.info("Slot Size {} ", shelve.getSlots().size()); - - persistShelveSlots(nodeId, shelve, connection); - - persistShelves(nodeId, connection, shelve); - } - } catch (SQLException e1) { - LOG.error(e1.getMessage(), e1); - } - } - - public void getCircuitPacks(String nodeId) throws InterruptedException, ExecutionException { - InstanceIdentifier deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class); - java.util.Optional deviceObject = - deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID, - Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); - if (!deviceObject.isPresent()) { - LOG.warn("Device object {} was not found", nodeId); - return; - } - LOG.info("Circuit pack size {}", deviceObject.get().getCircuitPacks().size()); - - try (Connection connection = dataSource.getConnection()) { - Preconditions.checkNotNull(connection); - for (int i = 0; i < deviceObject.get().getCircuitPacks().size(); i++) { - CircuitPacks cp = deviceObject.get().getCircuitPacks().get(i); - - if (cp.getCpSlots() != null) { - persistCircuitPacksSlots(nodeId, cp, connection); - } - LOG.info("Everything {}", cp); - LOG.info("CP is {}", cp); - - persistPorts(cp, connection); - - persistCircuitPacks(nodeId, connection, cp); - } - } catch (SQLException e1) { - LOG.error(e1.getMessage(), e1); - } - } - - private void persistCircuitPacks(String nodeId, Connection connection, CircuitPacks cp) { - String[] parameters = prepareCircuitPacksParameters(nodeId, cp); - String query = Queries.getQuery().deviceCircuitPackInsert().get(); - try (PreparedStatement stmt = connection.prepareStatement(query)) { - for (int j = 0; j < parameters.length; j++) { - stmt.setString(j + 1, parameters[j]); - } - stmt.execute(); - stmt.clearParameters(); - } catch (SQLException e) { - LOG.error(e.getMessage(), e); - } - } - - private void persistShelves(String nodeId, Connection connection, Shelves shelve) { - String[] shelvesParameter = prepareShelvesParameters(nodeId, shelve); - String query = Queries.getQuery().deviceShelfInsert().get(); - try (PreparedStatement preparedStmt = connection.prepareStatement(query)) { - for (int j = 0; j < shelvesParameter.length; j++) { - preparedStmt.setString(j + 1, shelvesParameter[j]); - } - preparedStmt.execute(); - preparedStmt.clearParameters(); - } catch (SQLException e) { - LOG.error(e.getMessage(), e); - } - } - - private void persistShelveSlots(String nodeId, Shelves shelves, Connection connection) { - String startTimetampStr = getCurrentTimestamp(); - for (int i = 0; i < shelves.getSlots().size(); i++) { - Slots slot = shelves.getSlots().get(i); - LOG.info("Getting Slot Details of {}", slot.getSlotName()); - String[] parameters = new String[] {nodeId, shelves.getShelfName(), slot.getSlotName(), slot.getLabel(), - slot.getProvisionedCircuitPack(), startTimetampStr, startTimetampStr}; - String query = Queries.getQuery().deviceShelfSlotInsert().get(); - try (PreparedStatement stmt = connection.prepareStatement(query)) { - for (int j = 0; j < parameters.length; j++) { - stmt.setString(j + 1, parameters[j]); - } - stmt.execute(); - stmt.clearParameters(); - } catch (SQLException e) { - LOG.error(e.getMessage(), e); - } - } - } - - private void persistCircuitPacksSlots(String nodeId, CircuitPacks circuitPacks, Connection connection) { - LOG.warn("CP slots are not persisted yet"); - } - - private void persistPorts(CircuitPacks circuitPacks, Connection connection) { - LOG.warn("Ports are not persisted yet"); - } - - - /** - * Prepares parameters for device insert query. - * - * @param deviceInfo the device Info - * @return String[] a string - */ - private static String[] prepareDeviceInfoParameters(Info deviceInfo) { - String startTimetampStr = getCurrentTimestamp(); - - return new String[] {prepareDashString(deviceInfo.getNodeId()), prepareDashString(deviceInfo.getNodeNumber()), - prepareDashString(deviceInfo.getNodeType().getName()), prepareDashString(deviceInfo.getClli()), - prepareDashString(deviceInfo.getVendor()), prepareDashString(deviceInfo.getModel()), - prepareDashString(deviceInfo.getSerialId()), prepareDashString(deviceInfo.getPrefixLength()), - prepareDashString(deviceInfo.getDefaultGateway()), prepareDashString(deviceInfo.getSource().getName()), - prepareDashString(deviceInfo.getCurrentIpAddress()), - prepareDashString(deviceInfo.getCurrentPrefixLength()), - prepareDashString(deviceInfo.getDefaultGateway()), - prepareDashString(deviceInfo.getMacAddress().getValue()), - prepareDashString(deviceInfo.getSoftwareVersion()), prepareDashString(deviceInfo.getTemplate()), - prepareDashString(deviceInfo.getCurrentDatetime()), - deviceInfo.getGeoLocation() != null ? prepareDashString(deviceInfo.getGeoLocation().getLatitude()) : "", - deviceInfo.getGeoLocation() != null ? prepareDashString(deviceInfo.getGeoLocation().getLongitude()) : "", - prepareDashString(deviceInfo.getMaxDegrees()), prepareDashString(deviceInfo.getMaxSrgs()), startTimetampStr, - startTimetampStr}; - } - - /** - * Prepares parameters for shelves. - * - * @param nodeId the node ID - * @param shelve the shelves - * @return String[] a string - */ - private static String[] prepareShelvesParameters(String nodeId, Shelves shelve) { - String startTimestamp = getCurrentTimestamp(); - - return new String[] {nodeId, shelve.getShelfName(), shelve.getShelfType(), shelve.getRack(), - shelve.getShelfPosition(), prepareEmptyString(shelve.getAdministrativeState()), shelve.getVendor(), - shelve.getModel(), shelve.getSerialId(), shelve.getType(), shelve.getProductCode(), - prepareEmptyString(shelve.getManufactureDate()), shelve.getClei(), shelve.getHardwareVersion(), - prepareEmptyString(shelve.getOperationalState()), prepareEmptyString(shelve.getEquipmentState()), - prepareEmptyString(shelve.getDueDate()), startTimestamp, startTimestamp}; - } - - private static String[] prepareCircuitPacksParameters(String nodeId, CircuitPacks cpack) { - return new String[] {nodeId, cpack.getCircuitPackName(), cpack.getCircuitPackType(), - cpack.getCircuitPackProductCode(), prepareEmptyString(cpack.getAdministrativeState()), - cpack.getVendor(), cpack.getModel(), cpack.getSerialId(), cpack.getType(), cpack.getProductCode(), - prepareEmptyString(cpack.getManufactureDate()), cpack.getClei(), cpack.getHardwareVersion(), - prepareEmptyString(cpack.getOperationalState()), prepareEmptyString(cpack.getEquipmentState()), - cpack.getCircuitPackMode(), cpack.getShelf(), cpack.getSlot(), cpack.getSubSlot(), - cpack.getCircuitPackCategory().getType().getName(), cpack.getCircuitPackCategory().getExtension(), - prepareEmptyString(cpack.getDueDate()), cpack.getParentCircuitPack().getCircuitPackName(), - cpack.getParentCircuitPack().getCpSlotName()}; - } -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/ListenerProvider.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/ListenerProvider.java deleted file mode 100644 index 0bfa50381..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/ListenerProvider.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.inventory; - -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; -import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.transportpce.common.InstanceIdentifiers; -import org.opendaylight.transportpce.inventory.listener.ClliNetworkChangeListener; -import org.opendaylight.transportpce.inventory.listener.DeviceListener; -import org.opendaylight.transportpce.inventory.listener.OverlayNetworkChangeListener; -import org.opendaylight.transportpce.inventory.listener.ServiceListener; -import org.opendaylight.transportpce.inventory.listener.UnderlayNetworkChangeListener; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * {@link ListenerProvider} registers {@link DataTreeChangeListener} for each - * network layer. - * - */ -public class ListenerProvider { - - private static final Logger LOG = LoggerFactory.getLogger(ListenerProvider.class); - - private final DataBroker dataBroker; - private final OverlayNetworkChangeListener overlayNetworkListener; - private final UnderlayNetworkChangeListener underlayNetworkListener; - private final ClliNetworkChangeListener clliNetworkChangeListener; - private final ServiceListener serviceListener; - private final DeviceListener deviceListener; - - /** - * Constructor invoked by blueprint injects all dependencies. - * - * @param dataBroker the databroker - * @param overlayNetworkListener the overlay network listener - * @param underlayNetworkListener the underlay network listener - * @param clliNetworkChangeListener the CLLI network changes listener - * @param serviceListener the service listener - * @param deviceListener the device listener - */ - public ListenerProvider(DataBroker dataBroker, OverlayNetworkChangeListener overlayNetworkListener, - UnderlayNetworkChangeListener underlayNetworkListener, ClliNetworkChangeListener clliNetworkChangeListener, - ServiceListener serviceListener, DeviceListener deviceListener) { - this.dataBroker = dataBroker; - this.overlayNetworkListener = overlayNetworkListener; - this.underlayNetworkListener = underlayNetworkListener; - this.clliNetworkChangeListener = clliNetworkChangeListener; - this.serviceListener = serviceListener; - this.deviceListener = deviceListener; - } - - /** - * Invoked by blueprint, registers the listeners. - */ - public void initialize() { - LOG.debug("Registering listeners..."); - dataBroker.registerDataTreeChangeListener( - new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.OVERLAY_NETWORK_II), - overlayNetworkListener); - LOG.info("Overlay network change listener was successfully registered"); - dataBroker.registerDataTreeChangeListener( - new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.UNDERLAY_NETWORK_II), - underlayNetworkListener); - LOG.info("Underlay network change listener was successfully registered"); - dataBroker.registerDataTreeChangeListener( - new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, InstanceIdentifiers.CLLI_NETWORK_II), - clliNetworkChangeListener); - LOG.info("CLLI network change listener was successfully registered"); - dataBroker.registerDataTreeChangeListener( - new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, ServiceListener.SERVICES_II), - serviceListener); - LOG.info("Service path listener was successfully registered"); - dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, - InstanceIdentifiers.NETCONF_TOPOLOGY_II.child(Node.class)), deviceListener); - LOG.info("Device change listener was successfully registered"); - } - -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/dto/InvDevInfo.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/dto/InvDevInfo.java deleted file mode 100644 index c528f0e23..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/dto/InvDevInfo.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.transportpce.inventory.dto; - -public class InvDevInfo { - private String nodeId; - private String nodeNumber; - private String nodeType; - private String clli; - private String vendor; - private String model; - private String serialId; - private String ipAddress; - private String prefixLength; - private String defaultGateway; - private String source; - private String currentIpAddress; - private String currentPrefixLength; - private String currentDefaultGateway; - private String macAddress; - private String softwareVersion; - private String template; - private String currentDatetime; - private String latitude; - private String longitude; - private String maxDegrees; - private String maxSrgs; - private String swVersion; - private String swValidationTimer; - private String activationDateTime; - private String createDate; - private String updateDate; - - - public String getNodeId() { - return this.nodeId; - } - - public void setNode_id(String nodeId) { - this.nodeId = nodeId; - } - - public String getNode_number() { - return this.nodeNumber; - } - - public void setNode_number(String nodeNumber) { - this.nodeNumber = nodeNumber; - } - - public String getNode_type() { - return this.nodeType; - } - - public void setNode_type(String nodeType) { - this.nodeType = nodeType; - } - - public String getClli() { - return this.clli; - } - - public void setClli(String clli) { - this.clli = clli; - } - - public String getVendor() { - return this.vendor; - } - - public void setVendor(String vendor) { - this.vendor = vendor; - } - - public String getModel() { - return this.model; - } - - public void setModel(String model) { - this.model = model; - } - - public String getSerial_id() { - return this.serialId; - } - - public void setSerial_id(String serialId) { - this.serialId = serialId; - } - - public String getIpAddress() { - return this.ipAddress; - } - - public void setIpAddress(String ipAddress) { - this.ipAddress = ipAddress; - } - - public String getPrefix_length() { - return this.prefixLength; - } - - public void setPrefix_length(String prefixLength) { - this.prefixLength = prefixLength; - } - - public String getDefault_gateway() { - return this.defaultGateway; - } - - public void setDefault_gateway(String defaultGateway) { - this.defaultGateway = defaultGateway; - } - - public String getSource() { - return this.source; - } - - public void setSource(String source) { - this.source = source; - } - - public String getCurrent_ipAddress() { - return this.currentIpAddress; - } - - public void setCurrent_ipAddress(String currentIpAddress) { - this.currentIpAddress = currentIpAddress; - } - - public String getCurrent_prefix_length() { - return this.currentPrefixLength; - } - - public void setCurrent_prefix_length(String currentPrefixLength) { - this.currentPrefixLength = currentPrefixLength; - } - - public String getCurrent_default_gateway() { - return this.currentDefaultGateway; - } - - public void setCurrent_default_gateway(String currentDefaultGateway) { - this.currentDefaultGateway = currentDefaultGateway; - } - - public String getMacAddress() { - return this.macAddress; - } - - public void setMacAddress(String macAddress) { - this.macAddress = macAddress; - } - - public String getSoftware_version() { - return this.softwareVersion; - } - - public void setSoftware_version(String softwareVersion) { - this.softwareVersion = softwareVersion; - } - - public String getTemplate() { - return this.template; - } - - public void setTemplate(String template) { - this.template = template; - } - - public String getCurrent_datetime() { - return this.currentDatetime; - } - - public void setCurrent_datetime(String currentDatetime) { - this.currentDatetime = currentDatetime; - } - - public String getLatitude() { - return this.latitude; - } - - public void setLatitude(String latitude) { - this.latitude = latitude; - } - - public String getLongitude() { - return this.longitude; - } - - public void setLongitude(String longitude) { - this.longitude = longitude; - } - - public String getMax_degrees() { - return this.maxDegrees; - } - - public void setMax_degrees(String maxDegrees) { - this.maxDegrees = maxDegrees; - } - - public String getMax_srgs() { - return this.maxSrgs; - } - - public void setMax_srgs(String maxSrgs) { - this.maxSrgs = maxSrgs; - } - - public String getSw_version() { - return this.swVersion; - } - - public void setSw_version(String swVersion) { - this.swVersion = swVersion; - } - - public String getSw_validation_timer() { - return this.swValidationTimer; - } - - public void setSw_validation_timer(String swValidationTimer) { - this.swValidationTimer = swValidationTimer; - } - - public String getActivation_date_time() { - return this.activationDateTime; - } - - public void setActivation_date_time(String activationDateTime) { - this.activationDateTime = activationDateTime; - } - - public String getCreate_date() { - return this.createDate; - } - - public void setCreate_date(String createDate) { - this.createDate = createDate; - } - - public String getUpdate_date() { - return this.updateDate; - } - - public void setUpdate_date(String updateDate) { - this.updateDate = updateDate; - } -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/job/PeriodicDeviceBackupJob.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/job/PeriodicDeviceBackupJob.java deleted file mode 100644 index a97d140c6..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/job/PeriodicDeviceBackupJob.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.transportpce.inventory.job; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Strings; -import com.google.common.io.Files; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Optional; -import java.util.concurrent.ExecutionException; -import org.apache.karaf.scheduler.Job; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.mdsal.dom.api.DOMSchemaService; -import org.opendaylight.transportpce.common.InstanceIdentifiers; -import org.opendaylight.transportpce.common.Timeouts; -import org.opendaylight.transportpce.common.device.DeviceTransactionManager; -import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class which periodically backups the device into a file implements {@link Job} - * interface which is automatically registered via whitboard pattern into karaf - * environment. This job will persist an {@link OrgOpenroadmDevice} capable with - * the models provided in transportpce-models - */ -public class PeriodicDeviceBackupJob implements Runnable { - - private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd_HH-mm-ss-SSS"; - private static final String ORG_OPENROADM_DEVICE = "org-openroadm-device"; - private static final Logger LOG = LoggerFactory.getLogger(PeriodicDeviceBackupJob.class); - - private final DataBroker dataBroker; - private final DeviceTransactionManager deviceTransactionManager; - - private final SchemaContext schemaContext; - private final SimpleDateFormat filenameFormatter; - - /** - * Folder property, where the file is placed. - */ - private String folder; - /** - * Prefix of device file. - */ - private String filePrefix; - - /** - * Constructor with injected fields. - * - * @param dataBroker the datatabroker - * @param domSchemaService the DOM schema service - * @param deviceTransactionManager the device transaction manager - */ - public PeriodicDeviceBackupJob(DataBroker dataBroker, DOMSchemaService domSchemaService, - DeviceTransactionManager deviceTransactionManager) { - this.dataBroker = dataBroker; - this.schemaContext = domSchemaService.getGlobalContext(); - this.deviceTransactionManager = deviceTransactionManager; - this.filenameFormatter = new SimpleDateFormat(TIMESTAMP_FORMAT); - } - - @Override - public void run() { - LOG.info("Running periodical device backup into {}", this.folder); - try { - backupAllDevices(); - } catch (InterruptedException | ExecutionException e) { - LOG.warn("Unable to read netconf topology from the operational datastore", e); - } - } - - /** - * Gets the folder. - * - * @return the folder - */ - public String getFolder() { - return this.folder; - } - - /** - * Sets the folder. - * - * @param folder the folder to set - */ - public void setFolder(String folder) { - this.folder = folder; - } - - /** - * Gets the filePrefix. - * - * @return the filePrefix - */ - public String getFilePrefix() { - return this.filePrefix; - } - - /** - * Sets the filePrefix. - * - * @param filePrefix the filePrefix to set - */ - public void setFilePrefix(String filePrefix) { - this.filePrefix = filePrefix; - } - - /** - * Stores all devices into files. - * - * @throws InterruptedException interrupted exception - * @throws ExecutionException execution exception - */ - private void backupAllDevices() throws InterruptedException, ExecutionException { - ReadOnlyTransaction newReadOnlyTransaction = this.dataBroker.newReadOnlyTransaction(); - Optional topology = newReadOnlyTransaction - .read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifiers.NETCONF_TOPOLOGY_II).get().toJavaUtil(); - if (!topology.isPresent()) { - LOG.warn("Netconf topology was not found in datastore"); - return; - } - - for (Node node : topology.get().getNode()) { - String nodeId = getNodeId(node); - if (Strings.isNullOrEmpty(nodeId)) { - LOG.debug("{} node is not a roadm device"); - continue; - } - storeRoadmDevice(nodeId); - } - } - - /** - * Stores a single ROADM device into a file. - * - * @param nodeId the node ID - */ - private void storeRoadmDevice(String nodeId) { - InstanceIdentifier deviceIi = InstanceIdentifier.create(OrgOpenroadmDevice.class); - Optional deviceObject = - this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIi, - Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); - if (!deviceObject.isPresent()) { - LOG.warn("Device object {} is not present.", nodeId); - return; - } - - // TODO: Serialization should be done via XMLDataObjectConverter when devices use the same model as - // this project - /* - * XMLDataObjectConverter createWithSchemaContext = - * XMLDataObjectConverter.createWithSchemaContext(schemaContext, nodeSerializer); Writer - * writerFromDataObject = createWithSchemaContext.writerFromDataObject(deviceObject.get(), - * OrgOpenroadmDevice.class, createWithSchemaContext.dataContainer()); - */ - StringBuilder serializedDevice = new StringBuilder(); - try { - serializedDevice.append(new ObjectMapper().writeValueAsString(deviceObject.get())); - } catch (JsonProcessingException e1) { - LOG.error(e1.getMessage(), e1); - } - - String prepareFileName = prepareFileName(nodeId); - File parent = new File(this.folder); - if (!parent.exists() && !parent.isDirectory() && !parent.mkdirs()) { - LOG.error("Could not create empty directory {}", this.folder); - throw new IllegalStateException(String.format("Could not create empty directory %s", this.folder)); - } - - File file = new File(parent, this.filePrefix.concat(prepareFileName)); - if (file.exists()) { - throw new IllegalStateException(String.format("The file %s already exists", file)); - } - try { - Files.asCharSink(file, StandardCharsets.UTF_8).write(serializedDevice.toString()); - } catch (IOException e) { - LOG.error("Could not write device backup into file {}", file); - } - } - - private String prepareFileName(String nodeId) { - String format = this.filenameFormatter.format(new Date()); - StringBuilder sb = new StringBuilder(format); - sb.append("__").append(nodeId).append("__").append(".xml"); - return sb.toString(); - } - - /** - * If the {@link Node} in the {@link Topology} is a {@link NetconfNode}, has - * capabilities of {@link PeriodicDeviceBackupJob#ORG_OPENROADM_DEVICE} and the - * key is not null returns the identifier of {@link OrgOpenroadmDevice} node. - * - * @param node inside the {@link Topology} - * @return node key - */ - private static String getNodeId(Node node) { - if (node == null) { - LOG.trace("The node is null"); - return ""; - } - NetconfNode netconfNode = node.augmentation(NetconfNode.class); - if (netconfNode == null) { - LOG.trace("The node {} has not properties of NetconfNode", node); - return ""; - } - if ((netconfNode.getAvailableCapabilities() == null) - || (netconfNode.getAvailableCapabilities().getAvailableCapability() == null)) { - LOG.trace("No available capabilities"); - return ""; - } - long count = netconfNode.getAvailableCapabilities().getAvailableCapability().stream() - .filter(cp -> (cp.getCapability() != null) && cp.getCapability().contains(ORG_OPENROADM_DEVICE)).count(); - if (count < 1) { - LOG.trace("The node {} has not capabilities of OpenROADMDevice", node); - return ""; - } - if ((node.key() == null) || (node.key().getNodeId() == null)) { - LOG.trace("Node {} has invalid key", node); - return ""; - } - if ("controller-config".equalsIgnoreCase(node.key().getNodeId().getValue())) { - LOG.info("Got controller-config instead of roadm-node"); - return ""; - } - return node.key().getNodeId().getValue(); - } - -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/ClliNetworkChangeListener.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/ClliNetworkChangeListener.java deleted file mode 100644 index 41a23ac8d..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/ClliNetworkChangeListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.inventory.listener; - -import java.util.Collection; -import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; -import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.Network; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ClliNetworkChangeListener implements DataTreeChangeListener { - - private static final Logger LOG = LoggerFactory.getLogger(ClliNetworkChangeListener.class); - - @Override - public void onDataTreeChanged(Collection> changes) { - LOG.info("Clli network changed {}", changes); - } - -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java deleted file mode 100644 index daa2b30f7..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/DeviceListener.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.transportpce.inventory.listener; - -import java.util.Collection; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; -import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType; -import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; -import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; -import org.opendaylight.transportpce.common.StringConstants; -import org.opendaylight.transportpce.inventory.DeviceInventory; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class implements the {@link DataTreeChangeListener} on a {@link Node}. This listener should - * be registered on a netconf topology node. - * - */ -public class DeviceListener implements DataTreeChangeListener { - - private static final Logger LOG = LoggerFactory.getLogger(DeviceListener.class); - private final DeviceInventory deviceInventory; - - /** - * Default constructor invoked by blueprint injects {@link DeviceInventory} as a persistence layer. - * - * @param deviceInventory reference to the {@link DeviceInventory} - */ - public DeviceListener(DeviceInventory deviceInventory) { - this.deviceInventory = deviceInventory; - } - - @Override - public void onDataTreeChanged(Collection> changes) { - List> changesWithoutDefaultNetconfNode = getRealDevicesOnly(changes); - for (DataTreeModification device : changesWithoutDefaultNetconfNode) { - String nodeId = device.getRootNode().getDataAfter().key().getNodeId().getValue(); - NetconfNode netconfNode = device.getRootNode().getDataAfter().augmentation(NetconfNode.class); - if (isCreate(device) || isUpdate(device)) { - LOG.info("Node {} was modified", nodeId); - try { - processModifiedSubtree(nodeId, netconfNode); - } catch (InterruptedException | ExecutionException e) { - LOG.error(e.getMessage(), e); - } - } else if (isDelete(device)) { - LOG.info("Node {} was deleted", nodeId); - } - } - } - - /** - * Handles the {@link ModificationType#SUBTREE_MODIFIED} case. If the changed node has - * {@link StringConstants.OPENROADM_DEVICE_MODEL_NAME} capabilities it may be persisted. - * - * @param nodeId device id - * @param netconfNode netconf node - * @throws InterruptedException may be thrown if there is a problem getting the device from - * datastore - * @throws ExecutionException may be thrown if there is a problem getting the device from datastore - */ - private void processModifiedSubtree(String nodeId, NetconfNode netconfNode) - throws InterruptedException, ExecutionException { - NetconfNodeConnectionStatus.ConnectionStatus connectionStatus = netconfNode.getConnectionStatus(); - long count = netconfNode.getAvailableCapabilities().getAvailableCapability().stream() - .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME)).count(); - if (count < 1) { - LOG.info("No {} capable device was found", StringConstants.OPENROADM_DEVICE_MODEL_NAME); - return; - } - if (ConnectionStatus.Connected.equals(connectionStatus)) { - this.deviceInventory.initializeDevice(nodeId); - } else if (ConnectionStatus.Connecting.equals(connectionStatus) - || ConnectionStatus.UnableToConnect.equals(connectionStatus)) { - LOG.info("The device is in {} state", connectionStatus); - } else { - LOG.warn("Invalid connection status {}", connectionStatus); - } - } - - /** - * Filters the {@link StringConstants#DEFAULT_NETCONF_NODEID} nodes from the provided - * {@link Collection}. - * - * @param changes a change - * @return {@code List>} a list of modifcations - */ - private static List> getRealDevicesOnly(Collection> changes) { - return changes.stream() - .filter(change -> ((change.getRootNode().getDataAfter() != null) - && !StringConstants.DEFAULT_NETCONF_NODEID - .equalsIgnoreCase(change.getRootNode().getDataAfter().key().getNodeId().getValue()) - && (change.getRootNode().getDataAfter().augmentation(NetconfNode.class) != null)) - || ((change.getRootNode().getDataBefore() != null) - && !StringConstants.DEFAULT_NETCONF_NODEID.equalsIgnoreCase( - change.getRootNode().getDataBefore().key().getNodeId().getValue()) - && (change.getRootNode().getDataBefore().augmentation(NetconfNode.class) != null) - - )).collect(Collectors.toList()); - } - - /** - * In the filtered collection checks if the change is a new write. - * - * @param change the change - * @return boolean true if the change is a new write - */ - private static boolean isCreate(DataTreeModification change) { - return (change.getRootNode().getDataBefore() == null) && (change.getRootNode().getDataAfter() != null) - && ModificationType.WRITE.equals(change.getRootNode().getModificationType()); - } - - /** - * In the filtered collection checks if the modification is update. - * - * @param change the change - * @return boolean true if the modification is update - */ - private static boolean isUpdate(DataTreeModification change) { - return ModificationType.SUBTREE_MODIFIED.equals(change.getRootNode().getModificationType()); - } - - /** - * In the filtered collection checks if the node was deleted. - * - * @param change the change - * @return boolean true if the node was deleted - */ - private static boolean isDelete(DataTreeModification change) { - return (change.getRootNode().getDataBefore() != null) && (change.getRootNode().getDataAfter() == null) - && ModificationType.DELETE.equals(change.getRootNode().getModificationType()); - } -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/OverlayNetworkChangeListener.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/OverlayNetworkChangeListener.java deleted file mode 100644 index f5acd159e..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/OverlayNetworkChangeListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.inventory.listener; - -import java.util.Collection; -import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; -import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.Network; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class OverlayNetworkChangeListener implements DataTreeChangeListener { - - private static final Logger LOG = LoggerFactory.getLogger(OverlayNetworkChangeListener.class); - - @Override - public void onDataTreeChanged(Collection> changes) { - LOG.info("Overlay network changed {}", changes); - } - -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/ServiceListener.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/ServiceListener.java deleted file mode 100644 index 4c82b9899..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/ServiceListener.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.inventory.listener; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; -import javax.sql.DataSource; -import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType; -import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; -import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; -import org.opendaylight.transportpce.inventory.query.Queries; -import org.opendaylight.transportpce.inventory.query.QueryUtils; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceList; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * {@link ServiceListener} listens on {@link ServiceList} changes. - * - */ -public class ServiceListener implements DataTreeChangeListener { - - private static final Logger LOG = LoggerFactory.getLogger(ServiceListener.class); - public static final InstanceIdentifier SERVICES_II = - InstanceIdentifier.create(ServiceList.class); - /** - * Implementation for the {@link ChangeHandler} stores a newly added {@link Services}. - */ - private static final ChangeHandler CREATE_HANDLER = (services, connection) -> { - try (PreparedStatement stmt = connection.prepareStatement(Queries.getQuery().serviceCreate().get())) { - QueryUtils.setCreateServiceParameters(stmt, services); - stmt.executeUpdate(); - stmt.clearParameters(); - } catch (SQLException e) { - LOG.error("Could not insert service path {}", services); - } - }; - - /** - * Implementation for the {@link ChangeHandler} removes the deleted {@link Services}. - */ - private static final ChangeHandler DELETE_HANDLER = (services, connection) -> { - try (PreparedStatement stmt = connection.prepareStatement(Queries.getQuery().serviceDelete().get())) { - stmt.setString(1, services.getServiceName()); - stmt.executeUpdate(); - stmt.clearParameters(); - } catch (SQLException e) { - LOG.error("Could not delete service path {}", services); - LOG.error(e.getMessage(), e); - } - }; - - private final DataSource dataSource; - - /** - * Default constructor invoked by bluprint injects all required dependencies. - * - * @param dataSource reference for {@link DataSource} - */ - public ServiceListener(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Override - public void onDataTreeChanged(Collection> changes) { - LOG.debug("Service path list changed ..."); - List> createItems = - changes.stream().filter(ServiceListener::writeFilter).collect(Collectors.toList()); - List> deleteItems = - changes.stream().filter(ServiceListener::deleteFilter).collect(Collectors.toList()); - try (Connection connection = dataSource.getConnection()) { - handleModification(createItems, CREATE_HANDLER, connection); - handleModification(deleteItems, DELETE_HANDLER, connection); - } catch (SQLException e) { - LOG.error(e.getMessage(), e); - } - } - - /** - * Handles the change with {@link ChangeHandler}. - * - * @param changeList list of modifications - * @param handleChange concrete implementation of {@link ChangeHandler} - * @param connection {@link DataSource} we don't want to create each time a new connection - */ - private void handleModification(List> changeList, ChangeHandler handleChange, - Connection connection) { - for (DataTreeModification change : changeList) { - ServiceList serviceList = change.getRootNode().getDataAfter(); - for (Services service : serviceList.getServices()) { - handleChange.handleChange(service, connection); - } - } - } - - /** - * Returns the filter for {@link ModificationType#WRITE} type change. - * - * @see #buildFilter(DataTreeModification, ModificationType) - * @param modification write modification object - * @return if the object was created - */ - private static boolean writeFilter(DataTreeModification modification) { - return buildFilter(modification, ModificationType.WRITE); - } - - /** - * Returns the filter for {@link ModificationType#DELETE} type change. - * - * @see #deleteFilter(DataTreeModification) - * @param modification delete modification - * @return if the object was deleted - */ - private static boolean deleteFilter(DataTreeModification modification) { - return buildFilter(modification, ModificationType.DELETE); - } - - /** - * Generalizes the creation of filter used in - * {@link #onDataTreeChanged(Collection)} method. - * - * @param modification a modification - * @param modificationType a modification type - * @return boolean modification status - */ - private static boolean buildFilter(DataTreeModification modification, - ModificationType modificationType) { - return (modification.getRootNode().getDataAfter() != null - && modificationType.equals(modification.getRootNode().getModificationType())); - } - - /** - * ChangeHandler interface is responsible for inserts or deletes in the DB based - * on the implementation. - * - */ - private interface ChangeHandler { - - /** - * Method will handle the changed {@link Services}. - * - * @param services changed object - * @param connection {@link Connection} should be created in the caller method and - * not closed in the implementation - */ - void handleChange(Services services, Connection connection); - } - -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/UnderlayNetworkChangeListener.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/UnderlayNetworkChangeListener.java deleted file mode 100644 index c8937eee3..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/listener/UnderlayNetworkChangeListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.inventory.listener; - -import java.util.Collection; -import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; -import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.Network; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class UnderlayNetworkChangeListener implements DataTreeChangeListener { - - private static final Logger LOG = LoggerFactory.getLogger(UnderlayNetworkChangeListener.class); - - @Override - public void onDataTreeChanged(Collection> changes) { - LOG.info("Underlay network changed {}", changes); - } - -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/Queries.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/Queries.java deleted file mode 100644 index eae4147e5..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/Queries.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.transportpce.inventory.query; - -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; - -public final class Queries { - - private static final String DEVICE_INFO_INSERT = - "INSERT INTO %sinv_dev_info " - + "(node_id, node_number, node_type, clli, vendor, model, serial_id, ipAddress, prefix_length, " - + "default_gateway, source, current_ipAddress, current_prefix_length, current_default_gateway, macAddress, " - + "software_version, template, current_datetime, latitude, longitude, max_degrees, max_srgs, sw_version, " - + "sw_validation_timer, activation_date_time, create_date, update_date) " - + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - - private static final String DEVICE_SHELF_INSERT = - "INSERT INTO %sinv_dev_shelf " - + "(node_id, shelf_name, shelf_type, rack, shelf_position, administrative_state, vendor, model, serial_id, " - + "type, product_code, manufacture_date, clei, hardware_version, operational_state, equipment_state, due_date, " - + "create_date, update_date) " - + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - - private static final String DEVICE_SHELF_SLOT_INSERT = - "INSERT INTO %sinv_dev_shelf_slot " - + "(node_id, shelf_name, slot_name, label, provisioned_circuit_pack, create_date, update_date) " - + "VALUES (?, ?, ?, ?, ?, ?, ?)"; - - private static final String DEVICE_CP_INSERT = - "INSERT INTO %sinv_dev_circuit_pack " - + "(node_id, circuitPackName, circuitPackType, circuitPackProductCode, administrative_state, vendor, model, " - + "serial_id, type, product_code, manufacture_date, clei, hardware_version, operational_state, " - + "equipment_state, shelf, slot, subSlo, cpCatType, extension, due_date, parentCpName, parentCpSlotName) " - + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - - private static final String SERVICE_INSERT = - "INSERT INTO %sinv_ser_main " - + "(service_name, common_id, sdnc_req_header_request_id, sdnc_req_header_rpc_action, " - + "sdnc_req_header_notification_url, sdnc_req_header_request_system_id, connection_type, lifecycle_state, " - + "administrative_state, operational_state, serv_condition, a_end_service_format, a_end_service_rate, " - + "a_end_clli, a_end_node_id, a_end_tx_port_device_name, a_end_tx_port_type, a_end_tx_port_name, " - + "a_end_tx_port_rack, a_end_tx_port_shelf, a_end_tx_port_slot, a_end_tx_port_sub_slot, " - + "a_end_tx_lgx_device_name, a_end_tx_lgx_port_name, a_end_tx_lgx_port_rack, a_end_tx_lgx_port_shelf, " - + "a_end_tx_tail_rnode_id, a_end_tx_xport_cp_name, a_end_tx_xport_port_name, a_end_tx_tail_roadm_port_aid, " - + "a_end_tx_tail_roadm_port_rack_loc, a_end_rx_port_device_name, a_end_rx_port_type, a_end_rx_port_name, " - + "a_end_rx_port_rack, a_end_rx_port_shelf, a_end_rx_port_slot, a_end_rx_port_sub_slot, " - + "a_end_rx_lgx_device_name, a_end_rx_lgx_port_name, a_end_rx_lgx_port_rack, a_end_rx_lgx_port_shelf, " - + "a_end_rx_tail_rnode_id, a_end_rx_xport_cp_name, a_end_rx_xport_port_name, a_end_rx_tail_roadm_port_aid, " - + "a_end_rx_tail_roadm_port_rack_loc, a_end_optic_type, a_end_router_node_id, a_end_router_ip_address, " - + "a_end_router_url, a_end_user_label, z_end_service_format, z_end_service_rate, z_end_clli, z_end_node_id, " - + "z_end_tx_port_device_name, z_end_tx_port_type, z_end_tx_port_name, z_end_tx_port_rack, z_end_tx_port_shelf, " - + "z_end_tx_port_slot, z_end_tx_port_sub_slot, z_end_tx_lgx_device_name, z_end_tx_lgx_port_name, " - + "z_end_tx_lgx_port_rack, z_end_tx_lgx_port_shelf, z_end_tx_tail_rnode_id, z_end_tx_xport_cp_name, " - + "z_end_tx_xport_port_name, z_end_tx_tail_roadm_port_aid, z_end_tx_tail_roadm_port_rack_loc, " - + "z_end_rx_port_device_name, z_end_rx_port_type, z_end_rx_port_name, z_end_rx_port_rack, z_end_rx_port_shelf, " - + "z_end_rx_port_slot, z_end_rx_port_sub_slot, z_end_rx_lgx_device_name, z_end_rx_lgx_port_name, " - + "z_end_rx_lgx_port_rack, z_end_rx_lgx_port_shelf, z_end_rx_tail_rnode_id, z_end_rx_xport_cp_name, " - + "z_end_rx_xport_port_name, z_end_rx_tail_roadm_port_aid, z_end_rx_tail_roadm_port_rack_loc, " - + "z_end_optic_type, z_end_router_node_id, z_end_router_ip_address, z_end_router_url, z_end_user_label, " - + "due_date, end_date, nc_code, nci_code, secondary_nci_code, customer, customer_contact, operator_contact, " - + "latency, fiber_span_srlgs, supp_serv_name, create_date, update_date) " - + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " - + "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " - + "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - - private static final String SERVICE_DELETE = - "DELETE FROM %sinv_ser_main WHERE service_name = ?"; - - private Queries() { - // util class - } - - public static Query getQuery() { - return new Query(); - } - - public static final class Query { - private String sql; - private String schema; - - private Query() { - this.schema = ""; - } - - public Query withSchema(String schema) { - this.schema = schema; - return this; - } - - public Query deviceInfoInsert() { - this.sql = DEVICE_INFO_INSERT; - return this; - } - - public Query deviceShelfInsert() { - this.sql = DEVICE_SHELF_INSERT; - return this; - } - - public Query deviceShelfSlotInsert() { - this.sql = DEVICE_SHELF_SLOT_INSERT; - return this; - } - - public Query deviceCircuitPackInsert() { - this.sql = DEVICE_CP_INSERT; - return this; - } - - public Query serviceCreate() { - this.sql = SERVICE_INSERT; - return this; - } - - public Query serviceDelete() { - this.sql = SERVICE_DELETE; - return this; - } - - public String get() { - Preconditions.checkArgument(!Strings.isNullOrEmpty(this.sql), "No query selected"); - return String.format(this.sql, this.schema.concat(".")); - } - } -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/QueryUtils.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/QueryUtils.java deleted file mode 100644 index 93b146a12..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/QueryUtils.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.inventory.query; - -import static org.opendaylight.transportpce.inventory.utils.StringUtils.getCurrentTimestamp; - -import com.google.common.base.Strings; - -import java.sql.PreparedStatement; -import java.sql.SQLException; - -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceAEnd; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceZEnd; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.Router; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.RxDirection; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.TxDirection; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.Port; -import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services; - -/** - * Query manipulation class. - */ -public final class QueryUtils { - - private QueryUtils() { - // no instance, just static access - } - - /** - * This method modifies the prepared statement for {@link Queries}. - * - * @param stmt the prepared statement - * @param servicePath the service path - * @throws SQLException a SQL exception - */ - public static void setCreateServiceParameters(PreparedStatement stmt, Services servicePath) throws SQLException { - StatementBuilder builder = StatementBuilder.builder(stmt); - builder.setParameter(servicePath.getServiceName()); - builder.setParameter(servicePath.getCommonId()); - - String requestId = ""; - String rpcAction = ""; - String notificationUrl = ""; - String requestSystemId = ""; - - if (servicePath.getSdncRequestHeader() != null) { - requestId = getStringOf(servicePath.getSdncRequestHeader().getRequestId()); - rpcAction = servicePath.getSdncRequestHeader().getRpcAction().getName(); - notificationUrl = servicePath.getSdncRequestHeader().getNotificationUrl(); - requestSystemId = servicePath.getSdncRequestHeader().getRequestSystemId(); - } - builder.setParameter(requestId).setParameter(rpcAction).setParameter(notificationUrl) - .setParameter(requestSystemId); - - String connectionType = ""; - String lifecycleState = ""; - String administrativeState = ""; - String condition = ""; - if (servicePath.getConnectionType() != null) { - connectionType = servicePath.getConnectionType().getName(); - } - if (servicePath.getLifecycleState() != null) { - lifecycleState = servicePath.getLifecycleState().getName(); - } - if (servicePath.getAdministrativeState() != null) { - administrativeState = servicePath.getAdministrativeState().getName(); - } - if (servicePath.getCondition() != null) { - condition = servicePath.getCondition().getName(); - } - // status stuff - builder.setParameter(connectionType); - builder.setParameter(lifecycleState); - builder.setParameter(administrativeState); - builder.setParameter(condition); - - // status stuff - ServiceAEnd serviceAEnd = servicePath.getServiceAEnd(); - builder.setParameter(serviceAEnd.getServiceFormat().getName()).setParameter(serviceAEnd.getServiceRate()) - .setParameter(serviceAEnd.getClli()).setParameter(serviceAEnd.getNodeId()); - - // tx port stuff - Port aendTxDirection = servicePath.getServiceAEnd().getTxDirection().getPort(); - builder.setParameter(aendTxDirection.getPortDeviceName()).setParameter(aendTxDirection.getPortName()) - .setParameter(aendTxDirection.getPortRack()).setParameter(aendTxDirection.getPortShelf()) - .setParameter(aendTxDirection.getPortSlot()).setParameter(aendTxDirection.getPortSubSlot()); - - // tx lgx stuff - TxDirection txDirectionA = servicePath.getServiceAEnd().getTxDirection(); - builder.setParameter(txDirectionA.getLgx().getLgxDeviceName()) - .setParameter(txDirectionA.getLgx().getLgxPortName()) - .setParameter(txDirectionA.getLgx().getLgxPortRack()) - .setParameter(txDirectionA.getLgx().getLgxPortShelf()); - builder.setParameter(txDirectionA.getTail().getTailRoadm().getNodeId()); - builder.setParameter(txDirectionA.getTail().getXponderPort().getCircuitPackName()); - builder.setParameter(txDirectionA.getTail().getXponderPort().getPortName()); - builder.setParameter(txDirectionA.getTail().getTailRoadmPortAid()); - builder.setParameter(txDirectionA.getTail().getTailRoadmPortRackLocation()); - - // rx lgx stuff - RxDirection rxDirectionA = servicePath.getServiceAEnd().getRxDirection(); - builder.setParameter(rxDirectionA.getLgx().getLgxDeviceName()) - .setParameter(rxDirectionA.getLgx().getLgxPortName()) - .setParameter(rxDirectionA.getLgx().getLgxPortRack()) - .setParameter(rxDirectionA.getLgx().getLgxPortShelf()); - builder.setParameter(rxDirectionA.getTail().getTailRoadm().getNodeId()); - builder.setParameter(rxDirectionA.getTail().getXponderPort().getCircuitPackName()); - builder.setParameter(rxDirectionA.getTail().getXponderPort().getPortName()); - builder.setParameter(rxDirectionA.getTail().getTailRoadmPortAid()); - builder.setParameter(rxDirectionA.getTail().getTailRoadmPortRackLocation()); - - builder.setParameter(servicePath.getServiceAEnd().getOpticType().getName()); - - Router routerA = servicePath.getServiceAEnd().getRouter(); - builder.setParameter(routerA.getNodeId()).setParameter(routerA.getIpAddress().toString()) - .setParameter(routerA.getUrl()); - builder.setParameter(servicePath.getServiceAEnd().getUserLabel()); - - ServiceZEnd serviceZEnd = servicePath.getServiceZEnd(); - builder.setParameter(serviceZEnd.getServiceFormat().getName()).setParameter(serviceZEnd.getServiceRate()) - .setParameter(serviceZEnd.getClli()).setParameter(serviceZEnd.getNodeId()); - - // tx port stuff - Port zendTxDirection = serviceZEnd.getTxDirection().getPort(); - builder.setParameter(zendTxDirection.getPortDeviceName()).setParameter(zendTxDirection.getPortName()) - .setParameter(zendTxDirection.getPortRack()).setParameter(zendTxDirection.getPortShelf()) - .setParameter(zendTxDirection.getPortSlot()).setParameter(zendTxDirection.getPortSubSlot()); - - // tx lgx stuff - TxDirection txDirectionZ = serviceZEnd.getTxDirection(); - builder.setParameter(txDirectionZ.getLgx().getLgxDeviceName()) - .setParameter(txDirectionZ.getLgx().getLgxPortName()) - .setParameter(txDirectionZ.getLgx().getLgxPortRack()) - .setParameter(txDirectionZ.getLgx().getLgxPortShelf()); - builder.setParameter(txDirectionZ.getTail().getTailRoadm().getNodeId()); - builder.setParameter(txDirectionZ.getTail().getXponderPort().getCircuitPackName()); - builder.setParameter(txDirectionZ.getTail().getXponderPort().getPortName()); - builder.setParameter(txDirectionZ.getTail().getTailRoadmPortAid()); - builder.setParameter(txDirectionZ.getTail().getTailRoadmPortRackLocation()); - - // rx lgx stuff - RxDirection rxDirectionZ = servicePath.getServiceAEnd().getRxDirection(); - builder.setParameter(rxDirectionZ.getLgx().getLgxDeviceName()) - .setParameter(rxDirectionZ.getLgx().getLgxPortName()) - .setParameter(rxDirectionZ.getLgx().getLgxPortRack()) - .setParameter(rxDirectionZ.getLgx().getLgxPortShelf()); - builder.setParameter(rxDirectionZ.getTail().getTailRoadm().getNodeId()); - builder.setParameter(rxDirectionZ.getTail().getXponderPort().getCircuitPackName()); - builder.setParameter(rxDirectionZ.getTail().getXponderPort().getPortName()); - builder.setParameter(rxDirectionZ.getTail().getTailRoadmPortAid()); - builder.setParameter(rxDirectionZ.getTail().getTailRoadmPortRackLocation()); - - builder.setParameter(servicePath.getServiceAEnd().getOpticType().getName()); - - Router routerZ = servicePath.getServiceZEnd().getRouter(); - builder.setParameter(routerZ.getNodeId()).setParameter(routerZ.getIpAddress().toString()) - .setParameter(routerZ.getUrl()); - builder.setParameter(servicePath.getServiceZEnd().getUserLabel()); - - String customerCode = ""; - if ((servicePath.getHardConstraints().getCustomerCode() == null) - || servicePath.getHardConstraints().getCustomerCode().isEmpty()) { - customerCode = servicePath.getHardConstraints().getCustomerCode().iterator().next(); - } - builder.setParameter(customerCode); - builder.setParameter(servicePath.getDueDate().getValue()); - builder.setParameter(servicePath.getEndDate().getValue()); - builder.setParameter(servicePath.getNcCode()); - builder.setParameter(servicePath.getNciCode()); - builder.setParameter(servicePath.getSecondaryNciCode()); - builder.setParameter(servicePath.getCustomer()); - builder.setParameter(servicePath.getCustomerContact()); - builder.setParameter(servicePath.getOperatorContact()); - builder.setParameter(servicePath.getLatency()); - String fiberSpanSrlgs = ""; - if ((servicePath.getFiberSpanSrlgs() == null) || servicePath.getFiberSpanSrlgs().isEmpty()) { - fiberSpanSrlgs = servicePath.getFiberSpanSrlgs().iterator().next(); - } - String supportingServiceName = ""; - if ((servicePath.getSupportingServiceName() == null) || servicePath.getSupportingServiceName().isEmpty()) { - supportingServiceName = servicePath.getSupportingServiceName().iterator().next(); - } - // TODO: hard constraints and soft constraints are missing - builder.setParameter(fiberSpanSrlgs); - builder.setParameter(supportingServiceName); - builder.setParameter(getCurrentTimestamp()); - builder.setParameter(getCurrentTimestamp()); - } - - /** - * If the input value is null or empty string returns an empty string otherwise - * its value. - * - * @param value a value potentially NULL - * @return String the string value potentially empty if value is NULL - */ - private static String getStringOf(String value) { - return Strings.isNullOrEmpty(value) ? "" : value; - } -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/StatementBuilder.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/StatementBuilder.java deleted file mode 100644 index d34ca5443..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/query/StatementBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.inventory.query; - -import java.sql.PreparedStatement; -import java.sql.SQLException; - -public final class StatementBuilder { - - private final PreparedStatement statement; - private int index; - - private StatementBuilder(PreparedStatement statement) { - this.statement = statement; - this.index = 1; - } - - public StatementBuilder setParameter(String value) throws SQLException { - this.statement.setString(this.index++, value); - return this; - } - - public StatementBuilder setParameter(Long value) throws SQLException { - this.statement.setLong(this.index++, value); - return this; - } - - public StatementBuilder setParameters(String... strings) throws SQLException { - for (int i = 0; i < strings.length; i++) { - statement.setString(i + 1, strings[i]); - } - return this; - } - - public StatementBuilder reset() { - this.index = 1; - return this; - } - - public static StatementBuilder builder(PreparedStatement statement) { - return new StatementBuilder(statement); - } -} diff --git a/inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/StringUtils.java b/inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/StringUtils.java deleted file mode 100644 index 7b48f784c..000000000 --- a/inventory/src/main/java/org/opendaylight/transportpce/inventory/utils/StringUtils.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright © 2017 AT&T and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.transportpce.inventory.utils; - -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * Utility class which handles strings in inventory project. - * - */ -public final class StringUtils { - public static final String DEFAULT_SQL_DATE = "yyyy-MM-dd HH:mm:ss"; - - private StringUtils() { - // hiding the constructor - } - - /** - * Returns the current timestamp formatted with - * {@link StringUtils#DEFAULT_SQL_DATE}. - * - * @see StringUtils#getTimestamp(Date) - * @return String the current timestamp formatted - */ - public static String getCurrentTimestamp() { - return getTimestamp(new Date()); - } - - /** - * This method will format the provided {@link Date} with the - * {@link StringUtils#DEFAULT_SQL_DATE} format. - * - * @param date a date - * @return string represenation of the given date - */ - public static String getTimestamp(Date date) { - SimpleDateFormat simpleDate = new SimpleDateFormat(DEFAULT_SQL_DATE); - return simpleDate.format(date); - } - - /** - * Checks the input object for null and if it's null returns a dash instead. - * - * @param object an input object - * @return if object is null a dash is returned, - * otherwise {@link Object#toString()} - */ - public static String prepareDashString(Object object) { - return prepareString(object, "-"); - } - - /** - * Checks the input object for null and if's null returns an empty string instead. - * - * @param object an input object - * @return if object is null an empty string is returned, - * otherwise {@link Object#toString()} - */ - public static String prepareEmptyString(Object object) { - return prepareString(object, ""); - } - - /** - * Checks if the given object is null and returns its representation given by - * replacement. - * - * @param objectString a string object - * @param replacement a replacement - * @return String the representation of the object given by replacement - */ - public static String prepareString(Object objectString, String replacement) { - return objectString == null ? replacement : objectString.toString(); - } -} diff --git a/inventory/src/main/resources/org/opendaylight/blueprint/inventory-blueprint.xml b/inventory/src/main/resources/org/opendaylight/blueprint/inventory-blueprint.xml deleted file mode 100644 index 072664d4c..000000000 --- a/inventory/src/main/resources/org/opendaylight/blueprint/inventory-blueprint.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ${deviceBackupPeriod} - - - org-openroadmdevice-backup-job - - - - diff --git a/pom.xml b/pom.xml index 9ed4041e5..f38c20b34 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL api common renderer - inventory networkmodel olm tests -- 2.36.6