Search in sources :

Example 6 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.

the class ConfigurationImplTest method testRemoveMemberReplicaForShard.

@Test
public void testRemoveMemberReplicaForShard() {
    configuration.removeMemberReplicaForShard("default", MEMBER_2);
    String shardName = configuration.getShardNameForModule("default");
    assertEquals("ModuleShardName", "default", shardName);
    ShardStrategy shardStrategy = configuration.getStrategyForModule("default");
    assertNull("ModuleStrategy", shardStrategy);
    Collection<MemberName> members = configuration.getMembersFromShardName("default");
    assertEquals("Members", ImmutableSortedSet.of(MEMBER_1, MEMBER_3), ImmutableSortedSet.copyOf(members));
    configuration.removeMemberReplicaForShard("non-existent", MEMBER_2);
    Set<String> shardNames = configuration.getAllShardNames();
    assertEquals("ShardNames", ImmutableSortedSet.of("people-1", "cars-1", "test-1", "default"), ImmutableSortedSet.copyOf(shardNames));
}
Also used : ShardStrategy(org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy) ModuleShardStrategy(org.opendaylight.controller.cluster.datastore.shardstrategy.ModuleShardStrategy) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) Test(org.junit.Test)

Example 7 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName 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 8 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.

the class ActorBehaviorTest method setUp.

@Before
public void setUp() throws Exception {
    initialBehavior = createInitialBehaviorMock();
    system = ActorSystem.apply("system1");
    final ActorRef storeRef = system.registerExtension(Persistence.lookup()).snapshotStoreFor(null);
    probe = new TestProbe(system);
    storeRef.tell(probe.ref(), ActorRef.noSender());
    final MemberName name = MemberName.forName("member-1");
    id = FrontendIdentifier.create(name, FrontendType.forName("type-1"));
    mockedActor = system.actorOf(MockedActor.props(id, initialBehavior));
    // handle initial actor recovery
    saveRequest = handleRecovery(null);
}
Also used : ActorRef(akka.actor.ActorRef) TestProbe(akka.testkit.TestProbe) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) Before(org.junit.Before)

Example 9 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.

the class ClusterAdminRpcService method removeAllShardReplicas.

