Search in sources :

Example 56 with NotFoundException

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

the class StackCreatorServiceRecipeValidationTest method testIfRecipeExistsThenEverythingShouldBeFine.

@Test
void testIfRecipeExistsThenEverythingShouldBeFine() throws TransactionExecutionException {
    String existingRecipeName = "existingRecipe";
    StackV4Request request = new StackV4Request();
    request.setName("stack_name");
    request.setInstanceGroups(List.of(getInstanceGroupWithRecipe(INSTANCE_GROUP_MASTER, Set.of(existingRecipeName))));
    when(recipeService.get(any(NameOrCrn.class), eq(WORKSPACE_ID))).thenReturn(getRecipeWithName(existingRecipeName));
    when(stackV4RequestToStackConverter.convert(request)).thenReturn(TestUtil.stack());
    when(transactionService.required(any(Supplier.class))).thenReturn(TestUtil.stack());
    when(stackService.getIdByNameInWorkspace(anyString(), any(Long.class))).thenThrow(new NotFoundException("stack not found by name"));
    underTest.createStack(user, workspace, request, false);
    verify(recipeService, times(1)).get(any(NameOrCrn.class), anyLong());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Supplier(java.util.function.Supplier) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) Test(org.junit.jupiter.api.Test)

Example 57 with NotFoundException

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

the class StackCreatorServiceRecipeValidationTest method voidTestIfRecipeDoesNotExistInInstanceGroupV4RequestThenEverythingShouldGoFine.

@Test
void voidTestIfRecipeDoesNotExistInInstanceGroupV4RequestThenEverythingShouldGoFine() throws TransactionExecutionException {
    StackV4Request request = new StackV4Request();
    request.setName("stack_name");
    request.setInstanceGroups(List.of(getInstanceGroupWithRecipe(INSTANCE_GROUP_MASTER, null), getInstanceGroupWithRecipe(INSTANCE_GROUP_COMPUTE, null)));
    when(stackV4RequestToStackConverter.convert(request)).thenReturn(TestUtil.stack());
    when(transactionService.required(any(Supplier.class))).thenReturn(TestUtil.stack());
    when(stackService.getIdByNameInWorkspace(anyString(), any(Long.class))).thenThrow(new NotFoundException("stack not found by name"));
    underTest.createStack(user, workspace, request, false);
    verify(recipeService, times(0)).get(any(NameOrCrn.class), anyLong());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Supplier(java.util.function.Supplier) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) Test(org.junit.jupiter.api.Test)

Example 58 with NotFoundException

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

the class ClusterHostServiceRunner method createKnoxRelatedGatewayCofniguration.

private Map<String, Object> createKnoxRelatedGatewayCofniguration(Cluster cluster, VirtualGroupRequest virtualGroupRequest, ClusterPreCreationApi connector) throws IOException {
    Gateway clusterGateway = cluster.getGateway();
    Map<String, Object> gateway = new HashMap<>();
    if (clusterGateway != null) {
        gateway.put("path", clusterGateway.getPath());
        gateway.put("ssotype", clusterGateway.getSsoType());
        gateway.put("ssoprovider", clusterGateway.getSsoProvider());
        gateway.put("signpub", clusterGateway.getSignPub());
        gateway.put("signcert", clusterGateway.getSignCert());
        gateway.put("signkey", clusterGateway.getSignKey());
        gateway.put("tokencert", clusterGateway.getTokenCert());
        gateway.put("mastersecret", clusterGateway.getKnoxMasterSecret());
        gateway.put("envAccessGroup", virtualGroupService.createOrGetVirtualGroup(virtualGroupRequest, UmsVirtualGroupRight.ENVIRONMENT_ACCESS));
        List<Map<String, Object>> topologies = getTopologies(clusterGateway, cluster.getBlueprint().getStackVersion());
        gateway.put("topologies", topologies);
        if (cluster.getBlueprint() != null) {
            Boolean autoTlsEnabled = cluster.getAutoTlsEnabled();
            Map<String, Integer> servicePorts = connector.getServicePorts(cluster.getBlueprint(), autoTlsEnabled);
            gateway.put("ports", servicePorts);
            gateway.put("protocol", autoTlsEnabled ? "https" : "http");
        }
        if (SSOType.SSO_PROVIDER_FROM_UMS.equals(clusterGateway.getSsoType())) {
            String accountId = ThreadBasedUserCrnProvider.getAccountId();
            try {
                String metadataXml = umsClient.getIdentityProviderMetadataXml(accountId, regionAwareInternalCrnGeneratorFactory);
                gateway.put("saml", metadataXml);
            } catch (Exception e) {
                LOGGER.debug("Could not get SAML metadata file to set up IdP in KNOXSSO.", e);
                throw new NotFoundException("Could not get SAML metadata file to set up IdP in KNOXSSO: " + e.getMessage());
            }
        }
    } else {
        gateway.put("ssotype", SSOType.NONE);
        LOGGER.debug("Cluster gateway (Knox) is not set. Configure ssotype to 'NONE' for backward compatibility.");
    }
    return gateway;
}
Also used : HashMap(java.util.HashMap) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Map(java.util.Map) ServiceLocationMap(com.sequenceiq.cloudbreak.cluster.model.ServiceLocationMap) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) IOException(java.io.IOException) NodesUnreachableException(com.sequenceiq.cloudbreak.util.NodesUnreachableException) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 59 with NotFoundException

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

the class StackImageService method changeImageCatalog.

public void changeImageCatalog(Stack stack, String imageCatalog) {
    try {
        Image currentImage = componentConfigProviderService.getImage(stack.getId());
        ImageCatalog targetImageCatalog = imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), imageCatalog);
        StatedImage targetImage = imageCatalogService.getImage(targetImageCatalog.getImageCatalogUrl(), targetImageCatalog.getName(), currentImage.getImageId());
        replaceStackImageComponent(stack, targetImage);
    } catch (IllegalArgumentException e) {
        LOGGER.error("Failed to change the image catalog.", e);
        throw new CloudbreakServiceException("Failed to change the image catalog.");
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.error(e.getMessage(), e);
        throw new NotFoundException(e.getMessage());
    } catch (CloudbreakImageCatalogException e) {
        LOGGER.error("Failed to replace stack image component", e);
        throw new CloudbreakServiceException(e.getMessage());
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)

Example 60 with NotFoundException

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

the class StackService method getByCrnInWorkspaceWithEntries.

public StackV4Response getByCrnInWorkspaceWithEntries(String crn, Long workspaceId, Set<String> entries, User user, StackType stackType) {
    try {
        return transactionService.required(() -> {
            Workspace workspace = workspaceService.get(workspaceId, user);
            ShowTerminatedClustersAfterConfig showTerminatedClustersAfterConfig = showTerminatedClusterConfigService.get();
            Optional<Stack> stack = findByCrnAndWorkspaceIdWithLists(crn, workspace.getId(), stackType, showTerminatedClustersAfterConfig);
            if (stack.isEmpty()) {
                throw new NotFoundException(format("Stack not found by crn '%s'", crn));
            }
            StackV4Response stackResponse = stackToStackV4ResponseConverter.convert(stack.get());
            stackResponse = stackResponseDecorator.decorate(stackResponse, stack.get(), entries);
            return stackResponse;
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : ShowTerminatedClustersAfterConfig(com.sequenceiq.cloudbreak.service.stack.ShowTerminatedClusterConfigService.ShowTerminatedClustersAfterConfig) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

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