09e82845f436c2495cbdb76571b55ffd58d0fd4f
[transportpce.git] / olm / src / main / java / org / opendaylight / transportpce / olm / OlmPowerServiceRpcImpl.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
9 package org.opendaylight.transportpce.olm;
10
11 import com.google.common.util.concurrent.ListenableFuture;
12 import org.opendaylight.transportpce.olm.service.OlmPowerService;
13 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseInput;
14 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseOutput;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInput;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentOutput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetInput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetOutput;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
26 import org.opendaylight.yangtools.yang.common.ErrorType;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
29 import org.osgi.service.component.annotations.Activate;
30 import org.osgi.service.component.annotations.Component;
31 import org.osgi.service.component.annotations.Reference;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36  * The Class OlmPowerServiceRpcImpl.
37  */
38 @Component
39 public class OlmPowerServiceRpcImpl implements TransportpceOlmService {
40     private static final Logger LOG = LoggerFactory.getLogger(OlmPowerServiceRpcImpl.class);
41     private final OlmPowerService olmPowerService;
42
43     @Activate
44     public OlmPowerServiceRpcImpl(@Reference OlmPowerService olmPowerService) {
45         this.olmPowerService = olmPowerService;
46     }
47
48     /**
49      * This method is the implementation of the 'get-pm' RESTCONF service, which
50      * is one of the external APIs into the olm application.
51      *
52      * <p>
53      * 1. get-pm This operation traverse through current PM list and gets PM for
54      * given NodeId and Resource name
55      *
56      * <p>
57      * The signature for this method was generated by yang tools from the
58      * olm API model.
59      *
60      * @param input
61      *            Input parameter from the olm yang model
62      *
63      * @return Result of the request
64      */
65     @Override
66     public ListenableFuture<RpcResult<GetPmOutput>> getPm(GetPmInput input) {
67         if (input.getNodeId() == null) {
68             LOG.error("getPm: NodeId can not be null");
69             return RpcResultBuilder.<GetPmOutput>failed()
70                     .withError(ErrorType.RPC, "Error with input parameters")
71                     .buildFuture();
72         }
73         return RpcResultBuilder.success(this.olmPowerService.getPm(input)).buildFuture();
74     }
75
76     /**
77      * This method is the implementation of the 'service-power-setup' RESTCONF service, which
78      * is one of the external APIs into the olm application.
79      *
80      * <p>
81      * 1. service-power-setup: This operation performs following steps:
82      *    Step1: Calculate Spanloss on all links which are part of service.
83      *    TODO Step2: Calculate power levels for each Tp-Id
84      *    TODO Step3: Post power values on roadm connections
85      *
86      * <p>
87      * The signature for this method was generated by yang tools from the
88      * olm API model.
89      *
90      * @param input
91      *            Input parameter from the olm yang model
92      *            Input will contain nodeId and termination point
93      *
94      * @return Result of the request
95      */
96     @Override
97     public ListenableFuture<RpcResult<ServicePowerSetupOutput>> servicePowerSetup(
98             ServicePowerSetupInput input) {
99         return RpcResultBuilder.success(this.olmPowerService.servicePowerSetup(input)).buildFuture();
100     }
101
102     /**
103      * This method is the implementation of the 'service-power-trundown' RESTCONF service, which
104      * is one of the external APIs into the olm application.
105      *
106      * <p>
107      * 1. service-power-turndown: This operation performs following steps:
108      *    Step1: For each TP within Node sets interface outofservice .
109      *    Step2: For each roam-connection sets power to -60dbm
110      *    Step3: Turns power mode off
111      *
112      * <p>
113      * The signature for this method was generated by yang tools from the
114      * olm API model.
115      *
116      * @param input
117      *            Input parameter from the olm yang model
118      *            Input will contain nodeId and termination point
119      *
120      * @return Result of the request
121      */
122     @Override
123     public ListenableFuture<RpcResult<ServicePowerTurndownOutput>>
124         servicePowerTurndown(ServicePowerTurndownInput input) {
125         return RpcResultBuilder.success(this.olmPowerService.servicePowerTurndown(input)).buildFuture();
126     }
127
128     /**
129      * This method calculates Spanloss for all Roadm to Roadm links,
130      * part of active inventory in Network Model or for newly added links
131      * based on input src-type.
132      *
133      * <p>
134      * 1. Calculate-Spanloss-Base: This operation performs following steps:
135      *    Step1: Read all Roadm-to-Roadm links from network model or get data for given linkID.
136      *    Step2: Retrieve PMs for each end point for OTS interface
137      *    Step3: Calculates Spanloss
138      *    Step4: Posts calculated spanloss in Device and in network model
139      *
140      * <p>
141      * The signature for this method was generated by yang tools from the
142      * renderer API model.
143      *
144      * @param input
145      *            Input parameter from the olm yang model
146      *            Input will contain SourceType and linkId if srcType is Link
147      *
148      * @return Result of the request
149      */
150     @Override
151     public ListenableFuture<RpcResult<CalculateSpanlossBaseOutput>>
152         calculateSpanlossBase(CalculateSpanlossBaseInput input) {
153         return RpcResultBuilder.success(this.olmPowerService.calculateSpanlossBase(input)).buildFuture();
154     }
155
156     @Override
157     public ListenableFuture<RpcResult<CalculateSpanlossCurrentOutput>> calculateSpanlossCurrent(
158             CalculateSpanlossCurrentInput input) {
159         return RpcResultBuilder.success(this.olmPowerService.calculateSpanlossCurrent(input)).buildFuture();
160     }
161
162     @Override
163     public ListenableFuture<RpcResult<ServicePowerResetOutput>> servicePowerReset(ServicePowerResetInput input) {
164         return RpcResultBuilder.success(this.olmPowerService.servicePowerReset(input)).buildFuture();
165     }
166 }