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