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