@Override
public Future<RpcResult<RemoveAllShardReplicasOutput>> removeAllShardReplicas(RemoveAllShardReplicasInput input) {
    LOG.info("Removing replicas for all shards");
    final String memberName = input.getMemberName();
    if (Strings.isNullOrEmpty(memberName)) {
        return newFailedRpcResultFuture("A valid member name must be specified");
    }
    final List<Entry<ListenableFuture<Success>, ShardResultBuilder>> shardResultData = new ArrayList<>();
    Function<String, Object> messageSupplier = shardName -> new RemoveShardReplica(shardName, MemberName.forName(memberName));
    sendMessageToManagerForConfiguredShards(DataStoreType.Config, shardResultData, messageSupplier);
    sendMessageToManagerForConfiguredShards(DataStoreType.Operational, shardResultData, messageSupplier);
    return waitForShardResults(shardResultData, shardResults -> new RemoveAllShardReplicasOutputBuilder().setShardResult(shardResults).build(), "       Failed to remove replica");
}
Also used : AddShardReplicaInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddShardReplicaInput) AddReplicasForAllShardsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddReplicasForAllShardsOutput) LoggerFactory(org.slf4j.LoggerFactory) SettableFuture(com.google.common.util.concurrent.SettableFuture) ChangeShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.ChangeShardMembersVotingStatus) GetPrefixShardRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleInput) Future(java.util.concurrent.Future) GetShardRoleReply(org.opendaylight.controller.cluster.datastore.messages.GetShardRoleReply) AddReplicasForAllShardsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddReplicasForAllShardsOutputBuilder) GetShardRoleOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleOutputBuilder) RemoveAllShardReplicasInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveAllShardReplicasInput) ActorRef(akka.actor.ActorRef) Map(java.util.Map) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) Patterns(akka.pattern.Patterns) AddShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddShardReplica) FlipMemberVotingStatesForAllShardsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.FlipMemberVotingStatesForAllShardsOutput) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) DatastoreSnapshotList(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshotList) GetPrefixShardRoleOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutputBuilder) Function(com.google.common.base.Function) GetShardRole(org.opendaylight.controller.cluster.datastore.messages.GetShardRole) Set(java.util.Set) ErrorType(org.opendaylight.yangtools.yang.common.RpcError.ErrorType) GetPrefixShardRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetPrefixShardRoleOutput) List(java.util.List) DataStoreType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType) GetShardRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleOutput) RemoveAllShardReplicasOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveAllShardReplicasOutputBuilder) Entry(java.util.Map.Entry) MemberVotingState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.member.voting.states.input.MemberVotingState) MakeLeaderLocalInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.MakeLeaderLocalInput) RemovePrefixShardReplica(org.opendaylight.controller.cluster.datastore.messages.RemovePrefixShardReplica) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RemovePrefixShardReplicaInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemovePrefixShardReplicaInput) HashMap(java.util.HashMap) SerializationUtils(org.apache.commons.lang3.SerializationUtils) Timeout(akka.util.Timeout) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) FlipShardMembersVotingStatus(org.opendaylight.controller.cluster.datastore.messages.FlipShardMembersVotingStatus) ClusterUtils(org.opendaylight.controller.cluster.datastore.utils.ClusterUtils) DistributedDataStoreInterface(org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface) Success(akka.actor.Status.Success) ChangeMemberVotingStatesForAllShardsInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForAllShardsInput) BackupDatastoreInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.BackupDatastoreInput) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) OnComplete(akka.dispatch.OnComplete) GetShardRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.GetShardRoleInput) RemoveShardReplica(org.opendaylight.controller.cluster.datastore.messages.RemoveShardReplica) SimpleEntry(java.util.AbstractMap.SimpleEntry) MakeLeaderLocal(org.opendaylight.controller.cluster.datastore.messages.MakeLeaderLocal) AddPrefixShardReplica(org.opendaylight.controller.cluster.datastore.messages.AddPrefixShardReplica) ChangeMemberVotingStatesForAllShardsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForAllShardsOutputBuilder) AddPrefixShardReplicaInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddPrefixShardReplicaInput) ChangeMemberVotingStatesForAllShardsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForAllShardsOutput) FlipMemberVotingStatesForAllShardsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.FlipMemberVotingStatesForAllShardsOutputBuilder) Logger(org.slf4j.Logger) Throwables(com.google.common.base.Throwables) FileOutputStream(java.io.FileOutputStream) RemoveShardReplicaInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveShardReplicaInput) IOException(java.io.IOException) RemoveAllShardReplicasOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveAllShardReplicasOutput) FutureCallback(com.google.common.util.concurrent.FutureCallback) ShardResultBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.shard.result.output.ShardResultBuilder) TimeUnit(java.util.concurrent.TimeUnit) Futures(com.google.common.util.concurrent.Futures) ShardResult(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.shard.result.output.ShardResult) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) ClusterAdminService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ClusterAdminService) GetSnapshot(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot) ChangeMemberVotingStatesForShardInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForShardInput) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) RemoveAllShardReplicasOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveAllShardReplicasOutputBuilder) ArrayList(java.util.ArrayList) RemoveShardReplica(org.opendaylight.controller.cluster.datastore.messages.RemoveShardReplica) Success(akka.actor.Status.Success)

Example 10 with MemberName

use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.

the class ShardManagerTest method testPerShardDatastoreContext.

