Search in sources :

Example 61 with NotFoundException

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

the class EditorInputHelperService method getInputCandidates.

/**
 * Utility method to get the list of inputs (ids) that are compatible with the given property definition (no constraint conflicts)..
 *
 * @param topologyId The id of the topology for which to find input candidates.
 * @param nodeTemplateName The name of the node template for which to get input candidates.
 * @param propertyDefinitionGetter Implementation on how to get the property definition (from node properties, capabilities properties, relationships
 *            properties).
 * @return A list of input candidates that are compatible with the requested property definition.
 */
public List<String> getInputCandidates(String topologyId, String nodeTemplateName, IPropertyDefinitionGetter propertyDefinitionGetter) {
    try {
        editionContextManager.init(topologyId);
        // check authorization to update a topology
        topologyService.checkEditionAuthorizations(EditionContextManager.getTopology());
        Topology topology = EditionContextManager.getTopology();
        NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateName);
        PropertyDefinition pd = propertyDefinitionGetter.get(nodeTemplate);
        if (pd == null) {
            throw new NotFoundException("Unexpected error, property definition cannot be found for node <" + nodeTemplateName + ">");
        }
        Map<String, PropertyDefinition> inputs = topology.getInputs();
        List<String> inputIds = new ArrayList<String>();
        if (inputs != null && !inputs.isEmpty()) {
            // iterate overs existing inputs and filter them by checking constraint compatibility
            for (Map.Entry<String, PropertyDefinition> inputEntry : inputs.entrySet()) {
                try {
                    inputEntry.getValue().checkIfCompatibleOrFail(pd);
                    inputIds.add(inputEntry.getKey());
                } catch (IncompatiblePropertyDefinitionException e) {
                // Nothing to do here, the id won't be added to the list
                }
            }
        }
        return inputIds;
    } finally {
        editionContextManager.destroy();
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ArrayList(java.util.ArrayList) NotFoundException(alien4cloud.exception.NotFoundException) Topology(org.alien4cloud.tosca.model.templates.Topology) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Map(java.util.Map) IncompatiblePropertyDefinitionException(alien4cloud.model.components.IncompatiblePropertyDefinitionException)

Example 62 with NotFoundException

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

the class SetNodeArtifactAsInputProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodeArtifactAsInputOperation operation, NodeTemplate nodeTemplate) {
    if (safe(nodeTemplate.getArtifacts()).get(operation.getArtifactName()) == null) {
        throw new NotFoundException("The artifact <" + operation.getArtifactName() + "> cannot be found on node <" + operation.getNodeName() + ">");
    }
    DeploymentArtifact artifact = nodeTemplate.getArtifacts().get(operation.getArtifactName());
    if (!safe(topology.getInputArtifacts()).containsKey(operation.getInputName())) {
        // we have to create the artifact
        operation.setNewArtifact(true);
        DeploymentArtifact inputArtifact = new DeploymentArtifact();
        inputArtifact.setArchiveName(artifact.getArchiveName());
        inputArtifact.setArchiveVersion(artifact.getArchiveVersion());
        inputArtifact.setArtifactType(artifact.getArtifactType());
        Map<String, DeploymentArtifact> inputArtifacts = topology.getInputArtifacts();
        if (inputArtifacts == null) {
            inputArtifacts = Maps.newHashMap();
            topology.setInputArtifacts(inputArtifacts);
        }
        inputArtifacts.put(operation.getInputName(), inputArtifact);
    }
    InputArtifactUtil.setInputArtifact(artifact, operation.getInputName());
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 63 with NotFoundException

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

the class UnSetNodeCapabilityPropertyAsOutputProcessor method check.

@SuppressWarnings("unchecked")
private void check(UnSetNodeCapabilityPropertyAsOutputOperation operation, Topology topology, NodeTemplate nodeTemplate) {
    if (nodeTemplate.getCapabilities() == null || nodeTemplate.getCapabilities().get(operation.getCapabilityName()) == null) {
        throw new NotFoundException("Capability " + operation.getCapabilityName() + " not found in node template " + operation.getNodeName());
    }
    Capability capabilityTemplate = nodeTemplate.getCapabilities().get(operation.getCapabilityName());
    CapabilityType indexedCapabilityType = EditionContextManager.get().getToscaContext().getElement(CapabilityType.class, capabilityTemplate.getType(), true);
    if (indexedCapabilityType.getProperties() == null || !indexedCapabilityType.getProperties().containsKey(operation.getPropertyName())) {
        throw new NotFoundException("Property " + operation.getPropertyName() + " not found in capability " + operation.getCapabilityName() + " of node " + operation.getNodeName());
    }
    Set<String> values = (Set<String>) MapUtil.get(topology.getOutputCapabilityProperties(), operation.getNodeName().concat(".").concat(operation.getCapabilityName()));
    if (!AlienUtils.safe(values).contains(operation.getPropertyName())) {
        throw new NotFoundException("Node " + operation.getNodeName() + " capability " + operation.getCapabilityName() + " 's property " + operation.getPropertyName() + " not found in outputs");
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Set(java.util.Set) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException)

Example 64 with NotFoundException

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

the class AbstractUpdateFileProcessor method beforeCommit.

@Override
@SneakyThrows
public void beforeCommit(T operation) {
    // validate that the operation is ok for beforeCommit process
    if (canPerformBeforeCommit(operation)) {
        try {
            TreeNode fileTreeNode = FileProcessorHelper.getFileTreeNode(operation.getPath());
            Path targetPath = EditionContextManager.get().getLocalGitPath().resolve(operation.getPath());
            Files.createDirectories(targetPath.getParent());
            try (InputStream inputStream = artifactRepository.getFile(operation.getTempFileId())) {
                Files.copy(inputStream, targetPath, StandardCopyOption.REPLACE_EXISTING);
            }
            artifactRepository.deleteFile(operation.getTempFileId());
            fileTreeNode.setArtifactId(null);
        } catch (NotFoundException e) {
            log.debug("The file is not referenced in the tree, must have been deleted in later operation.", e);
        }
    }
}
Also used : Path(java.nio.file.Path) TreeNode(alien4cloud.utils.TreeNode) InputStream(java.io.InputStream) NotFoundException(alien4cloud.exception.NotFoundException) SneakyThrows(lombok.SneakyThrows)

Example 65 with NotFoundException

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

the class RenameGroupProcessor method process.

@Override
public void process(Csar csar, Topology topology, RenameGroupOperation operation) {
    if (operation.getNewGroupName() == null || !operation.getNewGroupName().matches("\\w+")) {
        throw new InvalidNameException("groupName", operation.getGroupName(), "\\w+");
    }
    if (topology.getGroups() == null) {
        throw new NotFoundException("Group with name [" + operation.getGroupName() + "] does not exists and cannot be renamed.");
    }
    if (topology.getGroups().containsKey(operation.getNewGroupName())) {
        throw new AlreadyExistException("Group with name [" + operation.getNewGroupName() + "] already exists, please choose another name");
    }
    NodeGroup nodeGroup = topology.getGroups().remove(operation.getGroupName());
    if (nodeGroup == null) {
        throw new NotFoundException("Group with name [" + operation.getGroupName() + "] does not exists and cannot be renamed.");
    }
    nodeGroup.setName(operation.getNewGroupName());
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    for (NodeTemplate nodeTemplate : nodeTemplates.values()) {
        if (nodeTemplate.getGroups() != null) {
            if (nodeTemplate.getGroups().remove(operation.getGroupName())) {
                nodeTemplate.getGroups().add(operation.getNewGroupName());
            }
        }
    }
    topology.getGroups().put(operation.getNewGroupName(), nodeGroup);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) InvalidNameException(alien4cloud.exception.InvalidNameException) NotFoundException(alien4cloud.exception.NotFoundException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

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