Search in sources :

Example 11 with StackV4Request

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

the class StackV4RequestToStackConverterTest method testNoEndpointGatewayLoadBalancerWhenEntitlementIsDisabled.

@Test
public void testNoEndpointGatewayLoadBalancerWhenEntitlementIsDisabled() {
    StackV4Request request = setupForEndpointGateway(true);
    // WHEN
    Stack stack = underTest.convert(request);
    // THEN
    assertTrue(stack.getLoadBalancers().isEmpty());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest) Test(org.junit.jupiter.api.Test)

Example 12 with StackV4Request

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

the class StackCreatorServiceRecipeValidationTest method testIfMultipleRecipesDoesNotExistsWhichHasGivenInOneOfTheHostgroupsThenBadRequestExceptionShouldCome.

@Test
void testIfMultipleRecipesDoesNotExistsWhichHasGivenInOneOfTheHostgroupsThenBadRequestExceptionShouldCome() {
    String notExistingRecipeName = "someNotExistingRecipe";
    String someOtherNotExistingRecipeName = "someOtherNotExistingRecipe";
    StackV4Request request = new StackV4Request();
    request.setInstanceGroups(List.of(getInstanceGroupWithRecipe(INSTANCE_GROUP_MASTER, Set.of(notExistingRecipeName, someOtherNotExistingRecipeName))));
    when(recipeService.get(any(NameOrCrn.class), eq(WORKSPACE_ID))).thenThrow(new NotFoundException("Recipe not found"));
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.createStack(user, workspace, request, false));
    Assert.assertNotNull(exception);
    Assertions.assertTrue(exception.getMessage().matches(String.format("The given recipes does not exists for the instance group \"%s\": (\\w+), (\\w+)", INSTANCE_GROUP_MASTER)));
    verify(recipeService, times(2)).get(any(NameOrCrn.class), anyLong());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) Test(org.junit.jupiter.api.Test)

Example 13 with StackV4Request

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

the class StackCreatorServiceRecipeValidationTest method testIfOneOfTheRecipeDoesNotExistsInOneInstanceGroupWhenOtherInstanceGroupHaveAnExistingRecipeThenBadRequestComesForThatInstanceGroup.

@Test
void testIfOneOfTheRecipeDoesNotExistsInOneInstanceGroupWhenOtherInstanceGroupHaveAnExistingRecipeThenBadRequestComesForThatInstanceGroup() {
    String existingRecipe = "someExistingRecipe";
    String someOtherExistingRecipe = "someOtherExistingRecipe";
    String notExistingRecipe = "thisOneDoesNotExists";
    StackV4Request request = new StackV4Request();
    request.setInstanceGroups(List.of(getInstanceGroupWithRecipe(INSTANCE_GROUP_MASTER, Set.of(existingRecipe)), getInstanceGroupWithRecipe(INSTANCE_GROUP_COMPUTE, Set.of(someOtherExistingRecipe, notExistingRecipe))));
    doAnswer(withNotFoundExceptionIfRecipeNameMatchesOtherwiseGiveRecipe(notExistingRecipe)).when(recipeService).get(any(NameOrCrn.class), eq(WORKSPACE_ID));
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.createStack(user, workspace, request, false));
    Assert.assertNotNull(exception);
    Assertions.assertEquals(String.format("The given recipe does not exist for the instance group \"%s\": %s", INSTANCE_GROUP_COMPUTE, notExistingRecipe), exception.getMessage());
    verify(recipeService, times(3)).get(any(NameOrCrn.class), anyLong());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) Test(org.junit.jupiter.api.Test)

Example 14 with StackV4Request

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

the class StackCreatorServiceRecipeValidationTest method testIfOneRecipeDoesNotExistsWhichIsGivenInOneOfTheHostgroupsThenBadRequestExceptionShouldCome.

@Test
void testIfOneRecipeDoesNotExistsWhichIsGivenInOneOfTheHostgroupsThenBadRequestExceptionShouldCome() {
    String notExistingRecipeName = "someNotExistingRecipe";
    StackV4Request request = new StackV4Request();
    request.setInstanceGroups(List.of(getInstanceGroupWithRecipe(INSTANCE_GROUP_MASTER, Set.of(notExistingRecipeName))));
    when(recipeService.get(any(NameOrCrn.class), eq(WORKSPACE_ID))).thenThrow(new NotFoundException("Recipe not found"));
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.createStack(user, workspace, request, false));
    Assert.assertNotNull(exception);
    Assertions.assertEquals(String.format("The given recipe does not exist for the instance group \"%s\": %s", INSTANCE_GROUP_MASTER, notExistingRecipeName), exception.getMessage());
    verify(recipeService, times(1)).get(any(NameOrCrn.class), anyLong());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) Test(org.junit.jupiter.api.Test)

Example 15 with StackV4Request

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

the class StackCreatorServiceTest method shouldThrowBadRequestWhenRecipeIsMissing.

@Test
public void shouldThrowBadRequestWhenRecipeIsMissing() {
    User user = new User();
    Workspace workspace = new Workspace();
    workspace.setId(WORKSPACE_ID);
    StackV4Request stackRequest = new StackV4Request();
    InstanceGroupV4Request instanceGroupV4Request = new InstanceGroupV4Request();
    instanceGroupV4Request.setName(INSTANCE_GROUP);
    instanceGroupV4Request.setRecipeNames(Set.of(RECIPE_NAME));
    stackRequest.setInstanceGroups(List.of(instanceGroupV4Request));
    doNothing().when(nodeCountLimitValidator).validateProvision(any());
    doThrow(new NotFoundException("missing recipe")).when(recipeService).get(NameOrCrn.ofName(RECIPE_NAME), WORKSPACE_ID);
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.createStack(user, workspace, stackRequest, false));
    assertThat(badRequestException).hasMessage("The given recipe does not exist for the instance group \"INSTANCE_GROUP\": RECIPE_NAME");
}
Also used : User(com.sequenceiq.cloudbreak.workspace.model.User) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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