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.circuit.pack.CpSlots;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.CpSlotsKey;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPorts;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPortsKey;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLink;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.external.links.ExternalLinkKey;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceKey;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLink;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.internal.links.InternalLinkKey;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMapKey;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.DegreeKey;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnections;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLink;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.physical.links.PhysicalLinkKey;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.Slots;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelf.SlotsKey;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.Shelves;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.shelves.ShelvesKey;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.Interface1;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.ethernet.container.EthernetBuilder;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfig;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfigKey;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfName;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfNameKey;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.och.container.OchBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.OtsBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.Tcm;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.attributes.TcmKey;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.container.OduBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsi;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.ExpMsiKey;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsi;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.RxMsiKey;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsi;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.opu.msi.TxMsiKey;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.otu.container.OtuBuilder;
77 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
78 import org.slf4j.Logger;
79 import org.slf4j.LoggerFactory;
81 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
82 value = "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING",
83 justification = "TODO review the SQL statement generation process")
84 public class INode221 {
85 private static final Logger LOG = LoggerFactory.getLogger(INode221.class);
87 private final DataSource dataSource;
88 private final DeviceTransactionManager deviceTransactionManager;
90 public INode221(DataSource dataSource, DeviceTransactionManager deviceTransactionManager) {
91 this.dataSource = dataSource;
92 this.deviceTransactionManager = deviceTransactionManager;
95 public boolean addNode(String deviceId) {
97 InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
98 Optional<Info> infoOpt =
99 deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.OPERATIONAL, infoIID,
100 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
102 if (infoOpt.isPresent()) {
103 deviceInfo = infoOpt.get();
105 LOG.warn("Could not get device info from DataBroker");
108 boolean sqlResult = false;
109 String query = Queries.getQuery().deviceInfoInsert().get();
110 LOG.info("Running {} query ", query);
111 try (Connection connection = dataSource.getConnection();
112 PreparedStatement preparedStatement = connection.prepareStatement(query)) {
113 Object[] prepareParameters = prepareDeviceInfoParameters(deviceInfo);
114 for (int i = 0; i < prepareParameters.length; i++) {
115 LOG.debug("Parameter {} has value {}", i + 1, prepareParameters[i]);
116 preparedStatement.setObject(i + 1, prepareParameters[i]);
119 int executeUpdate = preparedStatement.executeUpdate();
120 LOG.info("{} entries were added", executeUpdate);
123 LOG.info("iNode AddNode call complete");
124 getRoadmShelves(deviceId);
125 LOG.info("iNode getRoadmShelves call complete");
126 getCircuitPacks(deviceId);
127 LOG.debug("iNode getCircuitPacks call complete");
129 LOG.debug("iNode persist interfaces call");
130 persistDevInterfaces(deviceId, connection);
131 LOG.debug("iNode persist interfaces 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 protocols call");
138 persistDevProtocols(deviceId, connection);
139 LOG.debug("iNode persist protocols call complete");
141 // LOG.debug("iNode persist wavelength map call");
142 // persistDevWavelengthMap(deviceId, connection);
143 // LOG.debug("iNode persist wavelength map call complete");
145 LOG.debug("iNode persist internal links map call");
146 persistDevInternalLinks(deviceId, connection);
147 LOG.debug("iNode persist internal links map call complete");
149 LOG.debug("iNode persist Physical links map call");
150 persistDevPhysicalLinks(deviceId, connection);
151 LOG.debug("iNode persist Physical links map call complete");
153 LOG.debug("iNode persist External links map call");
154 persistDevExternalLinks(deviceId, connection);
155 LOG.debug("iNode persist External links map call complete");
157 LOG.debug("iNode persist degree map call");
158 persistDevDegree(deviceId, connection);
159 LOG.debug("iNode persist degree map call complete");
161 LOG.debug("iNode persist srg map call");
162 persistDevSrg(deviceId, connection);
163 LOG.debug("iNode persist srg map call complete");
165 LOG.debug("iNode persist Roadm Connections call");
166 persistDevRoadmConnections(deviceId, connection);
167 LOG.debug("iNode persist Roadm Connections call complete");
169 LOG.debug("iNode persist Connection Map call");
170 persistDevConnectionMap(deviceId, connection);
171 LOG.debug("iNode persist Connection Map call complete");
173 } catch (SQLException | InterruptedException | ExecutionException e) {
174 LOG.error("Something wrong when storing node into DB", e);
179 public boolean nodeExists(String nodeId) {
180 String selectTableSQL = "select count(*) node_exists from inv_dev_info where node_id = ?";
182 LOG.info("Checking if {} exists in DB", nodeId);
183 try (Connection connection = dataSource.getConnection();
184 PreparedStatement preparedStmt = connection.prepareStatement(selectTableSQL)) {
185 preparedStmt.setString(1, nodeId);
186 try (ResultSet rs = preparedStmt.executeQuery()) {
188 nodeExists = rs.getInt("node_exists");
189 LOG.debug("Found {} devices matching {}", nodeExists, nodeId);
192 } catch (SQLException e) {
193 LOG.error("Something wrong when fetching node in DB", e);
195 return nodeExists == 0 ? false : true;
198 public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException {
199 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
200 Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
201 LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
202 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
203 if (!deviceObject.isPresent()) {
204 LOG.error("No device found in operational datastore for nodeId {}", nodeId);
208 Map<ShelvesKey, Shelves> shelvesMap = deviceObject.get().nonnullShelves();
209 LOG.info("Shelves size {}", shelvesMap.size());
210 try (Connection connection = requireNonNull(dataSource.getConnection())) {
211 for (Map.Entry<ShelvesKey, Shelves> entry : shelvesMap.entrySet()) {
212 Shelves shelve = entry.getValue();
213 String shelfName = shelve.getShelfName();
215 LOG.info("Getting Shelve Details of {}", shelfName);
216 if (shelve.getSlots() != null) {
217 LOG.info("Slot Size {} ", shelve.getSlots().size());
218 persistShelveSlots(nodeId, shelve, connection);
220 LOG.info("No Slots for shelf {}", shelfName);
224 persistShelves(nodeId, connection, shelve);
226 } catch (SQLException e1) {
227 LOG.error("Something wrong when fetching ROADM shelves in DB", e1);
231 public void getCircuitPacks(String nodeId) throws InterruptedException, ExecutionException {
232 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
233 Optional<OrgOpenroadmDevice> deviceObject =
234 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
235 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
236 if (!deviceObject.isPresent()) {
237 LOG.warn("Device object {} was not found", nodeId);
241 Map<CircuitPacksKey, CircuitPacks> circuitPacksMap = deviceObject.get().nonnullCircuitPacks();
242 LOG.info("Circuit pack size {}", circuitPacksMap.size());
244 try (Connection connection = requireNonNull(dataSource.getConnection())) {
246 for (Map.Entry<CircuitPacksKey, CircuitPacks> entry : circuitPacksMap.entrySet()) {
247 CircuitPacks cp = entry.getValue();
249 if (cp.getCpSlots() != null) {
250 persistCircuitPacksSlots(nodeId, cp, connection);
252 LOG.info("Everything {}", cp);
253 LOG.info("CP is {}", cp);
255 persistPorts(cp, connection);
257 persistCircuitPacks(nodeId, connection, cp);
259 } catch (SQLException e1) {
260 LOG.error("Something wrong when fetching Circuit Packs in DB", e1);
264 private void persistCircuitPacks(String nodeId, Connection connection, CircuitPacks cp) {
265 Object[] parameters = prepareCircuitPacksParameters(nodeId, cp);
266 String query = Queries.getQuery().deviceCircuitPackInsert().get();
267 LOG.info("Running {} query ", query);
268 try (PreparedStatement stmt = connection.prepareStatement(query)) {
269 for (int j = 0; j < parameters.length; j++) {
270 stmt.setObject(j + 1, parameters[j]);
273 stmt.clearParameters();
274 } catch (SQLException e) {
275 LOG.error("Something wrong when storing Circuit Packs in DB", e);
279 private void persistShelves(String nodeId, Connection connection, Shelves shelve) {
280 Object[] shelvesParameter = prepareShelvesParameters(nodeId, shelve);
281 String query = Queries.getQuery().deviceShelfInsert().get();
282 LOG.info("Running {} query ", query);
283 try (PreparedStatement preparedStmt = connection.prepareStatement(query)) {
284 for (int j = 0; j < shelvesParameter.length; j++) {
285 preparedStmt.setObject(j + 1, shelvesParameter[j]);
287 preparedStmt.execute();
288 preparedStmt.clearParameters();
289 } catch (SQLException e) {
290 LOG.error("Something wrong when storing shelves in DB", e);
294 private void persistShelveSlots(String nodeId, Shelves shelves, Connection connection) {
295 String startTimetampStr = getCurrentTimestamp();
297 Map<SlotsKey, Slots> slotsMap = shelves.nonnullSlots();
298 for (Map.Entry<SlotsKey, Slots> entry : slotsMap.entrySet()) {
299 Slots slot = entry.getValue();
300 LOG.info("Getting Slot Details of {}", slot.getSlotName());
301 Object[] parameters = new Object[]{nodeId,
302 shelves.getShelfName(),
305 slot.getProvisionedCircuitPack(),
309 String query = Queries.getQuery().deviceShelfSlotInsert().get();
310 LOG.info("Running {} query ", query);
311 try (PreparedStatement stmt = connection.prepareStatement(query)) {
312 for (int j = 0; j < parameters.length; j++) {
313 stmt.setObject(j + 1, parameters[j]);
316 stmt.clearParameters();
317 } catch (SQLException e) {
318 LOG.error("Something wrong when storing shelves slots in DB", e);
324 private void persistCircuitPacksSlots(String nodeId, CircuitPacks circuitPacks, Connection connection) {
325 String startTimetampStr = getCurrentTimestamp();
327 Map<CpSlotsKey, CpSlots> cpSlotsMap = circuitPacks.nonnullCpSlots();
328 for (Map.Entry<CpSlotsKey, CpSlots> entry : cpSlotsMap.entrySet()) {
329 CpSlots cpSlot = entry.getValue();
331 Object[] parameters = new Object[]{nodeId,
332 circuitPacks.getCircuitPackName(),
333 cpSlot.getSlotName(),
335 cpSlot.getProvisionedCircuitPack(),
339 String query = Queries.getQuery().deviceCPSlotInsert().get();
340 LOG.info("Running {} query ", query);
341 try (PreparedStatement stmt = connection.prepareStatement(query)) {
342 for (int j = 0; j < parameters.length; j++) {
343 stmt.setObject(j + 1, parameters[j]);
346 stmt.clearParameters();
347 } catch (SQLException e) {
348 LOG.error("Something wrong when storing Cirtcuits Packs slots in DB", e);
353 private void persistPorts(CircuitPacks circuitPacks, Connection connection) {
354 LOG.warn("Ports are not persisted yet");
359 * Prepares parameters for device insert query.
361 * @param deviceInfo device info
362 * @return Object Object
364 private static Object[] prepareDeviceInfoParameters(Info deviceInfo) {
365 String startTimetampStr = getCurrentTimestamp();
366 //Integer maxNumBin15minHistoricalPm = null;
367 //Integer maxNumBin24hourHistoricalPm = null;
368 //String serialId = "";
370 String nodeId = prepareDashString(deviceInfo.getNodeId());
371 Long nodeNumber = deviceInfo.getNodeNumber().toJava();
372 Integer nodeTypeEnu = deviceInfo.getNodeType().getIntValue();
373 String clli = prepareDashString(deviceInfo.getClli());
374 String vendor = prepareDashString(deviceInfo.getVendor());
375 String model = prepareDashString(deviceInfo.getModel());
376 String ipAddress = prepareDashString(deviceInfo.getIpAddress().getIpv4Address().getValue());
377 String prefixLength = prepareDashString(deviceInfo.getPrefixLength());
378 String defaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue());
379 Integer sourceEnum = deviceInfo.getSource().getIntValue();
380 String currentIpAddress = prepareDashString(deviceInfo.getCurrentIpAddress().getIpv4Address().getValue());
381 String currentPrefixLength = prepareDashString(deviceInfo.getCurrentPrefixLength());
382 String currentDefaultGateway = prepareDashString(deviceInfo.getDefaultGateway().getIpv4Address().getValue());
383 String macAddress = prepareDashString(deviceInfo.getMacAddress().getValue());
384 String softwareVersion = prepareDashString(deviceInfo.getSoftwareVersion());
385 String openroadmVersion = "2.2.1";
386 String template = prepareDashString(deviceInfo.getTemplate());
387 String currentDatetime = prepareDashString(deviceInfo.getCurrentDatetime().getValue());
389 (deviceInfo.getGeoLocation() != null ? prepareDashString(deviceInfo.getGeoLocation().getLatitude()) : "");
390 String geoLongitude =
391 (deviceInfo.getGeoLocation() != null ? prepareDashString(deviceInfo.getGeoLocation().getLongitude()) : "");
392 String maxDegrees = prepareDashString(deviceInfo.getMaxDegrees()); // max_degrees
393 String maxSrgs = prepareDashString(deviceInfo.getMaxSrgs()); //max_srgs
394 String swVersion = prepareDashString(deviceInfo.getSoftwareVersion()); //sw_version
395 String swValidationTimer = prepareDashString(""); //sw_validation_timer
396 String activationDateTime = prepareDashString(""); //activation_date_time
397 /*jsonDevInfo = JsonStringBuilder.getDevInfoJson().replace("$$NODE-ID$$",nodeId)
398 .replace("$$NODE-NUMBER$$", nodeNumber)
399 .replace("$$NODE-TYPE$$",nodeType)
400 .replace("$$CLLI$$",clli)
401 .replace("$$VENDOR$$",vendor)
402 .replace("$$MODEL$$",model)
403 .replace("$$SERIAL-ID$$",serialId)
404 .replace("$$IPADDRESS$$",ipAddress)
405 .replace("$$PREFIX-LENGTH$$",prefixLength)
406 .replace("$$DEFAULTGATEWAY$$",defaultGateway)
407 .replace("$$SOURCE$$",String.valueOf(source))
408 .replace("$$CURRENT-IPADDRESS$$",currentIpAddress)
409 .replace("$$CURRENT-PREFIX-LENGTH$$",currentPrefixLength)
410 .replace("$$CURRENT-DEFAULTGATEWAY$$",currentDefailtGateway)
411 .replace("$$MACADDRESS$$",macAddress)
412 .replace("$$SOFTWAREVERSION$$",softwareVersion)
413 .replace("$$OPENROADM-VERSION$$",openroadmVersion)
414 .replace("$$TEMPLATE$$",template)
415 .replace("$$CURRENT-DATETIME$$",currentDatetime)
416 .replace("$$LATITUDE$$",latitude)
417 .replace("$$LONGITUDE$$",longitude)
418 .replace("$$MAX-DEGREES$$",maxDegrees)
419 .replace("$$MAX-SRGS$$",maxSrgs)
420 .replace("$$MAX-NUM-BIN-15MIN-HISTORICAL-PM$$",prepareDashString(""))
421 .replace("$$MAX-NUM-BIN-24HOUR-HISTORICAL-PM$$",prepareDashString(""))
422 .replace("$$SW-VERSION$$",swVersion)
423 .replace("$$SW-VALIDATION-TIMER$$",swValidationTimer)
424 .replace("$$ACTIVATION-DATE-TIME$$",activationDateTime);*/
442 currentDefaultGateway,
452 //maxNumBin15minHistoricalPm,
453 //maxNumBin24hourHistoricalPm,
464 private static Object[] prepareShelvesParameters(String nodeId, Shelves shelve) {
465 String startTimestamp = getCurrentTimestamp();
467 return new Object[]{nodeId,
468 shelve.getShelfName(),
469 shelve.getShelfType(),
471 shelve.getShelfPosition(),
472 (shelve.getAdministrativeState() == null ? null : shelve.getAdministrativeState().getIntValue()),
475 shelve.getSerialId(),
477 shelve.getProductCode(),
478 (shelve.getManufactureDate() == null ? null : shelve.getManufactureDate().getValue()),
480 shelve.getHardwareVersion(),
481 (shelve.getOperationalState() == null ? null : shelve.getOperationalState().getIntValue()),
482 (shelve.getEquipmentState() == null ? null : shelve.getEquipmentState().getIntValue()),
483 (shelve.getDueDate() == null ? null : shelve.getDueDate().getValue()),
488 private static Object[] prepareCircuitPacksParameters(String nodeId, CircuitPacks cpack) {
489 String startTimestamp = getCurrentTimestamp();
490 return new Object[]{nodeId,
491 cpack.getCircuitPackName(),
492 cpack.getCircuitPackType(),
493 cpack.getCircuitPackProductCode(),
494 (cpack.getAdministrativeState() == null ? "" : cpack.getAdministrativeState().getIntValue()),
499 cpack.getProductCode(),
500 (cpack.getManufactureDate() == null ? "" : cpack.getManufactureDate().getValue()),
502 cpack.getHardwareVersion(),
503 prepareEmptyString(cpack.getOperationalState().getIntValue()),
504 cpack.getCircuitPackCategory().getType().getName(),
505 cpack.getCircuitPackCategory().getExtension(),
506 (cpack.getEquipmentState() == null ? "" : cpack.getEquipmentState().getIntValue()),
507 cpack.getCircuitPackMode(),
511 prepareEmptyString(cpack.getDueDate()),
512 prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" :
513 ((cpack.getParentCircuitPack().getCircuitPackName() == null) ? "" :
514 cpack.getParentCircuitPack().getCircuitPackName())
516 prepareEmptyString((cpack.getParentCircuitPack() == null) ? "" :
517 ((cpack.getParentCircuitPack().getCpSlotName() == null) ? "" :
518 cpack.getParentCircuitPack().getCpSlotName())
524 private Object[] prepareDevInterfaceParameters(String nodeId, Interface deviceInterface, Connection connection) {
526 int administrativeStateEnu = deviceInterface.getAdministrativeState().getIntValue();
527 int operationalState = deviceInterface.getOperationalState().getIntValue();
528 int ethernetDuplexEnu = -1;
529 int ethernetAutoNegotiationEnu = -1;
530 int maintTestsignalTestpatternEnu = -1;
531 int maintTestsignalTypeEnu = -1;
533 int otuMaintTypeEnu = -1;
534 //int otsFiberTypeEnu = -1;
535 String name = deviceInterface.getName();
536 String description = deviceInterface.getDescription();
537 String type = deviceInterface.getType().getTypeName();
538 String circuitId = deviceInterface.getCircuitId();
539 String supportingInterface = deviceInterface.getSupportingInterface();
540 String supportingCircuitPackName = deviceInterface.getSupportingCircuitPackName();
541 String supportingPort = deviceInterface.getSupportingPort().toString();
542 String ethernetSpeed = "";
543 String ethernetFec = "";
544 String ethernetMtu = "";
545 String ethernetCurrSpeed = "";
546 String ethernetCurrDuplex = "";
547 //String mciMcttpMinFreq = "";
548 //String mciMcttpMaxFreq = "";
549 //String mciMcttpCenterFreq = "";
550 //String mciMcttpSlotWidth = "";
551 //String mciNmcCtpFrequency = "";
552 //String mciNmcCtpWidth = "";
554 //String ochFrequency = "";
555 //String ochWidth = "";
556 //String ochWavelengthNumber = "";
557 String ochModulationFormat = "";
558 String ochTransmitPower = "";
559 String otsSpanLossReceive = "";
560 String otsSpanLossTransmit = "";
561 //String otsIngressSpanLossAgingMargin = "";
562 //String otsEolMaxLoadPin = "";
563 String oduRate = ""; //BUG in following case switch statement ???
564 //String oduFunction = "";
565 String oduMonitoringMode = "";
566 //String oduNoOamFunction = "";
567 String oduProactiveDelayMeasurementEnabled = "";
568 //String oduPoaTribPortNumber = "";
569 //String oduTxSapi = "";
570 //String oduTxDapi = "";
571 //String oduTxOperator = "";
572 //String oduAcceptedSapi = "";
573 //String oduAcceptedDapi = "";
574 //String oduAcceptedOperator = "";
575 //String oduExpectedSapi = "";
576 //String oduExpectedDapi = "";
577 //String oduTimActEnabled = "";
578 //String oduTimDetectMode = "";
579 //String oduDegmIntervals = "";
580 //String oduDegthrPercentage = "";
581 String opuPayloadType = "";
582 String opuRxPayloadType = "";
583 String opuExpPayloadType = "";
584 String opuPayloadInterface = "";
585 String maintTestsignalEnabled = "";
586 String maintTestsignalBiterrors = "";
587 String maintTestsignalBiterrorsterminal = "";
588 String maintTestsignalSyncseconds = "";
589 String maintTestsignalSyncsecondsterminal = "";
591 //String otuTxSapi = "";
592 //String otuTxDapi = "";
593 //String otuTxOperator = "";
594 //String otuAcceptedSapi = "";
595 //String otuAcceptedDapi = "";
596 //String otuAcceptedOperator = "";
597 //String otuExpectedSapi = "";
598 //String otuExpectedDapi = "";
599 //String otuTimActEnabled = "";
600 //String otuTimDetectMode = "";
601 //String otuDegmIntervals = "";
602 //String otuDegthrPercentage = "";
603 String otuMaintLoopbackEnabled = "";
604 //String mtOtuRate = "";
605 //String mtOtuFec = "";
606 //String mtOtuMaintLoopback = "";
607 //String mtOtuEnabled = "";
608 //String mtOtuType = "";
610 switch (deviceInterface.getType().toString()) {
613 //EthernetBuilder ethIfBuilder = new EthernetBuilder();
614 EthernetBuilder ethIfBuilder =
615 new EthernetBuilder(deviceInterface.augmentation(Interface1.class).getEthernet());
616 ethernetSpeed = ethIfBuilder.getSpeed().toString();
617 ethernetFec = ethIfBuilder.getFec().getName();
618 ethernetDuplexEnu = ethIfBuilder.getDuplex().getIntValue();
619 ethernetMtu = ethIfBuilder.getMtu().toString();
620 ethernetAutoNegotiationEnu = ethIfBuilder.getAutoNegotiation().getIntValue();
621 ethernetCurrSpeed = ethIfBuilder.getCurrSpeed();
622 ethernetCurrDuplex = ethIfBuilder.getCurrDuplex();
626 OchBuilder ochIfBuilder = new OchBuilder(deviceInterface.augmentation(
627 org.opendaylight.yang.gen.v1
628 .http.org.openroadm.optical.channel.interfaces.rev161014.Interface1.class)
630 ochRate = ochIfBuilder.getRate().getName();
631 //ochWavelengthNumber = ochIfBuilder.getWavelengthNumber().toString();
632 ochModulationFormat = ochIfBuilder.getModulationFormat().getName();
633 ochTransmitPower = ochIfBuilder.getTransmitPower().toString();
637 OtsBuilder otsIfBuilder = new OtsBuilder(deviceInterface.augmentation(
638 org.opendaylight.yang.gen.v1
639 .http.org.openroadm.optical.transport.interfaces.rev161014.Interface1.class)
641 //otsFiberTypeEnu = otsIfBuilder.getFiberType().getIntValue();
642 otsSpanLossReceive = otsIfBuilder.getSpanLossReceive().toString();
643 otsSpanLossTransmit = otsIfBuilder.getSpanLossTransmit().toString();
647 OduBuilder oduIfBuilder = new OduBuilder(deviceInterface.augmentation(
648 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.Interface1.class)
650 oduRate = String.valueOf(oduIfBuilder.getRate());
651 oduMonitoringMode = oduIfBuilder.getMonitoringMode().getName();
652 oduProactiveDelayMeasurementEnabled = oduIfBuilder.getProactiveDelayMeasurementEnabled().toString();
654 persistDevInterfaceTcm(nodeId, name, oduIfBuilder, connection);
655 persistDevInterfaceOtnOduTxMsi(nodeId, name, oduIfBuilder, connection);
656 persistDevInterfaceOtnOduRxMsi(nodeId, name, oduIfBuilder, connection);
657 persistDevInterfaceOtnOduExpMsi(nodeId, name, oduIfBuilder, connection);
659 opuPayloadType = oduIfBuilder.getOpu().getPayloadType();
660 opuRxPayloadType = oduIfBuilder.getOpu().getRxPayloadType();
661 opuExpPayloadType = oduIfBuilder.getOpu().getExpPayloadType();
662 opuPayloadInterface = oduIfBuilder.getOpu().getPayloadInterface();
663 /*persistDevInterfaceOtnOduTxMsi(nodeId,name,oduIfBuilder,connection);
664 persistDevInterfaceOtnOduRxMsi(nodeId,name,oduIfBuilder,connection);
665 persistDevInterfaceOtnOduExpMsi(nodeId,name,oduIfBuilder,connection); */
666 maintTestsignalEnabled = oduIfBuilder.getMaintTestsignal().getEnabled().toString();
667 maintTestsignalTestpatternEnu = oduIfBuilder.getMaintTestsignal().getTestPattern().getIntValue();
668 maintTestsignalTypeEnu = oduIfBuilder.getMaintTestsignal().getType().getIntValue();
669 maintTestsignalBiterrors = oduIfBuilder.getMaintTestsignal().getBitErrors().toString();
670 maintTestsignalBiterrorsterminal = oduIfBuilder.getMaintTestsignal().getBitErrorsTerminal().toString();
671 maintTestsignalSyncseconds = oduIfBuilder.getMaintTestsignal().getSyncSeconds();
672 maintTestsignalSyncsecondsterminal = oduIfBuilder.getMaintTestsignal().getSyncSecondsTerminal();
676 OtuBuilder otuIfBuilder = new OtuBuilder(deviceInterface.augmentation(
677 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.Interface1.class)
679 otuRate = otuIfBuilder.getRate().getName();
680 otuFecEnu = otuIfBuilder.getFec().getIntValue();
681 otuMaintLoopbackEnabled = otuIfBuilder.getMaintLoopback().getEnabled().toString();
682 otuMaintTypeEnu = otuIfBuilder.getMaintLoopback().getType().getIntValue();
686 LOG.error("Could not get interface type");
689 String startTimestamp = getCurrentTimestamp();
691 return new Object[]{nodeId,
695 Integer.toString(administrativeStateEnu),
696 Integer.toString(operationalState),
699 supportingCircuitPackName,
703 Integer.toString(ethernetDuplexEnu),
705 Integer.toString(ethernetAutoNegotiationEnu),
710 //mciMcttpCenterFreq,
712 //mciNmcCtpFrequency,
714 "", "", "", "", "", "",
718 //ochWavelengthNumber,
722 //Integer.toString(otsFiberTypeEnu),
726 //otsIngressSpanLossAgingMargin,
735 oduProactiveDelayMeasurementEnabled,
736 //oduPoaTribPortNumber,
742 //oduAcceptedOperator,
748 //oduDegthrPercentage,
749 "", "", "", "", "", "", "", "", "", "", "", "", "",
754 maintTestsignalEnabled,
755 Integer.toString(maintTestsignalTestpatternEnu),
756 Integer.toString(maintTestsignalTypeEnu),
757 maintTestsignalBiterrors,
758 maintTestsignalBiterrorsterminal,
759 maintTestsignalSyncseconds,
760 maintTestsignalSyncsecondsterminal,
762 Integer.toString(otuFecEnu),
768 //otuAcceptedOperator,
774 //otuDegthrPercentage,
775 "", "", "", "", "", "", "", "", "", "", "", "",
776 otuMaintLoopbackEnabled,
777 Integer.toString(otuMaintTypeEnu),
780 //mtOtuMaintLoopback,
790 private static Object[] prepareDevInterfaceTcmParameters(String nodeId, String interfaceName, Tcm tcm) {
793 String layer = tcm.getLayer().toString();
794 int monitoringModeEnu = tcm.getMonitoringMode().getIntValue();
795 String ltcActEnabled = tcm.getLtcActEnabled().toString();
796 String proactiveDelayMeasurementEnabled = tcm.getProactiveDelayMeasurementEnabled().toString();
797 //int tcmDirectionEnu = -1;
798 //int timDetectModeEnu = -1;
799 //String txSapi = "";
800 //String txDapi = "";
801 //String txOperator = "";
802 //String acceptedSapi = "";
803 //String acceptedDapi = "";
804 //String acceptedOperator = "";
805 //String expectedSapi = "";
806 //String expectedDapi = "";
807 //String timActEnabled = "";
808 //String degmIntervals = "";
809 //String degthrPercentage = "";
811 String startTimestamp = getCurrentTimestamp();
813 return new Object[]{nodeId,
816 Integer.toString(monitoringModeEnu),
818 proactiveDelayMeasurementEnabled,
819 //Integer.toString(tcmDirectionEnu),
830 "", "", "", "", "", "", "", "", "",
831 //Integer.toString(timDetectModeEnu),
841 private static Object[] prepareDevInterfaceOtnOduTxMsiParameters(String nodeId, String interfaceName, TxMsi txMsi) {
843 String tribSlot = txMsi.getTribSlot().toString();
844 String odtuType = txMsi.getOdtuType().getTypeName();
845 String tribPort = txMsi.getTribPort().toString();
846 String tribPortPayload = txMsi.getTribPortPayload();
848 String startTimestamp = getCurrentTimestamp();
850 return new Object[]{nodeId,
862 private static Object[] prepareDevInterfaceOtnOduRxMsiParameters(String nodeId, String interfaceName, RxMsi rxMsi) {
864 String tribSlot = rxMsi.getTribSlot().toString();
865 String odtuType = rxMsi.getOdtuType().getTypeName();
866 String tribPort = rxMsi.getTribPort().toString();
867 String tribPortPayload = rxMsi.getTribPortPayload();
869 String startTimestamp = getCurrentTimestamp();
871 return new Object[]{nodeId,
884 private static Object[] prepareDevInterfaceOtnOduExpMsiParameters(String nodeId, String interfaceName,
887 String tribSlot = expMsi.getTribSlot().toString();
888 String odtuType = expMsi.getOdtuType().getTypeName();
889 String tribPort = expMsi.getTribPort().toString();
890 String tribPortPayload = expMsi.getTribPortPayload();
892 String startTimestamp = getCurrentTimestamp();
894 return new Object[]{nodeId,
906 private void persistDevInterfaces(String nodeId, Connection connection) {
908 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
909 Optional<OrgOpenroadmDevice> deviceObject =
910 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
911 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
913 /*InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
914 .child(Interface.class);
915 Optional<Interface> interfaceOpt =
916 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, interfaceIID,
917 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); */
920 Map<InterfaceKey, Interface> interfaceMap = deviceObject.get().nonnullInterface();
921 for (Map.Entry<InterfaceKey, Interface> entry : interfaceMap.entrySet()) {
922 Interface deviceInterface;
924 deviceInterface = entry.getValue();
925 /*if (interfaceOpt.isPresent()) {
926 deviceInterface = interfaceOpt.get();
928 LOG.warn("Could not get interface info");
931 Object[] parameters = prepareDevInterfaceParameters(nodeId, deviceInterface, connection);
933 String query = Queries.getQuery().deviceInterfacesInsert().get();
934 LOG.info("Running {} query ", query);
935 try (PreparedStatement stmt = connection.prepareStatement(query)) {
936 for (int j = 0; j < parameters.length; j++) {
937 stmt.setObject(j + 1, parameters[j]);
940 stmt.clearParameters();
941 } catch (SQLException e) {
942 LOG.error("Something wrong when storing devices interfaces in DB", e);
947 private void persistDevProtocols(String nodeId, Connection connection) {
949 InstanceIdentifier<Protocols> protocolsIID =
950 InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
951 Optional<Protocols> protocolObject =
952 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
953 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
954 if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
955 LOG.error("LLDP subtree is missing");
959 protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig().getAdminStatus()
961 String msgTxtInterval =
962 protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig().getMsgTxInterval()
964 String mxgTxHoldMultiplier =
965 protocolObject.get().augmentation(Protocols1.class).getLldp().getGlobalConfig().getMsgTxHoldMultiplier()
967 String startTimestamp = getCurrentTimestamp();
968 persistDevProtocolLldpPortConfig(nodeId, connection);
969 persistDevProtocolLldpNbrList(nodeId, connection);
971 Object[] parameters = {nodeId,
972 Integer.toString(adminstatusEnu),
979 String query = Queries.getQuery().deviceProtocolInsert().get();
980 LOG.info("Running {} query ", query);
981 try (PreparedStatement stmt = connection.prepareStatement(query)) {
982 for (int j = 0; j < parameters.length; j++) {
983 stmt.setObject(j + 1, parameters[j]);
986 stmt.clearParameters();
987 } catch (SQLException e) {
988 LOG.error("Something wrong when storing devices protocols in DB", e);
994 private void persistDevProtocolLldpPortConfig(String nodeId, Connection connection) {
996 InstanceIdentifier<Protocols> protocolsIID =
997 InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
998 Optional<Protocols> protocolObject =
999 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1000 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1001 if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
1002 LOG.error("LLDP subtree is missing");
1005 String startTimestamp = getCurrentTimestamp();
1007 Map<PortConfigKey, PortConfig> portConfigMap = protocolObject.get()
1008 .augmentation(Protocols1.class).getLldp().nonnullPortConfig();
1009 for (Map.Entry<PortConfigKey, PortConfig> entry : portConfigMap.entrySet()) {
1011 PortConfig portConfig = entry.getValue();
1012 String ifName = portConfig.getIfName();
1013 int adminStatusEnu = portConfig.getAdminStatus().getIntValue();
1015 Object[] parameters = {nodeId,
1017 Integer.toString(adminStatusEnu),
1022 String query = Queries.getQuery().deviceProtocolPortConfigInsert().get();
1023 LOG.info("Running {} query ", query);
1024 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1025 for (int j = 0; j < parameters.length; j++) {
1026 stmt.setObject(j + 1, parameters[j]);
1029 stmt.clearParameters();
1030 } catch (SQLException e) {
1031 LOG.error("Something wrong when storing devices protocols LLDP Port config in DB", e);
1038 private void persistDevProtocolLldpNbrList(String nodeId, Connection connection) {
1040 InstanceIdentifier<Protocols> protocolsIID =
1041 InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
1042 Optional<Protocols> protocolObject =
1043 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, protocolsIID,
1044 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1045 if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class) == null) {
1046 LOG.error("LLDP subtree is missing");
1049 String startTimestamp = getCurrentTimestamp();
1051 Map<IfNameKey, IfName> ifNameMap = protocolObject.get()
1052 .augmentation(Protocols1.class).getLldp().getNbrList().nonnullIfName();
1053 for (Map.Entry<IfNameKey, IfName> entry : ifNameMap.entrySet()) {
1055 IfName ifNameObj = entry.getValue();
1056 String ifName = ifNameObj.getIfName();
1057 String remotesysname = ifNameObj.getRemoteSysName();
1058 String remotemgmtaddresssubtype = ifNameObj.getRemoteMgmtAddressSubType().getName();
1059 String remotemgmtaddress = ifNameObj.getRemoteMgmtAddress().getIpv4Address().toString();
1060 int remoteportidsubtypeEnu = ifNameObj.getRemotePortIdSubType().getIntValue();
1061 String remoteportid = ifNameObj.getRemotePortId();
1062 int remotechassisidsubtypeEnu = ifNameObj.getRemoteChassisIdSubType().getIntValue();
1063 String remotechassisid = ifNameObj.getRemoteChassisId();
1065 Object[] parameters = {nodeId,
1068 remotemgmtaddresssubtype,
1070 Integer.toString(remoteportidsubtypeEnu),
1072 Integer.toString(remotechassisidsubtypeEnu),
1078 String query = Queries.getQuery().deviceProtocolLldpNbrlistInsert().get();
1079 LOG.info("Running {} query ", query);
1080 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1081 for (int j = 0; j < parameters.length; j++) {
1082 stmt.setObject(j + 1, parameters[j]);
1085 stmt.clearParameters();
1086 } catch (SQLException e) {
1087 LOG.error("Something wrong when storing devices protocols LLDP list number in DB", e);
1093 private void persistDevInternalLinks(String nodeId, Connection connection) {
1095 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1096 Optional<OrgOpenroadmDevice> deviceObject =
1097 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1098 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1099 if (!deviceObject.isPresent()) {
1100 LOG.error("Device with node id {} not found", nodeId);
1103 String startTimestamp = getCurrentTimestamp();
1105 Map<InternalLinkKey, InternalLink> internalLinkMap = deviceObject.get().nonnullInternalLink();
1106 for (Map.Entry<InternalLinkKey, InternalLink> entry : internalLinkMap.entrySet()) {
1107 InternalLink internalLink = entry.getValue();
1108 String internalLinkName = internalLink.getInternalLinkName();
1109 String sourceCircuitPackName = internalLink.getSource().getCircuitPackName();
1110 String sourcePortName = internalLink.getSource().getPortName().toString();
1111 String destinationCircuitPackName = internalLink.getDestination().getCircuitPackName();
1112 String destinationPortName = internalLink.getDestination().getPortName().toString();
1114 Object[] parameters = {nodeId,
1116 sourceCircuitPackName,
1118 destinationCircuitPackName,
1119 destinationPortName,
1124 String query = Queries.getQuery().deviceInternalLinkInsert().get();
1125 LOG.info("Running {} query ", query);
1126 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1127 for (int j = 0; j < parameters.length; j++) {
1128 stmt.setObject(j + 1, parameters[j]);
1131 stmt.clearParameters();
1132 } catch (SQLException e) {
1133 LOG.error("Something wrong when storing devices internal links", e);
1140 private void persistDevExternalLinks(String nodeId, Connection connection) {
1142 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1143 Optional<OrgOpenroadmDevice> deviceObject =
1144 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1145 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1146 if (!deviceObject.isPresent()) {
1147 LOG.error("Device with node id {} not found", nodeId);
1150 String startTimestamp = getCurrentTimestamp();
1152 Map<ExternalLinkKey, ExternalLink> externalLinkMap = deviceObject.get().nonnullExternalLink();
1153 for (Map.Entry<ExternalLinkKey, ExternalLink> entry : externalLinkMap.entrySet()) {
1154 ExternalLink externalLink = entry.getValue();
1155 String externalLinkName = externalLink.getExternalLinkName();
1156 String sourceNodeId = externalLink.getSource().getNodeId();
1157 String sourceCircuitPackName = externalLink.getSource().getCircuitPackName();
1158 String sourcePortName = externalLink.getSource().getPortName();
1159 String destinationNodeId = externalLink.getDestination().getNodeId();
1160 String destinationCircuitPackName = externalLink.getDestination().getCircuitPackName();
1161 String destinationPortName = externalLink.getDestination().getPortName();
1163 Object[] parameters = {nodeId,
1166 sourceCircuitPackName,
1169 destinationCircuitPackName,
1170 destinationPortName,
1175 String query = Queries.getQuery().deviceExternalLinkInsert().get();
1176 LOG.info("Running {} query ", query);
1177 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1178 for (int j = 0; j < parameters.length; j++) {
1179 stmt.setObject(j + 1, parameters[j]);
1182 stmt.clearParameters();
1183 } catch (SQLException e) {
1184 LOG.error("Something wrong when storing devices external links", e);
1190 private void persistDevPhysicalLinks(String nodeId, Connection connection) {
1192 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1193 Optional<OrgOpenroadmDevice> deviceObject =
1194 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1195 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1196 if (!deviceObject.isPresent()) {
1197 LOG.error("Device with node id {} not found", nodeId);
1201 String startTimestamp = getCurrentTimestamp();
1203 Map<PhysicalLinkKey, PhysicalLink> physicalLinkMap = deviceObject.get().nonnullPhysicalLink();
1204 for (Map.Entry<PhysicalLinkKey, PhysicalLink> entry : physicalLinkMap.entrySet()) {
1205 PhysicalLink physicalLink = entry.getValue();
1206 String physicalLinkName = physicalLink.getPhysicalLinkName();
1207 String sourceCircuitPackName = physicalLink.getSource().getCircuitPackName();
1208 String sourcePortName = physicalLink.getSource().getPortName().toString();
1209 String destinationCircuitPackName = physicalLink.getDestination().getCircuitPackName();
1210 String destinationPortName = physicalLink.getDestination().getPortName().toString();
1212 Object[] parameters = {nodeId,
1214 sourceCircuitPackName,
1216 destinationCircuitPackName,
1217 destinationPortName,
1222 String query = Queries.getQuery().devicePhysicalLinkInsert().get();
1223 LOG.info("Running {} query ", query);
1224 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1225 for (int j = 0; j < parameters.length; j++) {
1226 stmt.setObject(j + 1, parameters[j]);
1229 stmt.clearParameters();
1230 } catch (SQLException e) {
1231 LOG.error("Something wrong when storing devices physical links", e);
1237 private void persistDevDegree(String nodeId, Connection connection) {
1239 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1240 Optional<OrgOpenroadmDevice> deviceObject =
1241 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1242 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1243 if (!deviceObject.isPresent()) {
1244 LOG.error("Device with node id {} not found", nodeId);
1247 String startTimestamp = getCurrentTimestamp();
1249 Map<DegreeKey, Degree> degreeMap = deviceObject.get().nonnullDegree();
1250 for (Map.Entry<DegreeKey, Degree> entry : degreeMap.entrySet()) {
1251 Degree degree = entry.getValue();
1252 String degreeNumber = degree.getDegreeNumber().toString();
1253 String maxWavelengths = degree.getMaxWavelengths().toString();
1254 String otdrPortCircuitPackName = degree.getOtdrPort().getCircuitPackName();
1255 String otdrPortPortName = degree.getOtdrPort().getPortName().toString();
1256 persistDevDegreeCircuitPack(nodeId, degree, degreeNumber, connection);
1257 persistDevDegreeConnectionPort(nodeId, degree, degreeNumber, connection);
1258 //String mcCapabilitiesSlotWidthGranularity = "";
1259 //String mcCapabilitiesCenterFreqGranularity = "";
1260 //String mcCapabilitiesMinSlots = "";
1261 //String mcCapabilitiesMaxSlots = "";
1263 Object[] parameters = {nodeId,
1266 otdrPortCircuitPackName,
1268 //mcCapabilitiesSlotWidthGranularity,
1269 //mcCapabilitiesCenterFreqGranularity,
1270 //mcCapabilitiesMinSlots,
1271 //mcCapabilitiesMaxSlots,
1277 String query = Queries.getQuery().deviceDegreeInsert().get();
1278 LOG.info("Running {} query ", query);
1279 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1280 for (int j = 0; j < parameters.length; j++) {
1281 stmt.setObject(j + 1, parameters[j]);
1284 stmt.clearParameters();
1285 } catch (SQLException e) {
1286 LOG.error("Something wrong when storing devices degrees", e);
1293 private void persistDevDegreeCircuitPack(String nodeId, Degree degree, String degreeNumber, Connection connection) {
1295 String startTimestamp = getCurrentTimestamp();
1297 Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1298 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks>
1299 circuitPacksMap = degree.nonnullCircuitPacks();
1300 for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1301 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks> entry :
1302 circuitPacksMap.entrySet()) {
1305 String circuitPackIndex = entry.getValue().getIndex().toString();
1306 String circuitPackName = entry.getValue().getCircuitPackName();
1308 Object[] parameters = {nodeId,
1316 String query = Queries.getQuery().deviceDegreeCircuitPackInsert().get();
1317 LOG.info("Running {} query ", query);
1318 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1319 for (int j = 0; j < parameters.length; j++) {
1320 stmt.setObject(j + 1, parameters[j]);
1323 stmt.clearParameters();
1324 } catch (SQLException e) {
1325 LOG.error("Something wrong when storing devices degrees circuit packs", e);
1331 private void persistDevDegreeConnectionPort(String nodeId, Degree degree, String degreeNumber,
1332 Connection connection) {
1334 String startTimestamp = getCurrentTimestamp();
1336 Map<ConnectionPortsKey, ConnectionPorts> connectionPortsMap = degree.nonnullConnectionPorts();
1337 for (Map.Entry<ConnectionPortsKey, ConnectionPorts> entry : connectionPortsMap.entrySet()) {
1339 ConnectionPorts connectionPorts = entry.getValue();
1340 String connectionPortIndex = connectionPorts.getIndex().toString();
1341 String circuitPackName = connectionPorts.getCircuitPackName();
1342 String portName = connectionPorts.getPortName().toString();
1344 Object[] parameters = {nodeId,
1346 connectionPortIndex,
1353 String query = Queries.getQuery().deviceDegreeConnectionPortInsert().get();
1354 LOG.info("Running {} query ", query);
1355 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1356 for (int j = 0; j < parameters.length; j++) {
1357 stmt.setObject(j + 1, parameters[j]);
1360 stmt.clearParameters();
1361 } catch (SQLException e) {
1362 LOG.error("Something wrong when storing devices degrees connection ports", e);
1369 private void persistDevSrg(String nodeId, Connection connection) {
1371 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1372 Optional<OrgOpenroadmDevice> deviceObject =
1373 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1374 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1375 if (!deviceObject.isPresent()) {
1376 LOG.error("Device with node id {} not found", nodeId);
1380 String startTimestamp = getCurrentTimestamp();
1382 Map<SharedRiskGroupKey, SharedRiskGroup> sharedRiskGroupMap = deviceObject.get().nonnullSharedRiskGroup();
1383 for (Map.Entry<SharedRiskGroupKey, SharedRiskGroup> entry : sharedRiskGroupMap.entrySet()) {
1384 SharedRiskGroup sharedRiskGroup = entry.getValue();
1385 String maxAddDropPorts = sharedRiskGroup.getMaxAddDropPorts().toString();
1386 String srgNumber = sharedRiskGroup.getSrgNumber().toString();
1387 //int wavelengthDuplicationEnu = sharedRiskGroup.getWavelengthDuplication().getIntValue();
1388 persistDevSrgCircuitPacks(nodeId, sharedRiskGroup, srgNumber, connection);
1389 //String currentProvisionedAddDropPorts = "";
1390 //String mcCapSlotWidthGranularity = "";
1391 //String mcCapCenterFreqGranularity = "";
1392 //String mcCapMinSlots = "";
1393 //String mcCapMaxSlots = "";
1395 Object[] parameters = {nodeId,
1397 //currentProvisionedAddDropPorts,
1400 //mcCapSlotWidthGranularity,
1401 //mcCapCenterFreqGranularity,
1409 String query = Queries.getQuery().deviceSharedRiskGroupInsert().get();
1410 LOG.info("Running {} query ", query);
1411 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1412 for (int j = 0; j < parameters.length; j++) {
1413 stmt.setObject(j + 1, parameters[j]);
1416 stmt.clearParameters();
1417 } catch (SQLException e) {
1418 LOG.error("Something wrong when storing devices SRG", e);
1424 private void persistDevSrgCircuitPacks(String nodeId, SharedRiskGroup sharedRiskGroup, String srgNumber,
1425 Connection connection) {
1427 String startTimestamp = getCurrentTimestamp();
1429 Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1430 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>
1431 circuitPacksMap = sharedRiskGroup.nonnullCircuitPacks();
1432 for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1433 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> entry :
1434 circuitPacksMap.entrySet()) {
1436 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks circuitPack =
1438 String circuitPackindex = circuitPack.getIndex().toString();
1439 String circuitPackName = circuitPack.getCircuitPackName();
1441 Object[] parameters = {nodeId,
1449 String query = Queries.getQuery().deviceSrgCircuitPackInsert().get();
1450 LOG.info("Running {} query ", query);
1451 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1452 for (int j = 0; j < parameters.length; j++) {
1453 stmt.setObject(j + 1, parameters[j]);
1456 stmt.clearParameters();
1457 } catch (SQLException e) {
1458 LOG.error("Something wrong when storing devices SRG circuit packs", e);
1464 private void persistDevRoadmConnections(String nodeId, Connection connection) {
1466 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1467 Optional<OrgOpenroadmDevice> deviceObject =
1468 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1469 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1470 if (!deviceObject.isPresent()) {
1471 LOG.error("Device with node id {} not found", nodeId);
1474 String startTimestamp = getCurrentTimestamp();
1476 Map<RoadmConnectionsKey, RoadmConnections> roadmConnectionsMap = deviceObject.get().nonnullRoadmConnections();
1477 for (Map.Entry<RoadmConnectionsKey, RoadmConnections> entry : roadmConnectionsMap.entrySet()) {
1478 RoadmConnections roadmConnections = entry.getValue();
1479 int opticalcontrolmodeEnu = roadmConnections.getOpticalControlMode().getIntValue();
1480 //String connectionName = "";
1481 //String connectionNumber = "";
1482 //String wavelengthNumber = "";
1483 String targetOutputPower = roadmConnections.getTargetOutputPower().toString();
1484 String srcIf = roadmConnections.getSource().getSrcIf();
1485 String dstIf = roadmConnections.getDestination().getDstIf();
1487 Object[] parameters = {nodeId,
1492 Integer.toString(opticalcontrolmodeEnu),
1501 String query = Queries.getQuery().deviceRoadmConnectionsInsert().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]);
1508 stmt.clearParameters();
1509 } catch (SQLException e) {
1510 LOG.error("Something wrong when storing devices ROADM connection ", e);
1517 private void persistDevConnectionMap(String nodeId, Connection connection) {
1519 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1520 Optional<OrgOpenroadmDevice> deviceObject =
1521 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1522 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1523 if (!deviceObject.isPresent()) {
1524 LOG.error("Device with node id {} not found", nodeId);
1527 String startTimestamp = getCurrentTimestamp();
1529 Map<ConnectionMapKey, ConnectionMap> connectionMapMap = deviceObject.get().nonnullConnectionMap();
1530 for (Map.Entry<ConnectionMapKey, ConnectionMap> entry : connectionMapMap.entrySet()) {
1531 ConnectionMap connectionMap = entry.getValue();
1532 String connectionMapNumber = connectionMap.getConnectionMapNumber().toString();
1533 String sourceCircuitPackName = connectionMap.getSource().getCircuitPackName();
1534 String sourcePortName = connectionMap.getSource().getCircuitPackName();
1537 Object[] parameters = {nodeId,
1538 connectionMapNumber,
1539 sourceCircuitPackName,
1545 String query = Queries.getQuery().deviceConnectionMapInsert().get();
1546 LOG.info("Running {} query ", query);
1547 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1548 for (int j = 0; j < parameters.length; j++) {
1549 stmt.setObject(j + 1, parameters[j]);
1552 stmt.clearParameters();
1553 } catch (SQLException e) {
1554 LOG.error("Something wrong when storing devices connection map", e);
1560 private void persistDevWavelengthMap(String nodeId, Connection connection) {
1563 String wavelengthNumber="", centerFrequency="", wavelength="";;
1565 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1566 Optional<OrgOpenroadmDevice> deviceObject =
1567 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1568 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1571 String startTimestamp = getCurrentTimestamp();
1572 for (int i = 0; i<deviceObject.get().getWavelengthMap().getWavelengths().size(); i++) {
1573 Wavelengths wavelengths = deviceObject.get().getWavelengthMap().getWavelengths().get(i);
1574 wavelengthNumber=wavelengths.getWavelengthNumber().toString();
1575 centerFrequency=wavelengths.getCenterFrequency().toString();
1576 wavelength=wavelengths.getWavelength().toString();
1579 Object[] parameters = {nodeId,
1587 String query = Queries.getQuery().deviceWavelengthInsert().get();
1588 LOG.info("Running {} query ", query);
1589 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1590 for (int j = 0; j < parameters.length; j++) {
1591 stmt.setObject(j + 1, parameters[j]);
1594 stmt.clearParameters();
1595 } catch (SQLException e) {
1596 LOG.error("Something wrong when storing devices wavelength map", e);
1604 private void persistDevInterfaceTcm(String nodeId, String interfaceName, OduBuilder oduBuilder,
1605 Connection connection) {
1607 Map<TcmKey, Tcm> tcmMap = oduBuilder.getTcm();
1608 for (Map.Entry<TcmKey, Tcm> entry : tcmMap.entrySet()) {
1609 Tcm tcm = entry.getValue();
1611 Object[] parameters = prepareDevInterfaceTcmParameters(nodeId, interfaceName, tcm);
1613 String query = Queries.getQuery().deviceInterfacesInsert().get();
1614 LOG.info("Running {} query ", query);
1615 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1616 for (int j = 0; j < parameters.length; j++) {
1617 stmt.setObject(j + 1, parameters[j]);
1620 stmt.clearParameters();
1621 } catch (SQLException e) {
1622 LOG.error("Something wrong when storing devices interface tcm", e);
1627 private void persistDevInterfaceOtnOduTxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1628 Connection connection) {
1630 Map<TxMsiKey, TxMsi> txMsi2Map = oduBuilder.getOpu().getMsi().getTxMsi();
1631 if (txMsi2Map == null) {
1632 LOG.error("Null txMsi2Map for node {}", nodeId);
1635 for (Map.Entry<TxMsiKey, TxMsi> entry : txMsi2Map.entrySet()) {
1636 TxMsi txMsi = entry.getValue();
1637 Object[] parameters = prepareDevInterfaceOtnOduTxMsiParameters(nodeId, interfaceName, txMsi);
1639 String query = Queries.getQuery().deviceInterfaceOtnOduTxMsiInsert().get();
1640 LOG.info("Running {} query ", query);
1641 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1642 for (int j = 0; j < parameters.length; j++) {
1643 stmt.setObject(j + 1, parameters[j]);
1646 stmt.clearParameters();
1647 } catch (SQLException e) {
1648 LOG.error("Something wrong when storing devices interface OTN ODU Tx MSI", e);
1654 private void persistDevInterfaceOtnOduRxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1655 Connection connection) {
1657 Map<RxMsiKey, RxMsi> rxMsi2Map = oduBuilder.getOpu().getMsi().getRxMsi();
1658 if (rxMsi2Map == null) {
1659 LOG.error("Null rxMsi2Map for node {}", nodeId);
1662 for (Map.Entry<RxMsiKey, RxMsi> entry : rxMsi2Map.entrySet()) {
1663 RxMsi rxMsi = entry.getValue();
1665 Object[] parameters = prepareDevInterfaceOtnOduRxMsiParameters(nodeId, interfaceName, rxMsi);
1667 String query = Queries.getQuery().deviceInterfaceOtnOduRxMsiInsert().get();
1668 LOG.info("Running {} query ", query);
1669 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1670 for (int j = 0; j < parameters.length; j++) {
1671 stmt.setObject(j + 1, parameters[j]);
1674 stmt.clearParameters();
1675 } catch (SQLException e) {
1676 LOG.error("Something wrong when storing devices interface OTN ODU Rx MSI", e);
1682 private void persistDevInterfaceOtnOduExpMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1683 Connection connection) {
1685 Map<ExpMsiKey, ExpMsi> expMsi2Map = oduBuilder.getOpu().getMsi().getExpMsi();
1686 if (expMsi2Map == null) {
1687 LOG.error("Null expMsi2Map for node {}", nodeId);
1690 for (Map.Entry<ExpMsiKey, ExpMsi> entry : expMsi2Map.entrySet()) {
1691 ExpMsi expMsi = entry.getValue();
1693 Object[] parameters = prepareDevInterfaceOtnOduExpMsiParameters(nodeId, interfaceName, expMsi);
1695 String query = Queries.getQuery().deviceInterfaceOtnOduExpMsiInsert().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]);
1702 stmt.clearParameters();
1703 } catch (SQLException e) {
1704 LOG.error("Something wrong when storing devices interface OTN ODU Exp MSI", e);