Skip to content

Commit

Permalink
[#202] Add option to export graph representation to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
shantstepanian committed Sep 23, 2018
1 parent cff4e18 commit 48b6722
Show file tree
Hide file tree
Showing 49 changed files with 198 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Functionality Improvements
#199: Adding support for PostgreSQL roles and extensions in the environment setup step
#202: Add option to export graph representation to a file

### Technical Improvements
Moving more of the code over to Kotlin
Expand Down
1 change: 1 addition & 0 deletions obevo-core/NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This product depends on (links to) the following software:
IntelliJ IDEA Annotations under The Apache Software License, Version 2.0
JCL 1.1.1 implemented over SLF4J under MIT License
JGraphT - Core under Eclipse Public License (EPL) 1.0
JGraphT - Ext under GNU Lesser General Public License Version 2.1, February 1999 or Eclipse Public License (EPL) 1.0
juniversalchardet under Mozilla Public License 1.1 (MPL 1.1)
org.jetbrains.kotlin:kotlin-stdlib under The Apache License, Version 2.0
org.jetbrains.kotlin:kotlin-stdlib-common under The Apache License, Version 2.0
Expand Down
2 changes: 2 additions & 0 deletions obevo-core/obevo-core.iml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-ext:0.9.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.18" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.2.61" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.2.61" level="project" />
Expand All @@ -40,6 +41,7 @@
<orderEntry type="module" module-name="obevo-internal-test-client-01" scope="TEST" />
<orderEntry type="module" module-name="obevo-internal-test-client-02" scope="TEST" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-core:0.9.1" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-ext:0.9.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.cli-parser:cli:7" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-configuration2:2.2" level="project" />
Expand Down
16 changes: 16 additions & 0 deletions obevo-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@
<artifactId>jgrapht-core</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-ext</artifactId>
<version>0.9.1</version>
<exclusions>
<!-- excluding these unused dependencies -->
<exclusion>
<groupId>org.tinyjee.jgraphx</groupId>
<artifactId>jgraphx</artifactId>
</exclusion>
<exclusion>
<groupId>jgraph</groupId>
<artifactId>jgraph</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2017 Goldman Sachs.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.gs.obevo.api.platform;

public enum GraphExportFormat {
DOT,
GML,
GRAPHML,
MATRIX,
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.gs.obevo.api.platform;

import java.io.File;

import com.gs.obevo.api.ChangesetNamePredicate;
import com.gs.obevo.api.appdata.ChangeKey;
import com.gs.obevo.api.appdata.DeployExecutionAttribute;
Expand All @@ -37,6 +39,8 @@ public class MainDeployerArgs {
private String reason;
private ImmutableSet<? extends DeployExecutionAttribute> deployExecutionAttributes = Sets.immutable.empty();
private String deployRequesterId;
private File sourceGraphExportFile;
private GraphExportFormat sourceGraphExportFormat;

public Predicate<? super ChangeKey> getChangeInclusionPredicate() {
return changeInclusionPredicate;
Expand Down Expand Up @@ -218,4 +222,20 @@ public MainDeployerArgs allChangesets(boolean allChangesets) {
this.setAllChangesets(allChangesets);
return this;
}

public File getSourceGraphExportFile() {
return sourceGraphExportFile;
}

public void setSourceGraphExportFile(File sourceGraphExportFile) {
this.sourceGraphExportFile = sourceGraphExportFile;
}

public GraphExportFormat getSourceGraphExportFormat() {
return sourceGraphExportFormat;
}

public void setSourceGraphExportFormat(GraphExportFormat sourceGraphExportFormat) {
this.sourceGraphExportFormat = sourceGraphExportFormat;
}
}
21 changes: 21 additions & 0 deletions obevo-core/src/main/java/com/gs/obevo/cmdline/DeployerArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.File;
import java.util.Arrays;

import com.gs.obevo.api.platform.GraphExportFormat;
import com.gs.obevo.util.inputreader.Credential;
import com.sampullara.cli.Argument;
import org.eclipse.collections.api.list.primitive.ImmutableBooleanList;
Expand Down Expand Up @@ -58,6 +59,8 @@ public class DeployerArgs {
private boolean lenientSetupEnvInfra = false;
private boolean strictSetupEnvInfra = false;
private Boolean forceEnvSetup;
private File sourceGraphExportFile;
private String sourceGraphExportFormatStr; // to be converted to enum in the getter

@Argument(value = "env", required = false)
public void setEnvNames(String[] envNames) {
Expand Down Expand Up @@ -383,4 +386,22 @@ public Boolean getForceEnvSetup() {
public void setForceEnvSetup(Boolean forceEnvSetup) {
this.forceEnvSetup = forceEnvSetup;
}

public File getSourceGraphExportFile() {
return sourceGraphExportFile;
}

@Argument(value = "sourceGraphExportFile", required = false, description = "file to write the graph represent of the input for")
public void setSourceGraphExportFile(File sourceGraphExportFile) {
this.sourceGraphExportFile = sourceGraphExportFile;
}

public GraphExportFormat getSourceGraphExportFormat() {
return GraphExportFormat.valueOf(sourceGraphExportFormatStr);
}

@Argument(value = "sourceGraphExportFormat", required = false, description = "output to write to, based on JGraphT implementation. Only used if sourceGraphExportFile is specified. Can be DOT, GML, GRAPHML, MATRIX. Default == DOT")
public void setSourceGraphExportFormatStr(String sourceGraphExportFormat) {
this.sourceGraphExportFormatStr = sourceGraphExportFormat;
}
}
33 changes: 33 additions & 0 deletions obevo-core/src/main/java/com/gs/obevo/impl/MainDeployer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ import org.eclipse.collections.impl.block.factory.Predicates
import org.eclipse.collections.impl.block.factory.StringFunctions
import org.eclipse.collections.impl.factory.Lists
import org.eclipse.collections.impl.factory.Sets
import org.jgrapht.DirectedGraph
import org.jgrapht.ext.*
import org.jgrapht.graph.DefaultEdge
import org.slf4j.LoggerFactory
import java.io.FileWriter
import java.io.Writer
import java.sql.Timestamp
import java.util.*
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -205,6 +210,12 @@ class MainDeployer<P : Platform, E : Environment<P>>(

val dependencyGraph = graphEnricher.createDependencyGraph(sourceChanges, deployerArgs.isRollback)

deployerArgs.sourceGraphExportFile?.let { sourceGraphOutputFile ->
val exporterFormat = deployerArgs.sourceGraphExportFormat ?: GraphExportFormat.DOT
val exporterFunc = getExporterFunc(exporterFormat)
FileWriter(sourceGraphOutputFile).use { exporterFunc(it, dependencyGraph) }
}

sourceChanges.each { it.dependentChanges = GraphUtil.getDependencyNodes(dependencyGraph, it) }

val artifactsToProcess = changesetCreator.determineChangeset(changePairs, sourceChanges, deployStrategy.isInitAllowedOnHashExceptions)
Expand Down Expand Up @@ -297,6 +308,28 @@ class MainDeployer<P : Platform, E : Environment<P>>(
}
}

private fun getExporterFunc(exporterFormat: Enum<GraphExportFormat>): (Writer, DirectedGraph<Change, DefaultEdge>) -> Unit {
val vertexNameProvider : VertexNameProvider<Change> = VertexNameProvider {
change : Change -> change.objectName + "." + change.changeName
}

when (exporterFormat) {
GraphExportFormat.DOT -> return { writer: Writer, graph: DirectedGraph<Change, DefaultEdge> ->
DOTExporter<Change, DefaultEdge>(IntegerNameProvider<Change>(), vertexNameProvider, null).export(writer, graph)
}
GraphExportFormat.GML -> return { writer: Writer, graph: DirectedGraph<Change, DefaultEdge> ->
GmlExporter<Change, DefaultEdge>(IntegerNameProvider<Change>(), vertexNameProvider, null, null).export(writer, graph)
}
GraphExportFormat.GRAPHML -> return { writer: Writer, graph: DirectedGraph<Change, DefaultEdge> ->
GraphMLExporter<Change, DefaultEdge>(IntegerNameProvider<Change>(), vertexNameProvider, null, null).export(writer, graph)
}
GraphExportFormat.MATRIX -> return { writer: Writer, graph: DirectedGraph<Change, DefaultEdge> ->
MatrixExporter<Change, DefaultEdge>().exportAdjacencyMatrix(writer, graph)
}
else -> throw IllegalArgumentException("Export Format $exporterFormat is not supported here")
}
}

private fun logArgumentMetrics(deployerArgs: MainDeployerArgs) {
deployMetricsCollector.addMetric("args.onboardingMode", deployerArgs.isOnboardingMode)
deployMetricsCollector.addMetric("args.init", deployerArgs.isPerformInitOnly)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.gs.obevo.cmdline;

import java.io.File;

import com.gs.obevo.api.platform.GraphExportFormat;
import com.gs.obevo.util.ArgsParser;
import org.junit.Test;

Expand Down Expand Up @@ -48,6 +51,14 @@ public void testChangesets() {
assertEquals(true, args.getForceEnvSetup());
}

@Test
public void testGraphArgs() {
DeployerArgs args = parseArgs("-sourcePath abc -sourceGraphExportFile /home/myfile.txt -sourceGraphExportFormat GML");
assertEquals("abc", args.getSourcePath());
assertEquals(new File("/home/myfile.txt"), args.getSourceGraphExportFile());
assertEquals(GraphExportFormat.GML, args.getSourceGraphExportFormat());
}

private DeployerArgs parseArgs(String argsStr) {
return new ArgsParser().parse(argsStr.split(" "), new DeployerArgs());
}
Expand Down
1 change: 1 addition & 0 deletions obevo-db-impls/obevo-db-db2/NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This product depends on (links to) the following software:
IntelliJ IDEA Annotations under The Apache Software License, Version 2.0
JCL 1.1.1 implemented over SLF4J under MIT License
JGraphT - Core under Eclipse Public License (EPL) 1.0
JGraphT - Ext under GNU Lesser General Public License Version 2.1, February 1999 or Eclipse Public License (EPL) 1.0
Joda time under Apache 2
juniversalchardet under Mozilla Public License 1.1 (MPL 1.1)
MySQL Connector/J under The GNU General Public License, v2 with FOSS exception
Expand Down
2 changes: 2 additions & 0 deletions obevo-db-impls/obevo-db-db2/obevo-db-db2.iml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<orderEntry type="library" scope="RUNTIME" name="Maven: us.fatehi:schemacrawler-oracle:14.16.01-java7" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: us.fatehi:schemacrawler-sqlserver:14.16.01-java7" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: us.fatehi:schemacrawler-db2:14.16.01-java7" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-ext:0.9.1" level="project" />
<orderEntry type="module" module-name="obevo-db" />
<orderEntry type="library" name="Maven: commons-dbutils:commons-dbutils:1.6" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:1.6.2" level="project" />
Expand All @@ -53,6 +54,7 @@
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.61" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-core:0.9.1" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-ext:0.9.1" level="project" />
<orderEntry type="library" name="Maven: com.google.code.cli-parser:cli:7" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.21" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-vfs2:2.0" level="project" />
Expand Down
1 change: 1 addition & 0 deletions obevo-db-impls/obevo-db-h2/NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This product depends on (links to) the following software:
IntelliJ IDEA Annotations under The Apache Software License, Version 2.0
JCL 1.1.1 implemented over SLF4J under MIT License
JGraphT - Core under Eclipse Public License (EPL) 1.0
JGraphT - Ext under GNU Lesser General Public License Version 2.1, February 1999 or Eclipse Public License (EPL) 1.0
Joda time under Apache 2
juniversalchardet under Mozilla Public License 1.1 (MPL 1.1)
MySQL Connector/J under The GNU General Public License, v2 with FOSS exception
Expand Down
2 changes: 2 additions & 0 deletions obevo-db-impls/obevo-db-h2/obevo-db-h2.iml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<orderEntry type="library" scope="RUNTIME" name="Maven: us.fatehi:schemacrawler-oracle:14.16.01-java7" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: us.fatehi:schemacrawler-sqlserver:14.16.01-java7" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: us.fatehi:schemacrawler-db2:14.16.01-java7" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-ext:0.9.1" level="project" />
<orderEntry type="module" module-name="obevo-db" />
<orderEntry type="library" name="Maven: commons-dbutils:commons-dbutils:1.6" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:1.6.2" level="project" />
Expand All @@ -53,6 +54,7 @@
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.61" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-core:0.9.1" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-ext:0.9.1" level="project" />
<orderEntry type="library" name="Maven: com.google.code.cli-parser:cli:7" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.21" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-vfs2:2.0" level="project" />
Expand Down
1 change: 1 addition & 0 deletions obevo-db-impls/obevo-db-hsql/NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This product depends on (links to) the following software:
IntelliJ IDEA Annotations under The Apache Software License, Version 2.0
JCL 1.1.1 implemented over SLF4J under MIT License
JGraphT - Core under Eclipse Public License (EPL) 1.0
JGraphT - Ext under GNU Lesser General Public License Version 2.1, February 1999 or Eclipse Public License (EPL) 1.0
Joda time under Apache 2
juniversalchardet under Mozilla Public License 1.1 (MPL 1.1)
MySQL Connector/J under The GNU General Public License, v2 with FOSS exception
Expand Down
2 changes: 2 additions & 0 deletions obevo-db-impls/obevo-db-hsql/obevo-db-hsql.iml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="RUNTIME" name="Maven: us.fatehi:schemacrawler:14.16.01-java7" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-ext:0.9.1" level="project" />
<orderEntry type="module" module-name="obevo-db" />
<orderEntry type="library" name="Maven: commons-dbutils:commons-dbutils:1.6" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:1.6.2" level="project" />
Expand All @@ -47,6 +48,7 @@
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.61" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-core:0.9.1" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-ext:0.9.1" level="project" />
<orderEntry type="library" name="Maven: com.google.code.cli-parser:cli:7" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.21" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-vfs2:2.0" level="project" />
Expand Down
1 change: 1 addition & 0 deletions obevo-db-impls/obevo-db-internal-test-helper/NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This product depends on (links to) the following software:
IntelliJ IDEA Annotations under The Apache Software License, Version 2.0
JCL 1.1.1 implemented over SLF4J under MIT License
JGraphT - Core under Eclipse Public License (EPL) 1.0
JGraphT - Ext under GNU Lesser General Public License Version 2.1, February 1999 or Eclipse Public License (EPL) 1.0
Joda time under Apache 2
JUnit under Common Public License Version 1.0
junit-addons under Apache License, Version 2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-ext:0.9.1" level="project" />
<orderEntry type="module" module-name="obevo-db" production-on-test="" />
<orderEntry type="library" name="Maven: commons-dbutils:commons-dbutils:1.6" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:1.6.2" level="project" />
Expand All @@ -42,6 +43,7 @@
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.61" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-core:0.9.1" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-ext:0.9.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.cli-parser:cli:7" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.21" level="project" />
Expand Down
1 change: 1 addition & 0 deletions obevo-db-impls/obevo-db-mssql/NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This product depends on (links to) the following software:
IntelliJ IDEA Annotations under The Apache Software License, Version 2.0
JCL 1.1.1 implemented over SLF4J under MIT License
JGraphT - Core under Eclipse Public License (EPL) 1.0
JGraphT - Ext under GNU Lesser General Public License Version 2.1, February 1999 or Eclipse Public License (EPL) 1.0
Joda time under Apache 2
juniversalchardet under Mozilla Public License 1.1 (MPL 1.1)
Microsoft JDBC Driver for SQL Server under MIT License
Expand Down
2 changes: 2 additions & 0 deletions obevo-db-impls/obevo-db-mssql/obevo-db-mssql.iml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<orderEntry type="library" scope="RUNTIME" name="Maven: us.fatehi:schemacrawler-oracle:14.16.01-java7" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: us.fatehi:schemacrawler-sqlserver:14.16.01-java7" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: us.fatehi:schemacrawler-db2:14.16.01-java7" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-ext:0.9.1" level="project" />
<orderEntry type="module" module-name="obevo-db" />
<orderEntry type="library" name="Maven: commons-dbutils:commons-dbutils:1.6" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:1.6.2" level="project" />
Expand All @@ -54,6 +55,7 @@
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.61" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-core:0.9.1" level="project" />
<orderEntry type="library" name="Maven: org.jgrapht:jgrapht-ext:0.9.1" level="project" />
<orderEntry type="library" name="Maven: com.google.code.cli-parser:cli:7" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.21" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-vfs2:2.0" level="project" />
Expand Down
Loading

0 comments on commit 48b6722

Please sign in to comment.