Search in sources :

Example 6 with PaaSRelationshipTemplate

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

use of alien4cloud.paas.model.PaaSRelationshipTemplate 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 8 with PaaSRelationshipTemplate

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

Example 9 with PaaSRelationshipTemplate

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

the class PaaSUtils method processRelationshipTemplateProperties.

/**
 * Inject relationshipTemplate, source, target and targeted capability properties as input parameters for all its interfaces operations <br>
 * The injected input names are uppercased and is in form:
 * <ul>
 * <li>{@code SELF_<PROPERTY_NAME>} for relationship property
 * <li>{@code SOURCE_<PROPERTY_NAME>} for source property
 * <li>{@code TARGET_<PROPERTY_NAME>} for target property
 * <li>{@code TARGET_CAPABILITIES_<CAPABILITY_NAME>_<PROPERTY_NAME>} for capability property
 * </ul>
 * In case of name conflict, the overriding order is: (--> = overrides)
 *
 * <pre>
 * declared input --> relationship property input --> source property input --> target property input --> targeted capability property input
 * </pre>
 *
 * @param paaSRelationshipTemplate The {@link PaaSRelationshipTemplate} to process
 * @param paaSNodeTemplates All the nodes of the topology
 */
public static void processRelationshipTemplateProperties(PaaSRelationshipTemplate paaSRelationshipTemplate, Map<String, PaaSNodeTemplate> paaSNodeTemplates) {
    RelationshipTemplate template = paaSRelationshipTemplate.getTemplate();
    // inject relationship properties
    injectPropertiesAsInputs(ToscaFunctionConstants.SELF, null, template.getProperties(), paaSRelationshipTemplate.getInterfaces(), baseName -> StringUtils.joinWith(AlienUtils.DEFAULT_PREFIX_SEPARATOR, ToscaFunctionConstants.SELF, baseName));
    // inject source properties
    injectSourcePropertiesAsInputs(paaSNodeTemplates.get(paaSRelationshipTemplate.getSource()), paaSRelationshipTemplate.getInterfaces());
    // inject target properties
    injectTargetPropertiesAsInputs(paaSNodeTemplates.get(template.getTarget()), paaSRelationshipTemplate.getInterfaces());
    // inject related target capability properties
    injectTargetedCapabilityProperties(paaSNodeTemplates.get(template.getTarget()), template.getTargetedCapabilityName(), paaSRelationshipTemplate.getInterfaces());
}
Also used : PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate)

Example 10 with PaaSRelationshipTemplate

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

the class ServiceResourceRelationshipService method processService.

private void processService(PaaSNodeTemplate paaSNodeTemplate) {
    ServiceNodeTemplate serviceNodeTemplate = (ServiceNodeTemplate) paaSNodeTemplate.getTemplate();
    ServiceResource serviceResource = serviceResourceService.getOrFail(serviceNodeTemplate.getServiceResourceId());
    for (PaaSRelationshipTemplate paaSRelationshipTemplate : paaSNodeTemplate.getRelationshipTemplates()) {
        Interface templateInterface = safe(paaSRelationshipTemplate.getInterfaces()).get(ToscaRelationshipLifecycleConstants.CONFIGURE);
        if (templateInterface != null) {
            if (paaSRelationshipTemplate.getSource().equals(paaSNodeTemplate.getId())) {
                processSourceOperations(paaSRelationshipTemplate, serviceResource, templateInterface);
            } else {
                processTargetOperations(paaSRelationshipTemplate, serviceResource, templateInterface);
            }
        }
    }
}
Also used : ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) PaaSRelationshipTemplate(alien4cloud.paas.model.PaaSRelationshipTemplate) ServiceResource(alien4cloud.model.service.ServiceResource) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Aggregations

PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)10 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)7 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 Test (org.junit.Test)2 ServiceResource (alien4cloud.model.service.ServiceResource)1 AbstractToscaParserSimpleProfileTest (alien4cloud.tosca.parser.AbstractToscaParserSimpleProfileTest)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Interface (org.alien4cloud.tosca.model.definitions.Interface)1 Capability (org.alien4cloud.tosca.model.templates.Capability)1 NodeGroup (org.alien4cloud.tosca.model.templates.NodeGroup)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 ScalingPolicy (org.alien4cloud.tosca.model.templates.ScalingPolicy)1 ServiceNodeTemplate (org.alien4cloud.tosca.model.templates.ServiceNodeTemplate)1