Search in sources :

Example 1 with MICRO_DUTY

use of com.sequenceiq.sdx.api.model.SdxClusterShape.MICRO_DUTY 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)

Aggregations

Sets (com.google.common.collect.Sets)1 OwnerAssignmentService (com.sequenceiq.authorization.service.OwnerAssignmentService)1 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)1 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)1 ImageCatalogV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint)1 BaseStackDetailsV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.BaseStackDetailsV4Response)1 ImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)1 RecipeV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.recipes.RecipeV4Endpoint)1 RecipeViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.recipes.responses.RecipeViewV4Response)1 RecipeViewV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.recipes.responses.RecipeViewV4Responses)1 StackV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint)1 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)1 ImageSettingsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.image.ImageSettingsV4Request)1 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)1 RangerRazEnabledV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.RangerRazEnabledV4Response)1 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)1 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)1 ClusterV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response)1 ClouderaManagerProductV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.clouderamanager.ClouderaManagerProductV4Response)1