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