2 * Copyright (c) 2019 Nordix Foundation. 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.controller.remote.rpc.registry.mbeans;
10 import akka.actor.Address;
11 import akka.util.Timeout;
12 import java.util.Collection;
13 import java.util.HashMap;
14 import java.util.HashSet;
17 import org.opendaylight.controller.remote.rpc.registry.ActionRoutingTable;
18 import org.opendaylight.controller.remote.rpc.registry.gossip.Bucket;
19 import org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreAccess;
20 import org.opendaylight.mdsal.dom.api.DOMActionInstance;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 public class RemoteActionRegistryMXBeanImpl extends AbstractRegistryMXBean<ActionRoutingTable, DOMActionInstance>
24 implements RemoteActionRegistryMXBean {
25 public RemoteActionRegistryMXBeanImpl(final BucketStoreAccess actionRegistryAccess, final Timeout timeout) {
26 super("RemoteActionRegistry", "RemoteActionBroker", actionRegistryAccess, timeout);
30 public Set<String> getLocalRegisteredAction() {
31 ActionRoutingTable table = localData();
32 Set<String> routedAction = new HashSet<>(table.getItems().size());
33 for (DOMActionInstance route : table.getItems()) {
34 final YangInstanceIdentifier actionPath = YangInstanceIdentifier.of(route.getType().lastNodeIdentifier());
35 if (!actionPath.isEmpty()) {
36 routedAction.add(ROUTE_CONSTANT + actionPath + NAME_CONSTANT + route.getType());
40 log.debug("Locally registered routed RPCs {}", routedAction);
45 public Map<String, String> findActionByName(final String name) {
46 ActionRoutingTable localTable = localData();
47 // Get all Actions from local bucket
48 Map<String, String> rpcMap = new HashMap<>(getActionMemberMapByName(localTable, name, LOCAL_CONSTANT));
50 // Get all Actions from remote bucket
51 Map<Address, Bucket<ActionRoutingTable>> buckets = remoteBuckets();
52 for (Map.Entry<Address, Bucket<ActionRoutingTable>> entry : buckets.entrySet()) {
53 ActionRoutingTable table = entry.getValue().getData();
54 rpcMap.putAll(getActionMemberMapByName(table, name, entry.getKey().toString()));
57 log.debug("list of Actions {} searched by name {}", rpcMap, name);
62 public Map<String, String> findActionByRoute(final String routeId) {
63 ActionRoutingTable localTable = localData();
64 Map<String, String> rpcMap = new HashMap<>(getActionMemberMapByAction(localTable, routeId, LOCAL_CONSTANT));
66 Map<Address, Bucket<ActionRoutingTable>> buckets = remoteBuckets();
67 for (Map.Entry<Address, Bucket<ActionRoutingTable>> entry : buckets.entrySet()) {
68 ActionRoutingTable table = entry.getValue().getData();
69 rpcMap.putAll(getActionMemberMapByAction(table, routeId, entry.getKey().toString()));
72 log.debug("list of Actions {} searched by route {}", rpcMap, routeId);
77 * Search if the routing table route String contains routeName.
79 private static Map<String, String> getActionMemberMapByAction(final ActionRoutingTable table,
80 final String routeName, final String address) {
81 Collection<DOMActionInstance> routes = table.getItems();
82 Map<String, String> actionMap = new HashMap<>(routes.size());
83 for (DOMActionInstance route : routes) {
84 final YangInstanceIdentifier actionPath = YangInstanceIdentifier.of(route.getType().lastNodeIdentifier());
85 if (!actionPath.isEmpty()) {
86 String routeString = actionPath.toString();
87 if (routeString.contains(routeName)) {
88 actionMap.put(ROUTE_CONSTANT + routeString + NAME_CONSTANT + route.getType(), address);
96 * Search if the routing table route type contains name.
98 private static Map<String, String> getActionMemberMapByName(final ActionRoutingTable table, final String name,
99 final String address) {
100 Collection<DOMActionInstance> routes = table.getItems();
101 Map<String, String> actionMap = new HashMap<>(routes.size());
102 for (DOMActionInstance route : routes) {
103 final YangInstanceIdentifier actionPath = YangInstanceIdentifier.of(route.getType().lastNodeIdentifier());
104 if (!actionPath.isEmpty()) {
105 String type = route.getType().toString();
106 if (type.contains(name)) {
107 actionMap.put(ROUTE_CONSTANT + actionPath + NAME_CONSTANT + type, address);
115 public String getBucketVersions() {
116 return bucketVersions();