Search in sources :

Example 26 with NotFoundException

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

the class RenameInputArtifactProcessor method process.

@Override
public void process(Csar csar, Topology topology, RenameInputArtifactOperation operation) {
    if (operation.getNewInputName() == null || operation.getNewInputName().isEmpty() || !operation.getNewInputName().matches("\\w+")) {
        throw new InvalidNameException("newInputName", operation.getNewInputName(), "\\w+");
    }
    if (safe(topology.getInputArtifacts()).containsKey(operation.getNewInputName())) {
        throw new AlreadyExistException("Input artifact with name <" + operation.getNewInputName() + "> already exists.");
    }
    if (!safe(topology.getInputArtifacts()).containsKey(operation.getInputName())) {
        throw new NotFoundException("Input artifact with name <" + operation.getInputName() + "> does not exists.");
    }
    DeploymentArtifact inputArtifact = topology.getInputArtifacts().remove(operation.getInputName());
    topology.getInputArtifacts().put(operation.getNewInputName(), inputArtifact);
    // change the value of concerned node template artifacts
    for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
        for (DeploymentArtifact dArtifact : safe(nodeTemplate.getArtifacts()).values()) {
            InputArtifactUtil.updateInputArtifactIdIfNeeded(dArtifact, operation.getInputName(), operation.getNewInputName());
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) InvalidNameException(alien4cloud.exception.InvalidNameException) NotFoundException(alien4cloud.exception.NotFoundException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 27 with NotFoundException

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

the class ResetNodeDeploymentArtifactProcessor method process.

@Override
public void process(Csar csar, Topology topology, ResetNodeDeploymentArtifactOperation operation) {
    // Get the node template's artifacts to reset
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
    DeploymentArtifact currentArtifact = nodeTemplate.getArtifacts() == null ? null : nodeTemplate.getArtifacts().get(operation.getArtifactName());
    if (currentArtifact == null) {
        throw new NotFoundException("Artifact with key [" + operation.getArtifactName() + "] do not exist in node template [" + nodeTemplate.getName() + "].");
    }
    // Get the node type's artifact
    Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, false, true);
    NodeType nodeType = nodeTypes.get(nodeTemplate.getType());
    DeploymentArtifact artifactFromNodeType = nodeType.getArtifacts() == null ? null : nodeType.getArtifacts().get(operation.getArtifactName());
    if (artifactFromNodeType == null) {
        throw new NotFoundException("Artifact with key [" + operation.getArtifactName() + "] do not exist in node type [" + nodeType.getId() + "].");
    }
    currentArtifact.setArtifactRef(artifactFromNodeType.getArtifactRef());
    currentArtifact.setArtifactName(artifactFromNodeType.getArtifactName());
    currentArtifact.setArtifactType(artifactFromNodeType.getArtifactType());
    currentArtifact.setArtifactRepository(artifactFromNodeType.getArtifactRepository());
    currentArtifact.setRepositoryName(artifactFromNodeType.getRepositoryName());
    currentArtifact.setRepositoryURL(artifactFromNodeType.getRepositoryURL());
    currentArtifact.setRepositoryCredential(artifactFromNodeType.getRepositoryCredential());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 28 with NotFoundException

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

the class EditorService method undoRedo.

/**
 * Undo or redo operations until the given index (including)
 *
 * @param topologyId The id of the topology for which to undo or redo operations.
 * @param at The index on which to place the undo/redo cursor (-1 means no operations, then 0 is first operation etc.)
 * @param lastOperationId The last known operation id for client optimistic locking.
 * @return The topology DTO.
 */
public TopologyDTO undoRedo(String topologyId, int at, String lastOperationId) {
    try {
        initContext(topologyId, lastOperationId);
        if (-1 > at || at > EditionContextManager.get().getOperations().size()) {
            throw new NotFoundException("Unable to find the requested index for undo/redo");
        }
        checkTopologyRecovery();
        if (at == EditionContextManager.get().getLastOperationIndex()) {
            // nothing to change.
            return dtoBuilder.buildTopologyDTO(EditionContextManager.get());
        }
        // TODO Improve this by avoiding dao query for (deep) cloning topology and keeping cache for TOSCA types that are required.
        editionContextManager.reset();
        Topology topology = EditionContextManager.getTopology();
        Csar csar = EditionContextManager.getCsar();
        for (int i = 0; i < at + 1; i++) {
            AbstractEditorOperation operation = EditionContextManager.get().getOperations().get(i);
            IEditorOperationProcessor processor = processorMap.get(operation.getClass());
            processor.process(csar, topology, operation);
        }
        EditionContextManager.get().setLastOperationIndex(at);
        return dtoBuilder.buildTopologyDTO(EditionContextManager.get());
    } catch (IOException e) {
        // FIXME undo should be fail-safe...
        return null;
    } finally {
        EditionContextManager.get().setCurrentOperation(null);
        editionContextManager.destroy();
    }
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) NotFoundException(alien4cloud.exception.NotFoundException) AbstractEditorOperation(org.alien4cloud.tosca.editor.operations.AbstractEditorOperation) Topology(org.alien4cloud.tosca.model.templates.Topology) IOException(java.io.IOException) EditorIOException(org.alien4cloud.tosca.editor.exception.EditorIOException) IEditorOperationProcessor(org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor)

Example 29 with NotFoundException

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

the class UnsetNodePropertyAsInputProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, UnsetNodePropertyAsInputOperation operation, NodeTemplate nodeTemplate) {
    // check if the node property value is a get_input
    AbstractPropertyValue currentValue = nodeTemplate.getProperties().get(operation.getPropertyName());
    if (!isGetInput(currentValue)) {
        throw new NotFoundException("Property {} of node {} is not associated to an input.", 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 association from property [ {} ] of the node template [ {} ] to an input 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 30 with NotFoundException

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

the class SetNodeCapabilityPropertyAsOutputProcessor method check.

private void check(SetNodeCapabilityPropertyAsOutputOperation 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());
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException)

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