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