use of com.sequenceiq.cloudbreak.api.model.AmbariAddressJson in project cloudbreak by hortonworks.
the class ScalingRequest method scaleUp.
private void scaleUp(int scalingAdjustment, int totalNodes) {
String hostGroup = policy.getHostGroup();
String ambari = cluster.getHost();
AmbariAddressJson ambariAddressJson = new AmbariAddressJson();
ambariAddressJson.setAmbariAddress(ambari);
History history = null;
try {
LOGGER.info("Sending request to add {} instance(s) into host group '{}', triggered policy '{}'", scalingAdjustment, hostGroup, policy.getName());
Long stackId = cloudbreakClient.stackV1Endpoint().getStackForAmbari(ambariAddressJson).getId();
UpdateStackJson updateStackJson = new UpdateStackJson();
updateStackJson.setWithClusterEvent(true);
InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
instanceGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
instanceGroupAdjustmentJson.setInstanceGroup(hostGroup);
updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
cloudbreakClient.stackV1Endpoint().put(stackId, updateStackJson);
history = historyService.createEntry(ScalingStatus.SUCCESS, "Upscale successfully triggered", totalNodes, policy);
} catch (RuntimeException e) {
history = historyService.createEntry(ScalingStatus.FAILED, "Couldn't trigger upscaling due to: " + e.getMessage(), totalNodes, policy);
LOGGER.error("Error adding nodes to cluster", e);
} finally {
if (history != null) {
notificationSender.send(history);
}
}
}
use of com.sequenceiq.cloudbreak.api.model.AmbariAddressJson 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.cloudbreak.api.model.AmbariAddressJson in project cloudbreak by hortonworks.
the class ScalingRequest method scaleDown.
private void scaleDown(int scalingAdjustment, int totalNodes) {
String hostGroup = policy.getHostGroup();
String ambari = cluster.getHost();
AmbariAddressJson ambariAddressJson = new AmbariAddressJson();
ambariAddressJson.setAmbariAddress(ambari);
History history = null;
try {
LOGGER.info("Sending request to remove {} node(s) from host group '{}', triggered policy '{}'", scalingAdjustment, hostGroup, policy.getName());
Long stackId = cloudbreakClient.stackV1Endpoint().getStackForAmbari(ambariAddressJson).getId();
UpdateClusterJson updateClusterJson = new UpdateClusterJson();
HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson();
hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
hostGroupAdjustmentJson.setWithStackUpdate(true);
hostGroupAdjustmentJson.setHostGroup(hostGroup);
updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
cloudbreakClient.clusterEndpoint().put(stackId, updateClusterJson);
history = historyService.createEntry(ScalingStatus.SUCCESS, "Downscale successfully triggered", totalNodes, policy);
} catch (Exception e) {
history = historyService.createEntry(ScalingStatus.FAILED, "Couldn't trigger downscaling due to: " + e.getMessage(), totalNodes, policy);
LOGGER.error("Error removing nodes from the cluster", e);
} finally {
if (history != null) {
notificationSender.send(history);
}
}
}
use of com.sequenceiq.cloudbreak.api.model.AmbariAddressJson in project cloudbreak by hortonworks.
the class ClusterSecurityService method hasAccess.
private boolean hasAccess(String userId, String account, String ambariAddress, Long stackId) {
StackResponse stack;
if (stackId != null) {
stack = cloudbreakClient.stackV1Endpoint().get(stackId, new HashSet<>());
} else {
AmbariAddressJson ambariAddressJson = new AmbariAddressJson();
ambariAddressJson.setAmbariAddress(ambariAddress);
stack = cloudbreakClient.stackV1Endpoint().getStackForAmbari(ambariAddressJson);
}
return stack.getOwner().equals(userId) || (stack.isPublicInAccount() && stack.getAccount().equals(account));
}
Aggregations