Search in sources :

Example 16 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardManagerTest method testServerRemovedShardActorNotRunning.

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

        {
            MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-2")).put("people", Arrays.asList("member-1", "member-2")).build());
            TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newShardMgrProps(mockConfig).withDispatcher(Dispatchers.DefaultDispatcherId()));
            shardManager.underlyingActor().waitForRecoveryComplete();
            shardManager.tell(new FindLocalShard("people", false), getRef());
            expectMsgClass(duration("5 seconds"), NotInitializedException.class);
            shardManager.tell(new FindLocalShard("default", false), getRef());
            expectMsgClass(duration("5 seconds"), NotInitializedException.class);
            // Removed the default shard replica from member-1
            ShardIdentifier.Builder builder = new ShardIdentifier.Builder();
            ShardIdentifier shardId = builder.shardName("default").memberName(MEMBER_1).type(shardMrgIDSuffix).build();
            shardManager.tell(new ServerRemoved(shardId.toString()), getRef());
            shardManager.underlyingActor().verifySnapshotPersisted(Sets.newHashSet("people"));
        }
    };
    LOG.info("testServerRemovedShardActorNotRunning ending");
}
Also used : ServerRemoved(org.opendaylight.controller.cluster.raft.messages.ServerRemoved) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 17 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardManager method onActorInitialized.

private void onActorInitialized(final Object message) {
    final ActorRef sender = getSender();
    if (sender == null) {
        // why is a non-actor sending this message? Just ignore.
        return;
    }
    String actorName = sender.path().name();
    // find shard name from actor name; actor name is stringified shardId
    final ShardIdentifier shardId;
    try {
        shardId = ShardIdentifier.fromShardIdString(actorName);
    } catch (IllegalArgumentException e) {
        LOG.debug("{}: ignoring actor {}", actorName, e);
        return;
    }
    markShardAsInitialized(shardId.getShardName());
}
Also used : ActorRef(akka.actor.ActorRef) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)

Example 18 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier 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 19 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardManager method onPrefixShardCreated.

private void onPrefixShardCreated(final PrefixShardCreated message) {
    LOG.debug("{}: onPrefixShardCreated: {}", persistenceId(), message);
    final PrefixShardConfiguration config = message.getConfiguration();
    final ShardIdentifier shardId = getShardIdentifier(cluster.getCurrentMemberName(), ClusterUtils.getCleanShardName(config.getPrefix().getRootIdentifier()));
    final String shardName = shardId.getShardName();
    if (isPreviousShardActorStopInProgress(shardName, message)) {
        return;
    }
    if (localShards.containsKey(shardName)) {
        LOG.debug("{}: Received create for an already existing shard {}", persistenceId(), shardName);
        final PrefixShardConfiguration existing = configuration.getAllPrefixShardConfigurations().get(config.getPrefix());
        if (existing != null && existing.equals(config)) {
            // we don't have to do nothing here
            return;
        }
    }
    doCreatePrefixShard(config, shardId, shardName);
}
Also used : ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) PrefixShardConfiguration(org.opendaylight.controller.cluster.datastore.config.PrefixShardConfiguration)

Example 20 with ShardIdentifier

use of org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier in project controller by opendaylight.

the class ShardManager method getPeerAddresses.

private Map<String, String> getPeerAddresses(final String shardName, final Collection<MemberName> members) {
    Map<String, String> peerAddresses = new HashMap<>();
    MemberName currentMemberName = this.cluster.getCurrentMemberName();
    for (MemberName memberName : members) {
        if (!currentMemberName.equals(memberName)) {
            ShardIdentifier shardId = getShardIdentifier(memberName, shardName);
            String address = peerAddressResolver.getShardActorAddress(shardName, memberName);
            peerAddresses.put(shardId.toString(), address);
        }
    }
    return peerAddresses;
}
Also used : HashMap(java.util.HashMap) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName)

Aggregations

ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)31 Test (org.junit.Test)15 ShardTestKit (org.opendaylight.controller.cluster.datastore.ShardTestKit)11 RegisterCandidateLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal)11 DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)11 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)6 ActorRef (akka.actor.ActorRef)3 Status (akka.actor.Status)3 DeleteSnapshotsFailure (akka.persistence.DeleteSnapshotsFailure)3 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)3 Timeout (akka.util.Timeout)3 Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)3 RegisterListenerLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterListenerLocal)3 ChangeShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus)3 FlipShardMembersVotingStatus (org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus)3 PeerDown (org.opendaylight.controller.cluster.datastore.messages.PeerDown)3 DOMEntityOwnershipListener (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener)3 TestActorRef (akka.testkit.TestActorRef)2 HashMap (java.util.HashMap)2