use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response in project cloudbreak by hortonworks.
the class CronTimeEvaluatorTest method validateScheduleBasedScaling.
private ScalingEvent validateScheduleBasedScaling(String testMode, Integer currentHostGroupCount, Integer desiredNodeCount, Optional<Integer> yarnGivenDecommissionCount) throws Exception {
TimeAlert alert = getAAlert(desiredNodeCount);
StackV4Response stackV4Response = MockStackResponseGenerator.getMockStackV4Response(clusterCrn, testHostGroup, "testFqdn" + testHostGroup, currentHostGroupCount, 0);
when(cloudbreakCommunicator.getByCrn(anyString())).thenReturn(stackV4Response);
when(stackResponseUtils.getNodeCountForHostGroup(stackV4Response, testHostGroup)).thenCallRealMethod();
when(scalingPolicyTargetCalculator.getDesiredAbsoluteNodeCount(any(ScalingEvent.class), anyInt())).thenCallRealMethod();
when(dateService.isTrigger(any(TimeAlert.class), anyLong())).thenReturn(true);
if (!"SCALE_UP_MODE".equals(testMode)) {
YarnScalingServiceV1Response yarnScalingServiceV1Response = getMockYarnScalingResponse("test", yarnGivenDecommissionCount.get());
when(stackResponseUtils.getCloudInstanceIdsForHostGroup(any(), any())).thenCallRealMethod();
when(yarnMetricsClient.getYarnMetricsForCluster(any(Cluster.class), any(StackV4Response.class), anyString(), any(), any(Optional.class))).thenReturn(yarnScalingServiceV1Response);
when(yarnResponseUtils.getYarnRecommendedDecommissionHostsForHostGroup(anyString(), any(YarnScalingServiceV1Response.class), any(Map.class), anyInt(), any(Optional.class), anyInt())).thenCallRealMethod();
}
underTest.publishIfNeeded(List.of(alert));
VerificationMode verificationMode = "SCALE_UP_MODE".equals(testMode) ? never() : times(1);
ArgumentCaptor<ScalingEvent> captor = ArgumentCaptor.forClass(ScalingEvent.class);
verify(eventPublisher).publishEvent(captor.capture());
verify(stackResponseUtils, verificationMode).getCloudInstanceIdsForHostGroup(any(), any());
verify(yarnMetricsClient, verificationMode).getYarnMetricsForCluster(any(Cluster.class), any(StackV4Response.class), anyString(), anyString(), any(Optional.class));
verify(yarnResponseUtils, verificationMode).getYarnRecommendedDecommissionHostsForHostGroup(anyString(), any(YarnScalingServiceV1Response.class), any(Map.class), anyInt(), any(Optional.class), anyInt());
return captor.getValue();
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response in project cloudbreak by hortonworks.
the class MockStackResponseGenerator method getMockStackV4ResponseWithStoppedAndRunningNodes.
public static StackV4Response getMockStackV4ResponseWithStoppedAndRunningNodes(String clusterCrn, String hostGroup, String fqdnBase, int runningHostGroupNodeCount, int stoppedHostGroupNodeCount) {
List<InstanceGroupV4Response> instanceGroupV4Responses = new ArrayList<>();
InstanceMetaDataV4Response master1 = new InstanceMetaDataV4Response();
master1.setDiscoveryFQDN("master1");
master1.setInstanceId("test_instanceid" + "master1");
instanceGroupV4Responses.add(instanceGroup("master", awsTemplate(), Set.of(master1)));
InstanceMetaDataV4Response worker1 = new InstanceMetaDataV4Response();
worker1.setDiscoveryFQDN("worker1");
worker1.setInstanceId("test_instanceid" + "worker1");
InstanceMetaDataV4Response worker2 = new InstanceMetaDataV4Response();
worker2.setDiscoveryFQDN("worker2");
worker2.setInstanceId("test_instanceid" + "worker2");
instanceGroupV4Responses.add(instanceGroup("worker", awsTemplate(), Set.of(worker1, worker2)));
Set<InstanceMetaDataV4Response> instanceMetadata = new HashSet<>();
int i;
for (i = 0; i < runningHostGroupNodeCount; ++i) {
InstanceMetaDataV4Response metadata1 = new InstanceMetaDataV4Response();
metadata1.setDiscoveryFQDN(fqdnBase + i);
metadata1.setInstanceId("test_instanceid_" + hostGroup + i);
metadata1.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
instanceMetadata.add(metadata1);
}
for (i = 0; i < stoppedHostGroupNodeCount; ++i) {
InstanceMetaDataV4Response metadata1 = new InstanceMetaDataV4Response();
metadata1.setDiscoveryFQDN(fqdnBase + runningHostGroupNodeCount + i);
metadata1.setInstanceId("test_instanceid_" + hostGroup + (runningHostGroupNodeCount + i));
metadata1.setInstanceStatus(InstanceStatus.STOPPED);
instanceMetadata.add(metadata1);
}
instanceGroupV4Responses.add(instanceGroup(hostGroup, awsTemplate(), instanceMetadata));
StackV4Response mockResponse = new StackV4Response();
mockResponse.setCrn(clusterCrn);
mockResponse.setInstanceGroups(instanceGroupV4Responses);
mockResponse.setNodeCount(instanceGroupV4Responses.stream().flatMap(ig -> ig.getMetadata().stream()).collect(Collectors.counting()).intValue());
mockResponse.setCloudPlatform(CloudPlatform.AWS);
return mockResponse;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response in project cloudbreak by hortonworks.
the class StackResponseUtilsTest method validateGetRoleConfigNameForHostGroup.
private void validateGetRoleConfigNameForHostGroup(String testService, String testRole, String testHostGroup, String expectedRoleConfigName) throws Exception {
StackV4Response mockStackResponse = mock(StackV4Response.class);
ClusterV4Response mockCluster = mock(ClusterV4Response.class);
BlueprintV4Response mockBluePrint = mock(BlueprintV4Response.class);
when(mockStackResponse.getCluster()).thenReturn(mockCluster);
when(mockCluster.getBlueprint()).thenReturn(mockBluePrint);
when(mockBluePrint.getBlueprint()).thenReturn(getTestBP());
String hostGroupRolename = underTest.getRoleConfigNameForHostGroup(mockStackResponse, testHostGroup, testService, testRole);
assertEquals("RoleConfigName in template should match for HostGroup", expectedRoleConfigName, hostGroupRolename);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response in project cloudbreak by hortonworks.
the class StackCreatorService method createStack.
public StackV4Response createStack(User user, Workspace workspace, StackV4Request stackRequest, boolean distroxRequest) {
long start = System.currentTimeMillis();
String stackName = stackRequest.getName();
nodeCountLimitValidator.validateProvision(stackRequest);
measure(() -> validateRecipeExistenceOnInstanceGroups(stackRequest.getInstanceGroups(), workspace.getId()), LOGGER, "Check that recipes do exist took {} ms");
measure(() -> ensureStackDoesNotExists(stackName, workspace), LOGGER, "Stack does not exist check took {} ms");
Stack stackStub = measure(() -> stackV4RequestToStackConverter.convert(stackRequest), LOGGER, "Stack request converted to stack took {} ms for stack {}", stackName);
stackStub.setWorkspace(workspace);
stackStub.setCreator(user);
StackType stackType = determineStackTypeBasedOnTheUsedApi(stackStub, distroxRequest);
stackStub.setType(stackType);
String platformString = stackStub.getCloudPlatform().toLowerCase();
MDCBuilder.buildMdcContext(stackStub);
Stack savedStack;
try {
Blueprint blueprint = measure(() -> determineBlueprint(stackRequest, workspace), LOGGER, "Blueprint determined in {} ms for stack {}", stackName);
Future<StatedImage> imgFromCatalogFuture = determineImageCatalog(stackName, platformString, stackRequest, blueprint, user, workspace);
hueWorkaroundValidatorService.validateForStackRequest(getHueHostGroups(blueprint.getBlueprintText()), stackStub.getName());
savedStack = transactionService.required(() -> {
Stack stack = measure(() -> stackDecorator.decorate(stackStub, stackRequest, user, workspace), LOGGER, "Decorate Stack with data took {} ms");
DetailedEnvironmentResponse environment = measure(() -> ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> environmentClientService.getByCrn(stack.getEnvironmentCrn())), LOGGER, "Get Environment from Environment service took {} ms");
if (stack.getOrchestrator() != null && stack.getOrchestrator().getApiEndpoint() != null) {
measure(() -> stackService.validateOrchestrator(stack.getOrchestrator()), LOGGER, "Validate orchestrator took {} ms");
}
stack.setUseCcm(environment.getTunnel().useCcm());
stack.setTunnel(environment.getTunnel());
if (stackRequest.getCluster() != null) {
measure(() -> setStackType(stack, blueprint), LOGGER, "Set stacktype for stack object took {} ms");
measure(() -> clusterCreationService.validate(stackRequest.getCluster(), stack, user, workspace, environment), LOGGER, "Validate cluster rds and autotls took {} ms");
}
measure(() -> fillInstanceMetadata(environment, stack), LOGGER, "Fill up instance metadata took {} ms");
StatedImage imgFromCatalog = measure(() -> getImageCatalog(imgFromCatalogFuture), LOGGER, "Select the correct image took {} ms");
stackRuntimeVersionValidator.validate(stackRequest, imgFromCatalog.getImage(), stackType);
Stack newStack = measure(() -> stackService.create(stack, platformString, imgFromCatalog, user, workspace, Optional.ofNullable(stackRequest.getResourceCrn())), LOGGER, "Save the remaining stack data took {} ms");
try {
LOGGER.info("Create cluster entity in the database with name {}.", stackName);
long clusterSaveStart = System.currentTimeMillis();
createClusterIfNeeded(user, stackRequest, newStack, stackName, blueprint);
LOGGER.info("Cluster save took {} ms", System.currentTimeMillis() - clusterSaveStart);
} catch (CloudbreakImageCatalogException | IOException | TransactionExecutionException e) {
throw new RuntimeException(e.getMessage(), e);
}
measure(() -> assignOwnerRoleOnDataHub(user, stackRequest, newStack), LOGGER, "assignOwnerRoleOnDataHub to stack took {} ms with name {}.", stackName);
return newStack;
});
} catch (TransactionExecutionException e) {
stackUnderOperationService.off();
if (e.getCause() instanceof DataIntegrityViolationException) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.STACK, getProperSqlErrorMessage((DataIntegrityViolationException) e.getCause()));
throw new BadRequestException(msg, e.getCause());
}
throw new TransactionRuntimeExecutionException(e);
}
StackV4Response response = measure(() -> stackToStackV4ResponseConverter.convert(savedStack), LOGGER, "Stack response has been created for stack took {} ms with name {}", stackName);
LOGGER.info("Generated stack response after creation: {}", JsonUtil.writeValueAsStringSilentSafe(response));
FlowIdentifier flowIdentifier = measure(() -> flowManager.triggerProvisioning(savedStack.getId()), LOGGER, "Stack triggerProvisioning took {} ms with name {}", stackName);
response.setFlowIdentifier(flowIdentifier);
metricService.submit(STACK_PREPARATION, System.currentTimeMillis() - start);
return response;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response in project cloudbreak by hortonworks.
the class SdxCcmUpgradeServiceTest method getStack.
private StackV4Response getStack(Tunnel tunnel, Status status) {
StackV4Response response = new StackV4Response();
response.setName("stackName");
response.setTunnel(tunnel);
response.setStatus(status);
return response;
}
Aggregations