2 * Copyright © 2024 Orange, Inc. 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
8 package org.opendaylight.transportpce.tapi.impl.rpc;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.HashMap;
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.get.topology.list.output.TopologyBuilder;
19 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology;
20 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.TopologyKey;
21 import org.opendaylight.yangtools.yang.common.ErrorType;
22 import org.opendaylight.yangtools.yang.common.RpcResult;
23 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 public class GetTopologyListImpl implements GetTopologyList {
29 private static final Logger LOG = LoggerFactory.getLogger(GetTopologyListImpl.class);
30 private final TapiContext tapiContext;
32 public GetTopologyListImpl(TapiContext tapiContext) {
33 this.tapiContext = tapiContext;
37 public ListenableFuture<RpcResult<GetTopologyListOutput>> invoke(GetTopologyListInput input) {
38 // TODO Auto-generated method stub
39 // TODO -> maybe we get errors when having CEPs?
40 Map<TopologyKey, Topology> 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")
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 (Topology topo : topologyMap.values()) {
51 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.topology.list.output.Topology
52 newTopo = new TopologyBuilder(topo).build();
53 newTopoMap.put(newTopo.key(), newTopo);
55 return RpcResultBuilder
56 .success(new GetTopologyListOutputBuilder().setTopology(newTopoMap).build())