use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.
the class YarnResourceConnectorTest method testLaunch.
@Test
public void testLaunch() throws Exception {
ArgumentCaptor<CreateApplicationRequest> createRequestCaptor = ArgumentCaptor.forClass(CreateApplicationRequest.class);
ArgumentCaptor<ApplicationDetailRequest> requestCaptor = ArgumentCaptor.forClass(ApplicationDetailRequest.class);
setUpHappyPath(createRequestCaptor, requestCaptor);
List<Group> groupList = IntStream.range(0, 2).mapToObj(this::createGroup).collect(Collectors.toList());
when(stackMock.getGroups()).thenReturn(groupList);
when(stackMock.getLoginUserName()).thenReturn(LOGIN_USER_NAME);
when(stackMock.getPublicKey()).thenReturn(PUBLIC_KEY);
when(imageMock.getUserDataByType(InstanceGroupType.CORE)).thenReturn(USER_DATA);
when(cloudInstanceMock.getTemplate()).thenReturn(instanceTemplateMock);
when(instanceTemplateMock.getParameter(PlatformParametersConsts.CUSTOM_INSTANCETYPE_CPUS, Integer.class)).thenReturn(2);
when(instanceTemplateMock.getParameter(PlatformParametersConsts.CUSTOM_INSTANCETYPE_MEMORY, Integer.class)).thenReturn(4096);
when(applicationNameUtilMock.createApplicationName(authenticatedContextMock)).thenReturn("n-1");
when(yarnApplicationCreationService.checkApplicationAlreadyCreated(any(), any())).thenReturn(false);
when(yarnApplicationCreationService.initializeRequest(any(), any())).thenReturn(createInitialApplicationRequest("n-1"));
List<CloudResourceStatus> cloudResourceStatusList = underTest.launch(authenticatedContextMock, stackMock, persistenceNotifierMock, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, Long.MAX_VALUE));
verify(persistenceNotifierMock, times(1)).notifyAllocation(any(), any());
verify(yarnApplicationCreationService).createApplication(any(), createRequestCaptor.capture());
String expectedAppName = "n-1";
assertCreateRequest(createRequestCaptor, groupList, expectedAppName);
ApplicationDetailRequest capturedRequest = requestCaptor.getValue();
assertEquals(expectedAppName, capturedRequest.getName());
assertCloudResourceStatusList(cloudResourceStatusList, expectedAppName);
}
use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.
the class YarnResourceConnectorTest method testLaunchApplicationAlreadyCreated.
@Test
public void testLaunchApplicationAlreadyCreated() throws Exception {
when(authenticatedContextMock.getCloudContext()).thenReturn(CloudContext.Builder.builder().withId(1L).withName("name").withCrn("crn").withPlatform("platform").withUserName(USER_NAME).withWorkspaceId(WORKSPACE_ID).build());
when(yarnClientUtilMock.createYarnClient(authenticatedContextMock)).thenReturn(yarnClientMock);
ArgumentCaptor<ApplicationDetailRequest> requestCaptor = ArgumentCaptor.forClass(ApplicationDetailRequest.class);
when(yarnClientMock.getApplicationDetail(requestCaptor.capture())).thenReturn(createResponseContext(YarnResourceConstants.HTTP_SUCCESS));
when(yarnApplicationCreationService.checkApplicationAlreadyCreated(any(), any())).thenReturn(true);
when(applicationNameUtilMock.createApplicationName(authenticatedContextMock)).thenReturn("n-1-hort");
List<CloudResourceStatus> cloudResourceStatusList = underTest.launch(authenticatedContextMock, stackMock, persistenceNotifierMock, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, Long.MAX_VALUE));
ApplicationDetailRequest capturedRequest = requestCaptor.getValue();
String expectedAppName = "n-1-hort";
assertEquals(expectedAppName, capturedRequest.getName());
assertCloudResourceStatusList(cloudResourceStatusList, "n-1-hort");
}
use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.
the class AwsLaunchTest method launchStack.
@Test
public void launchStack() throws Exception {
setup();
setupRetryService();
setupFreemarkerTemplateProcessing();
setupDescribeStacksResponses();
setupDescribeImagesResponse();
setupDescribeStackResourceResponse();
setupAutoscalingResponses();
setupDescribeInstancesResponse();
setupCreateVolumeResponse();
setupDescribeVolumeResponse();
setupDescribeSubnetResponse();
setupDescribePrefixListsResponse();
InMemoryStateStore.putStack(1L, PollGroup.POLLABLE);
AuthenticatedContext authenticatedContext = componentTestUtil.getAuthenticatedContext();
authenticatedContext.putParameter(AmazonEc2Client.class, amazonEc2Client);
awsResourceConnector.launch(authenticatedContext, componentTestUtil.getStackForLaunch(InstanceStatus.CREATE_REQUESTED, InstanceStatus.CREATE_REQUESTED), persistenceNotifier, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, Long.MAX_VALUE));
// assert
verify(persistenceNotifier).notifyAllocation(argThat(cloudResource -> ResourceType.AWS_VPC.equals(cloudResource.getType())), any());
verify(persistenceNotifier, times(2)).notifyAllocation(argThat(cloudResource -> ResourceType.AWS_VOLUMESET.equals(cloudResource.getType())), any());
verify(persistenceNotifier).notifyAllocation(argThat(cloudResource -> ResourceType.AWS_SUBNET.equals(cloudResource.getType())), any());
verify(persistenceNotifier).notifyAllocation(argThat(cloudResource -> ResourceType.CLOUDFORMATION_STACK.equals(cloudResource.getType())), any());
InOrder inOrder = inOrder(amazonEc2Client, amazonCloudFormationClient, amazonEc2Client);
inOrder.verify(amazonEc2Client).describeImages(any());
inOrder.verify(amazonCloudFormationClient).createStack(any());
inOrder.verify(amazonEc2Client, times(2)).createVolume(any());
inOrder.verify(amazonEc2Client, times(2)).attachVolume(any());
inOrder.verify(amazonEc2Client, never()).describePrefixLists();
}
use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.
the class AzureUpscaleServiceTest method testUpscaleWhenVmsNotStartedInTime.
@Test
public void testUpscaleWhenVmsNotStartedInTime() {
CloudContext cloudContext = createCloudContext();
AuthenticatedContext ac = new AuthenticatedContext(cloudContext, null);
CloudResource template = createCloudResource(TEMPLATE, ResourceType.ARM_TEMPLATE);
List<CloudResource> resources = List.of(createCloudResource("volumes", ResourceType.AZURE_VOLUMESET), template);
List<Group> scaledGroups = createScaledGroups();
when(cloudResourceHelper.getScaledGroups(stack)).thenReturn(scaledGroups);
CloudError cloudError = new CloudError().withCode("code").withMessage("Error happened");
cloudError.details().add(new CloudError().withCode("code").withMessage("Please check the power state later"));
when(azureTemplateDeploymentService.getTemplateDeployment(client, stack, ac, azureStackView, AzureInstanceTemplateOperation.UPSCALE)).thenThrow(new Retry.ActionFailedException("VMs not started in time.", new CloudException("Error", null, cloudError)));
when(azureUtils.convertToCloudConnectorException(any(CloudException.class), anyString())).thenCallRealMethod();
when(azureUtils.convertToCloudConnectorException(any(Throwable.class), anyString())).thenCallRealMethod();
CloudConnectorException cloudConnectorException = assertThrows(CloudConnectorException.class, () -> underTest.upscale(ac, stack, resources, azureStackView, client, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 0L)));
assertThat(cloudConnectorException.getMessage()).contains("Stack upscale failed, status code code, error message: Error happened, details: Please check the power state later");
}
use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.
the class AzureUpscaleServiceTest method testUpscaleThenThereAreNewInstancesRequired.
@Test
public void testUpscaleThenThereAreNewInstancesRequired() throws QuotaExceededException {
CloudContext cloudContext = createCloudContext();
AuthenticatedContext ac = new AuthenticatedContext(cloudContext, null);
CloudResource template = createCloudResource(TEMPLATE, ResourceType.ARM_TEMPLATE);
List<CloudResource> resources = List.of(createCloudResource("volumes", ResourceType.AZURE_VOLUMESET), template);
List<Group> scaledGroups = createScaledGroups();
when(cloudResourceHelper.getScaledGroups(stack)).thenReturn(scaledGroups);
when(azureTemplateDeploymentService.getTemplateDeployment(client, stack, ac, azureStackView, AzureInstanceTemplateOperation.UPSCALE)).thenReturn(templateDeployment);
when(templateDeployment.exportTemplate()).thenReturn(mock(DeploymentExportResult.class));
CloudResource newInstance = CloudResource.builder().instanceId("instanceid").type(ResourceType.AZURE_INSTANCE).status(CommonStatus.CREATED).name("instance").params(Map.of()).build();
List<CloudResource> newInstances = List.of(newInstance);
when(azureCloudResourceService.getDeploymentCloudResources(templateDeployment)).thenReturn(newInstances);
when(azureCloudResourceService.getInstanceCloudResources(STACK_NAME, newInstances, scaledGroups, RESOURCE_GROUP)).thenReturn(newInstances);
when(azureCloudResourceService.getNetworkResources(resources)).thenReturn(NETWORK_RESOURCES);
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 0L);
List<CloudResourceStatus> actual = underTest.upscale(ac, stack, resources, azureStackView, client, adjustmentTypeWithThreshold);
assertFalse(actual.isEmpty());
assertEquals(template, actual.get(0).getCloudResource());
assertEquals(ResourceStatus.IN_PROGRESS, actual.get(0).getStatus());
verify(cloudResourceHelper).getScaledGroups(stack);
verify(azureTemplateDeploymentService).getTemplateDeployment(client, stack, ac, azureStackView, AzureInstanceTemplateOperation.UPSCALE);
verify(templateDeployment).exportTemplate();
verify(azureCloudResourceService).getInstanceCloudResources(STACK_NAME, newInstances, scaledGroups, RESOURCE_GROUP);
verify(azureCloudResourceService).getNetworkResources(resources);
verify(azureUtils).getStackName(any(CloudContext.class));
verify(azureResourceGroupMetadataProvider).getResourceGroupName(any(CloudContext.class), eq(stack));
verify(azureComputeResourceService).buildComputeResourcesForUpscale(ac, stack, scaledGroups, newInstances, List.of(), NETWORK_RESOURCES, adjustmentTypeWithThreshold);
}
Aggregations