Search in sources :

Example 1 with DOMActionInstance

use of org.opendaylight.mdsal.dom.api.DOMActionInstance in project controller by opendaylight.

the class RemoteActionRegistryMXBeanImpl method getActionMemberMapByName.

/**
 * Search if the routing table route type contains name.
 */
private static Map<String, String> getActionMemberMapByName(final ActionRoutingTable table, final String name, final String address) {
    Collection<DOMActionInstance> routes = table.getItems();
    Map<String, String> actionMap = new HashMap<>(routes.size());
    for (DOMActionInstance route : routes) {
        final YangInstanceIdentifier actionPath = YangInstanceIdentifier.create(new NodeIdentifier(route.getType().lastNodeIdentifier()));
        if (!actionPath.isEmpty()) {
            String type = route.getType().toString();
            if (type.contains(name)) {
                actionMap.put(ROUTE_CONSTANT + actionPath + NAME_CONSTANT + type, address);
            }
        }
    }
    return actionMap;
}
Also used : HashMap(java.util.HashMap) DOMActionInstance(org.opendaylight.mdsal.dom.api.DOMActionInstance) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 2 with DOMActionInstance

use of org.opendaylight.mdsal.dom.api.DOMActionInstance in project controller by opendaylight.

the class ActionRegistryTest method verifyBucket.

private static void verifyBucket(final Bucket<ActionRoutingTable> bucket, final List<DOMActionInstance> expRouteIds) {
    ActionRoutingTable table = bucket.getData();
    assertNotNull("Bucket ActionRoutingTable is null", table);
    for (DOMActionInstance r : expRouteIds) {
        if (!table.contains(r)) {
            fail("ActionRoutingTable does not contain " + r + ". Actual: " + table);
        }
    }
    assertEquals("ActionRoutingTable size", expRouteIds.size(), table.size());
}
Also used : DOMActionInstance(org.opendaylight.mdsal.dom.api.DOMActionInstance)

Example 3 with DOMActionInstance

use of org.opendaylight.mdsal.dom.api.DOMActionInstance in project controller by opendaylight.

the class ActionRegistryTest method testActionAddRemoveInCluster.

/**
 * Three node cluster. 1. Register action on 1 node, ensure 2nd node gets updated 2. Remove action on
 * 1 node, ensure 2nd node gets updated
 */
@Test
public void testActionAddRemoveInCluster() {
    LOG.info("testActionAddRemoveInCluster starting");
    List<DOMActionInstance> addedRouteIds = createRouteIds();
    Address node1Address = node1.provider().getDefaultAddress();
    // Add action on node 1
    registry1.tell(new UpdateActions(addedRouteIds, Collections.emptyList()), ActorRef.noSender());
    // Bucket store on node2 should get a message to update its local copy of remote buckets
    final TestKit testKit = new TestKit(node2);
    Map<Address, Bucket<ActionRoutingTable>> buckets = retrieveBuckets(registry2, testKit, node1Address);
    verifyBucket(buckets.get(node1Address), addedRouteIds);
    // Now remove
    registry1.tell(new UpdateActions(Collections.emptyList(), addedRouteIds), ActorRef.noSender());
    // Bucket store on node2 should get a message to update its local copy of remote buckets.
    // Wait for the bucket for node1 to be empty.
    verifyEmptyBucket(testKit, registry2, node1Address);
    LOG.info("testActionAddRemoveInCluster ending");
}
Also used : UpdateActions(org.opendaylight.controller.remote.rpc.registry.ActionRegistry.Messages.UpdateActions) UniqueAddress(akka.cluster.UniqueAddress) Address(akka.actor.Address) Bucket(org.opendaylight.controller.remote.rpc.registry.gossip.Bucket) DOMActionInstance(org.opendaylight.mdsal.dom.api.DOMActionInstance) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test)

Example 4 with DOMActionInstance

