Search in sources :

Example 31 with NodeTemplate

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

the class LocationResourceService method addResourceTemplate.

private LocationResourceTemplate addResourceTemplate(Location location, String resourceName, String resourceTypeName) {
    NodeType resourceType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, resourceTypeName, location.getDependencies());
    NodeTemplate nodeTemplate = templateBuilder.buildNodeTemplate(location.getDependencies(), resourceType);
    LocationResourceTemplate locationResourceTemplate = new LocationResourceTemplate();
    locationResourceTemplate.setGenerated(false);
    fillAndSaveLocationResourceTemplate(location, resourceName, locationResourceTemplate, resourceType, nodeTemplate);
    return locationResourceTemplate;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) PolicyLocationResourceTemplate(alien4cloud.model.orchestrators.locations.PolicyLocationResourceTemplate) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType)

Example 32 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate 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 33 with NodeTemplate

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

the class FunctionEvaluator method extractRuntimeInformationProperty.

/**
 * Extract property value from runtime informations
 *
 * @param topology
 * @param propertyOrAttributeName
 * @param nodes
 * @return
 */
private static String extractRuntimeInformationProperty(Topology topology, String propertyOrAttributeName, List<? extends IPaaSTemplate> nodes) {
    AbstractPropertyValue propertyOrAttributeValue;
    NodeTemplate template = null;
    for (IPaaSTemplate node : nodes) {
        String nodeName = node.getId();
        template = topology.getNodeTemplates().get(nodeName);
        if (template != null && template.getProperties() != null) {
            propertyOrAttributeValue = template.getProperties().get(propertyOrAttributeName);
            if (propertyOrAttributeValue != null) {
                return PropertyUtil.getScalarValue(propertyOrAttributeValue);
            }
        }
    }
    log.warn("Couldn't find property [ {} ] of node [ {} ]", propertyOrAttributeName, nodes);
    return "[" + nodes + "." + propertyOrAttributeName + "=Error!]";
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) IPaaSTemplate(alien4cloud.paas.IPaaSTemplate) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 34 with NodeTemplate

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

the class LocationResourceGeneratorService method generateComputeFromImageAndFlavor.

/**
 * Generate resources of type compute given a set of images and flavors
 *
 * @param imageContext
 * @param flavorContext
 * @param linuxComputeContext
 * @param windowsComputeContext
 * @param resourceAccessor
 * @return
 */
public List<LocationResourceTemplate> generateComputeFromImageAndFlavor(ImageFlavorContext imageContext, ImageFlavorContext flavorContext, ComputeContext linuxComputeContext, ComputeContext windowsComputeContext, ILocationResourceAccessor resourceAccessor) {
    List<LocationResourceTemplate> images = imageContext.getTemplates();
    List<LocationResourceTemplate> flavors = flavorContext.getTemplates();
    Set<CSARDependency> dependencies = resourceAccessor.getDependencies();
    List<LocationResourceTemplate> generated = Lists.newArrayList();
    for (LocationResourceTemplate image : images) {
        for (LocationResourceTemplate flavor : flavors) {
            String defaultComputeName = generateDefaultName(image, flavor);
            int count = 0;
            ComputeContext computeContext = isWindowsImage(image) && windowsComputeContext != null ? windowsComputeContext : linuxComputeContext;
            for (NodeType indexedNodeType : computeContext.getNodeTypes()) {
                String name = StringUtils.isNotBlank(computeContext.getGeneratedNamePrefix()) ? computeContext.getGeneratedNamePrefix() : defaultComputeName;
                if (count > 0) {
                    name = name + "_" + count;
                }
                NodeTemplate node = templateBuilder.buildNodeTemplate(dependencies, indexedNodeType);
                // set the imageId
                node.getProperties().put(computeContext.getImageIdPropertyName(), image.getTemplate().getProperties().get(imageContext.getIdPropertyName()));
                // set the flavorId
                node.getProperties().put(computeContext.getFlavorIdPropertyName(), flavor.getTemplate().getProperties().get(flavorContext.getIdPropertyName()));
                // copy os and host capabilities properties
                copyCapabilityBasedOnTheType(image.getTemplate(), node, "os");
                copyCapabilityBasedOnTheType(flavor.getTemplate(), node, "host");
                LocationResourceTemplate resource = new LocationResourceTemplate();
                resource.setService(false);
                resource.setTemplate(node);
                resource.setName(name);
                count++;
                generated.add(resource);
            }
        }
    }
    return generated;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 35 with NodeTemplate

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

the class RuntimeController method validateCommand.

private void validateCommand(OperationExecRequest operationRequest, Topology topology) throws ConstraintFunctionalException {
    NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operationRequest.getNodeTemplateName(), TopologyUtils.getNodeTemplates(topology));
    NodeType indexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
    Map<String, Interface> interfaces = IndexedModelUtils.mergeInterfaces(indexedNodeType.getInterfaces(), nodeTemplate.getInterfaces());
    if (interfaces == null || interfaces.get(operationRequest.getInterfaceName()) == null) {
        throw new NotFoundException("Interface [" + operationRequest.getInterfaceName() + "] not found in the node template [" + operationRequest.getNodeTemplateName() + "] related to [" + indexedNodeType.getId() + "]");
    }
    Interface interfass = interfaces.get(operationRequest.getInterfaceName());
    validateOperation(interfass, operationRequest, topology.getDependencies());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Aggregations

NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)162 NodeType (org.alien4cloud.tosca.model.types.NodeType)52 Map (java.util.Map)40 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)37 Test (org.junit.Test)32 Capability (org.alien4cloud.tosca.model.templates.Capability)27 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)25 Topology (org.alien4cloud.tosca.model.templates.Topology)22 NotFoundException (alien4cloud.exception.NotFoundException)17 Then (cucumber.api.java.en.Then)15 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)15 HashMap (java.util.HashMap)14 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)13 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)13 TopologyDTO (alien4cloud.topology.TopologyDTO)12 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)12 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)11 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)11 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)10 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)10