Search in sources :

Example 6 with ConstraintTechnicalException

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);
    }
}
Also used : ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) OrchestratorDeploymentProperties(org.alien4cloud.alm.deployment.configuration.model.OrchestratorDeploymentProperties)

Example 7 with ConstraintTechnicalException

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);
    }
}
Also used : ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) NotFoundException(alien4cloud.exception.NotFoundException) LocationPolicyTask(alien4cloud.topology.task.LocationPolicyTask) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) NodeMatchingConfigAutoSelectModifier(org.alien4cloud.alm.deployment.configuration.flow.modifiers.matching.NodeMatchingConfigAutoSelectModifier) NodePropsOverride(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration.NodePropsOverride)

Example 8 with ConstraintTechnicalException

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;
    }
}
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 9 with ConstraintTechnicalException

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

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