Search in sources :

Example 26 with SdxClusterRequest

use of com.sequenceiq.sdx.api.model.SdxClusterRequest in project cloudbreak by hortonworks.

the class SdxServiceTest method testCreateNOTInternalSdxClusterFromLightDutyTemplateWhenBaseLocationSpecifiedShouldCreateStackRequestWithSettedUpBaseLocation.

@Test
void testCreateNOTInternalSdxClusterFromLightDutyTemplateWhenBaseLocationSpecifiedShouldCreateStackRequestWithSettedUpBaseLocation() throws IOException, TransactionExecutionException {
    when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
    String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.1.0/aws/light_duty.json");
    when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
    // doNothing().when(cloudStorageLocationValidator.validate("s3a://some/dir", ));
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(null, LIGHT_DUTY);
    withCloudStorage(sdxClusterRequest);
    long id = 10L;
    when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
        SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
        sdxWithId.setId(id);
        return sdxWithId;
    });
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
    Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
    SdxCluster createdSdxCluster = result.getLeft();
    assertEquals("s3a://some/dir", createdSdxCluster.getCloudStorageBaseLocation());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 27 with SdxClusterRequest

use of com.sequenceiq.sdx.api.model.SdxClusterRequest in project cloudbreak by hortonworks.

the class SdxServiceTest method testSdxCreateMediumDutySdx.

@Test
void testSdxCreateMediumDutySdx() throws IOException, TransactionExecutionException {
    final String runtime = "7.2.7";
    when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
    String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/" + runtime + "/aws/medium_duty_ha.json");
    when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
    when(sdxReactorFlowManager.triggerSdxCreation(any())).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(runtime, MEDIUM_DUTY_HA);
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
    withCloudStorage(sdxClusterRequest);
    long id = 10L;
    when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
        SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
        sdxWithId.setId(id);
        return sdxWithId;
    });
    when(clock.getCurrentTimeMillis()).thenReturn(1L);
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
    Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
    SdxCluster createdSdxCluster = result.getLeft();
    assertEquals(id, createdSdxCluster.getId());
    ArgumentCaptor<SdxCluster> captor = ArgumentCaptor.forClass(SdxCluster.class);
    verify(sdxClusterRepository, times(1)).save(captor.capture());
    SdxCluster capturedSdx = captor.getValue();
    assertEquals(MEDIUM_DUTY_HA, capturedSdx.getClusterShape());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 28 with SdxClusterRequest

use of com.sequenceiq.sdx.api.model.SdxClusterRequest in project cloudbreak by hortonworks.

the class SdxServiceTest method testCreateSdxClusterWithCustomInstanceGroup.

