Search in sources :

Example 41 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class DistroXV1RequestToStackV4RequestConverterTest method convertAvailabilityZoneComesFromEnv.

@Test
void convertAvailabilityZoneComesFromEnv() {
    DistroXV1Request source = new DistroXV1Request();
    source.setEnvironmentName("envname");
    DistroXDatabaseRequest databaseRequest = new DistroXDatabaseRequest();
    databaseRequest.setAvailabilityType(DistroXDatabaseAvailabilityType.HA);
    source.setExternalDatabase(databaseRequest);
    DetailedEnvironmentResponse env = createAwsEnvironment();
    env.getNetwork().setSubnetMetas(Map.of("SubnetMeta", createCloudSubnet()));
    when(environmentClientService.getByName(source.getEnvironmentName())).thenReturn(env);
    when(networkConverter.convertToNetworkV4Request(any())).thenReturn(createAwsNetworkV4Request());
    when(databaseRequestConverter.convert(any(DistroXDatabaseRequest.class))).thenReturn(createDatabaseRequest());
    StackV4Request convert = underTest.convert(source);
    assertThat(convert.getExternalDatabase()).isNotNull();
    assertThat(convert.getExternalDatabase().getAvailabilityType()).isEqualTo(DatabaseAvailabilityType.HA);
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DistroXDatabaseRequest(com.sequenceiq.distrox.api.v1.distrox.model.database.DistroXDatabaseRequest) 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 42 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class DistroXV1RequestToStackV4RequestConverterTest method convertStackRequest.

@Test
void convertStackRequest() {
    when(databaseRequestConverter.convert(any(DatabaseRequest.class))).thenReturn(createDistroXDatabaseRequest());
    StackV4Request source = new StackV4Request();
    source.setName("stackname");
    DatabaseRequest databaseRequest = new DatabaseRequest();
    databaseRequest.setAvailabilityType(DatabaseAvailabilityType.HA);
    source.setExternalDatabase(databaseRequest);
    DistroXV1Request convert = underTest.convert(source);
    assertThat(convert.getExternalDatabase()).isNotNull();
    assertThat(convert.getExternalDatabase().getAvailabilityType()).isEqualTo(DistroXDatabaseAvailabilityType.HA);
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DatabaseRequest(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseRequest) 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 43 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class DistroXV1RequestToStackV4RequestConverterTest method testStackV4RequestToDistroXV1RequestWhenEnvironmentCrnIsNullThenNoCallHappensTowardsTheEnvironmentClientServiceAndNoEnvNameSetHappens.

@Test
void testStackV4RequestToDistroXV1RequestWhenEnvironmentCrnIsNullThenNoCallHappensTowardsTheEnvironmentClientServiceAndNoEnvNameSetHappens() {
    StackV4Request source = new StackV4Request();
    source.setName("SomeStack");
    source.setEnvironmentCrn(null);
    DistroXV1Request result = assertDoesNotThrow(() -> underTest.convert(source));
    verify(environmentClientService, never()).getByCrn(any());
    Assertions.assertNull(result.getEnvironmentName());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 44 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class DistroXV1RequestToStackV4RequestConverterTest method testStackV4RequestToDistroXV1RequestRegardlessOfTheStateOfTheEnvironment.

@ParameterizedTest
@EnumSource(EnvironmentStatus.class)
void testStackV4RequestToDistroXV1RequestRegardlessOfTheStateOfTheEnvironment(EnvironmentStatus status) {
    StackV4Request source = new StackV4Request();
    source.setName("SomeStack");
    source.setEnvironmentCrn("SomeEnvCrn");
    DetailedEnvironmentResponse env = createAwsEnvironment();
    env.setCrn(source.getEnvironmentCrn());
    env.setEnvironmentStatus(status);
    when(environmentClientService.getByCrn(source.getEnvironmentCrn())).thenReturn(env);
    DistroXV1Request result = assertDoesNotThrow(() -> underTest.convert(source));
    verify(environmentClientService, times(1)).getByCrn(any());
    verify(environmentClientService, times(1)).getByCrn(source.getEnvironmentCrn());
    Assertions.assertEquals(env.getName(), result.getEnvironmentName());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 45 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class StackOperations method post.

public StackV4Response post(Long workspaceId, CloudbreakUser cloudbreakUser, @Valid StackV4Request request, boolean distroxRequest) {
    LOGGER.info("Post for Stack in workspace {}.", workspaceId);
    User user = userService.getOrCreate(cloudbreakUser);
    LOGGER.info("Cloudbreak user for the requested stack is {}.", cloudbreakUser);
    Workspace workspace = workspaceService.get(workspaceId, user);
    StackV4Response stackV4Response = stackCommonService.createInWorkspace(request, user, workspace, distroxRequest);
    LOGGER.info("Adding environment name and credential to the response.");
    environmentServiceDecorator.prepareEnvironmentAndCredentialName(stackV4Response);
    LOGGER.info("Adding SDX CRN and name to the response.");
    sdxServiceDecorator.prepareSdxAttributes(stackV4Response);
    return stackV4Response;
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace)

Aggregations

StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)105 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)66 Test (org.junit.jupiter.api.Test)58 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)52 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)36 Test (org.junit.Test)36 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)34 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)33 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)32 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)31 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)17 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)14 Map (java.util.Map)13 Set (java.util.Set)13 Optional (java.util.Optional)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)11 HashMap (java.util.HashMap)11 List (java.util.List)11