Search in sources :

Example 16 with AdjustmentTypeWithThreshold

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);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CreateApplicationRequest(com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.CreateApplicationRequest) ApplicationDetailRequest(com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.ApplicationDetailRequest) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) Test(org.junit.Test)

Example 17 with AdjustmentTypeWithThreshold

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");
}
Also used : ApplicationDetailRequest(com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.ApplicationDetailRequest) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) Test(org.junit.Test)

Example 18 with AdjustmentTypeWithThreshold

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();
}
Also used : DescribeMountTargetsResult(com.amazonaws.services.elasticfilesystem.model.DescribeMountTargetsResult) Arrays(java.util.Arrays) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ActiveProfiles(org.springframework.test.context.ActiveProfiles) AmazonCloudWatchClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonCloudWatchClient) DescribeStacksResult(com.amazonaws.services.cloudformation.model.DescribeStacksResult) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) AmazonEC2Waiters(com.amazonaws.services.ec2.waiters.AmazonEC2Waiters) AmazonCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) DescribeScalingActivitiesRequest(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesRequest) SpringRunner(org.springframework.test.context.junit4.SpringRunner) AmazonAutoScalingWaiters(com.amazonaws.services.autoscaling.waiters.AmazonAutoScalingWaiters) Waiter(com.amazonaws.waiters.Waiter) MockBean(org.springframework.boot.test.mock.mockito.MockBean) Reservation(com.amazonaws.services.ec2.model.Reservation) LifeCycleState(com.amazonaws.services.elasticfilesystem.model.LifeCycleState) DescribeFileSystemsResult(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsResult) AmazonServiceException(com.amazonaws.AmazonServiceException) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Output(com.amazonaws.services.cloudformation.model.Output) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) TestPropertySource(org.springframework.test.context.TestPropertySource) AmazonCloudFormationWaiters(com.amazonaws.services.cloudformation.waiters.AmazonCloudFormationWaiters) Retry(com.sequenceiq.cloudbreak.service.Retry) FreeMarkerTemplateUtils(com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils) AwsResourceConnector(com.sequenceiq.cloudbreak.cloud.aws.connector.resource.AwsResourceConnector) CreateFileSystemResult(com.amazonaws.services.elasticfilesystem.model.CreateFileSystemResult) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) AmazonAutoScalingClient(com.sequenceiq.cloudbreak.cloud.aws.client.AmazonAutoScalingClient) VolumeState(com.amazonaws.services.ec2.model.VolumeState) Mockito.inOrder(org.mockito.Mockito.inOrder) DeleteFileSystemResult(com.amazonaws.services.elasticfilesystem.model.DeleteFileSystemResult) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) LocationHelper(com.sequenceiq.cloudbreak.cloud.storage.LocationHelper) Mock(org.mockito.Mock) DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) AVAILABILITY_ZONE(com.sequenceiq.cloudbreak.cloud.aws.component.ComponentTestUtil.AVAILABILITY_ZONE) RunWith(org.junit.runner.RunWith) AmazonEfsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient) ResourceRetriever(com.sequenceiq.cloudbreak.cloud.service.ResourceRetriever) Supplier(java.util.function.Supplier) StackResourceDetail(com.amazonaws.services.cloudformation.model.StackResourceDetail) Inject(javax.inject.Inject) CreateVolumeResult(com.amazonaws.services.ec2.model.CreateVolumeResult) Answer(org.mockito.stubbing.Answer) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) DeleteMountTargetResult(com.amazonaws.services.elasticfilesystem.model.DeleteMountTargetResult) DescribeImagesResult(com.amazonaws.services.ec2.model.DescribeImagesResult) ResourceType(com.sequenceiq.common.api.type.ResourceType) InOrder(org.mockito.InOrder) AmazonElasticFileSystemClient(com.amazonaws.services.elasticfilesystem.AmazonElasticFileSystemClient) FileSystemDescription(com.amazonaws.services.elasticfilesystem.model.FileSystemDescription) DescribeScalingActivitiesResult(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesResult) AwsCloudFormationClient(com.sequenceiq.cloudbreak.cloud.aws.AwsCloudFormationClient) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) DescribePrefixListsResult(com.amazonaws.services.ec2.model.DescribePrefixListsResult) InMemoryStateStore(com.sequenceiq.cloudbreak.cloud.store.InMemoryStateStore) Import(org.springframework.context.annotation.Import) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Stack(com.amazonaws.services.cloudformation.model.Stack) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) LifecycleState(com.amazonaws.services.autoscaling.model.LifecycleState) Mockito.verify(org.mockito.Mockito.verify) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) Mockito.never(org.mockito.Mockito.never) MountTargetDescription(com.amazonaws.services.elasticfilesystem.model.MountTargetDescription) CustomAmazonWaiterProvider(com.sequenceiq.cloudbreak.cloud.aws.scheduler.CustomAmazonWaiterProvider) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) Instance(com.amazonaws.services.autoscaling.model.Instance) DescribeStackResourceResult(com.amazonaws.services.cloudformation.model.DescribeStackResourceResult) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) PollGroup(com.sequenceiq.cloudbreak.cloud.scheduler.PollGroup) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InOrder(org.mockito.InOrder) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Test(org.junit.Test)

Example 19 with AdjustmentTypeWithThreshold

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");
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) CloudError(com.microsoft.azure.CloudError) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudException(com.microsoft.azure.CloudException) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Retry(com.sequenceiq.cloudbreak.service.Retry) Test(org.junit.Test)

Example 20 with AdjustmentTypeWithThreshold

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);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DeploymentExportResult(com.microsoft.azure.management.resources.DeploymentExportResult) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.Test)

Aggregations

AdjustmentTypeWithThreshold (com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold)41 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)22 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)20 Group (com.sequenceiq.cloudbreak.cloud.model.Group)20 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)18 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)15 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)14 Test (org.junit.jupiter.api.Test)14 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)12 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)12 List (java.util.List)12 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)11 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)11 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 QuotaExceededException (com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException)9 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)9 AdjustmentType (com.sequenceiq.common.api.type.AdjustmentType)9 Inject (javax.inject.Inject)9