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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations