use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologyCompositionService method recursivelyDetectTopologyCompositionCyclicReference.
/**
* Deeply explore composition in order to detect cyclic reference: if a descendant references the mainTopologyId.
*/
public void recursivelyDetectTopologyCompositionCyclicReference(String mainTopologyId, String substitutionTopologyId) {
Topology child = topologyServiceCore.getOrFail(substitutionTopologyId);
if (child == null || child.getNodeTemplates() == null || child.getNodeTemplates().isEmpty()) {
return;
}
for (Entry<String, NodeTemplate> nodeEntry : child.getNodeTemplates().entrySet()) {
String type = nodeEntry.getValue().getType();
NodeType nodeType = csarRepoSearchService.getElementInDependencies(NodeType.class, type, child.getDependencies());
if (nodeType.getSubstitutionTopologyId() != null) {
if (nodeType.getSubstitutionTopologyId().equals(mainTopologyId)) {
throw new CyclicReferenceException("Cyclic reference : a topology template can not reference itself (even indirectly)");
}
recursivelyDetectTopologyCompositionCyclicReference(mainTopologyId, nodeType.getSubstitutionTopologyId());
}
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate 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;
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate 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());
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologyService method processNodeTemplate.
/**
* Process a node template to retrieve filters for node replacements search.
*
* TODO cleanup this method, better return a filter for node rather than adding it to a parameter list.
*
* @param topology The topology for which to search filters.
* @param nodeTempEntry The node template for which to find replacement filter.
* @param nodeTemplatesToFilters The map of filters in which to add the filter for the new Node.
*/
public void processNodeTemplate(final Topology topology, final Entry<String, NodeTemplate> nodeTempEntry, Map<String, Map<String, Set<String>>> nodeTemplatesToFilters) {
String capabilityFilterKey = "capabilities.type";
String requirementFilterKey = "requirements.type";
NodeTemplate template = nodeTempEntry.getValue();
Map<String, RelationshipTemplate> relTemplates = template.getRelationships();
nodeTemplatesToFilters.put(nodeTempEntry.getKey(), null);
// process the node template source of relationships
if (relTemplates != null && !relTemplates.isEmpty()) {
for (RelationshipTemplate relationshipTemplate : relTemplates.values()) {
addFilters(nodeTempEntry.getKey(), requirementFilterKey, relationshipTemplate.getRequirementType(), nodeTemplatesToFilters);
}
}
// process the node template target of relationships
List<RelationshipEntry> targetRelationships = TopologyUtils.getTargetRelationships(nodeTempEntry.getKey(), topology.getNodeTemplates());
for (RelationshipEntry targetRelationshipEntry : targetRelationships) {
addFilters(nodeTempEntry.getKey(), capabilityFilterKey, targetRelationshipEntry.getRelationship().getRequirementType(), nodeTemplatesToFilters);
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologyServiceCore method getIndexedRelationshipTypesFromTopology.
/**
* Get IndexedRelationshipType in a topology
*
* @param topology the topology to find all relationship types
* @param failOnTypeNotFound
* @return the map containing rel
*/
public Map<String, RelationshipType> getIndexedRelationshipTypesFromTopology(Topology topology, boolean failOnTypeNotFound) {
Map<String, RelationshipType> relationshipTypes = Maps.newHashMap();
if (topology.getNodeTemplates() == null) {
return relationshipTypes;
}
for (Map.Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
NodeTemplate template = templateEntry.getValue();
if (template.getRelationships() != null) {
for (Map.Entry<String, RelationshipTemplate> relationshipEntry : template.getRelationships().entrySet()) {
RelationshipTemplate relationship = relationshipEntry.getValue();
if (!relationshipTypes.containsKey(relationship.getType())) {
RelationshipType relationshipType = getFromContextIfDefined(RelationshipType.class, relationship.getType(), topology.getDependencies(), failOnTypeNotFound);
relationshipTypes.put(relationship.getType(), relationshipType);
}
}
}
}
if (topology.getSubstitutionMapping() != null && topology.getSubstitutionMapping().getSubstitutionType() != null) {
for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getCapabilities()).values()) {
addRelationshipTypeFromSubstitutionTarget(topology, relationshipTypes, substitutionTarget, failOnTypeNotFound);
}
for (SubstitutionTarget substitutionTarget : safe(topology.getSubstitutionMapping().getRequirements()).values()) {
addRelationshipTypeFromSubstitutionTarget(topology, relationshipTypes, substitutionTarget, failOnTypeNotFound);
}
}
return relationshipTypes;
}
Aggregations