Search in sources :

Example 61 with Status

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

the class CloudbreakUtil method waitForStatuses.

private static WaitResult waitForStatuses(CloudbreakClient cloudbreakClient, Long workspaceId, String stackName, Map<String, String> desiredStatuses, String accountId) {
    WaitResult waitResult = WaitResult.SUCCESSFUL;
    Map<String, String> currentStatuses = new HashMap<>();
    int retryCount = 0;
    do {
        LOGGER.info("Waiting for status(es) {}, stack id: {}, current status(es) {} ...", desiredStatuses, stackName, currentStatuses);
        sleep();
        StackV4Endpoint stackV4Endpoint = cloudbreakClient.stackV4Endpoint();
        try {
            StackStatusV4Response statusResult = stackV4Endpoint.getStatusByName(workspaceId, stackName, accountId);
            for (String statusPath : desiredStatuses.keySet()) {
                currentStatuses.put(statusPath, statusResult.getStatus().name());
            }
        } catch (RuntimeException ignore) {
            continue;
        }
        retryCount++;
    } while (!checkStatuses(currentStatuses, desiredStatuses) && !checkFailedStatuses(currentStatuses) && retryCount < MAX_RETRY);
    LOGGER.info("Status(es) {} for {} are in desired status(es) {}", desiredStatuses.keySet(), stackName, currentStatuses.values());
    if (currentStatuses.values().stream().anyMatch(cs -> cs.contains("FAILED")) || checkNotExpectedDelete(currentStatuses, desiredStatuses)) {
        waitResult = WaitResult.FAILED;
    }
    if (retryCount == MAX_RETRY) {
        waitResult = WaitResult.TIMEOUT;
    }
    return waitResult;
}
Also used : Arrays(java.util.Arrays) StackV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) StackStatusV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) HashMap(java.util.HashMap) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) Component(org.springframework.stereotype.Component) Map(java.util.Map) Entry(java.util.Map.Entry) Collections(java.util.Collections) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) HashMap(java.util.HashMap) StackV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint) StackV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint) StackStatusV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response)

Example 62 with Status

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

the class SshJClientActions method checkMeteringStatus.

public DistroXTestDto checkMeteringStatus(DistroXTestDto testDto, List<InstanceGroupV4Response> instanceGroups, List<String> hostGroupNames) {
    String meteringStatusCommand = "sudo cdp-doctor metering status --format json";
    Map<String, Pair<Integer, String>> meteringStatusReportByIp = getInstanceGroupIps(instanceGroups, hostGroupNames, false).stream().collect(Collectors.toMap(ip -> ip, ip -> executeSshCommand(ip, meteringStatusCommand)));
    for (Entry<String, Pair<Integer, String>> meteringStatusReport : meteringStatusReportByIp.entrySet()) {
        List<Integer> heartbeatEventCounts = new Json(meteringStatusReport.getValue().getValue()).getMap().entrySet().stream().filter(status -> String.valueOf(status.getKey()).contains("heartbeatEventCount")).map(Entry::getValue).collect(Collectors.toList()).stream().map(countObject -> (Integer) countObject).collect(Collectors.toList());
        LOGGER.info(format("heartbeatEventCounts: %s", heartbeatEventCounts));
        Log.log(LOGGER, format(" Found '%s' Metering Heartbeat Events at '%s' instance. ", heartbeatEventCounts, meteringStatusReport.getKey()));
        if (CollectionUtils.isEmpty(heartbeatEventCounts) || heartbeatEventCounts.contains(0)) {
            LOGGER.error("Metering Heartbeat Events does NOT generated on '{}' instance!", meteringStatusReport.getKey());
            throw new TestFailException(format("Metering Heartbeat Events does NOT generated on '%s' instance!", meteringStatusReport.getKey()));
        }
    }
    for (Entry<String, Pair<Integer, String>> meteringStatusReport : meteringStatusReportByIp.entrySet()) {
        List<String> heartbeatStatusesNotOk = new Json(meteringStatusReport.getValue().getValue()).getMap().entrySet().stream().filter(status -> String.valueOf(status.getValue()).contains("NOK")).map(Entry::getKey).collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(heartbeatStatusesNotOk)) {
            heartbeatStatusesNotOk.forEach(event -> {
                if (StringUtils.containsIgnoreCase(event, "databusReachable")) {
                    Log.log(LOGGER, format(" Found 'databusReachable' status is not OK at '%s' instance. However this is acceptable!", meteringStatusReport.getKey()));
                    LOGGER.warn("Found 'databusReachable' status is not OK at '{}' instance. However this is acceptable!", meteringStatusReport.getKey());
                } else {
                    Log.log(LOGGER, format(" Found '%s' not OK at '%s' instance. ", event, meteringStatusReport.getKey()));
                    LOGGER.error("There is 'Not OK' Metering Heartbeat status {} is present on '{}' instance!", event, meteringStatusReport.getKey());
                    throw new TestFailException(format("There is 'Not OK' Metering Heartbeat status %s is present on '%s' instance!", event, meteringStatusReport.getKey()));
                }
            });
        }
    }
    return testDto;
}
Also used : FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) SshJClient(com.sequenceiq.it.cloudbreak.util.ssh.client.SshJClient) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Pair(org.apache.commons.lang3.tuple.Pair) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Map(java.util.Map) FreeIpaClient(com.sequenceiq.it.cloudbreak.FreeIpaClient) SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) Logger(org.slf4j.Logger) Collection(java.util.Collection) Log(com.sequenceiq.it.cloudbreak.log.Log) Set(java.util.Set) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) InstanceMetaDataResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) AbstractSdxTestDto(com.sequenceiq.it.cloudbreak.dto.AbstractSdxTestDto) SSHClient(net.schmizz.sshj.SSHClient) Entry(java.util.Map.Entry) Entry(java.util.Map.Entry) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) Json(com.sequenceiq.cloudbreak.common.json.Json) Pair(org.apache.commons.lang3.tuple.Pair)

