diff --git a/src/main/java/org/gcube/portal/databook/server/CassandraClusterConnection.java b/src/main/java/org/gcube/portal/databook/server/CassandraClusterConnection.java index 6844853..8fba175 100644 --- a/src/main/java/org/gcube/portal/databook/server/CassandraClusterConnection.java +++ b/src/main/java/org/gcube/portal/databook/server/CassandraClusterConnection.java @@ -51,7 +51,36 @@ public class CassandraClusterConnection { */ protected CassandraClusterConnection(boolean dropSchema) { if (clusterName == null || host == null || keyspaceName == null) { - RunningCluster cluster = RunningCluster.getInstance(); + RunningCluster cluster = RunningCluster.getInstance(null); + clusterName = cluster.getClusterName(); + host = cluster.getHost(); + keyspaceName = cluster.getKeyspaceName(); + } + + AstyanaxContext clusterContext = new AstyanaxContext.Builder() + .forCluster(clusterName) + .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()) + .withConnectionPoolConfiguration( + new ConnectionPoolConfigurationImpl( + clusterName).setMaxConnsPerHost(100) + .setSeeds(host)) + .withConnectionPoolMonitor( + new CountingConnectionPoolMonitor()) + .buildCluster(ThriftFamilyFactory.getInstance()); + + _log.info(keyspaceName + " KeySpace SetUp ..."); + SetUpKeySpaces(clusterContext, dropSchema); + _log.info("CONNECTED! using KeySpace: " + keyspaceName); + } + + /** + * + * @param dropSchema set true if you want do drop the current and set up new one + * @return the connection to cassandra cluster + */ + protected CassandraClusterConnection(boolean dropSchema, String infrastructureName) { + if (clusterName == null || host == null || keyspaceName == null) { + RunningCluster cluster = RunningCluster.getInstance(infrastructureName); clusterName = cluster.getClusterName(); host = cluster.getHost(); keyspaceName = cluster.getKeyspaceName(); diff --git a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java index 040a28b..169518d 100644 --- a/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java +++ b/src/main/java/org/gcube/portal/databook/server/DBCassandraAstyanaxImpl.java @@ -192,6 +192,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore { public DBCassandraAstyanaxImpl() { conn = new CassandraClusterConnection(false); } + + /** + * public constructor, no dropping schema is allowed, infrastructureName is given. + */ + public DBCassandraAstyanaxImpl(String infrastructureName) { + conn = new CassandraClusterConnection(false, infrastructureName); + } + /** * execute the mutation batch * @param m diff --git a/src/main/java/org/gcube/portal/databook/server/RunningCluster.java b/src/main/java/org/gcube/portal/databook/server/RunningCluster.java index cea344e..1bc34ce 100644 --- a/src/main/java/org/gcube/portal/databook/server/RunningCluster.java +++ b/src/main/java/org/gcube/portal/databook/server/RunningCluster.java @@ -58,30 +58,31 @@ public class RunningCluster implements Serializable { * Keyspace Name */ private String keyspaceName; + /** - * + * @ param infrastructureName could be null * @return an instance of the RunningCluster */ - public static synchronized RunningCluster getInstance() { + public static synchronized RunningCluster getInstance(String infrastructureName) { if (singleton == null) { - singleton = new RunningCluster(); + singleton = new RunningCluster(infrastructureName); } return singleton; } /** * private constructor */ - private RunningCluster() { + private RunningCluster(String infrastructureName) { try { - List resources = getConfigurationFromIS(); + List resources = getConfigurationFromIS(infrastructureName); if (resources.size() > 1) { _log.error("Too many Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" in this scope "); throw new TooManyRunningClustersException("There exist more than 1 Runtime Resource in this scope having name " - + RUNTIME_RESOURCE_NAME + " and Platform " + PLATFORM_NAME + ". Only one allowed per infrasrtucture."); + + RUNTIME_RESOURCE_NAME + " and Platform " + PLATFORM_NAME + ". Only one allowed per infrasrtucture."); } else if (resources.size() == 0){ _log.error("There is no Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" and Platform " + PLATFORM_NAME + " in this scope. Using default configuration properties: " + DEFAULT_CONFIGURATION); - loadDefaultConfiguration(); + loadDefaultConfiguration(); } else { for (ServiceEndpoint res : resources) { @@ -100,9 +101,13 @@ public class RunningCluster implements Serializable { * @return the * @throws Exception */ - private List getConfigurationFromIS() throws Exception { - PortalContext context = PortalContext.getConfiguration(); - String scope = "/" + context.getInfrastructureName(); + private List getConfigurationFromIS(String infrastructureName) throws Exception { + PortalContext context = PortalContext.getConfiguration(); + String scope = "/"; + if(infrastructureName != null && !infrastructureName.isEmpty()) + scope += infrastructureName; + else + scope += context.getInfrastructureName(); String currScope = ScopeProvider.instance.get(); ScopeProvider.instance.set(scope); SimpleQuery query = queryFor(ServiceEndpoint.class);