Search in sources :

Example 1 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project yorc-a4c-plugin by ystia.

the class ShowTopology method printNode.

/**
 * Print info about a Node
 * @param node
 */
private static void printNode(PaaSNodeTemplate node) {
    log.debug("******* Compute Node " + node.getId() + " *******");
    NodeTemplate nt = node.getTemplate();
    log.debug("CsarPath = " + node.getCsarPath());
    log.debug("Type = " + nt.getType());
    // Children
    List<PaaSNodeTemplate> children = node.getChildren();
    for (PaaSNodeTemplate child : children) {
        log.info("Child: " + child.getId());
    }
    // properties
    for (String prop : nt.getProperties().keySet()) {
        AbstractPropertyValue absval = nt.getProperties().get(prop);
        if (absval instanceof ScalarPropertyValue) {
            ScalarPropertyValue scaval = (ScalarPropertyValue) absval;
            log.debug(">> Property: " + prop + "=" + scaval.getValue());
        }
    }
    // Attributes
    Map<String, IValue> attrs = nt.getAttributes();
    if (attrs != null) {
        for (String attname : attrs.keySet()) {
            IValue att = attrs.get(attname);
            log.debug(">> Attribute: " + attname + "=" + att);
        }
    }
    // capabilities
    Map<String, Capability> capabilities = nt.getCapabilities();
    if (capabilities != null) {
        for (String capname : capabilities.keySet()) {
            Capability cap = capabilities.get(capname);
            log.debug(">> Capability " + capname);
            log.debug("type : " + cap.getType());
            log.debug("properties : " + cap.getProperties());
        }
    }
    // requirements
    Map<String, Requirement> requirements = nt.getRequirements();
    if (requirements != null) {
        for (String reqname : requirements.keySet()) {
            Requirement req = requirements.get(reqname);
            log.debug(">> Requirement: " + reqname);
            log.debug("type : " + req.getType());
            log.debug("properties : " + req.getProperties());
        }
    }
    // relationships
    Map<String, RelationshipTemplate> relations = nt.getRelationships();
    if (relations != null) {
        for (String relname : relations.keySet()) {
            RelationshipTemplate rel = relations.get(relname);
            log.debug(">> Relationship: " + relname);
            log.debug("type : " + rel.getType());
            log.debug("properties : " + rel.getProperties());
        }
    }
    // artifacts
    Map<String, DeploymentArtifact> artifacts = nt.getArtifacts();
    if (artifacts != null) {
        for (DeploymentArtifact art : artifacts.values()) {
            printArtifact(art);
        }
    }
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) Requirement(org.alien4cloud.tosca.model.templates.Requirement) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate)

Example 2 with RelationshipTemplate

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

the class PaaSUtilsTest method buildFakePaaSRelTemplate.

private PaaSRelationshipTemplate buildFakePaaSRelTemplate(String source, String target, String targetedCapability) {
    PaaSRelationshipTemplate fakePaaSRelTemplate = Mockito.mock(PaaSRelationshipTemplate.class);
    RelationshipTemplate relationshipTemplate = buildFakeRelationShip(target, targetedCapability);
    Mockito.when(fakePaaSRelTemplate.getTemplate()).thenReturn(relationshipTemplate);
    Map<String, Operation> operations = Maps.newHashMap();
    operations.put(operation1, buildFakeOperation());
    Map<String, Interface> interfaces = Maps.newHashMap();
    interfaces.put(interface1, buildFakeInterface(operations));
    Mockito.when(fakePaaSRelTemplate.getInterfaces()).thenReturn(interfaces);
    Mockito.when(fakePaaSRelTemplate.getSource()).thenReturn(source);
    return fakePaaSRelTemplate;
}
Also used : PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate)

Example 3 with RelationshipTemplate

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

the class FunctionEvaluator method doGetProperty.

