From c9308c45ba12ab87f8a38569a8d79fdab144f064 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Tue, 16 May 2017 15:43:12 +0000 Subject: [PATCH] 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 --- .../databook/server/RunningCluster.java | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) 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 c1b843a..d8ae873 100644 --- a/src/main/java/org/gcube/portal/databook/server/RunningCluster.java +++ b/src/main/java/org/gcube/portal/databook/server/RunningCluster.java @@ -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 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 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")+"/"); + } }