@Test
void testCreateSdxClusterWithCustomInstanceGroup() throws Exception {
    final String runtime = "7.2.12";
    when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
    String microDutyJson = FileReaderUtils.readFileFromClasspath("/duties/" + runtime + "/aws/micro_duty.json");
    when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(microDutyJson, StackV4Request.class));
    when(sdxReactorFlowManager.triggerSdxCreation(any())).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(runtime, MICRO_DUTY);
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
    withCloudStorage(sdxClusterRequest);
    withRecipe(sdxClusterRequest);
    withCustomInstanceGroups(sdxClusterRequest);
    RecipeViewV4Responses recipeViewV4Responses = new RecipeViewV4Responses();
    RecipeViewV4Response recipeViewV4Response = new RecipeViewV4Response();
    recipeViewV4Response.setName("post-install");
    recipeViewV4Responses.setResponses(List.of(recipeViewV4Response));
    when(recipeV4Endpoint.listInternal(anyLong(), anyString())).thenReturn(recipeViewV4Responses);
    long id = 10L;
    when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
        SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
        sdxWithId.setId(id);
        return sdxWithId;
    });
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(clock.getCurrentTimeMillis()).thenReturn(1L);
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
    when(entitlementService.microDutySdxEnabled(anyString())).thenReturn(true);
    when(entitlementService.isDatalakeSelectInstanceTypeEnabled(anyString())).thenReturn(true);
    Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
    SdxCluster createdSdxCluster = result.getLeft();
    assertEquals(id, createdSdxCluster.getId());
    ArgumentCaptor<SdxCluster> captor = ArgumentCaptor.forClass(SdxCluster.class);
    verify(sdxClusterRepository, times(1)).save(captor.capture());
    verify(recipeV4Endpoint, times(1)).listInternal(anyLong(), anyString());
    SdxCluster capturedSdx = captor.getValue();
    assertEquals(MICRO_DUTY, capturedSdx.getClusterShape());
    StackV4Request stackRequest = JsonUtil.readValue(capturedSdx.getStackRequest(), StackV4Request.class);
    Optional<InstanceGroupV4Request> masterGroup = stackRequest.getInstanceGroups().stream().filter(instanceGroup -> "master".equals(instanceGroup.getName())).findAny();
    assertTrue(masterGroup.isPresent());
    assertEquals("verylarge", masterGroup.get().getTemplate().getInstanceType());
    Optional<InstanceGroupV4Request> idbrokerGroup = stackRequest.getInstanceGroups().stream().filter(instanceGroup -> "idbroker".equals(instanceGroup.getName())).findAny();
    assertTrue(idbrokerGroup.isPresent());
    assertEquals("notverylarge", idbrokerGroup.get().getTemplate().getInstanceType());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) BaseStackDetailsV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseStackDetailsV4Response) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RangerRazEnabledV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.RangerRazEnabledV4Response) Mockito.doThrow(org.mockito.Mockito.doThrow) MockitoAnnotations(org.mockito.MockitoAnnotations) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) Pair(org.apache.commons.lang3.tuple.Pair) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) RegionAwareInternalCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator) SdxRecipe(com.sequenceiq.sdx.api.model.SdxRecipe) Set(java.util.Set) Arguments(org.junit.jupiter.params.provider.Arguments) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) SdxClusterResizeRequest(com.sequenceiq.sdx.api.model.SdxClusterResizeRequest) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) CloudStorageLocationValidator(com.sequenceiq.datalake.service.validation.cloudstorage.CloudStorageLocationValidator) CCMV2_JUMPGATE_REQUIRED_VERSION(com.sequenceiq.datalake.service.sdx.SdxService.CCMV2_JUMPGATE_REQUIRED_VERSION) Mock(org.mockito.Mock) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.lenient(org.mockito.Mockito.lenient) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) SdxClusterRequestBase(com.sequenceiq.sdx.api.model.SdxClusterRequestBase) CUSTOM(com.sequenceiq.sdx.api.model.SdxClusterShape.CUSTOM) LinkedHashMap(java.util.LinkedHashMap) FileReaderUtils(com.sequenceiq.cloudbreak.util.FileReaderUtils) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CORE(com.sequenceiq.common.api.type.InstanceGroupType.CORE) GATEWAY(com.sequenceiq.common.api.type.InstanceGroupType.GATEWAY) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) InjectMocks(org.mockito.InjectMocks) DistroXV1Endpoint(com.sequenceiq.distrox.api.v1.distrox.endpoint.DistroXV1Endpoint) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ImageSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.image.ImageSettingsV4Request) SdxCustomClusterRequest(com.sequenceiq.sdx.api.model.SdxCustomClusterRequest) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) DisplayName(org.junit.jupiter.api.DisplayName) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) RecipeV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.recipes.RecipeV4Endpoint) FileSystemType(com.sequenceiq.common.model.FileSystemType) ClouderaManagerProductV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.clouderamanager.ClouderaManagerProductV4Response) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CCMV2_REQUIRED_VERSION(com.sequenceiq.datalake.service.sdx.SdxService.CCMV2_REQUIRED_VERSION) SdxDatabaseAvailabilityType(com.sequenceiq.sdx.api.model.SdxDatabaseAvailabilityType) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FlowCancelService(com.sequenceiq.flow.service.FlowCancelService) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CloudbreakInternalCrnClient(com.sequenceiq.cloudbreak.client.CloudbreakInternalCrnClient) SdxCloudStorageRequest(com.sequenceiq.sdx.api.model.SdxCloudStorageRequest) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) MethodSource(org.junit.jupiter.params.provider.MethodSource) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) Tunnel(com.sequenceiq.common.api.type.Tunnel) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) StackV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint) RecipeViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.recipes.responses.RecipeViewV4Responses) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) CDPConfigService(com.sequenceiq.datalake.configuration.CDPConfigService) UUID(java.util.UUID) Sets(com.google.common.collect.Sets) SdxAwsSpotParameters(com.sequenceiq.sdx.api.model.SdxAwsSpotParameters) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) Test(org.junit.jupiter.api.Test) SdxStatusService(com.sequenceiq.datalake.service.sdx.status.SdxStatusService) LIGHT_DUTY(com.sequenceiq.sdx.api.model.SdxClusterShape.LIGHT_DUTY) List(java.util.List) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) MEDIUM_DUTY_REQUIRED_VERSION(com.sequenceiq.datalake.service.sdx.SdxService.MEDIUM_DUTY_REQUIRED_VERSION) Optional(java.util.Optional) CloudbreakServiceCrnEndpoints(com.sequenceiq.cloudbreak.client.CloudbreakServiceCrnEndpoints) SdxInstanceGroupRequest(com.sequenceiq.sdx.api.model.SdxInstanceGroupRequest) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Clock(com.sequenceiq.cloudbreak.common.service.Clock) RecipeViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.recipes.responses.RecipeViewV4Response) ClouderaManagerV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.clouderamanager.ClouderaManagerV4Response) DatalakeStatusEnum(com.sequenceiq.datalake.entity.DatalakeStatusEnum) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape) SdxReactorFlowManager(com.sequenceiq.datalake.flow.SdxReactorFlowManager) ImageCatalogService(com.sequenceiq.datalake.service.imagecatalog.ImageCatalogService) MICRO_DUTY(com.sequenceiq.sdx.api.model.SdxClusterShape.MICRO_DUTY) HashMap(java.util.HashMap) SdxClusterRepository(com.sequenceiq.datalake.repository.SdxClusterRepository) CrnTestUtil(com.sequenceiq.cloudbreak.auth.crn.CrnTestUtil) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) MEDIUM_DUTY_HA(com.sequenceiq.sdx.api.model.SdxClusterShape.MEDIUM_DUTY_HA) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) ImageCatalogV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint) RegionAwareCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator) EnvironmentClientService(com.sequenceiq.datalake.service.EnvironmentClientService) S3CloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) Mockito.when(org.mockito.Mockito.when) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StackViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response) Mockito.verify(org.mockito.Mockito.verify) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) FlowType(com.sequenceiq.flow.api.model.FlowType) ClusterV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response) Collections(java.util.Collections) SdxAwsRequest(com.sequenceiq.sdx.api.model.SdxAwsRequest) RecipeViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.recipes.responses.RecipeViewV4Response) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Supplier(java.util.function.Supplier) RecipeViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.recipes.responses.RecipeViewV4Responses) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 29 with SdxClusterRequest

