Search in sources :

Example 1 with Status

use of com.sequenceiq.cloudbreak.api.model.Status in project cloudbreak by hortonworks.

the class ClusterMonitor method execute.

@Override
public void execute(JobExecutionContext context) {
    evalContext(context);
    try {
        CloudbreakClient cloudbreakClient = applicationContext.getBean(CloudbreakClientConfiguration.class).cloudbreakClient();
        ClusterService clusterService = applicationContext.getBean(ClusterService.class);
        List<Cluster> clusters = clusterService.findAll();
        Set<AutoscaleStackResponse> allStacks = cloudbreakClient.stackV1Endpoint().getAllForAutoscale();
        for (AutoscaleStackResponse stack : allStacks) {
            Status clusterStatus = stack.getClusterStatus();
            if (clusterStatus != null && AVAILABLE.equals(clusterStatus)) {
                String ambariIp = stack.getAmbariServerIp();
                Optional<Cluster> clusterOptional = clusters.stream().filter(c -> c.getStackId() != null && c.getStackId().equals(stack.getStackId())).findFirst();
                if (ambariIp != null) {
                    ClusterCreationEvaluator clusterCreationEvaluator = applicationContext.getBean(ClusterCreationEvaluator.class);
                    clusterCreationEvaluator.setContext(new ClusterCreationEvaluatorContext(stack, clusterOptional));
                    executorService.submit(clusterCreationEvaluator);
                } else {
                    LOGGER.info("Could not find Ambari for stack: {}(ID:{})", stack.getName(), stack.getStackId());
                }
            } else {
                LOGGER.info("Do not create or update cluster while the Cloudbreak cluster {}(ID:{}) is in '{}' state instead of 'AVAILABLE'!", stack.getName(), stack.getStackId(), stack.getClusterStatus());
            }
        }
    } catch (Exception ex) {
        LOGGER.error("New clusters could not be synchronized from Cloudbreak.", ex);
    }
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status) JobExecutionContext(org.quartz.JobExecutionContext) EvaluatorContext(com.sequenceiq.periscope.monitor.evaluator.EvaluatorContext) Logger(org.slf4j.Logger) Cluster(com.sequenceiq.periscope.domain.Cluster) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) LoggerFactory(org.slf4j.LoggerFactory) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) Set(java.util.Set) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) ApplicationContext(org.springframework.context.ApplicationContext) ClusterCreationEvaluator(com.sequenceiq.periscope.monitor.evaluator.ClusterCreationEvaluator) Status(com.sequenceiq.cloudbreak.api.model.Status) List(java.util.List) Component(org.springframework.stereotype.Component) JobDataMap(org.quartz.JobDataMap) ClusterCreationEvaluatorContext(com.sequenceiq.periscope.model.ClusterCreationEvaluatorContext) Map(java.util.Map) Optional(java.util.Optional) Collections(java.util.Collections) ExecutorService(java.util.concurrent.ExecutorService) CloudbreakClientConfiguration(com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration) ClusterService(com.sequenceiq.periscope.service.ClusterService) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) ClusterCreationEvaluatorContext(com.sequenceiq.periscope.model.ClusterCreationEvaluatorContext) Cluster(com.sequenceiq.periscope.domain.Cluster) CloudbreakClientConfiguration(com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration) ClusterService(com.sequenceiq.periscope.service.ClusterService) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) ClusterCreationEvaluator(com.sequenceiq.periscope.monitor.evaluator.ClusterCreationEvaluator)

Example 2 with Status

use of com.sequenceiq.cloudbreak.api.model.Status in project cloudbreak by hortonworks.

the class CloudbreakUtil method waitForStatuses.

private static WaitResult waitForStatuses(CloudbreakClient cloudbreakClient, String stackId, Map<String, String> desiredStatuses) {
    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, stackId, currentStatuses);
        sleep();
        StackV1Endpoint stackV1Endpoint = cloudbreakClient.stackV1Endpoint();
        try {
            Map<String, Object> statusResult = stackV1Endpoint.status(Long.valueOf(stackId));
            for (String statusPath : desiredStatuses.keySet()) {
                currentStatuses.put(statusPath, (String) statusResult.get(statusPath));
            }
        } 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(), stackId, 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 : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) Arrays(java.util.Arrays) HostMetadataResponse(com.sequenceiq.cloudbreak.api.model.HostMetadataResponse) HostGroupResponse(com.sequenceiq.cloudbreak.api.model.HostGroupResponse) LoggerFactory(org.slf4j.LoggerFactory) AutoscaleClusterHistoryResponse(com.sequenceiq.periscope.api.model.AutoscaleClusterHistoryResponse) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) HashMap(java.util.HashMap) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) AutoscaleClient(com.sequenceiq.periscope.client.AutoscaleClient) HashSet(java.util.HashSet) Value(org.springframework.beans.factory.annotation.Value) Status(com.sequenceiq.cloudbreak.api.model.Status) StackEndpoint(com.sequenceiq.cloudbreak.api.endpoint.common.StackEndpoint) Assert(org.testng.Assert) Map(java.util.Map) FALSE(java.lang.Boolean.FALSE) Logger(org.slf4j.Logger) HistoryEndpoint(com.sequenceiq.periscope.api.endpoint.v1.HistoryEndpoint) Collection(java.util.Collection) Set(java.util.Set) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) Family(javax.ws.rs.core.Response.Status.Family) List(java.util.List) Component(org.springframework.stereotype.Component) Response(javax.ws.rs.core.Response) Entry(java.util.Map.Entry) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) CloudbreakEventsJson(com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson) EventEndpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint) Collections(java.util.Collections) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) StringUtils(org.springframework.util.StringUtils) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HashMap(java.util.HashMap) StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) StackEndpoint(com.sequenceiq.cloudbreak.api.endpoint.common.StackEndpoint) HistoryEndpoint(com.sequenceiq.periscope.api.endpoint.v1.HistoryEndpoint) EventEndpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint)

