Search in sources :

Example 1 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.controller.CloudbreakApiException in project cloudbreak by hortonworks.

the class ClusterToClusterResponseConverter method convertContainerConfig.

private void convertContainerConfig(Cluster source, ClusterResponse clusterResponse) {
    Json customContainerDefinition = source.getCustomContainerDefinition();
    if (customContainerDefinition != null && StringUtils.isNoneEmpty(customContainerDefinition.getValue())) {
        try {
            Map<String, String> map = customContainerDefinition.get(Map.class);
            Map<String, String> result = new HashMap<>();
            for (Entry<String, String> stringStringEntry : map.entrySet()) {
                result.put(stringStringEntry.getKey(), stringStringEntry.getValue());
            }
            clusterResponse.setCustomContainers(new CustomContainerResponse(result));
        } catch (IOException e) {
            LOGGER.error("Failed to add customContainerDefinition to response", e);
            throw new CloudbreakApiException("Failed to add customContainerDefinition to response", e);
        }
    }
}
Also used : HashMap(java.util.HashMap) CustomContainerResponse(com.sequenceiq.cloudbreak.api.model.CustomContainerResponse) AmbariRepoDetailsJson(com.sequenceiq.cloudbreak.api.model.AmbariRepoDetailsJson) GatewayJson(com.sequenceiq.cloudbreak.api.model.GatewayJson) Json(com.sequenceiq.cloudbreak.domain.json.Json) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) IOException(java.io.IOException) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException)

Example 2 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.controller.CloudbreakApiException in project cloudbreak by hortonworks.

the class ReactorFlowManager method notify.

private void notify(String selector, Acceptable acceptable) {
    Event<Acceptable> event = eventFactory.createEventWithErrHandler(acceptable);
    reactor.notify(selector, event);
    try {
        Boolean accepted = true;
        if (event.getData().accepted() != null) {
            accepted = event.getData().accepted().await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS);
        }
        if (accepted == null || !accepted) {
            Stack stack = stackService.get(event.getData().getStackId());
            throw new FlowsAlreadyRunningException(String.format("Stack %s has flows under operation, request not allowed.", stack.getName()));
        }
    } catch (InterruptedException e) {
        throw new CloudbreakApiException(e.getMessage());
    }
}
Also used : FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.controller.FlowsAlreadyRunningException) Acceptable(com.sequenceiq.cloudbreak.cloud.Acceptable) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 3 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.controller.CloudbreakApiException in project cloudbreak by hortonworks.

the class StackService method create.

