The infrastructure name parameter now can be passed.

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@122843 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-02-04 15:52:46 +00:00
parent a5ea860381
commit 094380d0ea
3 changed files with 53 additions and 11 deletions

View File

@ -51,7 +51,36 @@ public class CassandraClusterConnection {
*/ */
protected CassandraClusterConnection(boolean dropSchema) { protected CassandraClusterConnection(boolean dropSchema) {
if (clusterName == null || host == null || keyspaceName == null) { 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<Cluster> 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(); clusterName = cluster.getClusterName();
host = cluster.getHost(); host = cluster.getHost();
keyspaceName = cluster.getKeyspaceName(); keyspaceName = cluster.getKeyspaceName();

View File

@ -192,6 +192,14 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
public DBCassandraAstyanaxImpl() { public DBCassandraAstyanaxImpl() {
conn = new CassandraClusterConnection(false); 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 * execute the mutation batch
* @param m * @param m

View File

@ -58,30 +58,31 @@ public class RunningCluster implements Serializable {
* Keyspace Name * Keyspace Name
*/ */
private String keyspaceName; private String keyspaceName;
/** /**
* * @ param infrastructureName could be null
* @return an instance of the RunningCluster * @return an instance of the RunningCluster
*/ */
public static synchronized RunningCluster getInstance() { public static synchronized RunningCluster getInstance(String infrastructureName) {
if (singleton == null) { if (singleton == null) {
singleton = new RunningCluster(); singleton = new RunningCluster(infrastructureName);
} }
return singleton; return singleton;
} }
/** /**
* private constructor * private constructor
*/ */
private RunningCluster() { private RunningCluster(String infrastructureName) {
try { try {
List<ServiceEndpoint> resources = getConfigurationFromIS(); List<ServiceEndpoint> resources = getConfigurationFromIS(infrastructureName);
if (resources.size() > 1) { if (resources.size() > 1) {
_log.error("Too many Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" in this scope "); _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 " 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){ 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); _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 { else {
for (ServiceEndpoint res : resources) { for (ServiceEndpoint res : resources) {
@ -100,9 +101,13 @@ public class RunningCluster implements Serializable {
* @return the * @return the
* @throws Exception * @throws Exception
*/ */
private List<ServiceEndpoint> getConfigurationFromIS() throws Exception { private List<ServiceEndpoint> getConfigurationFromIS(String infrastructureName) throws Exception {
PortalContext context = PortalContext.getConfiguration(); PortalContext context = PortalContext.getConfiguration();
String scope = "/" + context.getInfrastructureName(); String scope = "/";
if(infrastructureName != null && !infrastructureName.isEmpty())
scope += infrastructureName;
else
scope += context.getInfrastructureName();
String currScope = ScopeProvider.instance.get(); String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
SimpleQuery query = queryFor(ServiceEndpoint.class); SimpleQuery query = queryFor(ServiceEndpoint.class);