X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2Fregistry%2Fmbeans%2FRemoteRpcRegistryMXBeanImpl.java;h=5442c403a7ba8a3273d69ef7898d2736f75d77e1;hb=c9aab0231686bc6aa06dcfef51fca8c272fb9382;hp=339d4b1a3285b58ac1203523b996c8a268b9fb9d;hpb=d04b71990a802071a786fe8f0df57bc4adbdec3f;p=controller.git diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImpl.java b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImpl.java index 339d4b1a32..5442c403a7 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImpl.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/main/java/org/opendaylight/controller/remote/rpc/registry/mbeans/RemoteRpcRegistryMXBeanImpl.java @@ -9,47 +9,69 @@ package org.opendaylight.controller.remote.rpc.registry.mbeans; import akka.actor.Address; +import akka.util.Timeout; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean; +import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier; import org.opendaylight.controller.remote.rpc.registry.RoutingTable; -import org.opendaylight.controller.remote.rpc.registry.RpcRegistry; import org.opendaylight.controller.remote.rpc.registry.gossip.Bucket; -import org.opendaylight.controller.sal.connector.api.RpcRouter; +import org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreAccess; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import scala.concurrent.Await; +import scala.concurrent.Future; public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements RemoteRpcRegistryMXBean { protected final Logger log = LoggerFactory.getLogger(getClass()); - private static final String NULL_CONSTANT = "null"; - private static final String LOCAL_CONSTANT = "local"; private static final String ROUTE_CONSTANT = "route:"; private static final String NAME_CONSTANT = " | name:"; - private final RpcRegistry rpcRegistry; + private final BucketStoreAccess rpcRegistryAccess; + private final Timeout timeout; - public RemoteRpcRegistryMXBeanImpl(final RpcRegistry rpcRegistry) { + public RemoteRpcRegistryMXBeanImpl(final BucketStoreAccess rpcRegistryAccess, Timeout timeout) { super("RemoteRpcRegistry", "RemoteRpcBroker", null); - this.rpcRegistry = rpcRegistry; + this.rpcRegistryAccess = rpcRegistryAccess; + this.timeout = timeout; registerMBean(); } + @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch", "rawtypes"}) + private RoutingTable getLocalData() { + try { + return (RoutingTable) Await.result((Future) rpcRegistryAccess.getLocalData(), timeout.duration()); + } catch (Exception e) { + throw new RuntimeException("getLocalData failed", e); + } + } + + @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch", "rawtypes"}) + private Map> getRemoteBuckets() { + try { + return (Map>) Await.result((Future)rpcRegistryAccess.getRemoteBuckets(), + timeout.duration()); + } catch (Exception e) { + throw new RuntimeException("getRemoteBuckets failed", e); + } + } + @Override public Set getGlobalRpc() { - RoutingTable table = rpcRegistry.getLocalData(); + RoutingTable table = getLocalData(); Set globalRpc = new HashSet<>(table.getRoutes().size()); - for (RpcRouter.RouteIdentifier route : table.getRoutes()) { - if (route.getRoute() == null) { - globalRpc.add(route.getType() != null ? route.getType().toString() : NULL_CONSTANT); + for (DOMRpcIdentifier route : table.getRoutes()) { + if (route.getContextReference().isEmpty()) { + globalRpc.add(route.getType().toString()); } } @@ -59,13 +81,12 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot @Override public Set getLocalRegisteredRoutedRpc() { - RoutingTable table = rpcRegistry.getLocalData(); + RoutingTable table = getLocalData(); Set routedRpc = new HashSet<>(table.getRoutes().size()); - for (RpcRouter.RouteIdentifier route : table.getRoutes()) { - if (route.getRoute() != null) { + for (DOMRpcIdentifier route : table.getRoutes()) { + if (!route.getContextReference().isEmpty()) { StringBuilder builder = new StringBuilder(ROUTE_CONSTANT); - builder.append(route.getRoute().toString()).append(NAME_CONSTANT).append(route.getType() != null - ? route.getType().toString() : NULL_CONSTANT); + builder.append(route.getContextReference().toString()).append(NAME_CONSTANT).append(route.getType()); routedRpc.add(builder.toString()); } } @@ -76,12 +97,12 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot @Override public Map findRpcByName(final String name) { - RoutingTable localTable = rpcRegistry.getLocalData(); + RoutingTable localTable = getLocalData(); // Get all RPCs from local bucket Map rpcMap = new HashMap<>(getRpcMemberMapByName(localTable, name, LOCAL_CONSTANT)); // Get all RPCs from remote bucket - Map> buckets = rpcRegistry.getRemoteBuckets(); + Map> buckets = getRemoteBuckets(); for (Entry> entry : buckets.entrySet()) { RoutingTable table = entry.getValue().getData(); rpcMap.putAll(getRpcMemberMapByName(table, name, entry.getKey().toString())); @@ -93,10 +114,10 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot @Override public Map findRpcByRoute(final String routeId) { - RoutingTable localTable = rpcRegistry.getLocalData(); + RoutingTable localTable = getLocalData(); Map rpcMap = new HashMap<>(getRpcMemberMapByRoute(localTable, routeId, LOCAL_CONSTANT)); - Map> buckets = rpcRegistry.getRemoteBuckets(); + Map> buckets = getRemoteBuckets(); for (Entry> entry : buckets.entrySet()) { RoutingTable table = entry.getValue().getData(); rpcMap.putAll(getRpcMemberMapByRoute(table, routeId, entry.getKey().toString())); @@ -111,15 +132,14 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot */ private static Map getRpcMemberMapByRoute(final RoutingTable table, final String routeName, final String address) { - Set> routes = table.getRoutes(); + Set routes = table.getRoutes(); Map rpcMap = new HashMap<>(routes.size()); - for (RpcRouter.RouteIdentifier route : table.getRoutes()) { - if (route.getRoute() != null) { - String routeString = route.getRoute().toString(); + for (DOMRpcIdentifier route : routes) { + if (!route.getContextReference().isEmpty()) { + String routeString = route.getContextReference().toString(); if (routeString.contains(routeName)) { StringBuilder builder = new StringBuilder(ROUTE_CONSTANT); - builder.append(routeString).append(NAME_CONSTANT).append(route.getType() != null - ? route.getType().toString() : NULL_CONSTANT); + builder.append(routeString).append(NAME_CONSTANT).append(route.getType()); rpcMap.put(builder.toString(), address); } } @@ -132,15 +152,14 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot */ private static Map getRpcMemberMapByName(final RoutingTable table, final String name, final String address) { - Set> routes = table.getRoutes(); + Set routes = table.getRoutes(); Map rpcMap = new HashMap<>(routes.size()); - for (RpcRouter.RouteIdentifier route : routes) { - if (route.getType() != null) { + for (DOMRpcIdentifier route : routes) { + if (!route.getContextReference().isEmpty()) { String type = route.getType().toString(); if (type.contains(name)) { StringBuilder builder = new StringBuilder(ROUTE_CONSTANT); - builder.append(route.getRoute() != null ? route.getRoute().toString() : NULL_CONSTANT) - .append(NAME_CONSTANT).append(type); + builder.append(route.getContextReference()).append(NAME_CONSTANT).append(type); rpcMap.put(builder.toString(), address); } } @@ -149,7 +168,12 @@ public class RemoteRpcRegistryMXBeanImpl extends AbstractMXBean implements Remot } @Override + @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch", "rawtypes"}) public String getBucketVersions() { - return rpcRegistry.getVersions().toString(); + try { + return Await.result((Future)rpcRegistryAccess.getBucketVersions(), timeout.duration()).toString(); + } catch (Exception e) { + throw new RuntimeException("getVersions failed", e); + } } }