Search in sources :

Example 71 with NodeType

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

the class NodeTypeScoreService method processNodeTypes.

private void processNodeTypes(NodeType[] indexedNodeTypes) {
    for (NodeType nodeType : indexedNodeTypes) {
        if (log.isDebugEnabled()) {
            log.debug("Processing node score for type {}", nodeType.getId());
        }
        Map<String, String[]> usedNodeFiler = Maps.newHashMap();
        usedNodeFiler.put("nodeTemplates.value.type", new String[] { nodeType.getElementId() });
        // count the applications that uses the node-type
        long usageFactor = usageBoost * alienESDAO.buildQuery(Topology.class).setFilters(fromKeyValueCouples("nodeTemplates.value.type", nodeType.getElementId(), "dependencies.name", nodeType.getArchiveName(), "dependencies.version", nodeType.getArchiveVersion())).count();
        // get the version factor (latest version of a node is better than previous version, snapshot versions do not get boost)
        long versionFactor = isLatestVersion(nodeType) ? versionBoost : 0;
        // default boost (boost node types that have a default capability)
        long defaultFactor = nodeType.getDefaultCapabilities() == null || nodeType.getDefaultCapabilities().isEmpty() ? 0 : defaultBoost;
        // update the score for the node type.
        nodeType.setAlienScore(usageFactor + defaultFactor + versionFactor);
        alienESDAO.save(nodeType);
    }
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) Topology(org.alien4cloud.tosca.model.templates.Topology)

Example 72 with NodeType

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

the class NodeTypeScoreService method isLatestVersion.

private boolean isLatestVersion(NodeType nodeType) {
    Map<String, String[]> filters = MapUtil.newHashMap(new String[] { "elementId" }, new String[][] { new String[] { nodeType.getElementId() } });
    // TODO get a single element and order by version.
    Version nodeVersion = new Version(((NodeType) nodeType).getArchiveVersion());
    for (Object otherVersionNodeType : alienESDAO.find(NodeType.class, filters, AlienConstants.DEFAULT_ES_SEARCH_SIZE).getData()) {
        Version otherVersion = new Version(((NodeType) otherVersionNodeType).getArchiveVersion());
        if (nodeVersion.compareTo(otherVersion) < 0) {
            return false;
        }
    }
    return true;
}
Also used : Version(alien4cloud.utils.version.Version) NodeType(org.alien4cloud.tosca.model.types.NodeType)

Example 73 with NodeType

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

the class TopologyCompositionService method recursivelyBuildSubstitutionStack.

/**
 * Deeply explore this topology to detect if some type must be substituted by the corresponding topology template content and feed the {@link Deque}. <br>
 * BTW, rename the nodes by prefixing all the node names.
 */
private void recursivelyBuildSubstitutionStack(Topology topology, Deque<CompositionCouple> stack, String prefix) {
    if (topology == null || topology.getNodeTemplates() == null || topology.getNodeTemplates().isEmpty()) {
        return;
    }
    for (Entry<String, NodeTemplate> nodeEntry : topology.getNodeTemplates().entrySet()) {
        String nodeName = nodeEntry.getKey();
        String type = nodeEntry.getValue().getType();
        // FIXME use tosca context, beware of child topologies (dependencies to use ? conflicts ?)
        NodeType nodeType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, type, topology.getDependencies());
        if (nodeType.getSubstitutionTopologyId() != null) {
            // this node type is a proxy for a topology template
            Topology child = topologyServiceCore.getOrFail(nodeType.getSubstitutionTopologyId());
            CompositionCouple couple = new CompositionCouple(topology, child, nodeName, nodeName + "_");
            renameNodes(couple);
            stack.offer(couple);
            recursivelyBuildSubstitutionStack(child, stack, nodeName + "_");
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Topology(org.alien4cloud.tosca.model.templates.Topology)

Example 74 with NodeType

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

the class NodeMatcherService method match.

public Map<String, List<LocationResourceTemplate>> match(Map<String, NodeType> nodesTypes, Map<String, NodeTemplate> nodesToMatch, Location location, String environmentId) {
    Map<String, List<LocationResourceTemplate>> matchingResult = Maps.newHashMap();
    // fetch location resources
    LocationResources locationResources = locationResourceService.getLocationResources(location);
    // Authorization filtering of location resources
    filterOnAuthorization(locationResources.getNodeTemplates(), environmentId);
    // fetch service resources
    List<ServiceResource> services = serviceResourceService.searchByLocation(location.getId());
    // self filtering: remove managed service linked to this location
    filterSelfManagedService(services, environmentId);
    // Authorization filtering of location resources
    filterOnAuthorization(services, environmentId);
    // from serviceResource to locationResource
    populateLocationResourcesWithServiceResource(locationResources, services, location.getId());
    Map<String, MatchingConfiguration> matchingConfigurations = locationMatchingConfigurationService.getMatchingConfiguration(location);
    Set<String> typesManagedByLocation = Sets.newHashSet();
    for (NodeType nodeType : locationResources.getNodeTypes().values()) {
        typesManagedByLocation.add(nodeType.getElementId());
        typesManagedByLocation.addAll(nodeType.getDerivedFrom());
    }
    INodeMatcherPlugin nodeMatcherPlugin = getNodeMatcherPlugin();
    for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodesToMatch.entrySet()) {
        String nodeTemplateId = nodeTemplateEntry.getKey();
        NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
        if (typesManagedByLocation.contains(nodeTemplate.getType())) {
            NodeType nodeTemplateType = nodesTypes.get(nodeTemplate.getType());
            if (nodeTemplateType == null) {
                throw new InvalidArgumentException("The given node types map must contain the type of the node template");
            }
            matchingResult.put(nodeTemplateId, nodeMatcherPlugin.matchNode(nodeTemplate, nodeTemplateType, locationResources, matchingConfigurations));
        }
    }
    return matchingResult;
}
Also used : MatchingConfiguration(alien4cloud.model.deployment.matching.MatchingConfiguration) LocationResources(alien4cloud.model.orchestrators.locations.LocationResources) ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) InvalidArgumentException(alien4cloud.exception.InvalidArgumentException) NodeType(org.alien4cloud.tosca.model.types.NodeType) List(java.util.List) ServiceResource(alien4cloud.model.service.ServiceResource) INodeMatcherPlugin(alien4cloud.deployment.matching.plugins.INodeMatcherPlugin) Map(java.util.Map)

Example 75 with NodeType

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

the class InputPropertiesStepDefinitions method getPropertyDefinition.

private PropertyDefinition getPropertyDefinition(String nodeName, String propertyName) throws Throwable {
    PropertyDefinition propDef = null;
    String url = String.format("/rest/v1/topologies/%s", Context.getInstance().getTopologyId());
    String response = Context.getRestClientInstance().get(url);
    TopologyDTO topologyDTO = JsonUtil.read(response, TopologyDTO.class, Context.getJsonMapper()).getData();
    NodeTemplate template = MapUtils.getObject(topologyDTO.getTopology().getNodeTemplates(), nodeName);
    if (template != null) {
        NodeType nodeType = MapUtils.getObject(topologyDTO.getNodeTypes(), template.getType());
        if (nodeType != null) {
            propDef = MapUtils.getObject(nodeType.getProperties(), propertyName);
        }
    }
    if (propDef == null) {
        throw new NullPointerException("The property definition is required for node " + nodeName + " and property " + propertyName + ", please check your cucumber scenario.");
    }
    return propDef;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) TopologyDTO(alien4cloud.topology.TopologyDTO) NodeType(org.alien4cloud.tosca.model.types.NodeType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

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