Search in sources :

Example 16 with StackStatusV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response in project cloudbreak by hortonworks.

the class ClusterStatusSyncHandlerTest method testOnApplicationEventWhenCBStackStatusActiveCBClusterStatusInactive.

@Test
public void testOnApplicationEventWhenCBStackStatusActiveCBClusterStatusInactive() {
    Cluster cluster = getACluster(ClusterState.SUSPENDED);
    when(clusterService.findById(anyLong())).thenReturn(cluster);
    StackStatusV4Response stackStatusV4Response = new StackStatusV4Response();
    stackStatusV4Response.setStatus(Status.AVAILABLE);
    stackStatusV4Response.setClusterStatus(Status.UPDATE_IN_PROGRESS);
    when(cloudbreakCommunicator.getStackStatusByCrn(anyString())).thenReturn(stackStatusV4Response);
    underTest.onApplicationEvent(new ClusterStatusSyncEvent(AUTOSCALE_CLUSTER_ID));
    verify(clusterService, never()).setState(anyLong(), any(ClusterState.class));
    verify(cloudbreakCommunicator).getStackStatusByCrn(CLOUDBREAK_STACK_CRN);
}
Also used : ClusterState(com.sequenceiq.periscope.api.model.ClusterState) ClusterStatusSyncEvent(com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent) Cluster(com.sequenceiq.periscope.domain.Cluster) StackStatusV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response) Test(org.junit.Test)

Example 17 with StackStatusV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response in project cloudbreak by hortonworks.

the class ClusterDeleteHandler method onApplicationEvent.

@Override
public void onApplicationEvent(ClusterDeleteEvent event) {
    Cluster cluster = clusterService.findById(event.getClusterId());
    if (cluster == null) {
        return;
    }
    LoggingUtils.buildMdcContext(cluster);
    StackStatusV4Response statusResponse = cloudbreakCommunicator.getStackStatusByCrn(cluster.getStackCrn());
    if (DELETE_COMPLETED.equals(statusResponse.getStatus())) {
        beforeDeleteCleanup(cluster);
        clusterService.removeById(event.getClusterId());
        LOGGER.info("Deleted cluster: {}, CB Stack status: {}", cluster.getStackCrn(), statusResponse.getStatus());
    }
}
Also used : Cluster(com.sequenceiq.periscope.domain.Cluster) StackStatusV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response)

Example 18 with StackStatusV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response 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)

Aggregations

StackStatusV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response)16 Cluster (com.sequenceiq.periscope.domain.Cluster)5 Test (org.junit.Test)4 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)3 ClusterStatusSyncEvent (com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent)3 SdxStatusEntity (com.sequenceiq.datalake.entity.SdxStatusEntity)2 ClusterState (com.sequenceiq.periscope.api.model.ClusterState)2 StackV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint)1 AutoscaleStackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response)1 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)1 AbstractEntityConverterTest (com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest)1 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1 DatalakeStatusEnum (com.sequenceiq.datalake.entity.DatalakeStatusEnum)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1