Search in sources :

Example 76 with State

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.State in project controller by opendaylight.

the class ClusterAdminRpcService method changeMemberVotingStatesForAllShards.

@Override
public Future<RpcResult<ChangeMemberVotingStatesForAllShardsOutput>> changeMemberVotingStatesForAllShards(final ChangeMemberVotingStatesForAllShardsInput input) {
    List<MemberVotingState> memberVotingStates = input.getMemberVotingState();
    if (memberVotingStates == null || memberVotingStates.isEmpty()) {
        return newFailedRpcResultFuture("No member voting state input was specified");
    }
    final List<Entry<ListenableFuture<Success>, ShardResultBuilder>> shardResultData = new ArrayList<>();
    Function<String, Object> messageSupplier = shardName -> toChangeShardMembersVotingStatus(shardName, memberVotingStates);
    LOG.info("Change member voting states for all shards");
    sendMessageToManagerForConfiguredShards(DataStoreType.Config, shardResultData, messageSupplier);
    sendMessageToManagerForConfiguredShards(DataStoreType.Operational, shardResultData, messageSupplier);
    return waitForShardResults(shardResultData, shardResults -> new ChangeMemberVotingStatesForAllShardsOutputBuilder().setShardResult(shardResults).build(), "Failed to change member voting states");
}
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) ChangeMemberVotingStatesForAllShardsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForAllShardsOutputBuilder) MemberVotingState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.member.voting.states.input.MemberVotingState) ArrayList(java.util.ArrayList) Success(akka.actor.Status.Success)

Example 77 with State

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.State in project controller by opendaylight.

the class ClusterAdminRpcServiceTest method testFlipMemberVotingStatesWithNoInitialLeader.

@Test
public void testFlipMemberVotingStatesWithNoInitialLeader() throws Exception {
    String name = "testFlipMemberVotingStatesWithNoInitialLeader";
    // Members 1, 2, and 3 are initially started up as non-voting. Members 4, 5, and 6 are initially
    // non-voting and simulated as down by not starting them up.
    ServerConfigurationPayload persistedServerConfig = new ServerConfigurationPayload(Arrays.asList(new ServerInfo("member-1", false), new ServerInfo("member-2", false), new ServerInfo("member-3", false), new ServerInfo("member-4", true), new ServerInfo("member-5", true), new ServerInfo("member-6", true)));
    setupPersistedServerConfigPayload(persistedServerConfig, "member-1", name, "cars", "people");
    setupPersistedServerConfigPayload(persistedServerConfig, "member-2", name, "cars", "people");
    setupPersistedServerConfigPayload(persistedServerConfig, "member-3", name, "cars", "people");
    String moduleShardsConfig = "module-shards-member1-and-2-and-3.conf";
    final MemberNode replicaNode1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).datastoreContextBuilder(DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(300).shardElectionTimeoutFactor(1)).build();
    final MemberNode replicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    final MemberNode replicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    // Initially there won't be a leader b/c all the up nodes are non-voting.
    replicaNode1.waitForMembersUp("member-2", "member-3");
    verifyVotingStates(replicaNode1.configDataStore(), "cars", new SimpleEntry<>("member-1", FALSE), new SimpleEntry<>("member-2", FALSE), new SimpleEntry<>("member-3", FALSE), new SimpleEntry<>("member-4", TRUE), new SimpleEntry<>("member-5", TRUE), new SimpleEntry<>("member-6", TRUE));
    verifyRaftState(replicaNode1.configDataStore(), "cars", raftState -> assertEquals("Expected raft state", RaftState.Follower.toString(), raftState.getRaftState()));
    ClusterAdminRpcService service1 = new ClusterAdminRpcService(replicaNode1.configDataStore(), replicaNode1.operDataStore(), null);
    RpcResult<FlipMemberVotingStatesForAllShardsOutput> rpcResult = service1.flipMemberVotingStatesForAllShards().get(10, TimeUnit.SECONDS);
    FlipMemberVotingStatesForAllShardsOutput result = verifySuccessfulRpcResult(rpcResult);
    verifyShardResults(result.getShardResult(), successShardResult("cars", DataStoreType.Config), successShardResult("people", DataStoreType.Config), successShardResult("cars", DataStoreType.Operational), successShardResult("people", DataStoreType.Operational));
    verifyVotingStates(new AbstractDataStore[] { replicaNode1.configDataStore(), replicaNode1.operDataStore(), replicaNode2.configDataStore(), replicaNode2.operDataStore(), replicaNode3.configDataStore(), replicaNode3.operDataStore() }, new String[] { "cars", "people" }, new SimpleEntry<>("member-1", TRUE), new SimpleEntry<>("member-2", TRUE), new SimpleEntry<>("member-3", TRUE), new SimpleEntry<>("member-4", FALSE), new SimpleEntry<>("member-5", FALSE), new SimpleEntry<>("member-6", FALSE));
    // Since member 1 was changed to voting and there was no leader, it should've started and election
    // and become leader
    verifyRaftState(replicaNode1.configDataStore(), "cars", raftState -> {
        assertNotNull("Expected non-null leader Id", raftState.getLeader());
        assertTrue("Expected leader member-1. Actual: " + raftState.getLeader(), raftState.getLeader().contains("member-1"));
    });
    verifyRaftState(replicaNode1.operDataStore(), "cars", raftState -> {
        assertNotNull("Expected non-null leader Id", raftState.getLeader());
        assertTrue("Expected leader member-1. Actual: " + raftState.getLeader(), raftState.getLeader().contains("member-1"));
    });
}
Also used : MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) ServerConfigurationPayload(org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload) ServerInfo(org.opendaylight.controller.cluster.raft.persisted.ServerInfo) FlipMemberVotingStatesForAllShardsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.FlipMemberVotingStatesForAllShardsOutput) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 78 with State

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.State in project bgpcep by opendaylight.

