Search in sources :

Example 31 with TTopologyTemplate

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);
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) Test(org.junit.jupiter.api.Test)

Example 32 with TTopologyTemplate

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) List(java.util.List) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) AllocationException(org.eclipse.winery.repository.exceptions.AllocationException)

Example 33 with TTopologyTemplate

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;
}
Also used : HashMap(java.util.HashMap) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with TTopologyTemplate

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);
}
Also used : QName(javax.xml.namespace.QName) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 35 with TTopologyTemplate

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);
}
Also used : TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) QName(javax.xml.namespace.QName) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)158 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)112 ArrayList (java.util.ArrayList)85 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)62 List (java.util.List)59 QName (javax.xml.namespace.QName)55 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)55 Test (org.junit.jupiter.api.Test)51 Map (java.util.Map)48 HashMap (java.util.HashMap)47 LinkedHashMap (java.util.LinkedHashMap)42 TNodeType (org.eclipse.winery.model.tosca.TNodeType)42 ModelUtilities (org.eclipse.winery.model.tosca.utils.ModelUtilities)38 IRepository (org.eclipse.winery.repository.backend.IRepository)38 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)36 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)35 Objects (java.util.Objects)34 IOException (java.io.IOException)32 HashSet (java.util.HashSet)32 Collectors (java.util.stream.Collectors)32