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