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