use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class AllocationUtilsTest method deepcopy.
@Test
public void deepcopy() {
topology.getNodeTemplates().forEach(nt -> {
nt.setMinInstances(1);
nt.setMaxInstances("1");
});
TTopologyTemplate clone = BackendUtils.clone(topology);
assertEquals(topology, clone);
TTopologyTemplate cloneNotEquals = AllocationUtils.deepCopy(topology);
assertNotEquals(topology, cloneNotEquals);
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class FulfillPolicies method assignTargetLabels.
private Map<TNodeTemplate, Set<String>> assignTargetLabels(TopologyWrapper topology) throws AllocationException {
Map<TNodeTemplate, Set<String>> possibleTargetLabels = new HashMap<>();
Map<TNodeTemplate, List<PolicyWrapper>> policiesForNTs = getPoliciesForNTs(topology, params);
for (TNodeTemplate topLevelNT : topology.getTopLevelNTs()) {
// set present target labels
Optional<String> targetLabelOptional = ModelUtilities.getTargetLabel(topLevelNT);
if (targetLabelOptional.isPresent()) {
possibleTargetLabels.put(topLevelNT, Collections.singleton(targetLabelOptional.get()));
continue;
} else {
possibleTargetLabels.put(topLevelNT, new HashSet<>());
}
// get matching fragments
List<TTopologyTemplate> matchingFragments = fragmentsCache.getAllMatchingFragments(topology, topLevelNT).values().stream().flatMap(List::stream).collect(Collectors.toList());
// remove matching fragments that don't fulfill the policies
matchingFragments = new PolicyComparison(policiesForNTs.get(topLevelNT), matchingFragments).getFragmentsFulfillingPolicies();
for (TTopologyTemplate fragment : matchingFragments) {
ModelUtilities.getTargetLabel(fragment.getNodeTemplates().get(0)).ifPresent(targetLabel -> possibleTargetLabels.get(topLevelNT).add(targetLabel));
}
if (possibleTargetLabels.get(topLevelNT).isEmpty()) {
throw new AllocationException("Couldn't find fragments from providers fulfilling specified policies");
}
}
return possibleTargetLabels;
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class FulfillPolicies method mapFragmentsByNTs.
/**
* Remap fragments fulfilling policies to the corresponding node templates.
*/
private Map<TNodeTemplate, List<TTopologyTemplate>> mapFragmentsByNTs(Map<TNodeTemplate, List<TTopologyTemplate>> fragments, List<TTopologyTemplate> fragmentsFulfillingPolicies) {
Map<TNodeTemplate, List<TTopologyTemplate>> fragmentsWithNTs = new HashMap<>();
for (TTopologyTemplate fragmentFulfillingPolicies : fragmentsFulfillingPolicies) {
for (Map.Entry<TNodeTemplate, List<TTopologyTemplate>> entry : fragments.entrySet()) {
if (entry.getValue().contains(fragmentFulfillingPolicies)) {
if (fragmentsWithNTs.containsKey(entry.getKey())) {
fragmentsWithNTs.get(entry.getKey()).add(fragmentFulfillingPolicies);
} else {
List<TTopologyTemplate> frags = new ArrayList<>();
frags.add(fragmentFulfillingPolicies);
fragmentsWithNTs.put(entry.getKey(), frags);
}
}
}
}
return fragmentsWithNTs;
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class TestWineryRepositoryClient method topologyTemplateOfServiceTemplateWithFourPoliciesIsNotNull.
@Test
public void topologyTemplateOfServiceTemplateWithFourPoliciesIsNotNull() throws Exception {
this.setRevisionTo("origin/plain");
QName serviceTemplate = new QName("http://plain.winery.opentosca.org/servicetemplates", "ServiceTemplateWithFourPolicies");
TTopologyTemplate topologyTemplate = TestWineryRepositoryClient.client.getTopologyTemplate(serviceTemplate);
assertNotNull(topologyTemplate);
}
use of org.eclipse.winery.model.tosca.TTopologyTemplate in project winery by eclipse.
the class TestWineryRepositoryClient method getPropertiesOfTestTopologyTemplate.
@Test
public void getPropertiesOfTestTopologyTemplate() throws Exception {
this.setRevisionTo("origin/plain");
QName serviceTemplate = new QName("http://plain.winery.opentosca.org/servicetemplates", "ServiceTemplateMinimalExampleWithAllPropertyVariants");
TTopologyTemplate topologyTemplate = TestWineryRepositoryClient.client.getTopologyTemplate(serviceTemplate);
assertNotNull(topologyTemplate);
final TNodeTemplate nodeTemplateWithTwoKVProperties = topologyTemplate.getNodeTemplate("NodeTypeWithTwoKVProperties");
assertNotNull(nodeTemplateWithTwoKVProperties);
TEntityTemplate.Properties properties = nodeTemplateWithTwoKVProperties.getProperties();
assertNotNull(properties);
final LinkedHashMap<String, String> kvProperties = ModelUtilities.getPropertiesKV(nodeTemplateWithTwoKVProperties);
assertNotNull(kvProperties);
final String value = kvProperties.get("key1");
assertEquals("value", value);
}
Aggregations