use of org.alien4cloud.tosca.exceptions.ConstraintTechnicalException in project alien4cloud by alien4cloud.
the class OrchestratorPropertiesService method setOrchestratorProperties.
public void setOrchestratorProperties(ApplicationEnvironment environment, Map<String, String> providerDeploymentProperties) {
if (MapUtils.isNotEmpty(providerDeploymentProperties)) {
OrchestratorDeploymentProperties properties = deploymentConfigurationDao.findById(OrchestratorDeploymentProperties.class, AbstractDeploymentConfig.generateId(environment.getTopologyVersion(), environment.getId()));
try {
orchestratorPropertiesValidationService.checkConstraints(properties.getOrchestratorId(), providerDeploymentProperties);
} catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
throw new ConstraintTechnicalException("Error on deployer user orchestrator properties validation", e);
}
if (properties.getProviderDeploymentProperties() == null) {
properties.setProviderDeploymentProperties(providerDeploymentProperties);
} else {
properties.getProviderDeploymentProperties().putAll(providerDeploymentProperties);
}
deploymentConfigurationDao.save(properties);
}
}
use of org.alien4cloud.tosca.exceptions.ConstraintTechnicalException in project alien4cloud by alien4cloud.
the class AbstractSetMatchedPropertyModifier method process.
@Override
public void process(Topology topology, FlowExecutionContext context) {
Optional<DeploymentMatchingConfiguration> configurationOptional = context.getConfiguration(DeploymentMatchingConfiguration.class, NodeMatchingConfigAutoSelectModifier.class.getSimpleName());
if (!configurationOptional.isPresent()) {
// we should not end-up here as location matching should be processed first
context.log().error(new LocationPolicyTask());
return;
}
DeploymentMatchingConfiguration matchingConfiguration = configurationOptional.get();
Map<String, String> lastUserSubstitutions = getUserMatches(matchingConfiguration);
U template = getTemplates(topology).get(templateId);
if (template == null) {
throw new NotFoundException("Topology [" + topology.getId() + "] does not contains any " + getSubject() + " with id [" + templateId + "]");
}
String substitutionId = lastUserSubstitutions.get(templateId);
if (substitutionId == null) {
throw new NotFoundException("The " + getSubject() + " [" + templateId + "] from topology [" + topology.getId() + "] is not matched.");
}
Map<String, V> allAvailableResourceTemplates = getAvailableResourceTemplates(context);
V resourceTemplate = allAvailableResourceTemplates.get(substitutionId);
try {
setProperty(context, resourceTemplate, template, matchingConfiguration);
} catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
throw new ConstraintTechnicalException("Dispatching constraint violation.", e);
}
}
use of org.alien4cloud.tosca.exceptions.ConstraintTechnicalException in project alien4cloud by alien4cloud.
the class DeploymentTopologyController method updateDeploymentSetup.
/**
* @param appId The application id
* @param environmentId Id of the environment we want to update
* @param updateRequest an {@link UpdateDeploymentTopologyRequest} object
* @return a {@link RestResponse} with:<br>
* the {@link DeploymentTopologyDTO} if everything went well, the <br>
* Error if not
*
* @throws OrchestratorDisabledException
*/
@ApiOperation(value = "Updates by merging the given request into the given application's deployment topology.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<?> updateDeploymentSetup(@PathVariable String appId, @PathVariable String environmentId, @RequestBody UpdateDeploymentTopologyRequest updateRequest) throws OrchestratorDisabledException {
try {
// check rights on related environment
DeploymentTopologyDTO dto = execute(appId, environmentId, (application, environment, topologyVersion, topology) -> {
// Set inputs
inputService.setInputValues(environment, topology, updateRequest.getInputProperties());
// Set orchestrator specific properties
orchestratorPropertiesService.setOrchestratorProperties(environment, updateRequest.getProviderDeploymentProperties());
});
return RestResponseBuilder.<DeploymentTopologyDTO>builder().data(dto).build();
} catch (ConstraintTechnicalException e) {
if (e.getCause() instanceof ConstraintFunctionalException) {
ConstraintFunctionalException ex = (ConstraintFunctionalException) e.getCause();
return RestConstraintValidator.fromException(ex, ex.getConstraintInformation().getName(), ex.getConstraintInformation().getValue());
}
throw e;
}
}
use of org.alien4cloud.tosca.exceptions.ConstraintTechnicalException in project alien4cloud by alien4cloud.
the class DeploymentTopologyController method updatePolicySubstitutionProperty.
@ApiOperation(value = "Update policy substitution's property.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(value = "/policies/{nodeId}/substitution/properties", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<?> updatePolicySubstitutionProperty(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @RequestBody UpdatePropertyRequest updateRequest) {
try {
Application application = applicationService.getOrFail(appId);
ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId);
AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> matchedPolicyPropertiesConfigService.updateProperty(application, environment, topology, nodeId, updateRequest.getPropertyName(), updateRequest.getPropertyValue()));
return RestResponseBuilder.<DeploymentTopologyDTO>builder().data(dto).build();
} catch (ConstraintTechnicalException e) {
if (e.getCause() instanceof ConstraintFunctionalException) {
return RestConstraintValidator.fromException((ConstraintFunctionalException) e.getCause(), updateRequest.getPropertyName(), updateRequest.getPropertyValue());
}
throw e;
}
}
Aggregations