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