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