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