Search in sources :

Example 1 with OTPatternRefinementModel

use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.

the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.

public static TDefinitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
    final TDefinitions definitions = createWrapperDefinitions(id, repository);
    HasIdInIdOrNameField element;
    if (id instanceof RelationshipTypeImplementationId) {
        element = new TRelationshipTypeImplementation();
    } else if (id instanceof NodeTypeImplementationId) {
        element = new TNodeTypeImplementation();
    } else if (id instanceof RequirementTypeId) {
        element = new TRequirementType();
    } else if (id instanceof NodeTypeId) {
        element = new TNodeType();
    } else if (id instanceof RelationshipTypeId) {
        element = new TRelationshipType();
    } else if (id instanceof CapabilityTypeId) {
        element = new TCapabilityType();
    } else if (id instanceof DataTypeId) {
        element = new TDataType();
    } else if (id instanceof ArtifactTypeId) {
        element = new TArtifactType();
    } else if (id instanceof PolicyTypeId) {
        element = new TPolicyType();
    } else if (id instanceof PolicyTemplateId) {
        element = new TPolicyTemplate();
    } else if (id instanceof ServiceTemplateId) {
        element = new TServiceTemplate();
    } else if (id instanceof ArtifactTemplateId) {
        element = new TArtifactTemplate();
    } else if (id instanceof ComplianceRuleId) {
        element = new OTComplianceRule(new OTComplianceRule.Builder(id.getXmlId().getDecoded()));
    } else if (id instanceof PatternRefinementModelId) {
        element = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder());
    } else if (id instanceof TopologyFragmentRefinementModelId) {
        element = new OTTopologyFragmentRefinementModel(new OTPatternRefinementModel.Builder());
    } else if (id instanceof TestRefinementModelId) {
        element = new OTTestRefinementModel(new OTTestRefinementModel.Builder());
    } else if (id instanceof InterfaceTypeId) {
        element = new TInterfaceType();
    } else if (id instanceof XSDImportId) {
        // TImport has no id; thus directly generating it without setting an id
        TImport tImport = new TImport();
        definitions.setElement(tImport);
        return definitions;
    } else {
        throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
    }
    copyIdToFields(element, id);
    definitions.setElement((TExtensibleElements) element);
    return definitions;
}
Also used : OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TestRefinementModelId(org.eclipse.winery.model.ids.extensions.TestRefinementModelId) TImport(org.eclipse.winery.model.tosca.TImport) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) TDataType(org.eclipse.winery.model.tosca.TDataType) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) HasIdInIdOrNameField(org.eclipse.winery.model.tosca.HasIdInIdOrNameField) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) InterfaceTypeId(org.eclipse.winery.model.ids.definitions.InterfaceTypeId) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) XSDImportId(org.eclipse.winery.model.ids.definitions.imports.XSDImportId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) DataTypeId(org.eclipse.winery.model.ids.definitions.DataTypeId) TInterfaceType(org.eclipse.winery.model.tosca.TInterfaceType) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Example 2 with OTPatternRefinementModel

use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.

the class ToscaComponentPatternMatcherTest method isCompatible.

