2 * Copyright © 2016 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
8 package org.opendaylight.transportpce.inventory;
10 import static java.util.Objects.requireNonNull;
11 import static org.opendaylight.transportpce.inventory.utils.StringUtils.getCurrentTimestamp;
12 import static org.opendaylight.transportpce.inventory.utils.StringUtils.prepareDashString;
13 import static org.opendaylight.transportpce.inventory.utils.StringUtils.prepareEmptyString;
15 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16 import java.sql.Connection;
17 import java.sql.PreparedStatement;
18 import java.sql.ResultSet;
19 import java.sql.SQLException;
21 import java.util.Optional;
22 import java.util.concurrent.ExecutionException;
23 import javax.sql.DataSource;
24 import org.eclipse.jdt.annotation.NonNull;
25 import org.eclipse.jdt.annotation.Nullable;
26 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
27 import org.opendaylight.transportpce.common.Timeouts;
28 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
29 import org.opendaylight.transportpce.inventory.query.Queries;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceData;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.CpSlots;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.CpSlotsKey;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPorts;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPortsKey;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLink;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLinkKey;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceKey;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLink;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLinkKey;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMapKey;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.DegreeKey;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnections;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLink;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLinkKey;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.Slots;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.SlotsKey;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.Shelves;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.ShelvesKey;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.Interface1;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.ethernet.container.EthernetBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfig;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfigKey;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfName;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfNameKey;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.och.container.OchBuilder;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.OtsBuilder;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.Tcm;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.TcmKey;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.container.OduBuilder;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsi;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsiKey;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsi;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsiKey;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsi;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsiKey;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.otu.container.OtuBuilder;
79 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
80 import org.slf4j.Logger;
81 import org.slf4j.LoggerFactory;
84 value = "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING",
85 justification = "TODO review the SQL statement generation process")
86 public class INode221 {
87 private static final Logger LOG = LoggerFactory.getLogger(INode221.class);
89 private final DataSource dataSource;
90 private final DeviceTransactionManager deviceTransactionManager;
92 public INode221(DataSource dataSource, DeviceTransactionManager deviceTransactionManager) {
93 this.dataSource = dataSource;
94 this.deviceTransactionManager = deviceTransactionManager;
97 public boolean addNode(String deviceId) {
99 InstanceIdentifier<Info> infoIID = InstanceIdentifier
100 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
103 Optional<Info> infoOpt =
104 deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.OPERATIONAL, infoIID,
105 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
107 if (infoOpt.isPresent()) {
108 deviceInfo = infoOpt.orElseThrow();
110 LOG.warn("Could not get device info from DataBroker");
113 boolean sqlResult = false;
114 String query = Queries.getQuery().deviceInfoInsert().get();
115 LOG.info("Running {} query ", query);
116 try (Connection connection = dataSource.getConnection();
117 PreparedStatement preparedStatement = connection.prepareStatement(query)) {
118 Object[] prepareParameters = prepareDeviceInfoParameters(deviceInfo);
119 for (int i = 0; i < prepareParameters.length; i++) {
120 LOG.debug("Parameter {} has value {}", i + 1, prepareParameters[i]);
121 preparedStatement.setObject(i + 1, prepareParameters[i]);
124 int executeUpdate = preparedStatement.executeUpdate();
125 LOG.info("{} entries were added", executeUpdate);
128 LOG.info("iNode AddNode call complete");
129 getRoadmShelves(deviceId);
130 LOG.info("iNode getRoadmShelves call complete");
131 getCircuitPacks(deviceId);
132 LOG.debug("iNode getCircuitPacks call complete");
134 LOG.debug("iNode persist interfaces call");
135 persistDevInterfaces(deviceId, connection);
136 LOG.debug("iNode persist interfaces call complete");
138 LOG.debug("iNode persist interfaces call");
139 persistDevInterfaces(deviceId, connection);
140 LOG.debug("iNode persist interfaces call complete");
142 LOG.debug("iNode persist protocols call");
143 persistDevProtocols(deviceId, connection);
144 LOG.debug("iNode persist protocols call complete");
146 // LOG.debug("iNode persist wavelength map call");
147 // persistDevWavelengthMap(deviceId, connection);
148 // LOG.debug("iNode persist wavelength map call complete");
150 LOG.debug("iNode persist internal links map call");
151 persistDevInternalLinks(deviceId, connection);
152 LOG.debug("iNode persist internal links map call complete");
154 LOG.debug("iNode persist Physical links map call");
155 persistDevPhysicalLinks(deviceId, connection);
156 LOG.debug("iNode persist Physical links map call complete");
158 LOG.debug("iNode persist External links map call");
159 persistDevExternalLinks(deviceId, connection);
160 LOG.debug("iNode persist External links map call complete");
162 LOG.debug("iNode persist degree map call");
163 persistDevDegree(deviceId, connection);
164 LOG.debug("iNode persist degree map call complete");
166 LOG.debug("iNode persist srg map call");
167 persistDevSrg(deviceId, connection);
168 LOG.debug("iNode persist srg map call complete");
170 LOG.debug("iNode persist Roadm Connections call");
171 persistDevRoadmConnections(deviceId, connection);
172 LOG.debug("iNode persist Roadm Connections call complete");
174 LOG.debug("iNode persist Connection Map call");
175 persistDevConnectionMap(deviceId, connection);
176 LOG.debug("iNode persist Connection Map call complete");
178 } catch (SQLException | InterruptedException | ExecutionException e) {
179 LOG.error("Something wrong when storing node into DB", e);
184 public boolean nodeExists(String nodeId) {
185 String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?";
187 LOG.info("Checking if {} exists in DB", nodeId);
188 try (Connection connection = dataSource.getConnection();
189 PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) {
190 preparedStmt.setString(1, nodeId);
191 try (ResultSet rs = preparedStmt.executeQuery()) {
193 nodeExists = rs.getInt("node_exists");
194 LOG.debug("Found {} devices matching {}", nodeExists, nodeId);
197 } catch (SQLException e) {
198 LOG.error("Something wrong when fetching node in DB", e);
200 return nodeExists != 0;
203 public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException {
204 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
205 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
207 Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
208 LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
209 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
210 if (!deviceObject.isPresent()) {
211 LOG.error("No device found in operational datastore for nodeId {}", nodeId);
215 Map<ShelvesKey, Shelves> shelvesMap = deviceObject.orElseThrow().nonnullShelves();
216 LOG.info("Shelves size {}", shelvesMap.size());
217 try (Connection connection = requireNonNull(dataSource.getConnection())) {
218 for (Map.Entry<ShelvesKey, Shelves> entry : shelvesMap.entrySet()) {
219 Shelves shelve = entry.getValue();
220 String shelfName = shelve.getShelfName();
222 LOG.info("Getting Shelve Details of {}", shelfName);
223 if (shelve.getSlots() != null) {
224 LOG.info("Slot Size {} ", shelve.getSlots().size());
225 persistShelveSlots(nodeId, shelve, connection);
227 LOG.info("No Slots for shelf {}", shelfName);
231 persistShelves(nodeId, connection, shelve);
233 } catch (SQLException e1) {
234 LOG.error("Something wrong when fetching ROADM shelves in DB", e1);
238 public void getCircuitPacks(String nodeId) throws InterruptedException, ExecutionException {
239 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
240 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
242 Optional<OrgOpenroadmDevice> deviceObject =
243 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
244 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
245 if (!deviceObject.isPresent()) {
246 LOG.warn("Device object {} was not found", nodeId);
250 Map<CircuitPacksKey, CircuitPacks> circuitPacksMap = deviceObject.orElseThrow().nonnullCircuitPacks();
251 LOG.info("Circuit pack size {}", circuitPacksMap.size());
253 try (Connection connection = requireNonNull(dataSource.getConnection())) {
255 for (Map.Entry<CircuitPacksKey, CircuitPacks> entry : circuitPacksMap.entrySet()) {
256 CircuitPacks cp = entry.getValue();
258 if (cp.getCpSlots() != null) {
259 persistCircuitPacksSlots(nodeId, cp, connection);
261 LOG.info("Everything {}", cp);
262 LOG.info("CP is {}", cp);
264 persistPorts(cp, connection);
266 persistCircuitPacks(nodeId, connection, cp);
268 } catch (SQLException e1) {
269 LOG.error("Something wrong when fetching Circuit Packs in DB", e1);
273 private void persistCircuitPacks(String nodeId, Connection connection, CircuitPacks cp) {
274 Object[] parameters = prepareCircuitPacksParameters(nodeId, cp);
275 String query = Queries.getQuery().deviceCircuitPackInsert().get();
276 LOG.info("Running {} query ", query);
277 try (PreparedStatement stmt = connection.prepareStatement(query)) {
278 for (int j = 0; j < parameters.length; j++) {
279 stmt.setObject(j + 1, parameters[j]);
282 stmt.clearParameters();
283 } catch (SQLException e) {
284 LOG.error("Something wrong when storing Circuit Packs in DB", e);
288 private void persistShelves(String nodeId, Connection connection, Shelves shelve) {
289 Object[] shelvesParameter = prepareShelvesParameters(nodeId, shelve);
290 String query = Queries.getQuery().deviceShelfInsert().get();
291 LOG.info("Running {} query ", query);
292 try (PreparedStatement preparedStmt = connection.prepareStatement(query)) {
293 for (int j = 0; j < shelvesParameter.length; j++) {
294 preparedStmt.setObject(j + 1, shelvesParameter[j]);
296 preparedStmt.execute();
297 preparedStmt.clearParameters();
298 } catch (SQLException e) {
299 LOG.error("Something wrong when storing shelves in DB", e);
303 private void persistShelveSlots(String nodeId, Shelves shelves, Connection connection) {
304 String startTimetampStr = getCurrentTimestamp();
306 Map<SlotsKey, Slots> slotsMap = shelves.nonnullSlots();
307 for (Map.Entry<SlotsKey, Slots> entry : slotsMap.entrySet()) {
308 Slots slot = entry.getValue();
309 LOG.info("Getting Slot Details of {}", slot.getSlotName());
310 Object[] parameters = new Object[]{nodeId,
311 shelves.getShelfName(),
314 slot.getProvisionedCircuitPack(),
318 String query = Queries.getQuery().deviceShelfSlotInsert().get();
319 LOG.info("Running {} query ", query);
320 try (PreparedStatement stmt = connection.prepareStatement(query)) {
321 for (int j = 0; j < parameters.length; j++) {
322 stmt.setObject(j + 1, parameters[j]);
325 stmt.clearParameters();
326 } catch (SQLException e) {
327 LOG.error("Something wrong when storing shelves slots in DB", e);
333 private void persistCircuitPacksSlots(String nodeId, CircuitPacks circuitPacks, Connection connection) {
334 String startTimetampStr = getCurrentTimestamp();
336 Map<CpSlotsKey, CpSlots> cpSlotsMap = circuitPacks.nonnullCpSlots();
337 for (Map.Entry<CpSlotsKey, CpSlots> entry : cpSlotsMap.entrySet()) {
338 CpSlots cpSlot = entry.getValue();
340 Object[] parameters = new Object[]{nodeId,
341 circuitPacks.getCircuitPackName(),
342 cpSlot.getSlotName(),
344 cpSlot.getProvisionedCircuitPack(),
348 String query = Queries.getQuery().deviceCPSlotInsert().get();
349 LOG.info("Running {} query ", query);
350 try (PreparedStatement stmt = connection.prepareStatement(query)) {
351 for (int j = 0; j < parameters.length; j++) {
352 stmt.setObject(j + 1, parameters[j]);
355 stmt.clearParameters();
356 } catch (SQLException e) {
357 LOG.error("Something wrong when storing Cirtcuits Packs slots in DB", e);
362 private void persistPorts(CircuitPacks circuitPacks, Connection connection) {
363 LOG.warn("Ports are not persisted yet");
368 * Prepares parameters for device insert query.
370 * @param deviceInfo device info
371 * @return Object Object
373 private static Object[] prepareDeviceInfoParameters(Info deviceInfo) {
374 String startTimetampStr = getCurrentTimestamp();
375 //Integer maxNumBin15minHistoricalPm = null;
376 //Integer maxNumBin24hourHistoricalPm = null;
377 //String serialId = "";
379 String nodeId = prepareDashString(deviceInfo.getNodeId());
380 Long nodeNumber = deviceInfo.getNodeNumber().toJava();
381 Integer nodeTypeEnu = deviceInfo.getNodeType().getIntValue();
382 String clli = prepareDashString(deviceInfo.getClli());
383 String vendor = prepareDashString(deviceInfo.getVendor());
384 String model = prepareDashString(deviceInfo.getModel());
385 String ipAddress = prepareDashString(deviceInfo.getIpAddress().getIpv4Address().getValue());
386 String prefixLength = prepareDashString(deviceInfo.getPrefixLength());
387 String defaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue());
388 Integer sourceEnum = deviceInfo.getSource().getIntValue();
389 String currentIpAddress = prepareDashString(deviceInfo.getCurrentIpAddress().getIpv4Address().getValue());
390 String currentPrefixLength = prepareDashString(deviceInfo.getCurrentPrefixLength());
391 String currentDefaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue());
392 String macAddress = prepareDashString(deviceInfo.getMacAddress().getValue());
393 String softwareVersion = prepareDashString(deviceInfo.getSoftwareVersion());
394 String openroadmVersion = "2.2.1";
395 String template = prepareDashString(deviceInfo.getTemplate());
396 String currentDatetime = prepareDashString(deviceInfo.getCurrentDatetime().getValue());
398 (deviceInfo.getGeoLocation() != null ? prepareDashString(deviceInfo.getGeoLocation().getLatitude()) : "");
399 String geoLongitude =
400 (deviceInfo.getGeoLocation() != null ? prepareDashString(deviceInfo.getGeoLocation().getLongitude()) : "");
401 String maxDegrees = prepareDashString(deviceInfo.getMaxDegrees()); // max_degrees
402 String maxSrgs = prepareDashString(deviceInfo.getMaxSrgs()); //max_srgs
403 String swVersion = prepareDashString(deviceInfo.getSoftwareVersion()); //sw_version
404 String swValidationTimer = prepareDashString(""); //sw_validation_timer
405 String activationDateTime = prepareDashString(""); //activation_date_time
406 /*jsonDevInfo = JsonStringBuilder.getDevInfoJson().replace("$$NODE-ID$$",nodeId)
407 .replace("$$NODE-NUMBER$$", nodeNumber)
408 .replace("$$NODE-TYPE$$",nodeType)
409 .replace("$$CLLI$$",clli)
410 .replace("$$VENDOR$$",vendor)
411 .replace("$$MODEL$$",model)
412 .replace("$$SERIAL-ID$$",serialId)
413 .replace("$$IPADDRESS$$",ipAddress)
414 .replace("$$PREFIX-LENGTH$$",prefixLength)
415 .replace("$$DEFAULTGATEWAY$$",defaultGateway)
416 .replace("$$SOURCE$$",String.valueOf(source))
417 .replace("$$CURRENT-IPADDRESS$$",currentIpAddress)
418 .replace("$$CURRENT-PREFIX-LENGTH$$",currentPrefixLength)
419 .replace("$$CURRENT-DEFAULTGATEWAY$$",currentDefailtGateway)
420 .replace("$$MACADDRESS$$",macAddress)
421 .replace("$$SOFTWAREVERSION$$",softwareVersion)
422 .replace("$$OPENROADM-VERSION$$",openroadmVersion)
423 .replace("$$TEMPLATE$$",template)
424 .replace("$$CURRENT-DATETIME$$",currentDatetime)
425 .replace("$$LATITUDE$$",latitude)
426 .replace("$$LONGITUDE$$",longitude)
427 .replace("$$MAX-DEGREES$$",maxDegrees)
428 .replace("$$MAX-SRGS$$",maxSrgs)
429 .replace("$$MAX-NUM-BIN-15MIN-HISTORICAL-PM$$",prepareDashString(""))
430 .replace("$$MAX-NUM-BIN-24HOUR-HISTORICAL-PM$$",prepareDashString(""))
431 .replace("$$SW-VERSION$$",swVersion)
432 .replace("$$SW-VALIDATION-TIMER$$",swValidationTimer)
433 .replace("$$ACTIVATION-DATE-TIME$$",activationDateTime);*/
451 currentDefaultGateway,
461 //maxNumBin15minHistoricalPm,
462 //maxNumBin24hourHistoricalPm,
473 private static Object[] prepareShelvesParameters(String nodeId, Shelves shelve) {
474 String startTimestamp = getCurrentTimestamp();
476 return new Object[]{nodeId,
477 shelve.getShelfName(),
478 shelve.getShelfType(),
480 shelve.getShelfPosition(),
481 (shelve.getAdministrativeState() == null ? null : shelve.getAdministrativeState().getIntValue()),
484 shelve.getSerialId(),
486 shelve.getProductCode(),
487 (shelve.getManufactureDate() == null ? null : shelve.getManufactureDate().getValue()),
489 shelve.getHardwareVersion(),
490 (shelve.getOperationalState() == null ? null : shelve.getOperationalState().getIntValue()),
491 (shelve.getEquipmentState() == null ? null : shelve.getEquipmentState().getIntValue()),
492 (shelve.getDueDate() == null ? null : shelve.getDueDate().getValue()),
497 private static Object[] prepareCircuitPacksParameters(String nodeId, CircuitPacks cpack) {
498 String startTimestamp = getCurrentTimestamp();
499 return new Object[]{nodeId,
500 cpack.getCircuitPackName(),
501 cpack.getCircuitPackType(),
502 cpack.getCircuitPackProductCode(),
503 (cpack.getAdministrativeState() == null ? "" : cpack.getAdministrativeState().getIntValue()),
508 cpack.getProductCode(),
509 (cpack.getManufactureDate() == null ? "" : cpack.getManufactureDate().getValue()),
511 cpack.getHardwareVersion(),
512 prepareEmptyString(cpack.getOperationalState().getIntValue()),
513 cpack.getCircuitPackCategory().getType().getName(),
514 cpack.getCircuitPackCategory().getExtension(),
515 (cpack.getEquipmentState() == null ? "" : cpack.getEquipmentState().getIntValue()),
516 cpack.getCircuitPackMode(),
520 prepareEmptyString(cpack.getDueDate()),
521 prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" :
522 ((cpack.getParentCircuitPack().getCircuitPackName() == null) ? "" :
523 cpack.getParentCircuitPack().getCircuitPackName())
525 prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" :
526 ((cpack.getParentCircuitPack().getCpSlotName() == null) ? "" :
527 cpack.getParentCircuitPack().getCpSlotName())
533 private Object[] prepareDevInterfaceParameters(String nodeId, Interface deviceInterface, Connection connection) {
535 int administrativeStateEnu = deviceInterface.getAdministrativeState().getIntValue();
536 int operationalState = deviceInterface.getOperationalState().getIntValue();
537 int ethernetDuplexEnu = -1;
538 int ethernetAutoNegotiationEnu = -1;
539 int maintTestsignalTestpatternEnu = -1;
540 int maintTestsignalTypeEnu = -1;
542 int otuMaintTypeEnu = -1;
543 //int otsFiberTypeEnu = -1;
544 String name = deviceInterface.getName();
545 String description = deviceInterface.getDescription();
546 String type = deviceInterface.getType().toString();
547 String circuitId = deviceInterface.getCircuitId();
548 String supportingInterface = deviceInterface.getSupportingInterface();
549 String supportingCircuitPackName = deviceInterface.getSupportingCircuitPackName();
550 String supportingPort = deviceInterface.getSupportingPort();
551 String ethernetSpeed = "";
552 String ethernetFec = "";
553 String ethernetMtu = "";
554 String ethernetCurrSpeed = "";
555 String ethernetCurrDuplex = "";
556 //String mciMcttpMinFreq = "";
557 //String mciMcttpMaxFreq = "";
558 //String mciMcttpCenterFreq = "";
559 //String mciMcttpSlotWidth = "";
560 //String mciNmcCtpFrequency = "";
561 //String mciNmcCtpWidth = "";
563 //String ochFrequency = "";
564 //String ochWidth = "";
565 //String ochWavelengthNumber = "";
566 String ochModulationFormat = "";
567 String ochTransmitPower = "";
568 String otsSpanLossReceive = "";
569 String otsSpanLossTransmit = "";
570 //String otsIngressSpanLossAgingMargin = "";
571 //String otsEolMaxLoadPin = "";
572 String oduRate = ""; //BUG in following case switch statement ???
573 //String oduFunction = "";
574 String oduMonitoringMode = "";
575 //String oduNoOamFunction = "";
576 String oduProactiveDelayMeasurementEnabled = "";
577 //String oduPoaTribPortNumber = "";
578 //String oduTxSapi = "";
579 //String oduTxDapi = "";
580 //String oduTxOperator = "";
581 //String oduAcceptedSapi = "";
582 //String oduAcceptedDapi = "";
583 //String oduAcceptedOperator = "";
584 //String oduExpectedSapi = "";
585 //String oduExpectedDapi = "";
586 //String oduTimActEnabled = "";
587 //String oduTimDetectMode = "";
588 //String oduDegmIntervals = "";
589 //String oduDegthrPercentage = "";
590 String opuPayloadType = "";
591 String opuRxPayloadType = "";
592 String opuExpPayloadType = "";
593 String opuPayloadInterface = "";
594 String maintTestsignalEnabled = "";
595 String maintTestsignalBiterrors = "";
596 String maintTestsignalBiterrorsterminal = "";
597 String maintTestsignalSyncseconds = "";
598 String maintTestsignalSyncsecondsterminal = "";
600 //String otuTxSapi = "";
601 //String otuTxDapi = "";
602 //String otuTxOperator = "";
603 //String otuAcceptedSapi = "";
604 //String otuAcceptedDapi = "";
605 //String otuAcceptedOperator = "";
606 //String otuExpectedSapi = "";
607 //String otuExpectedDapi = "";
608 //String otuTimActEnabled = "";
609 //String otuTimDetectMode = "";
610 //String otuDegmIntervals = "";
611 //String otuDegthrPercentage = "";
612 String otuMaintLoopbackEnabled = "";
613 //String mtOtuRate = "";
614 //String mtOtuFec = "";
615 //String mtOtuMaintLoopback = "";
616 //String mtOtuEnabled = "";
617 //String mtOtuType = "";
619 switch (deviceInterface.getType().toString()) {
622 //EthernetBuilder ethIfBuilder = new EthernetBuilder();
623 EthernetBuilder ethIfBuilder =
624 new EthernetBuilder(deviceInterface.augmentation(Interface1.class).getEthernet());
625 ethernetSpeed = ethIfBuilder.getSpeed().toString();
626 ethernetFec = ethIfBuilder.getFec().getName();
627 ethernetDuplexEnu = ethIfBuilder.getDuplex().getIntValue();
628 ethernetMtu = ethIfBuilder.getMtu().toString();
629 ethernetAutoNegotiationEnu = ethIfBuilder.getAutoNegotiation().getIntValue();
630 ethernetCurrSpeed = ethIfBuilder.getCurrSpeed();
631 ethernetCurrDuplex = ethIfBuilder.getCurrDuplex();
635 OchBuilder ochIfBuilder = new OchBuilder(deviceInterface.augmentation(
636 org.opendaylight.yang.gen.v1
637 .http.org.openroadm.optical.channel.interfaces.rev161014.Interface1.class)
639 ochRate = ochIfBuilder.getRate().toString();
640 //ochWavelengthNumber = ochIfBuilder.getWavelengthNumber().toString();
641 ochModulationFormat = ochIfBuilder.getModulationFormat().getName();
642 ochTransmitPower = ochIfBuilder.getTransmitPower().toString();
646 OtsBuilder otsIfBuilder = new OtsBuilder(deviceInterface.augmentation(
647 org.opendaylight.yang.gen.v1
648 .http.org.openroadm.optical.transport.interfaces.rev161014.Interface1.class)
650 //otsFiberTypeEnu = otsIfBuilder.getFiberType().getIntValue();
651 otsSpanLossReceive = otsIfBuilder.getSpanLossReceive().toString();
652 otsSpanLossTransmit = otsIfBuilder.getSpanLossTransmit().toString();
656 OduBuilder oduIfBuilder = new OduBuilder(deviceInterface.augmentation(
657 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.Interface1.class)
659 oduRate = String.valueOf(oduIfBuilder.getRate());
660 oduMonitoringMode = oduIfBuilder.getMonitoringMode().getName();
661 oduProactiveDelayMeasurementEnabled = oduIfBuilder.getProactiveDelayMeasurementEnabled().toString();
663 persistDevInterfaceTcm(nodeId, name, oduIfBuilder, connection);
664 persistDevInterfaceOtnOduTxMsi(nodeId, name, oduIfBuilder, connection);
665 persistDevInterfaceOtnOduRxMsi(nodeId, name, oduIfBuilder, connection);
666 persistDevInterfaceOtnOduExpMsi(nodeId, name, oduIfBuilder, connection);
668 opuPayloadType = oduIfBuilder.getOpu().getPayloadType();
669 opuRxPayloadType = oduIfBuilder.getOpu().getRxPayloadType();
670 opuExpPayloadType = oduIfBuilder.getOpu().getExpPayloadType();
671 opuPayloadInterface = oduIfBuilder.getOpu().getPayloadInterface();
672 /*persistDevInterfaceOtnOduTxMsi(nodeId,name,oduIfBuilder,connection);
673 persistDevInterfaceOtnOduRxMsi(nodeId,name,oduIfBuilder,connection);
674 persistDevInterfaceOtnOduExpMsi(nodeId,name,oduIfBuilder,connection); */
675 maintTestsignalEnabled = oduIfBuilder.getMaintTestsignal().getEnabled().toString();
676 maintTestsignalTestpatternEnu = oduIfBuilder.getMaintTestsignal().getTestPattern().getIntValue();
677 maintTestsignalTypeEnu = oduIfBuilder.getMaintTestsignal().getType().getIntValue();
678 maintTestsignalBiterrors = oduIfBuilder.getMaintTestsignal().getBitErrors().toString();
679 maintTestsignalBiterrorsterminal = oduIfBuilder.getMaintTestsignal().getBitErrorsTerminal().toString();
680 maintTestsignalSyncseconds = oduIfBuilder.getMaintTestsignal().getSyncSeconds();
681 maintTestsignalSyncsecondsterminal = oduIfBuilder.getMaintTestsignal().getSyncSecondsTerminal();
685 OtuBuilder otuIfBuilder = new OtuBuilder(deviceInterface.augmentation(
686 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.Interface1.class)
688 otuRate = otuIfBuilder.getRate().toString();
689 otuFecEnu = otuIfBuilder.getFec().getIntValue();
690 otuMaintLoopbackEnabled = otuIfBuilder.getMaintLoopback().getEnabled().toString();
691 otuMaintTypeEnu = otuIfBuilder.getMaintLoopback().getType().getIntValue();
695 LOG.error("Could not get interface type");
698 String startTimestamp = getCurrentTimestamp();
700 return new Object[]{nodeId,
704 Integer.toString(administrativeStateEnu),
705 Integer.toString(operationalState),
708 supportingCircuitPackName,
712 Integer.toString(ethernetDuplexEnu),
714 Integer.toString(ethernetAutoNegotiationEnu),
719 //mciMcttpCenterFreq,
721 //mciNmcCtpFrequency,
723 "", "", "", "", "", "",
727 //ochWavelengthNumber,
731 //Integer.toString(otsFiberTypeEnu),
735 //otsIngressSpanLossAgingMargin,
744 oduProactiveDelayMeasurementEnabled,
745 //oduPoaTribPortNumber,
751 //oduAcceptedOperator,
757 //oduDegthrPercentage,
758 "", "", "", "", "", "", "", "", "", "", "", "", "",
763 maintTestsignalEnabled,
764 Integer.toString(maintTestsignalTestpatternEnu),
765 Integer.toString(maintTestsignalTypeEnu),
766 maintTestsignalBiterrors,
767 maintTestsignalBiterrorsterminal,
768 maintTestsignalSyncseconds,
769 maintTestsignalSyncsecondsterminal,
771 Integer.toString(otuFecEnu),
777 //otuAcceptedOperator,
783 //otuDegthrPercentage,
784 "", "", "", "", "", "", "", "", "", "", "", "",
785 otuMaintLoopbackEnabled,
786 Integer.toString(otuMaintTypeEnu),
789 //mtOtuMaintLoopback,
799 private static Object[] prepareDevInterfaceTcmParameters(String nodeId, String interfaceName, Tcm tcm) {
802 String layer = tcm.getLayer().toString();
803 int monitoringModeEnu = tcm.getMonitoringMode().getIntValue();
804 String ltcActEnabled = tcm.getLtcActEnabled().toString();
805 String proactiveDelayMeasurementEnabled = tcm.getProactiveDelayMeasurementEnabled().toString();
806 //int tcmDirectionEnu = -1;
807 //int timDetectModeEnu = -1;
808 //String txSapi = "";
809 //String txDapi = "";
810 //String txOperator = "";
811 //String acceptedSapi = "";
812 //String acceptedDapi = "";
813 //String acceptedOperator = "";
814 //String expectedSapi = "";
815 //String expectedDapi = "";
816 //String timActEnabled = "";
817 //String degmIntervals = "";
818 //String degthrPercentage = "";
820 String startTimestamp = getCurrentTimestamp();
822 return new Object[]{nodeId,
825 Integer.toString(monitoringModeEnu),
827 proactiveDelayMeasurementEnabled,
828 //Integer.toString(tcmDirectionEnu),
839 "", "", "", "", "", "", "", "", "",
840 //Integer.toString(timDetectModeEnu),
850 private static Object[] prepareDevInterfaceOtnOduTxMsiParameters(String nodeId, String interfaceName, TxMsi txMsi) {
852 String tribSlot = txMsi.getTribSlot().toString();
853 String odtuType = txMsi.getOdtuType().toString();
854 String tribPort = txMsi.getTribPort().toString();
855 String tribPortPayload = txMsi.getTribPortPayload();
857 String startTimestamp = getCurrentTimestamp();
859 return new Object[]{nodeId,
871 private static Object[] prepareDevInterfaceOtnOduRxMsiParameters(String nodeId, String interfaceName, RxMsi rxMsi) {
873 String tribSlot = rxMsi.getTribSlot().toString();
874 String odtuType = rxMsi.getOdtuType().toString();
875 String tribPort = rxMsi.getTribPort().toString();
876 String tribPortPayload = rxMsi.getTribPortPayload();
878 String startTimestamp = getCurrentTimestamp();
880 return new Object[]{nodeId,
893 private static Object[] prepareDevInterfaceOtnOduExpMsiParameters(String nodeId, String interfaceName,
896 String tribSlot = expMsi.getTribSlot().toString();
897 String odtuType = expMsi.getOdtuType().toString();
898 String tribPort = expMsi.getTribPort().toString();
899 String tribPortPayload = expMsi.getTribPortPayload();
901 String startTimestamp = getCurrentTimestamp();
903 return new Object[]{nodeId,
915 private void persistDevInterfaces(String nodeId, Connection connection) {
917 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
918 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
920 Optional<OrgOpenroadmDevice> deviceObject =
921 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
922 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
924 /*InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
925 .child(Interface.class);
926 Optional<Interface> interfaceOpt =
927 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, interfaceIID,
928 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); */
931 Map<InterfaceKey, Interface> interfaceMap = deviceObject.orElseThrow().nonnullInterface();
932 for (Map.Entry<InterfaceKey, Interface> entry : interfaceMap.entrySet()) {
933 Interface deviceInterface;
935 deviceInterface = entry.getValue();
936 /*if (interfaceOpt.isPresent()) {
937 deviceInterface = interfaceOpt.get();
939 LOG.warn("Could not get interface info");
942 Object[] parameters = prepareDevInterfaceParameters(nodeId, deviceInterface, connection);
944 String query = Queries.getQuery().deviceInterfacesInsert().get();
945 LOG.info("Running {} query ", query);
946 try (PreparedStatement stmt = connection.prepareStatement(query)) {
947 for (int j = 0; j < parameters.length; j++) {
948 stmt.setObject(j + 1, parameters[j]);
951 stmt.clearParameters();
952 } catch (SQLException e) {
953 LOG.error("Something wrong when storing devices interfaces in DB", e);
958 private void persistDevProtocols(String nodeId, Connection connection) {
960 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier
961 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
962 .child(Protocols.class)
964 Optional<Protocols> protocolObject =
965 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
966 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
967 if (!protocolObject.isPresent() || protocolObject.orElseThrow().augmentation(Protocols1.class) == null) {
968 LOG.error("LLDP subtree is missing");
972 protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp().getGlobalConfig().getAdminStatus()
974 String msgTxtInterval =
975 protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp().getGlobalConfig().getMsgTxInterval()
977 String mxgTxHoldMultiplier =
978 protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp().getGlobalConfig()
979 .getMsgTxHoldMultiplier().toString();
980 String startTimestamp = getCurrentTimestamp();
981 persistDevProtocolLldpPortConfig(nodeId, connection);
982 persistDevProtocolLldpNbrList(nodeId, connection);
984 Object[] parameters = {nodeId,
985 Integer.toString(adminstatusEnu),
992 String query = Queries.getQuery().deviceProtocolInsert().get();
993 LOG.info("Running {} query ", query);
994 try (PreparedStatement stmt = connection.prepareStatement(query)) {
995 for (int j = 0; j < parameters.length; j++) {
996 stmt.setObject(j + 1, parameters[j]);
999 stmt.clearParameters();
1000 } catch (SQLException e) {
1001 LOG.error("Something wrong when storing devices protocols in DB", e);
1007 private void persistDevProtocolLldpPortConfig(String nodeId, Connection connection) {
1009 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier
1010 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1011 .child(Protocols.class)
1013 Optional<Protocols> protocolObject =
1014 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1015 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1016 if (!protocolObject.isPresent() || protocolObject.orElseThrow().augmentation(Protocols1.class) == null) {
1017 LOG.error("LLDP subtree is missing");
1020 String startTimestamp = getCurrentTimestamp();
1022 Map<PortConfigKey, PortConfig> portConfigMap = protocolObject.orElseThrow()
1023 .augmentation(Protocols1.class).getLldp().nonnullPortConfig();
1024 for (Map.Entry<PortConfigKey, PortConfig> entry : portConfigMap.entrySet()) {
1026 PortConfig portConfig = entry.getValue();
1027 String ifName = portConfig.getIfName();
1028 int adminStatusEnu = portConfig.getAdminStatus().getIntValue();
1030 Object[] parameters = {nodeId,
1032 Integer.toString(adminStatusEnu),
1037 String query = Queries.getQuery().deviceProtocolPortConfigInsert().get();
1038 LOG.info("Running {} query ", query);
1039 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1040 for (int j = 0; j < parameters.length; j++) {
1041 stmt.setObject(j + 1, parameters[j]);
1044 stmt.clearParameters();
1045 } catch (SQLException e) {
1046 LOG.error("Something wrong when storing devices protocols LLDP Port config in DB", e);
1053 private void persistDevProtocolLldpNbrList(String nodeId, Connection connection) {
1055 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier
1056 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1057 .child(Protocols.class)
1059 Optional<Protocols> protocolObject =
1060 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1061 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1062 if (!protocolObject.isPresent() || protocolObject.orElseThrow().augmentation(Protocols1.class) == null) {
1063 LOG.error("LLDP subtree is missing");
1066 String startTimestamp = getCurrentTimestamp();
1068 Map<IfNameKey, IfName> ifNameMap = protocolObject.orElseThrow()
1069 .augmentation(Protocols1.class).getLldp().getNbrList().nonnullIfName();
1070 for (Map.Entry<IfNameKey, IfName> entry : ifNameMap.entrySet()) {
1072 IfName ifNameObj = entry.getValue();
1073 String ifName = ifNameObj.getIfName();
1074 String remotesysname = ifNameObj.getRemoteSysName();
1075 String remotemgmtaddresssubtype = ifNameObj.getRemoteMgmtAddressSubType().getName();
1076 String remotemgmtaddress = ifNameObj.getRemoteMgmtAddress().getIpv4Address().toString();
1077 int remoteportidsubtypeEnu = ifNameObj.getRemotePortIdSubType().getIntValue();
1078 String remoteportid = ifNameObj.getRemotePortId();
1079 int remotechassisidsubtypeEnu = ifNameObj.getRemoteChassisIdSubType().getIntValue();
1080 String remotechassisid = ifNameObj.getRemoteChassisId();
1082 Object[] parameters = {nodeId,
1085 remotemgmtaddresssubtype,
1087 Integer.toString(remoteportidsubtypeEnu),
1089 Integer.toString(remotechassisidsubtypeEnu),
1095 String query = Queries.getQuery().deviceProtocolLldpNbrlistInsert().get();
1096 LOG.info("Running {} query ", query);
1097 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1098 for (int j = 0; j < parameters.length; j++) {
1099 stmt.setObject(j + 1, parameters[j]);
1102 stmt.clearParameters();
1103 } catch (SQLException e) {
1104 LOG.error("Something wrong when storing devices protocols LLDP list number in DB", e);
1110 private void persistDevInternalLinks(String nodeId, Connection connection) {
1112 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1113 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1115 Optional<OrgOpenroadmDevice> deviceObject =
1116 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1117 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1118 if (!deviceObject.isPresent()) {
1119 LOG.error("Device with node id {} not found", nodeId);
1122 String startTimestamp = getCurrentTimestamp();
1124 Map<InternalLinkKey, InternalLink> internalLinkMap = deviceObject.orElseThrow().nonnullInternalLink();
1125 for (Map.Entry<InternalLinkKey, InternalLink> entry : internalLinkMap.entrySet()) {
1126 InternalLink internalLink = entry.getValue();
1127 String internalLinkName = internalLink.getInternalLinkName();
1128 String sourceCircuitPackName = internalLink.getSource().getCircuitPackName();
1129 String sourcePortName = internalLink.getSource().getPortName();
1130 String destinationCircuitPackName = internalLink.getDestination().getCircuitPackName();
1131 String destinationPortName = internalLink.getDestination().getPortName();
1133 Object[] parameters = {nodeId,
1135 sourceCircuitPackName,
1137 destinationCircuitPackName,
1138 destinationPortName,
1143 String query = Queries.getQuery().deviceInternalLinkInsert().get();
1144 LOG.info("Running {} query ", query);
1145 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1146 for (int j = 0; j < parameters.length; j++) {
1147 stmt.setObject(j + 1, parameters[j]);
1150 stmt.clearParameters();
1151 } catch (SQLException e) {
1152 LOG.error("Something wrong when storing devices internal links", e);
1159 private void persistDevExternalLinks(String nodeId, Connection connection) {
1161 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1162 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1164 Optional<OrgOpenroadmDevice> deviceObject =
1165 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1166 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1167 if (!deviceObject.isPresent()) {
1168 LOG.error("Device with node id {} not found", nodeId);
1171 String startTimestamp = getCurrentTimestamp();
1173 Map<ExternalLinkKey, ExternalLink> externalLinkMap = deviceObject.orElseThrow().nonnullExternalLink();
1174 for (Map.Entry<ExternalLinkKey, ExternalLink> entry : externalLinkMap.entrySet()) {
1175 ExternalLink externalLink = entry.getValue();
1176 String externalLinkName = externalLink.getExternalLinkName();
1177 String sourceNodeId = externalLink.getSource().getNodeId();
1178 String sourceCircuitPackName = externalLink.getSource().getCircuitPackName();
1179 String sourcePortName = externalLink.getSource().getPortName();
1180 String destinationNodeId = externalLink.getDestination().getNodeId();
1181 String destinationCircuitPackName = externalLink.getDestination().getCircuitPackName();
1182 String destinationPortName = externalLink.getDestination().getPortName();
1184 Object[] parameters = {nodeId,
1187 sourceCircuitPackName,
1190 destinationCircuitPackName,
1191 destinationPortName,
1196 String query = Queries.getQuery().deviceExternalLinkInsert().get();
1197 LOG.info("Running {} query ", query);
1198 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1199 for (int j = 0; j < parameters.length; j++) {
1200 stmt.setObject(j + 1, parameters[j]);
1203 stmt.clearParameters();
1204 } catch (SQLException e) {
1205 LOG.error("Something wrong when storing devices external links", e);
1211 private void persistDevPhysicalLinks(String nodeId, Connection connection) {
1213 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1214 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1216 Optional<OrgOpenroadmDevice> deviceObject =
1217 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1218 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1219 if (!deviceObject.isPresent()) {
1220 LOG.error("Device with node id {} not found", nodeId);
1224 String startTimestamp = getCurrentTimestamp();
1226 Map<PhysicalLinkKey, PhysicalLink> physicalLinkMap = deviceObject.orElseThrow().nonnullPhysicalLink();
1227 for (Map.Entry<PhysicalLinkKey, PhysicalLink> entry : physicalLinkMap.entrySet()) {
1228 PhysicalLink physicalLink = entry.getValue();
1229 String physicalLinkName = physicalLink.getPhysicalLinkName();
1230 String sourceCircuitPackName = physicalLink.getSource().getCircuitPackName();
1231 String sourcePortName = physicalLink.getSource().getPortName();
1232 String destinationCircuitPackName = physicalLink.getDestination().getCircuitPackName();
1233 String destinationPortName = physicalLink.getDestination().getPortName();
1235 Object[] parameters = {nodeId,
1237 sourceCircuitPackName,
1239 destinationCircuitPackName,
1240 destinationPortName,
1245 String query = Queries.getQuery().devicePhysicalLinkInsert().get();
1246 LOG.info("Running {} query ", query);
1247 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1248 for (int j = 0; j < parameters.length; j++) {
1249 stmt.setObject(j + 1, parameters[j]);
1252 stmt.clearParameters();
1253 } catch (SQLException e) {
1254 LOG.error("Something wrong when storing devices physical links", e);
1260 private void persistDevDegree(String nodeId, Connection connection) {
1262 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1263 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1265 Optional<OrgOpenroadmDevice> deviceObject =
1266 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1267 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1268 if (!deviceObject.isPresent()) {
1269 LOG.error("Device with node id {} not found", nodeId);
1272 String startTimestamp = getCurrentTimestamp();
1274 Map<DegreeKey, Degree> degreeMap = deviceObject.orElseThrow().nonnullDegree();
1275 for (Map.Entry<DegreeKey, Degree> entry : degreeMap.entrySet()) {
1276 Degree degree = entry.getValue();
1277 String degreeNumber = degree.getDegreeNumber().toString();
1278 String maxWavelengths = degree.getMaxWavelengths().toString();
1279 String otdrPortCircuitPackName = degree.getOtdrPort().getCircuitPackName();
1280 String otdrPortPortName = degree.getOtdrPort().getPortName();
1281 persistDevDegreeCircuitPack(nodeId, degree, degreeNumber, connection);
1282 persistDevDegreeConnectionPort(nodeId, degree, degreeNumber, connection);
1283 //String mcCapabilitiesSlotWidthGranularity = "";
1284 //String mcCapabilitiesCenterFreqGranularity = "";
1285 //String mcCapabilitiesMinSlots = "";
1286 //String mcCapabilitiesMaxSlots = "";
1288 Object[] parameters = {nodeId,
1291 otdrPortCircuitPackName,
1293 //mcCapabilitiesSlotWidthGranularity,
1294 //mcCapabilitiesCenterFreqGranularity,
1295 //mcCapabilitiesMinSlots,
1296 //mcCapabilitiesMaxSlots,
1302 String query = Queries.getQuery().deviceDegreeInsert().get();
1303 LOG.info("Running {} query ", query);
1304 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1305 for (int j = 0; j < parameters.length; j++) {
1306 stmt.setObject(j + 1, parameters[j]);
1309 stmt.clearParameters();
1310 } catch (SQLException e) {
1311 LOG.error("Something wrong when storing devices degrees", e);
1318 private void persistDevDegreeCircuitPack(String nodeId, Degree degree, String degreeNumber, Connection connection) {
1320 String startTimestamp = getCurrentTimestamp();
1322 Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1323 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks>
1324 circuitPacksMap = degree.nonnullCircuitPacks();
1325 for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1326 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks> entry :
1327 circuitPacksMap.entrySet()) {
1330 String circuitPackIndex = entry.getValue().getIndex().toString();
1331 String circuitPackName = entry.getValue().getCircuitPackName();
1333 Object[] parameters = {nodeId,
1341 String query = Queries.getQuery().deviceDegreeCircuitPackInsert().get();
1342 LOG.info("Running {} query ", query);
1343 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1344 for (int j = 0; j < parameters.length; j++) {
1345 stmt.setObject(j + 1, parameters[j]);
1348 stmt.clearParameters();
1349 } catch (SQLException e) {
1350 LOG.error("Something wrong when storing devices degrees circuit packs", e);
1356 private void persistDevDegreeConnectionPort(String nodeId, Degree degree, String degreeNumber,
1357 Connection connection) {
1359 String startTimestamp = getCurrentTimestamp();
1361 Map<ConnectionPortsKey, ConnectionPorts> connectionPortsMap = degree.nonnullConnectionPorts();
1362 for (Map.Entry<ConnectionPortsKey, ConnectionPorts> entry : connectionPortsMap.entrySet()) {
1364 ConnectionPorts connectionPorts = entry.getValue();
1365 String connectionPortIndex = connectionPorts.getIndex().toString();
1366 String circuitPackName = connectionPorts.getCircuitPackName();
1367 String portName = connectionPorts.getPortName();
1369 Object[] parameters = {nodeId,
1371 connectionPortIndex,
1378 String query = Queries.getQuery().deviceDegreeConnectionPortInsert().get();
1379 LOG.info("Running {} query ", query);
1380 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1381 for (int j = 0; j < parameters.length; j++) {
1382 stmt.setObject(j + 1, parameters[j]);
1385 stmt.clearParameters();
1386 } catch (SQLException e) {
1387 LOG.error("Something wrong when storing devices degrees connection ports", e);
1394 private void persistDevSrg(String nodeId, Connection connection) {
1396 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1397 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1399 Optional<OrgOpenroadmDevice> deviceObject =
1400 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1401 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1402 if (!deviceObject.isPresent()) {
1403 LOG.error("Device with node id {} not found", nodeId);
1407 String startTimestamp = getCurrentTimestamp();
1409 Map<SharedRiskGroupKey, SharedRiskGroup> sharedRiskGroupMap = deviceObject.orElseThrow()
1410 .nonnullSharedRiskGroup();
1411 for (Map.Entry<SharedRiskGroupKey, SharedRiskGroup> entry : sharedRiskGroupMap.entrySet()) {
1412 SharedRiskGroup sharedRiskGroup = entry.getValue();
1413 String maxAddDropPorts = sharedRiskGroup.getMaxAddDropPorts().toString();
1414 String srgNumber = sharedRiskGroup.getSrgNumber().toString();
1415 //int wavelengthDuplicationEnu = sharedRiskGroup.getWavelengthDuplication().getIntValue();
1416 persistDevSrgCircuitPacks(nodeId, sharedRiskGroup, srgNumber, connection);
1417 //String currentProvisionedAddDropPorts = "";
1418 //String mcCapSlotWidthGranularity = "";
1419 //String mcCapCenterFreqGranularity = "";
1420 //String mcCapMinSlots = "";
1421 //String mcCapMaxSlots = "";
1423 Object[] parameters = {nodeId,
1425 //currentProvisionedAddDropPorts,
1428 //mcCapSlotWidthGranularity,
1429 //mcCapCenterFreqGranularity,
1437 String query = Queries.getQuery().deviceSharedRiskGroupInsert().get();
1438 LOG.info("Running {} query ", query);
1439 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1440 for (int j = 0; j < parameters.length; j++) {
1441 stmt.setObject(j + 1, parameters[j]);
1444 stmt.clearParameters();
1445 } catch (SQLException e) {
1446 LOG.error("Something wrong when storing devices SRG", e);
1452 private void persistDevSrgCircuitPacks(String nodeId, SharedRiskGroup sharedRiskGroup, String srgNumber,
1453 Connection connection) {
1455 String startTimestamp = getCurrentTimestamp();
1457 Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1458 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>
1459 circuitPacksMap = sharedRiskGroup.nonnullCircuitPacks();
1460 for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1461 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> entry :
1462 circuitPacksMap.entrySet()) {
1464 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks circuitPack =
1466 String circuitPackindex = circuitPack.getIndex().toString();
1467 String circuitPackName = circuitPack.getCircuitPackName();
1469 Object[] parameters = {nodeId,
1477 String query = Queries.getQuery().deviceSrgCircuitPackInsert().get();
1478 LOG.info("Running {} query ", query);
1479 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1480 for (int j = 0; j < parameters.length; j++) {
1481 stmt.setObject(j + 1, parameters[j]);
1484 stmt.clearParameters();
1485 } catch (SQLException e) {
1486 LOG.error("Something wrong when storing devices SRG circuit packs", e);
1492 private void persistDevRoadmConnections(String nodeId, Connection connection) {
1494 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1495 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1497 Optional<OrgOpenroadmDevice> deviceObject =
1498 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1499 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1500 if (!deviceObject.isPresent()) {
1501 LOG.error("Device with node id {} not found", nodeId);
1504 String startTimestamp = getCurrentTimestamp();
1506 Map<RoadmConnectionsKey, RoadmConnections> roadmConnectionsMap = deviceObject.orElseThrow()
1507 .nonnullRoadmConnections();
1508 for (Map.Entry<RoadmConnectionsKey, RoadmConnections> entry : roadmConnectionsMap.entrySet()) {
1509 RoadmConnections roadmConnections = entry.getValue();
1510 int opticalcontrolmodeEnu = roadmConnections.getOpticalControlMode().getIntValue();
1511 //String connectionName = "";
1512 //String connectionNumber = "";
1513 //String wavelengthNumber = "";
1514 String targetOutputPower = roadmConnections.getTargetOutputPower().toString();
1515 String srcIf = roadmConnections.getSource().getSrcIf();
1516 String dstIf = roadmConnections.getDestination().getDstIf();
1518 Object[] parameters = {nodeId,
1523 Integer.toString(opticalcontrolmodeEnu),
1532 String query = Queries.getQuery().deviceRoadmConnectionsInsert().get();
1533 LOG.info("Running {} query ", query);
1534 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1535 for (int j = 0; j < parameters.length; j++) {
1536 stmt.setObject(j + 1, parameters[j]);
1539 stmt.clearParameters();
1540 } catch (SQLException e) {
1541 LOG.error("Something wrong when storing devices ROADM connection ", e);
1548 private void persistDevConnectionMap(String nodeId, Connection connection) {
1550 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1551 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1553 Optional<OrgOpenroadmDevice> deviceObject =
1554 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1555 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1556 if (!deviceObject.isPresent()) {
1557 LOG.error("Device with node id {} not found", nodeId);
1560 String startTimestamp = getCurrentTimestamp();
1562 Map<ConnectionMapKey, ConnectionMap> connectionMapMap = deviceObject.orElseThrow().nonnullConnectionMap();
1563 for (Map.Entry<ConnectionMapKey, ConnectionMap> entry : connectionMapMap.entrySet()) {
1564 ConnectionMap connectionMap = entry.getValue();
1565 String connectionMapNumber = connectionMap.getConnectionMapNumber().toString();
1566 String sourceCircuitPackName = connectionMap.getSource().getCircuitPackName();
1567 String sourcePortName = connectionMap.getSource().getCircuitPackName();
1570 Object[] parameters = {nodeId,
1571 connectionMapNumber,
1572 sourceCircuitPackName,
1578 String query = Queries.getQuery().deviceConnectionMapInsert().get();
1579 LOG.info("Running {} query ", query);
1580 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1581 for (int j = 0; j < parameters.length; j++) {
1582 stmt.setObject(j + 1, parameters[j]);
1585 stmt.clearParameters();
1586 } catch (SQLException e) {
1587 LOG.error("Something wrong when storing devices connection map", e);
1593 private void persistDevWavelengthMap(String nodeId, Connection connection) {
1596 String wavelengthNumber="", centerFrequency="", wavelength="";;
1598 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1599 Optional<OrgOpenroadmDevice> deviceObject =
1600 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1601 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1604 String startTimestamp = getCurrentTimestamp();
1605 for (int i = 0; i<deviceObject.get().getWavelengthMap().getWavelengths().size(); i++) {
1606 Wavelengths wavelengths = deviceObject.get().getWavelengthMap().getWavelengths().get(i);
1607 wavelengthNumber=wavelengths.getWavelengthNumber().toString();
1608 centerFrequency=wavelengths.getCenterFrequency().toString();
1609 wavelength=wavelengths.getWavelength().toString();
1612 Object[] parameters = {nodeId,
1620 String query = Queries.getQuery().deviceWavelengthInsert().get();
1621 LOG.info("Running {} query ", query);
1622 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1623 for (int j = 0; j < parameters.length; j++) {
1624 stmt.setObject(j + 1, parameters[j]);
1627 stmt.clearParameters();
1628 } catch (SQLException e) {
1629 LOG.error("Something wrong when storing devices wavelength map", e);
1637 private void persistDevInterfaceTcm(String nodeId, String interfaceName, OduBuilder oduBuilder,
1638 Connection connection) {
1640 Map<TcmKey, Tcm> tcmMap = oduBuilder.getTcm();
1641 for (Map.Entry<TcmKey, Tcm> entry : tcmMap.entrySet()) {
1642 Tcm tcm = entry.getValue();
1644 Object[] parameters = prepareDevInterfaceTcmParameters(nodeId, interfaceName, tcm);
1646 String query = Queries.getQuery().deviceInterfacesInsert().get();
1647 LOG.info("Running {} query ", query);
1648 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1649 for (int j = 0; j < parameters.length; j++) {
1650 stmt.setObject(j + 1, parameters[j]);
1653 stmt.clearParameters();
1654 } catch (SQLException e) {
1655 LOG.error("Something wrong when storing devices interface tcm", e);
1660 private void persistDevInterfaceOtnOduTxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1661 Connection connection) {
1663 Map<TxMsiKey, TxMsi> txMsi2Map = oduBuilder.getOpu().getMsi().getTxMsi();
1664 if (txMsi2Map == null) {
1665 LOG.error("Null txMsi2Map for node {}", nodeId);
1668 for (Map.Entry<TxMsiKey, TxMsi> entry : txMsi2Map.entrySet()) {
1669 TxMsi txMsi = entry.getValue();
1670 Object[] parameters = prepareDevInterfaceOtnOduTxMsiParameters(nodeId, interfaceName, txMsi);
1672 String query = Queries.getQuery().deviceInterfaceOtnOduTxMsiInsert().get();
1673 LOG.info("Running {} query ", query);
1674 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1675 for (int j = 0; j < parameters.length; j++) {
1676 stmt.setObject(j + 1, parameters[j]);
1679 stmt.clearParameters();
1680 } catch (SQLException e) {
1681 LOG.error("Something wrong when storing devices interface OTN ODU Tx MSI", e);
1687 private void persistDevInterfaceOtnOduRxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1688 Connection connection) {
1690 Map<RxMsiKey, RxMsi> rxMsi2Map = oduBuilder.getOpu().getMsi().getRxMsi();
1691 if (rxMsi2Map == null) {
1692 LOG.error("Null rxMsi2Map for node {}", nodeId);
1695 for (Map.Entry<RxMsiKey, RxMsi> entry : rxMsi2Map.entrySet()) {
1696 RxMsi rxMsi = entry.getValue();
1698 Object[] parameters = prepareDevInterfaceOtnOduRxMsiParameters(nodeId, interfaceName, rxMsi);
1700 String query = Queries.getQuery().deviceInterfaceOtnOduRxMsiInsert().get();
1701 LOG.info("Running {} query ", query);
1702 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1703 for (int j = 0; j < parameters.length; j++) {
1704 stmt.setObject(j + 1, parameters[j]);
1707 stmt.clearParameters();
1708 } catch (SQLException e) {
1709 LOG.error("Something wrong when storing devices interface OTN ODU Rx MSI", e);
1715 private void persistDevInterfaceOtnOduExpMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1716 Connection connection) {
1718 Map<ExpMsiKey, ExpMsi> expMsi2Map = oduBuilder.getOpu().getMsi().getExpMsi();
1719 if (expMsi2Map == null) {
1720 LOG.error("Null expMsi2Map for node {}", nodeId);
1723 for (Map.Entry<ExpMsiKey, ExpMsi> entry : expMsi2Map.entrySet()) {
1724 ExpMsi expMsi = entry.getValue();
1726 Object[] parameters = prepareDevInterfaceOtnOduExpMsiParameters(nodeId, interfaceName, expMsi);
1728 String query = Queries.getQuery().deviceInterfaceOtnOduExpMsiInsert().get();
1729 LOG.info("Running {} query ", query);
1730 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1731 for (int j = 0; j < parameters.length; j++) {
1732 stmt.setObject(j + 1, parameters[j]);
1735 stmt.clearParameters();
1736 } catch (SQLException e) {
1737 LOG.error("Something wrong when storing devices interface OTN ODU Exp MSI", e);