Search in sources :

Example 1 with Configuration

use of org.opendaylight.controller.cluster.datastore.config.Configuration in project controller by opendaylight.

the class TransactionProxyTest method testReadRoot.

@Test
public void testReadRoot() throws ReadFailedException, InterruptedException, ExecutionException, java.util.concurrent.TimeoutException {
    SchemaContext schemaContext = SchemaContextHelper.full();
    Configuration configuration = mock(Configuration.class);
    doReturn(configuration).when(mockActorContext).getConfiguration();
    doReturn(schemaContext).when(mockActorContext).getSchemaContext();
    doReturn(Sets.newHashSet("test", "cars")).when(configuration).getAllShardNames();
    NormalizedNode<?, ?> expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    NormalizedNode<?, ?> expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME);
    setUpReadData("test", NormalizedNodeAggregatorTest.getRootNode(expectedNode1, schemaContext));
    setUpReadData("cars", NormalizedNodeAggregatorTest.getRootNode(expectedNode2, schemaContext));
    doReturn(MemberName.forName(memberName)).when(mockActorContext).getCurrentMemberName();
    doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(mockActorContext).getClientDispatcher();
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
    Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(YangInstanceIdentifier.EMPTY).get(5, TimeUnit.SECONDS);
    assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
    NormalizedNode<?, ?> normalizedNode = readOptional.get();
    assertTrue("Expect value to be a Collection", normalizedNode.getValue() instanceof Collection);
    @SuppressWarnings("unchecked") Collection<NormalizedNode<?, ?>> collection = (Collection<NormalizedNode<?, ?>>) normalizedNode.getValue();
    for (NormalizedNode<?, ?> node : collection) {
        assertTrue("Expected " + node + " to be a ContainerNode", node instanceof ContainerNode);
    }
    assertTrue("Child with QName = " + TestModel.TEST_QNAME + " not found", NormalizedNodeAggregatorTest.findChildWithQName(collection, TestModel.TEST_QNAME) != null);
    assertEquals(expectedNode1, NormalizedNodeAggregatorTest.findChildWithQName(collection, TestModel.TEST_QNAME));
    assertTrue("Child with QName = " + CarsModel.BASE_QNAME + " not found", NormalizedNodeAggregatorTest.findChildWithQName(collection, CarsModel.BASE_QNAME) != null);
    assertEquals(expectedNode2, NormalizedNodeAggregatorTest.findChildWithQName(collection, CarsModel.BASE_QNAME));
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) Collection(java.util.Collection) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 2 with Configuration

use of org.opendaylight.controller.cluster.datastore.config.Configuration in project controller by opendaylight.

the class DistributedEntityOwnershipServiceTest method setUp.

@Before
public void setUp() {
    DatastoreContext datastoreContext = DatastoreContext.newBuilder().dataStoreName(dataStoreName).shardInitializationTimeout(10, TimeUnit.SECONDS).build();
    Configuration configuration = new ConfigurationImpl(new EmptyModuleShardConfigProvider()) {

        @Override
        public Collection<MemberName> getUniqueMemberNamesForAllShards() {
            return Sets.newHashSet(MemberName.forName("member-1"));
        }
    };
    DatastoreContextFactory mockContextFactory = mock(DatastoreContextFactory.class);
    Mockito.doReturn(datastoreContext).when(mockContextFactory).getBaseDatastoreContext();
    Mockito.doReturn(datastoreContext).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString());
    dataStore = new DistributedDataStore(getSystem(), new MockClusterWrapper(), configuration, mockContextFactory, null);
    dataStore.onGlobalContextUpdated(SchemaContextHelper.entityOwners());
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) DistributedDataStore(org.opendaylight.controller.cluster.datastore.DistributedDataStore) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) DatastoreContextFactory(org.opendaylight.controller.cluster.datastore.DatastoreContextFactory) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) MockClusterWrapper(org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) Before(org.junit.Before)

Example 3 with Configuration

use of org.opendaylight.controller.cluster.datastore.config.Configuration in project controller by opendaylight.

the class IntegrationTestKit method setupAbstractDataStore.

private AbstractDataStore setupAbstractDataStore(final Class<? extends AbstractDataStore> implementation, final String typeName, final String moduleShardsConfig, final String modulesConfig, final boolean waitUntilLeader, final SchemaContext schemaContext, final String... shardNames) throws Exception {
    final ClusterWrapper cluster = new ClusterWrapperImpl(getSystem());
    final Configuration config = new ConfigurationImpl(moduleShardsConfig, modulesConfig);
    setDataStoreName(typeName);
    final DatastoreContext datastoreContext = datastoreContextBuilder.build();
    final DatastoreContextFactory mockContextFactory = Mockito.mock(DatastoreContextFactory.class);
    Mockito.doReturn(datastoreContext).when(mockContextFactory).getBaseDatastoreContext();
    Mockito.doReturn(datastoreContext).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString());
    final Constructor<? extends AbstractDataStore> constructor = implementation.getDeclaredConstructor(ActorSystem.class, ClusterWrapper.class, Configuration.class, DatastoreContextFactory.class, DatastoreSnapshot.class);
    final AbstractDataStore dataStore = constructor.newInstance(getSystem(), cluster, config, mockContextFactory, restoreFromSnapshot);
    dataStore.onGlobalContextUpdated(schemaContext);
    if (waitUntilLeader) {
        waitUntilLeader(dataStore.getActorContext(), shardNames);
    }
    datastoreContextBuilder = DatastoreContext.newBuilderFrom(datastoreContext);
    return dataStore;
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)