Example 63 with Status

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

the class AwsSdxSpotInstanceTest method testSdxOnSpotInstances.

@Test(dataProvider = TEST_CONTEXT)
@Description(given = "there is a running cloudbreak ", when = "creating an SDX with 100% spot percentage ", then = "SDX is started on spot instances, or fails with insufficient spot capacity")
public void testSdxOnSpotInstances(TestContext testContext) {
    String sdx = resourcePropertyProvider().getName();
    SdxDatabaseRequest database = new SdxDatabaseRequest();
    database.setCreate(false);
    testContext.given(SdxTestDto.class).withCloudStorage().withExternalDatabase(database).withSpotPercentage(100).when(sdxTestClient.create(), key(sdx)).then((tc, testDto, client) -> {
        testDto.await(STACK_CREATED, key(sdx));
        Map<String, Exception> exceptionMap = testContext.getExceptionMap();
        if (!exceptionMap.isEmpty()) {
            String key = testDto.getAwaitExceptionKey(STACK_CREATED);
            if (exceptionMap.containsKey(key)) {
                LOGGER.info("Awaiting STACK_CREATED failed, clearing exception to check status reason", exceptionMap.get(key));
                exceptionMap.remove(key);
            }
        }
        return testDto;
    }).when(sdxTestClient.describe()).then(assertSpotInstances()).validate();
}
Also used : SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) RunningParameter.key(com.sequenceiq.it.cloudbreak.context.RunningParameter.key) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) Test(org.testng.annotations.Test) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) SdxTestClient(com.sequenceiq.it.cloudbreak.client.SdxTestClient) SdxDatabaseRequest(com.sequenceiq.sdx.api.model.SdxDatabaseRequest) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) Assertion(com.sequenceiq.it.cloudbreak.assertion.Assertion) Map(java.util.Map) SdxClient(com.sequenceiq.it.cloudbreak.SdxClient) InstanceLifeCycle(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceLifeCycle) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) Map(java.util.Map) SdxDatabaseRequest(com.sequenceiq.sdx.api.model.SdxDatabaseRequest) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest)

Example 64 with Status

use of com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status 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

DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)23 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)22 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)18 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)12 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 StackStatusV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response)9 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)7 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)6 Collection (java.util.Collection)6 List (java.util.List)6 Set (java.util.Set)6 Inject (javax.inject.Inject)6 PollerStoppedException (com.dyngr.exception.PollerStoppedException)5 ClusterV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response)5 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)5