Search in sources :

Example 61 with BadRequestException

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

the class BlueprintRequestToBlueprintConverter method validateBlueprint.

private void validateBlueprint(String blueprintText) {
    try {
        JsonNode root = JsonUtil.readTree(blueprintText);
        hasBlueprintInBlueprint(root);
        hasBlueprintNameInBlueprint(root);
        validateHostGroups(root);
    } catch (IOException e) {
        throw new BadRequestException("Invalid Blueprint: Failed to parse JSON.", e);
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Example 62 with BadRequestException

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

the class NetworkRequestToNetworkConverter method convert.

@Override
public Network convert(NetworkRequest source) {
    Network network = new Network();
    if (Strings.isNullOrEmpty(source.getName())) {
        network.setName(missingResourceNameGenerator.generateName(APIResourceType.NETWORK));
    } else {
        network.setName(source.getName());
    }
    network.setDescription(source.getDescription());
    network.setSubnetCIDR(source.getSubnetCIDR());
    network.setStatus(ResourceStatus.USER_MANAGED);
    network.setCloudPlatform(source.getCloudPlatform());
    Map<String, Object> parameters = source.getParameters();
    if (parameters != null && !parameters.isEmpty()) {
        try {
            network.setAttributes(new Json(parameters));
        } catch (JsonProcessingException ignored) {
            throw new BadRequestException("Invalid parameters");
        }
    }
    if (source.getTopologyId() != null) {
        network.setTopology(topologyService.getById(source.getTopologyId()));
    }
    return network;
}
Also used : Network(com.sequenceiq.cloudbreak.domain.Network) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Json(com.sequenceiq.cloudbreak.domain.json.Json) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 63 with BadRequestException

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

the class OrchestratorRequestToOrchestratorConverter method convert.

@Override
public Orchestrator convert(OrchestratorRequest source) {
    Orchestrator orchestrator = new Orchestrator();
    orchestrator.setApiEndpoint(source.getApiEndpoint());
    orchestrator.setType(source.getType());
    Map<String, Object> params = new HashMap<>();
    if (source.getParameters() != null && !source.getParameters().isEmpty()) {
        params = source.getParameters();
    }
    try {
        orchestrator.setAttributes(new Json(params));
    } catch (JsonProcessingException e) {
        throw new BadRequestException("Invalid parameters", e);
    }
    return orchestrator;
}
Also used : HashMap(java.util.HashMap) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Json(com.sequenceiq.cloudbreak.domain.json.Json) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 64 with BadRequestException

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

the class RDSConfigRequestToRDSConfigConverter method convert.

@Override
public RDSConfig convert(RDSConfigRequest source) {
    RDSConfig rdsConfig = new RDSConfig();
    if (Strings.isNullOrEmpty(source.getName())) {
        rdsConfig.setName(missingResourceNameGenerator.generateName(APIResourceType.RDS_CONFIG));
    } else {
        rdsConfig.setName(source.getName());
    }
    rdsConfig.setConnectionURL(source.getConnectionURL());
    Optional<DatabaseVendor> databaseVendor = DatabaseVendor.getVendorByJdbcUrl(source.getConnectionURL());
    if (databaseVendor.isPresent()) {
        rdsConfig.setDatabaseEngine(databaseVendor.get().name());
        rdsConfig.setConnectionDriver(databaseVendor.get().connectionDriver());
    } else {
        throw new BadRequestException("Not a valid DatabaseVendor which was provided in the jdbc url.");
    }
    rdsConfig.setConnectionUserName(source.getConnectionUserName());
    rdsConfig.setConnectionPassword(source.getConnectionPassword());
    rdsConfig.setCreationDate(new Date().getTime());
    rdsConfig.setStatus(ResourceStatus.USER_MANAGED);
    rdsConfig.setType(source.getType());
    return rdsConfig;
}
Also used : DatabaseVendor(com.sequenceiq.cloudbreak.api.model.DatabaseVendor) RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Date(java.util.Date)

Example 65 with BadRequestException

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

the class BlueprintService method create.

@Transactional(TxType.NEVER)
public Blueprint create(IdentityUser user, Blueprint blueprint, Collection<Map<String, Map<String, String>>> properties) {
    LOGGER.debug("Creating blueprint: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
    Blueprint savedBlueprint;
    blueprint.setOwner(user.getUserId());
    blueprint.setAccount(user.getAccount());
    if (properties != null && !properties.isEmpty()) {
        LOGGER.info("Extend validation with the following properties: {}", properties);
        Map<String, Map<String, String>> configs = new HashMap<>(properties.size());
        for (Map<String, Map<String, String>> property : properties) {
            for (Entry<String, Map<String, String>> entry : property.entrySet()) {
                Map<String, String> configValues = configs.get(entry.getKey());
                if (configValues != null) {
                    configValues.putAll(entry.getValue());
                } else {
                    configs.put(entry.getKey(), entry.getValue());
                }
            }
        }
        String extendedBlueprint = blueprintProcessorFactory.get(blueprint.getBlueprintText()).extendBlueprintGlobalConfiguration(SiteConfigurations.fromMap(configs), false).asText();
        LOGGER.info("Extended validation result: {}", extendedBlueprint);
        blueprint.setBlueprintText(extendedBlueprint);
    }
    try {
        savedBlueprint = blueprintRepository.save(blueprint);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.BLUEPRINT, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    }
    return savedBlueprint;
}
Also used : HashMap(java.util.HashMap) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HashMap(java.util.HashMap) Map(java.util.Map) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Transactional(javax.transaction.Transactional)

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