use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class TopologyService method searchForNodeTypes.
/**
* Search for nodeTypes given some filters. Apply AND filter strategy when multiple values for a filter key.
*/
public List<SuggestionsTask> searchForNodeTypes(String workspace, Map<String, Map<String, Set<String>>> nodeTemplatesToFilters, Map<String, NodeType> toExcludeIndexedNodeTypes, boolean excludeAbstract) throws IOException {
if (nodeTemplatesToFilters == null || nodeTemplatesToFilters.isEmpty()) {
return null;
}
List<SuggestionsTask> toReturnTasks = Lists.newArrayList();
for (Map.Entry<String, Map<String, Set<String>>> nodeTemplatesToFiltersEntry : nodeTemplatesToFilters.entrySet()) {
Map<String, String[]> formattedFilters = Maps.newHashMap();
Map<String, FilterValuesStrategy> filterValueStrategy = Maps.newHashMap();
NodeType[] data = null;
if (nodeTemplatesToFiltersEntry.getValue() != null) {
for (Map.Entry<String, Set<String>> filterEntry : nodeTemplatesToFiltersEntry.getValue().entrySet()) {
formattedFilters.put(filterEntry.getKey(), filterEntry.getValue().toArray(new String[filterEntry.getValue().size()]));
// AND strategy if multiple values
filterValueStrategy.put(filterEntry.getKey(), FilterValuesStrategy.AND);
}
// retrieve only non abstract components
if (excludeAbstract) {
formattedFilters.put("abstract", ArrayUtils.toArray(String.valueOf("false")));
}
// use topology workspace + global workspace
formattedFilters.put("workspace", ArrayUtils.toArray(workspace, "ALIEN_GLOBAL_WORKSPACE"));
GetMultipleDataResult<NodeType> searchResult = alienDAO.search(NodeType.class, null, formattedFilters, filterValueStrategy, 20);
data = getIndexedNodeTypesFromSearchResponse(searchResult, toExcludeIndexedNodeTypes.get(nodeTemplatesToFiltersEntry.getKey()));
}
TaskCode taskCode = ArrayUtils.isEmpty(data) ? TaskCode.IMPLEMENT : TaskCode.REPLACE;
SuggestionsTask task = new SuggestionsTask();
task.setNodeTemplateName(nodeTemplatesToFiltersEntry.getKey());
task.setComponent(toExcludeIndexedNodeTypes.get(nodeTemplatesToFiltersEntry.getKey()));
task.setCode(taskCode);
task.setSuggestedNodeTypes(data);
toReturnTasks.add(task);
}
return toReturnTasks;
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class NodeFilterValidationService method validateRequirementFilters.
/**
* Performs validation of the node filters to check that relationships targets the filter requirements.
*/
private List<NodeFiltersTask> validateRequirementFilters(Topology topology, boolean skipInputs) {
List<NodeFiltersTask> toReturnTaskList = Lists.newArrayList();
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, true, true);
Map<String, CapabilityType> capabilityTypes = topologyServiceCore.getIndexedCapabilityTypesFromTopology(topology);
for (Map.Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
Map<String, RelationshipTemplate> relationshipsMap = nodeTempEntry.getValue().getRelationships();
if (relationshipsMap == null || relationshipsMap.isEmpty()) {
continue;
}
NodeType sourceNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTempEntry.getValue().getType(), topology.getDependencies());
if (sourceNodeType.isAbstract()) {
continue;
}
NodeFiltersTask task = new NodeFiltersTask();
task.setNodeTemplateName(nodeTempEntry.getKey());
task.setCode(TaskCode.NODE_FILTER_INVALID);
task.setComponent(sourceNodeType);
task.setNodeFiltersToSatisfy(Lists.<NodeFilterToSatisfy>newArrayList());
validateFiltersForNode(sourceNodeType, relationshipsMap, topology, nodeTypes, capabilityTypes, task, skipInputs);
if (!task.getNodeFiltersToSatisfy().isEmpty()) {
toReturnTaskList.add(task);
}
}
return toReturnTaskList.isEmpty() ? null : toReturnTaskList;
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class TopologyCapabilityBoundsValidationServices method isCapabilityUpperBoundReachedForTarget.
//
public boolean isCapabilityUpperBoundReachedForTarget(String nodeTemplateName, Map<String, NodeTemplate> nodeTemplates, String capabilityName, Set<CSARDependency> dependencies) {
NodeTemplate nodeTemplate = nodeTemplates.get(nodeTemplateName);
NodeType relatedIndexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), dependencies);
chekCapability(nodeTemplateName, capabilityName, nodeTemplate);
CapabilityDefinition capabilityDefinition = getCapabilityDefinition(relatedIndexedNodeType.getCapabilities(), capabilityName);
if (capabilityDefinition.getUpperBound() == Integer.MAX_VALUE) {
return false;
}
List<RelationshipEntry> targetRelatedRelationships = TopologyUtils.getTargetRelationships(nodeTemplateName, nodeTemplates);
if (targetRelatedRelationships == null || targetRelatedRelationships.isEmpty()) {
return false;
}
int count = 0;
for (RelationshipEntry relationshipEntry : targetRelatedRelationships) {
if (relationshipEntry.getRelationship().getTargetedCapabilityName().equals(capabilityName)) {
count++;
}
}
return count >= capabilityDefinition.getUpperBound();
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class TopologyRequirementBoundsValidationServices method isRequirementUpperBoundReachedForSource.
/**
* Check if the upperBound of a requirement is reached on a node template
*
* @param nodeTemplate the node to check for requirement bound
* @param requirementName the name of the requirement
* @param dependencies the dependencies of the topology
* @return true if requirement upper bound is reached, false otherwise
*/
public boolean isRequirementUpperBoundReachedForSource(NodeTemplate nodeTemplate, String requirementName, Set<CSARDependency> dependencies) {
NodeType relatedIndexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), dependencies);
Requirement requirement = nodeTemplate.getRequirements().get(requirementName);
if (nodeTemplate.getRelationships() == null || nodeTemplate.getRelationships().isEmpty()) {
return false;
}
RequirementDefinition requirementDefinition = getRequirementDefinition(relatedIndexedNodeType.getRequirements(), requirementName, requirement.getType());
if (requirementDefinition.getUpperBound() == Integer.MAX_VALUE) {
return false;
}
int count = countRelationshipsForRequirement(nodeTemplate, requirementDefinition);
return count >= requirementDefinition.getUpperBound();
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class TopologyTreeBuilderService method getNonNativesNodes.
/**
* Get the non-natives node of a topology.
*
* @param topology
* @return a Map of non-natives nodes.
*/
@ToscaContextual
public Map<String, NodeTemplate> getNonNativesNodes(Topology topology) {
Map<String, NodeTemplate> nonNativesNode = new HashMap<>();
if (topology.getNodeTemplates() != null) {
for (Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
NodeTemplate template = templateEntry.getValue();
NodeType indexedToscaElement = ToscaContext.getOrFail(NodeType.class, template.getType());
boolean isCompute = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeComputeConstants.COMPUTE_TYPE);
boolean isNetwork = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeNetworkConstants.NETWORK_TYPE);
boolean isVolume = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeBlockStorageConstants.BLOCKSTORAGE_TYPE);
if (!isCompute && !isNetwork && !isVolume) {
nonNativesNode.put(templateEntry.getKey(), template);
}
}
}
return nonNativesNode;
}
Aggregations