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