@Test
public void testPerShardDatastoreContext() throws Exception {
    LOG.info("testPerShardDatastoreContext starting");
    final DatastoreContextFactory mockFactory = newDatastoreContextFactory(datastoreContextBuilder.shardElectionTimeoutFactor(5).build());
    Mockito.doReturn(DatastoreContext.newBuilderFrom(datastoreContextBuilder.build()).shardElectionTimeoutFactor(6).build()).when(mockFactory).getShardDatastoreContext("default");
    Mockito.doReturn(DatastoreContext.newBuilderFrom(datastoreContextBuilder.build()).shardElectionTimeoutFactor(7).build()).when(mockFactory).getShardDatastoreContext("topology");
    final MockConfiguration mockConfig = new MockConfiguration() {

        @Override
        public Collection<String> getMemberShardNames(final MemberName memberName) {
            return Arrays.asList("default", "topology");
        }

        @Override
        public Collection<MemberName> getMembersFromShardName(final String shardName) {
            return members("member-1");
        }
    };
    final ActorRef defaultShardActor = actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId("default"));
    final ActorRef topologyShardActor = actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId("topology"));
    final Map<String, Entry<ActorRef, DatastoreContext>> shardInfoMap = Collections.synchronizedMap(new HashMap<String, Entry<ActorRef, DatastoreContext>>());
    shardInfoMap.put("default", new AbstractMap.SimpleEntry<>(defaultShardActor, null));
    shardInfoMap.put("topology", new AbstractMap.SimpleEntry<>(topologyShardActor, null));
    final PrimaryShardInfoFutureCache primaryShardInfoCache = new PrimaryShardInfoFutureCache();
    final CountDownLatch newShardActorLatch = new CountDownLatch(2);
    class LocalShardManager extends ShardManager {

        LocalShardManager(final AbstractShardManagerCreator<?> creator) {
            super(creator);
        }

        @Override
        protected ActorRef newShardActor(final ShardInformation info) {
            Entry<ActorRef, DatastoreContext> entry = shardInfoMap.get(info.getShardName());
            ActorRef ref = null;
            if (entry != null) {
                ref = entry.getKey();
                entry.setValue(info.getDatastoreContext());
            }
            newShardActorLatch.countDown();
            return ref;
        }
    }
    final Creator<ShardManager> creator = new Creator<ShardManager>() {

        private static final long serialVersionUID = 1L;

        @Override
        public ShardManager create() throws Exception {
            return new LocalShardManager(new GenericCreator<>(LocalShardManager.class).datastoreContextFactory(mockFactory).primaryShardInfoCache(primaryShardInfoCache).configuration(mockConfig));
        }
    };
    TestKit kit = new TestKit(getSystem());
    final ActorRef shardManager = actorFactory.createActor(Props.create(new DelegatingShardManagerCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()));
    shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), kit.getRef());
    assertEquals("Shard actors created", true, newShardActorLatch.await(5, TimeUnit.SECONDS));
    assertEquals("getShardElectionTimeoutFactor", 6, shardInfoMap.get("default").getValue().getShardElectionTimeoutFactor());
    assertEquals("getShardElectionTimeoutFactor", 7, shardInfoMap.get("topology").getValue().getShardElectionTimeoutFactor());
    DatastoreContextFactory newMockFactory = newDatastoreContextFactory(datastoreContextBuilder.shardElectionTimeoutFactor(5).build());
    Mockito.doReturn(DatastoreContext.newBuilderFrom(datastoreContextBuilder.build()).shardElectionTimeoutFactor(66).build()).when(newMockFactory).getShardDatastoreContext("default");
    Mockito.doReturn(DatastoreContext.newBuilderFrom(datastoreContextBuilder.build()).shardElectionTimeoutFactor(77).build()).when(newMockFactory).getShardDatastoreContext("topology");
    shardManager.tell(newMockFactory, kit.getRef());
    DatastoreContext newContext = MessageCollectorActor.expectFirstMatching(defaultShardActor, DatastoreContext.class);
    assertEquals("getShardElectionTimeoutFactor", 66, newContext.getShardElectionTimeoutFactor());
    newContext = MessageCollectorActor.expectFirstMatching(topologyShardActor, DatastoreContext.class);
    assertEquals("getShardElectionTimeoutFactor", 77, newContext.getShardElectionTimeoutFactor());
    LOG.info("testPerShardDatastoreContext ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) DatastoreContextFactory(org.opendaylight.controller.cluster.datastore.DatastoreContextFactory) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) AddressFromURIString(akka.actor.AddressFromURIString) Creator(akka.japi.Creator) TestKit(akka.testkit.javadsl.TestKit) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractMap(java.util.AbstractMap) Entry(java.util.Map.Entry) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) PrimaryShardInfoFutureCache(org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)32 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 ActorRef (akka.actor.ActorRef)4 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)3 AddressFromURIString (akka.actor.AddressFromURIString)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Entry (java.util.Map.Entry)2 Before (org.junit.Before)2 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)2 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)2 DatastoreContextFactory (org.opendaylight.controller.cluster.datastore.DatastoreContextFactory)2 ModuleShardConfiguration (org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)2 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)2 CreateShard (org.opendaylight.controller.cluster.datastore.messages.CreateShard)2 ModuleShardStrategy (org.opendaylight.controller.cluster.datastore.shardstrategy.ModuleShardStrategy)2 ShardStrategy (org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy)2 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)2 Address (akka.actor.Address)1