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 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.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.transportpce.common.Timeouts;
27 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
28 import org.opendaylight.transportpce.inventory.query.Queries;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceData;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.CpSlots;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.CpSlotsKey;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.PortsKey;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPorts;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPortsKey;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLink;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLinkKey;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceKey;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLink;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLinkKey;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMapKey;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.DegreeKey;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnections;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLink;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLinkKey;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.Slots;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.SlotsKey;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.Shelves;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.ShelvesKey;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.Interface1;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.ethernet.container.EthernetBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfig;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfigKey;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfName;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfNameKey;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.och.container.OchBuilder;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.OtsBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.Tcm;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.TcmKey;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.container.OduBuilder;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsi;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsiKey;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsi;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsiKey;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsi;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsiKey;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.otu.container.OtuBuilder;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.wavelength.map.rev161014.wavelength.map.g.Wavelengths;
81 import org.opendaylight.yang.gen.v1.http.org.openroadm.wavelength.map.rev161014.wavelength.map.g.WavelengthsKey;
82 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
83 import org.slf4j.Logger;
84 import org.slf4j.LoggerFactory;
86 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
87 value = "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING",
88 justification = "TODO review the SQL statement generation process")
89 public class INode121 {
91 private static final Logger LOG = LoggerFactory.getLogger(INode121.class);
93 private final DataSource dataSource;
94 private final DeviceTransactionManager deviceTransactionManager;
96 public INode121(DataSource dataSource, DeviceTransactionManager deviceTransactionManager) {
97 this.dataSource = dataSource;
98 this.deviceTransactionManager = deviceTransactionManager;
101 public boolean addNode(String deviceId) {
103 InstanceIdentifier<Info> infoIID = InstanceIdentifier
104 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
107 Optional<Info> infoOpt =
108 deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.OPERATIONAL, infoIID,
109 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
111 if (!infoOpt.isPresent()) {
112 LOG.warn("Could not get device info from DataBroker");
115 deviceInfo = infoOpt.get();
116 boolean sqlResult = false;
117 String query = Queries.getQuery().deviceInfoInsert().get();
118 LOG.info("Running {} query ", query);
119 try (Connection connection = dataSource.getConnection();
120 PreparedStatement preparedStatement = connection.prepareStatement(query)) {
121 Object[] prepareParameters = prepareDeviceInfoParameters(deviceInfo);
122 for (int i = 0; i < prepareParameters.length; i++) {
123 LOG.debug("Parameter {} has value {}", i + 1, prepareParameters[i]);
124 preparedStatement.setObject(i + 1, prepareParameters[i]);
127 int executeUpdate = preparedStatement.executeUpdate();
128 LOG.info("{} entries were added", executeUpdate);
131 LOG.debug("iNode AddNode call complete");
132 getRoadmShelves(deviceId);
133 LOG.debug("iNode getRoadmShelves call complete");
134 getCircuitPacks(deviceId);
135 LOG.debug("iNode getCircuitPacks call complete");
137 LOG.debug("iNode persist interfaces call");
138 persistDevInterfaces(deviceId, connection);
139 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");
147 LOG.debug("iNode persist wavelength map call");
148 persistDevWavelengthMap(deviceId, connection);
149 LOG.debug("iNode persist wavelength map call complete");
151 LOG.debug("iNode persist internal links map call");
152 persistDevInternalLinks(deviceId, connection);
153 LOG.debug("iNode persist internal links map call complete");
155 LOG.debug("iNode persist Physical links map call");
156 persistDevPhysicalLinks(deviceId, connection);
157 LOG.debug("iNode persist Physical links map call complete");
159 LOG.debug("iNode persist External links map call");
160 persistDevExternalLinks(deviceId, connection);
161 LOG.debug("iNode persist External links map call complete");
163 LOG.debug("iNode persist degree map call");
164 persistDevDegree(deviceId, connection);
165 LOG.debug("iNode persist degree map call complete");
167 LOG.debug("iNode persist srg map call");
168 persistDevSrg(deviceId, connection);
169 LOG.debug("iNode persist srg map call complete");
171 LOG.debug("iNode persist Roadm Connections call");
172 persistDevRoadmConnections(deviceId, connection);
173 LOG.debug("iNode persist Roadm Connections call complete");
175 LOG.debug("iNode persist Connection Map call");
176 persistDevConnectionMap(deviceId, connection);
177 LOG.debug("iNode persist Connection Map call complete");
179 } catch (SQLException | InterruptedException | ExecutionException e) {
180 LOG.error("Something wrong when storing node into DB", e);
185 public boolean nodeExists(String nodeId) {
186 String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?";
188 LOG.info("Checking if {} exists in DB", nodeId);
189 try (Connection connection = dataSource.getConnection();
190 PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) {
191 preparedStmt.setString(1, nodeId);
192 try (ResultSet rs = preparedStmt.executeQuery()) {
194 nodeExists = rs.getInt("node_exists");
195 LOG.debug("Found {} devices matching {}", nodeExists, nodeId);
198 } catch (SQLException e) {
199 LOG.error("Something wrong when fetching node in DB", e);
201 return nodeExists != 0;
204 public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException {
205 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
206 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
208 Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
209 LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
210 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
211 if (!deviceObject.isPresent()) {
214 Map<ShelvesKey, Shelves> shelvesMap = deviceObject.get().nonnullShelves();
215 LOG.info("Shelves size {}", shelvesMap.size());
216 try (Connection connection = requireNonNull(dataSource.getConnection())) {
217 for (Map.Entry<ShelvesKey, Shelves> shelveEntry : shelvesMap.entrySet()) {
218 Shelves shelve = shelveEntry.getValue();
219 String shelfName = shelve.getShelfName();
220 LOG.info("Getting Shelve Details of {}", shelfName);
221 if (shelve.getSlots() != null) {
222 LOG.info("Slot Size {} ", shelve.getSlots().size());
223 persistShelveSlots(nodeId, shelve, connection);
225 LOG.info("No Slots for shelf {}", shelfName);
228 persistShelves(nodeId, connection, shelve);
230 } catch (SQLException e1) {
231 LOG.error("Something wrong when fetching ROADM shelves in DB", e1);
235 public void getCircuitPacks(String nodeId) throws InterruptedException, ExecutionException {
236 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
237 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
239 Optional<OrgOpenroadmDevice> deviceObject =
240 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
241 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
242 if (!deviceObject.isPresent()) {
243 LOG.warn("Device object {} was not found", nodeId);
246 Map<CircuitPacksKey, CircuitPacks> circuitPacksMap = deviceObject.get().nonnullCircuitPacks();
247 LOG.info("Circuit pack size {}", circuitPacksMap.size());
249 try (Connection connection = requireNonNull(dataSource.getConnection())) {
250 for (Map.Entry<CircuitPacksKey, CircuitPacks> circuitPackEntry : circuitPacksMap.entrySet()) {
251 CircuitPacks cp = circuitPackEntry.getValue();
253 if (cp.getCpSlots() != null) {
254 persistCircuitPacksSlots(nodeId, cp, connection);
256 LOG.info("Everything {}", cp);
257 LOG.info("CP is {}", cp);
259 //persistPorts(cp, connection);
260 if (cp.getPorts() != null) {
261 persistCPPorts(nodeId, connection, cp);
263 persistCircuitPacks(nodeId, connection, cp);
265 } catch (SQLException e1) {
266 LOG.error("Something wrong when fetching Circuit Packs in DB", e1);
270 private void persistCircuitPacks(String nodeId, Connection connection, CircuitPacks cp) {
271 Object[] parameters = prepareCircuitPacksParameters(nodeId, cp);
272 String query = Queries.getQuery().deviceCircuitPackInsert().get();
273 LOG.info("Running {} query ", query);
274 try (PreparedStatement stmt = connection.prepareStatement(query)) {
275 for (int j = 0; j < parameters.length; j++) {
276 stmt.setObject(j + 1, parameters[j]);
279 stmt.clearParameters();
280 } catch (SQLException e) {
281 LOG.error("Something wrong when storing Circuit Packs in DB", e);
285 private void persistShelves(String nodeId, Connection connection, Shelves shelve) {
286 Object[] shelvesParameter = prepareShelvesParameters(nodeId, shelve);
287 String query = Queries.getQuery().deviceShelfInsert().get();
288 LOG.info("Running {} query ", query);
289 try (PreparedStatement preparedStmt = connection.prepareStatement(query)) {
290 for (int j = 0; j < shelvesParameter.length; j++) {
291 preparedStmt.setObject(j + 1, shelvesParameter[j]);
293 preparedStmt.execute();
294 preparedStmt.clearParameters();
295 } catch (SQLException e) {
296 LOG.error("Something wrong when storing shelves in DB", e);
300 private void persistShelveSlots(String nodeId, Shelves shelves, Connection connection) {
301 String startTimetampStr = getCurrentTimestamp();
302 Map<SlotsKey, Slots> slotsMap = shelves.nonnullSlots();
303 for (Map.Entry<SlotsKey, Slots> slotEntry : slotsMap.entrySet()) {
304 Slots slot = slotEntry.getValue();
305 LOG.info("Getting Slot Details of {}", slot.getSlotName());
306 Object[] parameters = new Object[]{nodeId,
307 shelves.getShelfName(),
310 slot.getProvisionedCircuitPack(),
314 String query = Queries.getQuery().deviceShelfSlotInsert().get();
315 LOG.info("Running {} query ", query);
316 try (PreparedStatement stmt = connection.prepareStatement(query)) {
317 for (int j = 0; j < parameters.length; j++) {
318 stmt.setObject(j + 1, parameters[j]);
321 stmt.clearParameters();
322 } catch (SQLException e) {
323 LOG.error("Something wrong when storing shelves slots in DB", e);
329 private void persistCircuitPacksSlots(String nodeId, CircuitPacks circuitPacks, Connection connection) {
330 String startTimetampStr = getCurrentTimestamp();
331 Map<CpSlotsKey, CpSlots> cpSlotsMap = circuitPacks.nonnullCpSlots();
332 for (Map.Entry<CpSlotsKey, CpSlots> cpSlotEntry: cpSlotsMap.entrySet()) {
333 CpSlots cpSlot = cpSlotEntry.getValue();
335 Object[] parameters = new Object[]{nodeId,
336 circuitPacks.getCircuitPackName(),
337 cpSlot.getSlotName(),
339 cpSlot.getProvisionedCircuitPack(),
344 String query = Queries.getQuery().deviceCPSlotInsert().get();
345 LOG.info("Running {} query ", query);
346 try (PreparedStatement stmt = connection.prepareStatement(query)) {
347 for (int j = 0; j < parameters.length; j++) {
348 stmt.setObject(j + 1, parameters[j]);
351 stmt.clearParameters();
352 } catch (SQLException e) {
353 LOG.error("Something wrong when storing Cirtcuits Packs slots in DB", e);
359 * Prepares parameters for device insert query.
361 * @param deviceInfo device information
362 * @return Object an object
364 private static Object[] prepareDeviceInfoParameters(Info deviceInfo) {
365 String startTimetampStr = getCurrentTimestamp();
367 String nodeId = prepareDashString(deviceInfo.getNodeId());
368 Long nodeNumber = deviceInfo.getNodeNumber().toJava();
369 String nodeTypeEnu = deviceInfo.getNodeType().getName();
370 String clli = prepareDashString(deviceInfo.getClli());
371 String vendor = prepareDashString(deviceInfo.getVendor());
372 String model = prepareDashString(deviceInfo.getModel());
373 String serialId = prepareDashString(deviceInfo.getSerialId());
374 String ipAddress = prepareDashString(deviceInfo.getIpAddress().getIpv4Address().getValue());
375 String prefixLength = prepareDashString(deviceInfo.getPrefixLength());
376 String defaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue());
377 String sourceEnum = deviceInfo.getSource().getName();
378 String currentIpAddress = prepareDashString(deviceInfo.getCurrentIpAddress().getIpv4Address().getValue());
379 String currentPrefixLength = prepareDashString(deviceInfo.getCurrentPrefixLength());
380 String currentDefaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue());
381 String macAddress = prepareDashString(deviceInfo.getMacAddress().getValue());
382 String softwareVersion = prepareDashString(deviceInfo.getSoftwareVersion());
383 //String openroadmVersion = "1.2.1";
384 String template = prepareDashString(deviceInfo.getTemplate());
385 String currentDatetime = prepareDashString(deviceInfo.getCurrentDatetime().getValue());
386 String geoLatitude = (deviceInfo.getGeoLocation() != null
387 ? prepareDashString(deviceInfo.getGeoLocation().getLatitude()) : "");
388 String geoLongitude = (deviceInfo.getGeoLocation() != null
389 ? prepareDashString(deviceInfo.getGeoLocation().getLongitude()) : "");
390 String maxDegrees = (deviceInfo.getMaxDegrees() == null ? "-1" : prepareDashString(deviceInfo.getMaxDegrees()));
391 String maxSrgs = (deviceInfo.getMaxSrgs() == null ? "-1" : prepareDashString(deviceInfo.getMaxSrgs()));
392 String swVersion = prepareDashString(deviceInfo.getSoftwareVersion()); //sw_version
393 String swValidationTimer = prepareDashString(""); //sw_validation_timer
394 String activationDateTime = prepareDashString(""); //activation_date_time
395 //Integer maxNumBin15minHistoricalPm = null;
396 //Integer maxNumBin24hourHistoricalPm = null;
397 /*jsonDevInfo = JsonStringBuilder.getDevInfoJson().replace("$$NODE-ID$$",nodeId)
398 .replace("$$NODE-NUMBER$$", nodeNumber)
399 .replace("$$NODE-TYPE$$",nodeType)
400 .replace("$$CLLI$$",clli)
401 .replace("$$VENDOR$$",vendor)
402 .replace("$$MODEL$$",model)
403 .replace("$$SERIAL-ID$$",serialId)
404 .replace("$$IPADDRESS$$",ipAddress)
405 .replace("$$PREFIX-LENGTH$$",prefixLength)
406 .replace("$$DEFAULTGATEWAY$$",defaultGateway)
407 .replace("$$SOURCE$$",String.valueOf(source))
408 .replace("$$CURRENT-IPADDRESS$$",currentIpAddress)
409 .replace("$$CURRENT-PREFIX-LENGTH$$",currentPrefixLength)
410 .replace("$$CURRENT-DEFAULTGATEWAY$$",currentDefailtGateway)
411 .replace("$$MACADDRESS$$",macAddress)
412 .replace("$$SOFTWAREVERSION$$",softwareVersion)
413 .replace("$$OPENROADM-VERSION$$",openroadmVersion)
414 .replace("$$TEMPLATE$$",template)
415 .replace("$$CURRENT-DATETIME$$",currentDatetime)
416 .replace("$$LATITUDE$$",latitude)
417 .replace("$$LONGITUDE$$",longitude)
418 .replace("$$MAX-DEGREES$$",maxDegrees)
419 .replace("$$MAX-SRGS$$",maxSrgs)
420 .replace("$$MAX-NUM-BIN-15MIN-HISTORICAL-PM$$",prepareDashString(""))
421 .replace("$$MAX-NUM-BIN-24HOUR-HISTORICAL-PM$$",prepareDashString(""))
422 .replace("$$SW-VERSION$$",swVersion)
423 .replace("$$SW-VALIDATION-TIMER$$",swValidationTimer)
424 .replace("$$ACTIVATION-DATE-TIME$$",activationDateTime);*/
441 currentDefaultGateway,
452 //maxNumBin15minHistoricalPm,
453 //maxNumBin24hourHistoricalPm,
464 private static Object[] prepareShelvesParameters(String nodeId, Shelves shelve) {
465 String startTimestamp = getCurrentTimestamp();
467 return new Object[]{nodeId,
468 shelve.getShelfName(),
469 shelve.getShelfType(),
471 shelve.getShelfPosition(),
472 (shelve.getAdministrativeState() == null ? null : shelve.getAdministrativeState().getIntValue()),
475 shelve.getSerialId(),
477 shelve.getProductCode(),
478 (shelve.getManufactureDate() == null ? null : shelve.getManufactureDate().getValue()),
480 shelve.getHardwareVersion(),
481 (shelve.getOperationalState() == null ? null : shelve.getOperationalState().getIntValue()),
482 (shelve.getEquipmentState() == null ? null : shelve.getEquipmentState().getIntValue()),
483 (shelve.getDueDate() == null ? null : shelve.getDueDate().getValue()),
489 private static Object[] prepareCPPortsParameters(String nodeId, CircuitPacks circuitPacks, Ports cpPort) {
491 String circuitPackName = circuitPacks.getCircuitPackName();
492 String portName = cpPort.getPortName();
493 String portType = cpPort.getPortType();
494 String portQualEnu = String.valueOf((cpPort.getPortQual() == null ? "-1" : cpPort.getPortQual().getName()));
495 String portWavelengthTypeEnu = "-1"; //cpPort.getPortWavelengthType().getIntValue(); /* Check error*/
496 String portDirectionEnu = String.valueOf((cpPort.getPortDirection() == null ? "" :
497 cpPort.getPortDirection().getName()));
498 String label = cpPort.getLabel();
499 String circuitId = cpPort.getCircuitId();
500 String administrativeStateEnu = (cpPort.getAdministrativeState() == null ? "" :
501 cpPort.getAdministrativeState().getName());
502 String operationalStateEnu =
503 (cpPort.getOperationalState() == null ? "" : cpPort.getOperationalState().getName());
504 String logicalConnectionPoint = cpPort.getLogicalConnectionPoint();
505 String parentPortCircuitPackName = (cpPort.getPartnerPort() == null ? "" :
506 (cpPort.getPartnerPort().getCircuitPackName() == null ? "" : cpPort.getPartnerPort().getCircuitPackName()));
507 String partnerPortPortName = (cpPort.getPartnerPort() == null ? "" :
508 (cpPort.getPartnerPort().getPortName() == null ? "" : cpPort.getPartnerPort().getPortName()));
509 String partnerPortCircuitPackName = (cpPort.getParentPort() == null ? "" :
510 (cpPort.getParentPort().getCircuitPackName() == null ? "" : cpPort.getParentPort().getCircuitPackName()));
511 String parentPortPortName = (cpPort.getParentPort() == null ? "" :
512 (cpPort.getParentPort().getPortName() == null ? "" : cpPort.getParentPort().toString()));
513 String roadmPortPortPowerCapabilityMinRx = (cpPort.getRoadmPort() == null ? "" :
514 (cpPort.getRoadmPort().getPortPowerCapabilityMinRx() == null ? "" :
515 cpPort.getRoadmPort().getPortPowerCapabilityMinRx().toString()));
516 String roadmPortPortPowerCapabilityMinTx = (cpPort.getRoadmPort() == null ? "" :
517 (cpPort.getRoadmPort().getPortPowerCapabilityMinTx() == null ? "" :
518 cpPort.getRoadmPort().getPortPowerCapabilityMinTx().toString()));
519 String roadmPortPortPowerCapabilityMaxRx = (cpPort.getRoadmPort() == null ? "" :
520 (cpPort.getRoadmPort().getPortPowerCapabilityMaxRx() == null ? "" :
521 cpPort.getRoadmPort().getPortPowerCapabilityMaxRx().toString()));
522 String roadmPortPortPowerCapabilityMaxTx = (cpPort.getRoadmPort() == null ? "" :
523 (cpPort.getRoadmPort().getPortPowerCapabilityMaxTx() == null ? "" :
524 cpPort.getRoadmPort().getPortPowerCapabilityMaxTx().toString()));
525 //String roadmPortCapableWavelengths = "";
526 //String roadmPortAvailableWavelengths = "";
527 //String roadmPortUsedWavelengths = "";
528 String transponderPortPortPowerCapabilityMinRx = (cpPort.getTransponderPort() == null ? "" :
529 (cpPort.getTransponderPort().getPortPowerCapabilityMinRx() == null ? "" :
530 cpPort.getTransponderPort().getPortPowerCapabilityMinRx().toString()));
531 String transponderPortPortPowerCapabilityMinTx = (cpPort.getTransponderPort() == null ? "" :
532 (cpPort.getTransponderPort().getPortPowerCapabilityMinTx() == null ? "" :
533 cpPort.getTransponderPort().getPortPowerCapabilityMinTx().toString()));
534 String transponderPortPortPowerCapabilityMaxRx = (cpPort.getTransponderPort() == null ? "" :
535 (cpPort.getTransponderPort().getPortPowerCapabilityMaxRx() == null ? "" :
536 cpPort.getTransponderPort().getPortPowerCapabilityMaxRx().toString()));
537 String transponderPortPortPowerCapabilityMaxTx = (cpPort.getTransponderPort() == null ? "" :
538 (cpPort.getTransponderPort().getPortPowerCapabilityMaxTx() == null ? "" :
539 cpPort.getTransponderPort().getPortPowerCapabilityMaxTx().toString()));
540 //String transponderPortCapableWavelengths = "";
541 String otdrPortLaunchCableLength = (cpPort.getOtdrPort() == null ? "" :
542 (cpPort.getOtdrPort().getLaunchCableLength() == null ? "" :
543 cpPort.getOtdrPort().getLaunchCableLength().toString()));
544 String otdrPortPortDirection = (cpPort.getOtdrPort() == null ? "-1" :
545 (cpPort.getOtdrPort().getPortDirection() == null ? "-1" :
546 Integer.toString(cpPort.getOtdrPort().getPortDirection().getIntValue())));
547 //String ilaPortPortPowerCapabilityMixRx = "";
548 //String ilaPortPortPowerCapabilityMixTx = "";
549 //String ilaPortPortPowerCapabilityMaxRx = "";
550 //String ilaPortPortPowerCapabilityMaxTx = "";
552 String startTimestamp = getCurrentTimestamp();
554 return new Object[]{nodeId,
559 portWavelengthTypeEnu,
563 administrativeStateEnu,
565 logicalConnectionPoint,
566 partnerPortCircuitPackName,
568 parentPortCircuitPackName,
570 roadmPortPortPowerCapabilityMinRx,
571 roadmPortPortPowerCapabilityMinTx,
572 roadmPortPortPowerCapabilityMaxRx,
573 roadmPortPortPowerCapabilityMaxTx,
574 //roadmPortCapableWavelengths,
575 //roadmPortAvailableWavelengths,
576 //roadmPortUsedWavelengths,
578 transponderPortPortPowerCapabilityMinRx,
579 transponderPortPortPowerCapabilityMinTx,
580 transponderPortPortPowerCapabilityMaxRx,
581 transponderPortPortPowerCapabilityMaxTx,
582 //transponderPortCapableWavelengths,
584 otdrPortLaunchCableLength,
585 otdrPortPortDirection,
586 //ilaPortPortPowerCapabilityMixRx,
587 //ilaPortPortPowerCapabilityMixTx,
588 //ilaPortPortPowerCapabilityMaxRx,
589 //ilaPortPortPowerCapabilityMaxTx,
597 private static Object[] prepareCircuitPacksParameters(String nodeId, CircuitPacks cpack) {
598 String startTimestamp = getCurrentTimestamp();
599 return new Object[]{nodeId,
600 cpack.getCircuitPackName(),
601 cpack.getCircuitPackType(),
602 cpack.getCircuitPackProductCode(),
603 (cpack.getAdministrativeState() == null ? "" : cpack.getAdministrativeState().getIntValue()),
608 cpack.getProductCode(),
609 (cpack.getManufactureDate() == null ? "" : cpack.getManufactureDate().getValue()),
611 cpack.getHardwareVersion(),
612 (cpack.getOperationalState() == null ? -1 : cpack.getOperationalState().getIntValue()),
613 cpack.getCircuitPackCategory().getType().getIntValue(),
614 cpack.getCircuitPackCategory().getExtension(),
615 (cpack.getEquipmentState() == null ? -1 : cpack.getEquipmentState().getIntValue()),
616 cpack.getCircuitPackMode(),
620 prepareEmptyString(cpack.getDueDate()),
621 prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" :
622 ((cpack.getParentCircuitPack().getCircuitPackName() == null) ? "" :
623 cpack.getParentCircuitPack().getCircuitPackName())
625 prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" :
626 ((cpack.getParentCircuitPack().getCpSlotName() == null) ? "" :
627 cpack.getParentCircuitPack().getCpSlotName())
634 private void persistCPPorts(String nodeId, Connection connection, CircuitPacks circuitPacks) {
636 Map<PortsKey, Ports> nonnullPorts = circuitPacks.nonnullPorts();
637 for (Map.Entry<PortsKey, Ports> entry : nonnullPorts.entrySet()) {
638 Object[] cpPortsParameters = prepareCPPortsParameters(nodeId, circuitPacks, entry.getValue());
639 String query = Queries.getQuery().deviceCPPortInsert().get();
640 LOG.info("Running {} query ", query);
641 try (PreparedStatement preparedStmt = connection.prepareStatement(query)) {
642 for (int j = 0; j < cpPortsParameters.length; j++) {
643 preparedStmt.setObject(j + 1, cpPortsParameters[j]);
645 preparedStmt.execute();
646 preparedStmt.clearParameters();
647 } catch (SQLException e) {
648 LOG.error("Something wrong when storing Cirtcuits Packs Ports in DB", e);
654 private Object[] prepareDevInterfaceParameters(String nodeId, Interface deviceInterface, Connection connection) {
656 String ethernetDuplexEnu = "";
657 String ethernetAutoNegotiationEnu = "";
658 String maintTestsignalTestpatternEnu = "";
659 String maintTestsignalTypeEnu = "";
660 String otuFecEnu = "";
661 String otuMaintTypeEnu = "";
662 //String otsFiberTypeEnu = "";
663 String ethernetSpeed = "-1";
664 String ethernetFec = "";
665 String ethernetMtu = "-1";
666 String ethernetCurrSpeed = "";
667 String ethernetCurrDuplex = "-1";
668 //String mciMcttpMinFreq = "";
669 //String mciMcttpMaxFreq = "";
670 //String mciMcttpCenterFreq = "";
671 //String mciMcttpSlotWidth = "";
672 //String mciNmcCtpFrequency = "";
673 //String mciNmcCtpWidth = "";
675 //String ochFrequency = "";
676 //String ochWidth = "";
677 String ochWavelengthNumber = "";
678 String ochModulationFormat = "";
679 String ochTransmitPower = "";
680 String otsSpanLossReceive = "";
681 String otsSpanLossTransmit = "";
682 //String otsIngressSpanLossAgingMargin = "";
683 //String otsEolMaxLoadPin = "";
685 //String oduFunction = "";
686 String oduMonitoringMode = "";
687 //String oduNoOamFunction = "";
688 String oduProactiveDelayMeasurementEnabled = "";
689 //String oduPoaTribPortNumber = "-1";
690 //String oduTxSapi = "";
691 //String oduTxDapi = "";
692 //String oduTxOperator = "";
693 //String oduAcceptedSapi = "";
694 //String oduAcceptedDapi = "";
695 //String oduAcceptedOperator = "";
696 //String oduExpectedSapi = "";
697 //String oduExpectedDapi = "";
698 //String oduTimActEnabled = "";
699 //String oduTimDetectMode = "";
700 //String oduDegmIntervals = "-1";
701 //String oduDegthrPercentage = "-1";
702 String opuPayloadType = "";
703 String opuRxPayloadType = "";
704 String opuExpPayloadType = "";
705 String opuPayloadInterface = "";
706 String maintTestsignalEnabled = "";
707 String maintTestsignalBiterrors = "-1";
708 String maintTestsignalBiterrorsterminal = "-1";
709 String maintTestsignalSyncseconds = "-1";
710 String maintTestsignalSyncsecondsterminal = "-1";
712 //String otuTxSapi = "";
713 //String otuTxDapi = "";
714 //String otuTxOperator = "";
715 //String otuAcceptedSapi = "";
716 //String otuAcceptedDapi = "";
717 //String otuAcceptedOperator = "";
718 //String otuExpectedSapi = "";
719 //String otuExpectedDapi = "";
720 //String otuTimActEnabled = "";
721 //String otuTimDetectMode = "";
722 //String otuDegmIntervals = "-1";
723 //String otuDegthrPercentage = "-1";
724 String otuMaintLoopbackEnabled = "";
725 //String mtOtuRate = "";
726 //String mtOtuFec = "";
727 //String mtOtuMaintLoopback = "";
728 //String mtOtuEnabled = "";
729 //String mtOtuType = "";
731 String name = deviceInterface.getName();
732 String description = deviceInterface.getDescription();
733 String type = deviceInterface.getType().getTypeName();
734 String administrativeStateEnu = deviceInterface.getAdministrativeState().getName();
735 int operationalState = deviceInterface.getOperationalState().getIntValue();
736 String circuitId = deviceInterface.getCircuitId();
737 String supportingInterface = deviceInterface.getSupportingInterface();
738 String supportingCircuitPackName = deviceInterface.getSupportingCircuitPackName();
739 String supportingPort = deviceInterface.getSupportingPort();
741 switch (deviceInterface.getType().toString()) {
744 //EthernetBuilder ethIfBuilder = new EthernetBuilder();
745 EthernetBuilder ethIfBuilder = new EthernetBuilder(deviceInterface.augmentation(Interface1.class)
747 ethernetSpeed = (ethIfBuilder.getSpeed() == null ? "-1" :
748 Integer.toString(ethIfBuilder.getSpeed().intValue()));
749 ethernetFec = ethIfBuilder.getFec().getName();
750 ethernetDuplexEnu = (ethIfBuilder.getDuplex() == null ? "" : ethIfBuilder.getDuplex().getName());
751 ethernetMtu = ethIfBuilder.getMtu().toString();
752 ethernetAutoNegotiationEnu = ethIfBuilder.getAutoNegotiation().getName();
753 ethernetCurrSpeed = ethIfBuilder.getCurrSpeed();
754 ethernetCurrDuplex = ethIfBuilder.getCurrDuplex();
758 OchBuilder ochIfBuilder = new OchBuilder(deviceInterface.augmentation(
759 org.opendaylight.yang.gen.v1
760 .http.org.openroadm.optical.channel.interfaces.rev161014.Interface1.class)
762 ochRate = ochIfBuilder.getRate().getName();
763 ochWavelengthNumber = ochIfBuilder.getWavelengthNumber().toString();
764 ochModulationFormat = ochIfBuilder.getModulationFormat().getName();
765 ochTransmitPower = ochIfBuilder.getTransmitPower().toString();
769 OtsBuilder otsIfBuilder = new OtsBuilder(deviceInterface.augmentation(
770 org.opendaylight.yang.gen.v1
771 .http.org.openroadm.optical.transport.interfaces.rev161014.Interface1.class)
773 //otsFiberTypeEnu = String.valueOf(otsIfBuilder.getFiberType().getIntValue());
774 otsSpanLossReceive = otsIfBuilder.getSpanLossReceive().toString();
775 otsSpanLossTransmit = otsIfBuilder.getSpanLossTransmit().toString();
779 OduBuilder oduIfBuilder = new OduBuilder(deviceInterface.augmentation(
780 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.Interface1.class)
782 oduRate = String.valueOf(oduIfBuilder.getRate());
783 oduMonitoringMode = oduIfBuilder.getMonitoringMode().getName();
784 oduProactiveDelayMeasurementEnabled = oduIfBuilder.getProactiveDelayMeasurementEnabled().toString();
786 persistDevInterfaceTcm(nodeId, name, oduIfBuilder, connection);
787 persistDevInterfaceOtnOduTxMsi(nodeId, name, oduIfBuilder, connection);
788 persistDevInterfaceOtnOduRxMsi(nodeId, name, oduIfBuilder, connection);
789 persistDevInterfaceOtnOduExpMsi(nodeId, name, oduIfBuilder, connection);
791 opuPayloadType = oduIfBuilder.getOpu().getPayloadType();
792 opuRxPayloadType = oduIfBuilder.getOpu().getRxPayloadType();
793 opuExpPayloadType = oduIfBuilder.getOpu().getExpPayloadType();
794 opuPayloadInterface = oduIfBuilder.getOpu().getPayloadInterface();
795 /*persistDevInterfaceOtnOduTxMsi(nodeId,name,oduIfBuilder,connection);
796 persistDevInterfaceOtnOduRxMsi(nodeId,name,oduIfBuilder,connection);
797 persistDevInterfaceOtnOduExpMsi(nodeId,name,oduIfBuilder,connection); */
798 maintTestsignalEnabled = oduIfBuilder.getMaintTestsignal().getEnabled().toString();
799 maintTestsignalTestpatternEnu = oduIfBuilder.getMaintTestsignal().getTestPattern().getName();
800 maintTestsignalTypeEnu = oduIfBuilder.getMaintTestsignal().getType().getName();
801 maintTestsignalBiterrors = Integer.toString(
802 oduIfBuilder.getMaintTestsignal().getBitErrors().intValue());
803 maintTestsignalBiterrorsterminal = oduIfBuilder.getMaintTestsignal().getBitErrorsTerminal().toString();
804 maintTestsignalSyncseconds = oduIfBuilder.getMaintTestsignal().getSyncSeconds();
805 maintTestsignalSyncsecondsterminal = oduIfBuilder.getMaintTestsignal().getSyncSecondsTerminal();
809 OtuBuilder otuIfBuilder =
810 new OtuBuilder(deviceInterface.augmentation(
811 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.Interface1.class)
813 otuRate = otuIfBuilder.getRate().getName();
814 otuFecEnu = otuIfBuilder.getFec().getName();
815 otuMaintLoopbackEnabled = otuIfBuilder.getMaintLoopback().getEnabled().toString();
816 otuMaintTypeEnu = otuIfBuilder.getMaintLoopback().getType().getName();
820 LOG.error("could not get interface type");
824 String startTimestamp = getCurrentTimestamp();
826 return new Object[]{nodeId,
830 administrativeStateEnu,
831 Integer.toString(operationalState),
834 supportingCircuitPackName,
840 ethernetAutoNegotiationEnu,
845 //mciMcttpCenterFreq,
847 //mciNmcCtpFrequency,
849 "", "", "", "", "", "",
860 //otsIngressSpanLossAgingMargin,
869 oduProactiveDelayMeasurementEnabled,
870 //oduPoaTribPortNumber,
876 //oduAcceptedOperator,
882 //oduDegthrPercentage,
883 "-1", "", "", "", "", "","", "", "", "", "", "-1", "-1",
888 maintTestsignalEnabled,
889 maintTestsignalTestpatternEnu,
890 maintTestsignalTypeEnu,
891 maintTestsignalBiterrors,
892 maintTestsignalBiterrorsterminal,
893 maintTestsignalSyncseconds,
894 maintTestsignalSyncsecondsterminal,
902 //otuAcceptedOperator,
908 //otuDegthrPercentage,
909 "", "", "", "", "", "","", "", "", "", "-1", "-1",
910 otuMaintLoopbackEnabled,
914 //mtOtuMaintLoopback,
924 private static Object[] prepareDevInterfaceTcmParameters(String nodeId, String interfaceName, Tcm tcm) {
926 String layer = tcm.getLayer().toString();
927 String monitoringModeEnu = tcm.getMonitoringMode().getName();
928 String ltcActEnabled = tcm.getLtcActEnabled().toString();
929 String proactiveDelayMeasurementEnabled = tcm.getProactiveDelayMeasurementEnabled().toString();
930 //String tcmDirectionEnu = "";
931 //String timDetectModeEnu = "";
932 //String txSapi = "";
933 //String txDapi = "";
934 //String txOperator = "";
935 //String acceptedSapi = "";
936 //String acceptedDapi = "";
937 //String acceptedOperator = "";
938 //String expectedSapi = "";
939 //String expectedDapi = "";
940 //String timActEnabled = "";
941 //String degmIntervals = "";
942 //String degthrPercentage = "";
943 String startTimestamp = getCurrentTimestamp();
945 return new Object[]{nodeId,
950 proactiveDelayMeasurementEnabled,
964 "", "", "", "", "", "", "", "", "", "", "", "", "",
970 private static Object[] prepareDevInterfaceOtnOduTxMsiParameters(String nodeId, String interfaceName, TxMsi txMsi) {
972 String tribSlot = txMsi.getTribSlot().toString();
973 String odtuType = txMsi.getOdtuType().getTypeName();
974 String tribPort = txMsi.getTribPort().toString();
975 String tribPortPayload = txMsi.getTribPortPayload();
977 String startTimestamp = getCurrentTimestamp();
979 return new Object[]{nodeId,
991 private static Object[] prepareDevInterfaceOtnOduRxMsiParameters(String nodeId, String interfaceName, RxMsi rxMsi) {
993 String tribSlot = rxMsi.getTribSlot().toString();
994 String odtuType = rxMsi.getOdtuType().getTypeName();
995 String tribPort = rxMsi.getTribPort().toString();
996 String tribPortPayload = rxMsi.getTribPortPayload();
998 String startTimestamp = getCurrentTimestamp();
1000 return new Object[]{nodeId,
1013 private static Object[] prepareDevInterfaceOtnOduExpMsiParameters(String nodeId, String interfaceName,
1016 String tribSlot = expMsi.getTribSlot().toString();
1017 String odtuType = expMsi.getOdtuType().getTypeName();
1018 String tribPort = expMsi.getTribPort().toString();
1019 String tribPortPayload = expMsi.getTribPortPayload();
1021 String startTimestamp = getCurrentTimestamp();
1023 return new Object[]{nodeId,
1035 private void persistDevInterfaces(String nodeId, Connection connection) {
1037 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1038 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1040 Optional<OrgOpenroadmDevice> deviceObject =
1041 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1042 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1043 if (!deviceObject.isPresent()) {
1046 Map<InterfaceKey, Interface> interfaceMap = deviceObject.get().nonnullInterface();
1047 for (Map.Entry<InterfaceKey, Interface> interfaceEntrySet : interfaceMap.entrySet()) {
1048 Interface deviceInterface = interfaceEntrySet.getValue();
1049 Object[] parameters = prepareDevInterfaceParameters(nodeId, deviceInterface, connection);
1051 String query = Queries.getQuery().deviceInterfacesInsert().get();
1052 LOG.info("Running {} query ", query);
1053 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1054 for (int j = 0; j < parameters.length; j++) {
1055 stmt.setObject(j + 1, parameters[j]);
1058 stmt.clearParameters();
1059 } catch (SQLException e) {
1060 LOG.error("Something wrong when storing devices interfaces in DB", e);
1065 private void persistDevProtocols(String nodeId, Connection connection) {
1067 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier
1068 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1069 .child(Protocols.class)
1071 Optional<Protocols> protocolObject =
1072 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1073 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1074 if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
1075 LOG.error("LLDP subtree is missing");
1078 String adminstatusEnu = protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig()
1079 .getAdminStatus().getName();
1080 String msgTxtInterval = protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig()
1081 .getMsgTxInterval().toString();
1082 String mxgTxHoldMultiplier = protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig()
1083 .getMsgTxHoldMultiplier().toString();
1084 String startTimestamp = getCurrentTimestamp();
1085 persistDevProtocolLldpPortConfig(nodeId, connection);
1086 persistDevProtocolLldpNbrList(nodeId, connection);
1088 Object[] parameters = {nodeId,
1091 mxgTxHoldMultiplier,
1096 String query = Queries.getQuery().deviceProtocolInsert().get();
1097 LOG.info("Running {} query ", query);
1098 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1099 for (int j = 0; j < parameters.length; j++) {
1100 stmt.setObject(j + 1, parameters[j]);
1103 stmt.clearParameters();
1104 } catch (SQLException e) {
1105 LOG.error("Something wrong when storing devices protocols in DB", e);
1110 private void persistDevProtocolLldpPortConfig(String nodeId, Connection connection) {
1112 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier
1113 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1114 .child(Protocols.class)
1116 Optional<Protocols> protocolObject =
1117 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1118 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1119 if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
1120 LOG.error("LLDP subtree is missing");
1123 String startTimestamp = getCurrentTimestamp();
1125 Map<PortConfigKey, PortConfig> portConfigMap = protocolObject.get()
1126 .augmentation(Protocols1.class).getLldp().nonnullPortConfig();
1127 for (Map.Entry<PortConfigKey, PortConfig> entry : portConfigMap.entrySet()) {
1128 PortConfig portConfig = entry.getValue();
1129 String ifName = portConfig.getIfName();
1130 String adminStatusEnu = portConfig.getAdminStatus().getName();
1132 Object[] parameters = {nodeId,
1139 String query = Queries.getQuery().deviceProtocolPortConfigInsert().get();
1140 LOG.info("Running {} query ", query);
1141 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1142 for (int j = 0; j < parameters.length; j++) {
1143 stmt.setObject(j + 1, parameters[j]);
1146 stmt.clearParameters();
1147 } catch (SQLException e) {
1148 LOG.error("Something wrong when storing devices protocols LLDP Port config in DB", e);
1155 private void persistDevProtocolLldpNbrList(String nodeId, Connection connection) {
1157 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier
1158 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1159 .child(Protocols.class)
1161 Optional<Protocols> protocolObject =
1162 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1163 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1164 if (!protocolObject.isPresent()) {
1165 LOG.error("Protocols is missing");
1168 if (protocolObject.get().augmentation(Protocols1.class).getLldp().getNbrList() == null) {
1170 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, protocolsIID,
1171 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1172 if (protocolObject.get().augmentation(Protocols1.class).getLldp().getNbrList() == null) {
1173 LOG.error("LLDP nbrlist subtree is missing for {}", nodeId);
1177 String startTimestamp = getCurrentTimestamp();
1178 Map<IfNameKey, IfName> ifNameMap =
1179 protocolObject.get().augmentation(Protocols1.class).getLldp().getNbrList().nonnullIfName();
1180 for (Map.Entry<IfNameKey, IfName> ifNameEntry : ifNameMap.entrySet()) {
1182 IfName ifNameObj = ifNameEntry.getValue();
1183 String ifName = ifNameObj.getIfName();
1184 String remotesysname = ifNameObj.getRemoteSysName();
1185 String remotemgmtaddresssubtype = ifNameObj.getRemoteMgmtAddressSubType().getName();
1186 String remotemgmtaddress = ifNameObj.getRemoteMgmtAddress().getIpv4Address().toString();
1187 String remoteportidsubtypeEnu = ifNameObj.getRemotePortIdSubType().getName();
1188 String remoteportid = ifNameObj.getRemotePortId();
1189 String remotechassisidsubtypeEnu = ifNameObj.getRemoteChassisIdSubType().getName();
1190 String remotechassisid = ifNameObj.getRemoteChassisId();
1192 Object[] parameters = {nodeId,
1195 remotemgmtaddresssubtype,
1197 remoteportidsubtypeEnu,
1199 remotechassisidsubtypeEnu,
1205 String query = Queries.getQuery().deviceProtocolLldpNbrlistInsert().get();
1206 LOG.info("Running {} query ", query);
1207 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1208 for (int j = 0; j < parameters.length; j++) {
1209 stmt.setObject(j + 1, parameters[j]);
1212 stmt.clearParameters();
1213 } catch (SQLException e) {
1214 LOG.error("Something wrong when storing devices protocols LLDP list number in DB", e);
1220 private void persistDevInternalLinks(String nodeId, Connection connection) {
1222 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1223 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1225 Optional<OrgOpenroadmDevice> deviceObject =
1226 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1227 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1228 if (!deviceObject.isPresent()) {
1231 if (deviceObject.get().getInternalLink() == null) {
1232 deviceObject = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION,
1233 deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1234 if (deviceObject.get().getInternalLink() == null) {
1235 LOG.info("External links not found for {}", nodeId);
1240 Map<InternalLinkKey, InternalLink> internalLinkMap = deviceObject.get().nonnullInternalLink();
1241 String startTimestamp = getCurrentTimestamp();
1242 for (Map.Entry<InternalLinkKey, InternalLink> internalLinkEntry: internalLinkMap.entrySet()) {
1243 InternalLink internalLink = internalLinkEntry.getValue();
1244 String internalLinkName = internalLink.getInternalLinkName();
1245 String sourceCircuitPackName = internalLink.getSource().getCircuitPackName();
1246 String sourcePortName = internalLink.getSource().getPortName();
1247 String destinationCircuitPackName = internalLink.getDestination().getCircuitPackName();
1248 String destinationPortName = internalLink.getDestination().getPortName();
1250 Object[] parameters = { nodeId, internalLinkName, sourceCircuitPackName, sourcePortName,
1251 destinationCircuitPackName, destinationPortName, startTimestamp, startTimestamp };
1252 String query = Queries.getQuery().deviceInternalLinkInsert().get();
1253 LOG.info("Running {} query ", query);
1254 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1255 for (int j = 0; j < parameters.length; j++) {
1256 stmt.setObject(j + 1, parameters[j]);
1259 stmt.clearParameters();
1260 } catch (SQLException e) {
1261 LOG.error("Something wrong when storing devices internal links", e);
1267 private void persistDevExternalLinks(String nodeId, Connection connection) {
1269 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1270 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1272 Optional<OrgOpenroadmDevice> deviceObject =
1273 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1274 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1275 if (!deviceObject.isPresent()) {
1278 if (deviceObject.get().getExternalLink() == null) {
1279 deviceObject = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION,
1280 deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1281 if (deviceObject.get().getExternalLink() == null) {
1282 LOG.info("External links not found for {}", nodeId);
1286 String startTimestamp = getCurrentTimestamp();
1288 Map<ExternalLinkKey, ExternalLink> externalLinkMap = deviceObject.get().nonnullExternalLink();
1289 for (Map.Entry<ExternalLinkKey, ExternalLink> externalLinkEntry: externalLinkMap.entrySet()) {
1290 ExternalLink externalLink = externalLinkEntry.getValue();
1291 String externalLinkName = externalLink.getExternalLinkName();
1292 String sourceNodeId = externalLink.getSource().getNodeId();
1293 String sourceCircuitPackName = externalLink.getSource().getCircuitPackName();
1294 String sourcePortName = externalLink.getSource().getPortName();
1295 String destinationNodeId = externalLink.getDestination().getNodeId();
1296 String destinationCircuitPackName = externalLink.getDestination().getCircuitPackName();
1297 String destinationPortName = externalLink.getDestination().getPortName();
1299 Object[] parameters = { nodeId, externalLinkName, sourceNodeId, sourceCircuitPackName,
1300 sourcePortName, destinationNodeId, destinationCircuitPackName, destinationPortName,
1301 startTimestamp, startTimestamp };
1303 String query = Queries.getQuery().deviceExternalLinkInsert().get();
1304 LOG.info("Running {} query ", query);
1305 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1306 for (int j = 0; j < parameters.length; j++) {
1307 stmt.setObject(j + 1, parameters[j]);
1310 stmt.clearParameters();
1311 } catch (SQLException e) {
1312 LOG.error("Something wrong when storing devices external links", e);
1317 private void persistDevPhysicalLinks(String nodeId, Connection connection) {
1319 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1320 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1322 Optional<OrgOpenroadmDevice> deviceObject =
1323 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1324 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1325 if (!deviceObject.isPresent()) {
1326 LOG.error("No device with node Id {}", nodeId);
1329 if (deviceObject.get().getPhysicalLink() == null) {
1331 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1332 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1333 if (!deviceObject.isPresent()) {
1334 LOG.error("No device with node Id {}", nodeId);
1337 if (deviceObject.get().getPhysicalLink() == null) {
1338 LOG.info("Physical links not found for {}", nodeId);
1343 String startTimestamp = getCurrentTimestamp();
1345 Map<PhysicalLinkKey, PhysicalLink> physicalLinkMap = deviceObject.get().nonnullPhysicalLink();
1346 for (Map.Entry<PhysicalLinkKey, PhysicalLink> physicalLinkEntry : physicalLinkMap.entrySet()) {
1347 PhysicalLink physicalLink = physicalLinkEntry.getValue();
1348 String physicalLinkName = physicalLink.getPhysicalLinkName();
1349 String sourceCircuitPackName = physicalLink.getSource().getCircuitPackName();
1350 String sourcePortName = physicalLink.getSource().getPortName();
1351 String destinationCircuitPackName = physicalLink.getDestination().getCircuitPackName();
1352 String destinationPortName = physicalLink.getDestination().getPortName();
1354 Object[] parameters = {nodeId,
1356 sourceCircuitPackName,
1358 destinationCircuitPackName,
1359 destinationPortName,
1364 String query = Queries.getQuery().devicePhysicalLinkInsert().get();
1365 LOG.info("Running {} query ", query);
1366 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1367 for (int j = 0; j < parameters.length; j++) {
1368 stmt.setObject(j + 1, parameters[j]);
1371 stmt.clearParameters();
1372 } catch (SQLException e) {
1373 LOG.error("Something wrong when storing devices physical links", e);
1379 private void persistDevDegree(String nodeId, Connection connection) {
1381 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1382 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1384 Optional<OrgOpenroadmDevice> deviceObject =
1385 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1386 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1389 /*if (deviceObject.get().getDegree()==null){
1391 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1392 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1394 if (!deviceObject.isPresent()) {
1395 LOG.error("Cannot get device for node {}", nodeId);
1398 String startTimestamp = getCurrentTimestamp();
1400 Map<DegreeKey, Degree> degreeMap = deviceObject.get().nonnullDegree();
1401 for (Map.Entry<DegreeKey, Degree> degreeEntry : degreeMap.entrySet()) {
1402 Degree degree = degreeEntry.getValue();
1403 String degreeNumber = degree.getDegreeNumber().toString();
1404 String maxWavelengths = degree.getMaxWavelengths().toString();
1405 String otdrPortCircuitPackName =
1406 (degree.getOtdrPort() == null ? "" : degree.getOtdrPort().getCircuitPackName());
1407 String otdrPortPortName =
1408 (degree.getOtdrPort() == null ? "" : degree.getOtdrPort().getPortName());
1409 // String mcCapabilitiesSlotWidthGranularity = "";
1410 // String mcCapabilitiesCenterFreqGranularity = "";
1411 // String mcCapabilitiesMinSlots = "-1";
1412 // String mcCapabilitiesMaxSlots = "-1";
1413 persistDevDegreeCircuitPack(nodeId, degree, degreeNumber, connection);
1414 persistDevDegreeConnectionPort(nodeId, degree, degreeNumber, connection);
1416 Object[] parameters = { nodeId, degreeNumber, maxWavelengths, otdrPortCircuitPackName, otdrPortPortName,
1417 // mcCapabilitiesSlotWidthGranularity,
1418 // mcCapabilitiesCenterFreqGranularity,
1419 // mcCapabilitiesMinSlots,
1420 // mcCapabilitiesMaxSlots,
1421 "", "", "-1", "-1", startTimestamp, startTimestamp };
1423 String query = Queries.getQuery().deviceDegreeInsert().get();
1424 LOG.info("Running {} query ", query);
1425 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1426 for (int j = 0; j < parameters.length; j++) {
1427 stmt.setObject(j + 1, parameters[j]);
1430 stmt.clearParameters();
1431 } catch (SQLException e) {
1432 LOG.error("Something wrong when storing devices degrees", e);
1439 private void persistDevDegreeCircuitPack(String nodeId, Degree degree, String degreeNumber, Connection connection) {
1441 String startTimestamp = getCurrentTimestamp();
1443 Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1444 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks>
1445 circuitPacksMap = degree.nonnullCircuitPacks();
1446 for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1447 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks> circuitPackEntry :
1448 circuitPacksMap.entrySet()) {
1450 String circuitPackIndex = circuitPackEntry.getValue().getIndex().toString();
1451 String circuitPackName = circuitPackEntry.getValue().getCircuitPackName();
1453 Object[] parameters = {nodeId,
1461 String query = Queries.getQuery().deviceDegreeCircuitPackInsert().get();
1462 LOG.info("Running {} query ", query);
1463 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1464 for (int j = 0; j < parameters.length; j++) {
1465 stmt.setObject(j + 1, parameters[j]);
1468 stmt.clearParameters();
1469 } catch (SQLException e) {
1470 LOG.error("Something wrong when storing devices degrees circuit packs", e);
1476 private void persistDevDegreeConnectionPort(String nodeId, Degree degree, String degreeNumber,
1477 Connection connection) {
1479 String startTimestamp = getCurrentTimestamp();
1481 Map<ConnectionPortsKey, ConnectionPorts> connectionPortsMap = degree.nonnullConnectionPorts();
1482 for (Map.Entry<ConnectionPortsKey, ConnectionPorts> portEntry : connectionPortsMap.entrySet()) {
1483 String connectionPortIndex = portEntry.getValue().getIndex().toString();
1484 String circuitPackName = portEntry.getValue().getCircuitPackName();
1485 String portName = portEntry.getValue().getPortName();
1487 Object[] parameters = {nodeId,
1489 connectionPortIndex,
1496 String query = Queries.getQuery().deviceDegreeConnectionPortInsert().get();
1497 LOG.info("Running {} query ", query);
1498 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1499 for (int j = 0; j < parameters.length; j++) {
1500 stmt.setObject(j + 1, parameters[j]);
1503 stmt.clearParameters();
1504 } catch (SQLException e) {
1505 LOG.error("Something wrong when storing devices degrees connection ports", e);
1512 private void persistDevSrg(String nodeId, Connection connection) {
1514 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1515 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1517 Optional<OrgOpenroadmDevice> deviceObject =
1518 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1519 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1520 if (!deviceObject.isPresent()) {
1521 LOG.error("No device found in operational datastore for node {}", nodeId);
1525 if (deviceObject.get().getSharedRiskGroup() == null) {
1527 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1528 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1529 if (!deviceObject.isPresent()) {
1530 LOG.error("No device found in configuration datastore for node {}", nodeId);
1536 Map<SharedRiskGroupKey, SharedRiskGroup> sharedRiskGroupMap = deviceObject.get().nonnullSharedRiskGroup();
1537 if (sharedRiskGroupMap.isEmpty()) {
1538 LOG.info("no srg found for node {} ", nodeId);
1541 String startTimestamp = getCurrentTimestamp();
1542 for (Map.Entry<SharedRiskGroupKey, SharedRiskGroup> groupEntry : sharedRiskGroupMap.entrySet()) {
1543 SharedRiskGroup sharedRiskGroup = groupEntry.getValue();
1544 //String currentProvisionedAddDropPorts = "-1";
1545 //String mcCapSlotWidthGranularity = "";
1546 //String mcCapCenterFreqGranularity = "";
1547 //String mcCapMinSlots = "-1";
1548 //String mcCapMaxSlots = "-1";
1549 String maxAddDropPorts = sharedRiskGroup.getMaxAddDropPorts().toString();
1550 String srgNumber = sharedRiskGroup.getSrgNumber().toString();
1551 String wavelengthDuplicationEnu = sharedRiskGroup.getWavelengthDuplication().getName();
1552 persistDevSrgCircuitPacks(nodeId, sharedRiskGroup, srgNumber, connection);
1554 Object[] parameters = {nodeId,
1556 //currentProvisionedAddDropPorts,
1559 wavelengthDuplicationEnu,
1560 //mcCapSlotWidthGranularity,
1561 //mcCapCenterFreqGranularity,
1569 String query = Queries.getQuery().deviceSharedRiskGroupInsert().get();
1570 LOG.info("Running {} query ", query);
1571 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1572 for (int j = 0; j < parameters.length; j++) {
1573 stmt.setObject(j + 1, parameters[j]);
1576 stmt.clearParameters();
1577 } catch (SQLException e) {
1578 LOG.error("Something wrong when storing devices SRG", e);
1585 private void persistDevSrgCircuitPacks(String nodeId, SharedRiskGroup sharedRiskGroup, String srgNumber,
1586 Connection connection) {
1588 String startTimestamp = getCurrentTimestamp();
1590 Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1591 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>
1592 circuitPacksMap = sharedRiskGroup.nonnullCircuitPacks();
1593 for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1594 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> entry :
1595 circuitPacksMap.entrySet()) {
1597 String circuitPackindex = entry.getValue().getIndex().toString();
1598 String circuitPackName = entry.getValue().getCircuitPackName();
1600 Object[] parameters = {nodeId,
1608 String query = Queries.getQuery().deviceSrgCircuitPackInsert().get();
1609 LOG.info("Running {} query ", query);
1610 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1611 for (int j = 0; j < parameters.length; j++) {
1612 stmt.setObject(j + 1, parameters[j]);
1615 stmt.clearParameters();
1616 } catch (SQLException e) {
1617 LOG.error("Something wrong when storing devices SRG circuit packs", e);
1623 private void persistDevRoadmConnections(String nodeId, Connection connection) {
1625 //int opticalcontrolmodeEnu=-1;
1627 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1628 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1630 Optional<OrgOpenroadmDevice> deviceObject =
1631 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1632 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1633 if (!deviceObject.isPresent()) {
1634 LOG.error("No device found in operational datastore for node {}", nodeId);
1637 if (deviceObject.get().getRoadmConnections() == null) {
1639 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1640 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1641 if (!deviceObject.isPresent()) {
1642 LOG.error("No device found in configuration datastore for node {}", nodeId);
1648 Map<RoadmConnectionsKey, RoadmConnections> connectionsMap = deviceObject.get().nonnullRoadmConnections();
1649 if (connectionsMap.isEmpty()) {
1650 LOG.info("ROADM Dev Connections not found!! for {}", nodeId);
1653 String startTimestamp = getCurrentTimestamp();
1654 for (Map.Entry<RoadmConnectionsKey, RoadmConnections> entry : connectionsMap.entrySet()) {
1655 RoadmConnections roadmConnections = entry.getValue();
1656 String connectionNumber = roadmConnections.getConnectionNumber();
1657 //String connectionName = "";
1658 String wavelengthNumber = roadmConnections.getWavelengthNumber().toString();
1659 String opticalcontrolmodeEnu = roadmConnections.getOpticalControlMode().getName();
1660 String targetOutputPower = roadmConnections.getTargetOutputPower().toString();
1661 String srcIf = roadmConnections.getSource().getSrcIf();
1662 String dstIf = roadmConnections.getDestination().getDstIf();
1664 Object[] parameters = {nodeId,
1669 opticalcontrolmodeEnu,
1677 String query = Queries.getQuery().deviceRoadmConnectionsInsert().get();
1678 LOG.info("Running {} query ", query);
1679 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1680 for (int j = 0; j < parameters.length; j++) {
1681 stmt.setObject(j + 1, parameters[j]);
1684 stmt.clearParameters();
1685 } catch (SQLException e) {
1686 LOG.error("Something wrong when storing devices ROADM connection ", e);
1692 private void persistDevConnectionMap(String nodeId, Connection connection) {
1694 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1695 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1697 Optional<OrgOpenroadmDevice> deviceObject =
1698 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1699 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1700 if (!deviceObject.isPresent()) {
1701 LOG.error("No device found in operational datastore for node {}", nodeId);
1704 String startTimestamp = getCurrentTimestamp();
1706 Map<ConnectionMapKey, ConnectionMap> connectionsMap = deviceObject.get().nonnullConnectionMap();
1707 for (Map.Entry<ConnectionMapKey, ConnectionMap> entry : connectionsMap.entrySet()) {
1708 ConnectionMap connectionMap = entry.getValue();
1709 String connectionMapNumber = connectionMap.getConnectionMapNumber().toString();
1710 String sourceCircuitPackName = connectionMap.getSource().getCircuitPackName();
1711 String sourcePortName = connectionMap.getSource().getCircuitPackName();
1714 Object[] parameters = {nodeId,
1715 connectionMapNumber,
1716 sourceCircuitPackName,
1722 String query = Queries.getQuery().deviceConnectionMapInsert().get();
1723 LOG.info("Running {} query ", query);
1724 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1725 for (int j = 0; j < parameters.length; j++) {
1726 stmt.setObject(j + 1, parameters[j]);
1729 stmt.clearParameters();
1730 } catch (SQLException e) {
1731 LOG.error("Something wrong when storing devices connection map", e);
1737 private void persistDevWavelengthMap(String nodeId, Connection connection) {
1739 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1740 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1742 Optional<OrgOpenroadmDevice> deviceObject =
1743 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1744 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1745 if (!deviceObject.isPresent()) {
1746 LOG.error("No device found in operational datastore for node {}", nodeId);
1750 String startTimestamp = getCurrentTimestamp();
1752 Map<WavelengthsKey, Wavelengths> wavelengthsMap = deviceObject.get().getWavelengthMap().nonnullWavelengths();
1753 for (Map.Entry<WavelengthsKey, Wavelengths> entry : wavelengthsMap.entrySet()) {
1754 Wavelengths wavelengths = entry.getValue();
1755 String wavelengthNumber = wavelengths.getWavelengthNumber().toString();
1756 String centerFrequency = wavelengths.getCenterFrequency().toString();
1757 String wavelength = wavelengths.getWavelength().toString();
1760 Object[] parameters = {nodeId,
1768 String query = Queries.getQuery().deviceWavelengthInsert().get();
1769 LOG.info("Running {} query ", query);
1770 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1771 for (int j = 0; j < parameters.length; j++) {
1772 stmt.setObject(j + 1, parameters[j]);
1775 stmt.clearParameters();
1776 } catch (SQLException e) {
1777 LOG.error("Something wrong when storing devices wavelength map", e);
1784 private void persistDevInterfaceTcm(String nodeId, String interfaceName, OduBuilder oduBuilder,
1785 Connection connection) {
1787 Map<TcmKey, Tcm> tcmMap = oduBuilder.getTcm();
1788 for (Map.Entry<TcmKey, Tcm> entry : tcmMap.entrySet()) {
1789 Tcm tcm = entry.getValue();
1791 Object[] parameters = prepareDevInterfaceTcmParameters(nodeId, interfaceName, tcm);
1793 String query = Queries.getQuery().deviceInterfacesInsert().get();
1794 LOG.info("Running {} query ", query);
1795 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1796 for (int j = 0; j < parameters.length; j++) {
1797 stmt.setObject(j + 1, parameters[j]);
1800 stmt.clearParameters();
1801 } catch (SQLException e) {
1802 LOG.error("Something wrong when storing devices interface tcm", e);
1807 private void persistDevInterfaceOtnOduTxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1808 Connection connection) {
1810 Map<TxMsiKey, TxMsi> txMsiMap = oduBuilder.getOpu().getMsi().nonnullTxMsi();
1811 for (Map.Entry<TxMsiKey, TxMsi> entry : txMsiMap.entrySet()) {
1813 TxMsi txMsi = entry.getValue();
1815 Object[] parameters = prepareDevInterfaceOtnOduTxMsiParameters(nodeId, interfaceName, txMsi);
1817 String query = Queries.getQuery().deviceInterfaceOtnOduTxMsiInsert().get();
1818 LOG.info("Running {} query ", query);
1819 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1820 for (int j = 0; j < parameters.length; j++) {
1821 stmt.setObject(j + 1, parameters[j]);
1824 stmt.clearParameters();
1825 } catch (SQLException e) {
1826 LOG.error("Something wrong when storing devices interface OTN ODU Tx MSI", e);
1832 private void persistDevInterfaceOtnOduRxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1833 Connection connection) {
1834 Map<RxMsiKey, RxMsi> rxMsiMap = oduBuilder.getOpu().getMsi().nonnullRxMsi();
1835 for (Map.Entry<RxMsiKey, RxMsi> entry : rxMsiMap.entrySet()) {
1836 RxMsi rxMsi = entry.getValue();
1838 Object[] parameters = prepareDevInterfaceOtnOduRxMsiParameters(nodeId, interfaceName, rxMsi);
1840 String query = Queries.getQuery().deviceInterfaceOtnOduRxMsiInsert().get();
1841 LOG.info("Running {} query ", query);
1842 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1843 for (int j = 0; j < parameters.length; j++) {
1844 stmt.setObject(j + 1, parameters[j]);
1847 stmt.clearParameters();
1848 } catch (SQLException e) {
1849 LOG.error("Something wrong when storing devices interface OTN ODU Rx MSI", e);
1855 private void persistDevInterfaceOtnOduExpMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1856 Connection connection) {
1858 Map<ExpMsiKey, ExpMsi> expMsiMap = oduBuilder.getOpu().getMsi().nonnullExpMsi();
1859 for (Map.Entry<ExpMsiKey, ExpMsi> entry : expMsiMap.entrySet()) {
1860 ExpMsi expMsi = entry.getValue();
1862 Object[] parameters = prepareDevInterfaceOtnOduExpMsiParameters(nodeId, interfaceName, expMsi);
1864 String query = Queries.getQuery().deviceInterfaceOtnOduExpMsiInsert().get();
1865 LOG.info("Running {} query ", query);
1866 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1867 for (int j = 0; j < parameters.length; j++) {
1868 stmt.setObject(j + 1, parameters[j]);
1871 stmt.clearParameters();
1872 } catch (SQLException e) {
1873 LOG.error("Something wrong when storing devices interface OTN ODU Exp MSI", e);