Refactor some small TAPI rpcs
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / impl / rpc / GetNodeEdgePointDetailsImpl.java
1 /*
2  * Copyright © 2024 Orange, Inc. 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.tapi.impl.rpc;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import org.opendaylight.transportpce.tapi.utils.TapiContext;
12 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetNodeEdgePointDetails;
13 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetNodeEdgePointDetailsInput;
14 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetNodeEdgePointDetailsOutput;
15 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetNodeEdgePointDetailsOutputBuilder;
16 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.node.edge.point.details.output.NodeEdgePointBuilder;
17 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePoint;
18 import org.opendaylight.yangtools.yang.common.ErrorType;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24
25 public class GetNodeEdgePointDetailsImpl implements GetNodeEdgePointDetails {
26     private static final Logger LOG = LoggerFactory.getLogger(GetNodeEdgePointDetailsImpl.class);
27     private final TapiContext tapiContext;
28
29     public GetNodeEdgePointDetailsImpl(TapiContext tapiContext) {
30         this.tapiContext = tapiContext;
31     }
32
33     @Override
34     public ListenableFuture<RpcResult<GetNodeEdgePointDetailsOutput>> invoke(GetNodeEdgePointDetailsInput input) {
35         // TODO Auto-generated method stub
36         // TODO -> maybe we get errors when having CEPs?
37         // Node id: if roadm -> ROADMid+PHOTONIC_MEDIA. if xpdr -> XPDRid-XPDRnbr+DSR/OTSi
38         // NEP id: if roadm -> ROADMid+PHOTONIC_MEDIA/MC/OTSiMC+TPid.
39         // if xpdr -> XPDRid-XPDRnbr+DSR/eODU/iODU/iOTSi/eOTSi/PHOTONIC_MEDIA+TPid
40         OwnedNodeEdgePoint nep =
41             this.tapiContext.getTapiNEP(input.getTopologyId(), input.getNodeId(), input.getNodeEdgePointId());
42         if (nep == null) {
43             LOG.error("Invalid TAPI nep name");
44             return RpcResultBuilder.<GetNodeEdgePointDetailsOutput>failed()
45                 .withError(ErrorType.RPC, "Invalid NEP name")
46                 .buildFuture();
47         }
48         return RpcResultBuilder
49                 .success(new GetNodeEdgePointDetailsOutputBuilder()
50                         .setNodeEdgePoint(new NodeEdgePointBuilder(nep).build())
51                         .build())
52                 .buildFuture();
53     }
54
55 }