use of org.alien4cloud.tosca.exceptions.ConstraintTechnicalException in project alien4cloud by alien4cloud.
the class DeploymentTopologyController method updateSubstitutionProperty.
@ApiOperation(value = "Update node substitution's property.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(value = "/substitutions/{nodeId}/properties", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<?> updateSubstitutionProperty(@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, () -> matchedNodePropertiesConfigService.updateProperty(application, environment, topology, nodeId, Optional.empty(), 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;
}
}
use of org.alien4cloud.tosca.exceptions.ConstraintTechnicalException in project alien4cloud by alien4cloud.
the class DeploymentTopologyController method updateSubstitutionCapabilityProperty.
@ApiOperation(value = "Update substitution's capability property.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(value = "/substitutions/{nodeId}/capabilities/{capabilityName}/properties", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<?> updateSubstitutionCapabilityProperty(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @PathVariable String capabilityName, @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, () -> matchedNodePropertiesConfigService.updateProperty(application, environment, topology, nodeId, Optional.of(capabilityName), 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;
}
}
use of org.alien4cloud.tosca.exceptions.ConstraintTechnicalException in project alien4cloud by alien4cloud.
the class ConstraintPropertyService method checkSimplePropertyConstraint.
/**
* Check constraints defined on a property for a specified value
*
* @param propertyName Property name (mainly used to create a comprehensive error message)
* @param stringValue Tested property value
* @param propertyDefinition Full property definition with type, constraints, default value,...
* @throws ConstraintViolationException
* @throws ConstraintValueDoNotMatchPropertyTypeException
*/
private static void checkSimplePropertyConstraint(final String propertyName, final String stringValue, final PropertyDefinition propertyDefinition) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
ConstraintInformation consInformation = null;
// check any property definition without constraints (type/value)
checkBasicType(propertyName, propertyDefinition.getType(), stringValue);
if (propertyDefinition.getConstraints() != null && !propertyDefinition.getConstraints().isEmpty()) {
IPropertyType<?> toscaType = ToscaTypes.fromYamlTypeName(propertyDefinition.getType());
for (PropertyConstraint constraint : propertyDefinition.getConstraints()) {
try {
consInformation = ConstraintUtil.getConstraintInformation(constraint);
consInformation.setPath(propertyName + ".constraints[" + consInformation.getName() + "]");
constraint.initialize(toscaType);
constraint.validate(toscaType, stringValue);
} catch (ConstraintViolationException e) {
throw new ConstraintViolationException(e.getMessage(), e, consInformation);
} catch (IntrospectionException e) {
// ConstraintValueDoNotMatchPropertyTypeException is not supposed to be raised here (only in constraint definition validation)
log.info("Constraint introspection error for property <" + propertyName + "> value <" + stringValue + ">", e);
throw new ConstraintTechnicalException("Constraint introspection error for property <" + propertyName + "> value <" + stringValue + ">", e);
}
}
}
}
use of org.alien4cloud.tosca.exceptions.ConstraintTechnicalException in project alien4cloud by alien4cloud.
the class ConstraintPropertyService method checkConstraints.
private static void checkConstraints(final String propertyName, final String stringValue, final String typeName, List<PropertyConstraint> constraints) throws ConstraintViolationException, ConstraintValueDoNotMatchPropertyTypeException {
ConstraintInformation consInformation = null;
for (PropertyConstraint constraint : constraints) {
IPropertyType<?> toscaType = ToscaTypes.fromYamlTypeName(typeName);
try {
consInformation = ConstraintUtil.getConstraintInformation(constraint);
consInformation.setPath(propertyName + ".constraints[" + consInformation.getName() + "]");
constraint.initialize(toscaType);
constraint.validate(toscaType, stringValue);
} catch (ConstraintViolationException e) {
throw new ConstraintViolationException(e.getMessage(), e, consInformation);
} catch (IntrospectionException e) {
// ConstraintValueDoNotMatchPropertyTypeException is not supposed to be raised here (only in constraint definition validation)
log.info("Constraint introspection error for property <" + propertyName + "> value <" + stringValue + ">", e);
throw new ConstraintTechnicalException("Constraint introspection error for property <" + propertyName + "> value <" + stringValue + ">", e);
}
}
}
use of org.alien4cloud.tosca.exceptions.ConstraintTechnicalException in project alien4cloud by alien4cloud.
the class InputService method setInputValues.
public void setInputValues(ApplicationEnvironment environment, Topology topology, Map<String, Object> inputProperties) {
if (safe(inputProperties).isEmpty()) {
return;
}
// Get the configuration object
DeploymentInputs configuration = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(environment.getTopologyVersion(), environment.getId()));
if (configuration == null) {
configuration = new DeploymentInputs(environment.getTopologyVersion(), environment.getId());
}
for (Map.Entry<String, Object> inputPropertyValue : inputProperties.entrySet()) {
if (topology.getInputs() == null || topology.getInputs().get(inputPropertyValue.getKey()) == null) {
throw new NotFoundException("Input", inputPropertyValue.getKey(), "Input <" + inputPropertyValue.getKey() + "> cannot be found on topology for application <" + environment.getApplicationId() + "> environement <" + environment.getId() + ">");
}
try {
propertyService.setPropertyValue(configuration.getInputs(), topology.getInputs().get(inputPropertyValue.getKey()), inputPropertyValue.getKey(), inputPropertyValue.getValue());
} catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException e) {
throw new ConstraintTechnicalException("Dispatching constraint violation.", e);
}
}
// Save configuration
deploymentConfigurationDao.save(configuration);
}
Aggregations