Skip to content

Commit

Permalink
update policy handling for completion
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeisel committed Nov 17, 2023
1 parent 5e7d449 commit 6e3193a
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.eclipse.winery.model.tosca.TRequirement;
import org.eclipse.winery.model.tosca.TRequirementType;
import org.eclipse.winery.model.tosca.TServiceTemplate;
import org.eclipse.winery.model.tosca.TTag;
import org.eclipse.winery.model.tosca.TTopologyTemplate;
import org.eclipse.winery.model.tosca.constants.OpenToscaBaseTypes;
import org.eclipse.winery.model.tosca.constants.ToscaBaseTypes;
Expand Down Expand Up @@ -1766,6 +1767,7 @@ public TTopologyTemplate getMatchingTopology(TServiceTemplate serviceTemplate, L
ProviderRepository repository = new ProviderRepository();
List<TNodeTemplate> lowLevelNodeTemplates = getNodeTemplatesWithoutOutgoingHostedOnRelationships(serviceTemplate);
List<TNodeTemplate> nodesToCheck = new ArrayList<>();


//Find lowest level nodes with open requirements which means they can be hosted by an other component
for (TNodeTemplate nodeTemplateCandidate : lowLevelNodeTemplates) {
Expand Down Expand Up @@ -1799,12 +1801,28 @@ public TTopologyTemplate getMatchingTopology(TServiceTemplate serviceTemplate, L
LOGGER.debug("Found {} compatible topology fragments for NodeTemplate {}",
compatibleNodeTemplates.size(), needHostNode.getId());

// TODO do proper selection based on policies
// Filter NodeTemplates based on Blacklist
compatibleNodeTemplates = compatibleNodeTemplates.stream().filter(nt -> !blacklist.contains(nt.getType())).toList();

// if(completionInputData.getPolicies().containsKey("cloudType")){
// compatibleNodeTemplates = compatibleNodeTemplates.stream().filter(nt -> nt.get);
// }

// Filter NodeTemplates based on Policies
IRepository repositoryFactory = RepositoryFactory.getRepository();
Map<QName, TNodeType> nodeTypes = repositoryFactory.getQNameToElementMapping(NodeTypeId.class);
for (Map.Entry<String, String> entry : policies.entrySet()) {
compatibleNodeTemplates = compatibleNodeTemplates.stream().filter(nt -> {
//get NodeType of NodeTemplate
TNodeType matchingType = nodeTypes.get(nt.getType());

if (matchingType.getTags() == null){
return true;
}
// check if NodeType has given Tag -> If it does have the tag it must be set as desrcibed by the policy, otherwise it is ignored
List<TTag> filteredTagList = matchingType.getTags().stream().filter(tag -> tag.getName().equalsIgnoreCase(entry.getKey())).toList();
if (filteredTagList.size() > 0){
return entry.getValue().equalsIgnoreCase(filteredTagList.get(0).getValue());
}
return true;
}).toList();
}

TNodeTemplate selectedTemplate = compatibleNodeTemplates.get(0);

Expand Down

0 comments on commit 6e3193a

Please sign in to comment.