private static AbstractPropertyValue doGetProperty(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate targetTemplate, FunctionPropertyValue function) {
    if (targetTemplate == null) {
        return null;
    }
    // If a requirement or capability name is defined then it is applied to the node template.
    if (function.getCapabilityOrRequirementName() != null) {
        if (targetTemplate instanceof RelationshipTemplate) {
            throw new IllegalArgumentException("Get property that specifies a capability or relationship target must be placed on a node template and not a relationship template.");
        }
        AbstractPropertyValue propertyValue = null;
        Capability targetCapability = safe(((NodeTemplate) targetTemplate).getCapabilities()).get(function.getCapabilityOrRequirementName());
        if (targetCapability != null) {
            propertyValue = getFromPath(evaluatorContext, targetTemplate, targetCapability.getProperties(), function.getElementNameToFetch());
        }
        if (propertyValue == null) {
            Requirement requirement = safe(((NodeTemplate) targetTemplate).getRequirements()).get(function.getCapabilityOrRequirementName());
            if (requirement != null) {
                propertyValue = getFromPath(evaluatorContext, targetTemplate, requirement.getProperties(), function.getElementNameToFetch());
            }
        }
        if (propertyValue == null) {
            // try to find the value from the host node.
            propertyValue = doGetProperty(evaluatorContext, TopologyNavigationUtil.getImmediateHostTemplate(evaluatorContext.getTopology(), (NodeTemplate) targetTemplate), function);
        }
        return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);
    }
    // Try to fetch from the node.
    AbstractPropertyValue propertyValue = getFromPath(evaluatorContext, targetTemplate, targetTemplate.getProperties(), function.getElementNameToFetch());
    if (propertyValue == null && targetTemplate instanceof NodeTemplate) {
        propertyValue = doGetProperty(evaluatorContext, TopologyNavigationUtil.getImmediateHostTemplate(evaluatorContext.getTopology(), (NodeTemplate) targetTemplate), function);
    }
    // if the property refers to a function (get_input/get_property then try to resolve it).
    return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);
}
Also used : Requirement(org.alien4cloud.tosca.model.templates.Requirement) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 4 with RelationshipTemplate

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

the class ToscaSerializerTest method simpleTest.

@Ignore
@Test
public void simpleTest() throws IOException, URISyntaxException {
    Topology topology = new Topology();
    topology.setDependencies(new HashSet<CSARDependency>());
    topology.getDependencies().add(new CSARDependency("name1", "1.0"));
    topology.getDependencies().add(new CSARDependency("name2", "2.0"));
    topology.setInputs(new HashMap<String, PropertyDefinition>());
    PropertyDefinition pd1 = new PropertyDefinition();
    pd1.setType("string");
    pd1.setConstraints(getConstraintList());
    pd1.setDescription("A description");
    topology.getInputs().put("input1", pd1);
    PropertyDefinition pd2 = new PropertyDefinition();
    pd2.setType("integer");
    pd2.setRequired(false);
    pd2.setDefault(new ScalarPropertyValue("10"));
    topology.getInputs().put("input2", pd2);
    PropertyDefinition pd3 = new PropertyDefinition();
    pd3.setType("map");
    pd3.setRequired(false);
    PropertyDefinition entrySchema = new PropertyDefinition();
    entrySchema.setType("integer");
    pd3.setEntrySchema(entrySchema);
    topology.getInputs().put("input3", pd3);
    topology.setNodeTemplates(new HashMap<String, NodeTemplate>());
    topology.getNodeTemplates().put("node1", new NodeTemplate());
    topology.getNodeTemplates().get("node1").setType("the.node.Type");
    topology.getNodeTemplates().get("node1").setProperties(buildSamplePropertyValueMap());
    topology.getNodeTemplates().get("node1").setRelationships(new HashMap<String, RelationshipTemplate>());
    topology.getNodeTemplates().get("node1").getRelationships().put("hostedOn", new RelationshipTemplate());
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setTarget("compute2");
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setRequirementType("capabilities.Capa");
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setRequirementName("host");
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setType("relationship.Rel");
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setProperties(buildSamplePropertyValueMap());
    topology.getNodeTemplates().get("node1").setCapabilities(new HashMap<String, Capability>());
    Capability capability = new Capability();
    capability.setProperties(buildSamplePropertyValueMap());
    topology.getNodeTemplates().get("node1").getCapabilities().put("capa1", capability);
    // this capability should not appear
    topology.getNodeTemplates().get("node1").getCapabilities().put("capa2", new Capability());
    topology.getNodeTemplates().get("node1").setArtifacts(new HashMap<String, DeploymentArtifact>());
    DeploymentArtifact da = new DeploymentArtifact();
    da.setArtifactName("artifact.war");
    da.setArtifactRef("010203904872876723");
    da.setArtifactType("artifacttypes.Artifact");
    topology.getNodeTemplates().get("node1").getArtifacts().put("artifact1", da);
    topology.setOutputProperties(new HashMap<String, Set<String>>());
    topology.getOutputProperties().put("node1", Sets.newHashSet("prop1", "prop2"));
    topology.setOutputAttributes(new HashMap<String, Set<String>>());
    topology.getOutputAttributes().put("node1", Sets.newHashSet("att1", "att2"));
    Map<String, Object> velocityCtx = new HashMap<String, Object>();
    velocityCtx.put("topology", topology);
    velocityCtx.put("template_name", "template-id");
    velocityCtx.put("template_version", "1.0.0-SNAPSHOT");
    velocityCtx.put("template_author", "Foo Bar");
    velocityCtx.put("application_description", "Here is a \nmultiline description");
    StringWriter writer = new StringWriter();
    VelocityUtil.generate("org/alien4cloud/tosca/exporter/topology-alien_dsl_1_4_0.yml.vm", writer, velocityCtx);
    System.out.println(writer.toString());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Capability(org.alien4cloud.tosca.model.templates.Capability) HashMap(java.util.HashMap) Topology(org.alien4cloud.tosca.model.templates.Topology) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) StringWriter(java.io.StringWriter) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with RelationshipTemplate

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