use of org.opendaylight.mdsal.dom.api.DOMActionInstance in project controller by opendaylight.

the class RemoteActionRegistryMXBeanImplTest method setUp.

@Before
public void setUp() {
    system = ActorSystem.create("test", ConfigFactory.load().getConfig("unit-test"));
    final DOMActionInstance emptyActionIdentifier = DOMActionInstance.of(REMOTE_SCHEMA_PATH, LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
    final DOMActionInstance localActionIdentifier = DOMActionInstance.of(LOCAL_SCHEMA_PATH, LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.of(LOCAL_QNAME));
    buckets = Lists.newArrayList(emptyActionIdentifier, localActionIdentifier);
    final RemoteOpsProviderConfig config = new RemoteOpsProviderConfig.Builder("system").build();
    final TestKit invoker = new TestKit(system);
    final TestKit registrar = new TestKit(system);
    final TestKit supervisor = new TestKit(system);
    final Props props = ActionRegistry.props(config, invoker.getRef(), registrar.getRef()).withDispatcher(Dispatchers.DefaultDispatcherId());
    testActor = new TestActorRef<>(system, props, supervisor.getRef(), "testActor");
    final Timeout timeout = Timeout.apply(10, TimeUnit.SECONDS);
    mxBean = new RemoteActionRegistryMXBeanImpl(new BucketStoreAccess(testActor, system.dispatcher(), timeout), timeout);
}
Also used : Timeout(akka.util.Timeout) DOMActionInstance(org.opendaylight.mdsal.dom.api.DOMActionInstance) RemoteOpsProviderConfig(org.opendaylight.controller.remote.rpc.RemoteOpsProviderConfig) TestKit(akka.testkit.javadsl.TestKit) Props(akka.actor.Props) BucketStoreAccess(org.opendaylight.controller.remote.rpc.registry.gossip.BucketStoreAccess) Before(org.junit.Before)

Example 5 with DOMActionInstance

use of org.opendaylight.mdsal.dom.api.DOMActionInstance in project controller by opendaylight.

the class RemoteActionRegistryMXBeanImpl method getActionMemberMapByAction.

/**
 * Search if the routing table route String contains routeName.
 */
private static Map<String, String> getActionMemberMapByAction(final ActionRoutingTable table, final String routeName, final String address) {
    Collection<DOMActionInstance> routes = table.getItems();
    Map<String, String> actionMap = new HashMap<>(routes.size());
    for (DOMActionInstance route : routes) {
        final YangInstanceIdentifier actionPath = YangInstanceIdentifier.create(new NodeIdentifier(route.getType().lastNodeIdentifier()));
        if (!actionPath.isEmpty()) {
            String routeString = actionPath.toString();
            if (routeString.contains(routeName)) {
                actionMap.put(ROUTE_CONSTANT + routeString + NAME_CONSTANT + route.getType(), address);
            }
        }
    }
    return actionMap;
}
Also used : HashMap(java.util.HashMap) DOMActionInstance(org.opendaylight.mdsal.dom.api.DOMActionInstance) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Aggregations

DOMActionInstance (org.opendaylight.mdsal.dom.api.DOMActionInstance)12 TestKit (akka.testkit.javadsl.TestKit)6 Address (akka.actor.Address)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 UniqueAddress (akka.cluster.UniqueAddress)4 Test (org.junit.Test)4 UpdateActions (org.opendaylight.controller.remote.rpc.registry.ActionRegistry.Messages.UpdateActions)4 Bucket (org.opendaylight.controller.remote.rpc.registry.gossip.Bucket)4 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)4 QName (org.opendaylight.yangtools.yang.common.QName)3 Props (akka.actor.Props)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 RemoteActionEndpoint (org.opendaylight.controller.remote.rpc.registry.ActionRegistry.RemoteActionEndpoint)2 Timeout (akka.util.Timeout)1 ClassToInstanceMap (com.google.common.collect.ClassToInstanceMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1