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);
}
}
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;
}
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 + "_");
}
}
}
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;
}
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;
}
Aggregations