@Test
public void isCompatible() {
    // same type
    TNodeTemplate refinementTemplate = new TNodeTemplate(new TNodeTemplate.Builder("d", new QName("type1")));
    ToscaNode refinement = new ToscaNode();
    refinement.addTEntityType(new TNodeType(new TNodeType.Builder("type1")));
    refinement.setNodeTemplate(refinementTemplate);
    TNodeTemplate candidateTemplate = new TNodeTemplate(new TNodeTemplate.Builder("c", new QName("type1")));
    ToscaNode candidate = new ToscaNode();
    candidate.addTEntityType(new TNodeType(new TNodeType.Builder("type1")));
    candidate.setNodeTemplate(candidateTemplate);
    OTPatternRefinementModel prm = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setRefinementStructure(new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplate(refinementTemplate))));
    // needs to be swapped manually as only prms retrieved from repo are swapped automatically
    PatternDetectionUtils.swapDetectorWithRefinement(prm);
    NamespaceManager namespaceManager = new MockNamespaceManager() {

        @Override
        public boolean isPatternNamespace(String namespace) {
            return namespace.equals("patternNs");
        }
    };
    ToscaComponentPatternMatcher matcher = new ToscaComponentPatternMatcher(prm, namespaceManager, new ArrayList<>(), new HashMap<>());
    assertTrue(matcher.isCompatible(refinement, candidate));
    // different type
    refinementTemplate.setType(new QName("type1"));
    refinement.getTypes().clear();
    refinement.addTEntityType(new TNodeType(new TNodeType.Builder("type1")));
    candidateTemplate.setType(new QName("type2"));
    candidate.getTypes().clear();
    candidate.addTEntityType(new TNodeType(new TNodeType.Builder("type2")));
    assertFalse(matcher.isCompatible(refinement, candidate));
    // share supertype
    refinement.addTEntityType(new TNodeType(new TNodeType.Builder("super")));
    candidate.addTEntityType(new TNodeType(new TNodeType.Builder("super")));
    assertTrue(matcher.isCompatible(refinement, candidate));
    // stay mapping exists
    OTStayMapping stayMapping = new OTStayMapping(new OTStayMapping.Builder().setDetectorElement(null).setRefinementElement(refinementTemplate));
    List<OTStayMapping> stayMappings = new ArrayList<>();
    stayMappings.add((OTStayMapping) PatternDetectionUtils.swapDetectorWithRefinement(stayMapping));
    prm.setStayMappings(stayMappings);
    assertFalse(matcher.isCompatible(refinement, candidate));
    assertNotNull(prm.getStayMappings());
    prm.getStayMappings().clear();
    assertTrue(matcher.isCompatible(refinement, candidate));
    // component pattern mapping exists
    List<OTPermutationMapping> componentPatternMappings = new ArrayList<>();
    OTPermutationMapping componentPatternMapping = new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(new TNodeTemplate.Builder("detector", QName.valueOf("{ns}type")).build()).setRefinementElement(refinementTemplate));
    componentPatternMappings.add((OTPermutationMapping) PatternDetectionUtils.swapDetectorWithRefinement(componentPatternMapping));
    prm.setPermutationMappings(componentPatternMappings);
    assertFalse(matcher.isCompatible(refinement, candidate));
    prm.getPermutationMappings().clear();
    assertTrue(matcher.isCompatible(refinement, candidate));
    // different behavior patterns
    List<TPolicy> refinementPolicies = new ArrayList<>();
    refinementPolicies.add(new TPolicy.Builder(QName.valueOf("{patternNs}type1")).build());
    refinementTemplate.setPolicies(refinementPolicies);
    List<TPolicy> candidatePolicies = new ArrayList<>();
    candidateTemplate.setPolicies(candidatePolicies);
    // detector has behavior pattern, candidate doesn't
    assertFalse(matcher.isCompatible(refinement, candidate));
    candidatePolicies.add(new TPolicy.Builder(QName.valueOf("{patternNs}type1")).build());
    // detector and candidate have same behavior pattern
    assertTrue(matcher.isCompatible(refinement, candidate));
    refinementPolicies.clear();
    // candidate has behavior pattern, detector doesn't
    assertFalse(matcher.isCompatible(refinement, candidate));
    candidatePolicies.clear();
    assertTrue(matcher.isCompatible(refinement, candidate));
    // detector supertype of candidate
    refinementTemplate.setType(new QName("super"));
    refinement.getTypes().clear();
    refinement.addTEntityType(new TNodeType(new TNodeType.Builder("super")));
    candidateTemplate.setType(new QName("type"));
    candidate.getTypes().clear();
    candidate.addTEntityType(new TNodeType(new TNodeType.Builder("type")));
    candidate.addTEntityType(new TNodeType(new TNodeType.Builder("super")));
    assertTrue(matcher.isCompatible(refinement, candidate));
    // candidate supertype of detector
    refinementTemplate.setType(new QName("type"));
    refinement.getTypes().clear();
    refinement.addTEntityType(new TNodeType(new TNodeType.Builder("type")));
    refinement.addTEntityType(new TNodeType(new TNodeType.Builder("super")));
    candidateTemplate.setType(new QName("super"));
    candidate.getTypes().clear();
    candidate.addTEntityType(new TNodeType(new TNodeType.Builder("super")));
    assertTrue(matcher.isCompatible(refinement, candidate));
    // different supertypes
    refinementTemplate.setType(new QName("type1"));
    refinement.getTypes().clear();
    refinement.addTEntityType(new TNodeType(new TNodeType.Builder("type1")));
    refinement.addTEntityType(new TNodeType(new TNodeType.Builder("super1")));
    candidateTemplate.setType(new QName("type2"));
    candidate.getTypes().clear();
    candidate.addTEntityType(new TNodeType(new TNodeType.Builder("type2")));
    candidate.addTEntityType(new TNodeType(new TNodeType.Builder("super2")));
    assertFalse(matcher.isCompatible(refinement, candidate));
}
Also used : MockNamespaceManager(org.eclipse.winery.topologygraph.matching.MockNamespaceManager) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) TNodeType(org.eclipse.winery.model.tosca.TNodeType) MockNamespaceManager(org.eclipse.winery.topologygraph.matching.MockNamespaceManager) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) TPolicy(org.eclipse.winery.model.tosca.TPolicy) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) Test(org.junit.jupiter.api.Test)

