Search in sources :

Example 1 with AVAILABLE

use of com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE 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 AVAILABLE

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

the class ClusterDownscaleService method updateMetadata.

public void updateMetadata(Long stackId, Collection<String> hostNames, String hostGroupName) {
    StackView stackView = stackService.getByIdView(stackId);
    ClusterView clusterView = stackView.getClusterView();
    hostNames.forEach(hn -> {
        HostGroup hostGroup = hostGroupService.getByClusterIdAndName(clusterView.getId(), hostGroupName);
        List<HostMetadata> hostMetaToRemove = hostGroup.getHostMetadata().stream().filter(md -> hostNames.contains(md.getHostName())).collect(Collectors.toList());
        hostGroup.getHostMetadata().removeAll(hostMetaToRemove);
        hostGroupService.save(hostGroup);
    });
    LOGGER.info("Start updating metadata");
    for (String hostName : hostNames) {
        stackService.updateMetaDataStatus(stackView.getId(), hostName, InstanceStatus.DECOMMISSIONED);
    }
    clusterService.updateClusterStatusByStackId(stackView.getId(), AVAILABLE);
    flowMessageService.fireEventAndLog(stackId, Msg.AMBARI_CLUSTER_SCALED_DOWN, AVAILABLE.name());
}
Also used : ClusterView(com.sequenceiq.cloudbreak.domain.view.ClusterView) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) UPDATE_FAILED(com.sequenceiq.cloudbreak.api.model.Status.UPDATE_FAILED) LoggerFactory(org.slf4j.LoggerFactory) Msg(com.sequenceiq.cloudbreak.core.flow2.stack.Msg) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) CloudbreakMessagesService(com.sequenceiq.cloudbreak.service.messages.CloudbreakMessagesService) Inject(javax.inject.Inject) Status(com.sequenceiq.cloudbreak.api.model.Status) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) Service(org.springframework.stereotype.Service) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Logger(org.slf4j.Logger) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) Collection(java.util.Collection) Set(java.util.Set) FlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.FlowMessageService) NotEnoughNodeException(com.sequenceiq.cloudbreak.service.cluster.NotEnoughNodeException) Collectors(java.util.stream.Collectors) StackUpdater(com.sequenceiq.cloudbreak.repository.StackUpdater) List(java.util.List) ClusterView(com.sequenceiq.cloudbreak.domain.view.ClusterView) CollectionUtils(org.springframework.util.CollectionUtils) InstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) CloudbreakEventService(com.sequenceiq.cloudbreak.service.events.CloudbreakEventService) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Aggregations

Status (com.sequenceiq.cloudbreak.api.model.Status)2 AVAILABLE (com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE)2 List (java.util.List)2 Set (java.util.Set)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 AutoscaleStackResponse (com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse)1 DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)1 InstanceStatus (com.sequenceiq.cloudbreak.api.model.InstanceStatus)1 UPDATE_FAILED (com.sequenceiq.cloudbreak.api.model.Status.UPDATE_FAILED)1 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)1 FlowMessageService (com.sequenceiq.cloudbreak.core.flow2.stack.FlowMessageService)1 Msg (com.sequenceiq.cloudbreak.core.flow2.stack.Msg)1 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)1 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)1 ClusterView (com.sequenceiq.cloudbreak.domain.view.ClusterView)1 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)1 StackUpdater (com.sequenceiq.cloudbreak.repository.StackUpdater)1 ClusterService (com.sequenceiq.cloudbreak.service.cluster.ClusterService)1 NotEnoughNodeException (com.sequenceiq.cloudbreak.service.cluster.NotEnoughNodeException)1