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;
}
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());
}
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();
}
}
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);
}
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());
}
Aggregations