Search in sources :

Example 1 with UpdateClusterV4Request

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

the class ClusterCommonService method put.

public FlowIdentifier put(String crn, UpdateClusterV4Request updateJson) {
    Stack stack = stackService.getByCrnWithLists(crn);
    Long stackId = stack.getId();
    MDCBuilder.buildMdcContext(stack);
    UserNamePasswordV4Request userNamePasswordJson = updateJson.getUserNamePassword();
    FlowIdentifier flowIdentifier;
    if (userNamePasswordJson != null) {
        flowIdentifier = clusterManagerUserNamePasswordChange(stack, userNamePasswordJson);
    } else if (updateJson.getStatus() != null) {
        LOGGER.debug("Cluster status update request received. Stack id:  {}, status: {} ", stackId, updateJson.getStatus());
        flowIdentifier = clusterOperationService.updateStatus(stackId, updateJson.getStatus());
    } else if (updateJson.getBlueprintName() != null && updateJson.getHostgroups() != null && stack.getCluster().isCreateFailed()) {
        LOGGER.debug("Cluster rebuild request received. Stack id:  {}", stackId);
        try {
            flowIdentifier = recreateCluster(stack, updateJson);
        } catch (TransactionExecutionException e) {
            throw new TransactionRuntimeExecutionException(e);
        }
    } else if (updateJson.getHostGroupAdjustment() != null) {
        environmentService.checkEnvironmentStatus(stack, EnvironmentStatus.upscalable());
        flowIdentifier = clusterHostgroupAdjustmentChange(stackId, updateJson, stack);
    } else {
        LOGGER.info("Invalid cluster update request received. Stack id: {}", stackId);
        throw new BadRequestException("Invalid update cluster request!");
    }
    return flowIdentifier;
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) UserNamePasswordV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 2 with UpdateClusterV4Request

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

the class ClusterCommonService method recreateCluster.

private FlowIdentifier recreateCluster(Stack stack, UpdateClusterV4Request updateCluster) throws TransactionExecutionException {
    Set<HostGroup> hostGroups = new HashSet<>();
    for (HostGroupV4Request json : updateCluster.getHostgroups()) {
        HostGroup hostGroup = hostGroupV4RequestToHostGroupConverter.convert(json);
        hostGroup = hostGroupDecorator.decorate(hostGroup, json, stack);
        hostGroups.add(hostGroup);
    }
    return clusterOperationService.recreate(stack, updateCluster.getBlueprintName(), hostGroups, updateCluster.getValidateBlueprint());
}
Also used : HostGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupV4Request) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) HashSet(java.util.HashSet)

Example 3 with UpdateClusterV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request 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 4 with UpdateClusterV4Request

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

the class StackOperations method putPassword.

public FlowIdentifier putPassword(@NotNull NameOrCrn nameOrCrn, Long workspaceId, @Valid UserNamePasswordV4Request userNamePasswordJson) {
    Stack stack = nameOrCrn.hasName() ? stackService.getByNameInWorkspace(nameOrCrn.getName(), workspaceId) : stackService.getNotTerminatedByCrnInWorkspace(nameOrCrn.getCrn(), workspaceId);
    UpdateClusterV4Request updateClusterJson = userNamePasswordV4RequestToUpdateClusterV4RequestConverter.convert(userNamePasswordJson);
    return clusterCommonService.put(stack.getResourceCrn(), updateClusterJson);
}
Also used : UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 5 with UpdateClusterV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request 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)

Aggregations

UpdateClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request)6 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 HostGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)2 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)2 UpdateStackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request)1 HostGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupV4Request)1 UserNamePasswordV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request)1 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)1 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)1 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)1 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)1 BlueprintTextProcessor (com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor)1 User (com.sequenceiq.cloudbreak.workspace.model.User)1 ScalingStatus (com.sequenceiq.periscope.api.model.ScalingStatus)1 HashSet (java.util.HashSet)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 Test (org.junit.jupiter.api.Test)1