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
9 package org.opendaylight.transportpce.olm;
11 import com.google.common.collect.ImmutableClassToInstanceMap;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.mdsal.binding.api.RpcProviderService;
14 import org.opendaylight.transportpce.olm.service.OlmPowerService;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBase;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseInput;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseOutput;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrent;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentOutput;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPm;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerReset;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetInput;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetOutput;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetup;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndown;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
34 import org.opendaylight.yangtools.concepts.Registration;
35 import org.opendaylight.yangtools.yang.binding.Rpc;
36 import org.opendaylight.yangtools.yang.common.ErrorType;
37 import org.opendaylight.yangtools.yang.common.RpcResult;
38 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
39 import org.osgi.service.component.annotations.Activate;
40 import org.osgi.service.component.annotations.Component;
41 import org.osgi.service.component.annotations.Deactivate;
42 import org.osgi.service.component.annotations.Reference;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 * The Class OlmPowerServiceRpcImpl.
50 public class OlmPowerServiceRpcImpl implements TransportpceOlmService {
51 private static final Logger LOG = LoggerFactory.getLogger(OlmPowerServiceRpcImpl.class);
52 private final OlmPowerService olmPowerService;
53 private Registration reg;
56 public OlmPowerServiceRpcImpl(@Reference OlmPowerService olmPowerService,
57 @Reference RpcProviderService rpcProviderService) {
58 this.olmPowerService = olmPowerService;
59 this.reg = rpcProviderService.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
60 .put(GetPm.class, this::getPm)
61 .put(ServicePowerSetup.class, this::servicePowerSetup)
62 .put(ServicePowerTurndown.class, this::servicePowerTurndown)
63 .put(CalculateSpanlossBase.class, this::calculateSpanlossBase)
64 .put(CalculateSpanlossCurrent.class, this::calculateSpanlossCurrent)
65 .put(ServicePowerReset.class, this::servicePowerReset)
67 LOG.info("OlmPowerServiceRpcImpl instantiated");
73 LOG.info("OlmPowerServiceRpcImpl Closed");
77 * This method is the implementation of the 'get-pm' RESTCONF service, which
78 * is one of the external APIs into the olm application.
81 * 1. get-pm This operation traverse through current PM list and gets PM for
82 * given NodeId and Resource name
85 * The signature for this method was generated by yang tools from the
89 * Input parameter from the olm yang model
91 * @return Result of the request
94 public final ListenableFuture<RpcResult<GetPmOutput>> getPm(GetPmInput input) {
95 if (input.getNodeId() == null) {
96 LOG.error("getPm: NodeId can not be null");
97 return RpcResultBuilder.<GetPmOutput>failed()
98 .withError(ErrorType.RPC, "Error with input parameters")
101 return RpcResultBuilder.success(this.olmPowerService.getPm(input)).buildFuture();
105 * This method is the implementation of the 'service-power-setup' RESTCONF service, which
106 * is one of the external APIs into the olm application.
109 * 1. service-power-setup: This operation performs following steps:
110 * Step1: Calculate Spanloss on all links which are part of service.
111 * TODO Step2: Calculate power levels for each Tp-Id
112 * TODO Step3: Post power values on roadm connections
115 * The signature for this method was generated by yang tools from the
119 * Input parameter from the olm yang model
120 * Input will contain nodeId and termination point
122 * @return Result of the request
125 public final ListenableFuture<RpcResult<ServicePowerSetupOutput>> servicePowerSetup(
126 ServicePowerSetupInput input) {
127 return RpcResultBuilder.success(this.olmPowerService.servicePowerSetup(input)).buildFuture();
131 * This method is the implementation of the 'service-power-trundown' RESTCONF service, which
132 * is one of the external APIs into the olm application.
135 * 1. service-power-turndown: This operation performs following steps:
136 * Step1: For each TP within Node sets interface outofservice .
137 * Step2: For each roam-connection sets power to -60dbm
138 * Step3: Turns power mode off
141 * The signature for this method was generated by yang tools from the
145 * Input parameter from the olm yang model
146 * Input will contain nodeId and termination point
148 * @return Result of the request
151 public final ListenableFuture<RpcResult<ServicePowerTurndownOutput>>
152 servicePowerTurndown(ServicePowerTurndownInput input) {
153 return RpcResultBuilder.success(this.olmPowerService.servicePowerTurndown(input)).buildFuture();
157 * This method calculates Spanloss for all Roadm to Roadm links,
158 * part of active inventory in Network Model or for newly added links
159 * based on input src-type.
162 * 1. Calculate-Spanloss-Base: This operation performs following steps:
163 * Step1: Read all Roadm-to-Roadm links from network model or get data for given linkID.
164 * Step2: Retrieve PMs for each end point for OTS interface
165 * Step3: Calculates Spanloss
166 * Step4: Posts calculated spanloss in Device and in network model
169 * The signature for this method was generated by yang tools from the
170 * renderer API model.
173 * Input parameter from the olm yang model
174 * Input will contain SourceType and linkId if srcType is Link
176 * @return Result of the request
179 public final ListenableFuture<RpcResult<CalculateSpanlossBaseOutput>>
180 calculateSpanlossBase(CalculateSpanlossBaseInput input) {
181 return RpcResultBuilder.success(this.olmPowerService.calculateSpanlossBase(input)).buildFuture();
185 public final ListenableFuture<RpcResult<CalculateSpanlossCurrentOutput>> calculateSpanlossCurrent(
186 CalculateSpanlossCurrentInput input) {
187 return RpcResultBuilder.success(this.olmPowerService.calculateSpanlossCurrent(input)).buildFuture();
191 public final ListenableFuture<RpcResult<ServicePowerResetOutput>> servicePowerReset(ServicePowerResetInput input) {
192 return RpcResultBuilder.success(this.olmPowerService.servicePowerReset(input)).buildFuture();
195 public Registration getRegisteredRpc() {