use of com.sequenceiq.sdx.api.model.SdxClusterRequest in project cloudbreak by hortonworks.

the class SdxServiceTest method testCreateMicroDuty.

@Test
void testCreateMicroDuty() throws IOException, TransactionExecutionException {
    final String runtime = "7.2.12";
    when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
    String microDutyJson = FileReaderUtils.readFileFromClasspath("/duties/" + runtime + "/aws/micro_duty.json");
    when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(microDutyJson, StackV4Request.class));
    when(sdxReactorFlowManager.triggerSdxCreation(any())).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(runtime, MICRO_DUTY);
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
    withCloudStorage(sdxClusterRequest);
    withRecipe(sdxClusterRequest);
    RecipeViewV4Responses recipeViewV4Responses = new RecipeViewV4Responses();
    RecipeViewV4Response recipeViewV4Response = new RecipeViewV4Response();
    recipeViewV4Response.setName("post-install");
    recipeViewV4Responses.setResponses(List.of(recipeViewV4Response));
    when(recipeV4Endpoint.listInternal(anyLong(), anyString())).thenReturn(recipeViewV4Responses);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    long id = 10L;
    when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
        SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
        sdxWithId.setId(id);
        return sdxWithId;
    });
    when(clock.getCurrentTimeMillis()).thenReturn(1L);
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
    when(entitlementService.microDutySdxEnabled(anyString())).thenReturn(true);
    Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
    SdxCluster createdSdxCluster = result.getLeft();
    assertEquals(id, createdSdxCluster.getId());
    ArgumentCaptor<SdxCluster> captor = ArgumentCaptor.forClass(SdxCluster.class);
    verify(sdxClusterRepository, times(1)).save(captor.capture());
    verify(recipeV4Endpoint, times(1)).listInternal(anyLong(), anyString());
    SdxCluster capturedSdx = captor.getValue();
    assertEquals(MICRO_DUTY, capturedSdx.getClusterShape());
}
Also used : RecipeViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.recipes.responses.RecipeViewV4Response) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) RecipeViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.recipes.responses.RecipeViewV4Responses) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 30 with SdxClusterRequest

