Search in sources :

Example 51 with NotFoundException

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

the class ProgressService method getLastFlowProgressByResourceCrn.

public SdxProgressResponse getLastFlowProgressByResourceCrn(String resourceCrn) {
    SdxProgressResponse response = new SdxProgressResponse();
    response.setLastFlowOperation(flowService.getLastFlowProgressByResourceCrn(resourceCrn));
    try {
        response.setLastInternalFlowOperation(progressV4Endpoint.getLastFlowLogProgressByResourceCrn(resourceCrn));
    } catch (NotFoundException notFoundException) {
        LOGGER.debug("Stack for datalake '{}' has not found yet. It is acceptable for progress response.", resourceCrn);
    }
    return response;
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxProgressResponse(com.sequenceiq.sdx.api.model.SdxProgressResponse)

Example 52 with NotFoundException

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

the class UserPreferencesService method getUserPreferences.

private UserPreferences getUserPreferences(String userCrn) {
    UserPreferences userPreferences;
    Optional<UserPreferences> userPreferencesOptional;
    LOGGER.debug("User preferences does not exist, creating it with crn '{}'", userCrn);
    userPreferences = new UserPreferences(generateExternalId(), generateExternalId(), userCrn);
    try {
        userPreferences = userPreferencesRepository.save(userPreferences);
    } catch (AccessDeniedException | DataIntegrityViolationException e) {
        LOGGER.debug("User exists with crn: '{}'", userCrn, e);
        userPreferencesOptional = userPreferencesRepository.findByUserCrn(userCrn);
        userPreferences = userPreferencesOptional.orElseThrow(() -> new NotFoundException("User does not exists with crn. If you see this error, " + "you've caught something big, because Duplicate exception occurred"));
    }
    return userPreferences;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 53 with NotFoundException

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

the class ClusterServiceRunnerTest method testRedeployGatewayCertificateWhenClusterCouldNotBeFoundByStackId.

@Test
void testRedeployGatewayCertificateWhenClusterCouldNotBeFoundByStackId() {
    when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack);
    when(stack.getCluster()).thenReturn(cluster);
    when(clusterService.findOneWithLists(anyLong())).thenThrow(new NotFoundException("Cluster could not be found"));
    Assertions.assertThrows(NotFoundException.class, () -> underTest.redeployGatewayCertificate(0L));
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 54 with NotFoundException

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

the class StructuredSynchronizerJobTest method testUnscheduleJobWhenStackServiceThrowsNotFoundException.

@Test
public void testUnscheduleJobWhenStackServiceThrowsNotFoundException() throws JobExecutionException {
    when(stackService.get(anyLong())).thenThrow(new NotFoundException("Stack not found"));
    underTest.executeTracedJob(jobExecutionContext);
    verify(syncJobService, times(1)).unschedule("1");
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 55 with NotFoundException

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

the class EnvironmentLoadBalancerService method updateLoadBalancerInEnvironmentAndStacks.

public FlowIdentifier updateLoadBalancerInEnvironmentAndStacks(EnvironmentDto environmentDto, EnvironmentLoadBalancerDto environmentLbDto) {
    requireNonNull(environmentDto);
    requireNonNull(environmentLbDto);
    loadBalancerEntitlementService.validateNetworkForEndpointGateway(environmentDto.getCloudPlatform(), environmentDto.getName(), environmentLbDto.getEndpointAccessGateway());
    if (!isLoadBalancerEnabledForDatalake(ThreadBasedUserCrnProvider.getAccountId(), environmentDto.getCloudPlatform(), environmentLbDto.getEndpointAccessGateway())) {
        throw new BadRequestException("Neither Endpoint Gateway nor Data Lake load balancer is enabled. Nothing to do.");
    }
    LOGGER.debug("Trying to find environment based on name {}, CRN {}", environmentDto.getName(), environmentDto.getResourceCrn());
    String accountId = Crn.safeFromString(environmentDto.getResourceCrn()).getAccountId();
    Environment environment = environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(environmentDto.getResourceCrn(), accountId).orElseThrow(() -> new NotFoundException(String.format("Could not find environment '%s' using crn '%s'", environmentDto.getName(), environmentDto.getResourceCrn())));
    String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
    return reactorFlowManager.triggerLoadBalancerUpdateFlow(environmentDto, environment.getId(), environment.getName(), environment.getResourceCrn(), environmentLbDto.getEndpointAccessGateway(), environmentLbDto.getEndpointGatewaySubnetIds(), userCrn);
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Environment(com.sequenceiq.environment.environment.domain.Environment) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

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