Search in sources :

Example 1 with HostGroupAdjustmentV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request in project cloudbreak by hortonworks.

the class StackScaleV4RequestToUpdateClusterV4RequestConverter method convert.

public UpdateClusterV4Request convert(StackScaleV4Request source) {
    try {
        return transactionService.required(() -> {
            UpdateClusterV4Request updateStackJson = new UpdateClusterV4Request();
            Stack stack = stackService.getByIdWithListsInTransaction(source.getStackId());
            stack.getInstanceGroups().stream().filter(instanceGroup -> source.getGroup().equals(instanceGroup.getGroupName())).findFirst().ifPresentOrElse(instanceGroup -> {
                String blueprintText = stack.getCluster().getBlueprint().getBlueprintText();
                BlueprintTextProcessor blueprintTextProcessor = clusterDefinitionTextProcessorFactory.createBlueprintTextProcessor(blueprintText);
                boolean dataNodeComponentInHostGroup = blueprintTextProcessor.isComponentExistsInHostGroup("DATANODE", instanceGroup.getGroupName());
                HostGroupAdjustmentV4Request hostGroupAdjustmentJson = new HostGroupAdjustmentV4Request();
                hostGroupAdjustmentJson.setWithStackUpdate(true);
                hostGroupAdjustmentJson.setValidateNodeCount(dataNodeComponentInHostGroup);
                hostGroupAdjustmentJson.setHostGroup(source.getGroup());
                hostGroupAdjustmentJson.setForced(source.getForced());
                int scaleNumber = source.getDesiredCount() - instanceGroup.getNotTerminatedInstanceMetaDataSet().size();
                hostGroupAdjustmentJson.setScalingAdjustment(scaleNumber);
                updateStackJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
            }, () -> {
                throw new BadRequestException(String.format("Group '%s' not available on stack", source.getGroup()));
            });
            return updateStackJson;
        });
    } catch (TransactionExecutionException e) {
        throw e.getCause();
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) BlueprintTextProcessor(com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with HostGroupAdjustmentV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request in project cloudbreak by hortonworks.

the class ClusterCommonServiceTest method testUpdateNodeCountWhenCheckCallEnvironmentCheck.

@Test
public void testUpdateNodeCountWhenCheckCallEnvironmentCheck() {
    Stack stack = new Stack();
    stack.setId(9876L);
    stack.setStackStatus(new StackStatus(stack, AVAILABLE));
    when(stackService.getByCrnWithLists("crn")).thenReturn(stack);
    doThrow(RuntimeException.class).when(environmentService).checkEnvironmentStatus(stack, EnvironmentStatus.upscalable());
    UpdateClusterV4Request update = new UpdateClusterV4Request();
    update.setHostGroupAdjustment(new HostGroupAdjustmentV4Request());
    assertThrows(RuntimeException.class, () -> underTest.put("crn", update));
    verify(environmentService).checkEnvironmentStatus(stack, EnvironmentStatus.upscalable());
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with HostGroupAdjustmentV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request in project cloudbreak by hortonworks.

the class ClusterOperationServiceTest method updateHostsTestAndCheckDownscaleAndUpscaleStatusChange.

@Test
public void updateHostsTestAndCheckDownscaleAndUpscaleStatusChange() {
    HostGroupAdjustmentV4Request downscaleHostGroupAdjustment = new HostGroupAdjustmentV4Request();
    downscaleHostGroupAdjustment.setHostGroup("worker");
    downscaleHostGroupAdjustment.setScalingAdjustment(-5);
    when(stackService.getById(STACK_ID)).thenReturn(stack);
    when(updateHostsValidator.validateRequest(stack, downscaleHostGroupAdjustment)).thenReturn(true);
    underTest.updateHosts(STACK_ID, downscaleHostGroupAdjustment);
    verify(stackUpdater, times(1)).updateStackStatus(STACK_ID, DetailedStackStatus.DOWNSCALE_REQUESTED, "Requested node count for downscaling: " + 5);
    verify(flowManager, times(1)).triggerClusterDownscale(STACK_ID, downscaleHostGroupAdjustment);
    HostGroupAdjustmentV4Request upscaleHostGroupAdjustment = new HostGroupAdjustmentV4Request();
    upscaleHostGroupAdjustment.setHostGroup("worker");
    upscaleHostGroupAdjustment.setScalingAdjustment(5);
    when(stackService.getById(STACK_ID)).thenReturn(stack);
    when(updateHostsValidator.validateRequest(stack, upscaleHostGroupAdjustment)).thenReturn(false);
    underTest.updateHosts(STACK_ID, upscaleHostGroupAdjustment);
    verify(stackUpdater, times(1)).updateStackStatus(STACK_ID, DetailedStackStatus.UPSCALE_REQUESTED, "Requested node count for upscaling: " + 5);
    verify(flowManager, times(1)).triggerClusterUpscale(STACK_ID, upscaleHostGroupAdjustment);
}
Also used : HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) Test(org.junit.jupiter.api.Test)

Example 4 with HostGroupAdjustmentV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request in project cloudbreak by hortonworks.

the class ReactorFlowManagerTest method shouldReturnTheNextFailureTransition.

@Test
public void shouldReturnTheNextFailureTransition() {
    InstanceGroupAdjustmentV4Request instanceGroupAdjustment = new InstanceGroupAdjustmentV4Request();
    instanceGroupAdjustment.setScalingAdjustment(5);
    instanceGroupAdjustment.setInstanceGroup("hostgroup");
    HostGroupAdjustmentV4Request hostGroupAdjustment = new HostGroupAdjustmentV4Request();
    hostGroupAdjustment.setHostGroup("hostgroup");
    hostGroupAdjustment.setScalingAdjustment(5);
    Map<String, Set<Long>> instanceIdsByHostgroup = new HashMap<>();
    instanceIdsByHostgroup.put("hostgroup", Collections.singleton(1L));
    ImageChangeDto imageChangeDto = new ImageChangeDto(STACK_ID, "imageid");
    when(stackService.getPlatformVariantByStackId(STACK_ID)).thenReturn(cloudPlatformVariant);
    when(cloudPlatformVariant.getVariant()).thenReturn(Variant.variant("AWS"));
    underTest.triggerProvisioning(STACK_ID);
    underTest.triggerClusterInstall(STACK_ID);
    underTest.triggerClusterReInstall(STACK_ID);
    underTest.triggerStackStop(STACK_ID);
    underTest.triggerStackStart(STACK_ID);
    underTest.triggerClusterStop(STACK_ID);
    underTest.triggerClusterStart(STACK_ID);
    underTest.triggerTermination(STACK_ID);
    underTest.triggerStackUpscale(STACK_ID, instanceGroupAdjustment, true);
    underTest.triggerStackDownscale(STACK_ID, instanceGroupAdjustment);
    underTest.triggerStackRemoveInstance(STACK_ID, "hostgroup", 5L);
    underTest.triggerStackRemoveInstance(STACK_ID, "hostgroup", 5L, false);
    underTest.triggerStackRemoveInstances(STACK_ID, instanceIdsByHostgroup, false);
    underTest.triggerClusterUpscale(STACK_ID, hostGroupAdjustment);
    underTest.triggerClusterDownscale(STACK_ID, hostGroupAdjustment);
    underTest.triggerClusterSync(STACK_ID);
    underTest.triggerClusterSyncWithoutCheck(STACK_ID);
    underTest.triggerStackSync(STACK_ID);
    underTest.triggerFullSync(STACK_ID);
    underTest.triggerFullSyncWithoutCheck(STACK_ID);
    underTest.triggerClusterCredentialReplace(STACK_ID, "admin", "admin1");
    underTest.triggerClusterCredentialUpdate(STACK_ID, "admin1");
    underTest.triggerClusterTermination(stack, false, USER_CRN);
    underTest.triggerClusterTermination(stack, true, USER_CRN);
    underTest.triggerManualRepairFlow(STACK_ID);
    underTest.triggerStackRepairFlow(STACK_ID, new UnhealthyInstances());
    underTest.triggerClusterRepairFlow(STACK_ID, new HashMap<>(), false);
    underTest.triggerClusterRepairFlow(STACK_ID, new HashMap<>(), true, false);
    underTest.triggerStackImageUpdate(new ImageChangeDto(STACK_ID, "asdf"));
    underTest.triggerMaintenanceModeValidationFlow(STACK_ID);
    underTest.triggerClusterCertificationRenewal(STACK_ID);
    underTest.triggerDatalakeClusterUpgrade(STACK_ID, "asdf");
    underTest.triggerDistroXUpgrade(STACK_ID, imageChangeDto, false, false, "variant");
    underTest.triggerSaltUpdate(STACK_ID);
    underTest.triggerPillarConfigurationUpdate(STACK_ID);
    underTest.triggerDatalakeDatabaseBackup(STACK_ID, null, null, true);
    underTest.triggerDatalakeDatabaseRestore(STACK_ID, null, null);
    underTest.triggerAutoTlsCertificatesRotation(STACK_ID, new CertificatesRotationV4Request());
    underTest.triggerStackLoadBalancerUpdate(STACK_ID);
    underTest.triggerSyncComponentVersionsFromCm(STACK_ID, Set.of());
    underTest.triggerDatalakeClusterRecovery(STACK_ID);
    underTest.triggerStopStartStackUpscale(STACK_ID, instanceGroupAdjustment, true);
    underTest.triggerStopStartStackDownscale(STACK_ID, instanceIdsByHostgroup, false);
    underTest.triggerClusterServicesRestart(STACK_ID);
    underTest.triggerClusterProxyConfigReRegistration(STACK_ID);
    int count = 0;
    for (Method method : underTest.getClass().getDeclaredMethods()) {
        if (method.getName().startsWith("trigger")) {
            count++;
        }
    }
    // -3: 2 notifyWithoutCheck, 1 terminationTriggerService, 1 triggerStackRemoveInstance internal
    verify(reactorNotifier, times(count - 3)).notify(anyLong(), anyString(), any(Acceptable.class));
    verify(reactorNotifier, times(2)).notifyWithoutCheck(anyLong(), anyString(), any(Acceptable.class));
    verify(terminationTriggerService, times(1)).triggerTermination(stack, true);
    verify(terminationTriggerService, times(1)).triggerTermination(stack, false);
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) UnhealthyInstances(com.sequenceiq.cloudbreak.service.stack.repair.UnhealthyInstances) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Method(java.lang.reflect.Method) ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) Test(org.junit.Test)

Example 5 with HostGroupAdjustmentV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request in project cloudbreak by hortonworks.

the class ScalingRequest method scaleDown.

private void scaleDown(int scalingAdjustment, int totalNodes) {
    metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_TRIGGERED);
    String hostGroup = policy.getHostGroup();
    String statusReason = null;
    ScalingStatus scalingStatus = null;
    String stackCrn = cluster.getStackCrn();
    String userCrn = cluster.getClusterPertain().getUserCrn();
    try {
        LOGGER.info("Sending request to remove '{}' node(s) from host group '{}', triggered adjustmentType '{}', cluster '{}', user '{}'", scalingAdjustment, hostGroup, policy.getAdjustmentType(), stackCrn, userCrn);
        UpdateClusterV4Request updateClusterJson = new UpdateClusterV4Request();
        HostGroupAdjustmentV4Request hostGroupAdjustmentJson = new HostGroupAdjustmentV4Request();
        hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        hostGroupAdjustmentJson.setWithStackUpdate(true);
        hostGroupAdjustmentJson.setHostGroup(hostGroup);
        hostGroupAdjustmentJson.setValidateNodeCount(false);
        updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
        // TODO CB-14929: CB-15153 List of nodes not provided. Do we really need to support this? Can Periscope always specify the list of nodes?
        cloudbreakCrnClient.withInternalCrn().autoscaleEndpoint().putCluster(stackCrn, cluster.getClusterPertain().getUserId(), updateClusterJson);
        scalingStatus = ScalingStatus.SUCCESS;
        statusReason = getMessageForCBSuccess();
        metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_SUCCESSFUL);
    } catch (Exception e) {
        scalingStatus = ScalingStatus.FAILED;
        metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_FAILED);
        statusReason = getMessageForCBException(e);
        LOGGER.error("Couldn't trigger downscaling for host group '{}', cluster '{}', desiredNodeCount '{}', error '{}' ", hostGroup, cluster.getStackCrn(), desiredHostGroupNodeCount, statusReason, e);
    } finally {
        processAutoscalingTriggered(scalingAdjustment, totalNodes, statusReason, scalingStatus);
    }
}
Also used : ScalingStatus(com.sequenceiq.periscope.api.model.ScalingStatus) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) ClientErrorException(javax.ws.rs.ClientErrorException)

Aggregations

HostGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request)5 UpdateClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 Test (org.junit.jupiter.api.Test)2 InstanceGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request)1 CertificatesRotationV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request)1 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)1 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)1 ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)1 UnhealthyInstances (com.sequenceiq.cloudbreak.service.stack.repair.UnhealthyInstances)1 BlueprintTextProcessor (com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor)1 ScalingStatus (com.sequenceiq.periscope.api.model.ScalingStatus)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1