Search in sources :

Example 21 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class DeleteInputProcessor method processInputOperation.

@Override
protected void processInputOperation(Csar csar, Topology topology, DeleteInputOperation operation, Map<String, PropertyDefinition> inputs) {
    if (!inputs.containsKey(operation.getInputName())) {
        throw new NotFoundException("Input " + operation.getInputName() + "not found in topology");
    }
    for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
        NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
        removeInputIdInProperties(nodeTemplate.getProperties(), nodeType.getProperties(), operation.getInputName());
        if (nodeTemplate.getRelationships() != null) {
            for (RelationshipTemplate relationshipTemplate : nodeTemplate.getRelationships().values()) {
                RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
                removeInputIdInProperties(relationshipTemplate.getProperties(), relationshipType.getProperties(), operation.getInputName());
            }
        }
        if (nodeTemplate.getCapabilities() != null) {
            for (Capability capability : nodeTemplate.getCapabilities().values()) {
                CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
                removeInputIdInProperties(capability.getProperties(), capabilityType.getProperties(), operation.getInputName());
            }
        }
    }
    deletePreConfiguredInput(csar, topology, operation);
    inputs.remove(operation.getInputName());
    log.debug("Remove the input " + operation.getInputName() + " from the topology " + topology.getId());
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) NotFoundException(alien4cloud.exception.NotFoundException)

Example 22 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class UpdateCapabilityPropertyValueProcessor method process.

@Override
@SneakyThrows
public void process(Csar csar, Topology topology, UpdateCapabilityPropertyValueOperation operation) {
    String propertyName = operation.getPropertyName();
    Object propertyValue = operation.getPropertyValue();
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
    Capability capability = nodeTemplate.getCapabilities().get(operation.getCapabilityName());
    CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
    if (!capabilityType.getProperties().containsKey(propertyName)) {
        throw new NotFoundException("Property <" + propertyName + "> doesn't exists for node <" + operation.getNodeName() + "> of type <" + capabilityType + ">");
    }
    log.debug("Updating property [ {} ] of the capability [ {} ] for the Node template [ {} ] from the topology [ {} ]: changing value from [{}] to [{}].", propertyName, capability.getType(), operation.getNodeName(), topology.getId(), capabilityType.getProperties().get(propertyName), propertyValue);
    try {
        propertyService.setCapabilityPropertyValue(capability, capabilityType.getProperties().get(propertyName), 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) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException) PropertyValueException(org.alien4cloud.tosca.editor.exception.PropertyValueException) SneakyThrows(lombok.SneakyThrows)

Example 23 with NotFoundException

use of alien4cloud.exception.NotFoundException 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 24 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class CsarFileRepository method getExpandedCSAR.

@Override
public Path getExpandedCSAR(String name, String version) {
    Path csarDir = rootPath.resolve(name).resolve(version);
    Path expandedPath = csarDir.resolve("expanded");
    if (Files.exists(expandedPath)) {
        return expandedPath;
    }
    throw new NotFoundException("CSAR: " + name + ", Version: " + version + " not found in the repository.");
}
Also used : Path(java.nio.file.Path) NotFoundException(alien4cloud.exception.NotFoundException)

Example 25 with NotFoundException

use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.

the class CsarFileRepository method getCSAR.

@Override
public Path getCSAR(String name, String version) {
    Path csarDir = rootPath.resolve(name).resolve(version);
    Path expandedPath = csarDir.resolve("expanded");
    Path zippedPath = csarDir.resolve(name.concat("-").concat(version).concat("." + CSAR_EXTENSION));
    if (Files.exists(zippedPath)) {
        return zippedPath;
    } else if (Files.exists(expandedPath)) {
        // the csar wasn't stored as a zip file. Zip the expanded dir then
        try {
            FileUtil.zip(expandedPath, zippedPath);
            return zippedPath;
        } catch (IOException e) {
            log.error("Failed to zip directory " + expandedPath, e);
            throw new NotFoundException("CSAR: " + name + ", Version: " + version + " not found in the repository.");
        }
    }
    throw new NotFoundException("CSAR: " + name + ", Version: " + version + " not found in the repository.");
}
Also used : Path(java.nio.file.Path) NotFoundException(alien4cloud.exception.NotFoundException) IOException(java.io.IOException)

Aggregations

NotFoundException (alien4cloud.exception.NotFoundException)88 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)17 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)12 Map (java.util.Map)10 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)10 AlreadyExistException (alien4cloud.exception.AlreadyExistException)9 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)9 Capability (org.alien4cloud.tosca.model.templates.Capability)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)8 SubstitutionTarget (org.alien4cloud.tosca.model.templates.SubstitutionTarget)8 Topology (org.alien4cloud.tosca.model.templates.Topology)7 Deployment (alien4cloud.model.deployment.Deployment)6 ApiOperation (io.swagger.annotations.ApiOperation)6 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)6 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 InvalidNameException (alien4cloud.exception.InvalidNameException)5 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5