Search in sources :

Example 1 with OTTopologyFragmentRefinementModel

use of org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel 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 OTTopologyFragmentRefinementModel

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

the class PermutationGeneratorTest method checkSimpleMutabilityTest.

@Test
void checkSimpleMutabilityTest() {
    setUp();
    PermutationGenerator permutationGenerator = new PermutationGenerator();
    OTTopologyFragmentRefinementModel refinementModel = (OTTopologyFragmentRefinementModel) candidateForTopology3WithDa.getRefinementModel();
    assertTrue(permutationGenerator.checkMutability(refinementModel));
    List<OTStringList> options = refinementModel.getPermutationOptions();
    assertNotNull(options);
    assertEquals(2, options.size());
    options.forEach(permutationOption -> assertEquals(1, permutationOption.getValues().size()));
}
Also used : OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) OTStringList(org.eclipse.winery.model.tosca.extensions.OTStringList) Test(org.junit.jupiter.api.Test)

Example 3 with OTTopologyFragmentRefinementModel

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

the class PermutationGenerator method chekMutabilityOfDetectorRelations.

private List<String> chekMutabilityOfDetectorRelations(OTTopologyFragmentRefinementModel refinementModel) {
    List<String> unmappableRelationIds = new ArrayList<>();
    // try to generate permutation maps.
    for (TNodeTemplate detectorNode : refinementModel.getDetector().getNodeTemplates()) {
        List<TRelationshipTemplate> unMappableRelations = ModelUtilities.getIncomingRelationshipTemplates(refinementModel.getDetector(), detectorNode).stream().filter(relation -> !permutabilityMappingExistsForDetectorElement(relation, refinementModel)).collect(Collectors.toList());
        for (TRelationshipTemplate unmappable : unMappableRelations) {
            logger.info("Checking unmapped relation \"{}\"", unmappable.getId());
            // If the relation exists between two components in a component set we ignore it, as there is no
            // case in which the relation has to be redirected while creating a permutation.
            boolean unmappableRelationExists = refinementModel.getComponentSets().stream().noneMatch(componentSet -> componentSet.getValues().containsAll(Arrays.asList(unmappable.getSourceElement().getRef().getId(), unmappable.getTargetElement().getRef().getId())));
            if (unmappableRelationExists) {
                // If there is only one permutation mapping sourcing from the current detector node,
                // the relation can be redirected directly to the corresponding refinement node.
                // If there are multiple permutations mappings sourcing from the relation's source detector node,
                // do crazy shit: If the corresponding refinement nodes of the relation's source have relations
                // that point to the same node that can be mapped to the current detector node (except for
                // relations among each other), the relation can be redirected to this node.
                TNodeTemplate source = (TNodeTemplate) unmappable.getSourceElement().getRef();
                List<TNodeTemplate> nodesTheSourceRefinesTo = getStayAndPermutationMappings(refinementModel).stream().filter(pm -> pm.getDetectorElement().getId().equals(source.getId())).map(OTPrmMapping::getRefinementElement).filter(element -> element instanceof TNodeTemplate).map(element -> (TNodeTemplate) element).distinct().collect(Collectors.toList());
                Set<TNodeTemplate> nodesTheRefinementNodesAreDependingOn = new HashSet<>();
                nodesTheSourceRefinesTo.forEach(node -> nodesTheRefinementNodesAreDependingOn.addAll(ModelUtilities.getOutgoingRelationshipTemplates(refinementModel.getRefinementStructure(), node).stream().map(outgoing -> outgoing.getTargetElement().getRef()).filter(target -> target instanceof TNodeTemplate).map(target -> (TNodeTemplate) target).filter(target -> refinementModel.getPermutationMappings().stream().anyMatch(pm -> pm.getRefinementElement().getId().equals(target.getId()) && pm.getDetectorElement().getId().equals(detectorNode.getId()))).collect(Collectors.toList())));
                // respective target of the relation automatically.
                if (nodesTheRefinementNodesAreDependingOn.size() == 1) {
                    TNodeTemplate target = nodesTheRefinementNodesAreDependingOn.iterator().next();
                    logger.info("Found possibility to redirect relation \"{}\" to refinement node \"{}\"", unmappable.getId(), target.getId());
                    addMutabilityMapping(unmappable, target, refinementModel);
                    unmappableRelationExists = false;
                }
            } else {
                logger.info("Relation \"{}\" is part of a component set", unmappable.getId());
            }
            if (unmappableRelationExists) {
                unmappableRelationIds.add(unmappable.getId());
            }
        }
    }
    return unmappableRelationIds;
}
Also used : Arrays(java.util.Arrays) RefinementUtils.getAllContentMappingsForRefinementNodeWithoutDetectorNode(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.getAllContentMappingsForRefinementNodeWithoutDetectorNode) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) SerializationUtils(org.apache.commons.lang3.SerializationUtils) RefinementUtils.isStayPlaceholder(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.isStayPlaceholder) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) RefinementUtils.addMutabilityMapping(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.addMutabilityMapping) RefinementUtils.getAllMappingsForDetectorNode(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.getAllMappingsForDetectorNode) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) VersionSupport(org.eclipse.winery.model.version.VersionSupport) Map(java.util.Map) OTPermutationMapping(org.eclipse.winery.model.tosca.extensions.OTPermutationMapping) RefinementUtils.noMappingExistsForRefinementNodeExeptForGivenDetectorNode(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.noMappingExistsForRefinementNodeExeptForGivenDetectorNode) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) OTStayMapping(org.eclipse.winery.model.tosca.extensions.OTStayMapping) RefinementUtils.getStayAndPermutationMappings(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.getStayAndPermutationMappings) RefinementUtils.isStayingRefinementElement(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.isStayingRefinementElement) Logger(org.slf4j.Logger) Set(java.util.Set) IOException(java.io.IOException) RefinementUtils.permutabilityMappingExistsForDetectorElement(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.permutabilityMappingExistsForDetectorElement) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) HasId(org.eclipse.winery.model.tosca.HasId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) RefinementUtils.permutabilityMappingExistsForRefinementNode(org.eclipse.winery.model.adaptation.substitution.refinement.RefinementUtils.permutabilityMappingExistsForRefinementNode) List(java.util.List) IRepository(org.eclipse.winery.repository.backend.IRepository) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) Sets(org.eclipse.collections.impl.factory.Sets) Optional(java.util.Optional) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) OTPrmMapping(org.eclipse.winery.model.tosca.extensions.OTPrmMapping) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) QName(javax.xml.namespace.QName) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) OTStringList(org.eclipse.winery.model.tosca.extensions.OTStringList) OTPrmMapping(org.eclipse.winery.model.tosca.extensions.OTPrmMapping) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ArrayList(java.util.ArrayList) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet)

