use of com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson 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.InstanceGroupAdjustmentJson in project cloudbreak by hortonworks.
the class UpdateStackRequestValidator method isValid.
@Override
public boolean isValid(UpdateStackJson value, ConstraintValidatorContext context) {
int updateResources = 0;
if (value.getStatus() != null) {
updateResources++;
}
InstanceGroupAdjustmentJson instanceGroupAdjustment = value.getInstanceGroupAdjustment();
if (instanceGroupAdjustment != null) {
updateResources++;
if (value.getWithClusterEvent() && instanceGroupAdjustment.getScalingAdjustment() < 0) {
addConstraintViolation(context, "Invalid PUT request on this resource. Update event has to be upscale if you define withClusterEvent = 'true'.");
return false;
}
}
if (updateResources != 1) {
addConstraintViolation(context, "Invalid PUT request on this resource. 1 update request is allowed at a time.");
return false;
}
return true;
}
use of com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson in project cloudbreak by hortonworks.
the class UpdateStackRequestValidatorTest method testIsValidShouldReturnFalseWhenRequestContainsNodeCountAndStatus.
@Test
public void testIsValidShouldReturnFalseWhenRequestContainsNodeCountAndStatus() {
UpdateStackJson updateStackJson = new UpdateStackJson();
InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
instanceGroupAdjustmentJson.setScalingAdjustment(4);
instanceGroupAdjustmentJson.setInstanceGroup("slave_1");
updateStackJson.setStatus(StatusRequest.STARTED);
updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
boolean valid = underTest.isValid(updateStackJson, constraintValidatorContext);
assertFalse(valid);
}
use of com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson in project cloudbreak by hortonworks.
the class UpdateStackRequestV2ToUpdateStackRequestConverter method convert.
@Override
public UpdateStackJson convert(StackScaleRequestV2 source) {
UpdateStackJson updateStackJson = new UpdateStackJson();
updateStackJson.setWithClusterEvent(true);
InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(source.getStackId(), source.getGroup());
if (instanceGroup != null) {
InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
instanceGroupAdjustmentJson.setInstanceGroup(source.getGroup());
int scaleNumber = source.getDesiredCount() - instanceGroup.getNodeCount();
instanceGroupAdjustmentJson.setScalingAdjustment(scaleNumber);
updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
} else {
throw new BadRequestException(String.format("Group '%s' not available on stack", source.getGroup()));
}
return updateStackJson;
}
use of com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson in project cloudbreak by hortonworks.
the class ReactorFlowManagerTest method shouldReturnTheNextFailureTransition.
@Test
public void shouldReturnTheNextFailureTransition() {
InstanceGroupAdjustmentJson instanceGroupAdjustment = new InstanceGroupAdjustmentJson();
HostGroupAdjustmentJson hostGroupAdjustment = new HostGroupAdjustmentJson();
underTest.triggerProvisioning(stackId);
underTest.triggerClusterInstall(stackId);
underTest.triggerClusterReInstall(stackId);
underTest.triggerStackStop(stackId);
underTest.triggerStackStart(stackId);
underTest.triggerClusterStop(stackId);
underTest.triggerClusterStart(stackId);
underTest.triggerTermination(stackId, false, false);
underTest.triggerTermination(stackId, false, true);
underTest.triggerStackUpscale(stackId, instanceGroupAdjustment, true);
underTest.triggerStackDownscale(stackId, instanceGroupAdjustment);
underTest.triggerStackRemoveInstance(stackId, "hostgroup", "hostname");
underTest.triggerClusterUpscale(stackId, hostGroupAdjustment);
underTest.triggerClusterDownscale(stackId, hostGroupAdjustment);
underTest.triggerClusterSync(stackId);
underTest.triggerStackSync(stackId);
underTest.triggerFullSync(stackId);
underTest.triggerClusterCredentialReplace(stackId, "admin", "admin1");
underTest.triggerClusterCredentialUpdate(stackId, "admin1");
underTest.triggerClusterTermination(stackId, false, false);
underTest.triggerClusterTermination(stackId, true, false);
underTest.triggerClusterUpgrade(stackId);
underTest.triggerManualRepairFlow(stackId);
underTest.triggerStackRepairFlow(stackId, new UnhealthyInstances());
underTest.triggerClusterRepairFlow(stackId, new HashMap<>(), true);
underTest.triggerEphemeralUpdate(stackId);
// Not start from 0 because flow cancellations
int count = 5;
for (Method method : underTest.getClass().getDeclaredMethods()) {
if (method.getName().startsWith("trigger")) {
count++;
}
}
verify(reactor, times(count)).notify((Object) anyObject(), any(Event.class));
}
Aggregations