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;
}
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());
}
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());
}
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());
}
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()));
}
Aggregations