the class TopologyTreeBuilderService method buildPaaSNodeTemplates.

/**
 * Fetch information from the repository to complete the topology node template informations with additional data such as artifacts paths etc.
 *
 * @param topology The topology for which to build PaaSNodeTemplate map.
 * @return A map of PaaSNodeTemplate that match the one of the NodeTempaltes in the given topology (and filled with artifact paths etc.).
 */
public Map<String, PaaSNodeTemplate> buildPaaSNodeTemplates(Topology topology) {
    Map<String, PaaSNodeTemplate> nodeTemplates = Maps.newHashMap();
    // Fill in PaaSNodeTemplate by fetching node types and CSAR path from the repositories.
    if (topology.getNodeTemplates() != null) {
        for (Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
            NodeTemplate template = templateEntry.getValue();
            PaaSNodeTemplate paaSNodeTemplate = new PaaSNodeTemplate(templateEntry.getKey(), template);
            fillType(topology, template, paaSNodeTemplate, NodeType.class);
            mergeInterfaces(paaSNodeTemplate, template);
            if (template.getRelationships() != null) {
                for (Map.Entry<String, RelationshipTemplate> relationshipEntry : template.getRelationships().entrySet()) {
                    RelationshipTemplate relationshipTemplate = relationshipEntry.getValue();
                    PaaSRelationshipTemplate paaSRelationshipTemplate = new PaaSRelationshipTemplate(relationshipEntry.getKey(), relationshipTemplate, paaSNodeTemplate.getId());
                    fillType(topology, relationshipTemplate, paaSRelationshipTemplate, RelationshipType.class);
                    mergeInterfaces(paaSRelationshipTemplate, relationshipTemplate);
                    paaSNodeTemplate.getRelationshipTemplates().add(paaSRelationshipTemplate);
                }
            }
            Capability scalableCapability = TopologyUtils.getScalableCapability(topology, templateEntry.getKey(), false);
            if (scalableCapability != null) {
                ScalingPolicy scalingPolicy = TopologyUtils.getScalingPolicy(scalableCapability);
                // A node with a scaling policy 1, 1, 1 is a simple node and so do not set scaling policy
                if (!ScalingPolicy.NOT_SCALABLE_POLICY.equals(scalingPolicy)) {
                    paaSNodeTemplate.setScalingPolicy(scalingPolicy);
                }
            }
            if (topology.getGroups() != null) {
                Set<String> nodeGroups = Sets.newHashSet();
                for (Map.Entry<String, NodeGroup> groupEntry : topology.getGroups().entrySet()) {
                    if (groupEntry.getValue().getMembers() != null && groupEntry.getValue().getMembers().contains(templateEntry.getKey())) {
                        nodeGroups.add(groupEntry.getKey());
                    }
                }
                paaSNodeTemplate.setGroups(nodeGroups);
            }
            nodeTemplates.put(templateEntry.getKey(), paaSNodeTemplate);
        }
    }
    return nodeTemplates;
}
Also used : ScalingPolicy(org.alien4cloud.tosca.model.templates.ScalingPolicy) Capability(org.alien4cloud.tosca.model.templates.Capability) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate) Map(java.util.Map) HashMap(java.util.HashMap) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

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