Search in sources :

Example 6 with Tag

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());
        }
    }
}
Also used : Tag(alien4cloud.model.common.Tag)

Example 7 with Tag

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());
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Tag(alien4cloud.model.common.Tag) TopologyContext(alien4cloud.paas.wf.TopologyContext) CyclicReferenceException(alien4cloud.exception.CyclicReferenceException)

Example 8 with Tag

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())));
    }
}
Also used : Tag(alien4cloud.model.common.Tag)

Example 9 with Tag

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);
}
Also used : Tag(alien4cloud.model.common.Tag)

Example 10 with Tag

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);
    }
}
Also used : Tag(alien4cloud.model.common.Tag)

Aggregations

Tag (alien4cloud.model.common.Tag)24 NodeType (org.alien4cloud.tosca.model.types.NodeType)6 Application (alien4cloud.model.application.Application)4 Given (cucumber.api.java.en.Given)3 Test (org.junit.Test)3 When (cucumber.api.java.en.When)2 Map (java.util.Map)2 AbstractToscaType (org.alien4cloud.tosca.model.types.AbstractToscaType)2 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)2 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)2 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)1 CyclicReferenceException (alien4cloud.exception.CyclicReferenceException)1 ImageData (alien4cloud.images.ImageData)1 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 Location (alien4cloud.model.orchestrators.locations.Location)1 TopologyContext (alien4cloud.paas.wf.TopologyContext)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 Then (cucumber.api.java.en.Then)1 Method (java.lang.reflect.Method)1 LinkedHashSet (java.util.LinkedHashSet)1