use of com.sequenceiq.periscope.model.AmbariStack 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.model.AmbariStack 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.model.AmbariStack 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.model.AmbariStack in project cloudbreak by hortonworks.
the class ClusterCreationEvaluator method createOrUpdateCluster.
private void createOrUpdateCluster(AutoscaleStackResponse stack, Optional<Cluster> clusterOptional) {
AmbariStack resolvedAmbari = createAmbariStack(stack);
Cluster cluster;
boolean sendNotification = false;
if (clusterOptional.isPresent()) {
cluster = clusterOptional.get();
MDCBuilder.buildMdcContext(cluster);
if (PENDING.equals(cluster.getState()) || SUSPENDED.equals(cluster.getState())) {
ambariHealthCheck(cluster.getUser(), resolvedAmbari);
LOGGER.info("Update cluster and set it's state to 'RUNNING' for Ambari host: {}", resolvedAmbari.getAmbari().getHost());
cluster = clusterService.update(cluster.getId(), resolvedAmbari, false, RUNNING, cluster.isAutoscalingEnabled());
sendNotification = true;
}
} else {
PeriscopeUser user = new PeriscopeUser(stack.getOwner(), null, stack.getAccount());
MDCBuilder.buildMdcContext(user, stack.getStackId(), null);
LOGGER.info("Creating cluster for Ambari host: {}", resolvedAmbari.getAmbari().getHost());
ambariHealthCheck(user, resolvedAmbari);
cluster = clusterService.create(user, resolvedAmbari, null);
sendNotification = true;
}
if (sendNotification) {
History history = historyService.createEntry(ScalingStatus.ENABLED, "Autoscaling has been enabled for the cluster.", 0, cluster);
notificationSender.send(history);
}
}
Aggregations