Search in sources :

Example 31 with Cluster

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

the class ClusterService method validateClusterUniqueness.

private void validateClusterUniqueness(AmbariStack stack) {
    Iterable<Cluster> clusters = clusterRepository.findAll();
    boolean clusterForTheSameStackAndAmbari = StreamSupport.stream(clusters.spliterator(), false).anyMatch(cluster -> {
        boolean equalityOfStackId = cluster.getStackId() != null && cluster.getStackId().equals(stack.getStackId());
        Ambari ambari = cluster.getAmbari();
        Ambari newAmbari = stack.getAmbari();
        boolean ambariObjectsNotNull = ambari != null && newAmbari != null;
        boolean ambariHostsNotEmpty = ambariObjectsNotNull && !isEmpty(ambari.getHost()) && !isEmpty(newAmbari.getHost());
        boolean equalityOfAmbariHost = ambariObjectsNotNull && ambariHostsNotEmpty && ambari.getHost().equals(newAmbari.getHost());
        return equalityOfStackId && equalityOfAmbariHost;
    });
    if (clusterForTheSameStackAndAmbari) {
        throw new BadRequestException("Cluster exists for the same Cloudbreak stack id and Ambari host.");
    }
}
Also used : Cluster(com.sequenceiq.periscope.domain.Cluster) BadRequestException(javax.ws.rs.BadRequestException) Ambari(com.sequenceiq.periscope.domain.Ambari)

Example 32 with Cluster

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

the class ClusterService method setAutoscaleState.

public Cluster setAutoscaleState(Long clusterId, boolean enableAutoscaling) {
    Cluster cluster = findOneById(clusterId);
    cluster.setAutoscalingEnabled(enableAutoscaling);
    addPrometheusAlertsToConsul(cluster);
    return clusterRepository.save(cluster);
}
Also used : Cluster(com.sequenceiq.periscope.domain.Cluster)

Example 33 with Cluster

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

the class ClusterService method update.

public Cluster update(Long clusterId, AmbariStack stack, boolean withPermissionCheck, ClusterState clusterState, boolean enableAutoscaling) {
    Cluster cluster = withPermissionCheck ? findOneById(clusterId) : find(clusterId);
    ClusterState newState = clusterState != null ? clusterState : cluster.getState();
    cluster.setState(newState);
    cluster.setAutoscalingEnabled(enableAutoscaling);
    cluster.update(stack);
    SecurityConfig sSecConf = stack.getSecurityConfig();
    if (sSecConf != null) {
        SecurityConfig updatedConfig = sSecConf;
        SecurityConfig securityConfig = securityConfigRepository.findByClusterId(clusterId);
        if (securityConfig != null) {
            securityConfig.update(updatedConfig);
            securityConfigRepository.save(securityConfig);
        } else {
            SecurityConfig sc = new SecurityConfig(sSecConf.getClientKey(), sSecConf.getClientCert(), sSecConf.getServerCert());
            sc.setCluster(cluster);
            sc = securityConfigRepository.save(sc);
            cluster.setSecurityConfig(sc);
        }
    }
    cluster = save(cluster);
    addPrometheusAlertsToConsul(cluster);
    return cluster;
}
Also used : ClusterState(com.sequenceiq.periscope.api.model.ClusterState) SecurityConfig(com.sequenceiq.periscope.domain.SecurityConfig) Cluster(com.sequenceiq.periscope.domain.Cluster)

Example 34 with Cluster

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

the class OwnerBasedPermissionEvaluator method getUserId.

private String getUserId(Object targetDomainObject) throws IllegalAccessException {
    Field clusterField = ReflectionUtils.findField(targetDomainObject.getClass(), "cluster");
    if (clusterField != null) {
        clusterField.setAccessible(true);
        Cluster cluster = (Cluster) clusterField.get(targetDomainObject);
        return getUserId(cluster);
    } else {
        Field userIdField = ReflectionUtils.findField(targetDomainObject.getClass(), "userId");
        if (userIdField != null) {
            userIdField.setAccessible(true);
            return (String) userIdField.get(targetDomainObject);
        }
        return getUserIdFromCluster(targetDomainObject);
    }
}
Also used : UserFilterField(com.sequenceiq.cloudbreak.common.service.user.UserFilterField) Field(java.lang.reflect.Field) Cluster(com.sequenceiq.periscope.domain.Cluster)

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