Search in sources :

Example 6 with ModuleShardConfiguration

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

the class ShardManager method doCreateShard.

private void doCreateShard(final CreateShard createShard) {
    final ModuleShardConfiguration moduleShardConfig = createShard.getModuleShardConfig();
    final String shardName = moduleShardConfig.getShardName();
    configuration.addModuleShardConfiguration(moduleShardConfig);
    DatastoreContext shardDatastoreContext = createShard.getDatastoreContext();
    if (shardDatastoreContext == null) {
        shardDatastoreContext = newShardDatastoreContext(shardName);
    } else {
        shardDatastoreContext = DatastoreContext.newBuilderFrom(shardDatastoreContext).shardPeerAddressResolver(peerAddressResolver).build();
    }
    ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), shardName);
    boolean shardWasInRecoveredSnapshot = currentSnapshot != null && currentSnapshot.getShardList().contains(shardName);
    Map<String, String> peerAddresses;
    boolean isActiveMember;
    if (shardWasInRecoveredSnapshot || configuration.getMembersFromShardName(shardName).contains(cluster.getCurrentMemberName())) {
        peerAddresses = getPeerAddresses(shardName);
        isActiveMember = true;
    } else {
        // The local member is not in the static shard member configuration and the shard did not
        // previously exist (ie !shardWasInRecoveredSnapshot). In this case we'll create
        // the shard with no peers and with elections disabled so it stays as follower. A
        // subsequent AddServer request will be needed to make it an active member.
        isActiveMember = false;
        peerAddresses = Collections.emptyMap();
        shardDatastoreContext = DatastoreContext.newBuilderFrom(shardDatastoreContext).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName()).build();
    }
    LOG.debug("{} doCreateShard: shardId: {}, memberNames: {}, peerAddresses: {}, isActiveMember: {}", persistenceId(), shardId, moduleShardConfig.getShardMemberNames(), peerAddresses, isActiveMember);
    ShardInformation info = new ShardInformation(shardName, shardId, peerAddresses, shardDatastoreContext, createShard.getShardBuilder(), peerAddressResolver);
    info.setActiveMember(isActiveMember);
    localShards.put(info.getShardName(), info);
    if (schemaContext != null) {
        info.setSchemaContext(schemaContext);
        info.setActor(newShardActor(info));
    }
}
Also used : DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)

Example 7 with ModuleShardConfiguration

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

the class DistributedShardedDOMDataTree method createPrefixConfigShard.

private static void createPrefixConfigShard(final AbstractDataStore dataStore) {
    Configuration configuration = dataStore.getActorContext().getConfiguration();
    Collection<MemberName> memberNames = configuration.getUniqueMemberNamesForAllShards();
    CreateShard createShardMessage = new CreateShard(new ModuleShardConfiguration(PrefixShards.QNAME.getNamespace(), "prefix-shard-configuration", ClusterUtils.PREFIX_CONFIG_SHARD_ID, ModuleShardStrategy.NAME, memberNames), Shard.builder(), dataStore.getActorContext().getDatastoreContext());
    dataStore.getActorContext().getShardManager().tell(createShardMessage, noSender());
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)

Example 8 with ModuleShardConfiguration

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

the class DistributedEntityOwnershipService method start.

public static DistributedEntityOwnershipService start(final ActorContext context, final EntityOwnerSelectionStrategyConfig strategyConfig) {
    ActorRef shardManagerActor = context.getShardManager();
    Configuration configuration = context.getConfiguration();
    Collection<MemberName> entityOwnersMemberNames = configuration.getUniqueMemberNamesForAllShards();
    CreateShard createShard = new CreateShard(new ModuleShardConfiguration(EntityOwners.QNAME.getNamespace(), "entity-owners", ENTITY_OWNERSHIP_SHARD_NAME, ModuleShardStrategy.NAME, entityOwnersMemberNames), newShardBuilder(context, strategyConfig), null);
    Future<Object> createFuture = context.executeOperationAsync(shardManagerActor, createShard, MESSAGE_TIMEOUT);
    createFuture.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                LOG.error("Failed to create {} shard", ENTITY_OWNERSHIP_SHARD_NAME, failure);
            } else {
                LOG.info("Successfully created {} shard", ENTITY_OWNERSHIP_SHARD_NAME);
            }
        }
    }, context.getClientDispatcher());
    return new DistributedEntityOwnershipService(context);
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) ActorRef(akka.actor.ActorRef) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)

Aggregations

ModuleShardConfiguration (org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)8 CreateShard (org.opendaylight.controller.cluster.datastore.messages.CreateShard)7 Test (org.junit.Test)5 ActorRef (akka.actor.ActorRef)4 TestActorRef (akka.testkit.TestActorRef)3 TestKit (akka.testkit.javadsl.TestKit)3 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)3 Shard (org.opendaylight.controller.cluster.datastore.Shard)3 ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)3 EmptyModuleShardConfigProvider (org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider)3 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)3 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)2 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)2 MemberNode (org.opendaylight.controller.cluster.datastore.MemberNode)2 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)2 DisableElectionsRaftPolicy (org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy)2 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)2 Success (akka.actor.Status.Success)1