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