the class GlobalUtil method buildAfiSafi.

/**
 * Build Afi Safi containing State.
 *
 * @param ribState             containing RIb Operational State
 * @param tablesKey            table Key
 * @param bgpTableTypeRegistry BGP TableType Registry
 * @return Afi Safi Operational State
 */
public static AfiSafi buildAfiSafi(final BGPRibState ribState, final TablesKey tablesKey, final BGPTableTypeRegistryConsumer bgpTableTypeRegistry) {
    final Optional<Class<? extends AfiSafiType>> optAfiSafi = bgpTableTypeRegistry.getAfiSafiType(tablesKey);
    if (!optAfiSafi.isPresent()) {
        return null;
    }
    final State state = new StateBuilder().addAugmentation(GlobalAfiSafiStateAugmentation.class, new GlobalAfiSafiStateAugmentationBuilder().setTotalPaths(ribState.getPathCount(tablesKey)).setTotalPrefixes(ribState.getPrefixesCount(tablesKey)).build()).build();
    return new AfiSafiBuilder().setAfiSafiName(optAfiSafi.get()).setState(state).build();
}
Also used : GlobalAfiSafiStateAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.GlobalAfiSafiStateAugmentation) AfiSafiBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafiBuilder) GlobalAfiSafiStateAugmentationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.GlobalAfiSafiStateAugmentationBuilder) BGPRibState(org.opendaylight.protocol.bgp.rib.spi.state.BGPRibState) State(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.State) StateBuilder(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.StateBuilder) AfiSafiType(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.AfiSafiType)

Example 79 with State

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.State in project bgpcep by opendaylight.

the class GlobalStateCliUtils method displayRibOperationalState.

static void displayRibOperationalState(@NonNull final String ribId, @NonNull final Global global, @NonNull final PrintStream stream) {
    final State globalState = global.getState();
    final ShellTable table = new ShellTable();
    table.column("Attribute").alignLeft();
    table.column("Value").alignLeft();
    addHeader(table, "RIB state");
    table.addRow().addContent("Router Id", ribId);
    table.addRow().addContent("As", globalState.getAs());
    table.addRow().addContent("Total Paths", globalState.getTotalPaths());
    table.addRow().addContent("Total Prefixes", globalState.getTotalPrefixes());
    global.getAfiSafis().getAfiSafi().forEach(afiSafi -> displayAfiSafi(afiSafi, table));
    table.print(stream);
}
Also used : ShellTable(org.apache.karaf.shell.table.ShellTable) State(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.State)

Example 80 with State

use of org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.afi.safi.State in project bgpcep by opendaylight.

the class GlobalStateCliUtils method displayAfiSafi.

private static void displayAfiSafi(final AfiSafi afiSafi, final ShellTable table) {
    final GlobalAfiSafiStateAugmentation state = afiSafi.getState().getAugmentation(GlobalAfiSafiStateAugmentation.class);
    addHeader(table, "AFI/SAFI state");
    table.addRow().addContent("Family", afiSafi.getAfiSafiName().getSimpleName());
    if (state == null) {
        return;
    }
    table.addRow().addContent("Total Paths", state.getTotalPaths());
    table.addRow().addContent("Total Prefixes", state.getTotalPrefixes());
}
Also used : GlobalAfiSafiStateAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.GlobalAfiSafiStateAugmentation)

Aggregations

ArrayList (java.util.ArrayList)31 Test (org.junit.Test)28 BigInteger (java.math.BigInteger)27 List (java.util.List)15 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)14 Collections (java.util.Collections)13 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)13 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Optional (com.google.common.base.Optional)11 Inject (javax.inject.Inject)11 Singleton (javax.inject.Singleton)11 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)10 ManagedNewTransactionRunnerImpl (org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl)10 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)10 ParentRefs (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs)10 FutureCallback (com.google.common.util.concurrent.FutureCallback)9 ByteBuf (io.netty.buffer.ByteBuf)9 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)9