Search in sources :

Example 66 with NotFoundException

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

the class FileProcessorHelper method getFileTreeNode.

/**
 * Get the tree node that represents a file from the archive under edition.
 *
 * @param path The path in which to lookup for the
 * @return the tree node from the archive.
 */
public static TreeNode getFileTreeNode(String path) {
    TreeNode root = EditionContextManager.get().getArchiveContentTree().getChildren().first();
    TreeNode target = root;
    String[] pathElements = path.split("/");
    for (int i = 0; i < pathElements.length; i++) {
        String pathElement = pathElements[i];
        TreeNode child = target.getChild(pathElement);
        if (child == null) {
            throw new NotFoundException("The artifact specified at path <" + path + "> does not exists in the topology archive.");
        }
        target = child;
    }
    return target;
}
Also used : TreeNode(alien4cloud.utils.TreeNode) NotFoundException(alien4cloud.exception.NotFoundException)

Example 67 with NotFoundException

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

the class RenameInputProcessor method processInputOperation.

@Override
protected void processInputOperation(Csar csar, Topology topology, RenameInputOperation operation, Map<String, PropertyDefinition> inputs) {
    if (!inputs.containsKey(operation.getInputName())) {
        throw new NotFoundException("Input " + operation.getInputName() + " not found");
    }
    if (operation.getInputName().equals(operation.getNewInputName())) {
        // nothing has changed.
        return;
    }
    if (operation.getNewInputName() == null || operation.getNewInputName().isEmpty() || !operation.getNewInputName().matches("\\w+")) {
        throw new InvalidNameException("newInputName", operation.getNewInputName(), "\\w+");
    }
    if (inputs.containsKey(operation.getNewInputName())) {
        throw new AlreadyExistException("Input " + operation.getNewInputName() + " already existed");
    }
    PropertyDefinition propertyDefinition = inputs.remove(operation.getInputName());
    inputs.put(operation.getNewInputName(), propertyDefinition);
    Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
    for (NodeTemplate nodeTemp : safe(nodeTemplates).values()) {
        renameInputInProperties(nodeTemp.getProperties(), operation.getInputName(), operation.getNewInputName());
        if (nodeTemp.getRelationships() != null) {
            for (RelationshipTemplate relationshipTemplate : nodeTemp.getRelationships().values()) {
                renameInputInProperties(relationshipTemplate.getProperties(), operation.getInputName(), operation.getNewInputName());
            }
        }
        if (nodeTemp.getCapabilities() != null) {
            for (Capability capability : nodeTemp.getCapabilities().values()) {
                renameInputInProperties(capability.getProperties(), operation.getInputName(), operation.getNewInputName());
            }
        }
    }
    // rename preconfigured input
    renamePreconfiguredInput(csar, topology, operation);
    log.debug("Change the name of an input parameter [ {} ] to [ {} ] for the topology ", operation.getInputName(), operation.getNewInputName(), topology.getId());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) InvalidNameException(alien4cloud.exception.InvalidNameException) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 68 with NotFoundException

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

the class UpdateNodeDeploymentArtifactProcessor method process.

@Override
public void process(Csar csar, Topology topology, UpdateNodeDeploymentArtifactOperation operation) {
    // Get the node template's artifacts to update
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
    DeploymentArtifact artifact = nodeTemplate.getArtifacts() == null ? null : nodeTemplate.getArtifacts().get(operation.getArtifactName());
    if (artifact == null) {
        throw new NotFoundException("Artifact with key [" + operation.getArtifactName() + "] do not exist");
    }
    if (operation.getArtifactRepository() == null) {
        // this is an archive file, ensure that the file exists within the archive
        FileProcessorHelper.getFileTreeNode(operation.getArtifactReference());
        artifact.setArtifactRepository(ArtifactRepositoryConstants.ALIEN_TOPOLOGY_REPOSITORY);
        artifact.setRepositoryName(null);
        artifact.setRepositoryURL(null);
    } else {
        artifact.setArtifactRepository(operation.getArtifactRepository());
        artifact.setRepositoryName(operation.getRepositoryName());
        artifact.setRepositoryURL(operation.getRepositoryUrl());
    }
    artifact.setArtifactRef(operation.getArtifactReference());
    artifact.setArchiveName(operation.getArchiveName());
    artifact.setArchiveVersion(operation.getArchiveVersion());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NotFoundException(alien4cloud.exception.NotFoundException) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 69 with NotFoundException

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

the class UnsetNodePropertyAsSecretProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodePropertyAsSecretOperation operation, NodeTemplate nodeTemplate) {
    // check if the node property value is a get_secret
    AbstractPropertyValue currentValue = nodeTemplate.getProperties().get(operation.getPropertyName());
    if (currentValue != null && !isGetSecret(currentValue)) {
        throw new NotFoundException("Property {} of node {} is not associated to an secret.", operation.getPropertyName(), operation.getNodeName());
    }
    NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
    PropertyDefinition nodePropertyDefinition = getOrFail(nodeType.getProperties(), operation.getPropertyName(), "Property {} do not exist for node {}", operation.getPropertyName(), operation.getNodeName());
    AbstractPropertyValue defaultPropertyValue = PropertyUtil.getDefaultPropertyValueFromPropertyDefinition(nodePropertyDefinition);
    nodeTemplate.getProperties().put(operation.getPropertyName(), defaultPropertyValue);
    log.debug("Remove secret property [ {} ] of the node template [ {} ] of the topology [ {} ].", operation.getPropertyName(), operation.getNodeName(), topology.getId());
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 70 with NotFoundException

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

the class AddRequirementSubstitutionTypeProcessor method process.

@Override
public void process(Csar csar, Topology topology, AddRequirementSubstitutionTypeOperation operation) {
    if (topology.getNodeTemplates() == null || !topology.getNodeTemplates().containsKey(operation.getNodeTemplateName())) {
        throw new NotFoundException("Node " + operation.getNodeTemplateName() + " do not exist");
    }
    NodeTemplate nodeTemplate = topology.getNodeTemplates().get(operation.getNodeTemplateName());
    if (nodeTemplate.getRequirements() == null || !nodeTemplate.getRequirements().containsKey(operation.getRequirementId())) {
        throw new NotFoundException("Requirement " + operation.getRequirementId() + " do not exist for node " + operation.getNodeTemplateName());
    }
    if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
        throw new NotFoundException("No substitution type has been found");
    }
    Map<String, SubstitutionTarget> substitutionRequirements = topology.getSubstitutionMapping().getRequirements();
    if (substitutionRequirements == null) {
        substitutionRequirements = Maps.newHashMap();
        topology.getSubstitutionMapping().setRequirements(substitutionRequirements);
    } else if (substitutionRequirements.containsKey(operation.getSubstitutionRequirementId())) {
        // ensure name unicity
        throw new AlreadyExistException(String.format("The substitution requirement <%s> already exists", operation.getSubstitutionRequirementId()));
    }
    substitutionRequirements.put(operation.getSubstitutionRequirementId(), new SubstitutionTarget(operation.getNodeTemplateName(), operation.getRequirementId()));
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NotFoundException(alien4cloud.exception.NotFoundException) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

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