use of com.sequenceiq.periscope.domain.Ambari 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);
}
}
use of com.sequenceiq.periscope.domain.Ambari in project cloudbreak by hortonworks.
the class ClusterCreationEvaluator method createAmbariStack.
private AmbariStack createAmbariStack(AutoscaleStackResponse stack) {
String host = stack.getAmbariServerIp();
String gatewayPort = String.valueOf(stack.getGatewayPort());
SecurityConfig securityConfig = tlsSecurityService.prepareSecurityConfig(stack.getStackId());
return new AmbariStack(new Ambari(host, gatewayPort, stack.getUserName(), stack.getPassword()), stack.getStackId(), securityConfig);
}
use of com.sequenceiq.periscope.domain.Ambari in project cloudbreak by hortonworks.
the class ConsulKeyValueService method deleteAlert.
public void deleteAlert(Cluster cluster, PrometheusAlert alert) {
Ambari ambari = cluster.getAmbari();
try {
TlsConfiguration tlsConfig = tlsSecurityService.getConfiguration(cluster);
ConsulClient consulClient = ConsulUtils.createClient(ambari.getHost(), cluster.getPort(), tlsConfig);
String alertKey = getKeyNameForAlert(alert);
consulClient.deleteKVValue(alertKey);
LOGGER.info("Alert has been removed from Consul KV store with name: '{}' on host: '{}'.", alertKey, ambari.getHost());
} catch (Exception e) {
LOGGER.warn("Alert could not be deleted from Consul KV store:", e);
}
}
use of com.sequenceiq.periscope.domain.Ambari in project cloudbreak by hortonworks.
the class ClusterSecurityService method tryResolve.
public AmbariStack tryResolve(Ambari ambari) {
try {
String host = ambari.getHost();
String user = ambari.getUser();
String pass = ambari.getPass();
AmbariAddressJson ambariAddressJson = new AmbariAddressJson();
ambariAddressJson.setAmbariAddress(host);
StackResponse stack = cloudbreakClient.stackV1Endpoint().getStackForAmbari(ambariAddressJson);
Long id = stack.getId();
SecurityConfig securityConfig = tlsSecurityService.prepareSecurityConfig(id);
if (user == null || pass == null) {
AutoscaleClusterResponse clusterResponse = cloudbreakClient.clusterEndpoint().getForAutoscale(id);
return new AmbariStack(new Ambari(host, ambari.getPort(), clusterResponse.getUserName(), clusterResponse.getPassword()), id, securityConfig);
} else {
return new AmbariStack(ambari, id, securityConfig);
}
} catch (RuntimeException ignored) {
return new AmbariStack(ambari);
}
}
use of com.sequenceiq.periscope.domain.Ambari 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.");
}
}
Aggregations