Example 4 with Configuration

use of org.opendaylight.controller.cluster.datastore.config.Configuration in project controller by opendaylight.

the class ActorContextTest method testBroadcast.

@Test
public void testBroadcast() {
    new TestKit(getSystem()) {

        {
            ActorRef shardActorRef1 = getSystem().actorOf(MessageCollectorActor.props());
            ActorRef shardActorRef2 = getSystem().actorOf(MessageCollectorActor.props());
            TestActorRef<MockShardManager> shardManagerActorRef = TestActorRef.create(getSystem(), MockShardManager.props());
            MockShardManager shardManagerActor = shardManagerActorRef.underlyingActor();
            shardManagerActor.addFindPrimaryResp("shard1", new RemotePrimaryShardFound(shardActorRef1.path().toString(), DataStoreVersions.CURRENT_VERSION));
            shardManagerActor.addFindPrimaryResp("shard2", new RemotePrimaryShardFound(shardActorRef2.path().toString(), DataStoreVersions.CURRENT_VERSION));
            shardManagerActor.addFindPrimaryResp("shard3", new NoShardLeaderException("not found"));
            Configuration mockConfig = mock(Configuration.class);
            doReturn(Sets.newLinkedHashSet(Arrays.asList("shard1", "shard2", "shard3"))).when(mockConfig).getAllShardNames();
            ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef, mock(ClusterWrapper.class), mockConfig, DatastoreContext.newBuilder().shardInitializationTimeout(200, TimeUnit.MILLISECONDS).build(), new PrimaryShardInfoFutureCache());
            actorContext.broadcast(v -> new TestMessage(), TestMessage.class);
            MessageCollectorActor.expectFirstMatching(shardActorRef1, TestMessage.class);
            MessageCollectorActor.expectFirstMatching(shardActorRef2, TestMessage.class);
        }
    };
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) ClusterWrapper(org.opendaylight.controller.cluster.datastore.ClusterWrapper) TestKit(akka.testkit.javadsl.TestKit) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Example 5 with Configuration

use of org.opendaylight.controller.cluster.datastore.config.Configuration in project controller by opendaylight.

the class DistributedDataStoreFactory method createInstance.

public static AbstractDataStore createInstance(final DOMSchemaService schemaService, final DatastoreContext initialDatastoreContext, final DatastoreSnapshotRestore datastoreSnapshotRestore, final ActorSystemProvider actorSystemProvider, final DatastoreContextIntrospector introspector, final DatastoreContextPropertiesUpdater updater, final Configuration orgConfig) {
    final String datastoreName = initialDatastoreContext.getDataStoreName();
    LOG.info("Create data store instance of type : {}", datastoreName);
    final ActorSystem actorSystem = actorSystemProvider.getActorSystem();
    final DatastoreSnapshot restoreFromSnapshot = datastoreSnapshotRestore.getAndRemove(datastoreName);
    Configuration config;
    if (orgConfig == null) {
        config = new ConfigurationImpl(DEFAULT_MODULE_SHARDS_PATH, DEFAULT_MODULES_PATH);
    } else {
        config = orgConfig;
    }
    final ClusterWrapper clusterWrapper = new ClusterWrapperImpl(actorSystem);
    final DatastoreContextFactory contextFactory = introspector.newContextFactory();
    // This is the potentially-updated datastore context, distinct from the initial one
    final DatastoreContext datastoreContext = contextFactory.getBaseDatastoreContext();
    final AbstractDataStore dataStore;
    if (datastoreContext.isUseTellBasedProtocol()) {
        dataStore = new ClientBackedDataStore(actorSystem, clusterWrapper, config, contextFactory, restoreFromSnapshot);
        LOG.info("Data store {} is using tell-based protocol", datastoreName);
    } else {
        dataStore = new DistributedDataStore(actorSystem, clusterWrapper, config, contextFactory, restoreFromSnapshot);
        LOG.info("Data store {} is using ask-based protocol", datastoreName);
    }
    updater.setListener(dataStore);
    schemaService.registerSchemaContextListener(dataStore);
    dataStore.setCloseable(updater);
    dataStore.waitTillReady();
    return dataStore;
}
Also used : ActorSystem(akka.actor.ActorSystem) ClientBackedDataStore(org.opendaylight.controller.cluster.databroker.ClientBackedDataStore) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)

Aggregations

Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)7 MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)3 ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)3 ActorRef (akka.actor.ActorRef)2 Test (org.junit.Test)2 ModuleShardConfiguration (org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)2 CreateShard (org.opendaylight.controller.cluster.datastore.messages.CreateShard)2 ActorSystem (akka.actor.ActorSystem)1 TestActorRef (akka.testkit.TestActorRef)1 TestKit (akka.testkit.javadsl.TestKit)1 Collection (java.util.Collection)1 Before (org.junit.Before)1 ClientBackedDataStore (org.opendaylight.controller.cluster.databroker.ClientBackedDataStore)1 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)1 ClusterWrapper (org.opendaylight.controller.cluster.datastore.ClusterWrapper)1 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)1 DatastoreContextFactory (org.opendaylight.controller.cluster.datastore.DatastoreContextFactory)1 DistributedDataStore (org.opendaylight.controller.cluster.datastore.DistributedDataStore)1 EmptyModuleShardConfigProvider (org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider)1 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)1