2 * Copyright © 2016 AT&T and others. All rights reserved.
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
8 package org.opendaylight.transportpce.inventory;
10 import static java.util.Objects.requireNonNull;
11 import static org.opendaylight.transportpce.inventory.utils.StringUtils.getCurrentTimestamp;
12 import static org.opendaylight.transportpce.inventory.utils.StringUtils.prepareDashString;
13 import static org.opendaylight.transportpce.inventory.utils.StringUtils.prepareEmptyString;
15 import java.sql.Connection;
16 import java.sql.PreparedStatement;
17 import java.sql.ResultSet;
18 import java.sql.SQLException;
20 import java.util.Optional;
21 import java.util.concurrent.ExecutionException;
22 import javax.sql.DataSource;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.transportpce.common.Timeouts;
27 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
28 import org.opendaylight.transportpce.inventory.query.Queries;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceData;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.CpSlots;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.CpSlotsKey;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPorts;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPortsKey;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLink;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLinkKey;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceKey;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLink;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLinkKey;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMapKey;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.DegreeKey;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnections;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLink;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLinkKey;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.Slots;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.SlotsKey;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.Shelves;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.ShelvesKey;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.Interface1;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.ethernet.container.EthernetBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfig;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfigKey;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfName;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfNameKey;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.och.container.OchBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.OtsBuilder;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.Tcm;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.TcmKey;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.container.OduBuilder;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsi;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsiKey;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsi;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsiKey;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsi;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsiKey;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.otu.container.OtuBuilder;
78 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
79 import org.slf4j.Logger;
80 import org.slf4j.LoggerFactory;
82 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
83 value = "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING",
84 justification = "TODO review the SQL statement generation process")
85 public class INode221 {
86 private static final Logger LOG = LoggerFactory.getLogger(INode221.class);
88 private final DataSource dataSource;
89 private final DeviceTransactionManager deviceTransactionManager;
91 public INode221(DataSource dataSource, DeviceTransactionManager deviceTransactionManager) {
92 this.dataSource = dataSource;
93 this.deviceTransactionManager = deviceTransactionManager;
96 public boolean addNode(String deviceId) {
98 InstanceIdentifier<Info> infoIID = InstanceIdentifier
99 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
102 Optional<Info> infoOpt =
103 deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.OPERATIONAL, infoIID,
104 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
106 if (infoOpt.isPresent()) {
107 deviceInfo = infoOpt.get();
109 LOG.warn("Could not get device info from DataBroker");
112 boolean sqlResult = false;
113 String query = Queries.getQuery().deviceInfoInsert().get();
114 LOG.info("Running {} query ", query);
115 try (Connection connection = dataSource.getConnection();
116 PreparedStatement preparedStatement = connection.prepareStatement(query)) {
117 Object[] prepareParameters = prepareDeviceInfoParameters(deviceInfo);
118 for (int i = 0; i < prepareParameters.length; i++) {
119 LOG.debug("Parameter {} has value {}", i + 1, prepareParameters[i]);
120 preparedStatement.setObject(i + 1, prepareParameters[i]);
123 int executeUpdate = preparedStatement.executeUpdate();
124 LOG.info("{} entries were added", executeUpdate);
127 LOG.info("iNode AddNode call complete");
128 getRoadmShelves(deviceId);
129 LOG.info("iNode getRoadmShelves call complete");
130 getCircuitPacks(deviceId);
131 LOG.debug("iNode getCircuitPacks call complete");
133 LOG.debug("iNode persist interfaces call");
134 persistDevInterfaces(deviceId, connection);
135 LOG.debug("iNode persist interfaces call complete");
137 LOG.debug("iNode persist interfaces call");
138 persistDevInterfaces(deviceId, connection);
139 LOG.debug("iNode persist interfaces call complete");
141 LOG.debug("iNode persist protocols call");
142 persistDevProtocols(deviceId, connection);
143 LOG.debug("iNode persist protocols call complete");
145 // LOG.debug("iNode persist wavelength map call");
146 // persistDevWavelengthMap(deviceId, connection);
147 // LOG.debug("iNode persist wavelength map call complete");
149 LOG.debug("iNode persist internal links map call");
150 persistDevInternalLinks(deviceId, connection);
151 LOG.debug("iNode persist internal links map call complete");
153 LOG.debug("iNode persist Physical links map call");
154 persistDevPhysicalLinks(deviceId, connection);
155 LOG.debug("iNode persist Physical links map call complete");
157 LOG.debug("iNode persist External links map call");
158 persistDevExternalLinks(deviceId, connection);
159 LOG.debug("iNode persist External links map call complete");
161 LOG.debug("iNode persist degree map call");
162 persistDevDegree(deviceId, connection);
163 LOG.debug("iNode persist degree map call complete");
165 LOG.debug("iNode persist srg map call");
166 persistDevSrg(deviceId, connection);
167 LOG.debug("iNode persist srg map call complete");
169 LOG.debug("iNode persist Roadm Connections call");
170 persistDevRoadmConnections(deviceId, connection);
171 LOG.debug("iNode persist Roadm Connections call complete");
173 LOG.debug("iNode persist Connection Map call");
174 persistDevConnectionMap(deviceId, connection);
175 LOG.debug("iNode persist Connection Map call complete");
177 } catch (SQLException | InterruptedException | ExecutionException e) {
178 LOG.error("Something wrong when storing node into DB", e);
183 public boolean nodeExists(String nodeId) {
184 String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?";
186 LOG.info("Checking if {} exists in DB", nodeId);
187 try (Connection connection = dataSource.getConnection();
188 PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) {
189 preparedStmt.setString(1, nodeId);
190 try (ResultSet rs = preparedStmt.executeQuery()) {
192 nodeExists = rs.getInt("node_exists");
193 LOG.debug("Found {} devices matching {}", nodeExists, nodeId);
196 } catch (SQLException e) {
197 LOG.error("Something wrong when fetching node in DB", e);
199 return nodeExists != 0;
202 public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException {
203 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
204 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
206 Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
207 LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
208 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
209 if (!deviceObject.isPresent()) {
210 LOG.error("No device found in operational datastore for nodeId {}", nodeId);
214 Map<ShelvesKey, Shelves> shelvesMap = deviceObject.get().nonnullShelves();
215 LOG.info("Shelves size {}", shelvesMap.size());
216 try (Connection connection = requireNonNull(dataSource.getConnection())) {
217 for (Map.Entry<ShelvesKey, Shelves> entry : shelvesMap.entrySet()) {
218 Shelves shelve = entry.getValue();
219 String shelfName = shelve.getShelfName();
221 LOG.info("Getting Shelve Details of {}", shelfName);
222 if (shelve.getSlots() != null) {
223 LOG.info("Slot Size {} ", shelve.getSlots().size());
224 persistShelveSlots(nodeId, shelve, connection);
226 LOG.info("No Slots for shelf {}", shelfName);
230 persistShelves(nodeId, connection, shelve);
232 } catch (SQLException e1) {
233 LOG.error("Something wrong when fetching ROADM shelves in DB", e1);
237 public void getCircuitPacks(String nodeId) throws InterruptedException, ExecutionException {
238 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
239 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
241 Optional<OrgOpenroadmDevice> deviceObject =
242 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
243 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
244 if (!deviceObject.isPresent()) {
245 LOG.warn("Device object {} was not found", nodeId);
249 Map<CircuitPacksKey, CircuitPacks> circuitPacksMap = deviceObject.get().nonnullCircuitPacks();
250 LOG.info("Circuit pack size {}", circuitPacksMap.size());
252 try (Connection connection = requireNonNull(dataSource.getConnection())) {
254 for (Map.Entry<CircuitPacksKey, CircuitPacks> entry : circuitPacksMap.entrySet()) {
255 CircuitPacks cp = entry.getValue();
257 if (cp.getCpSlots() != null) {
258 persistCircuitPacksSlots(nodeId, cp, connection);
260 LOG.info("Everything {}", cp);
261 LOG.info("CP is {}", cp);
263 persistPorts(cp, connection);
265 persistCircuitPacks(nodeId, connection, cp);
267 } catch (SQLException e1) {
268 LOG.error("Something wrong when fetching Circuit Packs in DB", e1);
272 private void persistCircuitPacks(String nodeId, Connection connection, CircuitPacks cp) {
273 Object[] parameters = prepareCircuitPacksParameters(nodeId, cp);
274 String query = Queries.getQuery().deviceCircuitPackInsert().get();
275 LOG.info("Running {} query ", query);
276 try (PreparedStatement stmt = connection.prepareStatement(query)) {
277 for (int j = 0; j < parameters.length; j++) {
278 stmt.setObject(j + 1, parameters[j]);
281 stmt.clearParameters();
282 } catch (SQLException e) {
283 LOG.error("Something wrong when storing Circuit Packs in DB", e);
287 private void persistShelves(String nodeId, Connection connection, Shelves shelve) {
288 Object[] shelvesParameter = prepareShelvesParameters(nodeId, shelve);
289 String query = Queries.getQuery().deviceShelfInsert().get();
290 LOG.info("Running {} query ", query);
291 try (PreparedStatement preparedStmt = connection.prepareStatement(query)) {
292 for (int j = 0; j < shelvesParameter.length; j++) {
293 preparedStmt.setObject(j + 1, shelvesParameter[j]);
295 preparedStmt.execute();
296 preparedStmt.clearParameters();
297 } catch (SQLException e) {
298 LOG.error("Something wrong when storing shelves in DB", e);
302 private void persistShelveSlots(String nodeId, Shelves shelves, Connection connection) {
303 String startTimetampStr = getCurrentTimestamp();
305 Map<SlotsKey, Slots> slotsMap = shelves.nonnullSlots();
306 for (Map.Entry<SlotsKey, Slots> entry : slotsMap.entrySet()) {
307 Slots slot = entry.getValue();
308 LOG.info("Getting Slot Details of {}", slot.getSlotName());
309 Object[] parameters = new Object[]{nodeId,
310 shelves.getShelfName(),
313 slot.getProvisionedCircuitPack(),
317 String query = Queries.getQuery().deviceShelfSlotInsert().get();
318 LOG.info("Running {} query ", query);
319 try (PreparedStatement stmt = connection.prepareStatement(query)) {
320 for (int j = 0; j < parameters.length; j++) {
321 stmt.setObject(j + 1, parameters[j]);
324 stmt.clearParameters();
325 } catch (SQLException e) {
326 LOG.error("Something wrong when storing shelves slots in DB", e);
332 private void persistCircuitPacksSlots(String nodeId, CircuitPacks circuitPacks, Connection connection) {
333 String startTimetampStr = getCurrentTimestamp();
335 Map<CpSlotsKey, CpSlots> cpSlotsMap = circuitPacks.nonnullCpSlots();
336 for (Map.Entry<CpSlotsKey, CpSlots> entry : cpSlotsMap.entrySet()) {
337 CpSlots cpSlot = entry.getValue();
339 Object[] parameters = new Object[]{nodeId,
340 circuitPacks.getCircuitPackName(),
341 cpSlot.getSlotName(),
343 cpSlot.getProvisionedCircuitPack(),
347 String query = Queries.getQuery().deviceCPSlotInsert().get();
348 LOG.info("Running {} query ", query);
349 try (PreparedStatement stmt = connection.prepareStatement(query)) {
350 for (int j = 0; j < parameters.length; j++) {
351 stmt.setObject(j + 1, parameters[j]);
354 stmt.clearParameters();
355 } catch (SQLException e) {
356 LOG.error("Something wrong when storing Cirtcuits Packs slots in DB", e);
361 private void persistPorts(CircuitPacks circuitPacks, Connection connection) {
362 LOG.warn("Ports are not persisted yet");
367 * Prepares parameters for device insert query.
369 * @param deviceInfo device info
370 * @return Object Object
372 private static Object[] prepareDeviceInfoParameters(Info deviceInfo) {
373 String startTimetampStr = getCurrentTimestamp();
374 //Integer maxNumBin15minHistoricalPm = null;
375 //Integer maxNumBin24hourHistoricalPm = null;
376 //String serialId = "";
378 String nodeId = prepareDashString(deviceInfo.getNodeId());
379 Long nodeNumber = deviceInfo.getNodeNumber().toJava();
380 Integer nodeTypeEnu = deviceInfo.getNodeType().getIntValue();
381 String clli = prepareDashString(deviceInfo.getClli());
382 String vendor = prepareDashString(deviceInfo.getVendor());
383 String model = prepareDashString(deviceInfo.getModel());
384 String ipAddress = prepareDashString(deviceInfo.getIpAddress().getIpv4Address().getValue());
385 String prefixLength = prepareDashString(deviceInfo.getPrefixLength());
386 String defaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue());
387 Integer sourceEnum = deviceInfo.getSource().getIntValue();
388 String currentIpAddress = prepareDashString(deviceInfo.getCurrentIpAddress().getIpv4Address().getValue());
389 String currentPrefixLength = prepareDashString(deviceInfo.getCurrentPrefixLength());
390 String currentDefaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue());
391 String macAddress = prepareDashString(deviceInfo.getMacAddress().getValue());
392 String softwareVersion = prepareDashString(deviceInfo.getSoftwareVersion());
393 String openroadmVersion = "2.2.1";
394 String template = prepareDashString(deviceInfo.getTemplate());
395 String currentDatetime = prepareDashString(deviceInfo.getCurrentDatetime().getValue());
397 (deviceInfo.getGeoLocation() != null ? prepareDashString(deviceInfo.getGeoLocation().getLatitude()) : "");
398 String geoLongitude =
399 (deviceInfo.getGeoLocation() != null ? prepareDashString(deviceInfo.getGeoLocation().getLongitude()) : "");
400 String maxDegrees = prepareDashString(deviceInfo.getMaxDegrees()); // max_degrees
401 String maxSrgs = prepareDashString(deviceInfo.getMaxSrgs()); //max_srgs
402 String swVersion = prepareDashString(deviceInfo.getSoftwareVersion()); //sw_version
403 String swValidationTimer = prepareDashString(""); //sw_validation_timer
404 String activationDateTime = prepareDashString(""); //activation_date_time
405 /*jsonDevInfo = JsonStringBuilder.getDevInfoJson().replace("$$NODE-ID$$",nodeId)
406 .replace("$$NODE-NUMBER$$", nodeNumber)
407 .replace("$$NODE-TYPE$$",nodeType)
408 .replace("$$CLLI$$",clli)
409 .replace("$$VENDOR$$",vendor)
410 .replace("$$MODEL$$",model)
411 .replace("$$SERIAL-ID$$",serialId)
412 .replace("$$IPADDRESS$$",ipAddress)
413 .replace("$$PREFIX-LENGTH$$",prefixLength)
414 .replace("$$DEFAULTGATEWAY$$",defaultGateway)
415 .replace("$$SOURCE$$",String.valueOf(source))
416 .replace("$$CURRENT-IPADDRESS$$",currentIpAddress)
417 .replace("$$CURRENT-PREFIX-LENGTH$$",currentPrefixLength)
418 .replace("$$CURRENT-DEFAULTGATEWAY$$",currentDefailtGateway)
419 .replace("$$MACADDRESS$$",macAddress)
420 .replace("$$SOFTWAREVERSION$$",softwareVersion)
421 .replace("$$OPENROADM-VERSION$$",openroadmVersion)
422 .replace("$$TEMPLATE$$",template)
423 .replace("$$CURRENT-DATETIME$$",currentDatetime)
424 .replace("$$LATITUDE$$",latitude)
425 .replace("$$LONGITUDE$$",longitude)
426 .replace("$$MAX-DEGREES$$",maxDegrees)
427 .replace("$$MAX-SRGS$$",maxSrgs)
428 .replace("$$MAX-NUM-BIN-15MIN-HISTORICAL-PM$$",prepareDashString(""))
429 .replace("$$MAX-NUM-BIN-24HOUR-HISTORICAL-PM$$",prepareDashString(""))
430 .replace("$$SW-VERSION$$",swVersion)
431 .replace("$$SW-VALIDATION-TIMER$$",swValidationTimer)
432 .replace("$$ACTIVATION-DATE-TIME$$",activationDateTime);*/
450 currentDefaultGateway,
460 //maxNumBin15minHistoricalPm,
461 //maxNumBin24hourHistoricalPm,
472 private static Object[] prepareShelvesParameters(String nodeId, Shelves shelve) {
473 String startTimestamp = getCurrentTimestamp();
475 return new Object[]{nodeId,
476 shelve.getShelfName(),
477 shelve.getShelfType(),
479 shelve.getShelfPosition(),
480 (shelve.getAdministrativeState() == null ? null : shelve.getAdministrativeState().getIntValue()),
483 shelve.getSerialId(),
485 shelve.getProductCode(),
486 (shelve.getManufactureDate() == null ? null : shelve.getManufactureDate().getValue()),
488 shelve.getHardwareVersion(),
489 (shelve.getOperationalState() == null ? null : shelve.getOperationalState().getIntValue()),
490 (shelve.getEquipmentState() == null ? null : shelve.getEquipmentState().getIntValue()),
491 (shelve.getDueDate() == null ? null : shelve.getDueDate().getValue()),
496 private static Object[] prepareCircuitPacksParameters(String nodeId, CircuitPacks cpack) {
497 String startTimestamp = getCurrentTimestamp();
498 return new Object[]{nodeId,
499 cpack.getCircuitPackName(),
500 cpack.getCircuitPackType(),
501 cpack.getCircuitPackProductCode(),
502 (cpack.getAdministrativeState() == null ? "" : cpack.getAdministrativeState().getIntValue()),
507 cpack.getProductCode(),
508 (cpack.getManufactureDate() == null ? "" : cpack.getManufactureDate().getValue()),
510 cpack.getHardwareVersion(),
511 prepareEmptyString(cpack.getOperationalState().getIntValue()),
512 cpack.getCircuitPackCategory().getType().getName(),
513 cpack.getCircuitPackCategory().getExtension(),
514 (cpack.getEquipmentState() == null ? "" : cpack.getEquipmentState().getIntValue()),
515 cpack.getCircuitPackMode(),
519 prepareEmptyString(cpack.getDueDate()),
520 prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" :
521 ((cpack.getParentCircuitPack().getCircuitPackName() == null) ? "" :
522 cpack.getParentCircuitPack().getCircuitPackName())
524 prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" :
525 ((cpack.getParentCircuitPack().getCpSlotName() == null) ? "" :
526 cpack.getParentCircuitPack().getCpSlotName())
532 private Object[] prepareDevInterfaceParameters(String nodeId, Interface deviceInterface, Connection connection) {
534 int administrativeStateEnu = deviceInterface.getAdministrativeState().getIntValue();
535 int operationalState = deviceInterface.getOperationalState().getIntValue();
536 int ethernetDuplexEnu = -1;
537 int ethernetAutoNegotiationEnu = -1;
538 int maintTestsignalTestpatternEnu = -1;
539 int maintTestsignalTypeEnu = -1;
541 int otuMaintTypeEnu = -1;
542 //int otsFiberTypeEnu = -1;
543 String name = deviceInterface.getName();
544 String description = deviceInterface.getDescription();
545 String type = deviceInterface.getType().getTypeName();
546 String circuitId = deviceInterface.getCircuitId();
547 String supportingInterface = deviceInterface.getSupportingInterface();
548 String supportingCircuitPackName = deviceInterface.getSupportingCircuitPackName();
549 String supportingPort = deviceInterface.getSupportingPort();
550 String ethernetSpeed = "";
551 String ethernetFec = "";
552 String ethernetMtu = "";
553 String ethernetCurrSpeed = "";
554 String ethernetCurrDuplex = "";
555 //String mciMcttpMinFreq = "";
556 //String mciMcttpMaxFreq = "";
557 //String mciMcttpCenterFreq = "";
558 //String mciMcttpSlotWidth = "";
559 //String mciNmcCtpFrequency = "";
560 //String mciNmcCtpWidth = "";
562 //String ochFrequency = "";
563 //String ochWidth = "";
564 //String ochWavelengthNumber = "";
565 String ochModulationFormat = "";
566 String ochTransmitPower = "";
567 String otsSpanLossReceive = "";
568 String otsSpanLossTransmit = "";
569 //String otsIngressSpanLossAgingMargin = "";
570 //String otsEolMaxLoadPin = "";
571 String oduRate = ""; //BUG in following case switch statement ???
572 //String oduFunction = "";
573 String oduMonitoringMode = "";
574 //String oduNoOamFunction = "";
575 String oduProactiveDelayMeasurementEnabled = "";
576 //String oduPoaTribPortNumber = "";
577 //String oduTxSapi = "";
578 //String oduTxDapi = "";
579 //String oduTxOperator = "";
580 //String oduAcceptedSapi = "";
581 //String oduAcceptedDapi = "";
582 //String oduAcceptedOperator = "";
583 //String oduExpectedSapi = "";
584 //String oduExpectedDapi = "";
585 //String oduTimActEnabled = "";
586 //String oduTimDetectMode = "";
587 //String oduDegmIntervals = "";
588 //String oduDegthrPercentage = "";
589 String opuPayloadType = "";
590 String opuRxPayloadType = "";
591 String opuExpPayloadType = "";
592 String opuPayloadInterface = "";
593 String maintTestsignalEnabled = "";
594 String maintTestsignalBiterrors = "";
595 String maintTestsignalBiterrorsterminal = "";
596 String maintTestsignalSyncseconds = "";
597 String maintTestsignalSyncsecondsterminal = "";
599 //String otuTxSapi = "";
600 //String otuTxDapi = "";
601 //String otuTxOperator = "";
602 //String otuAcceptedSapi = "";
603 //String otuAcceptedDapi = "";
604 //String otuAcceptedOperator = "";
605 //String otuExpectedSapi = "";
606 //String otuExpectedDapi = "";
607 //String otuTimActEnabled = "";
608 //String otuTimDetectMode = "";
609 //String otuDegmIntervals = "";
610 //String otuDegthrPercentage = "";
611 String otuMaintLoopbackEnabled = "";
612 //String mtOtuRate = "";
613 //String mtOtuFec = "";
614 //String mtOtuMaintLoopback = "";
615 //String mtOtuEnabled = "";
616 //String mtOtuType = "";
618 switch (deviceInterface.getType().toString()) {
621 //EthernetBuilder ethIfBuilder = new EthernetBuilder();
622 EthernetBuilder ethIfBuilder =
623 new EthernetBuilder(deviceInterface.augmentation(Interface1.class).getEthernet());
624 ethernetSpeed = ethIfBuilder.getSpeed().toString();
625 ethernetFec = ethIfBuilder.getFec().getName();
626 ethernetDuplexEnu = ethIfBuilder.getDuplex().getIntValue();
627 ethernetMtu = ethIfBuilder.getMtu().toString();
628 ethernetAutoNegotiationEnu = ethIfBuilder.getAutoNegotiation().getIntValue();
629 ethernetCurrSpeed = ethIfBuilder.getCurrSpeed();
630 ethernetCurrDuplex = ethIfBuilder.getCurrDuplex();
634 OchBuilder ochIfBuilder = new OchBuilder(deviceInterface.augmentation(
635 org.opendaylight.yang.gen.v1
636 .http.org.openroadm.optical.channel.interfaces.rev161014.Interface1.class)
638 ochRate = ochIfBuilder.getRate().getName();
639 //ochWavelengthNumber = ochIfBuilder.getWavelengthNumber().toString();
640 ochModulationFormat = ochIfBuilder.getModulationFormat().getName();
641 ochTransmitPower = ochIfBuilder.getTransmitPower().toString();
645 OtsBuilder otsIfBuilder = new OtsBuilder(deviceInterface.augmentation(
646 org.opendaylight.yang.gen.v1
647 .http.org.openroadm.optical.transport.interfaces.rev161014.Interface1.class)
649 //otsFiberTypeEnu = otsIfBuilder.getFiberType().getIntValue();
650 otsSpanLossReceive = otsIfBuilder.getSpanLossReceive().toString();
651 otsSpanLossTransmit = otsIfBuilder.getSpanLossTransmit().toString();
655 OduBuilder oduIfBuilder = new OduBuilder(deviceInterface.augmentation(
656 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.Interface1.class)
658 oduRate = String.valueOf(oduIfBuilder.getRate());
659 oduMonitoringMode = oduIfBuilder.getMonitoringMode().getName();
660 oduProactiveDelayMeasurementEnabled = oduIfBuilder.getProactiveDelayMeasurementEnabled().toString();
662 persistDevInterfaceTcm(nodeId, name, oduIfBuilder, connection);
663 persistDevInterfaceOtnOduTxMsi(nodeId, name, oduIfBuilder, connection);
664 persistDevInterfaceOtnOduRxMsi(nodeId, name, oduIfBuilder, connection);
665 persistDevInterfaceOtnOduExpMsi(nodeId, name, oduIfBuilder, connection);
667 opuPayloadType = oduIfBuilder.getOpu().getPayloadType();
668 opuRxPayloadType = oduIfBuilder.getOpu().getRxPayloadType();
669 opuExpPayloadType = oduIfBuilder.getOpu().getExpPayloadType();
670 opuPayloadInterface = oduIfBuilder.getOpu().getPayloadInterface();
671 /*persistDevInterfaceOtnOduTxMsi(nodeId,name,oduIfBuilder,connection);
672 persistDevInterfaceOtnOduRxMsi(nodeId,name,oduIfBuilder,connection);
673 persistDevInterfaceOtnOduExpMsi(nodeId,name,oduIfBuilder,connection); */
674 maintTestsignalEnabled = oduIfBuilder.getMaintTestsignal().getEnabled().toString();
675 maintTestsignalTestpatternEnu = oduIfBuilder.getMaintTestsignal().getTestPattern().getIntValue();
676 maintTestsignalTypeEnu = oduIfBuilder.getMaintTestsignal().getType().getIntValue();
677 maintTestsignalBiterrors = oduIfBuilder.getMaintTestsignal().getBitErrors().toString();
678 maintTestsignalBiterrorsterminal = oduIfBuilder.getMaintTestsignal().getBitErrorsTerminal().toString();
679 maintTestsignalSyncseconds = oduIfBuilder.getMaintTestsignal().getSyncSeconds();
680 maintTestsignalSyncsecondsterminal = oduIfBuilder.getMaintTestsignal().getSyncSecondsTerminal();
684 OtuBuilder otuIfBuilder = new OtuBuilder(deviceInterface.augmentation(
685 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.Interface1.class)
687 otuRate = otuIfBuilder.getRate().getName();
688 otuFecEnu = otuIfBuilder.getFec().getIntValue();
689 otuMaintLoopbackEnabled = otuIfBuilder.getMaintLoopback().getEnabled().toString();
690 otuMaintTypeEnu = otuIfBuilder.getMaintLoopback().getType().getIntValue();
694 LOG.error("Could not get interface type");
697 String startTimestamp = getCurrentTimestamp();
699 return new Object[]{nodeId,
703 Integer.toString(administrativeStateEnu),
704 Integer.toString(operationalState),
707 supportingCircuitPackName,
711 Integer.toString(ethernetDuplexEnu),
713 Integer.toString(ethernetAutoNegotiationEnu),
718 //mciMcttpCenterFreq,
720 //mciNmcCtpFrequency,
722 "", "", "", "", "", "",
726 //ochWavelengthNumber,
730 //Integer.toString(otsFiberTypeEnu),
734 //otsIngressSpanLossAgingMargin,
743 oduProactiveDelayMeasurementEnabled,
744 //oduPoaTribPortNumber,
750 //oduAcceptedOperator,
756 //oduDegthrPercentage,
757 "", "", "", "", "", "", "", "", "", "", "", "", "",
762 maintTestsignalEnabled,
763 Integer.toString(maintTestsignalTestpatternEnu),
764 Integer.toString(maintTestsignalTypeEnu),
765 maintTestsignalBiterrors,
766 maintTestsignalBiterrorsterminal,
767 maintTestsignalSyncseconds,
768 maintTestsignalSyncsecondsterminal,
770 Integer.toString(otuFecEnu),
776 //otuAcceptedOperator,
782 //otuDegthrPercentage,
783 "", "", "", "", "", "", "", "", "", "", "", "",
784 otuMaintLoopbackEnabled,
785 Integer.toString(otuMaintTypeEnu),
788 //mtOtuMaintLoopback,
798 private static Object[] prepareDevInterfaceTcmParameters(String nodeId, String interfaceName, Tcm tcm) {
801 String layer = tcm.getLayer().toString();
802 int monitoringModeEnu = tcm.getMonitoringMode().getIntValue();
803 String ltcActEnabled = tcm.getLtcActEnabled().toString();
804 String proactiveDelayMeasurementEnabled = tcm.getProactiveDelayMeasurementEnabled().toString();
805 //int tcmDirectionEnu = -1;
806 //int timDetectModeEnu = -1;
807 //String txSapi = "";
808 //String txDapi = "";
809 //String txOperator = "";
810 //String acceptedSapi = "";
811 //String acceptedDapi = "";
812 //String acceptedOperator = "";
813 //String expectedSapi = "";
814 //String expectedDapi = "";
815 //String timActEnabled = "";
816 //String degmIntervals = "";
817 //String degthrPercentage = "";
819 String startTimestamp = getCurrentTimestamp();
821 return new Object[]{nodeId,
824 Integer.toString(monitoringModeEnu),
826 proactiveDelayMeasurementEnabled,
827 //Integer.toString(tcmDirectionEnu),
838 "", "", "", "", "", "", "", "", "",
839 //Integer.toString(timDetectModeEnu),
849 private static Object[] prepareDevInterfaceOtnOduTxMsiParameters(String nodeId, String interfaceName, TxMsi txMsi) {
851 String tribSlot = txMsi.getTribSlot().toString();
852 String odtuType = txMsi.getOdtuType().getTypeName();
853 String tribPort = txMsi.getTribPort().toString();
854 String tribPortPayload = txMsi.getTribPortPayload();
856 String startTimestamp = getCurrentTimestamp();
858 return new Object[]{nodeId,
870 private static Object[] prepareDevInterfaceOtnOduRxMsiParameters(String nodeId, String interfaceName, RxMsi rxMsi) {
872 String tribSlot = rxMsi.getTribSlot().toString();
873 String odtuType = rxMsi.getOdtuType().getTypeName();
874 String tribPort = rxMsi.getTribPort().toString();
875 String tribPortPayload = rxMsi.getTribPortPayload();
877 String startTimestamp = getCurrentTimestamp();
879 return new Object[]{nodeId,
892 private static Object[] prepareDevInterfaceOtnOduExpMsiParameters(String nodeId, String interfaceName,
895 String tribSlot = expMsi.getTribSlot().toString();
896 String odtuType = expMsi.getOdtuType().getTypeName();
897 String tribPort = expMsi.getTribPort().toString();
898 String tribPortPayload = expMsi.getTribPortPayload();
900 String startTimestamp = getCurrentTimestamp();
902 return new Object[]{nodeId,
914 private void persistDevInterfaces(String nodeId, Connection connection) {
916 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
917 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
919 Optional<OrgOpenroadmDevice> deviceObject =
920 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
921 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
923 /*InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
924 .child(Interface.class);
925 Optional<Interface> interfaceOpt =
926 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, interfaceIID,
927 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); */
930 Map<InterfaceKey, Interface> interfaceMap = deviceObject.get().nonnullInterface();
931 for (Map.Entry<InterfaceKey, Interface> entry : interfaceMap.entrySet()) {
932 Interface deviceInterface;
934 deviceInterface = entry.getValue();
935 /*if (interfaceOpt.isPresent()) {
936 deviceInterface = interfaceOpt.get();
938 LOG.warn("Could not get interface info");
941 Object[] parameters = prepareDevInterfaceParameters(nodeId, deviceInterface, connection);
943 String query = Queries.getQuery().deviceInterfacesInsert().get();
944 LOG.info("Running {} query ", query);
945 try (PreparedStatement stmt = connection.prepareStatement(query)) {
946 for (int j = 0; j < parameters.length; j++) {
947 stmt.setObject(j + 1, parameters[j]);
950 stmt.clearParameters();
951 } catch (SQLException e) {
952 LOG.error("Something wrong when storing devices interfaces in DB", e);
957 private void persistDevProtocols(String nodeId, Connection connection) {
959 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier
960 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
961 .child(Protocols.class)
963 Optional<Protocols> protocolObject =
964 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
965 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
966 if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
967 LOG.error("LLDP subtree is missing");
971 protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig().getAdminStatus()
973 String msgTxtInterval =
974 protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig().getMsgTxInterval()
976 String mxgTxHoldMultiplier =
977 protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig().getMsgTxHoldMultiplier()
979 String startTimestamp = getCurrentTimestamp();
980 persistDevProtocolLldpPortConfig(nodeId, connection);
981 persistDevProtocolLldpNbrList(nodeId, connection);
983 Object[] parameters = {nodeId,
984 Integer.toString(adminstatusEnu),
991 String query = Queries.getQuery().deviceProtocolInsert().get();
992 LOG.info("Running {} query ", query);
993 try (PreparedStatement stmt = connection.prepareStatement(query)) {
994 for (int j = 0; j < parameters.length; j++) {
995 stmt.setObject(j + 1, parameters[j]);
998 stmt.clearParameters();
999 } catch (SQLException e) {
1000 LOG.error("Something wrong when storing devices protocols in DB", e);
1006 private void persistDevProtocolLldpPortConfig(String nodeId, Connection connection) {
1008 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier
1009 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1010 .child(Protocols.class)
1012 Optional<Protocols> protocolObject =
1013 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1014 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1015 if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
1016 LOG.error("LLDP subtree is missing");
1019 String startTimestamp = getCurrentTimestamp();
1021 Map<PortConfigKey, PortConfig> portConfigMap = protocolObject.get()
1022 .augmentation(Protocols1.class).getLldp().nonnullPortConfig();
1023 for (Map.Entry<PortConfigKey, PortConfig> entry : portConfigMap.entrySet()) {
1025 PortConfig portConfig = entry.getValue();
1026 String ifName = portConfig.getIfName();
1027 int adminStatusEnu = portConfig.getAdminStatus().getIntValue();
1029 Object[] parameters = {nodeId,
1031 Integer.toString(adminStatusEnu),
1036 String query = Queries.getQuery().deviceProtocolPortConfigInsert().get();
1037 LOG.info("Running {} query ", query);
1038 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1039 for (int j = 0; j < parameters.length; j++) {
1040 stmt.setObject(j + 1, parameters[j]);
1043 stmt.clearParameters();
1044 } catch (SQLException e) {
1045 LOG.error("Something wrong when storing devices protocols LLDP Port config in DB", e);
1052 private void persistDevProtocolLldpNbrList(String nodeId, Connection connection) {
1054 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier
1055 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1056 .child(Protocols.class)
1058 Optional<Protocols> protocolObject =
1059 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1060 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1061 if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
1062 LOG.error("LLDP subtree is missing");
1065 String startTimestamp = getCurrentTimestamp();
1067 Map<IfNameKey, IfName> ifNameMap = protocolObject.get()
1068 .augmentation(Protocols1.class).getLldp().getNbrList().nonnullIfName();
1069 for (Map.Entry<IfNameKey, IfName> entry : ifNameMap.entrySet()) {
1071 IfName ifNameObj = entry.getValue();
1072 String ifName = ifNameObj.getIfName();
1073 String remotesysname = ifNameObj.getRemoteSysName();
1074 String remotemgmtaddresssubtype = ifNameObj.getRemoteMgmtAddressSubType().getName();
1075 String remotemgmtaddress = ifNameObj.getRemoteMgmtAddress().getIpv4Address().toString();
1076 int remoteportidsubtypeEnu = ifNameObj.getRemotePortIdSubType().getIntValue();
1077 String remoteportid = ifNameObj.getRemotePortId();
1078 int remotechassisidsubtypeEnu = ifNameObj.getRemoteChassisIdSubType().getIntValue();
1079 String remotechassisid = ifNameObj.getRemoteChassisId();
1081 Object[] parameters = {nodeId,
1084 remotemgmtaddresssubtype,
1086 Integer.toString(remoteportidsubtypeEnu),
1088 Integer.toString(remotechassisidsubtypeEnu),
1094 String query = Queries.getQuery().deviceProtocolLldpNbrlistInsert().get();
1095 LOG.info("Running {} query ", query);
1096 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1097 for (int j = 0; j < parameters.length; j++) {
1098 stmt.setObject(j + 1, parameters[j]);
1101 stmt.clearParameters();
1102 } catch (SQLException e) {
1103 LOG.error("Something wrong when storing devices protocols LLDP list number in DB", e);
1109 private void persistDevInternalLinks(String nodeId, Connection connection) {
1111 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1112 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1114 Optional<OrgOpenroadmDevice> deviceObject =
1115 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1116 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1117 if (!deviceObject.isPresent()) {
1118 LOG.error("Device with node id {} not found", nodeId);
1121 String startTimestamp = getCurrentTimestamp();
1123 Map<InternalLinkKey, InternalLink> internalLinkMap = deviceObject.get().nonnullInternalLink();
1124 for (Map.Entry<InternalLinkKey, InternalLink> entry : internalLinkMap.entrySet()) {
1125 InternalLink internalLink = entry.getValue();
1126 String internalLinkName = internalLink.getInternalLinkName();
1127 String sourceCircuitPackName = internalLink.getSource().getCircuitPackName();
1128 String sourcePortName = internalLink.getSource().getPortName();
1129 String destinationCircuitPackName = internalLink.getDestination().getCircuitPackName();
1130 String destinationPortName = internalLink.getDestination().getPortName();
1132 Object[] parameters = {nodeId,
1134 sourceCircuitPackName,
1136 destinationCircuitPackName,
1137 destinationPortName,
1142 String query = Queries.getQuery().deviceInternalLinkInsert().get();
1143 LOG.info("Running {} query ", query);
1144 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1145 for (int j = 0; j < parameters.length; j++) {
1146 stmt.setObject(j + 1, parameters[j]);
1149 stmt.clearParameters();
1150 } catch (SQLException e) {
1151 LOG.error("Something wrong when storing devices internal links", e);
1158 private void persistDevExternalLinks(String nodeId, Connection connection) {
1160 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1161 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1163 Optional<OrgOpenroadmDevice> deviceObject =
1164 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1165 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1166 if (!deviceObject.isPresent()) {
1167 LOG.error("Device with node id {} not found", nodeId);
1170 String startTimestamp = getCurrentTimestamp();
1172 Map<ExternalLinkKey, ExternalLink> externalLinkMap = deviceObject.get().nonnullExternalLink();
1173 for (Map.Entry<ExternalLinkKey, ExternalLink> entry : externalLinkMap.entrySet()) {
1174 ExternalLink externalLink = entry.getValue();
1175 String externalLinkName = externalLink.getExternalLinkName();
1176 String sourceNodeId = externalLink.getSource().getNodeId();
1177 String sourceCircuitPackName = externalLink.getSource().getCircuitPackName();
1178 String sourcePortName = externalLink.getSource().getPortName();
1179 String destinationNodeId = externalLink.getDestination().getNodeId();
1180 String destinationCircuitPackName = externalLink.getDestination().getCircuitPackName();
1181 String destinationPortName = externalLink.getDestination().getPortName();
1183 Object[] parameters = {nodeId,
1186 sourceCircuitPackName,
1189 destinationCircuitPackName,
1190 destinationPortName,
1195 String query = Queries.getQuery().deviceExternalLinkInsert().get();
1196 LOG.info("Running {} query ", query);
1197 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1198 for (int j = 0; j < parameters.length; j++) {
1199 stmt.setObject(j + 1, parameters[j]);
1202 stmt.clearParameters();
1203 } catch (SQLException e) {
1204 LOG.error("Something wrong when storing devices external links", e);
1210 private void persistDevPhysicalLinks(String nodeId, Connection connection) {
1212 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1213 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1215 Optional<OrgOpenroadmDevice> deviceObject =
1216 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1217 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1218 if (!deviceObject.isPresent()) {
1219 LOG.error("Device with node id {} not found", nodeId);
1223 String startTimestamp = getCurrentTimestamp();
1225 Map<PhysicalLinkKey, PhysicalLink> physicalLinkMap = deviceObject.get().nonnullPhysicalLink();
1226 for (Map.Entry<PhysicalLinkKey, PhysicalLink> entry : physicalLinkMap.entrySet()) {
1227 PhysicalLink physicalLink = entry.getValue();
1228 String physicalLinkName = physicalLink.getPhysicalLinkName();
1229 String sourceCircuitPackName = physicalLink.getSource().getCircuitPackName();
1230 String sourcePortName = physicalLink.getSource().getPortName();
1231 String destinationCircuitPackName = physicalLink.getDestination().getCircuitPackName();
1232 String destinationPortName = physicalLink.getDestination().getPortName();
1234 Object[] parameters = {nodeId,
1236 sourceCircuitPackName,
1238 destinationCircuitPackName,
1239 destinationPortName,
1244 String query = Queries.getQuery().devicePhysicalLinkInsert().get();
1245 LOG.info("Running {} query ", query);
1246 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1247 for (int j = 0; j < parameters.length; j++) {
1248 stmt.setObject(j + 1, parameters[j]);
1251 stmt.clearParameters();
1252 } catch (SQLException e) {
1253 LOG.error("Something wrong when storing devices physical links", e);
1259 private void persistDevDegree(String nodeId, Connection connection) {
1261 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1262 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1264 Optional<OrgOpenroadmDevice> deviceObject =
1265 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1266 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1267 if (!deviceObject.isPresent()) {
1268 LOG.error("Device with node id {} not found", nodeId);
1271 String startTimestamp = getCurrentTimestamp();
1273 Map<DegreeKey, Degree> degreeMap = deviceObject.get().nonnullDegree();
1274 for (Map.Entry<DegreeKey, Degree> entry : degreeMap.entrySet()) {
1275 Degree degree = entry.getValue();
1276 String degreeNumber = degree.getDegreeNumber().toString();
1277 String maxWavelengths = degree.getMaxWavelengths().toString();
1278 String otdrPortCircuitPackName = degree.getOtdrPort().getCircuitPackName();
1279 String otdrPortPortName = degree.getOtdrPort().getPortName();
1280 persistDevDegreeCircuitPack(nodeId, degree, degreeNumber, connection);
1281 persistDevDegreeConnectionPort(nodeId, degree, degreeNumber, connection);
1282 //String mcCapabilitiesSlotWidthGranularity = "";
1283 //String mcCapabilitiesCenterFreqGranularity = "";
1284 //String mcCapabilitiesMinSlots = "";
1285 //String mcCapabilitiesMaxSlots = "";
1287 Object[] parameters = {nodeId,
1290 otdrPortCircuitPackName,
1292 //mcCapabilitiesSlotWidthGranularity,
1293 //mcCapabilitiesCenterFreqGranularity,
1294 //mcCapabilitiesMinSlots,
1295 //mcCapabilitiesMaxSlots,
1301 String query = Queries.getQuery().deviceDegreeInsert().get();
1302 LOG.info("Running {} query ", query);
1303 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1304 for (int j = 0; j < parameters.length; j++) {
1305 stmt.setObject(j + 1, parameters[j]);
1308 stmt.clearParameters();
1309 } catch (SQLException e) {
1310 LOG.error("Something wrong when storing devices degrees", e);
1317 private void persistDevDegreeCircuitPack(String nodeId, Degree degree, String degreeNumber, Connection connection) {
1319 String startTimestamp = getCurrentTimestamp();
1321 Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1322 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks>
1323 circuitPacksMap = degree.nonnullCircuitPacks();
1324 for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1325 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks> entry :
1326 circuitPacksMap.entrySet()) {
1329 String circuitPackIndex = entry.getValue().getIndex().toString();
1330 String circuitPackName = entry.getValue().getCircuitPackName();
1332 Object[] parameters = {nodeId,
1340 String query = Queries.getQuery().deviceDegreeCircuitPackInsert().get();
1341 LOG.info("Running {} query ", query);
1342 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1343 for (int j = 0; j < parameters.length; j++) {
1344 stmt.setObject(j + 1, parameters[j]);
1347 stmt.clearParameters();
1348 } catch (SQLException e) {
1349 LOG.error("Something wrong when storing devices degrees circuit packs", e);
1355 private void persistDevDegreeConnectionPort(String nodeId, Degree degree, String degreeNumber,
1356 Connection connection) {
1358 String startTimestamp = getCurrentTimestamp();
1360 Map<ConnectionPortsKey, ConnectionPorts> connectionPortsMap = degree.nonnullConnectionPorts();
1361 for (Map.Entry<ConnectionPortsKey, ConnectionPorts> entry : connectionPortsMap.entrySet()) {
1363 ConnectionPorts connectionPorts = entry.getValue();
1364 String connectionPortIndex = connectionPorts.getIndex().toString();
1365 String circuitPackName = connectionPorts.getCircuitPackName();
1366 String portName = connectionPorts.getPortName();
1368 Object[] parameters = {nodeId,
1370 connectionPortIndex,
1377 String query = Queries.getQuery().deviceDegreeConnectionPortInsert().get();
1378 LOG.info("Running {} query ", query);
1379 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1380 for (int j = 0; j < parameters.length; j++) {
1381 stmt.setObject(j + 1, parameters[j]);
1384 stmt.clearParameters();
1385 } catch (SQLException e) {
1386 LOG.error("Something wrong when storing devices degrees connection ports", e);
1393 private void persistDevSrg(String nodeId, Connection connection) {
1395 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1396 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1398 Optional<OrgOpenroadmDevice> deviceObject =
1399 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1400 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1401 if (!deviceObject.isPresent()) {
1402 LOG.error("Device with node id {} not found", nodeId);
1406 String startTimestamp = getCurrentTimestamp();
1408 Map<SharedRiskGroupKey, SharedRiskGroup> sharedRiskGroupMap = deviceObject.get().nonnullSharedRiskGroup();
1409 for (Map.Entry<SharedRiskGroupKey, SharedRiskGroup> entry : sharedRiskGroupMap.entrySet()) {
1410 SharedRiskGroup sharedRiskGroup = entry.getValue();
1411 String maxAddDropPorts = sharedRiskGroup.getMaxAddDropPorts().toString();
1412 String srgNumber = sharedRiskGroup.getSrgNumber().toString();
1413 //int wavelengthDuplicationEnu = sharedRiskGroup.getWavelengthDuplication().getIntValue();
1414 persistDevSrgCircuitPacks(nodeId, sharedRiskGroup, srgNumber, connection);
1415 //String currentProvisionedAddDropPorts = "";
1416 //String mcCapSlotWidthGranularity = "";
1417 //String mcCapCenterFreqGranularity = "";
1418 //String mcCapMinSlots = "";
1419 //String mcCapMaxSlots = "";
1421 Object[] parameters = {nodeId,
1423 //currentProvisionedAddDropPorts,
1426 //mcCapSlotWidthGranularity,
1427 //mcCapCenterFreqGranularity,
1435 String query = Queries.getQuery().deviceSharedRiskGroupInsert().get();
1436 LOG.info("Running {} query ", query);
1437 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1438 for (int j = 0; j < parameters.length; j++) {
1439 stmt.setObject(j + 1, parameters[j]);
1442 stmt.clearParameters();
1443 } catch (SQLException e) {
1444 LOG.error("Something wrong when storing devices SRG", e);
1450 private void persistDevSrgCircuitPacks(String nodeId, SharedRiskGroup sharedRiskGroup, String srgNumber,
1451 Connection connection) {
1453 String startTimestamp = getCurrentTimestamp();
1455 Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1456 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>
1457 circuitPacksMap = sharedRiskGroup.nonnullCircuitPacks();
1458 for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1459 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> entry :
1460 circuitPacksMap.entrySet()) {
1462 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks circuitPack =
1464 String circuitPackindex = circuitPack.getIndex().toString();
1465 String circuitPackName = circuitPack.getCircuitPackName();
1467 Object[] parameters = {nodeId,
1475 String query = Queries.getQuery().deviceSrgCircuitPackInsert().get();
1476 LOG.info("Running {} query ", query);
1477 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1478 for (int j = 0; j < parameters.length; j++) {
1479 stmt.setObject(j + 1, parameters[j]);
1482 stmt.clearParameters();
1483 } catch (SQLException e) {
1484 LOG.error("Something wrong when storing devices SRG circuit packs", e);
1490 private void persistDevRoadmConnections(String nodeId, Connection connection) {
1492 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1493 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1495 Optional<OrgOpenroadmDevice> deviceObject =
1496 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1497 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1498 if (!deviceObject.isPresent()) {
1499 LOG.error("Device with node id {} not found", nodeId);
1502 String startTimestamp = getCurrentTimestamp();
1504 Map<RoadmConnectionsKey, RoadmConnections> roadmConnectionsMap = deviceObject.get().nonnullRoadmConnections();
1505 for (Map.Entry<RoadmConnectionsKey, RoadmConnections> entry : roadmConnectionsMap.entrySet()) {
1506 RoadmConnections roadmConnections = entry.getValue();
1507 int opticalcontrolmodeEnu = roadmConnections.getOpticalControlMode().getIntValue();
1508 //String connectionName = "";
1509 //String connectionNumber = "";
1510 //String wavelengthNumber = "";
1511 String targetOutputPower = roadmConnections.getTargetOutputPower().toString();
1512 String srcIf = roadmConnections.getSource().getSrcIf();
1513 String dstIf = roadmConnections.getDestination().getDstIf();
1515 Object[] parameters = {nodeId,
1520 Integer.toString(opticalcontrolmodeEnu),
1529 String query = Queries.getQuery().deviceRoadmConnectionsInsert().get();
1530 LOG.info("Running {} query ", query);
1531 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1532 for (int j = 0; j < parameters.length; j++) {
1533 stmt.setObject(j + 1, parameters[j]);
1536 stmt.clearParameters();
1537 } catch (SQLException e) {
1538 LOG.error("Something wrong when storing devices ROADM connection ", e);
1545 private void persistDevConnectionMap(String nodeId, Connection connection) {
1547 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier
1548 .builderOfInherited(OrgOpenroadmDeviceData.class, OrgOpenroadmDevice.class)
1550 Optional<OrgOpenroadmDevice> deviceObject =
1551 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1552 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1553 if (!deviceObject.isPresent()) {
1554 LOG.error("Device with node id {} not found", nodeId);
1557 String startTimestamp = getCurrentTimestamp();
1559 Map<ConnectionMapKey, ConnectionMap> connectionMapMap = deviceObject.get().nonnullConnectionMap();
1560 for (Map.Entry<ConnectionMapKey, ConnectionMap> entry : connectionMapMap.entrySet()) {
1561 ConnectionMap connectionMap = entry.getValue();
1562 String connectionMapNumber = connectionMap.getConnectionMapNumber().toString();
1563 String sourceCircuitPackName = connectionMap.getSource().getCircuitPackName();
1564 String sourcePortName = connectionMap.getSource().getCircuitPackName();
1567 Object[] parameters = {nodeId,
1568 connectionMapNumber,
1569 sourceCircuitPackName,
1575 String query = Queries.getQuery().deviceConnectionMapInsert().get();
1576 LOG.info("Running {} query ", query);
1577 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1578 for (int j = 0; j < parameters.length; j++) {
1579 stmt.setObject(j + 1, parameters[j]);
1582 stmt.clearParameters();
1583 } catch (SQLException e) {
1584 LOG.error("Something wrong when storing devices connection map", e);
1590 private void persistDevWavelengthMap(String nodeId, Connection connection) {
1593 String wavelengthNumber="", centerFrequency="", wavelength="";;
1595 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1596 Optional<OrgOpenroadmDevice> deviceObject =
1597 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1598 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1601 String startTimestamp = getCurrentTimestamp();
1602 for (int i = 0; i<deviceObject.get().getWavelengthMap().getWavelengths().size(); i++) {
1603 Wavelengths wavelengths = deviceObject.get().getWavelengthMap().getWavelengths().get(i);
1604 wavelengthNumber=wavelengths.getWavelengthNumber().toString();
1605 centerFrequency=wavelengths.getCenterFrequency().toString();
1606 wavelength=wavelengths.getWavelength().toString();
1609 Object[] parameters = {nodeId,
1617 String query = Queries.getQuery().deviceWavelengthInsert().get();
1618 LOG.info("Running {} query ", query);
1619 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1620 for (int j = 0; j < parameters.length; j++) {
1621 stmt.setObject(j + 1, parameters[j]);
1624 stmt.clearParameters();
1625 } catch (SQLException e) {
1626 LOG.error("Something wrong when storing devices wavelength map", e);
1634 private void persistDevInterfaceTcm(String nodeId, String interfaceName, OduBuilder oduBuilder,
1635 Connection connection) {
1637 Map<TcmKey, Tcm> tcmMap = oduBuilder.getTcm();
1638 for (Map.Entry<TcmKey, Tcm> entry : tcmMap.entrySet()) {
1639 Tcm tcm = entry.getValue();
1641 Object[] parameters = prepareDevInterfaceTcmParameters(nodeId, interfaceName, tcm);
1643 String query = Queries.getQuery().deviceInterfacesInsert().get();
1644 LOG.info("Running {} query ", query);
1645 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1646 for (int j = 0; j < parameters.length; j++) {
1647 stmt.setObject(j + 1, parameters[j]);
1650 stmt.clearParameters();
1651 } catch (SQLException e) {
1652 LOG.error("Something wrong when storing devices interface tcm", e);
1657 private void persistDevInterfaceOtnOduTxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1658 Connection connection) {
1660 Map<TxMsiKey, TxMsi> txMsi2Map = oduBuilder.getOpu().getMsi().getTxMsi();
1661 if (txMsi2Map == null) {
1662 LOG.error("Null txMsi2Map for node {}", nodeId);
1665 for (Map.Entry<TxMsiKey, TxMsi> entry : txMsi2Map.entrySet()) {
1666 TxMsi txMsi = entry.getValue();
1667 Object[] parameters = prepareDevInterfaceOtnOduTxMsiParameters(nodeId, interfaceName, txMsi);
1669 String query = Queries.getQuery().deviceInterfaceOtnOduTxMsiInsert().get();
1670 LOG.info("Running {} query ", query);
1671 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1672 for (int j = 0; j < parameters.length; j++) {
1673 stmt.setObject(j + 1, parameters[j]);
1676 stmt.clearParameters();
1677 } catch (SQLException e) {
1678 LOG.error("Something wrong when storing devices interface OTN ODU Tx MSI", e);
1684 private void persistDevInterfaceOtnOduRxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1685 Connection connection) {
1687 Map<RxMsiKey, RxMsi> rxMsi2Map = oduBuilder.getOpu().getMsi().getRxMsi();
1688 if (rxMsi2Map == null) {
1689 LOG.error("Null rxMsi2Map for node {}", nodeId);
1692 for (Map.Entry<RxMsiKey, RxMsi> entry : rxMsi2Map.entrySet()) {
1693 RxMsi rxMsi = entry.getValue();
1695 Object[] parameters = prepareDevInterfaceOtnOduRxMsiParameters(nodeId, interfaceName, rxMsi);
1697 String query = Queries.getQuery().deviceInterfaceOtnOduRxMsiInsert().get();
1698 LOG.info("Running {} query ", query);
1699 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1700 for (int j = 0; j < parameters.length; j++) {
1701 stmt.setObject(j + 1, parameters[j]);
1704 stmt.clearParameters();
1705 } catch (SQLException e) {
1706 LOG.error("Something wrong when storing devices interface OTN ODU Rx MSI", e);
1712 private void persistDevInterfaceOtnOduExpMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1713 Connection connection) {
1715 Map<ExpMsiKey, ExpMsi> expMsi2Map = oduBuilder.getOpu().getMsi().getExpMsi();
1716 if (expMsi2Map == null) {
1717 LOG.error("Null expMsi2Map for node {}", nodeId);
1720 for (Map.Entry<ExpMsiKey, ExpMsi> entry : expMsi2Map.entrySet()) {
1721 ExpMsi expMsi = entry.getValue();
1723 Object[] parameters = prepareDevInterfaceOtnOduExpMsiParameters(nodeId, interfaceName, expMsi);
1725 String query = Queries.getQuery().deviceInterfaceOtnOduExpMsiInsert().get();
1726 LOG.info("Running {} query ", query);
1727 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1728 for (int j = 0; j < parameters.length; j++) {
1729 stmt.setObject(j + 1, parameters[j]);
1732 stmt.clearParameters();
1733 } catch (SQLException e) {
1734 LOG.error("Something wrong when storing devices interface OTN ODU Exp MSI", e);