Example 4 with OTTopologyFragmentRefinementModel

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

the class PermutationGeneratorTestWithGitBackedRepository method simplePrmTest.

@Test
void simplePrmTest() throws Exception {
    this.setRevisionTo("origin/plain");
    OTPatternRefinementModel refinementModel = generatePrmWithoutPermutationMaps();
    PatternRefinementModelId id = new PatternRefinementModelId(refinementModel.getTargetNamespace(), refinementModel.getIdFromIdOrNameField(), false);
    RepositoryFactory.getRepository().setElement(id, refinementModel);
    PermutationGenerator generator = new PermutationGenerator();
    Map<String, OTTopologyFragmentRefinementModel> permutations = generator.generatePermutations(refinementModel);
    assertEquals(6, permutations.size());
    OTTopologyFragmentRefinementModel permutation_1 = permutations.get("SimplePrm_permutation-1-w1-wip1");
    assertNotNull(permutation_1);
    assertEquals(4, permutation_1.getDetector().getNodeTemplates().size());
    assertEquals(4, permutation_1.getDetector().getRelationshipTemplates().size());
    OTTopologyFragmentRefinementModel permutation_2 = permutations.get("SimplePrm_permutation-2-w1-wip1");
    assertNotNull(permutation_2);
    assertEquals(3, permutation_2.getDetector().getNodeTemplates().size());
    assertEquals(2, permutation_2.getDetector().getRelationshipTemplates().size());
    OTTopologyFragmentRefinementModel permutation_3 = permutations.get("SimplePrm_permutation-3-w1-wip1");
    assertNotNull(permutation_3);
    assertEquals(4, permutation_3.getDetector().getNodeTemplates().size());
    assertEquals(3, permutation_3.getDetector().getRelationshipTemplates().size());
    OTTopologyFragmentRefinementModel permutation_1_2 = permutations.get("SimplePrm_permutation-1-2-w1-wip1");
    assertNotNull(permutation_1_2);
    assertEquals(4, permutation_1_2.getDetector().getNodeTemplates().size());
    assertEquals(4, permutation_1_2.getDetector().getRelationshipTemplates().size());
    OTTopologyFragmentRefinementModel permutation_1_3 = permutations.get("SimplePrm_permutation-1-3-w1-wip1");
    assertNotNull(permutation_1_3);
    assertEquals(5, permutation_1_3.getDetector().getNodeTemplates().size());
    assertEquals(5, permutation_1_3.getDetector().getRelationshipTemplates().size());
    OTTopologyFragmentRefinementModel permutation_2_3 = permutations.get("SimplePrm_permutation-2-3-w1-wip1");
    assertNotNull(permutation_2_3);
    assertEquals(4, permutation_2_3.getDetector().getNodeTemplates().size());
    assertEquals(3, permutation_2_3.getDetector().getRelationshipTemplates().size());
}
Also used : PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Example 5 with OTTopologyFragmentRefinementModel

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

the class PatternDetectionUtilsTest method toPdrms.

@Test
public void toPdrms() {
    List<OTRefinementModel> refinementModels = new ArrayList<>();
    refinementModels.add(new OTTestRefinementModel());
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 0);
    refinementModels.add(new OTTopologyFragmentRefinementModel());
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 0);
    OTPatternRefinementModel prm = new OTPatternRefinementModel();
    refinementModels.add(prm);
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 0);
    prm.setIsPdrm(true);
    refinementModels.add(prm);
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 1);
    prm.setIsPdrm(false);
    PatternDetectionUtils.toPdrms(refinementModels);
    assertEquals(refinementModels.size(), 0);
}
Also used : OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) ArrayList(java.util.ArrayList) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) Test(org.junit.jupiter.api.Test)

Aggregations

OTTopologyFragmentRefinementModel (org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel)11 OTPatternRefinementModel (org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel)8 Map (java.util.Map)7 PatternRefinementModelId (org.eclipse.winery.model.ids.extensions.PatternRefinementModelId)7 ArrayList (java.util.ArrayList)6 TopologyFragmentRefinementModelId (org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 QName (javax.xml.namespace.QName)5 HasId (org.eclipse.winery.model.tosca.HasId)4 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)4 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)4 OTStayMapping (org.eclipse.winery.model.tosca.extensions.OTStayMapping)4 ModelUtilities (org.eclipse.winery.model.tosca.utils.ModelUtilities)4 RepositoryFactory (org.eclipse.winery.repository.backend.RepositoryFactory)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 IOException (java.io.IOException)3 Arrays (java.util.Arrays)3