Search in sources :

Example 91 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class LocationService method autoConfigure.

/**
 * This method calls the orchestrator plugin to try to auto-configure the
 *
 * @param orchestrator The orchestrator for which to auto-configure a location.
 * @param location The location to auto-configure
 * @return the List of {@link LocationResourceTemplate} generated from the location auto-configuration call, null is a valid answer.
 */
private List<LocationResourceTemplate> autoConfigure(Orchestrator orchestrator, Location location) throws UnsupportedOperationException {
    // get the orchestrator plugin instance
    IOrchestratorPlugin orchestratorInstance = (IOrchestratorPlugin) orchestratorPluginService.getOrFail(orchestrator.getId());
    ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
    IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
    ILocationResourceAccessor accessor = locationResourceService.accessor(location.getId());
    // let's try to auto-configure the location
    List<LocationResourceTemplate> templates = configuratorPlugin.instances(accessor);
    if (templates != null) {
        // save the instances
        for (LocationResourceTemplate template : templates) {
            // initialize the instances from data.
            template.setId(UUID.randomUUID().toString());
            template.setLocationId(location.getId());
            template.setGenerated(true);
            template.setEnabled(true);
            NodeType nodeType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, template.getTemplate().getType(), location.getDependencies());
            nodeType.getDerivedFrom().add(0, template.getTemplate().getType());
            template.setTypes(nodeType.getDerivedFrom());
            LocationTemplateCreated event = new LocationTemplateCreated(this);
            event.setTemplate(template);
            event.setLocation(location);
            event.setToscaType(nodeType);
            applicationContext.publishEvent(event);
        }
        alienDAO.save(templates.toArray(new LocationResourceTemplate[templates.size()]));
        alienDAO.save(location);
    }
    return templates;
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) ILocationResourceAccessor(alien4cloud.orchestrators.plugin.ILocationResourceAccessor) NodeType(org.alien4cloud.tosca.model.types.NodeType) LocationTemplateCreated(alien4cloud.events.LocationTemplateCreated) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 92 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class NodeMatcherService method populateLocationResourcesWithServiceResource.

/**
 * Populate this {@link LocationResources} using these {@link ServiceResource}s in order to make them available as {@link LocationResourceTemplate} for
 * matching purpose.
 *
 * TODO: Improve this ugly code to put ServiceResource in LocationResourceTemplates.
 */
private void populateLocationResourcesWithServiceResource(LocationResources locationResources, List<ServiceResource> services, String locationId) {
    for (ServiceResource serviceResource : services) {
        LocationResourceTemplate lrt = new LocationResourceTemplate();
        lrt.setService(true);
        lrt.setEnabled(true);
        // for a service we also want to display the version, so just add it to the name
        lrt.setName(serviceResource.getName() + ":" + serviceResource.getVersion());
        lrt.setId(serviceResource.getId());
        ServiceNodeTemplate serviceNodeTemplate = new ServiceNodeTemplate(serviceResource.getNodeInstance());
        lrt.setTemplate(serviceNodeTemplate);
        lrt.setLocationId(locationId);
        String serviceTypeName = serviceResource.getNodeInstance().getNodeTemplate().getType();
        List<String> types = Lists.newArrayList(serviceTypeName);
        lrt.setTypes(types);
        NodeType serviceType = toscaTypeSearchService.findOrFail(NodeType.class, serviceTypeName, serviceResource.getNodeInstance().getTypeVersion());
        types.addAll(serviceType.getDerivedFrom());
        locationResources.getNodeTypes().put(serviceTypeName, serviceType);
        Csar csar = toscaTypeSearchService.getArchive(serviceType.getArchiveName(), serviceType.getArchiveVersion());
        Set<CSARDependency> dependencies = Sets.newHashSet();
        if (csar.getDependencies() != null) {
            dependencies.addAll(csar.getDependencies());
        }
        dependencies.add(new CSARDependency(csar.getName(), csar.getVersion()));
        if (serviceType.getCapabilities() != null && !serviceType.getCapabilities().isEmpty()) {
            for (CapabilityDefinition capabilityDefinition : serviceType.getCapabilities()) {
                locationResources.getCapabilityTypes().put(capabilityDefinition.getType(), csarRepoSearchService.getRequiredElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), dependencies));
            }
        }
        locationResources.getNodeTemplates().add(lrt);
    }
}
Also used : ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) Csar(org.alien4cloud.tosca.model.Csar) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) ServiceResource(alien4cloud.model.service.ServiceResource) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 93 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class LocationResourceGeneratorService method buildComputeContext.

public ComputeContext buildComputeContext(String elementType, String namePefix, String imageIdPropertyName, String flavorIdPropertyName, ILocationResourceAccessor resourceAccessor) {
    ComputeContext context = new ComputeContext();
    context.setFlavorIdPropertyName(flavorIdPropertyName);
    context.setImageIdPropertyName(imageIdPropertyName);
    context.setGeneratedNamePrefix(namePefix);
    try {
        NodeType nodeType = resourceAccessor.getIndexedToscaElement(elementType);
        context.getNodeTypes().add(nodeType);
    } catch (NotFoundException e) {
        log.warn("No compute found with the element id: " + elementType, e);
    }
    return context;
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException)

