Search in sources :

Example 1 with ShardState

use of org.elasticsearch.cluster.SnapshotsInProgress.ShardState in project crate by crate.

the class SnapshotsInProgressSerializationTests method randomSnapshot.

private Entry randomSnapshot() {
    Snapshot snapshot = new Snapshot(randomAlphaOfLength(10), new SnapshotId(randomAlphaOfLength(10), randomAlphaOfLength(10)));
    boolean includeGlobalState = randomBoolean();
    boolean partial = randomBoolean();
    State state = randomFrom(State.values());
    int numberOfIndices = randomIntBetween(0, 10);
    List<IndexId> indices = new ArrayList<>();
    for (int i = 0; i < numberOfIndices; i++) {
        indices.add(new IndexId(randomAlphaOfLength(10), randomAlphaOfLength(10)));
    }
    List<String> templates = new ArrayList<>();
    if (includeGlobalState == false) {
        int numberOfTemplates = randomIntBetween(0, 5);
        for (int i = 0; i < numberOfTemplates; i++) {
            templates.add(randomAlphaOfLength(10));
        }
    }
    long startTime = randomLong();
    long repositoryStateId = randomLong();
    ImmutableOpenMap.Builder<ShardId, SnapshotsInProgress.ShardSnapshotStatus> builder = ImmutableOpenMap.builder();
    final List<Index> esIndices = indices.stream().map(i -> new Index(i.getName(), randomAlphaOfLength(10))).collect(Collectors.toList());
    for (Index idx : esIndices) {
        int shardsCount = randomIntBetween(1, 10);
        for (int j = 0; j < shardsCount; j++) {
            ShardId shardId = new ShardId(idx, j);
            String nodeId = randomAlphaOfLength(10);
            ShardState shardState = randomFrom(ShardState.values());
            builder.put(shardId, new SnapshotsInProgress.ShardSnapshotStatus(nodeId, shardState, shardState.failed() ? randomAlphaOfLength(10) : null, randomAlphaOfLength(10)));
        }
    }
    ImmutableOpenMap<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shards = builder.build();
    return new Entry(snapshot, includeGlobalState, partial, state, indices, templates, startTime, repositoryStateId, shards, randomBoolean());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) State(org.elasticsearch.cluster.SnapshotsInProgress.State) ClusterModule(org.elasticsearch.cluster.ClusterModule) Index(org.elasticsearch.index.Index) IndexId(org.elasticsearch.repositories.IndexId) Collectors(java.util.stream.Collectors) Diff(org.elasticsearch.cluster.Diff) Entry(org.elasticsearch.cluster.SnapshotsInProgress.Entry) ArrayList(java.util.ArrayList) List(java.util.List) AbstractDiffableWireSerializationTestCase(org.elasticsearch.test.AbstractDiffableWireSerializationTestCase) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress) ShardState(org.elasticsearch.cluster.SnapshotsInProgress.ShardState) Writeable(org.elasticsearch.common.io.stream.Writeable) Custom(org.elasticsearch.cluster.ClusterState.Custom) IndexId(org.elasticsearch.repositories.IndexId) ArrayList(java.util.ArrayList) Index(org.elasticsearch.index.Index) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) ShardId(org.elasticsearch.index.shard.ShardId) ShardState(org.elasticsearch.cluster.SnapshotsInProgress.ShardState) Entry(org.elasticsearch.cluster.SnapshotsInProgress.Entry) State(org.elasticsearch.cluster.SnapshotsInProgress.State) ShardState(org.elasticsearch.cluster.SnapshotsInProgress.ShardState) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ClusterModule (org.elasticsearch.cluster.ClusterModule)1 Custom (org.elasticsearch.cluster.ClusterState.Custom)1 Diff (org.elasticsearch.cluster.Diff)1 SnapshotsInProgress (org.elasticsearch.cluster.SnapshotsInProgress)1 Entry (org.elasticsearch.cluster.SnapshotsInProgress.Entry)1 ShardState (org.elasticsearch.cluster.SnapshotsInProgress.ShardState)1 State (org.elasticsearch.cluster.SnapshotsInProgress.State)1 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)1 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)1 Writeable (org.elasticsearch.common.io.stream.Writeable)1 Index (org.elasticsearch.index.Index)1 ShardId (org.elasticsearch.index.shard.ShardId)1 IndexId (org.elasticsearch.repositories.IndexId)1 AbstractDiffableWireSerializationTestCase (org.elasticsearch.test.AbstractDiffableWireSerializationTestCase)1