Search in sources :

Example 21 with STOPPED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED in project cloudbreak by hortonworks.

the class MockStackResponseGenerator method getMockStackV4Response.

public static StackV4Response getMockStackV4Response(String clusterCrn, String hostGroup, String fqdnBase, int currentHostGroupCount, boolean withUnhealthyInstances) {
    List<InstanceGroupV4Response> instanceGroupV4Responses = new ArrayList<>();
    InstanceMetaDataV4Response master1 = new InstanceMetaDataV4Response();
    master1.setDiscoveryFQDN("master1");
    master1.setInstanceId("test_instanceid" + "master1");
    instanceGroupV4Responses.add(instanceGroup("master", awsTemplate(), Set.of(master1)));
    InstanceMetaDataV4Response worker1 = new InstanceMetaDataV4Response();
    worker1.setDiscoveryFQDN("worker1");
    worker1.setInstanceId("test_instanceid" + "worker1");
    InstanceMetaDataV4Response worker2 = new InstanceMetaDataV4Response();
    worker2.setDiscoveryFQDN("worker2");
    worker2.setInstanceId("test_instanceid" + "worker2");
    instanceGroupV4Responses.add(instanceGroup("worker", awsTemplate(), Set.of(worker1, worker2)));
    Set fqdnToInstanceIds = new HashSet();
    if (!withUnhealthyInstances) {
        for (int i = 1; i <= currentHostGroupCount; i++) {
            InstanceMetaDataV4Response metadata1 = new InstanceMetaDataV4Response();
            metadata1.setDiscoveryFQDN(fqdnBase + i);
            metadata1.setInstanceId("test_instanceid_" + hostGroup + i);
            metadata1.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
            fqdnToInstanceIds.add(metadata1);
        }
    } else {
        // Add nodes with InstanceStatuses STOPPED and SERVICES_UNHEALTHY
        List<InstanceStatus> unhealthyStatuses = List.of(InstanceStatus.STOPPED, InstanceStatus.SERVICES_UNHEALTHY);
        for (InstanceStatus status : unhealthyStatuses) {
            InstanceMetaDataV4Response metadataResponse = new InstanceMetaDataV4Response();
            metadataResponse.setDiscoveryFQDN(fqdnBase + unhealthyStatuses.indexOf(status));
            metadataResponse.setInstanceId("test_instanceid_" + hostGroup + unhealthyStatuses.indexOf(status));
            metadataResponse.setInstanceStatus(status);
            fqdnToInstanceIds.add(metadataResponse);
        }
        // Add remaining healthy instances
        for (int i = unhealthyStatuses.size(); i < currentHostGroupCount; ++i) {
            InstanceMetaDataV4Response metadataResponse = new InstanceMetaDataV4Response();
            metadataResponse.setDiscoveryFQDN(fqdnBase + i);
            metadataResponse.setInstanceId("test_instanceid_" + hostGroup + i);
            metadataResponse.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
            fqdnToInstanceIds.add(metadataResponse);
        }
    }
    instanceGroupV4Responses.add(instanceGroup(hostGroup, awsTemplate(), fqdnToInstanceIds));
    StackV4Response mockReponse = new StackV4Response();
    mockReponse.setCrn(clusterCrn);
    mockReponse.setInstanceGroups(instanceGroupV4Responses);
    mockReponse.setCloudPlatform(CloudPlatform.AWS);
    return mockReponse;
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) HashSet(java.util.HashSet) Set(java.util.Set) InstanceMetaDataV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.instancemetadata.InstanceMetaDataV4Response) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) ArrayList(java.util.ArrayList) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) HashSet(java.util.HashSet)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)12 Test (org.junit.jupiter.api.Test)7 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)6 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)6 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 PollerException (com.dyngr.exception.PollerException)5 PollerStoppedException (com.dyngr.exception.PollerStoppedException)5 UserBreakException (com.dyngr.exception.UserBreakException)5 DatabaseAvailabilityType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)4 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)4 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Inject (javax.inject.Inject)3 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)2 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)2 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)2 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)2