Example 3 with Status

use of com.sequenceiq.cloudbreak.api.model.Status in project cloudbreak by hortonworks.

the class StackStartStopService method handleError.

private void handleError(StackView stackView, Exception exception, DetailedStackStatus detailedStackStatus, Msg msg, String logMessage) {
    LOGGER.error(logMessage, exception);
    Status stackStatus = detailedStackStatus.getStatus();
    stackUpdater.updateStackStatus(stackView.getId(), detailedStackStatus, logMessage + exception.getMessage());
    flowMessageService.fireEventAndLog(stackView.getId(), msg, stackStatus.name(), exception.getMessage());
    if (stackView.getClusterView() != null) {
        clusterService.updateClusterStatusByStackId(stackView.getId(), STOPPED);
        if (stackView.getClusterView().getEmailNeeded()) {
            emailSenderService.sendStopFailureEmail(stackView.getClusterView().getOwner(), stackView.getClusterView().getEmailTo(), stackUtil.extractAmbariIp(stackView), stackView.getClusterView().getName());
            flowMessageService.fireEventAndLog(stackView.getId(), Msg.STACK_NOTIFICATION_EMAIL, stackStatus.name());
        }
    }
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status) BillingStatus(com.sequenceiq.cloudbreak.common.type.BillingStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)

Example 4 with Status

use of com.sequenceiq.cloudbreak.api.model.Status in project cloudbreak by hortonworks.

the class AmbariClusterStatusUpdater method updateClusterStatus.

private void updateClusterStatus(Long stackId, Status stackStatus, Cluster cluster, ClusterStatus ambariClusterStatus) {
    Status statusInEvent = stackStatus;
    String statusReason = ambariClusterStatus.getStatusReason();
    if (isUpdateEnabled(ambariClusterStatus)) {
        if (updateClusterStatus(stackId, cluster, ambariClusterStatus.getClusterStatus())) {
            statusInEvent = ambariClusterStatus.getStackStatus();
            statusReason = ambariClusterStatus.getStatusReason();
        } else {
            statusReason = "The cluster's state is up to date.";
        }
    }
    cloudbreakEventService.fireCloudbreakEvent(stackId, statusInEvent.name(), cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_SYNCHRONIZED.code(), Collections.singletonList(statusReason)));
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status)

Example 5 with Status

use of com.sequenceiq.cloudbreak.api.model.Status in project cloudbreak by hortonworks.

the class ClusterDownscaleService method handleClusterDownscaleFailure.

public void handleClusterDownscaleFailure(long stackId, Exception error) {
    String errorDetailes = error.getMessage();
    LOGGER.error("Error during Cluster downscale flow: ", error);
    Status status = UPDATE_FAILED;
    if (error instanceof NotEnoughNodeException) {
        status = AVAILABLE;
    }
    clusterService.updateClusterStatusByStackId(stackId, status, errorDetailes);
    stackUpdater.updateStackStatus(stackId, DetailedStackStatus.AVAILABLE, "Node(s) could not be removed from the cluster: " + errorDetailes);
    flowMessageService.fireEventAndLog(stackId, Msg.AMBARI_CLUSTER_SCALING_FAILED, UPDATE_FAILED.name(), "removed from", errorDetailes);
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) InstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus) NotEnoughNodeException(com.sequenceiq.cloudbreak.service.cluster.NotEnoughNodeException)

Aggregations

Status (com.sequenceiq.cloudbreak.api.model.Status)7 DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)3 CloudbreakEventsJson (com.sequenceiq.cloudbreak.api.model.CloudbreakEventsJson)2 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)2 Stack (com.sequenceiq.cloudbreak.domain.Stack)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Component (org.springframework.stereotype.Component)2 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)1 StackEndpoint (com.sequenceiq.cloudbreak.api.endpoint.common.StackEndpoint)1 EventEndpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint)1 StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)1 AutoscaleStackResponse (com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse)1 HostGroupResponse (com.sequenceiq.cloudbreak.api.model.HostGroupResponse)1 HostMetadataResponse (com.sequenceiq.cloudbreak.api.model.HostMetadataResponse)1 InstanceGroupResponse (com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse)1