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) {
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();
host = cluster.getHost();
keyspaceName = cluster.getKeyspaceName();

View File

@ -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

View File

@ -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<ServiceEndpoint> resources = getConfigurationFromIS();
List<ServiceEndpoint> 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<ServiceEndpoint> getConfigurationFromIS() throws Exception {
private List<ServiceEndpoint> getConfigurationFromIS(String infrastructureName) throws Exception {
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();
ScopeProvider.instance.set(scope);
SimpleQuery query = queryFor(ServiceEndpoint.class);