Example 3 with OTPatternRefinementModel

use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.

the class ComponentPatternDetectionTest method testRemoveBehaviorPatterns.

@Test
public void testRemoveBehaviorPatterns() {
    // region: detector
    TNodeTemplate detectorElement = new TNodeTemplate(new TNodeTemplate.Builder("detectorElement", QName.valueOf("{ns}type1")).setX("1").setY("1"));
    TNodeTemplate detectorElement2 = new TNodeTemplate(new TNodeTemplate.Builder("detectorElement2", QName.valueOf("{ns}pattern1")).setX("1").setY("1"));
    List<TPolicy> detectorPolicies = new ArrayList<>();
    detectorPolicies.add(new TPolicy(new TPolicy.Builder(QName.valueOf("{patternNs}one")).setName("one")));
    detectorPolicies.add(new TPolicy(new TPolicy.Builder(QName.valueOf("{patternNs}two")).setName("two")));
    detectorElement.setPolicies(detectorPolicies);
    TTopologyTemplate detector = new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplates(Arrays.asList(detectorElement, detectorElement2)));
    // endregion
    // region: refinement
    TNodeTemplate refinementElement = new TNodeTemplate(new TNodeTemplate.Builder("refinementElement", QName.valueOf("{ns}type1")).setX("1").setY("1"));
    TNodeTemplate refinementElement2 = new TNodeTemplate(new TNodeTemplate.Builder("refinementElement2", QName.valueOf("{ns}type2")).setX("1").setY("1"));
    List<TPolicy> refinementPolicies = new ArrayList<>();
    refinementPolicies.add(new TPolicy(new TPolicy.Builder(QName.valueOf("{patternNs}one")).setName("one")));
    refinementElement.setPolicies(refinementPolicies);
    TTopologyTemplate refinement = new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplates(Arrays.asList(refinementElement, refinementElement2)));
    // endregion
    OTStayMapping stayMapping = new OTStayMapping(new OTStayMapping.Builder().setDetectorElement(detectorElement).setRefinementElement(refinementElement));
    OTPatternRefinementModel prm = new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(detector).setRefinementStructure(refinement).setStayMappings(Arrays.asList(stayMapping)));
    PatternDetectionUtils.swapDetectorWithRefinement(prm);
    TNodeTemplate nodeTemplate = new TNodeTemplate(new TNodeTemplate.Builder("nodeTemplate", QName.valueOf("{ns}type1")).setX("1").setY("1"));
    TNodeTemplate nodeTemplate2 = new TNodeTemplate(new TNodeTemplate.Builder("nodeTemplate2", QName.valueOf("{ns}type2")).setX("1").setY("1"));
    nodeTemplate.setPolicies(new ArrayList<>(refinementPolicies));
    TTopologyTemplate topology = new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplates(Arrays.asList(nodeTemplate, nodeTemplate2)));
    ComponentPatternDetection detection = new ComponentPatternDetection(new DefaultRefinementChooser(), Arrays.asList(prm));
    detection.refineTopology(topology);
    assertEquals(topology.getNodeTemplates().size(), 2);
    Set<QName> types = topology.getNodeTemplates().stream().map(TNodeTemplate::getType).collect(Collectors.toSet());
    assertTrue(types.contains(QName.valueOf("{ns}type1")));
    assertTrue(types.contains(QName.valueOf("{ns}pattern1")));
    TNodeTemplate nodeTemplate1 = topology.getNodeTemplate("nodeTemplate");
    assertNotNull(nodeTemplate1);
    assertNotNull(nodeTemplate1.getPolicies());
    List<TPolicy> policies = nodeTemplate1.getPolicies();
    assertEquals(policies.size(), 1);
    assertTrue(policies.stream().anyMatch(policy -> policy.getPolicyType().equals(QName.valueOf("{patternNs}one"))));
}
Also used : TPolicy(org.eclipse.winery.model.tosca.TPolicy) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) HasPolicies(org.eclipse.winery.model.tosca.HasPolicies) OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) PatternDetectionUtils(org.eclipse.winery.topologygraph.matching.patterndetection.PatternDetectionUtils) GraphMapping(org.jgrapht.GraphMapping) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) ToscaComponentPatternMatcher(org.eclipse.winery.topologygraph.matching.patterndetection.ToscaComponentPatternMatcher) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ToscaIsomorphismMatcher(org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) OTRelationDirection(org.eclipse.winery.model.tosca.extensions.OTRelationDirection) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OTAttributeMappingType(org.eclipse.winery.model.tosca.extensions.OTAttributeMappingType) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) Iterator(java.util.Iterator) DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) Set(java.util.Set) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) QName(javax.xml.namespace.QName) Collections(java.util.Collections) ToscaTransformer(org.eclipse.winery.topologygraph.transformation.ToscaTransformer) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) DefaultRefinementChooser(org.eclipse.winery.model.adaptation.substitution.refinement.DefaultRefinementChooser) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) TPolicy(org.eclipse.winery.model.tosca.TPolicy) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Example 4 with OTPatternRefinementModel

