Search in sources :

Example 11 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.

the class TopologyTreeBuilderService method processRelationship.

private void processRelationship(PaaSNodeTemplate paaSNodeTemplate, Map<String, PaaSNodeTemplate> nodeTemplates) {
    PaaSRelationshipTemplate hostedOnRelationship = getPaaSRelationshipTemplateFromType(paaSNodeTemplate, NormativeRelationshipConstants.HOSTED_ON);
    if (hostedOnRelationship != null) {
        String target = hostedOnRelationship.getTemplate().getTarget();
        PaaSNodeTemplate parent = nodeTemplates.get(target);
        parent.getChildren().add(paaSNodeTemplate);
        paaSNodeTemplate.setParent(parent);
    }
    // Relationships are defined from sources to target. We have to make sure that target node also has the relationship injected.
    List<PaaSRelationshipTemplate> allRelationships = getPaaSRelationshipsTemplateFromType(paaSNodeTemplate, NormativeRelationshipConstants.ROOT);
    for (PaaSRelationshipTemplate relationship : allRelationships) {
        // inject the relationship in it's target.
        String target = relationship.getTemplate().getTarget();
        nodeTemplates.get(target).getRelationshipTemplates().add(relationship);
    }
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate)

Example 12 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.

the class TopologyTreeBuilderService method processBlockStorage.

private void processBlockStorage(PaaSNodeTemplate paaSNodeTemplate, Map<String, PaaSNodeTemplate> nodeTemplates) {
    PaaSRelationshipTemplate attachTo = getPaaSRelationshipTemplateFromType(paaSNodeTemplate, NormativeRelationshipConstants.ATTACH_TO);
    if (attachTo != null) {
        String target = attachTo.getTemplate().getTarget();
        PaaSNodeTemplate parent = nodeTemplates.get(target);
        parent.getStorageNodes().add(paaSNodeTemplate);
        paaSNodeTemplate.setParent(parent);
    }
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate)

Example 13 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.

the class TopologyTreeBuilderService method processOperationsOutputs.

/**
 * For every templates (nodes and relationship), check the attributes and interfaces operations input parameters for usage of the get_operation_output
 * function.
 * if found, register the referenced output on the related operation
 *
 * @param paaSNodeTemplates
 */
private void processOperationsOutputs(final Map<String, PaaSNodeTemplate> paaSNodeTemplates) {
    // TODO: try to cache already processed nodes
    for (PaaSNodeTemplate paaSNodeTemplate : paaSNodeTemplates.values()) {
        processAttributesForOperationOutputs(paaSNodeTemplate, paaSNodeTemplates);
        processOperationsInputsForOperationOutputs(paaSNodeTemplate, paaSNodeTemplates);
        // do the same for the relationships
        for (PaaSRelationshipTemplate paaSRelationshipTemplate : paaSNodeTemplate.getRelationshipTemplates()) {
            processAttributesForOperationOutputs(paaSRelationshipTemplate, paaSNodeTemplates);
            processOperationsInputsForOperationOutputs(paaSRelationshipTemplate, paaSNodeTemplates);
        }
    }
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate)

Example 14 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.

the class TopologyTreeBuilderService method processNetwork.

private void processNetwork(PaaSNodeTemplate paaSNodeTemplate, Map<String, PaaSNodeTemplate> nodeTemplates) {
    List<PaaSRelationshipTemplate> networkRelationships = getPaaSRelationshipsTemplateFromType(paaSNodeTemplate, NormativeRelationshipConstants.NETWORK);
    List<PaaSNodeTemplate> networks = Lists.newArrayList();
    if (networkRelationships != null && !networkRelationships.isEmpty()) {
        for (PaaSRelationshipTemplate networkRelationship : networkRelationships) {
            String target = networkRelationship.getTemplate().getTarget();
            PaaSNodeTemplate network = nodeTemplates.get(target);
            networks.add(network);
            network.setParent(paaSNodeTemplate);
        }
    }
    paaSNodeTemplate.setNetworkNodes(networks);
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate)

Example 15 with PaaSNodeTemplate

use of alien4cloud.paas.model.PaaSNodeTemplate 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

PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)21 PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)7 Test (org.junit.Test)7 AbstractToscaParserSimpleProfileTest (alien4cloud.tosca.parser.AbstractToscaParserSimpleProfileTest)5 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)5 PaaSTopology (alien4cloud.paas.model.PaaSTopology)4 Capability (org.alien4cloud.tosca.model.templates.Capability)3 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 NodeGroup (org.alien4cloud.tosca.model.templates.NodeGroup)2 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)2 Location (alien4cloud.model.orchestrators.locations.Location)1 ParsingException (alien4cloud.tosca.parser.ParsingException)1 Closeable (java.io.Closeable)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1