Search in sources :

Example 16 with DistroXV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request in project cloudbreak by hortonworks.

the class DistroXV1RequestToStackV4RequestConverterTest method convert.

@Test
void convert() {
    when(environmentClientService.getByName(anyString())).thenReturn(createAwsEnvironment());
    when(networkConverter.convertToNetworkV4Request(any())).thenReturn(createAwsNetworkV4Request());
    when(databaseRequestConverter.convert(any(DistroXDatabaseRequest.class))).thenReturn(createDatabaseRequest());
    DistroXV1Request source = new DistroXV1Request();
    source.setEnvironmentName("envname");
    DistroXDatabaseRequest databaseRequest = new DistroXDatabaseRequest();
    databaseRequest.setAvailabilityType(DistroXDatabaseAvailabilityType.HA);
    databaseRequest.setDatabaseEngineVersion("13");
    source.setExternalDatabase(databaseRequest);
    StackV4Request convert = underTest.convert(source);
    assertThat(convert.getExternalDatabase()).isNotNull();
    assertThat(convert.getExternalDatabase().getAvailabilityType()).isEqualTo(DatabaseAvailabilityType.HA);
    assertThat(convert.getExternalDatabase().getDatabaseEngineVersion()).isEqualTo("13");
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DistroXDatabaseRequest(com.sequenceiq.distrox.api.v1.distrox.model.database.DistroXDatabaseRequest) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with DistroXV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request in project cloudbreak by hortonworks.

the class DistroXServiceTest method testWithInvalidEnvironmentNameValue.

@Test
@DisplayName("When request doesn't contains a valid environment name then BadRequestException should come")
void testWithInvalidEnvironmentNameValue() {
    String invalidEnvNameValue = "somethingInvalidStuff";
    DistroXV1Request r = new DistroXV1Request();
    r.setEnvironmentName(invalidEnvNameValue);
    when(environmentClientService.getByName(invalidEnvNameValue)).thenReturn(null);
    BadRequestException err = assertThrows(BadRequestException.class, () -> underTest.post(r));
    assertEquals("No environment name provided hence unable to obtain some important data", err.getMessage());
    verify(environmentClientService, calledOnce()).getByName(any());
    verify(environmentClientService, calledOnce()).getByName(invalidEnvNameValue);
    verify(stackOperations, never()).post(any(), any(), any(), anyBoolean());
    verify(workspaceService, never()).getForCurrentUser();
    verify(stackRequestConverter, never()).convert(any(DistroXV1Request.class));
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 18 with DistroXV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request in project cloudbreak by hortonworks.

the class DistroXServiceTest method testWithValidEnvironmentNameValueButTheActualEnvIsNotAvailableBadRequestExceptionShouldCome.

@ParameterizedTest
@EnumSource(value = com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus.class)
@DisplayName("When request contains a valid environment name but that environment is not in the AVAILABLE state then BadRequestException should come")
void testWithValidEnvironmentNameValueButTheActualEnvIsNotAvailableBadRequestExceptionShouldCome(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus detailedStackStatus) {
    if (!detailedStackStatus.getAvailabilityStatus().isAvailable()) {
        String envName = "someAwesomeExistingButNotAvailableEnvironment";
        DistroXV1Request r = new DistroXV1Request();
        r.setEnvironmentName(envName);
        DetailedEnvironmentResponse envResponse = new DetailedEnvironmentResponse();
        envResponse.setCrn("crn");
        envResponse.setName(envName);
        DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
        freeipa.setAvailabilityStatus(detailedStackStatus.getAvailabilityStatus());
        freeipa.setStatus(detailedStackStatus.getStatus());
        when(freeipaClientService.getByEnvironmentCrn("crn")).thenReturn(freeipa);
        when(environmentClientService.getByName(envName)).thenReturn(envResponse);
        BadRequestException err = assertThrows(BadRequestException.class, () -> underTest.post(r));
        assertEquals(String.format("If you want to provision a Data Hub then the FreeIPA instance must be running in the '%s' Environment.", envName), err.getMessage());
        verify(environmentClientService, calledOnce()).getByName(any());
        verify(environmentClientService, calledOnce()).getByName(eq(envName));
        verify(stackOperations, never()).post(any(), any(), any(), anyBoolean());
        verify(workspaceService, never()).getForCurrentUser();
        verify(stackRequestConverter, never()).convert(any(DistroXV1Request.class));
    }
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 19 with DistroXV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request in project cloudbreak by hortonworks.

the class DistroXServiceTest method testIfDlIsRunning.

@Test
public void testIfDlIsRunning() {
    String envName = "someAwesomeEnvironment";
    DistroXV1Request request = new DistroXV1Request();
    request.setEnvironmentName(envName);
    DetailedEnvironmentResponse envResponse = new DetailedEnvironmentResponse();
    envResponse.setEnvironmentStatus(AVAILABLE);
    envResponse.setCrn("crn");
    DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
    freeipa.setAvailabilityStatus(AvailabilityStatus.AVAILABLE);
    freeipa.setStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status.AVAILABLE);
    when(freeipaClientService.getByEnvironmentCrn("crn")).thenReturn(freeipa);
    when(environmentClientService.getByName(envName)).thenReturn(envResponse);
    when(platformAwareSdxConnector.listSdxCrns(any(), any())).thenReturn(Set.of(DATALAKE_CRN));
    when(platformAwareSdxConnector.listSdxCrnsWithAvailability(any(), any(), any())).thenReturn(Set.of(Pair.of(DATALAKE_CRN, StatusCheckResult.AVAILABLE)));
    underTest.post(request);
    verify(platformAwareSdxConnector).listSdxCrns(any(), any());
    verify(platformAwareSdxConnector).listSdxCrnsWithAvailability(any(), any(), any());
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with DistroXV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request in project cloudbreak by hortonworks.

the class DistroXServiceTest method testIfDlIsNotExists.

@Test
public void testIfDlIsNotExists() {
    String envName = "someAwesomeEnvironment";
    DistroXV1Request request = new DistroXV1Request();
    request.setEnvironmentName(envName);
    DetailedEnvironmentResponse envResponse = new DetailedEnvironmentResponse();
    envResponse.setEnvironmentStatus(AVAILABLE);
    envResponse.setCrn("crn");
    DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
    freeipa.setAvailabilityStatus(AvailabilityStatus.AVAILABLE);
    freeipa.setStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status.AVAILABLE);
    when(freeipaClientService.getByEnvironmentCrn("crn")).thenReturn(freeipa);
    when(environmentClientService.getByName(envName)).thenReturn(envResponse);
    when(platformAwareSdxConnector.listSdxCrns(any(), any())).thenReturn(Set.of());
    assertThrows(BadRequestException.class, () -> underTest.post(request));
    verify(platformAwareSdxConnector).listSdxCrns(any(), any());
    verifyNoMoreInteractions(platformAwareSdxConnector);
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DistroXV1Request (com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request)21 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)12 Test (org.junit.jupiter.api.Test)12 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)8 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)7 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)4 DistroXDatabaseRequest (com.sequenceiq.distrox.api.v1.distrox.model.database.DistroXDatabaseRequest)4 InstanceGroupV1Request (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request)3 DisplayName (org.junit.jupiter.api.DisplayName)3 DatabaseRequest (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseRequest)2 TagsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request)2 EnvironmentClientService (com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService)2 NullUtil.getIfNotNull (com.sequenceiq.cloudbreak.util.NullUtil.getIfNotNull)2 DistroXClusterV1Request (com.sequenceiq.distrox.api.v1.distrox.model.cluster.DistroXClusterV1Request)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Inject (javax.inject.Inject)2 DefaultClusterTemplateV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.requests.DefaultClusterTemplateV4Request)1 ClusterTemplateViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateViewV4Response)1