2 * Copyright © 2017 AT&T and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.transportpce.inventory;
11 import static java.util.Objects.requireNonNull;
12 import static org.opendaylight.transportpce.inventory.utils.StringUtils.getCurrentTimestamp;
13 import static org.opendaylight.transportpce.inventory.utils.StringUtils.prepareDashString;
14 import static org.opendaylight.transportpce.inventory.utils.StringUtils.prepareEmptyString;
16 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
17 import java.sql.Connection;
18 import java.sql.PreparedStatement;
19 import java.sql.ResultSet;
20 import java.sql.SQLException;
22 import java.util.Optional;
23 import java.util.concurrent.ExecutionException;
24 import javax.sql.DataSource;
25 import org.eclipse.jdt.annotation.NonNull;
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.pack.Ports;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.PortsKey;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPorts;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPortsKey;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLink;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLinkKey;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceKey;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLink;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLinkKey;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMapKey;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.DegreeKey;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnections;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLink;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLinkKey;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.Slots;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.SlotsKey;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.Shelves;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.ShelvesKey;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.Interface1;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.ethernet.container.EthernetBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfig;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfigKey;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfName;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfNameKey;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.och.container.OchBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.OtsBuilder;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.Tcm;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.TcmKey;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.container.OduBuilder;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsi;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsiKey;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsi;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsiKey;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsi;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsiKey;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.otu.container.OtuBuilder;
81 import org.opendaylight.yang.gen.v1.http.org.openroadm.wavelength.map.rev161014.wavelength.map.g.Wavelengths;
82 import org.opendaylight.yang.gen.v1.http.org.openroadm.wavelength.map.rev161014.wavelength.map.g.WavelengthsKey;
83 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
84 import org.slf4j.Logger;
85 import org.slf4j.LoggerFactory;
88 value = "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING",
89 justification = "TODO review the SQL statement generation process")
90 public class INode121 {
92 private static final Logger LOG = LoggerFactory.getLogger(INode121.class);
94 private final DataSource dataSource;
95 private final DeviceTransactionManager deviceTransactionManager;
97 public INode121(DataSource dataSource, DeviceTransactionManager deviceTransactionManager) {
98 this.dataSource = dataSource;
99 this.deviceTransactionManager = deviceTransactionManager;
102 public boolean addNode(String deviceId) {
104 InstanceIdentifier<Info> infoIID = InstanceIdentifier
105 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
108 Optional<Info> infoOpt =
109 deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.OPERATIONAL, infoIID,
110 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
112 if (!infoOpt.isPresent()) {
113 LOG.warn("Could not get device info from DataBroker");
116 deviceInfo = infoOpt.orElseThrow();
117 boolean sqlResult = false;
118 String query = Queries.getQuery().deviceInfoInsert().get();
119 LOG.info("Running {} query ", query);
120 try (Connection connection = dataSource.getConnection();
121 PreparedStatement preparedStatement = connection.prepareStatement(query)) {
122 Object[] prepareParameters = prepareDeviceInfoParameters(deviceInfo);
123 for (int i = 0; i < prepareParameters.length; i++) {
124 LOG.debug("Parameter {} has value {}", i + 1, prepareParameters[i]);
125 preparedStatement.setObject(i + 1, prepareParameters[i]);
128 int executeUpdate = preparedStatement.executeUpdate();
129 LOG.info("{} entries were added", executeUpdate);
132 LOG.debug("iNode AddNode call complete");
133 getRoadmShelves(deviceId);
134 LOG.debug("iNode getRoadmShelves call complete");
135 getCircuitPacks(deviceId);
136 LOG.debug("iNode getCircuitPacks call complete");
138 LOG.debug("iNode persist interfaces call");
139 persistDevInterfaces(deviceId, connection);
140 LOG.debug("iNode persist interfaces call complete");
143 LOG.debug("iNode persist protocols call");
144 persistDevProtocols(deviceId, connection);
145 LOG.debug("iNode persist protocols call complete");
148 LOG.debug("iNode persist wavelength map call");
149 persistDevWavelengthMap(deviceId, connection);
150 LOG.debug("iNode persist wavelength map call complete");
152 LOG.debug("iNode persist internal links map call");
153 persistDevInternalLinks(deviceId, connection);
154 LOG.debug("iNode persist internal links map call complete");
156 LOG.debug("iNode persist Physical links map call");
157 persistDevPhysicalLinks(deviceId, connection);
158 LOG.debug("iNode persist Physical links map call complete");
160 LOG.debug("iNode persist External links map call");
161 persistDevExternalLinks(deviceId, connection);
162 LOG.debug("iNode persist External links map call complete");
164 LOG.debug("iNode persist degree map call");
165 persistDevDegree(deviceId, connection);
166 LOG.debug("iNode persist degree map call complete");
168 LOG.debug("iNode persist srg map call");
169 persistDevSrg(deviceId, connection);
170 LOG.debug("iNode persist srg map call complete");
172 LOG.debug("iNode persist Roadm Connections call");
173 persistDevRoadmConnections(deviceId, connection);
174 LOG.debug("iNode persist Roadm Connections call complete");
176 LOG.debug("iNode persist Connection Map call");
177 persistDevConnectionMap(deviceId, connection);
178 LOG.debug("iNode persist Connection Map call complete");
180 } catch (SQLException | InterruptedException | ExecutionException e) {
181 LOG.error("Something wrong when storing node into DB", e);
186 public boolean nodeExists(String nodeId) {
187 String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?";
189 LOG.info("Checking if {} exists in DB", nodeId);
190 try (Connection connection = dataSource.getConnection();
191 PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) {
192 preparedStmt.setString(1, nodeId);
193 try (ResultSet rs = preparedStmt.executeQuery()) {
195 nodeExists = rs.getInt("node_exists");
196 LOG.debug("Found {} devices matching {}", nodeExists, nodeId);
199 } catch (SQLException e) {
200 LOG.error("Something wrong when fetching node in DB", e);
202 return nodeExists != 0;
205 public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException {
206 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
207 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
209 Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
210 LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
211 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
212 if (!deviceObject.isPresent()) {
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> shelveEntry : shelvesMap.entrySet()) {
219 Shelves shelve = shelveEntry.getValue();
220 String shelfName = shelve.getShelfName();
221 LOG.info("Getting Shelve Details of {}", shelfName);
222 if (shelve.getSlots() != null) {
223 LOG.info("Slot Size {} ", shelve.getSlots().size());
224 persistShelveSlots(nodeId, shelve, connection);
226 LOG.info("No Slots for shelf {}", shelfName);
229 persistShelves(nodeId, connection, shelve);
231 } catch (SQLException e1) {
232 LOG.error("Something wrong when fetching ROADM shelves in DB", e1);
236 public void getCircuitPacks(String nodeId) throws InterruptedException, ExecutionException {
237 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
238 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
240 Optional<OrgOpenroadmDevice> deviceObject =
241 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
242 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
243 if (!deviceObject.isPresent()) {
244 LOG.warn("Device object {} was not found", nodeId);
247 Map<CircuitPacksKey, CircuitPacks> circuitPacksMap = deviceObject.orElseThrow().nonnullCircuitPacks();
248 LOG.info("Circuit pack size {}", circuitPacksMap.size());
250 try (Connection connection = requireNonNull(dataSource.getConnection())) {
251 for (Map.Entry<CircuitPacksKey, CircuitPacks> circuitPackEntry : circuitPacksMap.entrySet()) {
252 CircuitPacks cp = circuitPackEntry.getValue();
254 if (cp.getCpSlots() != null) {
255 persistCircuitPacksSlots(nodeId, cp, connection);
257 LOG.info("Everything {}", cp);
258 LOG.info("CP is {}", cp);
260 //persistPorts(cp, connection);
261 if (cp.getPorts() != null) {
262 persistCPPorts(nodeId, connection, cp);
264 persistCircuitPacks(nodeId, connection, cp);
266 } catch (SQLException e1) {
267 LOG.error("Something wrong when fetching Circuit Packs in DB", e1);
271 private void persistCircuitPacks(String nodeId, Connection connection, CircuitPacks cp) {
272 Object[] parameters = prepareCircuitPacksParameters(nodeId, cp);
273 String query = Queries.getQuery().deviceCircuitPackInsert().get();
274 LOG.info("Running {} query ", query);
275 try (PreparedStatement stmt = connection.prepareStatement(query)) {
276 for (int j = 0; j < parameters.length; j++) {
277 stmt.setObject(j + 1, parameters[j]);
280 stmt.clearParameters();
281 } catch (SQLException e) {
282 LOG.error("Something wrong when storing Circuit Packs in DB", e);
286 private void persistShelves(String nodeId, Connection connection, Shelves shelve) {
287 Object[] shelvesParameter = prepareShelvesParameters(nodeId, shelve);
288 String query = Queries.getQuery().deviceShelfInsert().get();
289 LOG.info("Running {} query ", query);
290 try (PreparedStatement preparedStmt = connection.prepareStatement(query)) {
291 for (int j = 0; j < shelvesParameter.length; j++) {
292 preparedStmt.setObject(j + 1, shelvesParameter[j]);
294 preparedStmt.execute();
295 preparedStmt.clearParameters();
296 } catch (SQLException e) {
297 LOG.error("Something wrong when storing shelves in DB", e);
301 private void persistShelveSlots(String nodeId, Shelves shelves, Connection connection) {
302 String startTimetampStr = getCurrentTimestamp();
303 Map<SlotsKey, Slots> slotsMap = shelves.nonnullSlots();
304 for (Map.Entry<SlotsKey, Slots> slotEntry : slotsMap.entrySet()) {
305 Slots slot = slotEntry.getValue();
306 LOG.info("Getting Slot Details of {}", slot.getSlotName());
307 Object[] parameters = new Object[]{nodeId,
308 shelves.getShelfName(),
311 slot.getProvisionedCircuitPack(),
315 String query = Queries.getQuery().deviceShelfSlotInsert().get();
316 LOG.info("Running {} query ", query);
317 try (PreparedStatement stmt = connection.prepareStatement(query)) {
318 for (int j = 0; j < parameters.length; j++) {
319 stmt.setObject(j + 1, parameters[j]);
322 stmt.clearParameters();
323 } catch (SQLException e) {
324 LOG.error("Something wrong when storing shelves slots in DB", e);
330 private void persistCircuitPacksSlots(String nodeId, CircuitPacks circuitPacks, Connection connection) {
331 String startTimetampStr = getCurrentTimestamp();
332 Map<CpSlotsKey, CpSlots> cpSlotsMap = circuitPacks.nonnullCpSlots();
333 for (Map.Entry<CpSlotsKey, CpSlots> cpSlotEntry: cpSlotsMap.entrySet()) {
334 CpSlots cpSlot = cpSlotEntry.getValue();
336 Object[] parameters = new Object[]{nodeId,
337 circuitPacks.getCircuitPackName(),
338 cpSlot.getSlotName(),
340 cpSlot.getProvisionedCircuitPack(),
345 String query = Queries.getQuery().deviceCPSlotInsert().get();
346 LOG.info("Running {} query ", query);
347 try (PreparedStatement stmt = connection.prepareStatement(query)) {
348 for (int j = 0; j < parameters.length; j++) {
349 stmt.setObject(j + 1, parameters[j]);
352 stmt.clearParameters();
353 } catch (SQLException e) {
354 LOG.error("Something wrong when storing Cirtcuits Packs slots in DB", e);
360 * Prepares parameters for device insert query.
362 * @param deviceInfo device information
363 * @return Object an object
365 private static Object[] prepareDeviceInfoParameters(Info deviceInfo) {
366 String startTimetampStr = getCurrentTimestamp();
368 String nodeId = prepareDashString(deviceInfo.getNodeId());
369 Long nodeNumber = deviceInfo.getNodeNumber().toJava();
370 String nodeTypeEnu = deviceInfo.getNodeType().getName();
371 String clli = prepareDashString(deviceInfo.getClli());
372 String vendor = prepareDashString(deviceInfo.getVendor());
373 String model = prepareDashString(deviceInfo.getModel());
374 String serialId = prepareDashString(deviceInfo.getSerialId());
375 String ipAddress = prepareDashString(deviceInfo.getIpAddress().getIpv4Address().getValue());
376 String prefixLength = prepareDashString(deviceInfo.getPrefixLength());
377 String defaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue());
378 String sourceEnum = deviceInfo.getSource().getName();
379 String currentIpAddress = prepareDashString(deviceInfo.getCurrentIpAddress().getIpv4Address().getValue());
380 String currentPrefixLength = prepareDashString(deviceInfo.getCurrentPrefixLength());
381 String currentDefaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue());
382 String macAddress = prepareDashString(deviceInfo.getMacAddress().getValue());
383 String softwareVersion = prepareDashString(deviceInfo.getSoftwareVersion());
384 //String openroadmVersion = "1.2.1";
385 String template = prepareDashString(deviceInfo.getTemplate());
386 String currentDatetime = prepareDashString(deviceInfo.getCurrentDatetime().getValue());
387 String geoLatitude = (deviceInfo.getGeoLocation() != null
388 ? prepareDashString(deviceInfo.getGeoLocation().getLatitude()) : "");
389 String geoLongitude = (deviceInfo.getGeoLocation() != null
390 ? prepareDashString(deviceInfo.getGeoLocation().getLongitude()) : "");
391 String maxDegrees = (deviceInfo.getMaxDegrees() == null ? "-1" : prepareDashString(deviceInfo.getMaxDegrees()));
392 String maxSrgs = (deviceInfo.getMaxSrgs() == null ? "-1" : prepareDashString(deviceInfo.getMaxSrgs()));
393 String swVersion = prepareDashString(deviceInfo.getSoftwareVersion()); //sw_version
394 String swValidationTimer = prepareDashString(""); //sw_validation_timer
395 String activationDateTime = prepareDashString(""); //activation_date_time
396 //Integer maxNumBin15minHistoricalPm = null;
397 //Integer maxNumBin24hourHistoricalPm = null;
398 /*jsonDevInfo = JsonStringBuilder.getDevInfoJson().replace("$$NODE-ID$$",nodeId)
399 .replace("$$NODE-NUMBER$$", nodeNumber)
400 .replace("$$NODE-TYPE$$",nodeType)
401 .replace("$$CLLI$$",clli)
402 .replace("$$VENDOR$$",vendor)
403 .replace("$$MODEL$$",model)
404 .replace("$$SERIAL-ID$$",serialId)
405 .replace("$$IPADDRESS$$",ipAddress)
406 .replace("$$PREFIX-LENGTH$$",prefixLength)
407 .replace("$$DEFAULTGATEWAY$$",defaultGateway)
408 .replace("$$SOURCE$$",String.valueOf(source))
409 .replace("$$CURRENT-IPADDRESS$$",currentIpAddress)
410 .replace("$$CURRENT-PREFIX-LENGTH$$",currentPrefixLength)
411 .replace("$$CURRENT-DEFAULTGATEWAY$$",currentDefailtGateway)
412 .replace("$$MACADDRESS$$",macAddress)
413 .replace("$$SOFTWAREVERSION$$",softwareVersion)
414 .replace("$$OPENROADM-VERSION$$",openroadmVersion)
415 .replace("$$TEMPLATE$$",template)
416 .replace("$$CURRENT-DATETIME$$",currentDatetime)
417 .replace("$$LATITUDE$$",latitude)
418 .replace("$$LONGITUDE$$",longitude)
419 .replace("$$MAX-DEGREES$$",maxDegrees)
420 .replace("$$MAX-SRGS$$",maxSrgs)
421 .replace("$$MAX-NUM-BIN-15MIN-HISTORICAL-PM$$",prepareDashString(""))
422 .replace("$$MAX-NUM-BIN-24HOUR-HISTORICAL-PM$$",prepareDashString(""))
423 .replace("$$SW-VERSION$$",swVersion)
424 .replace("$$SW-VALIDATION-TIMER$$",swValidationTimer)
425 .replace("$$ACTIVATION-DATE-TIME$$",activationDateTime);*/
442 currentDefaultGateway,
453 //maxNumBin15minHistoricalPm,
454 //maxNumBin24hourHistoricalPm,
465 private static Object[] prepareShelvesParameters(String nodeId, Shelves shelve) {
466 String startTimestamp = getCurrentTimestamp();
468 return new Object[]{nodeId,
469 shelve.getShelfName(),
470 shelve.getShelfType(),
472 shelve.getShelfPosition(),
473 (shelve.getAdministrativeState() == null ? null : shelve.getAdministrativeState().getIntValue()),
476 shelve.getSerialId(),
478 shelve.getProductCode(),
479 (shelve.getManufactureDate() == null ? null : shelve.getManufactureDate().getValue()),
481 shelve.getHardwareVersion(),
482 (shelve.getOperationalState() == null ? null : shelve.getOperationalState().getIntValue()),
483 (shelve.getEquipmentState() == null ? null : shelve.getEquipmentState().getIntValue()),
484 (shelve.getDueDate() == null ? null : shelve.getDueDate().getValue()),
490 private static Object[] prepareCPPortsParameters(String nodeId, CircuitPacks circuitPacks, Ports cpPort) {
492 String circuitPackName = circuitPacks.getCircuitPackName();
493 String portName = cpPort.getPortName();
494 String portType = cpPort.getPortType();
495 String portQualEnu = String.valueOf((cpPort.getPortQual() == null ? "-1" : cpPort.getPortQual().getName()));
496 String portWavelengthTypeEnu = "-1"; //cpPort.getPortWavelengthType().getIntValue(); /* Check error*/
497 String portDirectionEnu = String.valueOf((cpPort.getPortDirection() == null ? "" :
498 cpPort.getPortDirection().getName()));
499 String label = cpPort.getLabel();
500 String circuitId = cpPort.getCircuitId();
501 String administrativeStateEnu = (cpPort.getAdministrativeState() == null ? "" :
502 cpPort.getAdministrativeState().getName());
503 String operationalStateEnu =
504 (cpPort.getOperationalState() == null ? "" : cpPort.getOperationalState().getName());
505 String logicalConnectionPoint = cpPort.getLogicalConnectionPoint();
506 String parentPortCircuitPackName = (cpPort.getPartnerPort() == null ? "" :
507 (cpPort.getPartnerPort().getCircuitPackName() == null ? "" : cpPort.getPartnerPort().getCircuitPackName()));
508 String partnerPortPortName = (cpPort.getPartnerPort() == null ? "" :
509 (cpPort.getPartnerPort().getPortName() == null ? "" : cpPort.getPartnerPort().getPortName()));
510 String partnerPortCircuitPackName = (cpPort.getParentPort() == null ? "" :
511 (cpPort.getParentPort().getCircuitPackName() == null ? "" : cpPort.getParentPort().getCircuitPackName()));
512 String parentPortPortName = (cpPort.getParentPort() == null ? "" :
513 (cpPort.getParentPort().getPortName() == null ? "" : cpPort.getParentPort().toString()));
514 String roadmPortPortPowerCapabilityMinRx = (cpPort.getRoadmPort() == null ? "" :
515 (cpPort.getRoadmPort().getPortPowerCapabilityMinRx() == null ? "" :
516 cpPort.getRoadmPort().getPortPowerCapabilityMinRx().toString()));
517 String roadmPortPortPowerCapabilityMinTx = (cpPort.getRoadmPort() == null ? "" :
518 (cpPort.getRoadmPort().getPortPowerCapabilityMinTx() == null ? "" :
519 cpPort.getRoadmPort().getPortPowerCapabilityMinTx().toString()));
520 String roadmPortPortPowerCapabilityMaxRx = (cpPort.getRoadmPort() == null ? "" :
521 (cpPort.getRoadmPort().getPortPowerCapabilityMaxRx() == null ? "" :
522 cpPort.getRoadmPort().getPortPowerCapabilityMaxRx().toString()));
523 String roadmPortPortPowerCapabilityMaxTx = (cpPort.getRoadmPort() == null ? "" :
524 (cpPort.getRoadmPort().getPortPowerCapabilityMaxTx() == null ? "" :
525 cpPort.getRoadmPort().getPortPowerCapabilityMaxTx().toString()));
526 //String roadmPortCapableWavelengths = "";
527 //String roadmPortAvailableWavelengths = "";
528 //String roadmPortUsedWavelengths = "";
529 String transponderPortPortPowerCapabilityMinRx = (cpPort.getTransponderPort() == null ? "" :
530 (cpPort.getTransponderPort().getPortPowerCapabilityMinRx() == null ? "" :
531 cpPort.getTransponderPort().getPortPowerCapabilityMinRx().toString()));
532 String transponderPortPortPowerCapabilityMinTx = (cpPort.getTransponderPort() == null ? "" :
533 (cpPort.getTransponderPort().getPortPowerCapabilityMinTx() == null ? "" :
534 cpPort.getTransponderPort().getPortPowerCapabilityMinTx().toString()));
535 String transponderPortPortPowerCapabilityMaxRx = (cpPort.getTransponderPort() == null ? "" :
536 (cpPort.getTransponderPort().getPortPowerCapabilityMaxRx() == null ? "" :
537 cpPort.getTransponderPort().getPortPowerCapabilityMaxRx().toString()));
538 String transponderPortPortPowerCapabilityMaxTx = (cpPort.getTransponderPort() == null ? "" :
539 (cpPort.getTransponderPort().getPortPowerCapabilityMaxTx() == null ? "" :
540 cpPort.getTransponderPort().getPortPowerCapabilityMaxTx().toString()));
541 //String transponderPortCapableWavelengths = "";
542 String otdrPortLaunchCableLength = (cpPort.getOtdrPort() == null ? "" :
543 (cpPort.getOtdrPort().getLaunchCableLength() == null ? "" :
544 cpPort.getOtdrPort().getLaunchCableLength().toString()));
545 String otdrPortPortDirection = (cpPort.getOtdrPort() == null ? "-1" :
546 (cpPort.getOtdrPort().getPortDirection() == null ? "-1" :
547 Integer.toString(cpPort.getOtdrPort().getPortDirection().getIntValue())));
548 //String ilaPortPortPowerCapabilityMixRx = "";
549 //String ilaPortPortPowerCapabilityMixTx = "";
550 //String ilaPortPortPowerCapabilityMaxRx = "";
551 //String ilaPortPortPowerCapabilityMaxTx = "";
553 String startTimestamp = getCurrentTimestamp();
555 return new Object[]{nodeId,
560 portWavelengthTypeEnu,
564 administrativeStateEnu,
566 logicalConnectionPoint,
567 partnerPortCircuitPackName,
569 parentPortCircuitPackName,
571 roadmPortPortPowerCapabilityMinRx,
572 roadmPortPortPowerCapabilityMinTx,
573 roadmPortPortPowerCapabilityMaxRx,
574 roadmPortPortPowerCapabilityMaxTx,
575 //roadmPortCapableWavelengths,
576 //roadmPortAvailableWavelengths,
577 //roadmPortUsedWavelengths,
579 transponderPortPortPowerCapabilityMinRx,
580 transponderPortPortPowerCapabilityMinTx,
581 transponderPortPortPowerCapabilityMaxRx,
582 transponderPortPortPowerCapabilityMaxTx,
583 //transponderPortCapableWavelengths,
585 otdrPortLaunchCableLength,
586 otdrPortPortDirection,
587 //ilaPortPortPowerCapabilityMixRx,
588 //ilaPortPortPowerCapabilityMixTx,
589 //ilaPortPortPowerCapabilityMaxRx,
590 //ilaPortPortPowerCapabilityMaxTx,
598 private static Object[] prepareCircuitPacksParameters(String nodeId, CircuitPacks cpack) {
599 String startTimestamp = getCurrentTimestamp();
600 return new Object[]{nodeId,
601 cpack.getCircuitPackName(),
602 cpack.getCircuitPackType(),
603 cpack.getCircuitPackProductCode(),
604 (cpack.getAdministrativeState() == null ? "" : cpack.getAdministrativeState().getIntValue()),
609 cpack.getProductCode(),
610 (cpack.getManufactureDate() == null ? "" : cpack.getManufactureDate().getValue()),
612 cpack.getHardwareVersion(),
613 (cpack.getOperationalState() == null ? -1 : cpack.getOperationalState().getIntValue()),
614 cpack.getCircuitPackCategory().getType().getIntValue(),
615 cpack.getCircuitPackCategory().getExtension(),
616 (cpack.getEquipmentState() == null ? -1 : cpack.getEquipmentState().getIntValue()),
617 cpack.getCircuitPackMode(),
621 prepareEmptyString(cpack.getDueDate()),
622 prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" :
623 ((cpack.getParentCircuitPack().getCircuitPackName() == null) ? "" :
624 cpack.getParentCircuitPack().getCircuitPackName())
626 prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" :
627 ((cpack.getParentCircuitPack().getCpSlotName() == null) ? "" :
628 cpack.getParentCircuitPack().getCpSlotName())
635 private void persistCPPorts(String nodeId, Connection connection, CircuitPacks circuitPacks) {
637 Map<PortsKey, Ports> nonnullPorts = circuitPacks.nonnullPorts();
638 for (Map.Entry<PortsKey, Ports> entry : nonnullPorts.entrySet()) {
639 Object[] cpPortsParameters = prepareCPPortsParameters(nodeId, circuitPacks, entry.getValue());
640 String query = Queries.getQuery().deviceCPPortInsert().get();
641 LOG.info("Running {} query ", query);
642 try (PreparedStatement preparedStmt = connection.prepareStatement(query)) {
643 for (int j = 0; j < cpPortsParameters.length; j++) {
644 preparedStmt.setObject(j + 1, cpPortsParameters[j]);
646 preparedStmt.execute();
647 preparedStmt.clearParameters();
648 } catch (SQLException e) {
649 LOG.error("Something wrong when storing Cirtcuits Packs Ports in DB", e);
655 private Object[] prepareDevInterfaceParameters(String nodeId, Interface deviceInterface, Connection connection) {
657 String ethernetDuplexEnu = "";
658 String ethernetAutoNegotiationEnu = "";
659 String maintTestsignalTestpatternEnu = "";
660 String maintTestsignalTypeEnu = "";
661 String otuFecEnu = "";
662 String otuMaintTypeEnu = "";
663 //String otsFiberTypeEnu = "";
664 String ethernetSpeed = "-1";
665 String ethernetFec = "";
666 String ethernetMtu = "-1";
667 String ethernetCurrSpeed = "";
668 String ethernetCurrDuplex = "-1";
669 //String mciMcttpMinFreq = "";
670 //String mciMcttpMaxFreq = "";
671 //String mciMcttpCenterFreq = "";
672 //String mciMcttpSlotWidth = "";
673 //String mciNmcCtpFrequency = "";
674 //String mciNmcCtpWidth = "";
676 //String ochFrequency = "";
677 //String ochWidth = "";
678 String ochWavelengthNumber = "";
679 String ochModulationFormat = "";
680 String ochTransmitPower = "";
681 String otsSpanLossReceive = "";
682 String otsSpanLossTransmit = "";
683 //String otsIngressSpanLossAgingMargin = "";
684 //String otsEolMaxLoadPin = "";
686 //String oduFunction = "";
687 String oduMonitoringMode = "";
688 //String oduNoOamFunction = "";
689 String oduProactiveDelayMeasurementEnabled = "";
690 //String oduPoaTribPortNumber = "-1";
691 //String oduTxSapi = "";
692 //String oduTxDapi = "";
693 //String oduTxOperator = "";
694 //String oduAcceptedSapi = "";
695 //String oduAcceptedDapi = "";
696 //String oduAcceptedOperator = "";
697 //String oduExpectedSapi = "";
698 //String oduExpectedDapi = "";
699 //String oduTimActEnabled = "";
700 //String oduTimDetectMode = "";
701 //String oduDegmIntervals = "-1";
702 //String oduDegthrPercentage = "-1";
703 String opuPayloadType = "";
704 String opuRxPayloadType = "";
705 String opuExpPayloadType = "";
706 String opuPayloadInterface = "";
707 String maintTestsignalEnabled = "";
708 String maintTestsignalBiterrors = "-1";
709 String maintTestsignalBiterrorsterminal = "-1";
710 String maintTestsignalSyncseconds = "-1";
711 String maintTestsignalSyncsecondsterminal = "-1";
713 //String otuTxSapi = "";
714 //String otuTxDapi = "";
715 //String otuTxOperator = "";
716 //String otuAcceptedSapi = "";
717 //String otuAcceptedDapi = "";
718 //String otuAcceptedOperator = "";
719 //String otuExpectedSapi = "";
720 //String otuExpectedDapi = "";
721 //String otuTimActEnabled = "";
722 //String otuTimDetectMode = "";
723 //String otuDegmIntervals = "-1";
724 //String otuDegthrPercentage = "-1";
725 String otuMaintLoopbackEnabled = "";
726 //String mtOtuRate = "";
727 //String mtOtuFec = "";
728 //String mtOtuMaintLoopback = "";
729 //String mtOtuEnabled = "";
730 //String mtOtuType = "";
732 String name = deviceInterface.getName();
733 String description = deviceInterface.getDescription();
734 String type = deviceInterface.getType().toString();
735 String administrativeStateEnu = deviceInterface.getAdministrativeState().getName();
736 int operationalState = deviceInterface.getOperationalState().getIntValue();
737 String circuitId = deviceInterface.getCircuitId();
738 String supportingInterface = deviceInterface.getSupportingInterface();
739 String supportingCircuitPackName = deviceInterface.getSupportingCircuitPackName();
740 String supportingPort = deviceInterface.getSupportingPort();
742 switch (deviceInterface.getType().toString()) {
745 //EthernetBuilder ethIfBuilder = new EthernetBuilder();
746 EthernetBuilder ethIfBuilder = new EthernetBuilder(deviceInterface.augmentation(Interface1.class)
748 ethernetSpeed = (ethIfBuilder.getSpeed() == null ? "-1" :
749 Integer.toString(ethIfBuilder.getSpeed().intValue()));
750 ethernetFec = ethIfBuilder.getFec().getName();
751 ethernetDuplexEnu = (ethIfBuilder.getDuplex() == null ? "" : ethIfBuilder.getDuplex().getName());
752 ethernetMtu = ethIfBuilder.getMtu().toString();
753 ethernetAutoNegotiationEnu = ethIfBuilder.getAutoNegotiation().getName();
754 ethernetCurrSpeed = ethIfBuilder.getCurrSpeed();
755 ethernetCurrDuplex = ethIfBuilder.getCurrDuplex();
759 OchBuilder ochIfBuilder = new OchBuilder(deviceInterface.augmentation(
760 org.opendaylight.yang.gen.v1
761 .http.org.openroadm.optical.channel.interfaces.rev161014.Interface1.class)
763 ochRate = ochIfBuilder.getRate().toString();
764 ochWavelengthNumber = ochIfBuilder.getWavelengthNumber().toString();
765 ochModulationFormat = ochIfBuilder.getModulationFormat().getName();
766 ochTransmitPower = ochIfBuilder.getTransmitPower().toString();
770 OtsBuilder otsIfBuilder = new OtsBuilder(deviceInterface.augmentation(
771 org.opendaylight.yang.gen.v1
772 .http.org.openroadm.optical.transport.interfaces.rev161014.Interface1.class)
774 //otsFiberTypeEnu = String.valueOf(otsIfBuilder.getFiberType().getIntValue());
775 otsSpanLossReceive = otsIfBuilder.getSpanLossReceive().toString();
776 otsSpanLossTransmit = otsIfBuilder.getSpanLossTransmit().toString();
780 OduBuilder oduIfBuilder = new OduBuilder(deviceInterface.augmentation(
781 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.Interface1.class)
783 oduRate = String.valueOf(oduIfBuilder.getRate());
784 oduMonitoringMode = oduIfBuilder.getMonitoringMode().getName();
785 oduProactiveDelayMeasurementEnabled = oduIfBuilder.getProactiveDelayMeasurementEnabled().toString();
787 persistDevInterfaceTcm(nodeId, name, oduIfBuilder, connection);
788 persistDevInterfaceOtnOduTxMsi(nodeId, name, oduIfBuilder, connection);
789 persistDevInterfaceOtnOduRxMsi(nodeId, name, oduIfBuilder, connection);
790 persistDevInterfaceOtnOduExpMsi(nodeId, name, oduIfBuilder, connection);
792 opuPayloadType = oduIfBuilder.getOpu().getPayloadType();
793 opuRxPayloadType = oduIfBuilder.getOpu().getRxPayloadType();
794 opuExpPayloadType = oduIfBuilder.getOpu().getExpPayloadType();
795 opuPayloadInterface = oduIfBuilder.getOpu().getPayloadInterface();
796 /*persistDevInterfaceOtnOduTxMsi(nodeId,name,oduIfBuilder,connection);
797 persistDevInterfaceOtnOduRxMsi(nodeId,name,oduIfBuilder,connection);
798 persistDevInterfaceOtnOduExpMsi(nodeId,name,oduIfBuilder,connection); */
799 maintTestsignalEnabled = oduIfBuilder.getMaintTestsignal().getEnabled().toString();
800 maintTestsignalTestpatternEnu = oduIfBuilder.getMaintTestsignal().getTestPattern().getName();
801 maintTestsignalTypeEnu = oduIfBuilder.getMaintTestsignal().getType().getName();
802 maintTestsignalBiterrors = Integer.toString(
803 oduIfBuilder.getMaintTestsignal().getBitErrors().intValue());
804 maintTestsignalBiterrorsterminal = oduIfBuilder.getMaintTestsignal().getBitErrorsTerminal().toString();
805 maintTestsignalSyncseconds = oduIfBuilder.getMaintTestsignal().getSyncSeconds();
806 maintTestsignalSyncsecondsterminal = oduIfBuilder.getMaintTestsignal().getSyncSecondsTerminal();
810 OtuBuilder otuIfBuilder =
811 new OtuBuilder(deviceInterface.augmentation(
812 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.Interface1.class)
814 otuRate = otuIfBuilder.getRate().toString();
815 otuFecEnu = otuIfBuilder.getFec().getName();
816 otuMaintLoopbackEnabled = otuIfBuilder.getMaintLoopback().getEnabled().toString();
817 otuMaintTypeEnu = otuIfBuilder.getMaintLoopback().getType().getName();
821 LOG.error("could not get interface type");
825 String startTimestamp = getCurrentTimestamp();
827 return new Object[]{nodeId,
831 administrativeStateEnu,
832 Integer.toString(operationalState),
835 supportingCircuitPackName,
841 ethernetAutoNegotiationEnu,
846 //mciMcttpCenterFreq,
848 //mciNmcCtpFrequency,
850 "", "", "", "", "", "",
861 //otsIngressSpanLossAgingMargin,
870 oduProactiveDelayMeasurementEnabled,
871 //oduPoaTribPortNumber,
877 //oduAcceptedOperator,
883 //oduDegthrPercentage,
884 "-1", "", "", "", "", "","", "", "", "", "", "-1", "-1",
889 maintTestsignalEnabled,
890 maintTestsignalTestpatternEnu,
891 maintTestsignalTypeEnu,
892 maintTestsignalBiterrors,
893 maintTestsignalBiterrorsterminal,
894 maintTestsignalSyncseconds,
895 maintTestsignalSyncsecondsterminal,
903 //otuAcceptedOperator,
909 //otuDegthrPercentage,
910 "", "", "", "", "", "","", "", "", "", "-1", "-1",
911 otuMaintLoopbackEnabled,
915 //mtOtuMaintLoopback,
925 private static Object[] prepareDevInterfaceTcmParameters(String nodeId, String interfaceName, Tcm tcm) {
927 String layer = tcm.getLayer().toString();
928 String monitoringModeEnu = tcm.getMonitoringMode().getName();
929 String ltcActEnabled = tcm.getLtcActEnabled().toString();
930 String proactiveDelayMeasurementEnabled = tcm.getProactiveDelayMeasurementEnabled().toString();
931 //String tcmDirectionEnu = "";
932 //String timDetectModeEnu = "";
933 //String txSapi = "";
934 //String txDapi = "";
935 //String txOperator = "";
936 //String acceptedSapi = "";
937 //String acceptedDapi = "";
938 //String acceptedOperator = "";
939 //String expectedSapi = "";
940 //String expectedDapi = "";
941 //String timActEnabled = "";
942 //String degmIntervals = "";
943 //String degthrPercentage = "";
944 String startTimestamp = getCurrentTimestamp();
946 return new Object[]{nodeId,
951 proactiveDelayMeasurementEnabled,
965 "", "", "", "", "", "", "", "", "", "", "", "", "",
971 private static Object[] prepareDevInterfaceOtnOduTxMsiParameters(String nodeId, String interfaceName, TxMsi txMsi) {
973 String tribSlot = txMsi.getTribSlot().toString();
974 String odtuType = txMsi.getOdtuType().toString();
975 String tribPort = txMsi.getTribPort().toString();
976 String tribPortPayload = txMsi.getTribPortPayload();
978 String startTimestamp = getCurrentTimestamp();
980 return new Object[]{nodeId,
992 private static Object[] prepareDevInterfaceOtnOduRxMsiParameters(String nodeId, String interfaceName, RxMsi rxMsi) {
994 String tribSlot = rxMsi.getTribSlot().toString();
995 String odtuType = rxMsi.getOdtuType().toString();
996 String tribPort = rxMsi.getTribPort().toString();
997 String tribPortPayload = rxMsi.getTribPortPayload();
999 String startTimestamp = getCurrentTimestamp();
1001 return new Object[]{nodeId,
1014 private static Object[] prepareDevInterfaceOtnOduExpMsiParameters(String nodeId, String interfaceName,
1017 String tribSlot = expMsi.getTribSlot().toString();
1018 String odtuType = expMsi.getOdtuType().toString();
1019 String tribPort = expMsi.getTribPort().toString();
1020 String tribPortPayload = expMsi.getTribPortPayload();
1022 String startTimestamp = getCurrentTimestamp();
1024 return new Object[]{nodeId,
1036 private void persistDevInterfaces(String nodeId, Connection connection) {
1038 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1039 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1041 Optional<OrgOpenroadmDevice> deviceObject =
1042 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1043 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1044 if (!deviceObject.isPresent()) {
1047 Map<InterfaceKey, Interface> interfaceMap = deviceObject.orElseThrow().nonnullInterface();
1048 for (Map.Entry<InterfaceKey, Interface> interfaceEntrySet : interfaceMap.entrySet()) {
1049 Interface deviceInterface = interfaceEntrySet.getValue();
1050 Object[] parameters = prepareDevInterfaceParameters(nodeId, deviceInterface, connection);
1052 String query = Queries.getQuery().deviceInterfacesInsert().get();
1053 LOG.info("Running {} query ", query);
1054 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1055 for (int j = 0; j < parameters.length; j++) {
1056 stmt.setObject(j + 1, parameters[j]);
1059 stmt.clearParameters();
1060 } catch (SQLException e) {
1061 LOG.error("Something wrong when storing devices interfaces in DB", e);
1066 private void persistDevProtocols(String nodeId, Connection connection) {
1068 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier
1069 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1070 .child(Protocols.class)
1072 Optional<Protocols> protocolObject =
1073 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1074 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1075 if (!protocolObject.isPresent() || protocolObject.orElseThrow().augmentation(Protocols1.class) == null) {
1076 LOG.error("LLDP subtree is missing");
1079 String adminstatusEnu = protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp().getGlobalConfig()
1080 .getAdminStatus().getName();
1081 String msgTxtInterval = protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp().getGlobalConfig()
1082 .getMsgTxInterval().toString();
1083 String mxgTxHoldMultiplier = protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp()
1084 .getGlobalConfig().getMsgTxHoldMultiplier().toString();
1085 String startTimestamp = getCurrentTimestamp();
1086 persistDevProtocolLldpPortConfig(nodeId, connection);
1087 persistDevProtocolLldpNbrList(nodeId, connection);
1089 Object[] parameters = {nodeId,
1092 mxgTxHoldMultiplier,
1097 String query = Queries.getQuery().deviceProtocolInsert().get();
1098 LOG.info("Running {} query ", query);
1099 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1100 for (int j = 0; j < parameters.length; j++) {
1101 stmt.setObject(j + 1, parameters[j]);
1104 stmt.clearParameters();
1105 } catch (SQLException e) {
1106 LOG.error("Something wrong when storing devices protocols in DB", e);
1111 private void persistDevProtocolLldpPortConfig(String nodeId, Connection connection) {
1113 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier
1114 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1115 .child(Protocols.class)
1117 Optional<Protocols> protocolObject =
1118 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1119 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1120 if (!protocolObject.isPresent() || protocolObject.orElseThrow().augmentation(Protocols1.class) == null) {
1121 LOG.error("LLDP subtree is missing");
1124 String startTimestamp = getCurrentTimestamp();
1126 Map<PortConfigKey, PortConfig> portConfigMap = protocolObject.orElseThrow()
1127 .augmentation(Protocols1.class).getLldp().nonnullPortConfig();
1128 for (Map.Entry<PortConfigKey, PortConfig> entry : portConfigMap.entrySet()) {
1129 PortConfig portConfig = entry.getValue();
1130 String ifName = portConfig.getIfName();
1131 String adminStatusEnu = portConfig.getAdminStatus().getName();
1133 Object[] parameters = {nodeId,
1140 String query = Queries.getQuery().deviceProtocolPortConfigInsert().get();
1141 LOG.info("Running {} query ", query);
1142 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1143 for (int j = 0; j < parameters.length; j++) {
1144 stmt.setObject(j + 1, parameters[j]);
1147 stmt.clearParameters();
1148 } catch (SQLException e) {
1149 LOG.error("Something wrong when storing devices protocols LLDP Port config in DB", e);
1156 private void persistDevProtocolLldpNbrList(String nodeId, Connection connection) {
1158 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier
1159 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1160 .child(Protocols.class)
1162 Optional<Protocols> protocolObject =
1163 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1164 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1165 if (!protocolObject.isPresent()) {
1166 LOG.error("Protocols is missing");
1169 if (protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp().getNbrList() == null) {
1171 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, protocolsIID,
1172 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1173 if (protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp().getNbrList() == null) {
1174 LOG.error("LLDP nbrlist subtree is missing for {}", nodeId);
1178 String startTimestamp = getCurrentTimestamp();
1179 Map<IfNameKey, IfName> ifNameMap =
1180 protocolObject.orElseThrow().augmentation(Protocols1.class).getLldp().getNbrList().nonnullIfName();
1181 for (Map.Entry<IfNameKey, IfName> ifNameEntry : ifNameMap.entrySet()) {
1183 IfName ifNameObj = ifNameEntry.getValue();
1184 String ifName = ifNameObj.getIfName();
1185 String remotesysname = ifNameObj.getRemoteSysName();
1186 String remotemgmtaddresssubtype = ifNameObj.getRemoteMgmtAddressSubType().getName();
1187 String remotemgmtaddress = ifNameObj.getRemoteMgmtAddress().getIpv4Address().toString();
1188 String remoteportidsubtypeEnu = ifNameObj.getRemotePortIdSubType().getName();
1189 String remoteportid = ifNameObj.getRemotePortId();
1190 String remotechassisidsubtypeEnu = ifNameObj.getRemoteChassisIdSubType().getName();
1191 String remotechassisid = ifNameObj.getRemoteChassisId();
1193 Object[] parameters = {nodeId,
1196 remotemgmtaddresssubtype,
1198 remoteportidsubtypeEnu,
1200 remotechassisidsubtypeEnu,
1206 String query = Queries.getQuery().deviceProtocolLldpNbrlistInsert().get();
1207 LOG.info("Running {} query ", query);
1208 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1209 for (int j = 0; j < parameters.length; j++) {
1210 stmt.setObject(j + 1, parameters[j]);
1213 stmt.clearParameters();
1214 } catch (SQLException e) {
1215 LOG.error("Something wrong when storing devices protocols LLDP list number in DB", e);
1221 private void persistDevInternalLinks(String nodeId, Connection connection) {
1223 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1224 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1226 Optional<OrgOpenroadmDevice> deviceObject =
1227 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1228 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1229 if (!deviceObject.isPresent()) {
1232 if (deviceObject.orElseThrow().getInternalLink() == null) {
1233 deviceObject = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION,
1234 deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1235 if (deviceObject.orElseThrow().getInternalLink() == null) {
1236 LOG.info("External links not found for {}", nodeId);
1241 Map<InternalLinkKey, InternalLink> internalLinkMap = deviceObject.orElseThrow().nonnullInternalLink();
1242 String startTimestamp = getCurrentTimestamp();
1243 for (Map.Entry<InternalLinkKey, InternalLink> internalLinkEntry: internalLinkMap.entrySet()) {
1244 InternalLink internalLink = internalLinkEntry.getValue();
1245 String internalLinkName = internalLink.getInternalLinkName();
1246 String sourceCircuitPackName = internalLink.getSource().getCircuitPackName();
1247 String sourcePortName = internalLink.getSource().getPortName();
1248 String destinationCircuitPackName = internalLink.getDestination().getCircuitPackName();
1249 String destinationPortName = internalLink.getDestination().getPortName();
1251 Object[] parameters = { nodeId, internalLinkName, sourceCircuitPackName, sourcePortName,
1252 destinationCircuitPackName, destinationPortName, startTimestamp, startTimestamp };
1253 String query = Queries.getQuery().deviceInternalLinkInsert().get();
1254 LOG.info("Running {} query ", query);
1255 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1256 for (int j = 0; j < parameters.length; j++) {
1257 stmt.setObject(j + 1, parameters[j]);
1260 stmt.clearParameters();
1261 } catch (SQLException e) {
1262 LOG.error("Something wrong when storing devices internal links", e);
1268 private void persistDevExternalLinks(String nodeId, Connection connection) {
1270 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1271 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1273 Optional<OrgOpenroadmDevice> deviceObject =
1274 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1275 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1276 if (!deviceObject.isPresent()) {
1279 if (deviceObject.orElseThrow().getExternalLink() == null) {
1280 deviceObject = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION,
1281 deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1282 if (deviceObject.orElseThrow().getExternalLink() == null) {
1283 LOG.info("External links not found for {}", nodeId);
1287 String startTimestamp = getCurrentTimestamp();
1289 Map<ExternalLinkKey, ExternalLink> externalLinkMap = deviceObject.orElseThrow().nonnullExternalLink();
1290 for (Map.Entry<ExternalLinkKey, ExternalLink> externalLinkEntry: externalLinkMap.entrySet()) {
1291 ExternalLink externalLink = externalLinkEntry.getValue();
1292 String externalLinkName = externalLink.getExternalLinkName();
1293 String sourceNodeId = externalLink.getSource().getNodeId();
1294 String sourceCircuitPackName = externalLink.getSource().getCircuitPackName();
1295 String sourcePortName = externalLink.getSource().getPortName();
1296 String destinationNodeId = externalLink.getDestination().getNodeId();
1297 String destinationCircuitPackName = externalLink.getDestination().getCircuitPackName();
1298 String destinationPortName = externalLink.getDestination().getPortName();
1300 Object[] parameters = { nodeId, externalLinkName, sourceNodeId, sourceCircuitPackName,
1301 sourcePortName, destinationNodeId, destinationCircuitPackName, destinationPortName,
1302 startTimestamp, startTimestamp };
1304 String query = Queries.getQuery().deviceExternalLinkInsert().get();
1305 LOG.info("Running {} query ", query);
1306 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1307 for (int j = 0; j < parameters.length; j++) {
1308 stmt.setObject(j + 1, parameters[j]);
1311 stmt.clearParameters();
1312 } catch (SQLException e) {
1313 LOG.error("Something wrong when storing devices external links", e);
1318 private void persistDevPhysicalLinks(String nodeId, Connection connection) {
1320 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1321 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1323 Optional<OrgOpenroadmDevice> deviceObject =
1324 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1325 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1326 if (!deviceObject.isPresent()) {
1327 LOG.error("No device with node Id {}", nodeId);
1330 if (deviceObject.orElseThrow().getPhysicalLink() == null) {
1332 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1333 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1334 if (!deviceObject.isPresent()) {
1335 LOG.error("No device with node Id {}", nodeId);
1338 if (deviceObject.orElseThrow().getPhysicalLink() == null) {
1339 LOG.info("Physical links not found for {}", nodeId);
1344 String startTimestamp = getCurrentTimestamp();
1346 Map<PhysicalLinkKey, PhysicalLink> physicalLinkMap = deviceObject.orElseThrow().nonnullPhysicalLink();
1347 for (Map.Entry<PhysicalLinkKey, PhysicalLink> physicalLinkEntry : physicalLinkMap.entrySet()) {
1348 PhysicalLink physicalLink = physicalLinkEntry.getValue();
1349 String physicalLinkName = physicalLink.getPhysicalLinkName();
1350 String sourceCircuitPackName = physicalLink.getSource().getCircuitPackName();
1351 String sourcePortName = physicalLink.getSource().getPortName();
1352 String destinationCircuitPackName = physicalLink.getDestination().getCircuitPackName();
1353 String destinationPortName = physicalLink.getDestination().getPortName();
1355 Object[] parameters = {nodeId,
1357 sourceCircuitPackName,
1359 destinationCircuitPackName,
1360 destinationPortName,
1365 String query = Queries.getQuery().devicePhysicalLinkInsert().get();
1366 LOG.info("Running {} query ", query);
1367 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1368 for (int j = 0; j < parameters.length; j++) {
1369 stmt.setObject(j + 1, parameters[j]);
1372 stmt.clearParameters();
1373 } catch (SQLException e) {
1374 LOG.error("Something wrong when storing devices physical links", e);
1380 private void persistDevDegree(String nodeId, Connection connection) {
1382 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1383 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1385 Optional<OrgOpenroadmDevice> deviceObject =
1386 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1387 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1390 /*if (deviceObject.get().getDegree()==null){
1392 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1393 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1395 if (!deviceObject.isPresent()) {
1396 LOG.error("Cannot get device for node {}", nodeId);
1399 String startTimestamp = getCurrentTimestamp();
1401 Map<DegreeKey, Degree> degreeMap = deviceObject.orElseThrow().nonnullDegree();
1402 for (Map.Entry<DegreeKey, Degree> degreeEntry : degreeMap.entrySet()) {
1403 Degree degree = degreeEntry.getValue();
1404 String degreeNumber = degree.getDegreeNumber().toString();
1405 String maxWavelengths = degree.getMaxWavelengths().toString();
1406 String otdrPortCircuitPackName =
1407 (degree.getOtdrPort() == null ? "" : degree.getOtdrPort().getCircuitPackName());
1408 String otdrPortPortName =
1409 (degree.getOtdrPort() == null ? "" : degree.getOtdrPort().getPortName());
1410 // String mcCapabilitiesSlotWidthGranularity = "";
1411 // String mcCapabilitiesCenterFreqGranularity = "";
1412 // String mcCapabilitiesMinSlots = "-1";
1413 // String mcCapabilitiesMaxSlots = "-1";
1414 persistDevDegreeCircuitPack(nodeId, degree, degreeNumber, connection);
1415 persistDevDegreeConnectionPort(nodeId, degree, degreeNumber, connection);
1417 Object[] parameters = { nodeId, degreeNumber, maxWavelengths, otdrPortCircuitPackName, otdrPortPortName,
1418 // mcCapabilitiesSlotWidthGranularity,
1419 // mcCapabilitiesCenterFreqGranularity,
1420 // mcCapabilitiesMinSlots,
1421 // mcCapabilitiesMaxSlots,
1422 "", "", "-1", "-1", startTimestamp, startTimestamp };
1424 String query = Queries.getQuery().deviceDegreeInsert().get();
1425 LOG.info("Running {} query ", query);
1426 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1427 for (int j = 0; j < parameters.length; j++) {
1428 stmt.setObject(j + 1, parameters[j]);
1431 stmt.clearParameters();
1432 } catch (SQLException e) {
1433 LOG.error("Something wrong when storing devices degrees", e);
1440 private void persistDevDegreeCircuitPack(String nodeId, Degree degree, String degreeNumber, Connection connection) {
1442 String startTimestamp = getCurrentTimestamp();
1444 Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1445 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks>
1446 circuitPacksMap = degree.nonnullCircuitPacks();
1447 for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1448 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks> circuitPackEntry :
1449 circuitPacksMap.entrySet()) {
1451 String circuitPackIndex = circuitPackEntry.getValue().getIndex().toString();
1452 String circuitPackName = circuitPackEntry.getValue().getCircuitPackName();
1454 Object[] parameters = {nodeId,
1462 String query = Queries.getQuery().deviceDegreeCircuitPackInsert().get();
1463 LOG.info("Running {} query ", query);
1464 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1465 for (int j = 0; j < parameters.length; j++) {
1466 stmt.setObject(j + 1, parameters[j]);
1469 stmt.clearParameters();
1470 } catch (SQLException e) {
1471 LOG.error("Something wrong when storing devices degrees circuit packs", e);
1477 private void persistDevDegreeConnectionPort(String nodeId, Degree degree, String degreeNumber,
1478 Connection connection) {
1480 String startTimestamp = getCurrentTimestamp();
1482 Map<ConnectionPortsKey, ConnectionPorts> connectionPortsMap = degree.nonnullConnectionPorts();
1483 for (Map.Entry<ConnectionPortsKey, ConnectionPorts> portEntry : connectionPortsMap.entrySet()) {
1484 String connectionPortIndex = portEntry.getValue().getIndex().toString();
1485 String circuitPackName = portEntry.getValue().getCircuitPackName();
1486 String portName = portEntry.getValue().getPortName();
1488 Object[] parameters = {nodeId,
1490 connectionPortIndex,
1497 String query = Queries.getQuery().deviceDegreeConnectionPortInsert().get();
1498 LOG.info("Running {} query ", query);
1499 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1500 for (int j = 0; j < parameters.length; j++) {
1501 stmt.setObject(j + 1, parameters[j]);
1504 stmt.clearParameters();
1505 } catch (SQLException e) {
1506 LOG.error("Something wrong when storing devices degrees connection ports", e);
1513 private void persistDevSrg(String nodeId, Connection connection) {
1515 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1516 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1518 Optional<OrgOpenroadmDevice> deviceObject =
1519 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1520 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1521 if (!deviceObject.isPresent()) {
1522 LOG.error("No device found in operational datastore for node {}", nodeId);
1526 if (deviceObject.orElseThrow().getSharedRiskGroup() == null) {
1528 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1529 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1530 if (!deviceObject.isPresent()) {
1531 LOG.error("No device found in configuration datastore for node {}", nodeId);
1537 Map<SharedRiskGroupKey, SharedRiskGroup> sharedRiskGroupMap = deviceObject.orElseThrow()
1538 .nonnullSharedRiskGroup();
1539 if (sharedRiskGroupMap.isEmpty()) {
1540 LOG.info("no srg found for node {} ", nodeId);
1543 String startTimestamp = getCurrentTimestamp();
1544 for (Map.Entry<SharedRiskGroupKey, SharedRiskGroup> groupEntry : sharedRiskGroupMap.entrySet()) {
1545 SharedRiskGroup sharedRiskGroup = groupEntry.getValue();
1546 //String currentProvisionedAddDropPorts = "-1";
1547 //String mcCapSlotWidthGranularity = "";
1548 //String mcCapCenterFreqGranularity = "";
1549 //String mcCapMinSlots = "-1";
1550 //String mcCapMaxSlots = "-1";
1551 String maxAddDropPorts = sharedRiskGroup.getMaxAddDropPorts().toString();
1552 String srgNumber = sharedRiskGroup.getSrgNumber().toString();
1553 String wavelengthDuplicationEnu = sharedRiskGroup.getWavelengthDuplication().getName();
1554 persistDevSrgCircuitPacks(nodeId, sharedRiskGroup, srgNumber, connection);
1556 Object[] parameters = {nodeId,
1558 //currentProvisionedAddDropPorts,
1561 wavelengthDuplicationEnu,
1562 //mcCapSlotWidthGranularity,
1563 //mcCapCenterFreqGranularity,
1571 String query = Queries.getQuery().deviceSharedRiskGroupInsert().get();
1572 LOG.info("Running {} query ", query);
1573 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1574 for (int j = 0; j < parameters.length; j++) {
1575 stmt.setObject(j + 1, parameters[j]);
1578 stmt.clearParameters();
1579 } catch (SQLException e) {
1580 LOG.error("Something wrong when storing devices SRG", e);
1587 private void persistDevSrgCircuitPacks(String nodeId, SharedRiskGroup sharedRiskGroup, String srgNumber,
1588 Connection connection) {
1590 String startTimestamp = getCurrentTimestamp();
1592 Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1593 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>
1594 circuitPacksMap = sharedRiskGroup.nonnullCircuitPacks();
1595 for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1596 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> entry :
1597 circuitPacksMap.entrySet()) {
1599 String circuitPackindex = entry.getValue().getIndex().toString();
1600 String circuitPackName = entry.getValue().getCircuitPackName();
1602 Object[] parameters = {nodeId,
1610 String query = Queries.getQuery().deviceSrgCircuitPackInsert().get();
1611 LOG.info("Running {} query ", query);
1612 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1613 for (int j = 0; j < parameters.length; j++) {
1614 stmt.setObject(j + 1, parameters[j]);
1617 stmt.clearParameters();
1618 } catch (SQLException e) {
1619 LOG.error("Something wrong when storing devices SRG circuit packs", e);
1625 private void persistDevRoadmConnections(String nodeId, Connection connection) {
1627 //int opticalcontrolmodeEnu=-1;
1629 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1630 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1632 Optional<OrgOpenroadmDevice> deviceObject =
1633 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1634 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1635 if (!deviceObject.isPresent()) {
1636 LOG.error("No device found in operational datastore for node {}", nodeId);
1639 if (deviceObject.orElseThrow().getRoadmConnections() == null) {
1641 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1642 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1643 if (!deviceObject.isPresent()) {
1644 LOG.error("No device found in configuration datastore for node {}", nodeId);
1650 Map<RoadmConnectionsKey, RoadmConnections> connectionsMap = deviceObject.orElseThrow()
1651 .nonnullRoadmConnections();
1652 if (connectionsMap.isEmpty()) {
1653 LOG.info("ROADM Dev Connections not found!! for {}", nodeId);
1656 String startTimestamp = getCurrentTimestamp();
1657 for (Map.Entry<RoadmConnectionsKey, RoadmConnections> entry : connectionsMap.entrySet()) {
1658 RoadmConnections roadmConnections = entry.getValue();
1659 String connectionNumber = roadmConnections.getConnectionNumber();
1660 //String connectionName = "";
1661 String wavelengthNumber = roadmConnections.getWavelengthNumber().toString();
1662 String opticalcontrolmodeEnu = roadmConnections.getOpticalControlMode().getName();
1663 String targetOutputPower = roadmConnections.getTargetOutputPower().toString();
1664 String srcIf = roadmConnections.getSource().getSrcIf();
1665 String dstIf = roadmConnections.getDestination().getDstIf();
1667 Object[] parameters = {nodeId,
1672 opticalcontrolmodeEnu,
1680 String query = Queries.getQuery().deviceRoadmConnectionsInsert().get();
1681 LOG.info("Running {} query ", query);
1682 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1683 for (int j = 0; j < parameters.length; j++) {
1684 stmt.setObject(j + 1, parameters[j]);
1687 stmt.clearParameters();
1688 } catch (SQLException e) {
1689 LOG.error("Something wrong when storing devices ROADM connection ", e);
1695 private void persistDevConnectionMap(String nodeId, Connection connection) {
1697 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1698 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1700 Optional<OrgOpenroadmDevice> deviceObject =
1701 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1702 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1703 if (!deviceObject.isPresent()) {
1704 LOG.error("No device found in operational datastore for node {}", nodeId);
1707 String startTimestamp = getCurrentTimestamp();
1709 Map<ConnectionMapKey, ConnectionMap> connectionsMap = deviceObject.orElseThrow().nonnullConnectionMap();
1710 for (Map.Entry<ConnectionMapKey, ConnectionMap> entry : connectionsMap.entrySet()) {
1711 ConnectionMap connectionMap = entry.getValue();
1712 String connectionMapNumber = connectionMap.getConnectionMapNumber().toString();
1713 String sourceCircuitPackName = connectionMap.getSource().getCircuitPackName();
1714 String sourcePortName = connectionMap.getSource().getCircuitPackName();
1717 Object[] parameters = {nodeId,
1718 connectionMapNumber,
1719 sourceCircuitPackName,
1725 String query = Queries.getQuery().deviceConnectionMapInsert().get();
1726 LOG.info("Running {} query ", query);
1727 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1728 for (int j = 0; j < parameters.length; j++) {
1729 stmt.setObject(j + 1, parameters[j]);
1732 stmt.clearParameters();
1733 } catch (SQLException e) {
1734 LOG.error("Something wrong when storing devices connection map", e);
1740 private void persistDevWavelengthMap(String nodeId, Connection connection) {
1742 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1743 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1745 Optional<OrgOpenroadmDevice> deviceObject =
1746 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1747 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1748 if (!deviceObject.isPresent()) {
1749 LOG.error("No device found in operational datastore for node {}", nodeId);
1753 String startTimestamp = getCurrentTimestamp();
1755 Map<WavelengthsKey, Wavelengths> wavelengthsMap = deviceObject.orElseThrow().getWavelengthMap()
1756 .nonnullWavelengths();
1757 for (Map.Entry<WavelengthsKey, Wavelengths> entry : wavelengthsMap.entrySet()) {
1758 Wavelengths wavelengths = entry.getValue();
1759 String wavelengthNumber = wavelengths.getWavelengthNumber().toString();
1760 String centerFrequency = wavelengths.getCenterFrequency().toString();
1761 String wavelength = wavelengths.getWavelength().toString();
1764 Object[] parameters = {nodeId,
1772 String query = Queries.getQuery().deviceWavelengthInsert().get();
1773 LOG.info("Running {} query ", query);
1774 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1775 for (int j = 0; j < parameters.length; j++) {
1776 stmt.setObject(j + 1, parameters[j]);
1779 stmt.clearParameters();
1780 } catch (SQLException e) {
1781 LOG.error("Something wrong when storing devices wavelength map", e);
1788 private void persistDevInterfaceTcm(String nodeId, String interfaceName, OduBuilder oduBuilder,
1789 Connection connection) {
1791 Map<TcmKey, Tcm> tcmMap = oduBuilder.getTcm();
1792 for (Map.Entry<TcmKey, Tcm> entry : tcmMap.entrySet()) {
1793 Tcm tcm = entry.getValue();
1795 Object[] parameters = prepareDevInterfaceTcmParameters(nodeId, interfaceName, tcm);
1797 String query = Queries.getQuery().deviceInterfacesInsert().get();
1798 LOG.info("Running {} query ", query);
1799 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1800 for (int j = 0; j < parameters.length; j++) {
1801 stmt.setObject(j + 1, parameters[j]);
1804 stmt.clearParameters();
1805 } catch (SQLException e) {
1806 LOG.error("Something wrong when storing devices interface tcm", e);
1811 private void persistDevInterfaceOtnOduTxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1812 Connection connection) {
1814 Map<TxMsiKey, TxMsi> txMsiMap = oduBuilder.getOpu().getMsi().nonnullTxMsi();
1815 for (Map.Entry<TxMsiKey, TxMsi> entry : txMsiMap.entrySet()) {
1817 TxMsi txMsi = entry.getValue();
1819 Object[] parameters = prepareDevInterfaceOtnOduTxMsiParameters(nodeId, interfaceName, txMsi);
1821 String query = Queries.getQuery().deviceInterfaceOtnOduTxMsiInsert().get();
1822 LOG.info("Running {} query ", query);
1823 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1824 for (int j = 0; j < parameters.length; j++) {
1825 stmt.setObject(j + 1, parameters[j]);
1828 stmt.clearParameters();
1829 } catch (SQLException e) {
1830 LOG.error("Something wrong when storing devices interface OTN ODU Tx MSI", e);
1836 private void persistDevInterfaceOtnOduRxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1837 Connection connection) {
1838 Map<RxMsiKey, RxMsi> rxMsiMap = oduBuilder.getOpu().getMsi().nonnullRxMsi();
1839 for (Map.Entry<RxMsiKey, RxMsi> entry : rxMsiMap.entrySet()) {
1840 RxMsi rxMsi = entry.getValue();
1842 Object[] parameters = prepareDevInterfaceOtnOduRxMsiParameters(nodeId, interfaceName, rxMsi);
1844 String query = Queries.getQuery().deviceInterfaceOtnOduRxMsiInsert().get();
1845 LOG.info("Running {} query ", query);
1846 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1847 for (int j = 0; j < parameters.length; j++) {
1848 stmt.setObject(j + 1, parameters[j]);
1851 stmt.clearParameters();
1852 } catch (SQLException e) {
1853 LOG.error("Something wrong when storing devices interface OTN ODU Rx MSI", e);
1859 private void persistDevInterfaceOtnOduExpMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1860 Connection connection) {
1862 Map<ExpMsiKey, ExpMsi> expMsiMap = oduBuilder.getOpu().getMsi().nonnullExpMsi();
1863 for (Map.Entry<ExpMsiKey, ExpMsi> entry : expMsiMap.entrySet()) {
1864 ExpMsi expMsi = entry.getValue();
1866 Object[] parameters = prepareDevInterfaceOtnOduExpMsiParameters(nodeId, interfaceName, expMsi);
1868 String query = Queries.getQuery().deviceInterfaceOtnOduExpMsiInsert().get();
1869 LOG.info("Running {} query ", query);
1870 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1871 for (int j = 0; j < parameters.length; j++) {
1872 stmt.setObject(j + 1, parameters[j]);
1875 stmt.clearParameters();
1876 } catch (SQLException e) {
1877 LOG.error("Something wrong when storing devices interface OTN ODU Exp MSI", e);