9d7aa642334dfeb43684d417363265b8353fca84
[transportpce.git] / inventory / src / main / java / org / opendaylight / transportpce / inventory / INode121.java
1 /*
2  * Copyright © 2017 AT&T and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.transportpce.inventory;
10
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;
15
16 import java.sql.Connection;
17 import java.sql.PreparedStatement;
18 import java.sql.ResultSet;
19 import java.sql.SQLException;
20 import java.util.Optional;
21 import java.util.concurrent.ExecutionException;
22 import javax.sql.DataSource;
23 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
24 import org.opendaylight.transportpce.common.Timeouts;
25 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
26 import org.opendaylight.transportpce.inventory.query.Queries;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.CpSlots;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLink;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLink;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnections;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLink;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.Slots;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.Shelves;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.Interface1;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.ethernet.container.EthernetBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfig;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfName;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.och.container.OchBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.OtsBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.Tcm;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.container.OduBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsi;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsi;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsi;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.otu.container.OtuBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.rstp.bridge.port.attr.RstpBridgePortTable;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.rstp.container.rstp.RstpBridgeInstance;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.wavelength.map.rev161014.wavelength.map.g.Wavelengths;
59 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
60 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory;
62
63 public class INode121 {
64
65     private static final Logger LOG = LoggerFactory.getLogger(INode121.class);
66
67     private final DataSource dataSource;
68     private final DeviceTransactionManager deviceTransactionManager;
69
70     public INode121(DataSource dataSource, DeviceTransactionManager deviceTransactionManager) {
71         this.dataSource = dataSource;
72         this.deviceTransactionManager = deviceTransactionManager;
73     }
74
75     public boolean addNode(String deviceId) {
76
77         InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
78         Optional<Info> infoOpt =
79                 deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.OPERATIONAL, infoIID,
80                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
81         Info deviceInfo;
82         if (infoOpt.isPresent()) {
83             deviceInfo = infoOpt.get();
84         } else {
85             LOG.warn("Could not get device info from DataBroker");
86             return false;
87         }
88         boolean sqlResult = false;
89         String query = Queries.getQuery().deviceInfoInsert().get();
90         LOG.info("Running {} query ", query);
91         try (Connection connection = dataSource.getConnection();
92              PreparedStatement preparedStatement = connection.prepareStatement(query)) {
93             Object[] prepareParameters = prepareDeviceInfoParameters(deviceInfo);
94             for (int i = 0; i < prepareParameters.length; i++) {
95                 LOG.debug("Parameter {} has value {}", i + 1, prepareParameters[i]);
96                 preparedStatement.setObject(i + 1, prepareParameters[i]);
97
98             }
99             int executeUpdate = preparedStatement.executeUpdate();
100             LOG.info("{} entries were added", executeUpdate);
101             sqlResult = true;
102
103             LOG.debug("iNode AddNode call complete");
104             getRoadmShelves(deviceId);
105             LOG.debug("iNode getRoadmShelves call complete");
106             getCircuitPacks(deviceId);
107             LOG.debug("iNode getCircuitPacks call complete");
108
109             LOG.debug("iNode persist interfaces call");
110             persistDevInterfaces(deviceId, connection);
111             LOG.debug("iNode persist interfaces call complete");
112
113
114             LOG.debug("iNode persist protocols call");
115             persistDevProtocols(deviceId, connection);
116             LOG.debug("iNode persist protocols call complete");
117
118
119             LOG.debug("iNode persist wavelength map call");
120             persistDevWavelengthMap(deviceId, connection);
121             LOG.debug("iNode persist wavelength map call complete");
122
123             LOG.debug("iNode persist internal links map call");
124             persistDevInternalLinks(deviceId, connection);
125             LOG.debug("iNode persist internal links map call complete");
126
127             LOG.debug("iNode persist Physical links map call");
128             persistDevPhysicalLinks(deviceId, connection);
129             LOG.debug("iNode persist Physical links map call complete");
130
131             LOG.debug("iNode persist External links map call");
132             persistDevExternalLinks(deviceId, connection);
133             LOG.debug("iNode persist External links map call complete");
134
135             LOG.debug("iNode persist degree map call");
136             persistDevDegree(deviceId, connection);
137             LOG.debug("iNode persist degree map call complete");
138
139             LOG.debug("iNode persist srg map call");
140             persistDevSrg(deviceId, connection);
141             LOG.debug("iNode persist srg map call complete");
142
143             LOG.debug("iNode persist Roadm Connections call");
144             persistDevRoadmConnections(deviceId, connection);
145             LOG.debug("iNode persist Roadm Connections call complete");
146
147             LOG.debug("iNode persist Connection Map call");
148             persistDevConnectionMap(deviceId, connection);
149             LOG.debug("iNode persist Connection Map call complete");
150
151         } catch (SQLException e) {
152             LOG.error(e.getMessage(), e);
153         } catch (InterruptedException e) {
154             LOG.error(e.getMessage(), e);
155         } catch (ExecutionException e) {
156             LOG.error(e.getMessage(), e);
157         }
158         return sqlResult;
159     }
160
161     public boolean nodeExists(String nodeId) {
162         String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?";
163         int nodeExists = 0;
164         LOG.info("Checking if {} exists in DB", nodeId);
165         try (Connection connection = dataSource.getConnection();
166              PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) {
167             preparedStmt.setString(1, nodeId);
168             try (ResultSet rs = preparedStmt.executeQuery()) {
169                 while (rs.next()) {
170                     nodeExists = rs.getInt("node_exists");
171                     LOG.debug("Found {} devices matching {}", nodeExists, nodeId);
172                 }
173             }
174         } catch (SQLException e) {
175             LOG.error(e.getMessage(), e);
176         }
177         return nodeExists == 0 ? false : true;
178     }
179
180     public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException {
181         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
182         Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
183                 LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
184                 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
185
186         LOG.info("Shelves size {}", deviceObject.get().getShelves().size());
187         try (Connection connection = requireNonNull(dataSource.getConnection())) {
188             for (int i = 0; i < deviceObject.get().getShelves().size(); i++) {
189                 Shelves shelve = deviceObject.get().getShelves().get(i);
190                 String shelfName = shelve.getShelfName();
191
192                 LOG.info("Getting Shelve Details of {}", shelfName);
193                 if (shelve.getSlots() != null) {
194                     LOG.info("Slot Size {} ", shelve.getSlots().size());
195                     persistShelveSlots(nodeId, shelve, connection);
196                 } else {
197                     LOG.info("No Slots for shelf {}", shelfName);
198                 }
199
200                 persistShelves(nodeId, connection, shelve);
201             }
202         } catch (SQLException e1) {
203             LOG.error(e1.getMessage(), e1);
204         }
205     }
206
207     public void getCircuitPacks(String nodeId) throws InterruptedException, ExecutionException {
208         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
209         Optional<OrgOpenroadmDevice> deviceObject =
210                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
211                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
212         if (!deviceObject.isPresent()) {
213             LOG.warn("Device object {} was not found", nodeId);
214             return;
215         }
216         LOG.info("Circuit pack size {}", deviceObject.get().getCircuitPacks().size());
217
218         try (Connection connection = requireNonNull(dataSource.getConnection())) {
219             for (int i = 0; i < deviceObject.get().getCircuitPacks().size(); i++) {
220                 CircuitPacks cp = deviceObject.get().getCircuitPacks().get(i);
221
222                 if (cp.getCpSlots() != null) {
223                     persistCircuitPacksSlots(nodeId, cp, connection);
224                 }
225                 LOG.info("Everything {}", cp);
226                 LOG.info("CP is {}", cp);
227
228                 //persistPorts(cp, connection);
229                 if (cp.getPorts() != null) {
230                     persistCPPorts(nodeId, connection, cp);
231                 }
232                 persistCircuitPacks(nodeId, connection, cp);
233             }
234         } catch (SQLException e1) {
235             LOG.error(e1.getMessage(), e1);
236         }
237     }
238
239     private void persistCircuitPacks(String nodeId, Connection connection, CircuitPacks cp) {
240         Object[] parameters = prepareCircuitPacksParameters(nodeId, cp);
241         String query = Queries.getQuery().deviceCircuitPackInsert().get();
242         LOG.info("Running {} query ", query);
243         try (PreparedStatement stmt = connection.prepareStatement(query)) {
244             for (int j = 0; j < parameters.length; j++) {
245                 stmt.setObject(j + 1, parameters[j]);
246             }
247             stmt.execute();
248             stmt.clearParameters();
249         } catch (SQLException e) {
250             LOG.error(e.getMessage(), e);
251         }
252     }
253
254     private void persistShelves(String nodeId, Connection connection, Shelves shelve) {
255         Object[] shelvesParameter = prepareShelvesParameters(nodeId, shelve);
256         String query = Queries.getQuery().deviceShelfInsert().get();
257         LOG.info("Running {} query ", query);
258         try (PreparedStatement preparedStmt = connection.prepareStatement(query)) {
259             for (int j = 0; j < shelvesParameter.length; j++) {
260                 preparedStmt.setObject(j + 1, shelvesParameter[j]);
261             }
262             preparedStmt.execute();
263             preparedStmt.clearParameters();
264         } catch (SQLException e) {
265             LOG.error(e.getMessage(), e);
266         }
267     }
268
269     private void persistShelveSlots(String nodeId, Shelves shelves, Connection connection) {
270         String startTimetampStr = getCurrentTimestamp();
271         for (int i = 0; i < shelves.getSlots().size(); i++) {
272             Slots slot = shelves.getSlots().get(i);
273             LOG.info("Getting Slot Details of {}", slot.getSlotName());
274             Object[] parameters = new Object[]{nodeId,
275                 shelves.getShelfName(),
276                 slot.getSlotName(),
277                 slot.getLabel(),
278                 slot.getProvisionedCircuitPack(),
279                 "0",
280                 startTimetampStr,
281                 startTimetampStr};
282             String query = Queries.getQuery().deviceShelfSlotInsert().get();
283             LOG.info("Running {} query ", query);
284             try (PreparedStatement stmt = connection.prepareStatement(query)) {
285                 for (int j = 0; j < parameters.length; j++) {
286                     stmt.setObject(j + 1, parameters[j]);
287                 }
288                 stmt.execute();
289                 stmt.clearParameters();
290             } catch (SQLException e) {
291                 LOG.error(e.getMessage(), e);
292             }
293         }
294     }
295
296
297     private void persistCircuitPacksSlots(String nodeId, CircuitPacks circuitPacks, Connection connection) {
298         String startTimetampStr = getCurrentTimestamp();
299         for (int i = 0; i < circuitPacks.getCpSlots().size(); i++) {
300             CpSlots cpSlot = circuitPacks.getCpSlots().get(i);
301
302             Object[] parameters = new Object[]{nodeId,
303                 circuitPacks.getCircuitPackName(),
304                 cpSlot.getSlotName(),
305                 cpSlot.getLabel(),
306                 cpSlot.getProvisionedCircuitPack(),
307                 "-1",
308                 "-1",
309                 startTimetampStr,
310                 startTimetampStr};
311             String query = Queries.getQuery().deviceCPSlotInsert().get();
312             LOG.info("Running {} query ", query);
313             try (PreparedStatement stmt = connection.prepareStatement(query)) {
314                 for (int j = 0; j < parameters.length; j++) {
315                     stmt.setObject(j + 1, parameters[j]);
316                 }
317                 stmt.execute();
318                 stmt.clearParameters();
319             } catch (SQLException e) {
320                 LOG.error(e.getMessage(), e);
321             }
322         }
323     }
324
325     private void persistPorts(CircuitPacks circuitPacks, Connection connection) {
326         LOG.warn("Ports are not persisted yet");
327     }
328
329
330     /**
331      * Prepares parameters for device insert query.
332      *
333      * @param deviceInfo device information
334      * @return Object an object
335      */
336     private static Object[] prepareDeviceInfoParameters(Info deviceInfo) {
337         String startTimetampStr = getCurrentTimestamp();
338
339         String nodeId = prepareDashString(deviceInfo.getNodeId());
340         Long nodeNumber = deviceInfo.getNodeNumber().toJava();
341         String nodeTypeEnu = deviceInfo.getNodeType().getName();
342         String clli = prepareDashString(deviceInfo.getClli());
343         String vendor = prepareDashString(deviceInfo.getVendor());
344         String model = prepareDashString(deviceInfo.getModel());
345         String serialId = prepareDashString(deviceInfo.getSerialId());
346         String ipAddress = prepareDashString(deviceInfo.getIpAddress().getIpv4Address().getValue());
347         String prefixLength = prepareDashString(deviceInfo.getPrefixLength());
348         String defaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue());
349         String sourceEnum = deviceInfo.getSource().getName();
350         String currentIpAddress = prepareDashString(deviceInfo.getCurrentIpAddress().getIpv4Address().getValue());
351         String currentPrefixLength = prepareDashString(deviceInfo.getCurrentPrefixLength());
352         String currentDefaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue());
353         String macAddress = prepareDashString(deviceInfo.getMacAddress().getValue());
354         String softwareVersion = prepareDashString(deviceInfo.getSoftwareVersion());
355         //String openroadmVersion = "1.2.1";
356         String template = prepareDashString(deviceInfo.getTemplate());
357         String currentDatetime = prepareDashString(deviceInfo.getCurrentDatetime().getValue());
358         String geoLatitude = (deviceInfo.getGeoLocation() != null
359             ? prepareDashString(deviceInfo.getGeoLocation().getLatitude()) : "");
360         String geoLongitude = (deviceInfo.getGeoLocation() != null
361             ? prepareDashString(deviceInfo.getGeoLocation().getLongitude()) : "");
362         String maxDegrees = (deviceInfo.getMaxDegrees() == null ? "-1" : prepareDashString(deviceInfo.getMaxDegrees()));
363         String maxSrgs = (deviceInfo.getMaxSrgs() == null ? "-1" : prepareDashString(deviceInfo.getMaxSrgs()));
364         String swVersion = prepareDashString(deviceInfo.getSoftwareVersion()); //sw_version
365         String swValidationTimer = prepareDashString(""); //sw_validation_timer
366         String activationDateTime = prepareDashString(""); //activation_date_time
367         //Integer maxNumBin15minHistoricalPm = null;
368         //Integer maxNumBin24hourHistoricalPm = null;
369         /*jsonDevInfo = JsonStringBuilder.getDevInfoJson().replace("$$NODE-ID$$",nodeId)
370                 .replace("$$NODE-NUMBER$$", nodeNumber)
371                 .replace("$$NODE-TYPE$$",nodeType)
372                 .replace("$$CLLI$$",clli)
373                 .replace("$$VENDOR$$",vendor)
374                 .replace("$$MODEL$$",model)
375                 .replace("$$SERIAL-ID$$",serialId)
376                 .replace("$$IPADDRESS$$",ipAddress)
377                 .replace("$$PREFIX-LENGTH$$",prefixLength)
378                 .replace("$$DEFAULTGATEWAY$$",defaultGateway)
379                 .replace("$$SOURCE$$",String.valueOf(source))
380                 .replace("$$CURRENT-IPADDRESS$$",currentIpAddress)
381                 .replace("$$CURRENT-PREFIX-LENGTH$$",currentPrefixLength)
382                 .replace("$$CURRENT-DEFAULTGATEWAY$$",currentDefailtGateway)
383                 .replace("$$MACADDRESS$$",macAddress)
384                 .replace("$$SOFTWAREVERSION$$",softwareVersion)
385                 .replace("$$OPENROADM-VERSION$$",openroadmVersion)
386                 .replace("$$TEMPLATE$$",template)
387                 .replace("$$CURRENT-DATETIME$$",currentDatetime)
388                 .replace("$$LATITUDE$$",latitude)
389                 .replace("$$LONGITUDE$$",longitude)
390                 .replace("$$MAX-DEGREES$$",maxDegrees)
391                 .replace("$$MAX-SRGS$$",maxSrgs)
392                 .replace("$$MAX-NUM-BIN-15MIN-HISTORICAL-PM$$",prepareDashString(""))
393                 .replace("$$MAX-NUM-BIN-24HOUR-HISTORICAL-PM$$",prepareDashString(""))
394                 .replace("$$SW-VERSION$$",swVersion)
395                 .replace("$$SW-VALIDATION-TIMER$$",swValidationTimer)
396                 .replace("$$ACTIVATION-DATE-TIME$$",activationDateTime);*/
397
398
399         return new Object[]{
400             nodeId,
401             nodeNumber,
402             nodeTypeEnu,
403             clli,
404             vendor,
405             model,
406             serialId,
407             ipAddress,
408             prefixLength,
409             defaultGateway,
410             sourceEnum,
411             currentIpAddress,
412             currentPrefixLength,
413             currentDefaultGateway,
414             macAddress,
415             softwareVersion,
416             //openroadmVersion,
417             "1.2.1",
418             template,
419             currentDatetime,
420             geoLatitude,
421             geoLongitude,
422             maxDegrees,
423             maxSrgs,
424             //maxNumBin15minHistoricalPm,
425             //maxNumBin24hourHistoricalPm,
426             null, null,
427             swVersion,
428             swValidationTimer,
429             activationDateTime,
430             startTimetampStr,
431             startTimetampStr
432         };
433     }
434
435
436     private static Object[] prepareShelvesParameters(String nodeId, Shelves shelve) {
437         String startTimestamp = getCurrentTimestamp();
438
439         return new Object[]{nodeId,
440             shelve.getShelfName(),
441             shelve.getShelfType(),
442             shelve.getRack(),
443             shelve.getShelfPosition(),
444             (shelve.getAdministrativeState() == null ? null : shelve.getAdministrativeState().getIntValue()),
445             shelve.getVendor(),
446             shelve.getModel(),
447             shelve.getSerialId(),
448             shelve.getType(),
449             shelve.getProductCode(),
450             (shelve.getManufactureDate() == null ? null : shelve.getManufactureDate().getValue()),
451             shelve.getClei(),
452             shelve.getHardwareVersion(),
453             (shelve.getOperationalState() == null ? null : shelve.getOperationalState().getIntValue()),
454             (shelve.getEquipmentState() == null ? null : shelve.getEquipmentState().getIntValue()),
455             (shelve.getDueDate() == null ? null : shelve.getDueDate().getValue()),
456             startTimestamp,
457             startTimestamp};
458     }
459
460
461     private static Object[] prepareCPPortsParameters(String nodeId, CircuitPacks circuitPacks, Ports cpPort) {
462
463         String circuitPackName = circuitPacks.getCircuitPackName();
464         String portName = cpPort.getPortName();
465         String portType = cpPort.getPortType();
466         String portQualEnu = String.valueOf((cpPort.getPortQual() == null ? "-1" : cpPort.getPortQual().getName()));
467         String portWavelengthTypeEnu = "-1"; //cpPort.getPortWavelengthType().getIntValue(); /* Check error*/
468         String portDirectionEnu = String.valueOf((cpPort.getPortDirection() == null ? "" :
469             cpPort.getPortDirection().getName()));
470         String label = cpPort.getLabel();
471         String circuitId = cpPort.getCircuitId();
472         String administrativeStateEnu = (cpPort.getAdministrativeState() == null ? "" :
473             cpPort.getAdministrativeState().getName());
474         String operationalStateEnu =
475             (cpPort.getOperationalState() == null ? "" : cpPort.getOperationalState().getName());
476         String logicalConnectionPoint = cpPort.getLogicalConnectionPoint();
477         String parentPortCircuitPackName = (cpPort.getPartnerPort() == null ? "" :
478             (cpPort.getPartnerPort().getCircuitPackName() == null ? "" : cpPort.getPartnerPort().getCircuitPackName()));
479         String partnerPortPortName = (cpPort.getPartnerPort() == null ? "" :
480             (cpPort.getPartnerPort().getPortName() == null ? "" : cpPort.getPartnerPort().getPortName().toString()));
481         String partnerPortCircuitPackName = (cpPort.getParentPort() == null ? "" :
482             (cpPort.getParentPort().getCircuitPackName() == null ? "" : cpPort.getParentPort().getCircuitPackName()));
483         String parentPortPortName = (cpPort.getParentPort() == null ? "" :
484             (cpPort.getParentPort().getPortName() == null ? "" : cpPort.getParentPort().toString()));
485         String roadmPortPortPowerCapabilityMinRx = (cpPort.getRoadmPort() == null ? "" :
486             (cpPort.getRoadmPort().getPortPowerCapabilityMinRx() == null ? "" :
487                 cpPort.getRoadmPort().getPortPowerCapabilityMinRx().toString()));
488         String roadmPortPortPowerCapabilityMinTx = (cpPort.getRoadmPort() == null ? "" :
489             (cpPort.getRoadmPort().getPortPowerCapabilityMinTx() == null ? "" :
490                 cpPort.getRoadmPort().getPortPowerCapabilityMinTx().toString()));
491         String roadmPortPortPowerCapabilityMaxRx = (cpPort.getRoadmPort() == null ? "" :
492             (cpPort.getRoadmPort().getPortPowerCapabilityMaxRx() == null ? "" :
493                 cpPort.getRoadmPort().getPortPowerCapabilityMaxRx().toString()));
494         String roadmPortPortPowerCapabilityMaxTx = (cpPort.getRoadmPort() == null ? "" :
495             (cpPort.getRoadmPort().getPortPowerCapabilityMaxTx() == null ? "" :
496                 cpPort.getRoadmPort().getPortPowerCapabilityMaxTx().toString()));
497         //String roadmPortCapableWavelengths = "";
498         //String roadmPortAvailableWavelengths = "";
499         //String roadmPortUsedWavelengths = "";
500         String transponderPortPortPowerCapabilityMinRx = (cpPort.getTransponderPort() == null ? "" :
501             (cpPort.getTransponderPort().getPortPowerCapabilityMinRx() == null ? "" :
502                 cpPort.getTransponderPort().getPortPowerCapabilityMinRx().toString()));
503         String transponderPortPortPowerCapabilityMinTx = (cpPort.getTransponderPort() == null ? "" :
504             (cpPort.getTransponderPort().getPortPowerCapabilityMinTx() == null ? "" :
505                 cpPort.getTransponderPort().getPortPowerCapabilityMinTx().toString()));
506         String transponderPortPortPowerCapabilityMaxRx = (cpPort.getTransponderPort() == null ? "" :
507             (cpPort.getTransponderPort().getPortPowerCapabilityMaxRx() == null ? "" :
508                 cpPort.getTransponderPort().getPortPowerCapabilityMaxRx().toString()));
509         String transponderPortPortPowerCapabilityMaxTx = (cpPort.getTransponderPort() == null ? "" :
510             (cpPort.getTransponderPort().getPortPowerCapabilityMaxTx() == null ? "" :
511                 cpPort.getTransponderPort().getPortPowerCapabilityMaxTx().toString()));
512         //String transponderPortCapableWavelengths = "";
513         String otdrPortLaunchCableLength = (cpPort.getOtdrPort() == null ? "" :
514             (cpPort.getOtdrPort().getLaunchCableLength() == null ? "" :
515                 cpPort.getOtdrPort().getLaunchCableLength().toString()));
516         String otdrPortPortDirection = (cpPort.getOtdrPort() == null ? "-1" :
517             (cpPort.getOtdrPort().getPortDirection() == null ? "-1" :
518                 Integer.valueOf(cpPort.getOtdrPort().getPortDirection().getIntValue()).toString()));
519         //String ilaPortPortPowerCapabilityMixRx = "";
520         //String ilaPortPortPowerCapabilityMixTx = "";
521         //String ilaPortPortPowerCapabilityMaxRx = "";
522         //String ilaPortPortPowerCapabilityMaxTx = "";
523
524         String startTimestamp = getCurrentTimestamp();
525
526         return new Object[]{nodeId,
527             circuitPackName,
528             portName,
529             portType,
530             portQualEnu,
531             portWavelengthTypeEnu,
532             portDirectionEnu,
533             label,
534             circuitId,
535             administrativeStateEnu,
536             operationalStateEnu,
537             logicalConnectionPoint,
538             partnerPortCircuitPackName,
539             partnerPortPortName,
540             parentPortCircuitPackName,
541             parentPortPortName,
542             roadmPortPortPowerCapabilityMinRx,
543             roadmPortPortPowerCapabilityMinTx,
544             roadmPortPortPowerCapabilityMaxRx,
545             roadmPortPortPowerCapabilityMaxTx,
546             //roadmPortCapableWavelengths,
547             //roadmPortAvailableWavelengths,
548             //roadmPortUsedWavelengths,
549             "", "", "",
550             transponderPortPortPowerCapabilityMinRx,
551             transponderPortPortPowerCapabilityMinTx,
552             transponderPortPortPowerCapabilityMaxRx,
553             transponderPortPortPowerCapabilityMaxTx,
554             //transponderPortCapableWavelengths,
555             "",
556             otdrPortLaunchCableLength,
557             otdrPortPortDirection,
558             //ilaPortPortPowerCapabilityMixRx,
559             //ilaPortPortPowerCapabilityMixTx,
560             //ilaPortPortPowerCapabilityMaxRx,
561             //ilaPortPortPowerCapabilityMaxTx,
562             "", "", "", "",
563             startTimestamp,
564             startTimestamp
565         };
566     }
567
568
569     private static Object[] prepareCircuitPacksParameters(String nodeId, CircuitPacks cpack) {
570         String startTimestamp = getCurrentTimestamp();
571         return new Object[]{nodeId,
572             cpack.getCircuitPackName(),
573             cpack.getCircuitPackType(),
574             cpack.getCircuitPackProductCode(),
575             (cpack.getAdministrativeState() == null ? "" : cpack.getAdministrativeState().getIntValue()),
576             cpack.getVendor(),
577             cpack.getModel(),
578             cpack.getSerialId(),
579             cpack.getType(),
580             cpack.getProductCode(),
581             (cpack.getManufactureDate() == null ? "" : cpack.getManufactureDate().getValue()),
582             cpack.getClei(),
583             cpack.getHardwareVersion(),
584             (cpack.getOperationalState() == null ? -1 : cpack.getOperationalState().getIntValue()),
585             cpack.getCircuitPackCategory().getType().getIntValue(),
586             cpack.getCircuitPackCategory().getExtension(),
587             (cpack.getEquipmentState() == null ? -1 : cpack.getEquipmentState().getIntValue()),
588             cpack.getCircuitPackMode(),
589             cpack.getShelf(),
590             cpack.getSlot(),
591             cpack.getSubSlot(),
592             prepareEmptyString(cpack.getDueDate()),
593             prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" :
594                 ((cpack.getParentCircuitPack().getCircuitPackName() == null) ? "" :
595                     cpack.getParentCircuitPack().getCircuitPackName())
596             ),
597             prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" :
598                 ((cpack.getParentCircuitPack().getCpSlotName() == null) ? "" :
599                     cpack.getParentCircuitPack().getCpSlotName())
600             ),
601             startTimestamp,
602             startTimestamp};
603     }
604
605
606     private void persistCPPorts(String nodeId, Connection connection, CircuitPacks circuitPacks) {
607
608         for (int i = 0; i < circuitPacks.getPorts().size(); i++) {
609             Object[] cpPortsParameters = prepareCPPortsParameters(nodeId, circuitPacks, circuitPacks.getPorts().get(i));
610             String query = Queries.getQuery().deviceCPPortInsert().get();
611             LOG.info("Running {} query ", query);
612             try (PreparedStatement preparedStmt = connection.prepareStatement(query)) {
613                 for (int j = 0; j < cpPortsParameters.length; j++) {
614                     preparedStmt.setObject(j + 1, cpPortsParameters[j]);
615                 }
616                 preparedStmt.execute();
617                 preparedStmt.clearParameters();
618             } catch (SQLException e) {
619                 LOG.error(e.getMessage(), e);
620             }
621         }
622     }
623
624
625     private Object[] prepareDevInterfaceParameters(String nodeId, Interface deviceInterface, Connection connection) {
626
627         String ethernetDuplexEnu = "";
628         String ethernetAutoNegotiationEnu = "";
629         String maintTestsignalTestpatternEnu = "";
630         String maintTestsignalTypeEnu = "";
631         String otuFecEnu = "";
632         String otuMaintTypeEnu = "";
633         String otsFiberTypeEnu = "";
634         String ethernetSpeed = "-1";
635         String ethernetFec = "";
636         String ethernetMtu = "-1";
637         String ethernetCurrSpeed = "";
638         String ethernetCurrDuplex = "-1";
639         //String mciMcttpMinFreq = "";
640         //String mciMcttpMaxFreq = "";
641         //String mciMcttpCenterFreq = "";
642         //String mciMcttpSlotWidth = "";
643         //String mciNmcCtpFrequency = "";
644         //String mciNmcCtpWidth = "";
645         String ochRate = "";
646         //String ochFrequency = "";
647         //String ochWidth = "";
648         String ochWavelengthNumber = "";
649         String ochModulationFormat = "";
650         String ochTransmitPower = "";
651         String otsSpanLossReceive = "";
652         String otsSpanLossTransmit = "";
653         //String otsIngressSpanLossAgingMargin = "";
654         //String otsEolMaxLoadPin = "";
655         String oduRate = "";
656         //String oduFunction = "";
657         String oduMonitoringMode = "";
658         //String oduNoOamFunction = "";
659         String oduProactiveDelayMeasurementEnabled = "";
660         //String oduPoaTribPortNumber = "-1";
661         //String oduTxSapi = "";
662         //String oduTxDapi = "";
663         //String oduTxOperator = "";
664         //String oduAcceptedSapi = "";
665         //String oduAcceptedDapi = "";
666         //String oduAcceptedOperator = "";
667         //String oduExpectedSapi = "";
668         //String oduExpectedDapi = "";
669         //String oduTimActEnabled = "";
670         //String oduTimDetectMode = "";
671         //String oduDegmIntervals = "-1";
672         //String oduDegthrPercentage = "-1";
673         String opuPayloadType = "";
674         String opuRxPayloadType = "";
675         String opuExpPayloadType = "";
676         String opuPayloadInterface = "";
677         String maintTestsignalEnabled = "";
678         String maintTestsignalBiterrors = "-1";
679         String maintTestsignalBiterrorsterminal = "-1";
680         String maintTestsignalSyncseconds = "-1";
681         String maintTestsignalSyncsecondsterminal = "-1";
682         String otuRate = "";
683         //String otuTxSapi = "";
684         //String otuTxDapi = "";
685         //String otuTxOperator = "";
686         //String otuAcceptedSapi = "";
687         //String otuAcceptedDapi = "";
688         //String otuAcceptedOperator = "";
689         //String otuExpectedSapi = "";
690         //String otuExpectedDapi = "";
691         //String otuTimActEnabled = "";
692         //String otuTimDetectMode = "";
693         //String otuDegmIntervals = "-1";
694         //String otuDegthrPercentage = "-1";
695         String otuMaintLoopbackEnabled = "";
696         //String mtOtuRate = "";
697         //String mtOtuFec = "";
698         //String mtOtuMaintLoopback = "";
699         //String mtOtuEnabled = "";
700         //String mtOtuType = "";
701
702         String name = deviceInterface.getName();
703         String description = deviceInterface.getDescription();
704         String type = deviceInterface.getType().getTypeName();
705         String administrativeStateEnu = deviceInterface.getAdministrativeState().getName();
706         int operationalState = deviceInterface.getOperationalState().getIntValue();
707         String circuitId = deviceInterface.getCircuitId();
708         String supportingInterface = deviceInterface.getSupportingInterface();
709         String supportingCircuitPackName = deviceInterface.getSupportingCircuitPackName();
710         String supportingPort = deviceInterface.getSupportingPort().toString();
711
712         switch (deviceInterface.getType().toString()) {
713
714             case "ethernet":
715                 //EthernetBuilder ethIfBuilder = new EthernetBuilder();
716                 EthernetBuilder ethIfBuilder = new EthernetBuilder(deviceInterface.augmentation(Interface1.class)
717                     .getEthernet());
718                 ethernetSpeed = (ethIfBuilder.getSpeed() == null ? "-1" :
719                     Integer.valueOf(ethIfBuilder.getSpeed().intValue()).toString());
720                 ethernetFec = ethIfBuilder.getFec().getName();
721                 ethernetDuplexEnu = (ethIfBuilder.getDuplex() == null ? "" : ethIfBuilder.getDuplex().getName());
722                 ethernetMtu = ethIfBuilder.getMtu().toString();
723                 ethernetAutoNegotiationEnu = ethIfBuilder.getAutoNegotiation().getName();
724                 ethernetCurrSpeed = ethIfBuilder.getCurrSpeed();
725                 ethernetCurrDuplex = ethIfBuilder.getCurrDuplex();
726                 break;
727
728             case "och":
729                 OchBuilder ochIfBuilder = new OchBuilder(deviceInterface.augmentation(
730                     org.opendaylight.yang.gen.v1
731                         .http.org.openroadm.optical.channel.interfaces.rev161014.Interface1.class)
732                     .getOch());
733                 ochRate = ochIfBuilder.getRate().getName();
734                 ochWavelengthNumber = ochIfBuilder.getWavelengthNumber().toString();
735                 ochModulationFormat = ochIfBuilder.getModulationFormat().getName();
736                 ochTransmitPower = ochIfBuilder.getTransmitPower().toString();
737                 break;
738
739             case "ots":
740                 OtsBuilder otsIfBuilder = new OtsBuilder(deviceInterface.augmentation(
741                     org.opendaylight.yang.gen.v1
742                         .http.org.openroadm.optical.transport.interfaces.rev161014.Interface1.class)
743                     .getOts());
744                 otsFiberTypeEnu = String.valueOf(otsIfBuilder.getFiberType().getIntValue());
745                 otsSpanLossReceive = otsIfBuilder.getSpanLossReceive().toString();
746                 otsSpanLossTransmit = otsIfBuilder.getSpanLossTransmit().toString();
747                 break;
748
749             case "odu":
750                 OduBuilder oduIfBuilder = new OduBuilder(deviceInterface.augmentation(
751                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.Interface1.class)
752                     .getOdu());
753                 oduRate = String.valueOf(oduIfBuilder.getRate());
754                 oduMonitoringMode = oduIfBuilder.getMonitoringMode().getName();
755                 oduProactiveDelayMeasurementEnabled = oduIfBuilder.isProactiveDelayMeasurementEnabled().toString();
756
757                 persistDevInterfaceTcm(nodeId, name, oduIfBuilder, connection);
758                 persistDevInterfaceOtnOduTxMsi(nodeId, name, oduIfBuilder, connection);
759                 persistDevInterfaceOtnOduRxMsi(nodeId, name, oduIfBuilder, connection);
760                 persistDevInterfaceOtnOduExpMsi(nodeId, name, oduIfBuilder, connection);
761
762                 opuPayloadType = oduIfBuilder.getOpu().getPayloadType();
763                 opuRxPayloadType = oduIfBuilder.getOpu().getRxPayloadType();
764                 opuExpPayloadType = oduIfBuilder.getOpu().getExpPayloadType();
765                 opuPayloadInterface = oduIfBuilder.getOpu().getPayloadInterface();
766                         /*persistDevInterfaceOtnOduTxMsi(nodeId,name,oduIfBuilder,connection);
767                         persistDevInterfaceOtnOduRxMsi(nodeId,name,oduIfBuilder,connection);
768                         persistDevInterfaceOtnOduExpMsi(nodeId,name,oduIfBuilder,connection); */
769                 maintTestsignalEnabled = oduIfBuilder.getMaintTestsignal().isEnabled().toString();
770                 maintTestsignalTestpatternEnu = oduIfBuilder.getMaintTestsignal().getTestPattern().getName();
771                 maintTestsignalTypeEnu = oduIfBuilder.getMaintTestsignal().getType().getName();
772                 maintTestsignalBiterrors = Integer.valueOf(oduIfBuilder.getMaintTestsignal().getBitErrors().intValue())
773                     .toString();
774                 maintTestsignalBiterrorsterminal = oduIfBuilder.getMaintTestsignal().getBitErrorsTerminal().toString();
775                 maintTestsignalSyncseconds = oduIfBuilder.getMaintTestsignal().getSyncSeconds();
776                 maintTestsignalSyncsecondsterminal = oduIfBuilder.getMaintTestsignal().getSyncSecondsTerminal();
777                 break;
778
779             case "otu":
780                 OtuBuilder otuIfBuilder =
781                     new OtuBuilder(deviceInterface.augmentation(
782                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.Interface1.class)
783                     .getOtu());
784                 otuRate = otuIfBuilder.getRate().getName();
785                 otuFecEnu = otuIfBuilder.getFec().getName();
786                 otuMaintLoopbackEnabled = otuIfBuilder.getMaintLoopback().isEnabled().toString();
787                 otuMaintTypeEnu = otuIfBuilder.getMaintLoopback().getType().getName();
788                 break;
789
790             default:
791                 LOG.error("could not get interface type");
792
793         }
794
795         String startTimestamp = getCurrentTimestamp();
796
797         return new Object[]{nodeId,
798             name,
799             description,
800             type,
801             administrativeStateEnu,
802             Integer.toString(operationalState),
803             circuitId,
804             supportingInterface,
805             supportingCircuitPackName,
806             supportingPort,
807             ethernetSpeed,
808             ethernetFec,
809             ethernetDuplexEnu,
810             ethernetMtu,
811             ethernetAutoNegotiationEnu,
812             ethernetCurrSpeed,
813             ethernetCurrDuplex,
814             //mciMcttpMinFreq,
815             //mciMcttpMaxFreq,
816             //mciMcttpCenterFreq,
817             //mciMcttpSlotWidth,
818             //mciNmcCtpFrequency,
819             //mciNmcCtpWidth,
820             "", "", "", "", "", "",
821             ochRate,
822             //ochFrequency,
823             //ochWidth,
824             "", "",
825             ochWavelengthNumber,
826             ochModulationFormat,
827             ochTransmitPower,
828             //otsFiberTypeEnu,
829             otsSpanLossReceive,
830             otsSpanLossTransmit,
831             //otsIngressSpanLossAgingMargin,
832             //otsEolMaxLoadPin,
833             "", "",
834             oduRate,
835             //oduFunction,
836             "",
837             oduMonitoringMode,
838             //oduNoOamFunction,
839             "",
840             oduProactiveDelayMeasurementEnabled,
841             //oduPoaTribPortNumber,
842             //oduTxSapi,
843             //oduTxDapi,
844             //oduTxOperator,
845             //oduAcceptedSapi,
846             //oduAcceptedDapi,
847             //oduAcceptedOperator,
848             //oduExpectedSapi,
849             //oduExpectedDapi,
850             //oduTimActEnabled,
851             //oduTimDetectMode,
852             //oduDegmIntervals,
853             //oduDegthrPercentage,
854             "-1", "", "", "", "", "","", "", "", "", "", "-1", "-1",
855             opuPayloadType,
856             opuRxPayloadType,
857             opuExpPayloadType,
858             opuPayloadInterface,
859             maintTestsignalEnabled,
860             maintTestsignalTestpatternEnu,
861             maintTestsignalTypeEnu,
862             maintTestsignalBiterrors,
863             maintTestsignalBiterrorsterminal,
864             maintTestsignalSyncseconds,
865             maintTestsignalSyncsecondsterminal,
866             otuRate,
867             otuFecEnu,
868             //otuTxSapi,
869             //otuTxDapi,
870             //otuTxOperator,
871             //otuAcceptedSapi,
872             //otuAcceptedDapi,
873             //otuAcceptedOperator,
874             //otuExpectedSapi,
875             //otuExpectedDapi,
876             //otuTimActEnabled,
877             //otuTimDetectMode,
878             //otuDegmIntervals,
879             //otuDegthrPercentage,
880             "", "", "", "", "", "","", "", "", "", "-1", "-1",
881             otuMaintLoopbackEnabled,
882             otuMaintTypeEnu,
883             //mtOtuRate,
884             //mtOtuFec,
885             //mtOtuMaintLoopback,
886             //mtOtuEnabled,
887             //mtOtuType,
888             "", "", "", "", "",
889             startTimestamp,
890             startTimestamp
891         };
892
893     }
894
895     private static Object[] prepareDevInterfaceTcmParameters(String nodeId, String interfaceName, Tcm tcm) {
896
897         String layer = tcm.getLayer().toString();
898         String monitoringModeEnu = tcm.getMonitoringMode().getName();
899         String ltcActEnabled = tcm.isLtcActEnabled().toString();
900         String proactiveDelayMeasurementEnabled = tcm.isProactiveDelayMeasurementEnabled().toString();
901         //String tcmDirectionEnu = "";
902         //String timDetectModeEnu = "";
903         //String txSapi = "";
904         //String txDapi = "";
905         //String txOperator = "";
906         //String acceptedSapi = "";
907         //String acceptedDapi = "";
908         //String acceptedOperator = "";
909         //String expectedSapi = "";
910         //String expectedDapi = "";
911         //String timActEnabled = "";
912         //String degmIntervals = "";
913         //String degthrPercentage = "";
914         String startTimestamp = getCurrentTimestamp();
915
916         return new Object[]{nodeId,
917             interfaceName,
918             layer,
919             monitoringModeEnu,
920             ltcActEnabled,
921             proactiveDelayMeasurementEnabled,
922             //tcmDirectionEnu,
923             //txSapi,
924             //txDapi,
925             //txOperator,
926             //acceptedSapi,
927             //acceptedDapi,
928             //acceptedOperator,
929             //expectedSapi,
930             //expectedDapi,
931             //timActEnabled,
932             //timDetectModeEnu,
933             //degmIntervals,
934             //degthrPercentage,
935             "", "", "", "", "", "", "", "", "", "", "", "", "",
936             startTimestamp,
937             startTimestamp};
938
939     }
940
941     private static Object[] prepareDevInterfaceOtnOduTxMsiParameters(String nodeId, String interfaceName, TxMsi txMsi) {
942
943         String tribSlot = txMsi.getTribSlot().toString();
944         String odtuType = txMsi.getOdtuType().getTypeName();
945         String tribPort = txMsi.getTribPort().toString();
946         String tribPortPayload = txMsi.getTribPortPayload();
947
948         String startTimestamp = getCurrentTimestamp();
949
950         return new Object[]{nodeId,
951             interfaceName,
952             tribSlot,
953             odtuType,
954             tribPort,
955             tribPortPayload,
956             startTimestamp,
957             startTimestamp
958         };
959
960     }
961
962     private static Object[] prepareDevInterfaceOtnOduRxMsiParameters(String nodeId, String interfaceName, RxMsi rxMsi) {
963
964         String tribSlot = rxMsi.getTribSlot().toString();
965         String odtuType = rxMsi.getOdtuType().getTypeName();
966         String tribPort = rxMsi.getTribPort().toString();
967         String tribPortPayload = rxMsi.getTribPortPayload();
968
969         String startTimestamp = getCurrentTimestamp();
970
971         return new Object[]{nodeId,
972             interfaceName,
973             tribSlot,
974             odtuType,
975             tribPort,
976             tribPortPayload,
977             startTimestamp,
978             startTimestamp
979         };
980
981     }
982
983
984     private static Object[] prepareDevInterfaceOtnOduExpMsiParameters(String nodeId, String interfaceName,
985         ExpMsi expMsi) {
986
987         String tribSlot = expMsi.getTribSlot().toString();
988         String odtuType = expMsi.getOdtuType().getTypeName();
989         String tribPort = expMsi.getTribPort().toString();
990         String tribPortPayload = expMsi.getTribPortPayload();
991
992         String startTimestamp = getCurrentTimestamp();
993
994         return new Object[]{nodeId,
995             interfaceName,
996             tribSlot,
997             odtuType,
998             tribPort,
999             tribPortPayload,
1000             startTimestamp,
1001             startTimestamp
1002         };
1003
1004     }
1005
1006     private void persistDevInterfaces(String nodeId, Connection connection) {
1007
1008         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1009         Optional<OrgOpenroadmDevice> deviceObject =
1010                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1011                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1012
1013         /*InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
1014            .child(Interface.class);
1015         Optional<Interface> interfaceOpt =
1016                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, interfaceIID,
1017                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); */
1018
1019         for (int i = 0; i < deviceObject.get().getInterface().size(); i++) {
1020             Interface deviceInterface;
1021
1022             deviceInterface = deviceObject.get().getInterface().get(i);
1023         /*if (interfaceOpt.isPresent()) {
1024             deviceInterface = interfaceOpt.get();
1025         } else {
1026             LOG.warn("Could not get interface info");
1027             return false;
1028         }*/
1029             Object[] parameters = prepareDevInterfaceParameters(nodeId, deviceInterface, connection);
1030
1031             String query = Queries.getQuery().deviceInterfacesInsert().get();
1032             LOG.info("Running {} query ", query);
1033             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1034                 for (int j = 0; j < parameters.length; j++) {
1035                     stmt.setObject(j + 1, parameters[j]);
1036                 }
1037                 stmt.execute();
1038                 stmt.clearParameters();
1039             } catch (SQLException e) {
1040                 LOG.error(e.getMessage(), e);
1041             }
1042         }
1043     }
1044
1045     private void persistDevProtocols(String nodeId, Connection connection) {
1046
1047         InstanceIdentifier<Protocols> protocolsIID =
1048                 InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
1049         Optional<Protocols> protocolObject =
1050                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1051                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1052         if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
1053             LOG.error("LLDP subtree is missing");
1054
1055         } else {
1056             String adminstatusEnu = protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig()
1057                 .getAdminStatus().getName();
1058             String msgTxtInterval = protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig()
1059                 .getMsgTxInterval().toString();
1060             String mxgTxHoldMultiplier = protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig()
1061                 .getMsgTxHoldMultiplier().toString();
1062             String startTimestamp = getCurrentTimestamp();
1063             persistDevProtocolLldpPortConfig(nodeId, connection);
1064             persistDevProtocolLldpNbrList(nodeId, connection);
1065
1066             Object[] parameters = {nodeId,
1067                 adminstatusEnu,
1068                 msgTxtInterval,
1069                 mxgTxHoldMultiplier,
1070                 startTimestamp,
1071                 startTimestamp
1072             };
1073
1074             String query = Queries.getQuery().deviceProtocolInsert().get();
1075             LOG.info("Running {} query ", query);
1076             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1077                 for (int j = 0; j < parameters.length; j++) {
1078                     stmt.setObject(j + 1, parameters[j]);
1079                 }
1080                 stmt.execute();
1081                 stmt.clearParameters();
1082             } catch (SQLException e) {
1083                 LOG.error(e.getMessage(), e);
1084             }
1085         }
1086     }
1087
1088
1089     private void persistDevProtocolLldpPortConfig(String nodeId, Connection connection) {
1090
1091         InstanceIdentifier<Protocols> protocolsIID =
1092                 InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
1093         Optional<Protocols> protocolObject =
1094                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1095                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1096         if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
1097             LOG.error("LLDP subtree is missing");
1098
1099         }
1100         String startTimestamp = getCurrentTimestamp();
1101         for (int i = 0; i < protocolObject.get().augmentation(Protocols1.class).getLldp().getPortConfig().size(); i++) {
1102             PortConfig portConfig =
1103                 protocolObject.get().augmentation(Protocols1.class).getLldp().getPortConfig().get(i);
1104             String ifName = portConfig.getIfName();
1105             String adminStatusEnu = portConfig.getAdminStatus().getName();
1106
1107             Object[] parameters = {nodeId,
1108                 ifName,
1109                 adminStatusEnu,
1110                 startTimestamp,
1111                 startTimestamp
1112             };
1113
1114             String query = Queries.getQuery().deviceProtocolPortConfigInsert().get();
1115             LOG.info("Running {} query ", query);
1116             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1117                 for (int j = 0; j < parameters.length; j++) {
1118                     stmt.setObject(j + 1, parameters[j]);
1119                 }
1120                 stmt.execute();
1121                 stmt.clearParameters();
1122             } catch (SQLException e) {
1123                 LOG.error(e.getMessage(), e);
1124             }
1125
1126         }
1127
1128     }
1129
1130     private void persistDevProtocolLldpNbrList(String nodeId, Connection connection) {
1131
1132         InstanceIdentifier<Protocols> protocolsIID =
1133                 InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
1134         Optional<Protocols> protocolObject =
1135                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1136                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1137         if (protocolObject.get().augmentation(Protocols1.class).getLldp().getNbrList() == null) {
1138             protocolObject =
1139                     deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, protocolsIID,
1140                             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1141
1142         }
1143         if (protocolObject.get().augmentation(Protocols1.class).getLldp().getNbrList() == null) {
1144             LOG.error("LLDP nbrlist subtree is missing for {}", nodeId);
1145
1146         } else {
1147             String startTimestamp = getCurrentTimestamp();
1148             for (int i = 0; i < protocolObject.get()
1149                 .augmentation(Protocols1.class).getLldp().getNbrList().getIfName().size(); i++) {
1150
1151                 IfName ifNameObj = protocolObject.get().augmentation(Protocols1.class).getLldp().getNbrList()
1152                     .getIfName().get(i);
1153                 String ifName = ifNameObj.getIfName();
1154                 String remotesysname = ifNameObj.getRemoteSysName();
1155                 String remotemgmtaddresssubtype = ifNameObj.getRemoteMgmtAddressSubType().getName();
1156                 String remotemgmtaddress = ifNameObj.getRemoteMgmtAddress().getIpv4Address().toString();
1157                 String remoteportidsubtypeEnu = ifNameObj.getRemotePortIdSubType().getName();
1158                 String remoteportid = ifNameObj.getRemotePortId();
1159                 String remotechassisidsubtypeEnu = ifNameObj.getRemoteChassisIdSubType().getName();
1160                 String remotechassisid = ifNameObj.getRemoteChassisId();
1161
1162                 Object[] parameters = {nodeId,
1163                     ifName,
1164                     remotesysname,
1165                     remotemgmtaddresssubtype,
1166                     remotemgmtaddress,
1167                     remoteportidsubtypeEnu,
1168                     remoteportid,
1169                     remotechassisidsubtypeEnu,
1170                     remotechassisid,
1171                     startTimestamp,
1172                     startTimestamp
1173                 };
1174
1175                 String query = Queries.getQuery().deviceProtocolLldpNbrlistInsert().get();
1176                 LOG.info("Running {} query ", query);
1177                 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1178                     for (int j = 0; j < parameters.length; j++) {
1179                         stmt.setObject(j + 1, parameters[j]);
1180                     }
1181                     stmt.execute();
1182                     stmt.clearParameters();
1183                 } catch (SQLException e) {
1184                     LOG.error(e.getMessage(), e);
1185                 }
1186
1187             }
1188         }
1189     }
1190
1191     private void persistDevProtocolRstp(String nodeId, Connection connection) {
1192
1193         InstanceIdentifier<Protocols> protocolsIID =
1194                 InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
1195         Optional<Protocols> protocolObject =
1196                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1197                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1198         if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
1199             LOG.error("LLDP subtree is missing");
1200
1201         }
1202         String startTimestamp = getCurrentTimestamp();
1203         for (int i = 0; i < protocolObject.get()
1204             .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.Protocols1.class)
1205             .getRstp().getRstpBridgeInstance().size(); i++) {
1206
1207             RstpBridgeInstance rstpBridgeInstance = protocolObject.get()
1208                 .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.Protocols1.class)
1209                 .getRstp().getRstpBridgeInstance().get(i);
1210             String bridgeName = rstpBridgeInstance.getBridgeName();
1211             String bridgePriority = rstpBridgeInstance.getRstpConfig().getBridgePriority().toString();
1212             String shutdown = rstpBridgeInstance.getRstpConfig().getShutdown().toString();
1213             String holdTime = rstpBridgeInstance.getRstpConfig().getHoldTime().toString();
1214             String helloTime = rstpBridgeInstance.getRstpConfig().getHelloTime().toString();
1215             String maxAge = rstpBridgeInstance.getRstpConfig().getMaxAge().toString();
1216             String forwardDelay = rstpBridgeInstance.getRstpConfig().getForwardDelay().toString();
1217             String transmitHoldCount = rstpBridgeInstance.getRstpConfig().getTransmitHoldCount().toString();
1218             String rootBridgePort =
1219                 rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootBridgePort().toString();
1220             String rootPathCost = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootPathCost().toString();
1221             String rootBridgePriority =
1222                 rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootBridgePriority().toString();
1223             String rootBridgeId = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootBridgeId().toString();
1224             String rootHoldTime = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootHoldTime().toString();
1225             String rootHelloTime = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootHelloTime().toString();
1226             String rootMaxAge = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootMaxAge().toString();
1227             String rootForwardDelay =
1228                 rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getRootForwardDelay().toString();
1229             String bridgeId = rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getBridgeId().toString();
1230             String topoChangeCount =
1231                 rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getTopoChangeCount().toString();
1232             String timeSinceTopoChange =
1233                 rstpBridgeInstance.getRstpState().getRstpBridgeAttr().getTimeSinceTopoChange().toString();
1234
1235             persistDevProtocolRstpBridgePort(nodeId, bridgeName, rstpBridgeInstance, connection);
1236             persistDevProtocolRstpBridgePortAttr(nodeId, bridgeName, rstpBridgeInstance, connection);
1237
1238             Object[] parameters = {nodeId,
1239                 bridgeName,
1240                 bridgePriority,
1241                 shutdown,
1242                 holdTime,
1243                 helloTime,
1244                 maxAge,
1245                 forwardDelay,
1246                 transmitHoldCount,
1247                 rootBridgePort,
1248                 rootPathCost,
1249                 rootBridgePriority,
1250                 rootBridgeId,
1251                 rootHoldTime,
1252                 rootHelloTime,
1253                 rootMaxAge,
1254                 rootForwardDelay,
1255                 bridgeId,
1256                 topoChangeCount,
1257                 timeSinceTopoChange,
1258                 startTimestamp,
1259                 startTimestamp
1260             };
1261
1262             String query = Queries.getQuery().deviceProtocolRstpInsert().get();
1263             LOG.info("Running {} query ", query);
1264             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1265                 for (int j = 0; j < parameters.length; j++) {
1266                     stmt.setObject(j + 1, parameters[j]);
1267                 }
1268                 stmt.execute();
1269                 stmt.clearParameters();
1270             } catch (SQLException e) {
1271                 LOG.error(e.getMessage(), e);
1272             }
1273
1274         }
1275     }
1276
1277     private void persistDevProtocolRstpBridgePort(String nodeId, String bridgeName,
1278         RstpBridgeInstance rstpBridgeInstance, Connection connection) {
1279
1280         String startTimestamp = getCurrentTimestamp();
1281         for (int i = 0; i < rstpBridgeInstance.getRstpConfig().getRstpBridgePortTable().size(); i++) {
1282             RstpBridgePortTable rstpBridgePortTable =
1283                 rstpBridgeInstance.getRstpConfig().getRstpBridgePortTable().get(i);
1284
1285             String ifName = rstpBridgePortTable.getIfname();
1286             String cost = rstpBridgePortTable.getCost().toString();
1287             String priority = rstpBridgePortTable.getPriority().toString();
1288
1289             Object[] parameters = {nodeId,
1290                 bridgeName,
1291                 ifName,
1292                 cost,
1293                 priority,
1294                 startTimestamp,
1295                 startTimestamp
1296             };
1297
1298             String query = Queries.getQuery().deviceProtocolRstpBridgePortInsert().get();
1299             LOG.info("Running {} query ", query);
1300             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1301                 for (int j = 0; j < parameters.length; j++) {
1302                     stmt.setObject(j + 1, parameters[j]);
1303                 }
1304                 stmt.execute();
1305                 stmt.clearParameters();
1306             } catch (SQLException e) {
1307                 LOG.error(e.getMessage(), e);
1308             }
1309
1310         }
1311     }
1312
1313     private void persistDevProtocolRstpBridgePortAttr(String nodeId, String bridgeName,
1314         RstpBridgeInstance rstpBridgeInstance, Connection connection) {
1315
1316         String startTimestamp = getCurrentTimestamp();
1317         for (int i = 0; i < rstpBridgeInstance.getRstpState().getRstpBridgePortAttr().getRstpBridgePortTable().size();
1318             i++) {
1319
1320             org.opendaylight.yang.gen.v1.http.org.openroadm.rstp.rev161014.rstp.bridge.port.state.attr
1321                 .RstpBridgePortTable rstpBridgePortTableAttr =
1322                     rstpBridgeInstance.getRstpState().getRstpBridgePortAttr().getRstpBridgePortTable().get(i);
1323
1324             String ifName = rstpBridgePortTableAttr.getIfname();
1325             String bridgePortState = rstpBridgePortTableAttr.getBridgePortState().getName();
1326             String bridgePortRole = rstpBridgePortTableAttr.getBridgePortRole().getName();
1327             String bridgePortId = rstpBridgePortTableAttr.getBridgePortId().toString();
1328             String openEdgeBridgePort = rstpBridgePortTableAttr.getOperEdgeBridgePort().toString();
1329             String designatedBridgePort = rstpBridgePortTableAttr.getDesignatedBridgePort().toString();
1330             String designatedBridgeId = rstpBridgePortTableAttr.getDesignatedBridgeid().toString();
1331
1332             Object[] parameters = {nodeId,
1333                 bridgeName,
1334                 ifName,
1335                 bridgePortState,
1336                 bridgePortRole,
1337                 bridgePortId,
1338                 openEdgeBridgePort,
1339                 designatedBridgePort,
1340                 designatedBridgeId,
1341                 startTimestamp,
1342                 startTimestamp
1343             };
1344
1345             String query = Queries.getQuery().deviceProtocolRstpBridgePortAttrInsert().get();
1346             LOG.info("Running {} query ", query);
1347             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1348                 for (int j = 0; j < parameters.length; j++) {
1349                     stmt.setObject(j + 1, parameters[j]);
1350                 }
1351                 stmt.execute();
1352                 stmt.clearParameters();
1353             } catch (SQLException e) {
1354                 LOG.error(e.getMessage(), e);
1355             }
1356
1357         }
1358     }
1359
1360
1361     private void persistDevInternalLinks(String nodeId, Connection connection) {
1362
1363         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1364         Optional<OrgOpenroadmDevice> deviceObject =
1365                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1366                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1367         if (deviceObject.get().getInternalLink() == null) {
1368             deviceObject =
1369                     deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1370                             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1371         }
1372         if (deviceObject.get().getInternalLink() == null) {
1373             LOG.info("External links not found for {}", nodeId);
1374         } else {
1375
1376
1377             String startTimestamp = getCurrentTimestamp();
1378             for (int i = 0; i < deviceObject.get().getInternalLink().size(); i++) {
1379                 InternalLink internalLink = deviceObject.get().getInternalLink().get(i);
1380                 String internalLinkName = internalLink.getInternalLinkName();
1381                 String sourceCircuitPackName = internalLink.getSource().getCircuitPackName();
1382                 String sourcePortName = internalLink.getSource().getPortName().toString();
1383                 String destinationCircuitPackName = internalLink.getDestination().getCircuitPackName();
1384                 String destinationPortName = internalLink.getDestination().getPortName().toString();
1385
1386                 Object[] parameters = {nodeId,
1387                     internalLinkName,
1388                     sourceCircuitPackName,
1389                     sourcePortName,
1390                     destinationCircuitPackName,
1391                     destinationPortName,
1392                     startTimestamp,
1393                     startTimestamp
1394                 };
1395
1396                 String query = Queries.getQuery().deviceInternalLinkInsert().get();
1397                 LOG.info("Running {} query ", query);
1398                 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1399                     for (int j = 0; j < parameters.length; j++) {
1400                         stmt.setObject(j + 1, parameters[j]);
1401                     }
1402                     stmt.execute();
1403                     stmt.clearParameters();
1404                 } catch (SQLException e) {
1405                     LOG.error(e.getMessage(), e);
1406                 }
1407
1408             }
1409         }
1410     }
1411
1412
1413     private void persistDevExternalLinks(String nodeId, Connection connection) {
1414
1415         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1416         Optional<OrgOpenroadmDevice> deviceObject =
1417                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1418                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1419
1420         if (deviceObject.get().getExternalLink() == null) {
1421             deviceObject =
1422                     deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1423                             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1424         }
1425         if (deviceObject.get().getExternalLink() == null) {
1426             LOG.info("External links not found for {}", nodeId);
1427         } else {
1428             String startTimestamp = getCurrentTimestamp();
1429             for (int i = 0; i < deviceObject.get().getExternalLink().size(); i++) {
1430                 ExternalLink externalLink = deviceObject.get().getExternalLink().get(i);
1431                 String externalLinkName = externalLink.getExternalLinkName();
1432                 String sourceNodeId = externalLink.getSource().getNodeId();
1433                 String sourceCircuitPackName = externalLink.getSource().getCircuitPackName();
1434                 String sourcePortName = externalLink.getSource().getPortName().toString();
1435                 String destinationNodeId = externalLink.getDestination().getNodeId();
1436                 String destinationCircuitPackName = externalLink.getDestination().getCircuitPackName();
1437                 String destinationPortName = externalLink.getDestination().getPortName().toString();
1438
1439                 Object[] parameters = {nodeId,
1440                     externalLinkName,
1441                     sourceNodeId,
1442                     sourceCircuitPackName,
1443                     sourcePortName,
1444                     destinationNodeId,
1445                     destinationCircuitPackName,
1446                     destinationPortName,
1447                     startTimestamp,
1448                     startTimestamp
1449                 };
1450
1451                 String query = Queries.getQuery().deviceExternalLinkInsert().get();
1452                 LOG.info("Running {} query ", query);
1453                 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1454                     for (int j = 0; j < parameters.length; j++) {
1455                         stmt.setObject(j + 1, parameters[j]);
1456                     }
1457                     stmt.execute();
1458                     stmt.clearParameters();
1459                 } catch (SQLException e) {
1460                     LOG.error(e.getMessage(), e);
1461                 }
1462
1463             }
1464         }
1465     }
1466
1467     private void persistDevPhysicalLinks(String nodeId, Connection connection) {
1468
1469         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1470         Optional<OrgOpenroadmDevice> deviceObject =
1471                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1472                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1473         if (deviceObject.get().getPhysicalLink() == null) {
1474             deviceObject =
1475                     deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1476                             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1477         }
1478         if (deviceObject.get().getPhysicalLink() == null) {
1479             LOG.info("Physical links not found for {}", nodeId);
1480         } else {
1481
1482             String startTimestamp = getCurrentTimestamp();
1483             for (int i = 0; i < deviceObject.get().getPhysicalLink().size(); i++) {
1484                 PhysicalLink physicalLink = deviceObject.get().getPhysicalLink().get(i);
1485                 String physicalLinkName = physicalLink.getPhysicalLinkName();
1486                 String sourceCircuitPackName = physicalLink.getSource().getCircuitPackName();
1487                 String sourcePortName = physicalLink.getSource().getPortName().toString();
1488                 String destinationCircuitPackName = physicalLink.getDestination().getCircuitPackName();
1489                 String destinationPortName = physicalLink.getDestination().getPortName().toString();
1490
1491                 Object[] parameters = {nodeId,
1492                     physicalLinkName,
1493                     sourceCircuitPackName,
1494                     sourcePortName,
1495                     destinationCircuitPackName,
1496                     destinationPortName,
1497                     startTimestamp,
1498                     startTimestamp
1499                 };
1500
1501                 String query = Queries.getQuery().devicePhysicalLinkInsert().get();
1502                 LOG.info("Running {} query ", query);
1503                 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1504                     for (int j = 0; j < parameters.length; j++) {
1505                         stmt.setObject(j + 1, parameters[j]);
1506                     }
1507                     stmt.execute();
1508                     stmt.clearParameters();
1509                 } catch (SQLException e) {
1510                     LOG.error(e.getMessage(), e);
1511                 }
1512
1513             }
1514         }
1515     }
1516
1517     private void persistDevDegree(String nodeId, Connection connection) {
1518
1519         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1520         Optional<OrgOpenroadmDevice> deviceObject =
1521                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1522                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1523
1524
1525         /*if (deviceObject.get().getDegree()==null){
1526             deviceObject =
1527                     deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1528                             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1529         } */
1530         if (deviceObject.get().getDegree() == null) {
1531             LOG.warn("Degree info not found for {}", nodeId);
1532         } else {
1533
1534             String startTimestamp = getCurrentTimestamp();
1535             for (int i = 0; i < deviceObject.get().getDegree().size(); i++) {
1536                 Degree degree = deviceObject.get().getDegree().get(i);
1537                 String degreeNumber = degree.getDegreeNumber().toString();
1538                 String maxWavelengths = degree.getMaxWavelengths().toString();
1539                 String otdrPortCircuitPackName =
1540                     (degree.getOtdrPort() == null ? "" : degree.getOtdrPort().getCircuitPackName());
1541                 String otdrPortPortName =
1542                     (degree.getOtdrPort() == null ? "" : degree.getOtdrPort().getPortName().toString());
1543                 //String mcCapabilitiesSlotWidthGranularity = "";
1544                 //String mcCapabilitiesCenterFreqGranularity = "";
1545                 //String mcCapabilitiesMinSlots = "-1";
1546                 //String mcCapabilitiesMaxSlots = "-1";
1547                 persistDevDegreeCircuitPack(nodeId, degree, degreeNumber, connection);
1548                 persistDevDegreeConnectionPort(nodeId, degree, degreeNumber, connection);
1549
1550                 Object[] parameters = {nodeId,
1551                     degreeNumber,
1552                     maxWavelengths,
1553                     otdrPortCircuitPackName,
1554                     otdrPortPortName,
1555                     //mcCapabilitiesSlotWidthGranularity,
1556                     //mcCapabilitiesCenterFreqGranularity,
1557                     //mcCapabilitiesMinSlots,
1558                     //mcCapabilitiesMaxSlots,
1559                     "", "", "-1", "-1",
1560                     startTimestamp,
1561                     startTimestamp
1562                 };
1563
1564                 String query = Queries.getQuery().deviceDegreeInsert().get();
1565                 LOG.info("Running {} query ", query);
1566                 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1567                     for (int j = 0; j < parameters.length; j++) {
1568                         stmt.setObject(j + 1, parameters[j]);
1569                     }
1570                     stmt.execute();
1571                     stmt.clearParameters();
1572                 } catch (SQLException e) {
1573                     LOG.error(e.getMessage(), e);
1574                 }
1575
1576             }
1577         }
1578     }
1579
1580
1581     private void persistDevDegreeCircuitPack(String nodeId, Degree degree, String degreeNumber, Connection connection) {
1582
1583         String startTimestamp = getCurrentTimestamp();
1584         for (int i = 0; i < degree.getCircuitPacks().size(); i++) {
1585
1586             String circuitPackIndex = degree.getCircuitPacks().get(i).getIndex().toString();
1587             String circuitPackName = degree.getCircuitPacks().get(i).getCircuitPackName();
1588
1589             Object[] parameters = {nodeId,
1590                 degreeNumber,
1591                 circuitPackIndex,
1592                 circuitPackName,
1593                 startTimestamp,
1594                 startTimestamp
1595             };
1596
1597             String query = Queries.getQuery().deviceDegreeCircuitPackInsert().get();
1598             LOG.info("Running {} query ", query);
1599             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1600                 for (int j = 0; j < parameters.length; j++) {
1601                     stmt.setObject(j + 1, parameters[j]);
1602                 }
1603                 stmt.execute();
1604                 stmt.clearParameters();
1605             } catch (SQLException e) {
1606                 LOG.error(e.getMessage(), e);
1607             }
1608
1609         }
1610     }
1611
1612     private void persistDevDegreeConnectionPort(String nodeId, Degree degree, String degreeNumber,
1613         Connection connection) {
1614
1615         String startTimestamp = getCurrentTimestamp();
1616         for (int i = 0; i < degree.getConnectionPorts().size(); i++) {
1617
1618             String connectionPortIndex = degree.getConnectionPorts().get(i).getIndex().toString();
1619             String circuitPackName = degree.getConnectionPorts().get(i).getCircuitPackName();
1620             String portName = degree.getConnectionPorts().get(i).getPortName().toString();
1621
1622             Object[] parameters = {nodeId,
1623                 degreeNumber,
1624                 connectionPortIndex,
1625                 circuitPackName,
1626                 portName,
1627                 startTimestamp,
1628                 startTimestamp
1629             };
1630
1631             String query = Queries.getQuery().deviceDegreeConnectionPortInsert().get();
1632             LOG.info("Running {} query ", query);
1633             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1634                 for (int j = 0; j < parameters.length; j++) {
1635                     stmt.setObject(j + 1, parameters[j]);
1636                 }
1637                 stmt.execute();
1638                 stmt.clearParameters();
1639             } catch (SQLException e) {
1640                 LOG.error(e.getMessage(), e);
1641             }
1642
1643         }
1644     }
1645
1646
1647     private void persistDevSrg(String nodeId, Connection connection) {
1648
1649         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1650         Optional<OrgOpenroadmDevice> deviceObject =
1651                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1652                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1653
1654         if (deviceObject.get().getSharedRiskGroup() == null) {
1655             deviceObject =
1656                     deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1657                             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1658         }
1659         if (deviceObject.get().getSharedRiskGroup() == null) {
1660             LOG.info("no srg found for node {} ", nodeId);
1661         } else {
1662             String startTimestamp = getCurrentTimestamp();
1663             for (int i = 0; i < deviceObject.get().getSharedRiskGroup().size(); i++) {
1664                 SharedRiskGroup sharedRiskGroup = deviceObject.get().getSharedRiskGroup().get(i);
1665                 //String currentProvisionedAddDropPorts = "-1";
1666                 //String mcCapSlotWidthGranularity = "";
1667                 //String mcCapCenterFreqGranularity = "";
1668                 //String mcCapMinSlots = "-1";
1669                 //String mcCapMaxSlots = "-1";
1670                 String maxAddDropPorts = sharedRiskGroup.getMaxAddDropPorts().toString();
1671                 String srgNumber = sharedRiskGroup.getSrgNumber().toString();
1672                 String wavelengthDuplicationEnu = sharedRiskGroup.getWavelengthDuplication().getName();
1673                 persistDevSrgCircuitPacks(nodeId, sharedRiskGroup, srgNumber, connection);
1674
1675                 Object[] parameters = {nodeId,
1676                     maxAddDropPorts,
1677                     //currentProvisionedAddDropPorts,
1678                     "-1",
1679                     srgNumber,
1680                     wavelengthDuplicationEnu,
1681                     //mcCapSlotWidthGranularity,
1682                     //mcCapCenterFreqGranularity,
1683                     //mcCapMinSlots,
1684                     //mcCapMaxSlots,
1685                     "", "", "", "",
1686                     startTimestamp,
1687                     startTimestamp
1688                 };
1689
1690                 String query = Queries.getQuery().deviceSharedRiskGroupInsert().get();
1691                 LOG.info("Running {} query ", query);
1692                 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1693                     for (int j = 0; j < parameters.length; j++) {
1694                         stmt.setObject(j + 1, parameters[j]);
1695                     }
1696                     stmt.execute();
1697                     stmt.clearParameters();
1698                 } catch (SQLException e) {
1699                     LOG.error(e.getMessage(), e);
1700                 }
1701
1702             }
1703         }
1704     }
1705
1706
1707     private void persistDevSrgCircuitPacks(String nodeId, SharedRiskGroup sharedRiskGroup, String srgNumber,
1708         Connection connection) {
1709
1710         String startTimestamp = getCurrentTimestamp();
1711         for (int i = 0; i < sharedRiskGroup.getCircuitPacks().size(); i++) {
1712
1713             String circuitPackindex = sharedRiskGroup.getCircuitPacks().get(i).getIndex().toString();
1714             String circuitPackName = sharedRiskGroup.getCircuitPacks().get(i).getCircuitPackName();
1715
1716             Object[] parameters = {nodeId,
1717                 srgNumber,
1718                 circuitPackindex,
1719                 circuitPackName,
1720                 startTimestamp,
1721                 startTimestamp
1722             };
1723
1724             String query = Queries.getQuery().deviceSrgCircuitPackInsert().get();
1725             LOG.info("Running {} query ", query);
1726             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1727                 for (int j = 0; j < parameters.length; j++) {
1728                     stmt.setObject(j + 1, parameters[j]);
1729                 }
1730                 stmt.execute();
1731                 stmt.clearParameters();
1732             } catch (SQLException e) {
1733                 LOG.error(e.getMessage(), e);
1734             }
1735
1736         }
1737     }
1738
1739     private void persistDevRoadmConnections(String nodeId, Connection connection) {
1740
1741         //int opticalcontrolmodeEnu=-1;
1742
1743         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1744         Optional<OrgOpenroadmDevice> deviceObject =
1745                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1746                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1747
1748         if (deviceObject.get().getRoadmConnections() == null) {
1749             deviceObject =
1750                     deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, deviceIID,
1751                             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1752         }
1753
1754         if (deviceObject.get().getRoadmConnections() != null) {
1755             String startTimestamp = getCurrentTimestamp();
1756             for (int i = 0; i < deviceObject.get().getRoadmConnections().size(); i++) {
1757                 RoadmConnections roadmConnections = deviceObject.get().getRoadmConnections().get(i);
1758                 String connectionNumber = roadmConnections.getConnectionNumber();
1759                 //String connectionName = "";
1760                 String wavelengthNumber = roadmConnections.getWavelengthNumber().toString();
1761                 String opticalcontrolmodeEnu = roadmConnections.getOpticalControlMode().getName();
1762                 String targetOutputPower = roadmConnections.getTargetOutputPower().toString();
1763                 String srcIf = roadmConnections.getSource().getSrcIf();
1764                 String dstIf = roadmConnections.getDestination().getDstIf();
1765
1766                 Object[] parameters = {nodeId,
1767                     //connectionName,
1768                     "",
1769                     connectionNumber,
1770                     wavelengthNumber,
1771                     opticalcontrolmodeEnu,
1772                     targetOutputPower,
1773                     srcIf,
1774                     dstIf,
1775                     startTimestamp,
1776                     startTimestamp
1777                 };
1778
1779                 String query = Queries.getQuery().deviceRoadmConnectionsInsert().get();
1780                 LOG.info("Running {} query ", query);
1781                 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1782                     for (int j = 0; j < parameters.length; j++) {
1783                         stmt.setObject(j + 1, parameters[j]);
1784                     }
1785                     stmt.execute();
1786                     stmt.clearParameters();
1787                 } catch (SQLException e) {
1788                     LOG.error(e.getMessage(), e);
1789                 }
1790
1791             }
1792         } else {
1793             LOG.info("ROADM Dev Connections not found!! for {}", nodeId);
1794         }
1795     }
1796
1797
1798     private void persistDevConnectionMap(String nodeId, Connection connection) {
1799
1800         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1801         Optional<OrgOpenroadmDevice> deviceObject =
1802                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1803                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1804
1805         String startTimestamp = getCurrentTimestamp();
1806         for (int i = 0; i < deviceObject.get().getConnectionMap().size(); i++) {
1807             ConnectionMap connectionMap = deviceObject.get().getConnectionMap().get(i);
1808             String connectionMapNumber = connectionMap.getConnectionMapNumber().toString();
1809             String sourceCircuitPackName = connectionMap.getSource().getCircuitPackName();
1810             String sourcePortName = connectionMap.getSource().getCircuitPackName();
1811
1812
1813             Object[] parameters = {nodeId,
1814                 connectionMapNumber,
1815                 sourceCircuitPackName,
1816                 sourcePortName,
1817                 startTimestamp,
1818                 startTimestamp
1819             };
1820
1821             String query = Queries.getQuery().deviceConnectionMapInsert().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]);
1826                 }
1827                 stmt.execute();
1828                 stmt.clearParameters();
1829             } catch (SQLException e) {
1830                 LOG.error(e.getMessage(), e);
1831             }
1832
1833         }
1834     }
1835
1836     private void persistDevWavelengthMap(String nodeId, Connection connection) {
1837
1838         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1839         Optional<OrgOpenroadmDevice> deviceObject =
1840                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1841                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1842
1843         String startTimestamp = getCurrentTimestamp();
1844         for (int i = 0; i < deviceObject.get().getWavelengthMap().getWavelengths().size(); i++) {
1845             Wavelengths wavelengths = deviceObject.get().getWavelengthMap().getWavelengths().get(i);
1846             String wavelengthNumber = wavelengths.getWavelengthNumber().toString();
1847             String centerFrequency = wavelengths.getCenterFrequency().toString();
1848             String wavelength = wavelengths.getWavelength().toString();
1849
1850
1851             Object[] parameters = {nodeId,
1852                 wavelengthNumber,
1853                 centerFrequency,
1854                 wavelength,
1855                 startTimestamp,
1856                 startTimestamp
1857             };
1858
1859             String query = Queries.getQuery().deviceWavelengthInsert().get();
1860             LOG.info("Running {} query ", query);
1861             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1862                 for (int j = 0; j < parameters.length; j++) {
1863                     stmt.setObject(j + 1, parameters[j]);
1864                 }
1865                 stmt.execute();
1866                 stmt.clearParameters();
1867             } catch (SQLException e) {
1868                 LOG.error(e.getMessage(), e);
1869             }
1870
1871         }
1872     }
1873
1874
1875     private void persistDevInterfaceTcm(String nodeId, String interfaceName, OduBuilder oduBuilder,
1876         Connection connection) {
1877
1878         for (int i = 0; i < oduBuilder.getTcm().size(); i++) {
1879             Tcm tcm;
1880
1881             tcm = oduBuilder.getTcm().get(i);
1882
1883             Object[] parameters = prepareDevInterfaceTcmParameters(nodeId, interfaceName, tcm);
1884
1885             String query = Queries.getQuery().deviceInterfacesInsert().get();
1886             LOG.info("Running {} query ", query);
1887             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1888                 for (int j = 0; j < parameters.length; j++) {
1889                     stmt.setObject(j + 1, parameters[j]);
1890                 }
1891                 stmt.execute();
1892                 stmt.clearParameters();
1893             } catch (SQLException e) {
1894                 LOG.error(e.getMessage(), e);
1895             }
1896         }
1897     }
1898
1899     private void persistDevInterfaceOtnOduTxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1900         Connection connection) {
1901
1902         for (int i = 0; i < oduBuilder.getTcm().size(); i++) {
1903             TxMsi txMsi;
1904
1905             txMsi = oduBuilder.getOpu().getMsi().getTxMsi().get(i);
1906
1907             Object[] parameters = prepareDevInterfaceOtnOduTxMsiParameters(nodeId, interfaceName, txMsi);
1908
1909             String query = Queries.getQuery().deviceInterfaceOtnOduTxMsiInsert().get();
1910             LOG.info("Running {} query ", query);
1911             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1912                 for (int j = 0; j < parameters.length; j++) {
1913                     stmt.setObject(j + 1, parameters[j]);
1914                 }
1915                 stmt.execute();
1916                 stmt.clearParameters();
1917             } catch (SQLException e) {
1918                 LOG.error(e.getMessage(), e);
1919             }
1920         }
1921     }
1922
1923
1924     private void persistDevInterfaceOtnOduRxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1925         Connection connection) {
1926
1927         for (int i = 0; i < oduBuilder.getTcm().size(); i++) {
1928             RxMsi rxMsi;
1929
1930             rxMsi = oduBuilder.getOpu().getMsi().getRxMsi().get(i);
1931
1932             Object[] parameters = prepareDevInterfaceOtnOduRxMsiParameters(nodeId, interfaceName, rxMsi);
1933
1934             String query = Queries.getQuery().deviceInterfaceOtnOduRxMsiInsert().get();
1935             LOG.info("Running {} query ", query);
1936             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1937                 for (int j = 0; j < parameters.length; j++) {
1938                     stmt.setObject(j + 1, parameters[j]);
1939                 }
1940                 stmt.execute();
1941                 stmt.clearParameters();
1942             } catch (SQLException e) {
1943                 LOG.error(e.getMessage(), e);
1944             }
1945         }
1946     }
1947
1948
1949     private void persistDevInterfaceOtnOduExpMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1950         Connection connection) {
1951
1952         for (int i = 0; i < oduBuilder.getTcm().size(); i++) {
1953             ExpMsi expMsi;
1954
1955             expMsi = oduBuilder.getOpu().getMsi().getExpMsi().get(i);
1956
1957             Object[] parameters = prepareDevInterfaceOtnOduExpMsiParameters(nodeId, interfaceName, expMsi);
1958
1959             String query = Queries.getQuery().deviceInterfaceOtnOduExpMsiInsert().get();
1960             LOG.info("Running {} query ", query);
1961             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1962                 for (int j = 0; j < parameters.length; j++) {
1963                     stmt.setObject(j + 1, parameters[j]);
1964                 }
1965                 stmt.execute();
1966                 stmt.clearParameters();
1967             } catch (SQLException e) {
1968                 LOG.error(e.getMessage(), e);
1969             }
1970         }
1971     }
1972
1973
1974 }