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