Search in sources :

Example 1 with Type

use of org.opensearch.cluster.routing.allocation.decider.Decision.Type in project OpenSearch by opensearch-project.

the class AllocateUnassignedDecision method fromDecision.

/**
 * Creates a {@link AllocateUnassignedDecision} from the given {@link Decision} and the assigned node, if any.
 */
public static AllocateUnassignedDecision fromDecision(Decision decision, @Nullable DiscoveryNode assignedNode, @Nullable List<NodeAllocationResult> nodeDecisions) {
    final Type decisionType = decision.type();
    AllocationStatus allocationStatus = decisionType != Decision.Type.YES ? AllocationStatus.fromDecision(decisionType) : null;
    return new AllocateUnassignedDecision(allocationStatus, assignedNode, null, nodeDecisions, false, 0L, 0L);
}
Also used : Type(org.opensearch.cluster.routing.allocation.decider.Decision.Type) AllocationStatus(org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus)

Example 2 with Type

use of org.opensearch.cluster.routing.allocation.decider.Decision.Type in project OpenSearch by opensearch-project.

the class AllocationDecisionTests method testFromDecisionType.

/**
 * Tests getting a {@link AllocationDecision} from {@link Type}.
 */
public void testFromDecisionType() {
    Type type = randomFrom(Type.values());
    AllocationDecision allocationDecision = AllocationDecision.fromDecisionType(type);
    AllocationDecision expected = type == Type.NO ? AllocationDecision.NO : type == Type.THROTTLE ? AllocationDecision.THROTTLED : AllocationDecision.YES;
    assertEquals(expected, allocationDecision);
}
Also used : Type(org.opensearch.cluster.routing.allocation.decider.Decision.Type)

Example 3 with Type

use of org.opensearch.cluster.routing.allocation.decider.Decision.Type in project OpenSearch by opensearch-project.

the class MoveDecisionTests method testSerialization.

public void testSerialization() throws IOException {
    List<NodeAllocationResult> nodeDecisions = new ArrayList<>();
    DiscoveryNode node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("node2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    Type finalDecision = randomFrom(Type.values());
    DiscoveryNode assignedNode = finalDecision == Type.YES ? node1 : null;
    nodeDecisions.add(new NodeAllocationResult(node1, Decision.NO, 2));
    nodeDecisions.add(new NodeAllocationResult(node2, finalDecision == Type.YES ? Decision.YES : randomFrom(Decision.NO, Decision.THROTTLE, Decision.YES), 1));
    MoveDecision moveDecision = MoveDecision.cannotRemain(Decision.NO, AllocationDecision.fromDecisionType(finalDecision), assignedNode, nodeDecisions);
    BytesStreamOutput output = new BytesStreamOutput();
    moveDecision.writeTo(output);
    MoveDecision readDecision = new MoveDecision(output.bytes().streamInput());
    assertEquals(moveDecision.canRemain(), readDecision.canRemain());
    assertEquals(moveDecision.getExplanation(), readDecision.getExplanation());
    assertEquals(moveDecision.forceMove(), readDecision.forceMove());
    assertEquals(moveDecision.getNodeDecisions().size(), readDecision.getNodeDecisions().size());
    assertEquals(moveDecision.getTargetNode(), readDecision.getTargetNode());
    assertEquals(moveDecision.getAllocationDecision(), readDecision.getAllocationDecision());
    // node2 should have the highest sort order
    assertEquals("node2", readDecision.getNodeDecisions().iterator().next().getNode().getId());
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Type(org.opensearch.cluster.routing.allocation.decider.Decision.Type) ArrayList(java.util.ArrayList) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Aggregations

Type (org.opensearch.cluster.routing.allocation.decider.Decision.Type)3 ArrayList (java.util.ArrayList)1 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)1 AllocationStatus (org.opensearch.cluster.routing.UnassignedInfo.AllocationStatus)1 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)1