@Transactional(TxType.NEVER)
public Stack create(IdentityUser user, Stack stack, String imageCatalog, Optional<String> imageId, Optional<Blueprint> blueprint) {
    Stack savedStack;
    stack.setOwner(user.getUserId());
    stack.setAccount(user.getAccount());
    stack.setGatewayPort(nginxPort);
    setPlatformVariant(stack);
    String stackName = stack.getName();
    MDCBuilder.buildMdcContext(stack);
    try {
        if (!stack.getStackAuthentication().passwordAuthenticationRequired() && !Strings.isNullOrEmpty(stack.getStackAuthentication().getPublicKey())) {
            long start = System.currentTimeMillis();
            rsaPublicKeyValidator.validate(stack.getStackAuthentication().getPublicKey());
            LOGGER.info("RSA key has been validated in {} ms fot stack {}", System.currentTimeMillis() - start, stackName);
        }
        if (stack.getOrchestrator() != null) {
            orchestratorRepository.save(stack.getOrchestrator());
        }
        stack.getStackAuthentication().setLoginUserName(SSH_USER_CB);
        long start = System.currentTimeMillis();
        String template = connector.getTemplate(stack);
        LOGGER.info("Get cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        savedStack = stackRepository.save(stack);
        LOGGER.info("Stackrepository save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        addTemplateForStack(stack, template);
        LOGGER.info("Save cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        addCloudbreakDetailsForStack(stack);
        LOGGER.info("Add Cloudbreak template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        MDCBuilder.buildMdcContext(savedStack);
        start = System.currentTimeMillis();
        instanceGroupRepository.save(savedStack.getInstanceGroups());
        LOGGER.info("Instance groups saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        SecurityConfig securityConfig = tlsSecurityService.storeSSHKeys();
        LOGGER.info("Generating SSH keys took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        securityConfig.setSaltPassword(PasswordUtil.generatePassword());
        securityConfig.setSaltBootPassword(PasswordUtil.generatePassword());
        securityConfig.setKnoxMasterSecret(PasswordUtil.generatePassword());
        LOGGER.info("Generating salt passwords took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        securityConfig.setStack(stack);
        start = System.currentTimeMillis();
        securityConfigRepository.save(securityConfig);
        LOGGER.info("Security config save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        savedStack.setSecurityConfig(securityConfig);
        start = System.currentTimeMillis();
        imageService.create(savedStack, connector.getPlatformParameters(stack), imageCatalog, imageId, blueprint);
        LOGGER.info("Image creation took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.STACK, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.error("Cloudbreak Image not found", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    } catch (CloudbreakImageCatalogException e) {
        LOGGER.error("Cloudbreak Image Catalog error", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    }
    return savedStack;
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) Stack(com.sequenceiq.cloudbreak.domain.Stack) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Transactional(javax.transaction.Transactional)

Example 4 with CloudbreakApiException

use of com.sequenceiq.cloudbreak.controller.CloudbreakApiException in project cloudbreak by hortonworks.

the class ClusterToClusterResponseConverter method convertKnox.

private void convertKnox(Cluster source, ClusterResponse clusterResponse) {
    Gateway gateway = source.getGateway();
    GatewayJson cloudGatewayJson = new GatewayJson();
    cloudGatewayJson.setEnableGateway(gateway.getEnableGateway());
    cloudGatewayJson.setTopologyName(gateway.getTopologyName());
    Json exposedJson = gateway.getExposedServices();
    if (exposedJson != null && StringUtils.isNoneEmpty(exposedJson.getValue())) {
        try {
            cloudGatewayJson.setExposedServices(exposedJson.get(ExposedServices.class).getServices());
        } catch (IOException e) {
            LOGGER.error("Failed to add exposedServices to response", e);
            throw new CloudbreakApiException("Failed to add exposedServices to response", e);
        }
    }
    cloudGatewayJson.setPath(gateway.getPath());
    cloudGatewayJson.setTokenCert(gateway.getTokenCert());
    cloudGatewayJson.setSsoProvider(gateway.getSsoProvider());
    cloudGatewayJson.setSsoType(gateway.getSsoType());
    cloudGatewayJson.setGatewayType(gateway.getGatewayType());
    clusterResponse.setGateway(cloudGatewayJson);
}
Also used : Gateway(com.sequenceiq.cloudbreak.domain.Gateway) AmbariRepoDetailsJson(com.sequenceiq.cloudbreak.api.model.AmbariRepoDetailsJson) GatewayJson(com.sequenceiq.cloudbreak.api.model.GatewayJson) Json(com.sequenceiq.cloudbreak.domain.json.Json) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) IOException(java.io.IOException) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) GatewayJson(com.sequenceiq.cloudbreak.api.model.GatewayJson)

Aggregations

CloudbreakApiException (com.sequenceiq.cloudbreak.controller.CloudbreakApiException)4 AmbariRepoDetailsJson (com.sequenceiq.cloudbreak.api.model.AmbariRepoDetailsJson)2 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)2 GatewayJson (com.sequenceiq.cloudbreak.api.model.GatewayJson)2 Stack (com.sequenceiq.cloudbreak.domain.Stack)2 Json (com.sequenceiq.cloudbreak.domain.json.Json)2 IOException (java.io.IOException)2 CustomContainerResponse (com.sequenceiq.cloudbreak.api.model.CustomContainerResponse)1 Acceptable (com.sequenceiq.cloudbreak.cloud.Acceptable)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 FlowsAlreadyRunningException (com.sequenceiq.cloudbreak.controller.FlowsAlreadyRunningException)1 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 Gateway (com.sequenceiq.cloudbreak.domain.Gateway)1 SecurityConfig (com.sequenceiq.cloudbreak.domain.SecurityConfig)1 HashMap (java.util.HashMap)1 Transactional (javax.transaction.Transactional)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1