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.");
}
}
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);
}
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;
}
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);
}
}
Aggregations