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.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;
26 public class GetTopologyListImpl implements GetTopologyList {
27 private static final Logger LOG = LoggerFactory.getLogger(GetTopologyListImpl.class);
28 private final TapiContext tapiContext;
30 public GetTopologyListImpl(TapiContext tapiContext) {
31 this.tapiContext = tapiContext;
35 public ListenableFuture<RpcResult<GetTopologyListOutput>> invoke(GetTopologyListInput input) {
36 // TODO Auto-generated method stub
37 // TODO -> maybe we get errors when having CEPs?
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")
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);
57 return RpcResultBuilder
58 .success(new GetTopologyListOutputBuilder().setTopology(newTopoMap).build())