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 if (route.getType().getLastComponent() != null) {
37 final YangInstanceIdentifier actionPath = YangInstanceIdentifier.create(
38 new NodeIdentifier(route.getType().getLastComponent()));
39 if (!actionPath.isEmpty()) {
40 routedAction.add(ROUTE_CONSTANT + actionPath + NAME_CONSTANT + route.getType());
45 log.debug("Locally registered routed RPCs {}", routedAction);
50 public Map<String, String> findActionByName(final String name) {
51 ActionRoutingTable localTable = localData();
52 // Get all Actions from local bucket
53 Map<String, String> rpcMap = new HashMap<>(getActionMemberMapByName(localTable, name, LOCAL_CONSTANT));
55 // Get all Actions from remote bucket
56 Map<Address, Bucket<ActionRoutingTable>> buckets = remoteBuckets();
57 for (Map.Entry<Address, Bucket<ActionRoutingTable>> entry : buckets.entrySet()) {
58 ActionRoutingTable table = entry.getValue().getData();
59 rpcMap.putAll(getActionMemberMapByName(table, name, entry.getKey().toString()));
62 log.debug("list of Actions {} searched by name {}", rpcMap, name);
67 public Map<String, String> findActionByRoute(final String routeId) {
68 ActionRoutingTable localTable = localData();
69 Map<String, String> rpcMap = new HashMap<>(getActionMemberMapByAction(localTable, routeId, LOCAL_CONSTANT));
71 Map<Address, Bucket<ActionRoutingTable>> buckets = remoteBuckets();
72 for (Map.Entry<Address, Bucket<ActionRoutingTable>> entry : buckets.entrySet()) {
73 ActionRoutingTable table = entry.getValue().getData();
74 rpcMap.putAll(getActionMemberMapByAction(table, routeId, entry.getKey().toString()));
77 log.debug("list of Actions {} searched by route {}", rpcMap, routeId);
82 * Search if the routing table route String contains routeName.
84 private static Map<String, String> getActionMemberMapByAction(final ActionRoutingTable table,
85 final String routeName, final String address) {
86 Collection<DOMActionInstance> routes = table.getItems();
87 Map<String, String> actionMap = new HashMap<>(routes.size());
88 for (DOMActionInstance route : routes) {
89 if (route.getType().getLastComponent() != null) {
90 final YangInstanceIdentifier actionPath = YangInstanceIdentifier.create(
91 new NodeIdentifier(route.getType().getLastComponent()));
92 if (!actionPath.isEmpty()) {
93 String routeString = actionPath.toString();
94 if (routeString.contains(routeName)) {
95 actionMap.put(ROUTE_CONSTANT + routeString + NAME_CONSTANT + route.getType(), address);
104 * Search if the routing table route type contains name.
106 private static Map<String, String> getActionMemberMapByName(final ActionRoutingTable table, final String name,
107 final String address) {
108 Collection<DOMActionInstance> routes = table.getItems();
109 Map<String, String> actionMap = new HashMap<>(routes.size());
110 for (DOMActionInstance route : routes) {
111 if (route.getType().getLastComponent() != null) {
112 final YangInstanceIdentifier actionPath = YangInstanceIdentifier.create(
113 new NodeIdentifier(route.getType().getLastComponent()));
114 if (!actionPath.isEmpty()) {
115 String type = route.getType().toString();
116 if (type.contains(name)) {
117 actionMap.put(ROUTE_CONSTANT + actionPath + NAME_CONSTANT + type, address);
126 public String getBucketVersions() {
127 return bucketVersions();