Skip to content

Commit

Permalink
Merge pull request #59 from akkumar/master
Browse files Browse the repository at this point in the history
VOLDEMORT_CONFIG_DIR environment variable introduced
  • Loading branch information
afeinberg committed Dec 30, 2011
2 parents deeff41 + fe10ef0 commit a01e4de
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,6 +6,7 @@ dist
*.iws *.iws
*# *#
.#* .#*
test-output
node.id node.id
rebalancing.slave.list rebalancing.slave.list
server.state server.state
Expand Down
4 changes: 2 additions & 2 deletions bin/voldemort-server.sh
Expand Up @@ -16,9 +16,9 @@
# limitations under the License. # limitations under the License.
# #


if [ $# -gt 1 ]; if [ $# -gt 2 ];
then then
echo 'USAGE: bin/voldemort-server.sh [voldemort_home]' echo 'USAGE: bin/voldemort-server.sh [voldemort_home] [voldemort_config_dir]'
exit 1 exit 1
fi fi


Expand Down
24 changes: 21 additions & 3 deletions src/java/voldemort/server/VoldemortConfig.java
Expand Up @@ -48,6 +48,7 @@ public class VoldemortConfig implements Serializable {


private static final long serialVersionUID = 1; private static final long serialVersionUID = 1;
public static final String VOLDEMORT_HOME_VAR_NAME = "VOLDEMORT_HOME"; public static final String VOLDEMORT_HOME_VAR_NAME = "VOLDEMORT_HOME";
public static final String VOLDEMORT_CONFIG_DIR = "VOLDEMORT_CONFIG_DIR";
private static final String VOLDEMORT_NODE_ID_VAR_NAME = "VOLDEMORT_NODE_ID"; private static final String VOLDEMORT_NODE_ID_VAR_NAME = "VOLDEMORT_NODE_ID";
public static int VOLDEMORT_DEFAULT_ADMIN_PORT = 6660; public static int VOLDEMORT_DEFAULT_ADMIN_PORT = 6660;


Expand Down Expand Up @@ -398,17 +399,33 @@ public static VoldemortConfig loadFromEnvironmentVariable() {
+ VoldemortConfig.VOLDEMORT_HOME_VAR_NAME + VoldemortConfig.VOLDEMORT_HOME_VAR_NAME
+ " has been defined, set it!"); + " has been defined, set it!");


return loadFromVoldemortHome(voldemortHome); String voldemortConfigDir = System.getenv(VoldemortConfig.VOLDEMORT_CONFIG_DIR);
if(voldemortConfigDir != null) {
if(!Utils.isReadableDir(voldemortConfigDir))
throw new ConfigurationException("Attempt to load configuration from VOLDEMORT_CONFIG_DIR, "
+ voldemortConfigDir
+ " failed. That is not a readable directory.");
}
return loadFromVoldemortHome(voldemortHome, voldemortConfigDir);
} }


public static VoldemortConfig loadFromVoldemortHome(String voldemortHome) { public static VoldemortConfig loadFromVoldemortHome(String voldemortHome) {
String voldemortConfigDir = voldemortHome + File.separator + "config";
return loadFromVoldemortHome(voldemortHome, voldemortConfigDir);

}

public static VoldemortConfig loadFromVoldemortHome(String voldemortHome,
String voldemortConfigDir) {
if(!Utils.isReadableDir(voldemortHome)) if(!Utils.isReadableDir(voldemortHome))
throw new ConfigurationException("Attempt to load configuration from VOLDEMORT_HOME, " throw new ConfigurationException("Attempt to load configuration from VOLDEMORT_HOME, "
+ voldemortHome + voldemortHome
+ " failed. That is not a readable directory."); + " failed. That is not a readable directory.");


String propertiesFile = voldemortHome + File.separator + "config" + File.separator if(voldemortConfigDir == null) {
+ "server.properties"; voldemortConfigDir = voldemortHome + File.separator + "config";
}
String propertiesFile = voldemortConfigDir + File.separator + "server.properties";
if(!Utils.isReadableFile(propertiesFile)) if(!Utils.isReadableFile(propertiesFile))
throw new ConfigurationException(propertiesFile throw new ConfigurationException(propertiesFile
+ " is not a readable configuration file."); + " is not a readable configuration file.");
Expand All @@ -417,6 +434,7 @@ public static VoldemortConfig loadFromVoldemortHome(String voldemortHome) {
try { try {
properties = new Props(new File(propertiesFile)); properties = new Props(new File(propertiesFile));
properties.put("voldemort.home", voldemortHome); properties.put("voldemort.home", voldemortHome);
properties.put("metadata.directory", voldemortConfigDir);
} catch(IOException e) { } catch(IOException e) {
throw new ConfigurationException(e); throw new ConfigurationException(e);
} }
Expand Down
4 changes: 3 additions & 1 deletion src/java/voldemort/server/VoldemortJsvcDaemon.java
Expand Up @@ -48,9 +48,11 @@ public void init(String[] args) throws Exception {
config = VoldemortConfig.loadFromEnvironmentVariable(); config = VoldemortConfig.loadFromEnvironmentVariable();
else if(args.length == 1) else if(args.length == 1)
config = VoldemortConfig.loadFromVoldemortHome(args[0]); config = VoldemortConfig.loadFromVoldemortHome(args[0]);
else if(args.length == 2)
config = VoldemortConfig.loadFromVoldemortHome(args[0], args[1]);
else else
croak("USAGE: java " + VoldemortJsvcDaemon.class.getName() croak("USAGE: java " + VoldemortJsvcDaemon.class.getName()
+ " [voldemort_home_dir]"); + " [voldemort_home_dir] [voldemort_config_dir]");
} catch(Exception e) { } catch(Exception e) {
logger.error(e); logger.error(e);
croak("Error while loading configuration: " + e.getMessage()); croak("Error while loading configuration: " + e.getMessage());
Expand Down
5 changes: 4 additions & 1 deletion src/java/voldemort/server/VoldemortServer.java
Expand Up @@ -286,8 +286,11 @@ public static void main(String[] args) throws Exception {
config = VoldemortConfig.loadFromEnvironmentVariable(); config = VoldemortConfig.loadFromEnvironmentVariable();
else if(args.length == 1) else if(args.length == 1)
config = VoldemortConfig.loadFromVoldemortHome(args[0]); config = VoldemortConfig.loadFromVoldemortHome(args[0]);
else if(args.length == 2)
config = VoldemortConfig.loadFromVoldemortHome(args[0], args[1]);
else else
croak("USAGE: java " + VoldemortServer.class.getName() + " [voldemort_home_dir]"); croak("USAGE: java " + VoldemortServer.class.getName()
+ " [voldemort_home_dir] [voldemort_config_dir]");
} catch(Exception e) { } catch(Exception e) {
logger.error(e); logger.error(e);
Utils.croak("Error while loading configuration: " + e.getMessage()); Utils.croak("Error while loading configuration: " + e.getMessage());
Expand Down
Expand Up @@ -16,9 +16,9 @@
# limitations under the License. # limitations under the License.
# #


if [ $# -gt 1 ]; if [ $# -gt 2 ];
then then
echo 'USAGE: bin/voldemort-server.sh [voldemort_home]' echo 'USAGE: bin/voldemort-server.sh [voldemort_home] [voldemort_config_dir]'
exit 1 exit 1
fi fi


Expand Down

0 comments on commit a01e4de

Please sign in to comment.