Skip to content

Commit

Permalink
[ALLUXIO-1949] Change PropertyKey from class to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
apc999 committed Jul 22, 2016
1 parent 8fe82c7 commit aa2104c
Show file tree
Hide file tree
Showing 4 changed files with 392 additions and 348 deletions.
103 changes: 49 additions & 54 deletions core/common/src/main/java/alluxio/Configuration.java
Expand Up @@ -75,13 +75,6 @@ public final class Configuration {
defaultInit(); defaultInit();
} }


/**
* The minimal configuration without loading any site or system properties.
*/
public static void emptyInit() {
init(null, false);
}

/** /**
* The default configuration. * The default configuration.
*/ */
Expand All @@ -104,19 +97,19 @@ private static void init(String sitePropertiesFile, boolean includeSystemPropert
ExceptionMessage.DEFAULT_PROPERTIES_FILE_DOES_NOT_EXIST.getMessage()); ExceptionMessage.DEFAULT_PROPERTIES_FILE_DOES_NOT_EXIST.getMessage());
} }
// Override runtime default // Override runtime default
defaultProps.setProperty(PropertyKey.MASTER_HOSTNAME, defaultProps.setProperty(PropertyKey.MASTER_HOSTNAME.toString(),
NetworkAddressUtils.getLocalHostName(250)); NetworkAddressUtils.getLocalHostName(250));
defaultProps.setProperty(PropertyKey.WORKER_NETWORK_NETTY_CHANNEL, defaultProps.setProperty(PropertyKey.WORKER_NETWORK_NETTY_CHANNEL.toString(),
String.valueOf(ChannelType.defaultType())); String.valueOf(ChannelType.defaultType()));
defaultProps.setProperty(PropertyKey.USER_NETWORK_NETTY_CHANNEL, defaultProps.setProperty(PropertyKey.USER_NETWORK_NETTY_CHANNEL.toString(),
String.valueOf(ChannelType.defaultType())); String.valueOf(ChannelType.defaultType()));


String confPaths; String confPaths;
// If site conf is overwritten in system properties, overwrite the default setting // If site conf is overwritten in system properties, overwrite the default setting
if (System.getProperty(PropertyKey.SITE_CONF_DIR) != null) { if (System.getProperty(PropertyKey.SITE_CONF_DIR.toString()) != null) {
confPaths = System.getProperty(PropertyKey.SITE_CONF_DIR); confPaths = System.getProperty(PropertyKey.SITE_CONF_DIR.toString());
} else { } else {
confPaths = defaultProps.getProperty(PropertyKey.SITE_CONF_DIR); confPaths = defaultProps.getProperty(PropertyKey.SITE_CONF_DIR.toString());
} }
String[] confPathList = confPaths.split(","); String[] confPathList = confPaths.split(",");


Expand All @@ -131,34 +124,36 @@ private static void init(String sitePropertiesFile, boolean includeSystemPropert
} }


// Now lets combine, order matters here // Now lets combine, order matters here
PROPERTIES.clear();
PROPERTIES.putAll(defaultProps); PROPERTIES.putAll(defaultProps);
if (siteProps != null) { if (siteProps != null) {
PROPERTIES.putAll(siteProps); PROPERTIES.putAll(siteProps);
} }
PROPERTIES.putAll(systemProps); PROPERTIES.putAll(systemProps);


String masterHostname = PROPERTIES.getProperty(PropertyKey.MASTER_HOSTNAME); String masterHostname = PROPERTIES.getProperty(PropertyKey.MASTER_HOSTNAME.toString());
String masterPort = PROPERTIES.getProperty(PropertyKey.MASTER_RPC_PORT); String masterPort = PROPERTIES.getProperty(PropertyKey.MASTER_RPC_PORT.toString());
boolean useZk = Boolean.parseBoolean(PROPERTIES.getProperty(PropertyKey.ZOOKEEPER_ENABLED)); boolean useZk = Boolean.parseBoolean(
PROPERTIES.getProperty(PropertyKey.ZOOKEEPER_ENABLED.toString()));
String masterAddress = String masterAddress =
(useZk ? Constants.HEADER_FT : Constants.HEADER) + masterHostname + ":" + masterPort; (useZk ? Constants.HEADER_FT : Constants.HEADER) + masterHostname + ":" + masterPort;
PROPERTIES.setProperty(PropertyKey.MASTER_ADDRESS, masterAddress); PROPERTIES.setProperty(PropertyKey.MASTER_ADDRESS.toString(), masterAddress);
checkUserFileBufferBytes(); checkUserFileBufferBytes();


