Search in sources :

Example 1 with InstanceGroupAdjustmentJson

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);
        }
    }
}
Also used : UpdateStackJson(com.sequenceiq.cloudbreak.api.model.UpdateStackJson) AmbariAddressJson(com.sequenceiq.cloudbreak.api.model.AmbariAddressJson) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) History(com.sequenceiq.periscope.domain.History)

Example 2 with InstanceGroupAdjustmentJson

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;
}
Also used : InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson)

Example 3 with InstanceGroupAdjustmentJson

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);
}
Also used : UpdateStackJson(com.sequenceiq.cloudbreak.api.model.UpdateStackJson) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) Test(org.junit.Test)

Example 4 with InstanceGroupAdjustmentJson

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;
}
Also used : UpdateStackJson(com.sequenceiq.cloudbreak.api.model.UpdateStackJson) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 5 with InstanceGroupAdjustmentJson

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));
}
Also used : UnhealthyInstances(com.sequenceiq.cloudbreak.service.stack.repair.UnhealthyInstances) Event(reactor.bus.Event) ClusterTerminationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.termination.ClusterTerminationEvent) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

InstanceGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson)11 UpdateStackJson (com.sequenceiq.cloudbreak.api.model.UpdateStackJson)8 Test (org.junit.Test)4 IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)3 AbstractCloudbreakIntegrationTest (com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest)3 Parameters (org.testng.annotations.Parameters)3 Test (org.testng.annotations.Test)3 StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)2 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)2 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)2 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)2 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Strings (com.google.api.client.repackaged.com.google.common.base.Strings)1 AmbariAddressJson (com.sequenceiq.cloudbreak.api.model.AmbariAddressJson)1 AutoscaleStackResponse (com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse)1 DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)1 InstanceStatus (com.sequenceiq.cloudbreak.api.model.InstanceStatus)1 AVAILABLE (com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE)1 STOPPED (com.sequenceiq.cloudbreak.api.model.Status.STOPPED)1