Search in sources :

Example 1 with Cluster

use of com.sequenceiq.periscope.domain.Cluster in project cloudbreak by hortonworks.

the class AutoScaleClusterCommonService method getClusters.

public List<AutoscaleClusterResponse> getClusters() {
    PeriscopeUser user = authenticatedUserService.getPeriscopeUser();
    MDCBuilder.buildUserMdcContext(user);
    List<Cluster> clusters = clusterService.findAllByUser(user);
    return clusterConverter.convertAllToJson(clusters);
}
Also used : PeriscopeUser(com.sequenceiq.periscope.domain.PeriscopeUser) Cluster(com.sequenceiq.periscope.domain.Cluster)

Example 2 with Cluster

use of com.sequenceiq.periscope.domain.Cluster in project cloudbreak by hortonworks.

the class AutoScaleClusterCommonService method setCluster.

private AutoscaleClusterResponse setCluster(PeriscopeUser user, AutoscaleClusterRequest json, Long clusterId) {
    Ambari ambari = ambariConverter.convert(json);
    Long stackId = json.getStackId();
    boolean access = clusterSecurityService.hasAccess(user, ambari, stackId);
    if (!access) {
        String host = ambari.getHost();
        LOGGER.info("Illegal access to Ambari cluster '{}' from user '{}'", host, user.getEmail());
        throw new AccessDeniedException(String.format("Accessing Ambari cluster '%s' is not allowed", host));
    } else {
        Cluster cluster = clusterRequestConverter.convert(json);
        if (!hasAmbariConnectionDetailsSpecified(json)) {
            AmbariStack ambariStack = new AmbariStack(ambari, stackId, null);
            cluster = clusterService.create(cluster, user, ambariStack, PENDING);
        } else {
            AmbariStack resolvedAmbari = clusterSecurityService.tryResolve(ambari);
            cluster = clusterId == null ? clusterService.create(cluster, user, resolvedAmbari, RUNNING) : clusterService.update(clusterId, resolvedAmbari, cluster.isAutoscalingEnabled());
        }
        createHistoryAndNotification(cluster);
        return createClusterJsonResponse(cluster);
    }
}
Also used : AmbariStack(com.sequenceiq.periscope.model.AmbariStack) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Cluster(com.sequenceiq.periscope.domain.Cluster) Ambari(com.sequenceiq.periscope.domain.Ambari)

Example 3 with Cluster

use of com.sequenceiq.periscope.domain.Cluster in project cloudbreak by hortonworks.

the class ScalingHandler method onApplicationEvent.

@Override
public void onApplicationEvent(ScalingEvent event) {
    BaseAlert alert = event.getAlert();
    Cluster cluster = clusterService.find(alert.getCluster().getId());
    MDCBuilder.buildMdcContext(cluster);
    scale(cluster, alert.getScalingPolicy());
}
Also used : BaseAlert(com.sequenceiq.periscope.domain.BaseAlert) Cluster(com.sequenceiq.periscope.domain.Cluster)

Example 4 with Cluster

use of com.sequenceiq.periscope.domain.Cluster in project cloudbreak by hortonworks.

the class AmbariAgentHealthEvaluator method run.

@Override
public void run() {
    Cluster cluster = clusterService.find(clusterId);
    MDCBuilder.buildMdcContext(cluster);
    LOGGER.info("Checking '{}' alerts.", AMBARI_AGENT_HEARTBEAT);
    try {
        AmbariClient ambariClient = ambariClientProvider.createAmbariClient(cluster);
        List<Map<String, Object>> alertHistory = ambariClient.getAlert(AMBARI_AGENT_HEARTBEAT_DEF_NAME);
        if (!alertHistory.isEmpty()) {
            List<String> hostNamesToRecover = new ArrayList<>();
            for (Map<String, Object> history : alertHistory) {
                String currentState = (String) history.get(ALERT_STATE);
                if (isAlertStateMet(currentState)) {
                    String hostName = (String) history.get(HOST_NAME);
                    hostNamesToRecover.add(hostName);
                    LOGGER.info("Alert: {} is in '{}' state for host '{}'.", AMBARI_AGENT_HEARTBEAT, currentState, hostName);
                }
            }
            if (!hostNamesToRecover.isEmpty()) {
                hostNamesToRecover.forEach(hn -> LOGGER.info("Host to recover: {}", hn));
                CloudbreakClient cbClient = cloudbreakClientConfiguration.cloudbreakClient();
                FailureReport failureReport = new FailureReport();
                failureReport.setFailedNodes(hostNamesToRecover);
                cbClient.clusterEndpoint().failureReport(cluster.getStackId(), failureReport);
            }
        }
    } catch (Exception e) {
        LOGGER.warn(String.format("Failed to retrieve '%s' alerts.", AMBARI_AGENT_HEARTBEAT), e);
        publishEvent(new UpdateFailedEvent(clusterId));
    }
}
Also used : CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) FailureReport(com.sequenceiq.cloudbreak.api.model.FailureReport) UpdateFailedEvent(com.sequenceiq.periscope.monitor.event.UpdateFailedEvent) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.periscope.domain.Cluster) Map(java.util.Map) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 5 with Cluster

use of com.sequenceiq.periscope.domain.Cluster in project cloudbreak by hortonworks.

the class ClusterCreationEvaluator method run.

@Override
public void run() {
    AutoscaleStackResponse stack = context.getStack();
    Optional<Cluster> clusterOptional = context.getClusterOptional();
    try {
        createOrUpdateCluster(stack, clusterOptional);
    } catch (AmbariHealtCheckException ahf) {
        LOGGER.warn(String.format("Ambari health check failed for Cloudbreak stack: %s(ID:%s)", stack.getStackId(), stack.getName()), ahf);
    } catch (TlsConfigurationException ex) {
        LOGGER.warn(String.format("Could not prepare TLS configuration for Cloudbreak stack: %s(ID:%s)", stack.getStackId(), stack.getName()), ex);
    } catch (Exception ex) {
        LOGGER.warn(String.format("Could not create cluster for Cloudbreak stack: %s(ID:%s)", stack.getStackId(), stack.getName()), ex);
    }
}
Also used : TlsConfigurationException(com.sequenceiq.periscope.service.security.TlsConfigurationException) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) Cluster(com.sequenceiq.periscope.domain.Cluster) TlsConfigurationException(com.sequenceiq.periscope.service.security.TlsConfigurationException)

Aggregations

Cluster (com.sequenceiq.periscope.domain.Cluster)34 Map (java.util.Map)6 PrometheusAlert (com.sequenceiq.periscope.domain.PrometheusAlert)5 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)4 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)4 MetricAlert (com.sequenceiq.periscope.domain.MetricAlert)4 PeriscopeUser (com.sequenceiq.periscope.domain.PeriscopeUser)4 UpdateFailedEvent (com.sequenceiq.periscope.monitor.event.UpdateFailedEvent)4 TimeAlert (com.sequenceiq.periscope.domain.TimeAlert)3 ScalingEvent (com.sequenceiq.periscope.monitor.event.ScalingEvent)3 Collections (java.util.Collections)3 List (java.util.List)3 Set (java.util.Set)3 Inject (javax.inject.Inject)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Component (org.springframework.stereotype.Component)3 AutoscaleStackResponse (com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse)2 FailureReport (com.sequenceiq.cloudbreak.api.model.FailureReport)2 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)2