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