Search in sources :

Example 1 with ConstraintTechnicalException

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

Example 2 with ConstraintTechnicalException

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

Example 3 with ConstraintTechnicalException

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);
            }
        }
    }
}
Also used : PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) IntrospectionException(java.beans.IntrospectionException) ConstraintInformation(alien4cloud.tosca.properties.constraints.ConstraintUtil.ConstraintInformation) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)

Example 4 with ConstraintTechnicalException

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);
        }
    }
}
Also used : PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) IntrospectionException(java.beans.IntrospectionException) ConstraintInformation(alien4cloud.tosca.properties.constraints.ConstraintUtil.ConstraintInformation) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)

Example 5 with ConstraintTechnicalException

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);
}
Also used : ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) NotFoundException(alien4cloud.exception.NotFoundException) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) Map(java.util.Map) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)

Aggregations

ConstraintTechnicalException (org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)9 ConstraintViolationException (org.alien4cloud.tosca.exceptions.ConstraintViolationException)5 Audit (alien4cloud.audit.annotation.Audit)4 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)4 ApiOperation (io.swagger.annotations.ApiOperation)4 ConstraintFunctionalException (org.alien4cloud.tosca.exceptions.ConstraintFunctionalException)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 Application (alien4cloud.model.application.Application)3 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)3 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)3 ConstraintValueDoNotMatchPropertyTypeException (org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException)3 Topology (org.alien4cloud.tosca.model.templates.Topology)3 NotFoundException (alien4cloud.exception.NotFoundException)2 ConstraintInformation (alien4cloud.tosca.properties.constraints.ConstraintUtil.ConstraintInformation)2 IntrospectionException (java.beans.IntrospectionException)2 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)2 LocationPolicyTask (alien4cloud.topology.task.LocationPolicyTask)1 Map (java.util.Map)1