aabbea2e434e0625f42d53c9fd1dad35914f455a
[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.isProactiveDelayMeasurementEnabled().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().isEnabled().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().isEnabled().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.isLtcActEnabled().toString();
796         String proactiveDelayMeasurementEnabled = tcm.isProactiveDelayMeasurementEnabled().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
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
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         }
1050         String startTimestamp = getCurrentTimestamp();
1051         @NonNull
1052         Map<IfNameKey, IfName> ifNameMap = protocolObject.get()
1053             .augmentation(Protocols1.class).getLldp().getNbrList().nonnullIfName();
1054         for (Map.Entry<IfNameKey, IfName> entry : ifNameMap.entrySet()) {
1055
1056             IfName ifNameObj = entry.getValue();
1057             String ifName = ifNameObj.getIfName();
1058             String remotesysname = ifNameObj.getRemoteSysName();
1059             String remotemgmtaddresssubtype = ifNameObj.getRemoteMgmtAddressSubType().getName();
1060             String remotemgmtaddress = ifNameObj.getRemoteMgmtAddress().getIpv4Address().toString();
1061             int remoteportidsubtypeEnu = ifNameObj.getRemotePortIdSubType().getIntValue();
1062             String remoteportid = ifNameObj.getRemotePortId();
1063             int remotechassisidsubtypeEnu = ifNameObj.getRemoteChassisIdSubType().getIntValue();
1064             String remotechassisid = ifNameObj.getRemoteChassisId();
1065
1066             Object[] parameters = {nodeId,
1067                 ifName,
1068                 remotesysname,
1069                 remotemgmtaddresssubtype,
1070                 remotemgmtaddress,
1071                 Integer.toString(remoteportidsubtypeEnu),
1072                 remoteportid,
1073                 Integer.toString(remotechassisidsubtypeEnu),
1074                 remotechassisid,
1075                 startTimestamp,
1076                 startTimestamp
1077             };
1078
1079             String query = Queries.getQuery().deviceProtocolLldpNbrlistInsert().get();
1080             LOG.info("Running {} query ", query);
1081             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1082                 for (int j = 0; j < parameters.length; j++) {
1083                     stmt.setObject(j + 1, parameters[j]);
1084                 }
1085                 stmt.execute();
1086                 stmt.clearParameters();
1087             } catch (SQLException e) {
1088                 LOG.error("Something wrong when storing devices protocols LLDP list number in DB", e);
1089             }
1090
1091         }
1092     }
1093
1094     private void persistDevInternalLinks(String nodeId, Connection connection) {
1095
1096         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1097         Optional<OrgOpenroadmDevice> deviceObject =
1098                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1099                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1100         if (!deviceObject.isPresent()) {
1101             LOG.error("Device with node id {} not found", nodeId);
1102             return;
1103
1104         }
1105         String startTimestamp = getCurrentTimestamp();
1106         @NonNull
1107         Map<InternalLinkKey, InternalLink> internalLinkMap = deviceObject.get().nonnullInternalLink();
1108         for (Map.Entry<InternalLinkKey, InternalLink> entry : internalLinkMap.entrySet()) {
1109             InternalLink internalLink = entry.getValue();
1110             String internalLinkName = internalLink.getInternalLinkName();
1111             String sourceCircuitPackName = internalLink.getSource().getCircuitPackName();
1112             String sourcePortName = internalLink.getSource().getPortName().toString();
1113             String destinationCircuitPackName = internalLink.getDestination().getCircuitPackName();
1114             String destinationPortName = internalLink.getDestination().getPortName().toString();
1115
1116             Object[] parameters = {nodeId,
1117                 internalLinkName,
1118                 sourceCircuitPackName,
1119                 sourcePortName,
1120                 destinationCircuitPackName,
1121                 destinationPortName,
1122                 startTimestamp,
1123                 startTimestamp
1124             };
1125
1126             String query = Queries.getQuery().deviceInternalLinkInsert().get();
1127             LOG.info("Running {} query ", query);
1128             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1129                 for (int j = 0; j < parameters.length; j++) {
1130                     stmt.setObject(j + 1, parameters[j]);
1131                 }
1132                 stmt.execute();
1133                 stmt.clearParameters();
1134             } catch (SQLException e) {
1135                 LOG.error("Something wrong when storing devices internal links", e);
1136             }
1137
1138         }
1139     }
1140
1141
1142     private void persistDevExternalLinks(String nodeId, Connection connection) {
1143
1144         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1145         Optional<OrgOpenroadmDevice> deviceObject =
1146                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1147                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1148         if (!deviceObject.isPresent()) {
1149             LOG.error("Device with node id {} not found", nodeId);
1150             return;
1151
1152         }
1153         String startTimestamp = getCurrentTimestamp();
1154         @NonNull
1155         Map<ExternalLinkKey, ExternalLink> externalLinkMap = deviceObject.get().nonnullExternalLink();
1156         for (Map.Entry<ExternalLinkKey, ExternalLink> entry : externalLinkMap.entrySet()) {
1157             ExternalLink externalLink = entry.getValue();
1158             String externalLinkName = externalLink.getExternalLinkName();
1159             String sourceNodeId = externalLink.getSource().getNodeId();
1160             String sourceCircuitPackName = externalLink.getSource().getCircuitPackName();
1161             String sourcePortName = externalLink.getSource().getPortName();
1162             String destinationNodeId = externalLink.getDestination().getNodeId();
1163             String destinationCircuitPackName = externalLink.getDestination().getCircuitPackName();
1164             String destinationPortName = externalLink.getDestination().getPortName();
1165
1166             Object[] parameters = {nodeId,
1167                 externalLinkName,
1168                 sourceNodeId,
1169                 sourceCircuitPackName,
1170                 sourcePortName,
1171                 destinationNodeId,
1172                 destinationCircuitPackName,
1173                 destinationPortName,
1174                 startTimestamp,
1175                 startTimestamp
1176             };
1177
1178             String query = Queries.getQuery().deviceExternalLinkInsert().get();
1179             LOG.info("Running {} query ", query);
1180             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1181                 for (int j = 0; j < parameters.length; j++) {
1182                     stmt.setObject(j + 1, parameters[j]);
1183                 }
1184                 stmt.execute();
1185                 stmt.clearParameters();
1186             } catch (SQLException e) {
1187                 LOG.error("Something wrong when storing devices external links", e);
1188             }
1189
1190         }
1191     }
1192
1193     private void persistDevPhysicalLinks(String nodeId, Connection connection) {
1194
1195         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1196         Optional<OrgOpenroadmDevice> deviceObject =
1197                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1198                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1199         if (!deviceObject.isPresent()) {
1200             LOG.error("Device with node id {} not found", nodeId);
1201             return;
1202
1203         }
1204         String startTimestamp = getCurrentTimestamp();
1205         @NonNull
1206         Map<PhysicalLinkKey, PhysicalLink> physicalLinkMap = deviceObject.get().nonnullPhysicalLink();
1207         for (Map.Entry<PhysicalLinkKey, PhysicalLink> entry : physicalLinkMap.entrySet()) {
1208             PhysicalLink physicalLink = entry.getValue();
1209             String physicalLinkName = physicalLink.getPhysicalLinkName();
1210             String sourceCircuitPackName = physicalLink.getSource().getCircuitPackName();
1211             String sourcePortName = physicalLink.getSource().getPortName().toString();
1212             String destinationCircuitPackName = physicalLink.getDestination().getCircuitPackName();
1213             String destinationPortName = physicalLink.getDestination().getPortName().toString();
1214
1215             Object[] parameters = {nodeId,
1216                 physicalLinkName,
1217                 sourceCircuitPackName,
1218                 sourcePortName,
1219                 destinationCircuitPackName,
1220                 destinationPortName,
1221                 startTimestamp,
1222                 startTimestamp
1223             };
1224
1225             String query = Queries.getQuery().devicePhysicalLinkInsert().get();
1226             LOG.info("Running {} query ", query);
1227             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1228                 for (int j = 0; j < parameters.length; j++) {
1229                     stmt.setObject(j + 1, parameters[j]);
1230                 }
1231                 stmt.execute();
1232                 stmt.clearParameters();
1233             } catch (SQLException e) {
1234                 LOG.error("Something wrong when storing devices physical links", e);
1235             }
1236
1237         }
1238     }
1239
1240     private void persistDevDegree(String nodeId, Connection connection) {
1241
1242         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1243         Optional<OrgOpenroadmDevice> deviceObject =
1244                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1245                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1246         if (!deviceObject.isPresent()) {
1247             LOG.error("Device with node id {} not found", nodeId);
1248             return;
1249
1250         }
1251         String startTimestamp = getCurrentTimestamp();
1252         @NonNull
1253         Map<DegreeKey, Degree> degreeMap = deviceObject.get().nonnullDegree();
1254         for (Map.Entry<DegreeKey, Degree> entry : degreeMap.entrySet()) {
1255             Degree degree = entry.getValue();
1256             String degreeNumber = degree.getDegreeNumber().toString();
1257             String maxWavelengths = degree.getMaxWavelengths().toString();
1258             String otdrPortCircuitPackName = degree.getOtdrPort().getCircuitPackName();
1259             String otdrPortPortName = degree.getOtdrPort().getPortName().toString();
1260             persistDevDegreeCircuitPack(nodeId, degree, degreeNumber, connection);
1261             persistDevDegreeConnectionPort(nodeId, degree, degreeNumber, connection);
1262             //String mcCapabilitiesSlotWidthGranularity = "";
1263             //String mcCapabilitiesCenterFreqGranularity = "";
1264             //String mcCapabilitiesMinSlots = "";
1265             //String mcCapabilitiesMaxSlots = "";
1266
1267             Object[] parameters = {nodeId,
1268                 degreeNumber,
1269                 maxWavelengths,
1270                 otdrPortCircuitPackName,
1271                 otdrPortPortName,
1272                 //mcCapabilitiesSlotWidthGranularity,
1273                 //mcCapabilitiesCenterFreqGranularity,
1274                 //mcCapabilitiesMinSlots,
1275                 //mcCapabilitiesMaxSlots,
1276                 "","","","",
1277                 startTimestamp,
1278                 startTimestamp
1279             };
1280
1281             String query = Queries.getQuery().deviceDegreeInsert().get();
1282             LOG.info("Running {} query ", query);
1283             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1284                 for (int j = 0; j < parameters.length; j++) {
1285                     stmt.setObject(j + 1, parameters[j]);
1286                 }
1287                 stmt.execute();
1288                 stmt.clearParameters();
1289             } catch (SQLException e) {
1290                 LOG.error("Something wrong when storing devices degrees", e);
1291             }
1292
1293         }
1294     }
1295
1296
1297     private void persistDevDegreeCircuitPack(String nodeId, Degree degree, String degreeNumber, Connection connection) {
1298
1299         String startTimestamp = getCurrentTimestamp();
1300         @NonNull
1301         Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1302                 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks>
1303             circuitPacksMap = degree.nonnullCircuitPacks();
1304         for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1305                 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks> entry :
1306                     circuitPacksMap.entrySet()) {
1307
1308
1309             String circuitPackIndex = entry.getValue().getIndex().toString();
1310             String circuitPackName = entry.getValue().getCircuitPackName();
1311
1312             Object[] parameters = {nodeId,
1313                 degreeNumber,
1314                 circuitPackIndex,
1315                 circuitPackName,
1316                 startTimestamp,
1317                 startTimestamp
1318             };
1319
1320             String query = Queries.getQuery().deviceDegreeCircuitPackInsert().get();
1321             LOG.info("Running {} query ", query);
1322             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1323                 for (int j = 0; j < parameters.length; j++) {
1324                     stmt.setObject(j + 1, parameters[j]);
1325                 }
1326                 stmt.execute();
1327                 stmt.clearParameters();
1328             } catch (SQLException e) {
1329                 LOG.error("Something wrong when storing devices degrees circuit packs", e);
1330             }
1331
1332         }
1333     }
1334
1335     private void persistDevDegreeConnectionPort(String nodeId, Degree degree, String degreeNumber,
1336         Connection connection) {
1337
1338         String startTimestamp = getCurrentTimestamp();
1339         @NonNull
1340         Map<ConnectionPortsKey, ConnectionPorts> connectionPortsMap = degree.nonnullConnectionPorts();
1341         for (Map.Entry<ConnectionPortsKey, ConnectionPorts> entry : connectionPortsMap.entrySet()) {
1342
1343             ConnectionPorts connectionPorts = entry.getValue();
1344             String connectionPortIndex = connectionPorts.getIndex().toString();
1345             String circuitPackName = connectionPorts.getCircuitPackName();
1346             String portName = connectionPorts.getPortName().toString();
1347
1348             Object[] parameters = {nodeId,
1349                 degreeNumber,
1350                 connectionPortIndex,
1351                 circuitPackName,
1352                 portName,
1353                 startTimestamp,
1354                 startTimestamp
1355             };
1356
1357             String query = Queries.getQuery().deviceDegreeConnectionPortInsert().get();
1358             LOG.info("Running {} query ", query);
1359             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1360                 for (int j = 0; j < parameters.length; j++) {
1361                     stmt.setObject(j + 1, parameters[j]);
1362                 }
1363                 stmt.execute();
1364                 stmt.clearParameters();
1365             } catch (SQLException e) {
1366                 LOG.error("Something wrong when storing devices degrees connection ports", e);
1367             }
1368
1369         }
1370     }
1371
1372
1373     private void persistDevSrg(String nodeId, Connection connection) {
1374
1375         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1376         Optional<OrgOpenroadmDevice> deviceObject =
1377                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1378                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1379         if (!deviceObject.isPresent()) {
1380             LOG.error("Device with node id {} not found", nodeId);
1381             return;
1382
1383         }
1384         String startTimestamp = getCurrentTimestamp();
1385         @NonNull
1386         Map<SharedRiskGroupKey, SharedRiskGroup> sharedRiskGroupMap = deviceObject.get().nonnullSharedRiskGroup();
1387         for (Map.Entry<SharedRiskGroupKey, SharedRiskGroup> entry : sharedRiskGroupMap.entrySet()) {
1388             SharedRiskGroup sharedRiskGroup = entry.getValue();
1389             String maxAddDropPorts = sharedRiskGroup.getMaxAddDropPorts().toString();
1390             String srgNumber = sharedRiskGroup.getSrgNumber().toString();
1391             //int wavelengthDuplicationEnu = sharedRiskGroup.getWavelengthDuplication().getIntValue();
1392             persistDevSrgCircuitPacks(nodeId, sharedRiskGroup, srgNumber, connection);
1393             //String currentProvisionedAddDropPorts = "";
1394             //String mcCapSlotWidthGranularity = "";
1395             //String mcCapCenterFreqGranularity = "";
1396             //String mcCapMinSlots = "";
1397             //String mcCapMaxSlots = "";
1398
1399             Object[] parameters = {nodeId,
1400                 maxAddDropPorts,
1401                 //currentProvisionedAddDropPorts,
1402                 "",
1403                 srgNumber,
1404                 //mcCapSlotWidthGranularity,
1405                 //mcCapCenterFreqGranularity,
1406                 //mcCapMinSlots,
1407                 //mcCapMaxSlots,
1408                 "","","","",
1409                 startTimestamp,
1410                 startTimestamp
1411             };
1412
1413             String query = Queries.getQuery().deviceSharedRiskGroupInsert().get();
1414             LOG.info("Running {} query ", query);
1415             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1416                 for (int j = 0; j < parameters.length; j++) {
1417                     stmt.setObject(j + 1, parameters[j]);
1418                 }
1419                 stmt.execute();
1420                 stmt.clearParameters();
1421             } catch (SQLException e) {
1422                 LOG.error("Something wrong when storing devices SRG", e);
1423             }
1424
1425         }
1426     }
1427
1428     private void persistDevSrgCircuitPacks(String nodeId, SharedRiskGroup sharedRiskGroup, String srgNumber,
1429         Connection connection) {
1430
1431         String startTimestamp = getCurrentTimestamp();
1432         @NonNull
1433         Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1434                 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>
1435                 circuitPacksMap = sharedRiskGroup.nonnullCircuitPacks();
1436         for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1437                 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> entry :
1438                     circuitPacksMap.entrySet()) {
1439
1440             org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks circuitPack =
1441                                 entry.getValue();
1442             String circuitPackindex = circuitPack.getIndex().toString();
1443             String circuitPackName = circuitPack.getCircuitPackName();
1444
1445             Object[] parameters = {nodeId,
1446                 srgNumber,
1447                 circuitPackindex,
1448                 circuitPackName,
1449                 startTimestamp,
1450                 startTimestamp
1451             };
1452
1453             String query = Queries.getQuery().deviceSrgCircuitPackInsert().get();
1454             LOG.info("Running {} query ", query);
1455             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1456                 for (int j = 0; j < parameters.length; j++) {
1457                     stmt.setObject(j + 1, parameters[j]);
1458                 }
1459                 stmt.execute();
1460                 stmt.clearParameters();
1461             } catch (SQLException e) {
1462                 LOG.error("Something wrong when storing devices SRG circuit packs", e);
1463             }
1464
1465         }
1466     }
1467
1468     private void persistDevRoadmConnections(String nodeId, Connection connection) {
1469
1470         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1471         Optional<OrgOpenroadmDevice> deviceObject =
1472                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1473                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1474         if (!deviceObject.isPresent()) {
1475             LOG.error("Device with node id {} not found", nodeId);
1476             return;
1477
1478         }
1479         String startTimestamp = getCurrentTimestamp();
1480         @NonNull
1481         Map<RoadmConnectionsKey, RoadmConnections> roadmConnectionsMap = deviceObject.get().nonnullRoadmConnections();
1482         for (Map.Entry<RoadmConnectionsKey, RoadmConnections> entry : roadmConnectionsMap.entrySet()) {
1483             RoadmConnections roadmConnections = entry.getValue();
1484             int opticalcontrolmodeEnu = roadmConnections.getOpticalControlMode().getIntValue();
1485             //String connectionName = "";
1486             //String connectionNumber = "";
1487             //String wavelengthNumber = "";
1488             String targetOutputPower = roadmConnections.getTargetOutputPower().toString();
1489             String srcIf = roadmConnections.getSource().getSrcIf();
1490             String dstIf = roadmConnections.getDestination().getDstIf();
1491
1492             Object[] parameters = {nodeId,
1493                 //connectionName,
1494                 //connectionNumber,
1495                 //wavelengthNumber,
1496                 "","","",
1497                 Integer.toString(opticalcontrolmodeEnu),
1498                 targetOutputPower,
1499                 srcIf,
1500                 dstIf,
1501                 startTimestamp,
1502                 startTimestamp
1503             };
1504
1505
1506             String query = Queries.getQuery().deviceRoadmConnectionsInsert().get();
1507             LOG.info("Running {} query ", query);
1508             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1509                 for (int j = 0; j < parameters.length; j++) {
1510                     stmt.setObject(j + 1, parameters[j]);
1511                 }
1512                 stmt.execute();
1513                 stmt.clearParameters();
1514             } catch (SQLException e) {
1515                 LOG.error("Something wrong when storing devices ROADM connection ", e);
1516             }
1517
1518         }
1519     }
1520
1521
1522     private void persistDevConnectionMap(String nodeId, Connection connection) {
1523
1524         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1525         Optional<OrgOpenroadmDevice> deviceObject =
1526                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1527                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1528         if (!deviceObject.isPresent()) {
1529             LOG.error("Device with node id {} not found", nodeId);
1530             return;
1531         }
1532         String startTimestamp = getCurrentTimestamp();
1533         @NonNull
1534         Map<ConnectionMapKey, ConnectionMap> connectionMapMap = deviceObject.get().nonnullConnectionMap();
1535         for (Map.Entry<ConnectionMapKey, ConnectionMap> entry : connectionMapMap.entrySet()) {
1536             ConnectionMap connectionMap = entry.getValue();
1537             String connectionMapNumber = connectionMap.getConnectionMapNumber().toString();
1538             String sourceCircuitPackName = connectionMap.getSource().getCircuitPackName();
1539             String sourcePortName = connectionMap.getSource().getCircuitPackName();
1540
1541
1542             Object[] parameters = {nodeId,
1543                 connectionMapNumber,
1544                 sourceCircuitPackName,
1545                 sourcePortName,
1546                 startTimestamp,
1547                 startTimestamp
1548             };
1549
1550             String query = Queries.getQuery().deviceConnectionMapInsert().get();
1551             LOG.info("Running {} query ", query);
1552             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1553                 for (int j = 0; j < parameters.length; j++) {
1554                     stmt.setObject(j + 1, parameters[j]);
1555                 }
1556                 stmt.execute();
1557                 stmt.clearParameters();
1558             } catch (SQLException e) {
1559                 LOG.error("Something wrong when storing devices connection map", e);
1560             }
1561
1562         }
1563     }
1564 /*
1565     private void persistDevWavelengthMap(String nodeId, Connection connection) {
1566
1567
1568         String wavelengthNumber="", centerFrequency="", wavelength="";;
1569
1570         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1571         Optional<OrgOpenroadmDevice> deviceObject =
1572                 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1573                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1574
1575
1576         String startTimestamp = getCurrentTimestamp();
1577         for (int i = 0; i<deviceObject.get().getWavelengthMap().getWavelengths().size(); i++) {
1578             Wavelengths wavelengths = deviceObject.get().getWavelengthMap().getWavelengths().get(i);
1579             wavelengthNumber=wavelengths.getWavelengthNumber().toString();
1580             centerFrequency=wavelengths.getCenterFrequency().toString();
1581             wavelength=wavelengths.getWavelength().toString();
1582
1583
1584             Object[] parameters = {nodeId,
1585                 wavelengthNumber,
1586                 centerFrequency,
1587                 wavelength,
1588                 startTimestamp,
1589                 startTimestamp
1590             };
1591
1592             String query = Queries.getQuery().deviceWavelengthInsert().get();
1593             LOG.info("Running {} query ", query);
1594             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1595                 for (int j = 0; j < parameters.length; j++) {
1596                     stmt.setObject(j + 1, parameters[j]);
1597                 }
1598                 stmt.execute();
1599                 stmt.clearParameters();
1600             } catch (SQLException e) {
1601                 LOG.error("Something wrong when storing devices wavelength map", e);
1602             }
1603
1604         }
1605     }
1606
1607 */
1608
1609     private void persistDevInterfaceTcm(String nodeId, String interfaceName, OduBuilder oduBuilder,
1610         Connection connection) {
1611
1612         Map<TcmKey, Tcm> tcmMap = oduBuilder.getTcm();
1613         for (Map.Entry<TcmKey, Tcm> entry : tcmMap.entrySet()) {
1614             Tcm tcm = entry.getValue();
1615
1616             Object[] parameters = prepareDevInterfaceTcmParameters(nodeId, interfaceName, tcm);
1617
1618             String query = Queries.getQuery().deviceInterfacesInsert().get();
1619             LOG.info("Running {} query ", query);
1620             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1621                 for (int j = 0; j < parameters.length; j++) {
1622                     stmt.setObject(j + 1, parameters[j]);
1623                 }
1624                 stmt.execute();
1625                 stmt.clearParameters();
1626             } catch (SQLException e) {
1627                 LOG.error("Something wrong when storing devices interface tcm", e);
1628             }
1629         }
1630     }
1631
1632     private void persistDevInterfaceOtnOduTxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1633         Connection connection) {
1634         @Nullable
1635         Map<TxMsiKey, TxMsi> txMsi2Map = oduBuilder.getOpu().getMsi().getTxMsi();
1636         if (txMsi2Map == null) {
1637             LOG.error("Null txMsi2Map for node {}", nodeId);
1638             return;
1639         }
1640         for (Map.Entry<TxMsiKey, TxMsi> entry : txMsi2Map.entrySet()) {
1641             TxMsi txMsi = entry.getValue();
1642             Object[] parameters = prepareDevInterfaceOtnOduTxMsiParameters(nodeId, interfaceName, txMsi);
1643
1644             String query = Queries.getQuery().deviceInterfaceOtnOduTxMsiInsert().get();
1645             LOG.info("Running {} query ", query);
1646             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1647                 for (int j = 0; j < parameters.length; j++) {
1648                     stmt.setObject(j + 1, parameters[j]);
1649                 }
1650                 stmt.execute();
1651                 stmt.clearParameters();
1652             } catch (SQLException e) {
1653                 LOG.error("Something wrong when storing devices interface OTN ODU Tx MSI", e);
1654             }
1655         }
1656     }
1657
1658
1659     private void persistDevInterfaceOtnOduRxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1660         Connection connection) {
1661         @Nullable
1662         Map<RxMsiKey, RxMsi> rxMsi2Map = oduBuilder.getOpu().getMsi().getRxMsi();
1663         if (rxMsi2Map == null) {
1664             LOG.error("Null rxMsi2Map for node {}", nodeId);
1665             return;
1666         }
1667         for (Map.Entry<RxMsiKey, RxMsi> entry : rxMsi2Map.entrySet()) {
1668             RxMsi rxMsi = entry.getValue();
1669
1670             Object[] parameters = prepareDevInterfaceOtnOduRxMsiParameters(nodeId, interfaceName, rxMsi);
1671
1672             String query = Queries.getQuery().deviceInterfaceOtnOduRxMsiInsert().get();
1673             LOG.info("Running {} query ", query);
1674             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1675                 for (int j = 0; j < parameters.length; j++) {
1676                     stmt.setObject(j + 1, parameters[j]);
1677                 }
1678                 stmt.execute();
1679                 stmt.clearParameters();
1680             } catch (SQLException e) {
1681                 LOG.error("Something wrong when storing devices interface OTN ODU Rx MSI", e);
1682             }
1683         }
1684     }
1685
1686
1687     private void persistDevInterfaceOtnOduExpMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1688         Connection connection) {
1689         @Nullable
1690         Map<ExpMsiKey, ExpMsi> expMsi2Map = oduBuilder.getOpu().getMsi().getExpMsi();
1691         if (expMsi2Map == null) {
1692             LOG.error("Null expMsi2Map for node {}", nodeId);
1693             return;
1694         }
1695         for (Map.Entry<ExpMsiKey, ExpMsi> entry : expMsi2Map.entrySet()) {
1696             ExpMsi expMsi = entry.getValue();
1697
1698             Object[] parameters = prepareDevInterfaceOtnOduExpMsiParameters(nodeId, interfaceName, expMsi);
1699
1700             String query = Queries.getQuery().deviceInterfaceOtnOduExpMsiInsert().get();
1701             LOG.info("Running {} query ", query);
1702             try (PreparedStatement stmt = connection.prepareStatement(query)) {
1703                 for (int j = 0; j < parameters.length; j++) {
1704                     stmt.setObject(j + 1, parameters[j]);
1705                 }
1706                 stmt.execute();
1707                 stmt.clearParameters();
1708             } catch (SQLException e) {
1709                 LOG.error("Something wrong when storing devices interface OTN ODU Exp MSI", e);
1710             }
1711         }
1712     }
1713
1714
1715 }