Bump upstream dependencies to Ca
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / impl / rpc / GetTopologyListImpl.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 java.util.HashMap;
12 import java.util.Map;
13 import org.opendaylight.transportpce.tapi.utils.TapiContext;
14 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyList;
15 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyListInput;
16 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyListOutput;
17 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyListOutputBuilder;
18 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.TopologyKey;
19 import org.opendaylight.yangtools.yang.common.ErrorType;
20 import org.opendaylight.yangtools.yang.common.RpcResult;
21 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25
26 public class GetTopologyListImpl implements GetTopologyList {
27     private static final Logger LOG = LoggerFactory.getLogger(GetTopologyListImpl.class);
28     private final TapiContext tapiContext;
29
30     public GetTopologyListImpl(TapiContext tapiContext) {
31         this.tapiContext = tapiContext;
32     }
33
34     @Override
35     public ListenableFuture<RpcResult<GetTopologyListOutput>> invoke(GetTopologyListInput input) {
36         // TODO Auto-generated method stub
37         // TODO -> maybe we get errors when having CEPs?
38         Map<TopologyKey,
39                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology>
40                 topologyMap = this.tapiContext.getTopologyContext();
41         if (topologyMap.isEmpty()) {
42             LOG.error("No topologies exist in tapi context");
43             return RpcResultBuilder.<GetTopologyListOutput>failed()
44                 .withError(ErrorType.APPLICATION, "No topologies exist in tapi context")
45                 .buildFuture();
46         }
47         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.topology.list.output.TopologyKey,
48             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.topology.list.output.Topology>
49                 newTopoMap = new HashMap<>();
50         for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology
51                 topo:topologyMap.values()) {
52             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.topology.list.output.Topology
53                 newTopo = new org.opendaylight.yang.gen.v1.urn
54                     .onf.otcc.yang.tapi.topology.rev221121.get.topology.list.output.TopologyBuilder(topo).build();
55             newTopoMap.put(newTopo.key(), newTopo);
56         }
57         return RpcResultBuilder
58                 .success(new GetTopologyListOutputBuilder().setTopology(newTopoMap).build())
59                 .buildFuture();
60     }
61
62 }