Search in sources :

Example 31 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class TopologyServiceCore method getIndexedRelationshipTypesFromTopology.

/**
 * Get IndexedRelationshipType in a topology
 *
 * @param topology the topology to find all relationship types
 * @param failOnTypeNotFound
 * @return the map containing rel
 */
public Map<String, RelationshipType> getIndexedRelationshipTypesFromTopology(Topology topology, boolean failOnTypeNotFound) {
    Map<String, RelationshipType> relationshipTypes = Maps.newHashMap();
    if (topology.getNodeTemplates() == null) {
        return relationshipTypes;
    }
    for (Map.Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
        NodeTemplate template = templateEntry.getValue();
        if (template.getRelationships() != null) {
            for (Map.Entry<String, RelationshipTemplate> relationshipEntry : template.getRelationships().entrySet()) {
                RelationshipTemplate relationship = relationshipEntry.getValue();
                if (!relationshipTypes.containsKey(relationship.getType())) {
                    RelationshipType relationshipType = getFromContextIfDefined(RelationshipType.class, relationship.getType(), topology.getDependencies(), failOnTypeNotFound);
                    relationshipTypes.put(relationship.getType(), relationshipType);
                }
            }
        }
    }
    if (topology.getSubstitutionMapping() != null && topology.getSubstitutionMapping().getSubstitutionType() != null) {
        for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getCapabilities()).values()) {
            addRelationshipTypeFromSubstitutionTarget(topology, relationshipTypes, substitutionTarget, failOnTypeNotFound);
        }
        for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getRequirements()).values()) {
            addRelationshipTypeFromSubstitutionTarget(topology, relationshipTypes, substitutionTarget, failOnTypeNotFound);
        }
    }
    return relationshipTypes;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) Map(java.util.Map)

Example 32 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class NodeFilterValidationService method validateRequirementFilters.

/**
 * Performs validation of the node filters to check that relationships targets the filter requirements.
 */
private List<NodeFiltersTask> validateRequirementFilters(Topology topology, boolean skipInputs) {
    List<NodeFiltersTask> toReturnTaskList = Lists.newArrayList();
    Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
    Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, true, true);
    Map<String, CapabilityType> capabilityTypes = topologyServiceCore.getIndexedCapabilityTypesFromTopology(topology);
    for (Map.Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
        Map<String, RelationshipTemplate> relationshipsMap = nodeTempEntry.getValue().getRelationships();
        if (relationshipsMap == null || relationshipsMap.isEmpty()) {
            continue;
        }
        NodeType sourceNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTempEntry.getValue().getType(), topology.getDependencies());
        if (sourceNodeType.isAbstract()) {
            continue;
        }
        NodeFiltersTask task = new NodeFiltersTask();
        task.setNodeTemplateName(nodeTempEntry.getKey());
        task.setCode(TaskCode.NODE_FILTER_INVALID);
        task.setComponent(sourceNodeType);
        task.setNodeFiltersToSatisfy(Lists.<NodeFilterToSatisfy>newArrayList());
        validateFiltersForNode(sourceNodeType, relationshipsMap, topology, nodeTypes, capabilityTypes, task, skipInputs);
        if (!task.getNodeFiltersToSatisfy().isEmpty()) {
            toReturnTaskList.add(task);
        }
    }
    return toReturnTaskList.isEmpty() ? null : toReturnTaskList;
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeFiltersTask(alien4cloud.topology.task.NodeFiltersTask) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map)

Example 33 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class DeleteFileProcessor method process.

@Override
public void process(Csar csar, Topology topology, DeleteFileOperation operation) {
    if (csar.getYamlFilePath().equals(operation.getPath())) {
        throw new InvalidPathException("Topology yaml file cannot be removed.");
    }
    TreeNode target = FileProcessorHelper.getFileTreeNode(operation.getPath());
    target.getParent().getChildren().remove(target);
    for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
        for (DeploymentArtifact artifact : safe(nodeTemplate.getArtifacts()).values()) {
            resetRemovedArtifact(artifact, operation.getPath());
        }
        cleanupInterfaces(nodeTemplate.getInterfaces(), operation.getPath());
        for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
            cleanupInterfaces(relationshipTemplate.getInterfaces(), operation.getPath());
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) TreeNode(alien4cloud.utils.TreeNode) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) InvalidPathException(org.alien4cloud.tosca.editor.exception.InvalidPathException)

Example 34 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate 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());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) InvalidNameException(alien4cloud.exception.InvalidNameException) Capability(org.alien4cloud.tosca.model.templates.Capability) NotFoundException(alien4cloud.exception.NotFoundException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 35 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class ReplaceNodeProcessor method addTheRelationshipsOnSource.

private void addTheRelationshipsOnSource(Topology topology, Map<String, Map<String, RelationshipTemplate>> relationshipDeleted) {
    for (String nodeName : relationshipDeleted.keySet()) {
        NodeTemplate nodeTemplate = safe(topology.getNodeTemplates()).get(nodeName);
        Map<String, RelationshipTemplate> relationship = relationshipDeleted.get(nodeName);
        for (String targetId : relationship.keySet()) {
            nodeTemplate.getRelationships().put(targetId, relationship.get(targetId));
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate)

Aggregations

RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)47 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)37 Map (java.util.Map)12 Capability (org.alien4cloud.tosca.model.templates.Capability)12 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)11 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7 NotFoundException (alien4cloud.exception.NotFoundException)6 PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)4 LinkedHashMap (java.util.LinkedHashMap)4 Topology (org.alien4cloud.tosca.model.templates.Topology)4 AlreadyExistException (alien4cloud.exception.AlreadyExistException)3 ParsingError (alien4cloud.tosca.parser.ParsingError)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Interface (org.alien4cloud.tosca.model.definitions.Interface)3 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)3 Requirement (org.alien4cloud.tosca.model.templates.Requirement)3 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)3 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)3