// Make sure the user hasn't set worker ports when there may be multiple workers per host // Make sure the user hasn't set worker ports when there may be multiple workers per host
int maxWorkersPerHost = getInt(PropertyKey.INTEGRATION_YARN_WORKERS_PER_HOST_MAX); int maxWorkersPerHost = getInt(PropertyKey.INTEGRATION_YARN_WORKERS_PER_HOST_MAX);
if (maxWorkersPerHost > 1) { if (maxWorkersPerHost > 1) {
String message = "%s cannot be specified when allowing multiple workers per host with " String message = "%s cannot be specified when allowing multiple workers per host with "
+ PropertyKey.INTEGRATION_YARN_WORKERS_PER_HOST_MAX + "=" + maxWorkersPerHost; + PropertyKey.INTEGRATION_YARN_WORKERS_PER_HOST_MAX + "=" + maxWorkersPerHost;
Preconditions.checkState(System.getProperty(PropertyKey.WORKER_DATA_PORT) == null, Preconditions.checkState(System.getProperty(PropertyKey.WORKER_DATA_PORT.toString()) == null,
String.format(message, PropertyKey.WORKER_DATA_PORT)); String.format(message, PropertyKey.WORKER_DATA_PORT));
Preconditions.checkState(System.getProperty(PropertyKey.WORKER_RPC_PORT) == null, Preconditions.checkState(System.getProperty(PropertyKey.WORKER_RPC_PORT.toString()) == null,
String.format(message, PropertyKey.WORKER_RPC_PORT)); String.format(message, PropertyKey.WORKER_RPC_PORT));
Preconditions.checkState(System.getProperty(PropertyKey.WORKER_WEB_PORT) == null, Preconditions.checkState(System.getProperty(PropertyKey.WORKER_WEB_PORT.toString()) == null,
String.format(message, PropertyKey.WORKER_WEB_PORT)); String.format(message, PropertyKey.WORKER_WEB_PORT));
PROPERTIES.setProperty(PropertyKey.WORKER_DATA_PORT, "0"); PROPERTIES.setProperty(PropertyKey.WORKER_DATA_PORT.toString(), "0");
PROPERTIES.setProperty(PropertyKey.WORKER_RPC_PORT, "0"); PROPERTIES.setProperty(PropertyKey.WORKER_RPC_PORT.toString(), "0");
PROPERTIES.setProperty(PropertyKey.WORKER_WEB_PORT, "0"); PROPERTIES.setProperty(PropertyKey.WORKER_WEB_PORT.toString(), "0");
} }
} }


Expand Down Expand Up @@ -186,10 +181,10 @@ public static void merge(Map<?, ?> properties) {
* @param key the key to set * @param key the key to set
* @param value the value for the key * @param value the value for the key
*/ */
public static void set(String key, String value) { public static void set(PropertyKey key, String value) {
Preconditions.checkArgument(key != null && value != null, Preconditions.checkArgument(key != null && value != null,
String.format("the key value pair (%s, %s) cannot have null", key, value)); String.format("the key value pair (%s, %s) cannot have null", key, value));
PROPERTIES.put(key, value); PROPERTIES.put(key.toString(), value);
checkUserFileBufferBytes(); checkUserFileBufferBytes();
} }


Expand All @@ -199,12 +194,12 @@ public static void set(String key, String value) {
* @param key the key to get the value for * @param key the key to get the value for
* @return the value for the given key * @return the value for the given key
*/ */
public static String get(String key) { public static String get(PropertyKey key) {
if (!PROPERTIES.containsKey(key)) { if (!PROPERTIES.containsKey(key.toString())) {
// if key is not found among the default properties // if key is not found among the default properties
throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(key)); throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(key));
} }
String raw = PROPERTIES.getProperty(key); String raw = PROPERTIES.getProperty(key.toString());
return lookup(raw); return lookup(raw);
} }


