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