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