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;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
24 public class RemoteActionRegistryMXBeanImpl extends AbstractRegistryMXBean<ActionRoutingTable, DOMActionInstance>
25 implements RemoteActionRegistryMXBean {
27 public RemoteActionRegistryMXBeanImpl(final BucketStoreAccess actionRegistryAccess, final Timeout timeout) {
28 super("RemoteActionRegistry", "RemoteActionBroker", actionRegistryAccess, timeout);
32 public Set<String> getLocalRegisteredAction() {
33 ActionRoutingTable table = localData();
34 Set<String> routedAction = new HashSet<>(table.getItems().size());
35 for (DOMActionInstance route : table.getItems()) {
36 final YangInstanceIdentifier actionPath = YangInstanceIdentifier.create(new NodeIdentifier(
37 route.getType().lastNodeIdentifier()));
38 if (!actionPath.isEmpty()) {
39 routedAction.add(ROUTE_CONSTANT + actionPath + NAME_CONSTANT + route.getType());
43 log.debug("Locally registered routed RPCs {}", routedAction);
48 public Map<String, String> findActionByName(final String name) {
49 ActionRoutingTable localTable = localData();
50 // Get all Actions from local bucket
51 Map<String, String> rpcMap = new HashMap<>(getActionMemberMapByName(localTable, name, LOCAL_CONSTANT));
53 // Get all Actions from remote bucket
54 Map<Address, Bucket<ActionRoutingTable>> buckets = remoteBuckets();
55 for (Map.Entry<Address, Bucket<ActionRoutingTable>> entry : buckets.entrySet()) {
56 ActionRoutingTable table = entry.getValue().getData();
57 rpcMap.putAll(getActionMemberMapByName(table, name, entry.getKey().toString()));
60 log.debug("list of Actions {} searched by name {}", rpcMap, name);
65 public Map<String, String> findActionByRoute(final String routeId) {
66 ActionRoutingTable localTable = localData();
67 Map<String, String> rpcMap = new HashMap<>(getActionMemberMapByAction(localTable, routeId, LOCAL_CONSTANT));
69 Map<Address, Bucket<ActionRoutingTable>> buckets = remoteBuckets();
70 for (Map.Entry<Address, Bucket<ActionRoutingTable>> entry : buckets.entrySet()) {
71 ActionRoutingTable table = entry.getValue().getData();
72 rpcMap.putAll(getActionMemberMapByAction(table, routeId, entry.getKey().toString()));
75 log.debug("list of Actions {} searched by route {}", rpcMap, routeId);
80 * Search if the routing table route String contains routeName.
82 private static Map<String, String> getActionMemberMapByAction(final ActionRoutingTable table,
83 final String routeName, final String address) {
84 Collection<DOMActionInstance> routes = table.getItems();
85 Map<String, String> actionMap = new HashMap<>(routes.size());
86 for (DOMActionInstance route : routes) {
87 final YangInstanceIdentifier actionPath = YangInstanceIdentifier.create(new NodeIdentifier(
88 route.getType().lastNodeIdentifier()));
89 if (!actionPath.isEmpty()) {
90 String routeString = actionPath.toString();
91 if (routeString.contains(routeName)) {
92 actionMap.put(ROUTE_CONSTANT + routeString + NAME_CONSTANT + route.getType(), address);
100 * Search if the routing table route type contains name.
102 private static Map<String, String> getActionMemberMapByName(final ActionRoutingTable table, final String name,
103 final String address) {
104 Collection<DOMActionInstance> routes = table.getItems();
105 Map<String, String> actionMap = new HashMap<>(routes.size());
106 for (DOMActionInstance route : routes) {
107 final YangInstanceIdentifier actionPath = YangInstanceIdentifier.create(new NodeIdentifier(
108 route.getType().lastNodeIdentifier()));
109 if (!actionPath.isEmpty()) {
110 String type = route.getType().toString();
111 if (type.contains(name)) {
112 actionMap.put(ROUTE_CONSTANT + actionPath + NAME_CONSTANT + type, address);
120 public String getBucketVersions() {
121 return bucketVersions();