removed dependency for PortalContext when instancing Cassandra cluster

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@148746 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2017-05-16 15:43:12 +00:00
parent 00622a0dc8
commit c9308c45ba
1 changed files with 34 additions and 3 deletions

View File

@ -3,11 +3,14 @@ package org.gcube.portal.databook.server;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.Properties;
import org.gcube.common.portal.GCubePortalConstants;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
@ -102,13 +105,12 @@ public class RunningCluster implements Serializable {
* @throws Exception
*/
private List<ServiceEndpoint> getConfigurationFromIS(String infrastructureName) throws Exception {
PortalContext context = PortalContext.getConfiguration();
_log.debug("getConfigurationFromIS infrastructureName="+infrastructureName );
String scope = "/";
if(infrastructureName != null && !infrastructureName.isEmpty())
scope += infrastructureName;
else {
scope += context.getInfrastructureName();
scope += readInfrastructureName();
_log.debug("infrastrucute name is null, setting root scope=" + scope);
}
String currScope = ScopeProvider.instance.get();
@ -120,7 +122,29 @@ public class RunningCluster implements Serializable {
List<ServiceEndpoint> toReturn = client.submit(query);
ScopeProvider.instance.set(currScope);
return toReturn;
}
}
private String readInfrastructureName() {
Properties props = new Properties();
try {
StringBuilder sb = new StringBuilder(getCatalinaHome());
sb.append(File.separator)
.append(PortalContext.CONFIGURATION_FOLDER)
.append(File.separator)
.append(PortalContext.INFRA_PROPERTY_FILENAME);
String propertyfile = sb.toString();
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
return props.getProperty(GCubePortalConstants.INFRASTRUCTURE_NAME);
}
catch(IOException e) {
_log.error("infrastructure.properties file not found under $CATALINA_HOME/conf/ dir, setting default infrastructure Name " + "gcube");
return "gcube";
}
}
/**
*
*/
@ -166,4 +190,11 @@ public class RunningCluster implements Serializable {
return "RunningCluster [host=" + host + ", clusterName=" + clusterName
+ ", keyspaceName=" + keyspaceName + "]";
}
/**
*
* @return $CATALINA_HOME
*/
private static String getCatalinaHome() {
return (System.getenv("CATALINA_HOME").endsWith("/") ? System.getenv("CATALINA_HOME") : System.getenv("CATALINA_HOME")+"/");
}
}