Skip to content

Commit

Permalink
refactoring of topologygraph
Browse files Browse the repository at this point in the history
  • Loading branch information
lharzenetter committed Aug 24, 2018
1 parent 661c1e9 commit 50b9f95
Show file tree
Hide file tree
Showing 20 changed files with 291 additions and 304 deletions.
73 changes: 30 additions & 43 deletions org.eclipse.winery.compliance/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,22 @@
<groupId>org.eclipse.winery</groupId>
<artifactId>org.eclipse.winery.model.tosca</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.winery</groupId>
<artifactId>org.eclipse.winery.topologygraph</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>1.0.1</version>
<version>${org.jgrapht.jgrapht-core.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.winery</groupId>
<artifactId>org.eclipse.winery.repository</artifactId>
<artifactId>org.eclipse.winery.topologygraph</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -72,28 +57,30 @@
<version>${org.slf4j}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.4-jre</version>
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.j2objc</groupId>
<artifactId>j2objc-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import java.util.Optional;

import org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher;
import org.eclipse.winery.topologygraph.matching.model.ToscaEdge;
import org.eclipse.winery.topologygraph.matching.model.ToscaGraph;
import org.eclipse.winery.topologygraph.matching.model.ToscaNode;
import org.eclipse.winery.topologygraph.matching.transformation.ToscaTransformer;
import org.eclipse.winery.topologygraph.model.ToscaEdge;
import org.eclipse.winery.topologygraph.model.ToscaGraph;
import org.eclipse.winery.topologygraph.model.ToscaNode;
import org.eclipse.winery.topologygraph.transformation.ToscaTransformer;
import org.eclipse.winery.model.tosca.TComplianceRule;
import org.eclipse.winery.model.tosca.TTopologyTemplate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.eclipse.winery.common.ids.Namespace;
import org.eclipse.winery.common.ids.definitions.ComplianceRuleId;
import org.eclipse.winery.topologygraph.matching.model.ToscaNode;
import org.eclipse.winery.topologygraph.model.ToscaNode;
import org.eclipse.winery.model.tosca.TComplianceRule;
import org.eclipse.winery.model.tosca.TServiceTemplate;
import org.eclipse.winery.repository.backend.IRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import java.util.stream.Collectors;

import org.eclipse.winery.topologygraph.matching.IToscaMatcher;
import org.eclipse.winery.topologygraph.matching.model.ToscaEdge;
import org.eclipse.winery.topologygraph.matching.model.ToscaEntity;
import org.eclipse.winery.topologygraph.matching.model.ToscaNode;
import org.eclipse.winery.topologygraph.model.ToscaEdge;
import org.eclipse.winery.topologygraph.model.ToscaEntity;
import org.eclipse.winery.topologygraph.model.ToscaNode;
import org.eclipse.winery.model.tosca.TEntityType;
import org.eclipse.winery.model.tosca.TPolicy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
import org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult;
import org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker;
import org.eclipse.winery.compliance.checking.ToscaComplianceRuleMatcher;
import org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher;
import org.eclipse.winery.topologygraph.matching.model.ToscaEdge;
import org.eclipse.winery.topologygraph.matching.model.ToscaEdgeFactory;
import org.eclipse.winery.topologygraph.matching.model.ToscaGraph;
import org.eclipse.winery.topologygraph.matching.model.ToscaNode;
import org.eclipse.winery.model.tosca.TComplianceRule;
import org.eclipse.winery.model.tosca.TExtensibleElements;
import org.eclipse.winery.model.tosca.TNodeTemplate;
Expand All @@ -56,12 +51,16 @@
import org.eclipse.winery.repository.backend.RepositoryFactory;
import org.eclipse.winery.repository.backend.filebased.FilebasedRepository;
import org.eclipse.winery.repository.configuration.FileBasedRepositoryConfiguration;
import org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher;
import org.eclipse.winery.topologygraph.model.ToscaEdge;
import org.eclipse.winery.topologygraph.model.ToscaEdgeFactory;
import org.eclipse.winery.topologygraph.model.ToscaGraph;
import org.eclipse.winery.topologygraph.model.ToscaNode;

import org.apache.commons.lang3.StringUtils;
import org.jgrapht.GraphMapping;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static com.google.common.collect.Lists.newArrayList;
import static org.eclipse.winery.compliance.ToscaModelHelper.TEST_TARGET_NAMESPACE;
Expand All @@ -78,10 +77,10 @@
import static org.eclipse.winery.compliance.ToscaModelHelper.createTServiceTemplate;
import static org.eclipse.winery.compliance.ToscaModelHelper.createTTopologyTemplate;
import static org.eclipse.winery.compliance.ToscaModelHelper.setDerivedFrom;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ToscaGraphIsomorphismTest {

Expand All @@ -98,8 +97,7 @@ private void persist(HashMap<DefinitionsChildId, TExtensibleElements> allEntitie
}
}

@Before
@After
@BeforeEach
public void cleanUp() {
repository.doClear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import org.eclipse.winery.common.ids.definitions.ComplianceRuleId;
import org.eclipse.winery.common.ids.definitions.NodeTypeId;
import org.eclipse.winery.topologygraph.matching.model.ToscaEdge;
import org.eclipse.winery.topologygraph.matching.model.ToscaGraph;
import org.eclipse.winery.topologygraph.matching.model.ToscaNode;
import org.eclipse.winery.topologygraph.matching.transformation.ToscaTransformer;
import org.eclipse.winery.topologygraph.model.ToscaEdge;
import org.eclipse.winery.topologygraph.model.ToscaGraph;
import org.eclipse.winery.topologygraph.model.ToscaNode;
import org.eclipse.winery.topologygraph.transformation.ToscaTransformer;
import org.eclipse.winery.model.tosca.TComplianceRule;
import org.eclipse.winery.model.tosca.TEntityType;
import org.eclipse.winery.model.tosca.TNodeTemplate;
Expand Down
3 changes: 1 addition & 2 deletions org.eclipse.winery.topologygraph/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>1.0.1</version>
<version>${org.jgrapht.jgrapht-core.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.winery</groupId>
Expand All @@ -42,5 +42,4 @@
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
********************************************************************************/
package org.eclipse.winery.topologygraph.matching;

import org.eclipse.winery.topologygraph.matching.model.ToscaEdge;
import org.eclipse.winery.topologygraph.matching.model.ToscaNode;
import org.eclipse.winery.topologygraph.model.ToscaEdge;
import org.eclipse.winery.topologygraph.model.ToscaNode;

public interface IToscaMatcher {

boolean isCompatible(ToscaNode left, ToscaNode right);
boolean isCompatible(ToscaNode left, ToscaNode right);

boolean isCompatible(ToscaEdge left, ToscaEdge right);
boolean isCompatible(ToscaEdge left, ToscaEdge right);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
********************************************************************************/
package org.eclipse.winery.topologygraph.matching;

import org.eclipse.winery.topologygraph.matching.model.ToscaEdge;
import org.eclipse.winery.topologygraph.matching.model.ToscaNode;
import org.eclipse.winery.topologygraph.model.ToscaEdge;
import org.eclipse.winery.topologygraph.model.ToscaNode;

public class ToscaComparatorProxy {
private final IToscaMatcher matcher;
private final IToscaMatcher matcher;

public ToscaComparatorProxy(IToscaMatcher matcher) {
this.matcher = (matcher != null) ? matcher : new ToscaDefaultMatcher();
}
public ToscaComparatorProxy(IToscaMatcher matcher) {
this.matcher = (matcher != null) ? matcher : new ToscaDefaultMatcher();
}

public int compareTypeCompatible(ToscaNode left, ToscaNode right) {
return matcher.isCompatible(left, right) ? 0 : -1;
}
public int compareTypeCompatible(ToscaNode left, ToscaNode right) {
return matcher.isCompatible(left, right) ? 0 : -1;
}

public int compareTypeCompatible(ToscaEdge left, ToscaEdge right) {
return matcher.isCompatible(left, right) ? 0 : -1;
}
public int compareTypeCompatible(ToscaEdge left, ToscaEdge right) {
return matcher.isCompatible(left, right) ? 0 : -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
********************************************************************************/
package org.eclipse.winery.topologygraph.matching;

import org.eclipse.winery.topologygraph.matching.model.ToscaEdge;
import org.eclipse.winery.topologygraph.matching.model.ToscaNode;
import org.eclipse.winery.topologygraph.model.ToscaEdge;
import org.eclipse.winery.topologygraph.model.ToscaNode;

import org.apache.commons.lang3.StringUtils;

public class ToscaDefaultMatcher implements IToscaMatcher {

@Override
public boolean isCompatible(ToscaNode left, ToscaNode right) {
return StringUtils.equals(left.getNodeTemplate().getName(), right.getNodeTemplate().getName());
}
@Override
public boolean isCompatible(ToscaNode left, ToscaNode right) {
return StringUtils.equals(left.getNodeTemplate().getName(), right.getNodeTemplate().getName());
}

@Override
public boolean isCompatible(ToscaEdge left, ToscaEdge right) {
return StringUtils.equals(left.getTemplate().getName(), right.getTemplate().getName());
}
@Override
public boolean isCompatible(ToscaEdge left, ToscaEdge right) {
return StringUtils.equals(left.getTemplate().getName(), right.getTemplate().getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
import java.util.Comparator;
import java.util.Iterator;

import org.eclipse.winery.topologygraph.matching.model.ToscaEdge;
import org.eclipse.winery.topologygraph.matching.model.ToscaGraph;
import org.eclipse.winery.topologygraph.matching.model.ToscaNode;
import org.eclipse.winery.topologygraph.model.ToscaEdge;
import org.eclipse.winery.topologygraph.model.ToscaGraph;
import org.eclipse.winery.topologygraph.model.ToscaNode;

import org.jgrapht.GraphMapping;
import org.jgrapht.alg.isomorphism.VF2SubgraphIsomorphismInspector;

public class ToscaIsomorphismMatcher {

public Iterator<GraphMapping<ToscaNode, ToscaEdge>> findMatches(ToscaGraph queryGraph, ToscaGraph toSearchIn, IToscaMatcher comp) {
public Iterator<GraphMapping<ToscaNode, ToscaEdge>> findMatches(ToscaGraph queryGraph, ToscaGraph toSearchIn, IToscaMatcher comp) {

// NEVER CHANGE THE ORDERING OF THE PARAMETERS. THE SWITCH (RIGHT, LEFT) IS DELIBERATE!
Comparator<ToscaNode> vertexComparator = (ToscaNode left, ToscaNode right) -> new ToscaComparatorProxy(comp).compareTypeCompatible(right, left);
Comparator<ToscaEdge> edgeComparator = (ToscaEdge left, ToscaEdge right) -> new ToscaComparatorProxy(comp).compareTypeCompatible(right, left);
// NEVER CHANGE THE ORDERING OF THE PARAMETERS. THE SWITCH (RIGHT, LEFT) IS DELIBERATE!
Comparator<ToscaNode> vertexComparator = (ToscaNode left, ToscaNode right) -> new ToscaComparatorProxy(comp).compareTypeCompatible(right, left);
Comparator<ToscaEdge> edgeComparator = (ToscaEdge left, ToscaEdge right) -> new ToscaComparatorProxy(comp).compareTypeCompatible(right, left);

VF2SubgraphIsomorphismInspector<ToscaNode, ToscaEdge> inspector = new VF2SubgraphIsomorphismInspector<>(toSearchIn, queryGraph, vertexComparator, edgeComparator);
return inspector.getMappings();
}
VF2SubgraphIsomorphismInspector<ToscaNode, ToscaEdge> inspector = new VF2SubgraphIsomorphismInspector<>(toSearchIn, queryGraph, vertexComparator, edgeComparator);
return inspector.getMappings();
}
}

This file was deleted.

Loading

0 comments on commit 50b9f95

Please sign in to comment.