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