Search in sources :

Example 1 with SdxClusterRequest

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

the class TagsUtilTest method addTestNameTagShouldAddTagToAbstractTestDtoWithTaggableRequest.

@Test
void addTestNameTagShouldAddTagToAbstractTestDtoWithTaggableRequest() {
    SdxTestDto testDto = new SdxTestDto(mock(TestContext.class));
    SdxClusterRequest request = new SdxClusterRequest();
    testDto.setRequest(request);
    when(testContext.getCloudPlatform()).thenReturn(CloudPlatform.MOCK);
    underTest.addTestNameTag(testContext.getCloudPlatform(), testDto, TEST_NAME);
    assertThat(request.getTags().get(TagsUtil.TEST_NAME_TAG)).isEqualTo(TEST_NAME);
}
Also used : SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) Test(org.testng.annotations.Test)

Example 2 with SdxClusterRequest

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

the class SdxServiceTest method testCreateSdxClusterWhenClusterWithSpecifiedNameAlreadyExistShouldThrowClusterAlreadyExistBadRequestException.

@Test
void testCreateSdxClusterWhenClusterWithSpecifiedNameAlreadyExistShouldThrowClusterAlreadyExistBadRequestException() {
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(null, MEDIUM_DUTY_HA);
    SdxCluster existing = new SdxCluster();
    existing.setEnvName("envir");
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(Collections.singletonList(existing));
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null)));
    assertEquals("SDX cluster exists for environment name: envir", badRequestException.getMessage());
}
Also used : SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with SdxClusterRequest

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

the class SdxServiceTest method testSdxCreateMediumDutySdx720Runtime.

@Test
void testSdxCreateMediumDutySdx720Runtime() {
    final String invalidRuntime = "7.2.0";
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(invalidRuntime, MEDIUM_DUTY_HA);
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.AWS, null);
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null)));
    assertEquals("Provisioning a Medium Duty SDX shape is only valid for CM version greater than or equal to " + MEDIUM_DUTY_REQUIRED_VERSION + " and not " + invalidRuntime, badRequestException.getMessage());
}
Also used : SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 4 with SdxClusterRequest

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

the class SdxServiceTest method testCreateNOTInternalSdxClusterFromLightDutyTemplateWhenLocationSpecifiedWithSlashShouldCreateAndSettedUpBaseLocationWithOUTSlash.

@Test
void testCreateNOTInternalSdxClusterFromLightDutyTemplateWhenLocationSpecifiedWithSlashShouldCreateAndSettedUpBaseLocationWithOUTSlash() 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);
    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 5 with SdxClusterRequest

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

the class SdxServiceTest method testCcmV2JumpgateVersionChecker.

@ParameterizedTest(name = "Runtime {0} is compatible with CCMv2JumpGate = {1}")
@MethodSource("ccmV2JumpgateScenarios")
void testCcmV2JumpgateVersionChecker(String runtime, boolean compatible) throws IOException {
    SdxClusterRequest sdxClusterRequest = createSdxClusterRequest(runtime, LIGHT_DUTY);
    when(sdxClusterRepository.findByAccountIdAndEnvNameAndDeletedIsNullAndDetachedIsFalse(anyString(), anyString())).thenReturn(new ArrayList<>());
    String lightDutyJson = FileReaderUtils.readFileFromClasspath("/duties/7.2.10/aws/light_duty.json");
    lenient().when(cdpConfigService.getConfigForKey(any())).thenReturn(JsonUtil.readValue(lightDutyJson, StackV4Request.class));
    mockEnvironmentCall(sdxClusterRequest, CloudPlatform.MOCK, Tunnel.CCMV2_JUMPGATE);
    if (!compatible) {
        assertThatThrownBy(() -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null))).isInstanceOf(BadRequestException.class).hasMessage(String.format("Runtime version %s does not support Cluster Connectivity Manager. " + "Please try creating a datalake with runtime version at least %s.", runtime, CCMV2_JUMPGATE_REQUIRED_VERSION));
    } else {
        ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.createSdx(USER_CRN, CLUSTER_NAME, sdxClusterRequest, null));
    }
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

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