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