Search in sources :

Example 36 with BadRequestException

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

the class LdapConfigService method create.

@Transactional(TxType.NEVER)
public LdapConfig create(IdentityUser user, LdapConfig ldapConfig) {
    ldapConfig.setOwner(user.getUserId());
    ldapConfig.setAccount(user.getAccount());
    try {
        return ldapConfigRepository.save(ldapConfig);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.LDAP_CONFIG, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Transactional(javax.transaction.Transactional)

Example 37 with BadRequestException

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

the class ImageCatalogService method delete.

public void delete(String name) {
    if (isEnvDefault(name)) {
        throw new BadRequestException(String.format("%s cannot be deleted because it is an environment default image catalog.", name));
    }
    ImageCatalog imageCatalog = get(name);
    authorizationService.hasWritePermission(imageCatalog);
    imageCatalog.setArchived(true);
    setImageCatalogAsDefault(null);
    imageCatalog.setImageCatalogName(generateArchiveName(name));
    imageCatalogRepository.save(imageCatalog);
    LOGGER.info("Image catalog has been archived: {}", imageCatalog);
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog)

Example 38 with BadRequestException

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

the class RecipeService method create.

@Transactional(TxType.NEVER)
public Recipe create(IdentityUser user, Recipe recipe) {
    recipe.setOwner(user.getUserId());
    recipe.setAccount(user.getAccount());
    try {
        return recipeRepository.save(recipe);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.RECIPE, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Transactional(javax.transaction.Transactional)

Example 39 with BadRequestException

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

the class FileSystemValidator method validateFilesystemRequest.

private void validateFilesystemRequest(FileSystemRequest fileSystemRequest) {
    ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
    Validator validator = validatorFactory.getValidator();
    try {
        String json = JsonUtil.writeValueAsString(fileSystemRequest.getProperties());
        Object fsConfig = JsonUtil.readValue(json, fileSystemRequest.getType().getClazz());
        Set<ConstraintViolation<Object>> violations = validator.validate(fsConfig);
        if (!violations.isEmpty()) {
            throw new ConstraintViolationException(violations);
        }
    } catch (IOException e) {
        throw new BadRequestException(e.getMessage(), e);
    }
}
Also used : ValidatorFactory(javax.validation.ValidatorFactory) ConstraintViolation(javax.validation.ConstraintViolation) ConstraintViolationException(javax.validation.ConstraintViolationException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) IOException(java.io.IOException) Validator(javax.validation.Validator)

Example 40 with BadRequestException

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

the class LdapConfigValidator method validateLdapConnection.

private void validateLdapConnection(String protocol, String serverHost, Integer serverPort, String bindDn, String bindPassword) {
    try {
        LOGGER.info("Validate connection to LDAP host: '{}', port: '{}', protocol: '{}'.", serverHost, serverPort, protocol);
        // BEGIN GENERATED CODE
        Hashtable<String, String> env = new Hashtable<>();
        // END GENERATED CODE
        env.put("com.sun.jndi.ldap.read.timeout", "1000");
        env.put("com.sun.jndi.ldap.connect.timeout", "5000");
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        String url = new StringBuilder(protocol).append("://").append(serverHost).append(':').append(serverPort).toString();
        env.put(Context.PROVIDER_URL, url);
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, bindDn);
        env.put(Context.SECURITY_CREDENTIALS, bindPassword);
        Context ctx = new InitialDirContext(env);
        ctx.close();
    } catch (NamingException e) {
        throw new BadRequestException("Failed to connect to LDAP server: " + e.getMessage(), e);
    }
}
Also used : Context(javax.naming.Context) InitialDirContext(javax.naming.directory.InitialDirContext) Hashtable(java.util.Hashtable) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)87 Stack (com.sequenceiq.cloudbreak.domain.Stack)16 Transactional (javax.transaction.Transactional)13 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)12 Json (com.sequenceiq.cloudbreak.domain.json.Json)12 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)12 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)11 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 IOException (java.io.IOException)7 Credential (com.sequenceiq.cloudbreak.domain.Credential)6 HashMap (java.util.HashMap)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)5 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)4 HashSet (java.util.HashSet)4 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)3