use of com.sequenceiq.sdx.api.model.SdxClusterRequest in project cloudbreak by hortonworks.

the class SdxServiceTest method testCreateSdxClusterWithSpotStackRequestContainsRequiredAttributes.

@Test
void testCreateSdxClusterWithSpotStackRequestContainsRequiredAttributes() throws IOException, TransactionExecutionException {
    when(transactionService.required(isA(Supplier.class))).thenAnswer(invocation -> invocation.getArgument(0, Supplier.class).get());
    String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.1.0/aws/light_duty.json");
    when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(null, LIGHT_DUTY);
    setSpot(sdxClusterRequest);
    withCloudStorage(sdxClusterRequest);
    long id = 10L;
    when(sdxClusterRepository.save(any(SdxCluster.class))).thenAnswer(invocation -> {
        SdxCluster sdxWithId = invocation.getArgument(0, SdxCluster.class);
        sdxWithId.setId(id);
        return sdxWithId;
    });
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
    Pair<SdxCluster, FlowIdentifier> result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
    SdxCluster createdSdxCluster = result.getLeft();
    // AWS 7.1.0 light duty contains exactly 2 instance groups
    assertThat(createdSdxCluster.getStackRequest()).containsSubsequence("{\"aws\":{\"spot\":{\"percentage\":100,\"maxPrice\":0.9}}", "{\"aws\":{\"spot\":{\"percentage\":100,\"maxPrice\":0.9}}");
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)37 Test (org.junit.jupiter.api.Test)26 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)20 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)17 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)16 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)14 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)13 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)11 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)10 SdxCloudStorageRequest (com.sequenceiq.sdx.api.model.SdxCloudStorageRequest)10 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 Supplier (java.util.function.Supplier)9 CloudStorageRequest (com.sequenceiq.common.api.cloudstorage.CloudStorageRequest)8 StorageLocationBase (com.sequenceiq.common.api.cloudstorage.StorageLocationBase)7 S3CloudStorageV1Parameters (com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters)7 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)5 RegionAwareInternalCrnGenerator (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator)5 RegionAwareInternalCrnGeneratorFactory (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory)5 LoggingResponse (com.sequenceiq.common.api.telemetry.response.LoggingResponse)5