use of alien4cloud.model.common.Tag in project alien4cloud by alien4cloud.
the class ToscaTypeIndexerService method deleteElement.
private void deleteElement(AbstractToscaType element) {
Tag iconTag = ArchiveImageLoader.getIconTag(element.getTags());
alienDAO.delete(element.getClass(), element.getId());
if (iconTag != null) {
if (!hasElementWithTag(element.getClass(), iconTag.getName(), iconTag.getValue())) {
imageDAO.deleteAll(iconTag.getValue());
}
}
}
use of alien4cloud.model.common.Tag in project alien4cloud by alien4cloud.
the class AddNodeProcessor method process.
@Override
public void process(Csar csar, Topology topology, AddNodeOperation operation) {
NameValidationUtils.validateNodeName(operation.getNodeName());
AlienUtils.failIfExists(topology.getNodeTemplates(), operation.getNodeName(), "A node template with the given name {} already exists in the topology {}.", operation.getNodeName(), topology.getId());
NodeType nodeType = toscaTypeSearchService.findByIdOrFail(NodeType.class, operation.getIndexedNodeTypeId());
if (nodeType.getSubstitutionTopologyId() != null) {
// it's a try to add this topology's type
if (nodeType.getSubstitutionTopologyId().equals(topology.getId())) {
throw new CyclicReferenceException("Cyclic reference : a topology template can not reference itself");
}
// detect try to add a substitution topology that indirectly reference this one
topologyCompositionService.recursivelyDetectTopologyCompositionCyclicReference(topology.getId(), nodeType.getSubstitutionTopologyId());
}
if (topology.getNodeTemplates() == null) {
topology.setNodeTemplates(new LinkedHashMap<>());
}
log.debug("Create node template [ {} ]", operation.getNodeName());
NodeType loadedIndexedNodeType = topologyService.loadType(topology, nodeType);
NodeTemplate nodeTemplate = TemplateBuilder.buildNodeTemplate(loadedIndexedNodeType);
nodeTemplate.setName(operation.getNodeName());
if (operation.getCoords() != null) {
// Set the position information of the node as meta-data.
nodeTemplate.setTags(Lists.newArrayList(new Tag(Constants.X_META, String.valueOf(operation.getCoords().getX())), new Tag(Constants.Y_META, String.valueOf(operation.getCoords().getY()))));
}
topology.getNodeTemplates().put(operation.getNodeName(), nodeTemplate);
log.debug("Adding a new Node template <" + operation.getNodeName() + "> bound to the node type <" + operation.getIndexedNodeTypeId() + "> to the topology <" + topology.getId() + "> .");
TopologyContext topologyContext = workflowBuilderService.buildTopologyContext(topology, csar);
workflowBuilderService.addNode(topologyContext, operation.getNodeName());
if (!operation.isSkipAutoCompletion()) {
danglingRequirementService.addDanglingRequirements(topology, topologyContext, nodeTemplate, operation.getRequirementSkipAutoCompletion());
}
}
use of alien4cloud.model.common.Tag in project alien4cloud by alien4cloud.
the class UpdateNodePositionProcessor method processNodeOperation.
@Override
protected void processNodeOperation(Csar csar, Topology topology, UpdateNodePositionOperation operation, NodeTemplate nodeTemplate) {
// Set the position information of the node as meta-data.
if (nodeTemplate.getTags() == null) {
nodeTemplate.setTags(Lists.newArrayList(new Tag(Constants.X_META, String.valueOf(operation.getCoords().getX())), new Tag(Constants.Y_META, String.valueOf(operation.getCoords().getY()))));
return;
}
boolean xSet = false;
boolean ySet = false;
for (Tag tag : nodeTemplate.getTags()) {
if (Constants.X_META.equals(tag.getName())) {
tag.setValue(String.valueOf(operation.getCoords().getX()));
xSet = true;
}
if (Constants.Y_META.equals(tag.getName())) {
tag.setValue(String.valueOf(operation.getCoords().getY()));
ySet = true;
}
}
if (!xSet) {
nodeTemplate.getTags().add(new Tag(Constants.X_META, String.valueOf(operation.getCoords().getX())));
}
if (!ySet) {
nodeTemplate.getTags().add(new Tag(Constants.Y_META, String.valueOf(operation.getCoords().getY())));
}
}
use of alien4cloud.model.common.Tag in project alien4cloud by alien4cloud.
the class TagService method upsertTag.
/**
* Add or update a tag to a taggable resource.
*
* @param resource The resource for which to add or update the given tag.
* @param key The key/name of the tag.
* @param value The value of the tag.
*/
public void upsertTag(ITaggableResource resource, String key, String value) {
if (StringUtils.isEmpty(key)) {
throw new IllegalArgumentException("The id of a tag cannot be null or empty.");
} else if (key.equals(AlienConstants.ALIEN_INTERNAL_TAG)) {
throw new InternalError("Tag update operation failed. Could not update internal alien tag <" + AlienConstants.ALIEN_INTERNAL_TAG + ">.");
}
if (resource.getTags() == null) {
resource.setTags(Lists.<Tag>newArrayList());
}
Tag newTag = new Tag(key, value);
if (resource.getTags().contains(newTag)) {
resource.getTags().remove(newTag);
}
resource.getTags().add(newTag);
alienDAO.save(resource);
}
use of alien4cloud.model.common.Tag in project alien4cloud by alien4cloud.
the class TagService method removeTag.
/**
* Remove an existing tag.
*
* @param resource The resource from which to remove the tag.
* @param key The key of the tag to remove.
*/
public void removeTag(ITaggableResource resource, String key) {
if (StringUtils.isEmpty(key)) {
throw new IllegalArgumentException("The id of a tag cannot be null or empty.");
} else if (key.equals(AlienConstants.ALIEN_INTERNAL_TAG)) {
throw new InternalError("Tag delete operation failed. Could not delete internal alien tag <" + AlienConstants.ALIEN_INTERNAL_TAG + ">.");
}
if (resource.getTags() != null) {
resource.getTags().remove(new Tag(key, null));
alienDAO.save(resource);
}
}
Aggregations