Expand All @@ -214,7 +209,7 @@ public static String get(String key) {
* @param key the key to check * @param key the key to check
* @return true if the key is in the {@link Properties}, false otherwise * @return true if the key is in the {@link Properties}, false otherwise
*/ */
public static boolean containsKey(String key) { public static boolean containsKey(PropertyKey key) {
return PROPERTIES.containsKey(key); return PROPERTIES.containsKey(key);
} }


Expand All @@ -224,9 +219,9 @@ public static boolean containsKey(String key) {
* @param key the key to get the value for * @param key the key to get the value for
* @return the value for the given key as an {@code int} * @return the value for the given key as an {@code int}
*/ */
public static int getInt(String key) { public static int getInt(PropertyKey key) {
if (PROPERTIES.containsKey(key)) { if (PROPERTIES.containsKey(key.toString())) {
String rawValue = PROPERTIES.getProperty(key); String rawValue = PROPERTIES.getProperty(key.toString());
try { try {
return Integer.parseInt(lookup(rawValue)); return Integer.parseInt(lookup(rawValue));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Expand All @@ -243,9 +238,9 @@ public static int getInt(String key) {
* @param key the key to get the value for * @param key the key to get the value for
* @return the value for the given key as a {@code long} * @return the value for the given key as a {@code long}
*/ */
public static long getLong(String key) { public static long getLong(PropertyKey key) {
if (PROPERTIES.containsKey(key)) { if (PROPERTIES.containsKey(key.toString())) {
String rawValue = PROPERTIES.getProperty(key); String rawValue = PROPERTIES.getProperty(key.toString());
try { try {
return Long.parseLong(lookup(rawValue)); return Long.parseLong(lookup(rawValue));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Expand All @@ -262,9 +257,9 @@ public static long getLong(String key) {
* @param key the key to get the value for * @param key the key to get the value for
* @return the value for the given key as a {@code double} * @return the value for the given key as a {@code double}
*/ */
public static double getDouble(String key) { public static double getDouble(PropertyKey key) {
if (PROPERTIES.containsKey(key)) { if (PROPERTIES.containsKey(key.toString())) {
String rawValue = PROPERTIES.getProperty(key); String rawValue = PROPERTIES.getProperty(key.toString());
try { try {
return Double.parseDouble(lookup(rawValue)); return Double.parseDouble(lookup(rawValue));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Expand All @@ -281,9 +276,9 @@ public static double getDouble(String key) {
* @param key the key to get the value for * @param key the key to get the value for
* @return the value for the given key as a {@code float} * @return the value for the given key as a {@code float}
*/ */
public static float getFloat(String key) { public static float PropertyKey(PropertyKey key) {
if (PROPERTIES.containsKey(key)) { if (PROPERTIES.containsKey(key.toString())) {
String rawValue = PROPERTIES.getProperty(key); String rawValue = PROPERTIES.getProperty(key.toString());
try { try {
return Float.parseFloat(lookup(rawValue)); return Float.parseFloat(lookup(rawValue));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Expand All @@ -300,9 +295,9 @@ public static float getFloat(String key) {
* @param key the key to get the value for * @param key the key to get the value for
* @return the value for the given key as a {@code boolean} * @return the value for the given key as a {@code boolean}
*/ */
public static boolean getBoolean(String key) { public static boolean getBoolean(PropertyKey key) {
if (PROPERTIES.containsKey(key)) { if (PROPERTIES.containsKey(key.toString())) {
String rawValue = PROPERTIES.getProperty(key); String rawValue = PROPERTIES.getProperty(key.toString());
return Boolean.parseBoolean(lookup(rawValue)); return Boolean.parseBoolean(lookup(rawValue));
} }
// if key is not found among the default properties // if key is not found among the default properties
Expand All @@ -316,11 +311,11 @@ public static boolean getBoolean(String key) {
* @param delimiter the delimiter to split the values * @param delimiter the delimiter to split the values
* @return the list of values for the given key * @return the list of values for the given key
*/ */
public static List<String> getList(String key, String delimiter) { public static List<String> getList(PropertyKey key, String delimiter) {
Preconditions.checkArgument(delimiter != null, "Illegal separator for Alluxio properties as " Preconditions.checkArgument(delimiter != null, "Illegal separator for Alluxio properties as "
+ "list"); + "list");
if (PROPERTIES.containsKey(key)) { if (PROPERTIES.containsKey(key.toString())) {
String rawValue = PROPERTIES.getProperty(key); String rawValue = PROPERTIES.getProperty(key.toString());
return Lists.newLinkedList(Splitter.on(delimiter).trimResults().omitEmptyStrings() return Lists.newLinkedList(Splitter.on(delimiter).trimResults().omitEmptyStrings()
.split(rawValue)); .split(rawValue));
} }
Expand All @@ -336,8 +331,8 @@ public static List<String> getList(String key, String delimiter) {
* @param <T> the type of the enum * @param <T> the type of the enum
* @return the value for the given key as an enum value * @return the value for the given key as an enum value
*/ */
public static <T extends Enum<T>> T getEnum(String key, Class<T> enumType) { public static <T extends Enum<T>> T getEnum(PropertyKey key, Class<T> enumType) {
if (!PROPERTIES.containsKey(key)) { if (!PROPERTIES.containsKey(key.toString())) {
throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(key)); throw new RuntimeException(ExceptionMessage.INVALID_CONFIGURATION_KEY.getMessage(key));
} }
final String val = get(key); final String val = get(key);
Expand All @@ -350,8 +345,8 @@ public static <T extends Enum<T>> T getEnum(String key, Class<T> enumType) {
* @param key the key to get the value for * @param key the key to get the value for
* @return the bytes of the value for the given key * @return the bytes of the value for the given key
*/ */
public static long getBytes(String key) { public static long getBytes(PropertyKey key) {
if (PROPERTIES.containsKey(key)) { if (PROPERTIES.containsKey(key.toString())) {
String rawValue = get(key); String rawValue = get(key);
try { try {
return FormatUtils.parseSpaceSize(rawValue); return FormatUtils.parseSpaceSize(rawValue);
Expand All @@ -370,9 +365,9 @@ public static long getBytes(String key) {
* @return the value for the given key as a class * @return the value for the given key as a class
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> Class<T> getClass(String key) { public static <T> Class<T> getClass(PropertyKey key) {
if (PROPERTIES.containsKey(key)) { if (PROPERTIES.containsKey(key.toString())) {
String rawValue = PROPERTIES.getProperty(key); String rawValue = PROPERTIES.getProperty(key.toString());
try { try {
return (Class<T>) Class.forName(rawValue); return (Class<T>) Class.forName(rawValue);
} catch (Exception e) { } catch (Exception e) {
Expand Down
4 changes: 3 additions & 1 deletion core/common/src/main/java/alluxio/Constants.java
Expand Up @@ -118,7 +118,9 @@ public final class Constants {
public static final String KEY_VALUE_WORKER_CLIENT_SERVICE_NAME = "KeyValueWorkerClient"; public static final String KEY_VALUE_WORKER_CLIENT_SERVICE_NAME = "KeyValueWorkerClient";


public static final String REST_API_PREFIX = "v1/api"; public static final String REST_API_PREFIX = "v1/api";
public static final String LOGGER_TYPE = PropertyKey.LOGGER_TYPE; public static final String LOGGER_TYPE = PropertyKey.LOGGER_TYPE.toString();
public static final String FORMAT_FILE_PREFIX = "_format_";



public static final String MASTER_COLUMN_FILE_PREFIX = "COL_"; public static final String MASTER_COLUMN_FILE_PREFIX = "COL_";


Expand Down

0 comments on commit aa2104c

Please sign in to comment.