Search in sources :

Example 6 with ConstraintFunctionalException

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);
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 7 with ConstraintFunctionalException

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());
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) PolicyType(org.alien4cloud.tosca.model.types.PolicyType) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 8 with ConstraintFunctionalException

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());
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 9 with ConstraintFunctionalException

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;
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with ConstraintFunctionalException

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;
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ConstraintFunctionalException (org.alien4cloud.tosca.exceptions.ConstraintFunctionalException)10 Audit (alien4cloud.audit.annotation.Audit)5 ApiOperation (io.swagger.annotations.ApiOperation)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)4 Application (alien4cloud.model.application.Application)4 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)4 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)4 PropertyValueException (org.alien4cloud.tosca.editor.exception.PropertyValueException)4 ConstraintTechnicalException (org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)4 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)4 Topology (org.alien4cloud.tosca.model.templates.Topology)4 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)3 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)3 NotFoundException (alien4cloud.exception.NotFoundException)2 Map (java.util.Map)2 OperationExecutionException (alien4cloud.paas.exception.OperationExecutionException)1 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)1 RestError (alien4cloud.rest.model.RestError)1