Example 94 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class TopologyService method initializeTypeLoader.

private ToscaTypeLoader initializeTypeLoader(Topology topology, boolean failOnTypeNotFound) {
    // FIXME we should use ToscaContext here, and why not allowing the caller to pass ona Context?
    ToscaTypeLoader loader = new ToscaTypeLoader(csarDependencyLoader);
    Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, false, failOnTypeNotFound);
    Map<String, RelationshipType> relationshipTypes = topologyServiceCore.getIndexedRelationshipTypesFromTopology(topology, failOnTypeNotFound);
    Map<String, PolicyType> policyTypes = topologyServiceCore.getPolicyTypesFromTopology(topology, failOnTypeNotFound);
    for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
        NodeType nodeType = nodeTypes.get(nodeTemplate.getType());
        // just load found types: the type might be null when failOnTypeNotFound is set to false.
        if (nodeType != null) {
            loader.loadType(nodeTemplate.getType(), csarDependencyLoader.buildDependencyBean(nodeType.getArchiveName(), nodeType.getArchiveVersion()));
        }
        for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
            RelationshipType relationshipType = relationshipTypes.get(relationshipTemplate.getType());
            // just load found types: the type might be null when failOnTypeNotFound is set to false.
            if (relationshipType != null) {
                loader.loadType(relationshipTemplate.getType(), csarDependencyLoader.buildDependencyBean(relationshipType.getArchiveName(), relationshipType.getArchiveVersion()));
            }
        }
    }
    for (PolicyTemplate policyTemplate : safe(topology.getPolicies()).values()) {
        PolicyType policyType = policyTypes.get(policyTemplate.getType());
        if (policyType != null) {
            loader.loadType(policyTemplate.getType(), csarDependencyLoader.buildDependencyBean(policyType.getArchiveName(), policyType.getArchiveVersion()));
        }
    }
    if (topology.getSubstitutionMapping() != null && topology.getSubstitutionMapping().getSubstitutionType() != null) {
        NodeType substitutionType = nodeTypes.get(topology.getSubstitutionMapping().getSubstitutionType());
        loader.loadType(substitutionType.getElementId(), csarDependencyLoader.buildDependencyBean(substitutionType.getArchiveName(), substitutionType.getArchiveVersion()));
        for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getCapabilities()).values()) {
            initializeSubstitutionTarget(loader, relationshipTypes, substitutionTarget);
        }
        for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getRequirements()).values()) {
            initializeSubstitutionTarget(loader, relationshipTypes, substitutionTarget);
        }
    }
    return loader;
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) ToscaTypeLoader(alien4cloud.tosca.container.ToscaTypeLoader) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 95 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class TopologyService method findReplacementForNode.

/**
 * Find replacements nodes for a node template
 *
 * @param nodeTemplateName the node to search for replacements
 * @param topology the topology
 * @return all possible replacement types for this node
 */
@SneakyThrows(IOException.class)
public NodeType[] findReplacementForNode(String nodeTemplateName, Topology topology) {
    NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateName);
    Map<String, Map<String, Set<String>>> nodeTemplatesToFilters = Maps.newHashMap();
    Entry<String, NodeTemplate> nodeTempEntry = Maps.immutableEntry(nodeTemplateName, nodeTemplate);
    NodeType indexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
    processNodeTemplate(topology, nodeTempEntry, nodeTemplatesToFilters);
    List<SuggestionsTask> topoTasks = searchForNodeTypes(topology.getWorkspace(), nodeTemplatesToFilters, MapUtil.newHashMap(new String[] { nodeTemplateName }, new NodeType[] { indexedNodeType }), false);
    if (CollectionUtils.isEmpty(topoTasks)) {
        return null;
    }
    return removeDuplicatedNodeTypeForReplacement(indexedNodeType.getElementId(), topoTasks.get(0).getSuggestedNodeTypes());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) SuggestionsTask(alien4cloud.topology.task.SuggestionsTask) Map(java.util.Map) SneakyThrows(lombok.SneakyThrows)

Aggregations

NodeType (org.alien4cloud.tosca.model.types.NodeType)156 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)50 Test (org.junit.Test)44 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)26 Set (java.util.Set)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)23 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)22 Map (java.util.Map)19 Csar (org.alien4cloud.tosca.model.Csar)19 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)16 HashMap (java.util.HashMap)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)15 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)14 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)14 Topology (org.alien4cloud.tosca.model.templates.Topology)9 NotFoundException (alien4cloud.exception.NotFoundException)8 Capability (org.alien4cloud.tosca.model.templates.Capability)8 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)8 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)7 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7