Abort power setup if setting gainloss fails
[transportpce.git] / olm / src / main / java / org / opendaylight / transportpce / olm / util / OlmUtils.java
1 /*
2  * Copyright © 2017 AT&T and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.olm.util;
9
10 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
11 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
12 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutputBuilder;
13 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.OpenroadmNodeVersion;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public final class OlmUtils {
18
19     private static final Logger LOG = LoggerFactory.getLogger(OlmUtils.class);
20     private static long DATABROKER_READ_TIMEOUT_SECONDS = 120;
21
22
23     /**
24      * This method retrieves list of current PMs for given nodeId,
25      * resourceType, resourceName and Granularity.Currently vendorExtentions
26      * are excluded but can be added back based on requirement
27      *
28      * <p>
29      * 1. pmFetch This operation traverse through current PM list and gets PM for
30      * given NodeId and Resource name
31      *
32      * @param input
33      *            Input parameter from the olm yang model get-pm rpc
34      * @param deviceTransactionManager
35      *            Device tx manager
36      * @param openRoadmVersion
37      *            OpenRoadm version number
38      *
39      * @return Result of the request list of PM readings
40      */
41     public static GetPmOutputBuilder pmFetch(GetPmInput input, DeviceTransactionManager deviceTransactionManager,
42                                              OpenroadmNodeVersion openRoadmVersion) {
43         LOG.info("Getting PM Data for NodeId: {} ResourceType: {} ResourceName: {}", input.getNodeId(),
44             input.getResourceType(), input.getResourceIdentifier());
45         GetPmOutputBuilder pmOutputBuilder;
46         switch (openRoadmVersion.getIntValue()) {
47             case 1:
48                 pmOutputBuilder = OlmUtils121.pmFetch(input, deviceTransactionManager);
49                 break;
50             case 2:
51                 pmOutputBuilder = OlmUtils221.pmFetch(input, deviceTransactionManager);
52                 break;
53             case 3:
54                 pmOutputBuilder = OlmUtils710.pmFetch(input, deviceTransactionManager);
55                 break;
56             default:
57                 LOG.error("Unrecognized OpenRoadm version");
58                 pmOutputBuilder = new GetPmOutputBuilder();
59         }
60         return pmOutputBuilder;
61     }
62
63     private OlmUtils() {
64     }
65
66 }