Skip to content

Commit 5839594

Browse files
authored
issues/1790: Make it possible to use standalone cassandra (#25)
issues/1790: Make it possible to use standalone cassandra
1 parent 8b1707b commit 5839594

20 files changed

+730
-751
lines changed

strongbox-db-import/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
</goals>
5454
<configuration>
5555
<jvmArguments>-Xmx1024m</jvmArguments>
56-
<arguments>--strongbox.db.janus-graph.storage-root=${project.build.directory}/db</arguments>
56+
<arguments>
57+
--strongbox.dbimport.root=${project.build.directory}
58+
</arguments>
5759
</configuration>
5860
</execution>
5961
</executions>

strongbox-db-import/src/main/java/org/carlspring/strongbox/db/schema/SchemaConfig.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

strongbox-db-import/src/main/java/org/carlspring/strongbox/db/server/EmbeddedDbServerConfiguration.java

Lines changed: 0 additions & 53 deletions
This file was deleted.

strongbox-db-import/src/main/java/org/carlspring/strongbox/db/Application.java renamed to strongbox-db-import/src/main/java/org/carlspring/strongbox/dbimport/Application.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package org.carlspring.strongbox.db;
1+
package org.carlspring.strongbox.dbimport;
22

3+
import org.janusgraph.core.JanusGraph;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
56
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
@@ -15,6 +16,8 @@ public class Application
1516
public static void main(String[] args)
1617
{
1718
ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
19+
ctx.getBean(JanusGraph.class);
20+
1821
SpringApplication.exit(ctx, () -> 0);
1922
}
2023
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package org.carlspring.strongbox.dbimport;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.nio.file.Files;
6+
import java.nio.file.Path;
7+
import java.nio.file.Paths;
8+
import java.nio.file.StandardCopyOption;
9+
10+
import org.carlspring.strongbox.db.schema.StrongboxSchema;
11+
import org.janusgraph.core.JanusGraph;
12+
import org.springframework.beans.factory.annotation.Value;
13+
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
14+
import org.springframework.context.annotation.Bean;
15+
import org.springframework.context.annotation.Configuration;
16+
import org.strongbox.db.server.CassandraEmbeddedConfiguration;
17+
import org.strongbox.db.server.CassandraEmbeddedProperties;
18+
import org.strongbox.db.server.JanusGraphConfiguration;
19+
import org.strongbox.db.server.JanusGraphProperties;
20+
import org.strongbox.db.server.JanusGraphServer;
21+
import org.strongbox.db.server.JanusGraphWithEmbeddedCassandra;
22+
23+
/**
24+
* @author Przemyslaw Fusik
25+
* @author sbespalov
26+
*/
27+
@Configuration
28+
@ConfigurationPropertiesScan
29+
class EmbeddedDbServerConfiguration
30+
{
31+
32+
@Bean
33+
JanusGraphServer embeddedDbServer(CassandraEmbeddedConfiguration cassandraConfiguration,
34+
JanusGraphConfiguration janusGraphConfiguration)
35+
throws IOException
36+
{
37+
return new JanusGraphWithEmbeddedCassandra(cassandraConfiguration, janusGraphConfiguration);
38+
}
39+
40+
private void extractConfigurationFile(String rootFolder,
41+
String configFileName)
42+
throws IOException
43+
{
44+
try (InputStream in = JanusGraphWithEmbeddedCassandra.class.getResourceAsStream(String.format("/etc/conf/%s", configFileName)))
45+
{
46+
Path configRoot = Paths.get(rootFolder).resolve("etc").resolve("conf");
47+
Files.createDirectories(configRoot);
48+
Files.copy(in,
49+
configRoot.resolve(configFileName),
50+
StandardCopyOption.REPLACE_EXISTING);
51+
}
52+
}
53+
54+
@Bean
55+
JanusGraph janusGraph(JanusGraphServer server)
56+
throws Exception
57+
{
58+
return new StrongboxSchema().createSchema(server.getJanusGraph());
59+
}
60+
61+
@Bean
62+
JanusGraphProperties dbImportJanusGraphProperties(@Value("${strongbox.dbimport.root}") String dbImportRoot)
63+
throws IOException
64+
{
65+
extractConfigurationFile(dbImportRoot, "janusgraph-cassandra.properties");
66+
Path configFilePath = Paths.get(dbImportRoot).resolve("etc").resolve("conf").resolve("janusgraph-cassandra.properties");
67+
68+
return new JanusGraphProperties( String.format("file:%s", configFilePath.toAbsolutePath().toString()));
69+
}
70+
71+
@Bean
72+
CassandraEmbeddedProperties dbImportCassandraEmbeddedProperties(@Value("${strongbox.dbimport.root}") String dbImportRoot)
73+
throws IOException
74+
{
75+
extractConfigurationFile(dbImportRoot, "cassandra.yaml");
76+
Path rootPath = Paths.get(dbImportRoot).toAbsolutePath();
77+
Path configFilePath = rootPath.resolve("etc").resolve("conf").resolve("cassandra.yaml");
78+
Path storageRootPath = rootPath.resolve("db");
79+
80+
return new CassandraEmbeddedProperties(storageRootPath.toString(), String.format("file:%s", configFilePath.toString()));
81+
}
82+
83+
}

strongbox-db-import/src/main/resources/application.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,5 @@ spring:
22
main:
33
web-application-type: NONE
44
strongbox:
5-
db:
6-
janus-graph:
7-
#TODO: [First start] randomize
8-
storage-username: cassandra
9-
storage-password: cassandra
10-
storage-host: 127.0.0.1
11-
storage-port: 49142
12-
storage-root: ./target/db
13-
logging:
14-
level:
15-
liquibase: INFO
5+
dbimport:
6+
root: ./target

strongbox-db-schema/src/main/java/org/carlspring/strongbox/db/schema/StrongboxSchema.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ public class StrongboxSchema
9595

9696
private static final Logger logger = LoggerFactory.getLogger(StrongboxSchema.class);
9797

98-
public void createSchema(JanusGraph jg)
98+
public JanusGraph createSchema(JanusGraph jg)
9999
throws InterruptedException
100100
{
101+
logger.info("Apply schema changes.");
102+
101103
JanusGraphManagement jgm = jg.openManagement();
102104
try
103105
{
@@ -161,6 +163,10 @@ public void createSchema(JanusGraph jg)
161163
{
162164
jgm.rollback();
163165
}
166+
167+
logger.info("Schema changes applied.");
168+
169+
return jg;
164170
}
165171

166172
protected void enableIndexes(JanusGraphManagement jgm,
@@ -196,7 +202,7 @@ protected Map<String, String> createRelationIndexes(JanusGraph jg,
196202
Map<String, String> result = new HashMap<>();
197203

198204
String name = ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS + "By" + StringUtils.capitalize(TAG_NAME);
199-
if (!jgm.containsGraphIndex(name))
205+
if (!jgm.containsRelationIndex(jgm.getEdgeLabel(ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS), name))
200206
{
201207
jgm.buildEdgeIndex(jgm.getEdgeLabel(ARTIFACT_GROUP_HAS_TAGGED_ARTIFACTS),
202208
name,

strongbox-db-server/src/main/java/org/strongbox/db/server/CassandraEmbeddedConfiguration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
public interface CassandraEmbeddedConfiguration
44
{
55

6-
Integer getPort();
6+
String getStorageRoot();
77

8-
String getStorageFolder();
9-
10-
String getCassandraConfigLoaderClassName();
8+
String getConfigLocation();
9+
1110
}

0 commit comments

Comments
 (0)