Search in sources :

Example 11 with NotFoundException

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

the class EnvironmentLoadBalancerServiceTest method testNoEnvironmentFound.

@Test
public void testNoEnvironmentFound() {
    EnvironmentLoadBalancerDto environmentLbDto = EnvironmentLoadBalancerDto.builder().withEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED).build();
    EnvironmentDto environmentDto = EnvironmentDto.builder().withName(ENV_NAME).withResourceCrn(ENV_CRN).build();
    String expectedError = String.format("Could not find environment '%s' using crn '%s'", ENV_NAME, ENV_CRN);
    when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(anyString(), anyString())).thenReturn(Optional.empty());
    doNothing().when(loadBalancerEntitlementService).validateNetworkForEndpointGateway(any(), any(), any());
    final NotFoundException[] exception = new NotFoundException[1];
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        exception[0] = assertThrows(NotFoundException.class, () -> underTest.updateLoadBalancerInEnvironmentAndStacks(environmentDto, environmentLbDto));
    });
    assertEquals(expectedError, exception[0].getMessage());
}
Also used : EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 12 with NotFoundException

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

the class ChangePrimaryGatewayService method selectNewPrimaryGatewayInstanceId.

public String selectNewPrimaryGatewayInstanceId(Stack stack, List<String> repairInstanceIds) {
    String newPrimaryGatewayInstanceId;
    try {
        GatewayConfig currentPrimaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
        Optional<String> freeIpaMasterInstanceId = findFreeIpaMasterInstanceId(stack, currentPrimaryGatewayConfig);
        if (freeIpaMasterInstanceId.isPresent() && !repairInstanceIds.contains(freeIpaMasterInstanceId.get())) {
            LOGGER.debug("Using the FreeIPA master as the new primary gateway");
            newPrimaryGatewayInstanceId = freeIpaMasterInstanceId.get();
        } else {
            newPrimaryGatewayInstanceId = currentPrimaryGatewayConfig.getInstanceId();
            if (repairInstanceIds.contains(newPrimaryGatewayInstanceId)) {
                LOGGER.debug("The current primary gateway is on the list of to avoid, searching for a different primary gateway");
                newPrimaryGatewayInstanceId = assignNewPrimaryGatewayInstanceId(stack, repairInstanceIds);
            }
        }
    } catch (NotFoundException | CloudbreakOrchestratorException e) {
        LOGGER.debug("No primary gateway found, searching for a different primary gateway");
        newPrimaryGatewayInstanceId = assignNewPrimaryGatewayInstanceId(stack, repairInstanceIds);
    }
    LOGGER.debug("The new primary gateway will be {}", newPrimaryGatewayInstanceId);
    return newPrimaryGatewayInstanceId;
}
Also used : CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 13 with NotFoundException

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

the class StackImageServiceTest method testChangeImageCatalogOutOfFlowThrowsNotFoundExceptionInCaseOfMissingTargetCatalog.

@Test
public void testChangeImageCatalogOutOfFlowThrowsNotFoundExceptionInCaseOfMissingTargetCatalog() throws CloudbreakImageNotFoundException {
    when(componentConfigProviderService.getImage(stack.getId())).thenReturn(anImageComponent());
    when(imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), TARGET_IMAGE_CATALOG)).thenThrow(new NotFoundException(""));
    assertThrows(NotFoundException.class, () -> victim.changeImageCatalog(stack, TARGET_IMAGE_CATALOG));
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Test(org.junit.jupiter.api.Test)

Example 14 with NotFoundException

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

the class ClusterUpgradeAvailabilityServiceTest method testCheckForUpgradesByNameShouldReturnImagesFromFallbackCatalogWhenThereAreAvailableImagesButImageCatalogByNameNotFound.

@Test
public void testCheckForUpgradesByNameShouldReturnImagesFromFallbackCatalogWhenThereAreAvailableImagesButImageCatalogByNameNotFound() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    Stack stack = createStack(createStackStatus(Status.AVAILABLE), StackType.WORKLOAD);
    com.sequenceiq.cloudbreak.cloud.model.Image currentImage = createCurrentImage();
    Result result = Mockito.mock(Result.class);
    Image currentImageFromCatalog = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
    Image properImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
    Image otherImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
    CloudbreakImageCatalogV3 imageCatalog = createImageCatalog(List.of(properImage, otherImage, currentImageFromCatalog));
    ImageFilterParams imageFilterParams = createImageFilterParams(stack, currentImageFromCatalog);
    UpgradeV4Response response = new UpgradeV4Response();
    when(imageFilterParamsFactory.create(currentImageFromCatalog, lockComponents, stack, INTERNAL_UPGRADE_SETTINGS)).thenReturn(imageFilterParams);
    when(clusterRepairService.repairWithDryRun(stack.getId())).thenReturn(result);
    when(result.isError()).thenReturn(false);
    when(imageService.getImage(stack.getId())).thenReturn(currentImage);
    when(imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), CATALOG_NAME)).thenThrow(new NotFoundException("not found"));
    when(imageCatalogProvider.getImageCatalogV3(FALLBACK_CATALOG_URL)).thenReturn(imageCatalog);
    ImageFilterResult filteredImages = createFilteredImages(properImage);
    when(clusterUpgradeImageFilter.filter(ACCOUNT_ID, imageCatalog, imageFilterParams)).thenReturn(filteredImages);
    when(upgradeOptionsResponseFactory.createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName())).thenReturn(response);
    when(imageProvider.getCurrentImageFromCatalog(CURRENT_IMAGE_ID, imageCatalog)).thenReturn(currentImageFromCatalog);
    when(instanceMetaDataService.anyInstanceStopped(stack.getId())).thenReturn(false);
    UpgradeV4Response actual = underTest.checkForUpgradesByName(stack, lockComponents, true, INTERNAL_UPGRADE_SETTINGS);
    assertEquals(response, actual);
    verify(imageService).getImage(stack.getId());
    verify(imageCatalogProvider).getImageCatalogV3(FALLBACK_CATALOG_URL);
    verify(clusterUpgradeImageFilter).filter(ACCOUNT_ID, imageCatalog, imageFilterParams);
    verify(upgradeOptionsResponseFactory).createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName());
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Result(com.sequenceiq.cloudbreak.service.cluster.model.Result) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Test(org.junit.Test)

Example 15 with NotFoundException

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

the class ImageCatalogServiceTest method testGetImagesWhenCustomImageCatalogDoesNotExists.

@Test
public void testGetImagesWhenCustomImageCatalogDoesNotExists() throws Exception {
    when(imageCatalogRepository.findByNameAndWorkspaceId(anyString(), anyLong())).thenThrow(new NotFoundException("no no"));
    thrown.expectMessage("The verycool catalog does not exist or does not belongs to your account.");
    thrown.expect(CloudbreakImageCatalogException.class);
    underTest.getImages(ORG_ID, "verycool", imageCatalogPlatform("aws")).getImages();
    verify(entitlementService, times(1)).baseImageEnabled(Objects.requireNonNull(Crn.fromString(user.getUserCrn())).getAccountId());
    verify(entitlementService, never()).baseImageEnabled(user.getUserCrn());
    verify(imageCatalogProvider, times(0)).getImageCatalogV3("");
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Test(org.junit.Test)

Aggregations

NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)73 Test (org.junit.jupiter.api.Test)33 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)11 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)9 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)8 Map (java.util.Map)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)6 List (java.util.List)6 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)5 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)5 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)5 Optional (java.util.Optional)5 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)4 Set (java.util.Set)4 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)3 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)3