2 * Copyright © 2017 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.olm.util;
10 import java.util.Optional;
11 import java.util.concurrent.ExecutionException;
12 import java.util.concurrent.TimeUnit;
13 import java.util.concurrent.TimeoutException;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.mdsal.binding.api.ReadTransaction;
17 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmInput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutputBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.Network;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.Nodes;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.NodesKey;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.NodeInfo.OpenroadmVersion;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public final class OlmUtils {
31 private static final Logger LOG = LoggerFactory.getLogger(OlmUtils.class);
32 private static long DATABROKER_READ_TIMEOUT_SECONDS = 120;
33 public static final long OLM_TIMER_1 = 120000; //#FUNCTESTVAL= 3000;
34 public static final long OLM_TIMER_2 = 20000; //#FUNCTESTVAL= 2000;
37 * This static method returns the port mapping {@link Nodes} for node.
40 * Unique identifier for the mounted netconf node
42 * Databroker used to read data from data store.
43 * @return {@link Nodes } from portMapping for given nodeId
45 public static Optional<Nodes> getNode(String nodeId, DataBroker db) {
46 InstanceIdentifier<Nodes> nodesIID = InstanceIdentifier.create(Network.class)
47 .child(Nodes.class, new NodesKey(nodeId));
48 try (ReadTransaction readTransaction = db.newReadOnlyTransaction()) {
49 return readTransaction.read(LogicalDatastoreType.CONFIGURATION, nodesIID)
50 .get(DATABROKER_READ_TIMEOUT_SECONDS, TimeUnit.SECONDS);
51 } catch (InterruptedException | ExecutionException | TimeoutException ex) {
52 LOG.error("Unable to read Portmapping for nodeId {}", nodeId, ex);
53 return Optional.empty();
58 * This method retrieves list of current PMs for given nodeId,
59 * resourceType, resourceName and Granularity.Currently vendorExtentions
60 * are excluded but can be added back based on requirement
63 * 1. pmFetch This operation traverse through current PM list and gets PM for
64 * given NodeId and Resource name
67 * Input parameter from the olm yang model get-pm rpc
68 * @param deviceTransactionManager
70 * @param openRoadmVersion
71 * OpenRoadm version number
73 * @return Result of the request list of PM readings
75 public static GetPmOutputBuilder pmFetch(GetPmInput input, DeviceTransactionManager deviceTransactionManager,
76 OpenroadmVersion openRoadmVersion) {
77 LOG.info("Getting PM Data for NodeId: {} ResourceType: {} ResourceName: {}", input.getNodeId(),
78 input.getResourceType(), input.getResourceIdentifier());
79 GetPmOutputBuilder pmOutputBuilder = new GetPmOutputBuilder();
80 if (openRoadmVersion.getIntValue() == 1) {
81 pmOutputBuilder = OlmUtils121.pmFetch(input, deviceTransactionManager);
83 pmOutputBuilder = OlmUtils22.pmFetch(input, deviceTransactionManager);
85 return pmOutputBuilder;