use of org.alien4cloud.tosca.exceptions.ConstraintFunctionalException in project alien4cloud by alien4cloud.
the class UpdateNodePropertyValueProcessor method process.
@Override
public void process(Csar csar, Topology topology, UpdateNodePropertyValueOperation operation) {
Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
NodeTemplate nodeTemp = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
String propertyName = operation.getPropertyName();
Object propertyValue = operation.getPropertyValue();
NodeType node = ToscaContext.getOrFail(NodeType.class, nodeTemp.getType());
PropertyDefinition propertyDefinition = node.getProperties().get(propertyName);
if (propertyDefinition == null) {
throw new NotFoundException("Property <" + propertyName + "> doesn't exists for node <" + operation.getNodeName() + "> of type <" + nodeTemp.getType() + ">");
}
log.debug("Updating property [ {} ] of the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", propertyName, operation.getNodeName(), topology.getId(), nodeTemp.getProperties().get(propertyName), propertyValue);
try {
propertyService.setPropertyValue(nodeTemp, propertyDefinition, propertyName, propertyValue);
} catch (ConstraintFunctionalException e) {
throw new PropertyValueException("Error when setting node " + operation.getNodeName() + " property.", e, propertyName, propertyValue);
}
}
use of org.alien4cloud.tosca.exceptions.ConstraintFunctionalException in project alien4cloud by alien4cloud.
the class UpdatePolicyPropertyValueProcessor method process.
@Override
protected void process(Csar csar, Topology topology, UpdatePolicyPropertyValueOperation operation, PolicyTemplate policyTemplate) {
PolicyType policyType = ToscaContext.getOrFail(PolicyType.class, policyTemplate.getType());
PropertyDefinition propertyDefinition = AlienUtils.getOrFail(policyType.getProperties(), operation.getPropertyName(), "Property [ {} ] doesn't exists in type [ {} ] for policy [ {} ].", operation.getPropertyName(), policyTemplate.getType(), operation.getPolicyName());
log.debug("Updating property [ {} ] of the policy template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", operation.getPropertyName(), operation.getPolicyName(), topology.getId(), policyTemplate.getProperties().get(operation.getPropertyName()), operation.getPropertyValue());
try {
propertyService.setPropertyValue(policyTemplate, propertyDefinition, operation.getPropertyName(), operation.getPropertyValue());
} catch (ConstraintFunctionalException e) {
throw new PropertyValueException("Error when setting policy " + operation.getPolicyName() + " property.", e, operation.getPropertyName(), operation.getPropertyValue());
}
}
use of org.alien4cloud.tosca.exceptions.ConstraintFunctionalException in project alien4cloud by alien4cloud.
the class UpdateRelationshipPropertyValueProcessor method process.
@Override
public void process(Csar csar, Topology topology, UpdateRelationshipPropertyValueOperation operation) {
NodeTemplate nodeTemplate = AlienUtils.getOrFail(topology.getNodeTemplates(), operation.getNodeName(), "The node with name [ {} ] cannot be found in the topology.", operation.getNodeName());
RelationshipTemplate relationshipTemplate = AlienUtils.getOrFail(nodeTemplate.getRelationships(), operation.getRelationshipName(), "The relationship with name [ {} ] cannot be found in the node [ {} ].", operation.getRelationshipName(), operation.getNodeName());
RelationshipType relationshipType = ToscaContext.getOrFail(RelationshipType.class, relationshipTemplate.getType());
PropertyDefinition propertyDefinition = AlienUtils.getOrFail(relationshipType.getProperties(), operation.getPropertyName(), "Property [ {} ] doesn't exists in type [ {} ] for relationship [ {} ] of node [ {} ].", operation.getPropertyName(), relationshipTemplate.getType(), operation.getRelationshipName(), operation.getNodeName());
log.debug("Updating property [ {} ] of the relationship [ {} ] for the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", operation.getPropertyName(), relationshipType, operation.getNodeName(), topology.getId(), relationshipType.getProperties().get(operation.getPropertyName()), operation.getPropertyValue());
try {
propertyService.setPropertyValue(relationshipTemplate, propertyDefinition, operation.getPropertyName(), operation.getPropertyValue());
} catch (ConstraintFunctionalException e) {
throw new PropertyValueException("Error when setting relationship " + operation.getNodeName() + "." + operation.getRelationshipName() + " property.", e, operation.getPropertyName(), operation.getPropertyValue());
}
}
use of org.alien4cloud.tosca.exceptions.ConstraintFunctionalException 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.ConstraintFunctionalException 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