Search in sources :

Example 11 with SdxClusterRequest

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

the class SdxServiceTest method testSdxCreateRazNotRequestedAndMultiAzRequested.

@ParameterizedTest(name = "{0}")
@MethodSource("razCloudPlatformDataProvider")
void testSdxCreateRazNotRequestedAndMultiAzRequested(String testCaseName, CloudPlatform cloudPlatform, boolean multiAz) 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));
    when(sdxReactorFlowManager.triggerSdxCreation(any())).thenReturn(new FlowIdentifier(FlowType.FLOW, "FLOW_ID"));
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest("7.1.0", LIGHT_DUTY);
    withCloudStorage(sdxClusterRequest);
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
    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, null);
    sdxClusterRequest.setEnableRangerRaz(false);
    sdxClusterRequest.setEnableMultiAz(multiAz);
    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();
    assertFalse(capturedSdx.isRangerRazEnabled());
    assertEquals(multiAz, capturedSdx.isEnableMultiAz());
}
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) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with SdxClusterRequest

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

the class SdxServiceTest method testCreateNOTInternalSdxClusterFromLightDutyTemplateShouldTriggerSdxCreationFlow.

@Test
void testCreateNOTInternalSdxClusterFromLightDutyTemplateShouldTriggerSdxCreationFlow() throws IOException, TransactionExecutionException {
    CrnTestUtil.mockCrnGenerator(regionAwareCrnGenerator);
    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);
    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.AZURE, 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("tagecske", capturedSdx.getTags().getValue("mytag"));
    assertEquals(CLUSTER_NAME, capturedSdx.getClusterName());
    assertEquals(LIGHT_DUTY, capturedSdx.getClusterShape());
    assertEquals("envir", capturedSdx.getEnvName());
    assertEquals("hortonworks", capturedSdx.getAccountId());
    assertEquals(USER_CRN, capturedSdx.getInitiatorUserCrn());
    verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(DatalakeStatusEnum.REQUESTED, "Datalake requested", createdSdxCluster);
    assertEquals(1L, capturedSdx.getCreated());
    assertFalse(capturedSdx.isCreateDatabase());
    assertTrue(createdSdxCluster.getCrn().matches("crn:cdp:datalake:us-west-1:hortonworks:datalake:.*"));
    StackV4Request stackV4Request = JsonUtil.readValue(capturedSdx.getStackRequest(), StackV4Request.class);
    assertEquals(2L, stackV4Request.getInstanceGroups().size());
    InstanceGroupV4Request core = getGroup(stackV4Request, CORE);
    assertEquals(1L, core.getSecurityGroup().getSecurityRules().size());
    assertEquals("0.0.0.0/0", core.getSecurityGroup().getSecurityRules().get(0).getSubnet());
    assertEquals("22", core.getSecurityGroup().getSecurityRules().get(0).getPorts().get(0));
    InstanceGroupV4Request gateway = getGroup(stackV4Request, GATEWAY);
    assertEquals(2L, gateway.getSecurityGroup().getSecurityRules().size());
    assertEquals("0.0.0.0/0", gateway.getSecurityGroup().getSecurityRules().get(0).getSubnet());
    assertEquals("443", gateway.getSecurityGroup().getSecurityRules().get(0).getPorts().get(0));
    assertEquals("0.0.0.0/0", gateway.getSecurityGroup().getSecurityRules().get(1).getSubnet());
    assertEquals("22", gateway.getSecurityGroup().getSecurityRules().get(1).getPorts().get(0));
    verify(sdxReactorFlowManager).triggerSdxCreation(createdSdxCluster);
}
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) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 13 with SdxClusterRequest

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

the class SdxServiceTest method testCreateInternalSdxClusterWithCustomInstanceGroupShouldFail.

@Test
void testCreateInternalSdxClusterWithCustomInstanceGroupShouldFail() {
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
    StackV4Request stackV4Request = new StackV4Request();
    ClusterV4Request clusterV4Request = new ClusterV4Request();
    stackV4Request.setCluster(clusterV4Request);
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest("7.2.12", CUSTOM);
    withCustomInstanceGroups(sdxClusterRequest);
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, stackV4Request));
    assertEquals("Custom instance group is not accepted on SDX Internal API.", badRequestException.getMessage());
}
Also used : ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 14 with SdxClusterRequest

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

the class SdxServiceTest method testCreateButEnvInDeleteInProgressPhase.

@ParameterizedTest
@MethodSource("deleteInProgressParamProvider")
void testCreateButEnvInDeleteInProgressPhase(EnvironmentStatus environmentStatus) {
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(null, MEDIUM_DUTY_HA);
    DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
    detailedEnvironmentResponse.setName(sdxClusterRequest.getEnvironment());
    detailedEnvironmentResponse.setCloudPlatform(CloudPlatform.AWS.name());
    detailedEnvironmentResponse.setCrn(getCrn());
    detailedEnvironmentResponse.setEnvironmentStatus(environmentStatus);
    when(environmentClientService.getByName(anyString())).thenReturn(detailedEnvironmentResponse);
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null)), "BadRequestException should thrown");
    assertEquals("The environment is in delete in progress phase. Please create a new environment first!", badRequestException.getMessage());
}
Also used : SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 15 with SdxClusterRequest

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

the class CloudStorageManifesterTest method whenCloudStorageAndLoggingDisabled.

@Test
public void whenCloudStorageAndLoggingDisabled() {
    ClusterV4Request clusterV4Request = new ClusterV4Request();
    clusterV4Request.setBlueprintName(exampleBlueprintName);
    CloudStorageRequest cloudStorageConfigReq = underTest.initCloudStorageRequest(new DetailedEnvironmentResponse(), clusterV4Request, null, new SdxClusterRequest());
    assertNull(cloudStorageConfigReq);
}
Also used : ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) SdxCloudStorageRequest(com.sequenceiq.sdx.api.model.SdxCloudStorageRequest) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) 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