use of alien4cloud.exception.InvalidNameException 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.InvalidNameException in project alien4cloud by alien4cloud.
the class AddRelationshipProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, AddRelationshipOperation operation, NodeTemplate sourceNode) {
if (operation.getRelationshipName() == null || operation.getRelationshipName().isEmpty()) {
throw new InvalidNameException("relationshipName", operation.getRelationshipName(), "Not null or empty");
}
if (AlienUtils.safe(sourceNode.getRelationships()).containsKey(operation.getRelationshipName())) {
throw new AlreadyExistException("Relationship " + operation.getRelationshipName() + " already exist on node " + operation.getNodeName());
}
if (sourceNode.getRequirements() == null || sourceNode.getRequirements().get(operation.getRequirementName()) == null) {
throw new NotFoundException("Unable to find requirement with name <" + operation.getRequirementName() + "> on the source node" + operation.getNodeName());
}
Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
// ensure that the target node exists
TopologyUtils.getNodeTemplate(topology.getId(), operation.getTarget(), nodeTemplates);
// We don't use the tosca context as the relationship type may not be in dependencies yet (that's why we use the load type below).
RelationshipType indexedRelationshipType = toscaTypeSearchService.find(RelationshipType.class, operation.getRelationshipType(), operation.getRelationshipVersion());
if (indexedRelationshipType == null) {
throw new NotFoundException(RelationshipType.class.getName(), operation.getRelationshipType() + ":" + operation.getRelationshipVersion(), "Unable to find relationship type to create template in topology.");
}
boolean upperBoundReachedSource = topologyRequirementBoundsValidationServices.isRequirementUpperBoundReachedForSource(sourceNode, operation.getRequirementName(), topology.getDependencies());
if (upperBoundReachedSource) {
// throw exception here
throw new RequirementBoundException(operation.getNodeName(), operation.getRequirementName());
}
boolean upperBoundReachedTarget = topologyCapabilityBoundsValidationServices.isCapabilityUpperBoundReachedForTarget(operation.getTarget(), nodeTemplates, operation.getTargetedCapabilityName(), topology.getDependencies());
// return with a rest response error
if (upperBoundReachedTarget) {
throw new CapabilityBoundException(operation.getTarget(), operation.getTargetedCapabilityName());
}
topologyService.loadType(topology, indexedRelationshipType);
NodeTemplate newSourceNode = topology.getNodeTemplates().get(sourceNode.getName());
if (sourceNode != newSourceNode) {
// topology has been reloaded
sourceNode = newSourceNode;
}
Map<String, RelationshipTemplate> relationships = sourceNode.getRelationships();
if (relationships == null) {
relationships = Maps.newHashMap();
sourceNode.setRelationships(relationships);
}
RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
relationshipTemplate.setName(operation.getRelationshipName());
relationshipTemplate.setTarget(operation.getTarget());
relationshipTemplate.setTargetedCapabilityName(operation.getTargetedCapabilityName());
relationshipTemplate.setRequirementName(operation.getRequirementName());
relationshipTemplate.setRequirementType(sourceNode.getRequirements().get(operation.getRequirementName()).getType());
relationshipTemplate.setType(indexedRelationshipType.getElementId());
relationshipTemplate.setArtifacts(newLinkedHashMap(indexedRelationshipType.getArtifacts()));
relationshipTemplate.setAttributes(newLinkedHashMap(indexedRelationshipType.getAttributes()));
Map<String, AbstractPropertyValue> properties = new LinkedHashMap<String, AbstractPropertyValue>();
TemplateBuilder.fillProperties(properties, indexedRelationshipType.getProperties(), null);
relationshipTemplate.setProperties(properties);
relationships.put(operation.getRelationshipName(), relationshipTemplate);
TopologyContext topologyContext = workflowBuilderService.buildTopologyContext(topology, csar);
workflowBuilderService.addRelationship(topologyContext, operation.getNodeName(), operation.getRelationshipName());
log.debug("Added relationship to the topology [" + topology.getId() + "], node name [" + operation.getNodeName() + "], relationship name [" + operation.getRelationshipName() + "]");
}
use of alien4cloud.exception.InvalidNameException 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);
}
use of alien4cloud.exception.InvalidNameException 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());
}
Aggregations