Repository: atlas Updated Branches: refs/heads/master 340f8637d -> 4152bc6d5
ATLAS-2448: added default values for JanusGraph cache configurations to improve performance Signed-off-by: Madhan Neethiraj <mad...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/4152bc6d Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/4152bc6d Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/4152bc6d Branch: refs/heads/master Commit: 4152bc6d5247e6abf11d9e5d7b34e26f6da3511e Parents: 340f863 Author: Ashutosh Mestry <ames...@hortonworks.com> Authored: Wed Feb 14 13:49:52 2018 -0800 Committer: Madhan Neethiraj <mad...@apache.org> Committed: Wed Feb 14 23:27:09 2018 -0800 ---------------------------------------------------------------------- .../org/apache/atlas/ApplicationProperties.java | 59 +++++++++++++++++++- .../apache/atlas/ApplicationPropertiesTest.java | 21 +++++++ 2 files changed, 77 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/4152bc6d/intg/src/main/java/org/apache/atlas/ApplicationProperties.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/ApplicationProperties.java b/intg/src/main/java/org/apache/atlas/ApplicationProperties.java index a35bdfe..320563e 100644 --- a/intg/src/main/java/org/apache/atlas/ApplicationProperties.java +++ b/intg/src/main/java/org/apache/atlas/ApplicationProperties.java @@ -21,6 +21,7 @@ import org.apache.atlas.security.InMemoryJAASConfiguration; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,6 +30,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.net.URL; +import java.util.AbstractMap.SimpleEntry; import java.util.Iterator; /** @@ -36,10 +38,15 @@ import java.util.Iterator; */ public final class ApplicationProperties extends PropertiesConfiguration { public static final String ATLAS_CONFIGURATION_DIRECTORY_PROPERTY = "atlas.conf"; - private static final Logger LOG = LoggerFactory.getLogger(ApplicationProperties.class); - public static final String APPLICATION_PROPERTIES = "atlas-application.properties"; + public static final String APPLICATION_PROPERTIES = "atlas-application.properties"; + + public static final SimpleEntry<String, String> DB_CACHE_CONF = new SimpleEntry<>("atlas.graph.cache.db-cache", "true"); + public static final SimpleEntry<String, String> DB_CACHE_CLEAN_WAIT_CONF = new SimpleEntry<>("atlas.graph.cache.db-cache-clean-wait", "20"); + public static final SimpleEntry<String, String> DB_CACHE_SIZE_CONF = new SimpleEntry<>("atlas.graph.cache.db-cache-size", "0.5"); + public static final SimpleEntry<String, String> DB_TX_CACHE_SIZE_CONF = new SimpleEntry<>("atlas.graph.cache.tx-cache.size", "15000"); + public static final SimpleEntry<String, String> DB_CACHE_TX_DIRTY_SIZE_CONF = new SimpleEntry<>("atlas.graph.cache.tx-dirty-size", "120"); private static volatile Configuration instance = null; @@ -90,7 +97,12 @@ public final class ApplicationProperties extends PropertiesConfiguration { LOG.info("Loading {} from {}", fileName, url); - Configuration configuration = new ApplicationProperties(url).interpolatedConfiguration(); + ApplicationProperties appProperties = new ApplicationProperties(url); + + appProperties.setDefaults(); + + Configuration configuration = appProperties.interpolatedConfiguration(); + logConfiguration(configuration); return configuration; } catch (Exception e) { @@ -131,6 +143,21 @@ public final class ApplicationProperties extends PropertiesConfiguration { } } + public static Class getClass(String fullyQualifiedClassName, Class assignableClass) throws AtlasException { + try { + Class<?> clazz = Class.forName(fullyQualifiedClassName); + if (assignableClass == null || assignableClass.isAssignableFrom(clazz)) { + return clazz; + } else { + String message = "Class " + clazz.getName() + " is not assignable to class " + assignableClass.getName(); + LOG.error(message); + throw new AtlasException(message); + } + } catch (Exception e) { + throw new AtlasException(e); + } + } + /** * Get the specified property as an {@link InputStream}. * If the property is not set, then the specified default filename @@ -200,4 +227,30 @@ public final class ApplicationProperties extends PropertiesConfiguration { } return inStr; } + + private void setDefaults() { + setDbCacheConfDefaults(); + } + + void setDefault(SimpleEntry<String, String> keyValueDefault, String currentValue) { + if (StringUtils.isNotEmpty(currentValue)) { + return; + } + + clearPropertyDirect(keyValueDefault.getKey()); + addPropertyDirect(keyValueDefault.getKey(), keyValueDefault.getValue()); + LOG.info("Property (set to default) {} = {}", keyValueDefault.getKey(), keyValueDefault.getValue()); + } + + private void setDbCacheConfDefaults() { + SimpleEntry<String, String> keyValues[] = new SimpleEntry[]{ DB_CACHE_CONF, DB_CACHE_CLEAN_WAIT_CONF, + DB_CACHE_SIZE_CONF, DB_TX_CACHE_SIZE_CONF, + DB_CACHE_TX_DIRTY_SIZE_CONF }; + + for(SimpleEntry<String, String> kv : keyValues) { + String currentValue = getString(kv.getKey()); + + setDefault(kv, currentValue); + } + } } http://git-wip-us.apache.org/repos/asf/atlas/blob/4152bc6d/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java ---------------------------------------------------------------------- diff --git a/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java b/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java index 89e5e9b..a002a7a 100644 --- a/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java +++ b/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java @@ -18,8 +18,14 @@ package org.apache.atlas; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.AbstractMap; +import com.sun.jersey.json.impl.provider.entity.JSONArrayProvider; import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; +import org.springframework.cache.interceptor.SimpleKey; import org.testng.annotations.Test; import static org.testng.Assert.*; @@ -126,4 +132,19 @@ public class ApplicationPropertiesTest { } } } + + @Test + public void verifySetDefault() throws AtlasException { + Configuration props = ApplicationProperties.get("test.properties"); + ApplicationProperties aProps = (ApplicationProperties) props; + + String defaultValue = "someValue"; + String someKey = "someKey"; + AbstractMap.SimpleEntry<String, String> defaultKV = new AbstractMap.SimpleEntry<>(someKey, defaultValue); + aProps.setDefault(defaultKV, "newValue"); + + assertNotEquals(props.getString(someKey), defaultValue); + aProps.setDefault(defaultKV, ""); + assertEquals(props.getString(someKey), defaultValue); + } }