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