Search in sources :

Example 1 with ConfigurationImpl

use of org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl 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 2 with ConfigurationImpl

use of org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl 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 3 with ConfigurationImpl

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

the class IntegrationTestKit method setupDistributedDataStoreWithoutConfig.

public DistributedDataStore setupDistributedDataStoreWithoutConfig(final String typeName, final SchemaContext schemaContext, final LogicalDatastoreType storeType) {
    final ClusterWrapper cluster = new ClusterWrapperImpl(getSystem());
    final ConfigurationImpl configuration = new ConfigurationImpl(new EmptyModuleShardConfigProvider());
    setDataStoreName(typeName);
    final DatastoreContext datastoreContext = getDatastoreContextBuilder().logicalStoreType(storeType).build();
    final DatastoreContextFactory mockContextFactory = Mockito.mock(DatastoreContextFactory.class);
    Mockito.doReturn(datastoreContext).when(mockContextFactory).getBaseDatastoreContext();
    Mockito.doReturn(datastoreContext).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString());
    final DistributedDataStore dataStore = new DistributedDataStore(getSystem(), cluster, configuration, mockContextFactory, restoreFromSnapshot);
    dataStore.onGlobalContextUpdated(schemaContext);
    datastoreContextBuilder = DatastoreContext.newBuilderFrom(datastoreContext);
    return dataStore;
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)

Example 4 with ConfigurationImpl

use of org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl 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)

Example 5 with ConfigurationImpl

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

the class ShardManagerTest method testOnCreateShardWithLocalMemberNotInShardConfig.

@Test
public void testOnCreateShardWithLocalMemberNotInShardConfig() {
    LOG.info("testOnCreateShardWithLocalMemberNotInShardConfig starting");
    new TestKit(getSystem()) {

        {
            datastoreContextBuilder.shardInitializationTimeout(1, TimeUnit.MINUTES).persistent(true);
            ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), ActorRef.noSender());
            Shard.Builder shardBuilder = Shard.builder();
            ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module", "foo", null, members("member-5", "member-6"));
            shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
            expectMsgClass(duration("5 seconds"), Success.class);
            shardManager.tell(new FindLocalShard("foo", true), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardFound.class);
            assertEquals("peerMembers size", 0, shardBuilder.getPeerAddresses().size());
            assertEquals("schemaContext", DisableElectionsRaftPolicy.class.getName(), shardBuilder.getDatastoreContext().getShardRaftConfig().getCustomRaftPolicyImplementationClass());
        }
    };
    LOG.info("testOnCreateShardWithLocalMemberNotInShardConfig ending");
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) Shard(org.opendaylight.controller.cluster.datastore.Shard) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)10 EmptyModuleShardConfigProvider (org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider)8 ActorRef (akka.actor.ActorRef)5 TestActorRef (akka.testkit.TestActorRef)5 TestKit (akka.testkit.javadsl.TestKit)5 Test (org.junit.Test)5 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)5 Shard (org.opendaylight.controller.cluster.datastore.Shard)3 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)3 ModuleShardConfiguration (org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)3 CreateShard (org.opendaylight.controller.cluster.datastore.messages.CreateShard)3 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)3 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)3 Status (akka.actor.Status)2 Failure (akka.actor.Status.Failure)2 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)2 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)2 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)2 ChangeServersVotingStatus (org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus)2 ServerChangeStatus (org.opendaylight.controller.cluster.raft.messages.ServerChangeStatus)2