Search in sources :

Example 46 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException 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 47 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException 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 48 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException 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)

Example 49 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class StackCommonServiceTest method testThrowsExceptionWhenDeleteInstanceFromDataLake.

@Test
public void testThrowsExceptionWhenDeleteInstanceFromDataLake() {
    Stack stack = new Stack();
    stack.setType(StackType.DATALAKE);
    when(stackService.findStackByNameOrCrnAndWorkspaceId(STACK_NAME, WORKSPACE_ID)).thenReturn(Optional.of(stack));
    BadRequestException exception = assertThrows(BadRequestException.class, () -> underTest.deleteInstanceInWorkspace(STACK_NAME, WORKSPACE_ID, "node1", true));
    assertEquals("node1 is a node of a data lake cluster, therefore it's not allowed to delete/stop it.", exception.getMessage());
    verifyNoInteractions(stackOperationService);
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 50 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class BlueprintServiceTest method testDeletionWithTerminatedClustersNonTerminatedStacks.

@Test
public void testDeletionWithTerminatedClustersNonTerminatedStacks() {
    Blueprint blueprint = getBlueprint("name", USER_MANAGED);
    Set<Cluster> clusters = new HashSet<>();
    clusters.add(getCluster("c1", 1L, blueprint, DetailedStackStatus.PRE_DELETE_IN_PROGRESS));
    clusters.add(getCluster("c2", 1L, blueprint, DetailedStackStatus.DELETE_IN_PROGRESS));
    clusters.add(getCluster("c3", 1L, blueprint, DetailedStackStatus.DELETE_COMPLETED));
    ClusterTemplateView clusterTemplateView = new ClusterTemplateView();
    clusterTemplateView.setName("ClusterDefinition");
    when(clusterTemplateViewService.findAllByStackIds(any())).thenReturn(Set.of(clusterTemplateView));
    when(clusterService.findByBlueprint(any())).thenReturn(clusters);
    BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.delete(blueprint));
    assertEquals("There is a cluster ['ClusterDefinition'] which uses cluster template 'name'. " + "Please remove this cluster before deleting the cluster template.", exception.getMessage());
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)298 Test (org.junit.jupiter.api.Test)134 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)34 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)26 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)22 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)21 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)21 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 Stack (com.sequenceiq.freeipa.entity.Stack)18 BaseDiagnosticsCollectionRequest (com.sequenceiq.common.api.diagnostics.BaseDiagnosticsCollectionRequest)14 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)14 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)14 Set (java.util.Set)14 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)13 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)12 Json (com.sequenceiq.cloudbreak.common.json.Json)12 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)12