use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.

the class ComponentPatternDetectionTest method prm2.

private OTPatternRefinementModel prm2() {
    // region: detector
    TNodeTemplate relationalDb = new TNodeTemplate(new TNodeTemplate.Builder("relationalDb-d2", QName.valueOf("{ns}relational-db")).setX("1").setY("1"));
    ModelUtilities.setPropertiesKV(relationalDb, new LinkedHashMap<>());
    TNodeTemplate privateCloud = new TNodeTemplate(new TNodeTemplate.Builder("privateCloud-d2", QName.valueOf("{ns}private-cloud")).setX("1").setY("1"));
    ModelUtilities.setPropertiesKV(privateCloud, new LinkedHashMap<>());
    TRelationshipTemplate relationalDbToPrivateCloud = new TRelationshipTemplate(new TRelationshipTemplate.Builder("relationalDb-privateCloud-d2", QName.valueOf("{ns}hostedOn"), relationalDb, privateCloud));
    TTopologyTemplate detector = new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplates(Arrays.asList(relationalDb, privateCloud)).addRelationshipTemplates(Arrays.asList(relationalDbToPrivateCloud)));
    // endregion
    // region: refinement
    TNodeTemplate database = new TNodeTemplate(new TNodeTemplate.Builder("database-rs2", QName.valueOf("{ns}mysql-db-5.7")).setX("1").setY("1"));
    TNodeTemplate dbms = new TNodeTemplate(new TNodeTemplate.Builder("dbms-rs2", QName.valueOf("{ns}mysql-dbms-5.7")).setX("1").setY("1"));
    TNodeTemplate vm = new TNodeTemplate(new TNodeTemplate.Builder("windows-server-2019-rs2", QName.valueOf("{ns}vm")).setX("1").setY("1"));
    TNodeTemplate vsphere = new TNodeTemplate(new TNodeTemplate.Builder("vsphere-rs2", QName.valueOf("{ns}vsphere-7")).setX("1").setY("1"));
    LinkedHashMap<String, String> dbProps = new LinkedHashMap<>();
    dbProps.put("dbName", "database");
    ModelUtilities.setPropertiesKV(database, dbProps);
    LinkedHashMap<String, String> dbmsProps = new LinkedHashMap<>();
    dbmsProps.put("adminPort", "33062");
    ModelUtilities.setPropertiesKV(dbms, dbmsProps);
    LinkedHashMap<String, String> vmProps = new LinkedHashMap<>();
    vmProps.put("ram", "64GB");
    ModelUtilities.setPropertiesKV(vm, vmProps);
    LinkedHashMap<String, String> vsphereProps = new LinkedHashMap<>();
    vsphereProps.put("api", "vsphere.uni-stuttgart");
    ModelUtilities.setPropertiesKV(vsphere, vsphereProps);
    TRelationshipTemplate dbToDbms = new TRelationshipTemplate(new TRelationshipTemplate.Builder("db-dbms-rs2", QName.valueOf("{ns}hostedOn"), database, dbms));
    TRelationshipTemplate dbmsToVm = new TRelationshipTemplate(new TRelationshipTemplate.Builder("dbms-vm-rs2", QName.valueOf("{ns}hostedOn"), dbms, vm));
    TRelationshipTemplate vmToVsphere = new TRelationshipTemplate(new TRelationshipTemplate.Builder("vm-vsphere-rs2", QName.valueOf("{ns}hostedOn"), vm, vsphere));
    TTopologyTemplate refinement = new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplates(Arrays.asList(database, dbms, vm, vsphere)).addRelationshipTemplates(Arrays.asList(dbToDbms, dbmsToVm, vmToVsphere)));
    // endregion
    List<OTPermutationMapping> permutationMappings = new ArrayList<>();
    permutationMappings.add(new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(relationalDb).setRefinementElement(database)));
    permutationMappings.add(new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(privateCloud).setRefinementElement(vsphere)));
    List<OTAttributeMapping> attributeMappings = new ArrayList<>();
    attributeMappings.add(new OTAttributeMapping(new OTAttributeMapping.Builder().setDetectorElement(relationalDb).setDetectorProperty("name").setRefinementElement(database).setRefinementProperty("dbName").setType(OTAttributeMappingType.SELECTIVE)));
    attributeMappings.add(new OTAttributeMapping(new OTAttributeMapping.Builder().setDetectorElement(privateCloud).setDetectorProperty("interface").setRefinementElement(vsphere).setRefinementProperty("api").setType(OTAttributeMappingType.SELECTIVE)));
    List<OTRelationMapping> relationMappings = new ArrayList<>();
    relationMappings.add(new OTRelationMapping(new OTRelationMapping.Builder().setDetectorElement(relationalDb).setRefinementElement(database).setRelationType("{ns}secureSqlConnection").setValidSourceOrTarget(null).setDirection(OTRelationDirection.INGOING)));
    relationMappings.add(new OTRelationMapping(new OTRelationMapping.Builder().setDetectorElement(privateCloud).setRefinementElement(vm).setRelationType("{ns}hostedOn").setValidSourceOrTarget(null).setDirection(OTRelationDirection.INGOING)));
    return new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(detector).setRefinementStructure(refinement).setPermutationMappings(permutationMappings).setAttributeMappings(attributeMappings).setRelationMappings(relationMappings));
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Example 5 with OTPatternRefinementModel

