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.isProactiveDelayMeasurementEnabled().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().isEnabled().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().isEnabled().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.isLtcActEnabled().toString();
796 String proactiveDelayMeasurementEnabled = tcm.isProactiveDelayMeasurementEnabled().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");
1050 String startTimestamp = getCurrentTimestamp();
1052 Map<IfNameKey, IfName> ifNameMap = protocolObject.get()
1053 .augmentation(Protocols1.class).getLldp().getNbrList().nonnullIfName();
1054 for (Map.Entry<IfNameKey, IfName> entry : ifNameMap.entrySet()) {
1056 IfName ifNameObj = entry.getValue();
1057 String ifName = ifNameObj.getIfName();
1058 String remotesysname = ifNameObj.getRemoteSysName();
1059 String remotemgmtaddresssubtype = ifNameObj.getRemoteMgmtAddressSubType().getName();
1060 String remotemgmtaddress = ifNameObj.getRemoteMgmtAddress().getIpv4Address().toString();
1061 int remoteportidsubtypeEnu = ifNameObj.getRemotePortIdSubType().getIntValue();
1062 String remoteportid = ifNameObj.getRemotePortId();
1063 int remotechassisidsubtypeEnu = ifNameObj.getRemoteChassisIdSubType().getIntValue();
1064 String remotechassisid = ifNameObj.getRemoteChassisId();
1066 Object[] parameters = {nodeId,
1069 remotemgmtaddresssubtype,
1071 Integer.toString(remoteportidsubtypeEnu),
1073 Integer.toString(remotechassisidsubtypeEnu),
1079 String query = Queries.getQuery().deviceProtocolLldpNbrlistInsert().get();
1080 LOG.info("Running {} query ", query);
1081 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1082 for (int j = 0; j < parameters.length; j++) {
1083 stmt.setObject(j + 1, parameters[j]);
1086 stmt.clearParameters();
1087 } catch (SQLException e) {
1088 LOG.error("Something wrong when storing devices protocols LLDP list number in DB", e);
1094 private void persistDevInternalLinks(String nodeId, Connection connection) {
1096 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1097 Optional<OrgOpenroadmDevice> deviceObject =
1098 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1099 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1100 if (!deviceObject.isPresent()) {
1101 LOG.error("Device with node id {} not found", nodeId);
1105 String startTimestamp = getCurrentTimestamp();
1107 Map<InternalLinkKey, InternalLink> internalLinkMap = deviceObject.get().nonnullInternalLink();
1108 for (Map.Entry<InternalLinkKey, InternalLink> entry : internalLinkMap.entrySet()) {
1109 InternalLink internalLink = entry.getValue();
1110 String internalLinkName = internalLink.getInternalLinkName();
1111 String sourceCircuitPackName = internalLink.getSource().getCircuitPackName();
1112 String sourcePortName = internalLink.getSource().getPortName().toString();
1113 String destinationCircuitPackName = internalLink.getDestination().getCircuitPackName();
1114 String destinationPortName = internalLink.getDestination().getPortName().toString();
1116 Object[] parameters = {nodeId,
1118 sourceCircuitPackName,
1120 destinationCircuitPackName,
1121 destinationPortName,
1126 String query = Queries.getQuery().deviceInternalLinkInsert().get();
1127 LOG.info("Running {} query ", query);
1128 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1129 for (int j = 0; j < parameters.length; j++) {
1130 stmt.setObject(j + 1, parameters[j]);
1133 stmt.clearParameters();
1134 } catch (SQLException e) {
1135 LOG.error("Something wrong when storing devices internal links", e);
1142 private void persistDevExternalLinks(String nodeId, Connection connection) {
1144 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1145 Optional<OrgOpenroadmDevice> deviceObject =
1146 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1147 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1148 if (!deviceObject.isPresent()) {
1149 LOG.error("Device with node id {} not found", nodeId);
1153 String startTimestamp = getCurrentTimestamp();
1155 Map<ExternalLinkKey, ExternalLink> externalLinkMap = deviceObject.get().nonnullExternalLink();
1156 for (Map.Entry<ExternalLinkKey, ExternalLink> entry : externalLinkMap.entrySet()) {
1157 ExternalLink externalLink = entry.getValue();
1158 String externalLinkName = externalLink.getExternalLinkName();
1159 String sourceNodeId = externalLink.getSource().getNodeId();
1160 String sourceCircuitPackName = externalLink.getSource().getCircuitPackName();
1161 String sourcePortName = externalLink.getSource().getPortName();
1162 String destinationNodeId = externalLink.getDestination().getNodeId();
1163 String destinationCircuitPackName = externalLink.getDestination().getCircuitPackName();
1164 String destinationPortName = externalLink.getDestination().getPortName();
1166 Object[] parameters = {nodeId,
1169 sourceCircuitPackName,
1172 destinationCircuitPackName,
1173 destinationPortName,
1178 String query = Queries.getQuery().deviceExternalLinkInsert().get();
1179 LOG.info("Running {} query ", query);
1180 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1181 for (int j = 0; j < parameters.length; j++) {
1182 stmt.setObject(j + 1, parameters[j]);
1185 stmt.clearParameters();
1186 } catch (SQLException e) {
1187 LOG.error("Something wrong when storing devices external links", e);
1193 private void persistDevPhysicalLinks(String nodeId, Connection connection) {
1195 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1196 Optional<OrgOpenroadmDevice> deviceObject =
1197 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1198 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1199 if (!deviceObject.isPresent()) {
1200 LOG.error("Device with node id {} not found", nodeId);
1204 String startTimestamp = getCurrentTimestamp();
1206 Map<PhysicalLinkKey, PhysicalLink> physicalLinkMap = deviceObject.get().nonnullPhysicalLink();
1207 for (Map.Entry<PhysicalLinkKey, PhysicalLink> entry : physicalLinkMap.entrySet()) {
1208 PhysicalLink physicalLink = entry.getValue();
1209 String physicalLinkName = physicalLink.getPhysicalLinkName();
1210 String sourceCircuitPackName = physicalLink.getSource().getCircuitPackName();
1211 String sourcePortName = physicalLink.getSource().getPortName().toString();
1212 String destinationCircuitPackName = physicalLink.getDestination().getCircuitPackName();
1213 String destinationPortName = physicalLink.getDestination().getPortName().toString();
1215 Object[] parameters = {nodeId,
1217 sourceCircuitPackName,
1219 destinationCircuitPackName,
1220 destinationPortName,
1225 String query = Queries.getQuery().devicePhysicalLinkInsert().get();
1226 LOG.info("Running {} query ", query);
1227 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1228 for (int j = 0; j < parameters.length; j++) {
1229 stmt.setObject(j + 1, parameters[j]);
1232 stmt.clearParameters();
1233 } catch (SQLException e) {
1234 LOG.error("Something wrong when storing devices physical links", e);
1240 private void persistDevDegree(String nodeId, Connection connection) {
1242 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1243 Optional<OrgOpenroadmDevice> deviceObject =
1244 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1245 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1246 if (!deviceObject.isPresent()) {
1247 LOG.error("Device with node id {} not found", nodeId);
1251 String startTimestamp = getCurrentTimestamp();
1253 Map<DegreeKey, Degree> degreeMap = deviceObject.get().nonnullDegree();
1254 for (Map.Entry<DegreeKey, Degree> entry : degreeMap.entrySet()) {
1255 Degree degree = entry.getValue();
1256 String degreeNumber = degree.getDegreeNumber().toString();
1257 String maxWavelengths = degree.getMaxWavelengths().toString();
1258 String otdrPortCircuitPackName = degree.getOtdrPort().getCircuitPackName();
1259 String otdrPortPortName = degree.getOtdrPort().getPortName().toString();
1260 persistDevDegreeCircuitPack(nodeId, degree, degreeNumber, connection);
1261 persistDevDegreeConnectionPort(nodeId, degree, degreeNumber, connection);
1262 //String mcCapabilitiesSlotWidthGranularity = "";
1263 //String mcCapabilitiesCenterFreqGranularity = "";
1264 //String mcCapabilitiesMinSlots = "";
1265 //String mcCapabilitiesMaxSlots = "";
1267 Object[] parameters = {nodeId,
1270 otdrPortCircuitPackName,
1272 //mcCapabilitiesSlotWidthGranularity,
1273 //mcCapabilitiesCenterFreqGranularity,
1274 //mcCapabilitiesMinSlots,
1275 //mcCapabilitiesMaxSlots,
1281 String query = Queries.getQuery().deviceDegreeInsert().get();
1282 LOG.info("Running {} query ", query);
1283 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1284 for (int j = 0; j < parameters.length; j++) {
1285 stmt.setObject(j + 1, parameters[j]);
1288 stmt.clearParameters();
1289 } catch (SQLException e) {
1290 LOG.error("Something wrong when storing devices degrees", e);
1297 private void persistDevDegreeCircuitPack(String nodeId, Degree degree, String degreeNumber, Connection connection) {
1299 String startTimestamp = getCurrentTimestamp();
1301 Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1302 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks>
1303 circuitPacksMap = degree.nonnullCircuitPacks();
1304 for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacksKey,
1305 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.CircuitPacks> entry :
1306 circuitPacksMap.entrySet()) {
1309 String circuitPackIndex = entry.getValue().getIndex().toString();
1310 String circuitPackName = entry.getValue().getCircuitPackName();
1312 Object[] parameters = {nodeId,
1320 String query = Queries.getQuery().deviceDegreeCircuitPackInsert().get();
1321 LOG.info("Running {} query ", query);
1322 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1323 for (int j = 0; j < parameters.length; j++) {
1324 stmt.setObject(j + 1, parameters[j]);
1327 stmt.clearParameters();
1328 } catch (SQLException e) {
1329 LOG.error("Something wrong when storing devices degrees circuit packs", e);
1335 private void persistDevDegreeConnectionPort(String nodeId, Degree degree, String degreeNumber,
1336 Connection connection) {
1338 String startTimestamp = getCurrentTimestamp();
1340 Map<ConnectionPortsKey, ConnectionPorts> connectionPortsMap = degree.nonnullConnectionPorts();
1341 for (Map.Entry<ConnectionPortsKey, ConnectionPorts> entry : connectionPortsMap.entrySet()) {
1343 ConnectionPorts connectionPorts = entry.getValue();
1344 String connectionPortIndex = connectionPorts.getIndex().toString();
1345 String circuitPackName = connectionPorts.getCircuitPackName();
1346 String portName = connectionPorts.getPortName().toString();
1348 Object[] parameters = {nodeId,
1350 connectionPortIndex,
1357 String query = Queries.getQuery().deviceDegreeConnectionPortInsert().get();
1358 LOG.info("Running {} query ", query);
1359 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1360 for (int j = 0; j < parameters.length; j++) {
1361 stmt.setObject(j + 1, parameters[j]);
1364 stmt.clearParameters();
1365 } catch (SQLException e) {
1366 LOG.error("Something wrong when storing devices degrees connection ports", e);
1373 private void persistDevSrg(String nodeId, Connection connection) {
1375 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1376 Optional<OrgOpenroadmDevice> deviceObject =
1377 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1378 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1379 if (!deviceObject.isPresent()) {
1380 LOG.error("Device with node id {} not found", nodeId);
1384 String startTimestamp = getCurrentTimestamp();
1386 Map<SharedRiskGroupKey, SharedRiskGroup> sharedRiskGroupMap = deviceObject.get().nonnullSharedRiskGroup();
1387 for (Map.Entry<SharedRiskGroupKey, SharedRiskGroup> entry : sharedRiskGroupMap.entrySet()) {
1388 SharedRiskGroup sharedRiskGroup = entry.getValue();
1389 String maxAddDropPorts = sharedRiskGroup.getMaxAddDropPorts().toString();
1390 String srgNumber = sharedRiskGroup.getSrgNumber().toString();
1391 //int wavelengthDuplicationEnu = sharedRiskGroup.getWavelengthDuplication().getIntValue();
1392 persistDevSrgCircuitPacks(nodeId, sharedRiskGroup, srgNumber, connection);
1393 //String currentProvisionedAddDropPorts = "";
1394 //String mcCapSlotWidthGranularity = "";
1395 //String mcCapCenterFreqGranularity = "";
1396 //String mcCapMinSlots = "";
1397 //String mcCapMaxSlots = "";
1399 Object[] parameters = {nodeId,
1401 //currentProvisionedAddDropPorts,
1404 //mcCapSlotWidthGranularity,
1405 //mcCapCenterFreqGranularity,
1413 String query = Queries.getQuery().deviceSharedRiskGroupInsert().get();
1414 LOG.info("Running {} query ", query);
1415 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1416 for (int j = 0; j < parameters.length; j++) {
1417 stmt.setObject(j + 1, parameters[j]);
1420 stmt.clearParameters();
1421 } catch (SQLException e) {
1422 LOG.error("Something wrong when storing devices SRG", e);
1428 private void persistDevSrgCircuitPacks(String nodeId, SharedRiskGroup sharedRiskGroup, String srgNumber,
1429 Connection connection) {
1431 String startTimestamp = getCurrentTimestamp();
1433 Map<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1434 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>
1435 circuitPacksMap = sharedRiskGroup.nonnullCircuitPacks();
1436 for (Map.Entry<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacksKey,
1437 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> entry :
1438 circuitPacksMap.entrySet()) {
1440 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks circuitPack =
1442 String circuitPackindex = circuitPack.getIndex().toString();
1443 String circuitPackName = circuitPack.getCircuitPackName();
1445 Object[] parameters = {nodeId,
1453 String query = Queries.getQuery().deviceSrgCircuitPackInsert().get();
1454 LOG.info("Running {} query ", query);
1455 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1456 for (int j = 0; j < parameters.length; j++) {
1457 stmt.setObject(j + 1, parameters[j]);
1460 stmt.clearParameters();
1461 } catch (SQLException e) {
1462 LOG.error("Something wrong when storing devices SRG circuit packs", e);
1468 private void persistDevRoadmConnections(String nodeId, Connection connection) {
1470 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1471 Optional<OrgOpenroadmDevice> deviceObject =
1472 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1473 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1474 if (!deviceObject.isPresent()) {
1475 LOG.error("Device with node id {} not found", nodeId);
1479 String startTimestamp = getCurrentTimestamp();
1481 Map<RoadmConnectionsKey, RoadmConnections> roadmConnectionsMap = deviceObject.get().nonnullRoadmConnections();
1482 for (Map.Entry<RoadmConnectionsKey, RoadmConnections> entry : roadmConnectionsMap.entrySet()) {
1483 RoadmConnections roadmConnections = entry.getValue();
1484 int opticalcontrolmodeEnu = roadmConnections.getOpticalControlMode().getIntValue();
1485 //String connectionName = "";
1486 //String connectionNumber = "";
1487 //String wavelengthNumber = "";
1488 String targetOutputPower = roadmConnections.getTargetOutputPower().toString();
1489 String srcIf = roadmConnections.getSource().getSrcIf();
1490 String dstIf = roadmConnections.getDestination().getDstIf();
1492 Object[] parameters = {nodeId,
1497 Integer.toString(opticalcontrolmodeEnu),
1506 String query = Queries.getQuery().deviceRoadmConnectionsInsert().get();
1507 LOG.info("Running {} query ", query);
1508 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1509 for (int j = 0; j < parameters.length; j++) {
1510 stmt.setObject(j + 1, parameters[j]);
1513 stmt.clearParameters();
1514 } catch (SQLException e) {
1515 LOG.error("Something wrong when storing devices ROADM connection ", e);
1522 private void persistDevConnectionMap(String nodeId, Connection connection) {
1524 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1525 Optional<OrgOpenroadmDevice> deviceObject =
1526 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1527 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1528 if (!deviceObject.isPresent()) {
1529 LOG.error("Device with node id {} not found", nodeId);
1532 String startTimestamp = getCurrentTimestamp();
1534 Map<ConnectionMapKey, ConnectionMap> connectionMapMap = deviceObject.get().nonnullConnectionMap();
1535 for (Map.Entry<ConnectionMapKey, ConnectionMap> entry : connectionMapMap.entrySet()) {
1536 ConnectionMap connectionMap = entry.getValue();
1537 String connectionMapNumber = connectionMap.getConnectionMapNumber().toString();
1538 String sourceCircuitPackName = connectionMap.getSource().getCircuitPackName();
1539 String sourcePortName = connectionMap.getSource().getCircuitPackName();
1542 Object[] parameters = {nodeId,
1543 connectionMapNumber,
1544 sourceCircuitPackName,
1550 String query = Queries.getQuery().deviceConnectionMapInsert().get();
1551 LOG.info("Running {} query ", query);
1552 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1553 for (int j = 0; j < parameters.length; j++) {
1554 stmt.setObject(j + 1, parameters[j]);
1557 stmt.clearParameters();
1558 } catch (SQLException e) {
1559 LOG.error("Something wrong when storing devices connection map", e);
1565 private void persistDevWavelengthMap(String nodeId, Connection connection) {
1568 String wavelengthNumber="", centerFrequency="", wavelength="";;
1570 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
1571 Optional<OrgOpenroadmDevice> deviceObject =
1572 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
1573 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1576 String startTimestamp = getCurrentTimestamp();
1577 for (int i = 0; i<deviceObject.get().getWavelengthMap().getWavelengths().size(); i++) {
1578 Wavelengths wavelengths = deviceObject.get().getWavelengthMap().getWavelengths().get(i);
1579 wavelengthNumber=wavelengths.getWavelengthNumber().toString();
1580 centerFrequency=wavelengths.getCenterFrequency().toString();
1581 wavelength=wavelengths.getWavelength().toString();
1584 Object[] parameters = {nodeId,
1592 String query = Queries.getQuery().deviceWavelengthInsert().get();
1593 LOG.info("Running {} query ", query);
1594 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1595 for (int j = 0; j < parameters.length; j++) {
1596 stmt.setObject(j + 1, parameters[j]);
1599 stmt.clearParameters();
1600 } catch (SQLException e) {
1601 LOG.error("Something wrong when storing devices wavelength map", e);
1609 private void persistDevInterfaceTcm(String nodeId, String interfaceName, OduBuilder oduBuilder,
1610 Connection connection) {
1612 Map<TcmKey, Tcm> tcmMap = oduBuilder.getTcm();
1613 for (Map.Entry<TcmKey, Tcm> entry : tcmMap.entrySet()) {
1614 Tcm tcm = entry.getValue();
1616 Object[] parameters = prepareDevInterfaceTcmParameters(nodeId, interfaceName, tcm);
1618 String query = Queries.getQuery().deviceInterfacesInsert().get();
1619 LOG.info("Running {} query ", query);
1620 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1621 for (int j = 0; j < parameters.length; j++) {
1622 stmt.setObject(j + 1, parameters[j]);
1625 stmt.clearParameters();
1626 } catch (SQLException e) {
1627 LOG.error("Something wrong when storing devices interface tcm", e);
1632 private void persistDevInterfaceOtnOduTxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1633 Connection connection) {
1635 Map<TxMsiKey, TxMsi> txMsi2Map = oduBuilder.getOpu().getMsi().getTxMsi();
1636 if (txMsi2Map == null) {
1637 LOG.error("Null txMsi2Map for node {}", nodeId);
1640 for (Map.Entry<TxMsiKey, TxMsi> entry : txMsi2Map.entrySet()) {
1641 TxMsi txMsi = entry.getValue();
1642 Object[] parameters = prepareDevInterfaceOtnOduTxMsiParameters(nodeId, interfaceName, txMsi);
1644 String query = Queries.getQuery().deviceInterfaceOtnOduTxMsiInsert().get();
1645 LOG.info("Running {} query ", query);
1646 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1647 for (int j = 0; j < parameters.length; j++) {
1648 stmt.setObject(j + 1, parameters[j]);
1651 stmt.clearParameters();
1652 } catch (SQLException e) {
1653 LOG.error("Something wrong when storing devices interface OTN ODU Tx MSI", e);
1659 private void persistDevInterfaceOtnOduRxMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1660 Connection connection) {
1662 Map<RxMsiKey, RxMsi> rxMsi2Map = oduBuilder.getOpu().getMsi().getRxMsi();
1663 if (rxMsi2Map == null) {
1664 LOG.error("Null rxMsi2Map for node {}", nodeId);
1667 for (Map.Entry<RxMsiKey, RxMsi> entry : rxMsi2Map.entrySet()) {
1668 RxMsi rxMsi = entry.getValue();
1670 Object[] parameters = prepareDevInterfaceOtnOduRxMsiParameters(nodeId, interfaceName, rxMsi);
1672 String query = Queries.getQuery().deviceInterfaceOtnOduRxMsiInsert().get();
1673 LOG.info("Running {} query ", query);
1674 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1675 for (int j = 0; j < parameters.length; j++) {
1676 stmt.setObject(j + 1, parameters[j]);
1679 stmt.clearParameters();
1680 } catch (SQLException e) {
1681 LOG.error("Something wrong when storing devices interface OTN ODU Rx MSI", e);
1687 private void persistDevInterfaceOtnOduExpMsi(String nodeId, String interfaceName, OduBuilder oduBuilder,
1688 Connection connection) {
1690 Map<ExpMsiKey, ExpMsi> expMsi2Map = oduBuilder.getOpu().getMsi().getExpMsi();
1691 if (expMsi2Map == null) {
1692 LOG.error("Null expMsi2Map for node {}", nodeId);
1695 for (Map.Entry<ExpMsiKey, ExpMsi> entry : expMsi2Map.entrySet()) {
1696 ExpMsi expMsi = entry.getValue();
1698 Object[] parameters = prepareDevInterfaceOtnOduExpMsiParameters(nodeId, interfaceName, expMsi);
1700 String query = Queries.getQuery().deviceInterfaceOtnOduExpMsiInsert().get();
1701 LOG.info("Running {} query ", query);
1702 try (PreparedStatement stmt = connection.prepareStatement(query)) {
1703 for (int j = 0; j < parameters.length; j++) {
1704 stmt.setObject(j + 1, parameters[j]);
1707 stmt.clearParameters();
1708 } catch (SQLException e) {
1709 LOG.error("Something wrong when storing devices interface OTN ODU Exp MSI", e);