use of org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel in project winery by eclipse.

the class ComponentPatternDetectionTest method prm1.

private OTPatternRefinementModel prm1() {
    // region: detector
    TNodeTemplate processorD = new TNodeTemplate(new TNodeTemplate.Builder("processor-d1", QName.valueOf("{ns}java-8-app")).setX("1").setY("1"));
    LinkedHashMap<String, String> processorDProps = new LinkedHashMap<>();
    processorDProps.put("port", "8081");
    ModelUtilities.setPropertiesKV(processorD, processorDProps);
    TNodeTemplate executionEnv = new TNodeTemplate(new TNodeTemplate.Builder("executionEnv-d1", QName.valueOf("{ns}execution-env")).setX("1").setY("1"));
    TNodeTemplate privateCloud = new TNodeTemplate(new TNodeTemplate.Builder("privateCloud-d1", QName.valueOf("{ns}private-cloud")).setX("1").setY("1"));
    TRelationshipTemplate processorDToExecutionEnv = new TRelationshipTemplate(new TRelationshipTemplate.Builder("processorD-executionEnv-d1", QName.valueOf("{ns}hostedOn"), processorD, executionEnv));
    TRelationshipTemplate executionEnvToPrivateCloud = new TRelationshipTemplate(new TRelationshipTemplate.Builder("executionEnv-privateCloud-d1", QName.valueOf("{ns}hostedOn"), executionEnv, privateCloud));
    TTopologyTemplate detector = new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplates(Arrays.asList(processorD, executionEnv, privateCloud)).addRelationshipTemplates(Arrays.asList(processorDToExecutionEnv, executionEnvToPrivateCloud)));
    // endregion
    // region: refinement
    TNodeTemplate processorRs = new TNodeTemplate(new TNodeTemplate.Builder("processor-rs1", QName.valueOf("{ns}java-8-app")).setX("1").setY("1"));
    TNodeTemplate webserver = new TNodeTemplate(new TNodeTemplate.Builder("webserver-rs1", QName.valueOf("{ns}tomcat-9")).setX("1").setY("1"));
    TNodeTemplate vm = new TNodeTemplate(new TNodeTemplate.Builder("ubuntu-2004-rs1", QName.valueOf("{ns}vm")).setX("1").setY("1"));
    TNodeTemplate openstack = new TNodeTemplate(new TNodeTemplate.Builder("openstack-rs1", QName.valueOf("{ns}openstack-victoria")).setX("1").setY("1"));
    LinkedHashMap<String, String> processorRsProps = new LinkedHashMap<>();
    processorRsProps.put("port", "8081");
    ModelUtilities.setPropertiesKV(processorRs, processorRsProps);
    LinkedHashMap<String, String> webserverProps = new LinkedHashMap<>();
    webserverProps.put("jmxPort", "9091");
    ModelUtilities.setPropertiesKV(webserver, webserverProps);
    LinkedHashMap<String, String> vmProps = new LinkedHashMap<>();
    vmProps.put("ram", "128GB");
    ModelUtilities.setPropertiesKV(vm, vmProps);
    LinkedHashMap<String, String> openstackProps = new LinkedHashMap<>();
    openstackProps.put("api", "openstack.uni-stuttgart");
    ModelUtilities.setPropertiesKV(openstack, openstackProps);
    TRelationshipTemplate processorToWebserver = new TRelationshipTemplate(new TRelationshipTemplate.Builder("processor-webserver-rs1", QName.valueOf("{ns}hostedOn"), processorRs, webserver));
    TRelationshipTemplate webserverToVm = new TRelationshipTemplate(new TRelationshipTemplate.Builder("webserver-vm-rs1", QName.valueOf("{ns}hostedOn"), webserver, vm));
    TRelationshipTemplate vmToOpenstack = new TRelationshipTemplate(new TRelationshipTemplate.Builder("vm-openstack-rs1", QName.valueOf("{ns}hostedOn"), vm, openstack));
    TTopologyTemplate refinement = new TTopologyTemplate(new TTopologyTemplate.Builder().addNodeTemplates(Arrays.asList(processorRs, webserver, vm, openstack)).addRelationshipTemplates(Arrays.asList(processorToWebserver, webserverToVm, vmToOpenstack)));
    // endregion
    OTStayMapping stayMapping = new OTStayMapping(new OTStayMapping.Builder().setDetectorElement(processorD).setRefinementElement(processorRs));
    List<OTPermutationMapping> permutationMappings = new ArrayList<>();
    permutationMappings.add(new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(executionEnv).setRefinementElement(webserver)));
    permutationMappings.add(new OTPermutationMapping(new OTPermutationMapping.Builder().setDetectorElement(privateCloud).setRefinementElement(openstack)));
    List<OTAttributeMapping> attributeMappings = new ArrayList<>();
    attributeMappings.add(new OTAttributeMapping(new OTAttributeMapping.Builder().setDetectorElement(executionEnv).setDetectorProperty("port").setRefinementElement(webserver).setRefinementProperty("jmxPort").setType(OTAttributeMappingType.SELECTIVE)));
    attributeMappings.add(new OTAttributeMapping(new OTAttributeMapping.Builder().setDetectorElement(privateCloud).setDetectorProperty("interface").setRefinementElement(openstack).setRefinementProperty("api").setType(OTAttributeMappingType.SELECTIVE)));
    List<OTRelationMapping> relationMappings = new ArrayList<>();
    relationMappings.add(new OTRelationMapping(new OTRelationMapping.Builder().setDetectorElement(privateCloud).setRefinementElement(vm).setRelationType("{ns}hostedOn").setValidSourceOrTarget(null).setDirection(OTRelationDirection.INGOING)));
    return new OTPatternRefinementModel(new OTPatternRefinementModel.Builder().setDetector(detector).setRefinementStructure(refinement).setStayMappings(Arrays.asList(stayMapping)).setPermutationMappings(permutationMappings).setAttributeMappings(attributeMappings).setRelationMappings(relationMappings));
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OTAttributeMapping(org.eclipse.winery.model.tosca.extensions.OTAttributeMapping) OTRelationMapping(org.eclipse.winery.model.tosca.extensions.OTRelationMapping) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)

Aggregations

OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)33 Test (org.junit.jupiter.api.Test)23 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)16 ArrayList (java.util.ArrayList)14 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)14 List (java.util.List)12 OTPermutationMapping (org.eclipse.winery.model.tosca.extensions.OTPermutationMapping)12 OTTopologyFragmentRefinementModel (org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)10 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)10 QName (javax.xml.namespace.QName)8 PatternRefinementModelId (org.eclipse.winery.model.ids.extensions.PatternRefinementModelId)8 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)8 ToscaNode (org.eclipse.winery.topologygraph.model.ToscaNode)8 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)8 Arrays (java.util.Arrays)7 LinkedHashMap (java.util.LinkedHashMap)7 PermutationHelper.addAllPermutationMappings (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.addAllPermutationMappings)7 PermutationHelper.generateComplexPrmWithPatternSet (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generateComplexPrmWithPatternSet)7 PermutationHelper.generatePrmWithTwoPatternsHostedOnAThird (org.eclipse.winery.model.adaptation.substitution.refinement.PermutationHelper.generatePrmWithTwoPatternsHostedOnAThird)7