Permalink
Browse files

Remove hard-coded paths from C and Java code

Dozens of hard-coded paths to binaries and helper scripts have been
converted to macros, and macros have been centralized in eucalyptus.h.

Fixes EUCA-3331

Conflicts:
	cluster/handlers.c
	cluster/handlers.h
	net/vnetwork.c
	node/handlers.c
  • Loading branch information...
1 parent c6d207b commit 59bc3e02377a53362ca63edcc347e1cde6b91f79 @a13m a13m committed Sep 12, 2012
Showing with 320 additions and 289 deletions.
  1. +6 −6 clc/modules/bootstrap/src/main/native/eucalyptus-bootstrap.c
  2. +13 −12 clc/modules/bootstrap/src/main/native/eucalyptus-bootstrap.h
  3. +1 −2 clc/modules/core/src/main/java/com/eucalyptus/util/StorageProperties.java
  4. +2 −3 clc/modules/core/src/main/java/com/eucalyptus/util/WalrusProperties.java
  5. +2 −1 clc/modules/msgs/src/main/java/com/eucalyptus/system/BaseDirectory.java
  6. +7 −7 clc/modules/msgs/src/main/java/com/eucalyptus/system/SubDirectory.java
  7. +14 −19 ...modules/storage-common/src/main/java/edu/ucsb/eucalyptus/storage/fs/FileSystemStorageManager.java
  8. +3 −3 clc/modules/storage-controller/src/main/java/com/eucalyptus/storage/AOEManager.java
  9. +1 −1 clc/modules/storage-controller/src/main/java/com/eucalyptus/storage/ISCSIManager.java
  10. +34 −45 clc/modules/storage-controller/src/main/java/com/eucalyptus/storage/OverlayManager.java
  11. +1 −1 clc/modules/walrus/src/main/java/edu/ucsb/eucalyptus/cloud/ws/WalrusControl.java
  12. +11 −11 clc/modules/walrus/src/main/java/edu/ucsb/eucalyptus/storage/fs/DRBDStorageManager.java
  13. +5 −5 cluster/CCclient.c
  14. +2 −2 cluster/handlers-state.c
  15. +21 −21 cluster/handlers.c
  16. +1 −1 cluster/handlers.h
  17. +4 −7 cluster/shutdownCC.c
  18. +8 −8 gatherlog/handlers.c
  19. +77 −76 net/vnetwork.c
  20. +3 −5 node/NCclient.c
  21. +2 −2 node/client-marshal-fake.c
  22. +5 −5 node/handlers.c
  23. +12 −12 node/handlers_default.c
  24. +3 −3 node/test_nc.c
  25. +1 −1 storage/blobstore.c
  26. +3 −1 storage/storage-windows.c
  27. +4 −2 util/euca_auth.c
  28. +64 −19 util/eucalyptus.h
  29. +10 −8 util/misc.c
@@ -685,12 +685,12 @@ char* java_library_path(euca_opts *args) {
#define JAVA_PATH_LEN 65536
char lib_dir[256], etc_dir[256], script_dir[256], class_cache_dir[256], *jar_list =
(char*) malloc(JAVA_PATH_LEN * sizeof(char));
- __die((strlen(GETARG(args, home)) + strlen(EUCA_LIB_DIR) >= 254),
- "Directory path too long: %s/%s", GETARG(args, home), EUCA_LIB_DIR);
- snprintf(lib_dir, 255, "%s%s", GETARG(args, home), EUCA_LIB_DIR);
- snprintf(etc_dir, 255, "%s%s", GETARG(args, home), EUCA_ETC_DIR);
- snprintf(class_cache_dir, 255, "%s%s", GETARG(args, home), EUCA_CLASSCACHE_DIR);
- snprintf(script_dir, 255, "%s%s", GETARG(args, home), EUCA_SCRIPT_DIR);
+ __die((strlen(GETARG(args, home)) + strlen(EUCALYPTUS_JAVA_LIB_DIR) >= 256),
+ "Directory path too long: " EUCALYPTUS_JAVA_LIB_DIR, GETARG(args, home));
+ snprintf(lib_dir, 255, EUCALYPTUS_JAVA_LIB_DIR, GETARG(args, home));
+ snprintf(etc_dir, 255, EUCA_ETC_DIR, GETARG(args, home));
+ snprintf(class_cache_dir, 255, EUCA_CLASSCACHE_DIR, GETARG(args, home));
+ snprintf(script_dir, 255, EUCA_SCRIPT_DIR, GETARG(args, home));
if (!CHECK_ISDIR(lib_dir))
__die(1, "Can't find library directory %s", lib_dir);
int wb = 0;
@@ -73,6 +73,8 @@
#include <sys/stat.h>
#include <linux/capability.h>
#include "eucalyptus-opts.h"
+#include <eucalyptus.h>
+
#define PRINT_NULL(x) ((x) == NULL ? "null" : (x))
#define LIMIT_FILENO 65535
#define LIMIT_NPROC RLIM_INFINITY
@@ -119,10 +121,6 @@ static int debug = 0;
#define __abort(r,condition,format,...) do { if(condition) {fprintf(stderr,"[error:%04d] ", __LINE__);fprintf(stderr, format "\n", ##__VA_ARGS__ ); fflush(stderr); return r;} } while(0)
#define __debug(format,...) do { if(debug){fprintf(stdout,"[debug:%04d] ", __LINE__);fprintf(stdout, format "\n", ##__VA_ARGS__ );fflush(stdout); } } while(0)
#define __error(format,...) do { fprintf(stderr,"[error:%04d] ", __LINE__);fprintf(stderr, format "\n", ##__VA_ARGS__ );fflush(stderr); } while(0)
-#define EUCA_LIB_DIR "/usr/share/eucalyptus"
-#define EUCA_ETC_DIR "/etc/eucalyptus/cloud.d"
-#define EUCA_CLASSCACHE_DIR "/var/run/eucalyptus/classcache"
-#define EUCA_SCRIPT_DIR "/etc/eucalyptus/cloud.d/scripts"
#define EUCA_MAIN "com/eucalyptus/bootstrap/SystemBootstrapper"
#define EUCA_RET_RELOAD 123
#define java_load_bootstrapper euca_load_bootstrapper
@@ -163,23 +161,26 @@ typedef struct {
jvm_opt.optionString=strdup(temp); \
} while(0)
static char *jvm_default_opts[] = {
- "-Xbootclasspath/p:%1$s/usr/share/eucalyptus/openjdk-crypto.jar",
+ "-Xbootclasspath/p:%1$s" EUCALYPTUS_DATA_DIR "/openjdk-crypto.jar",
"-Xmx1024m",
"-XX:MaxPermSize=256m",
"-XX:+UseConcMarkSweepGC",
"-Djava.net.preferIPv4Stack=true",
- "-Djava.security.policy=%1$s/etc/eucalyptus/cloud.d/security.policy",
- "-Djava.library.path=%1$s/usr/lib/eucalyptus",
+ "-Djava.security.policy=" EUCA_ETC_DIR "/security.policy",
+ "-Djava.library.path=" EUCALYPTUS_LIB_DIR,
"-Djava.awt.headless=true",
"-Dsun.java.command=Eucalyptus",
"-Deuca.home=%1$s",
"-Deuca.db.home=",
"-Deuca.extra_version=",
- "-Deuca.var.dir=%1$s/var/lib/eucalyptus",
- "-Deuca.run.dir=%1$s/var/run/eucalyptus",
- "-Deuca.lib.dir=%1$s/usr/share/eucalyptus",
- "-Deuca.conf.dir=%1$s/etc/eucalyptus/cloud.d",
- "-Deuca.log.dir=%1$s/var/log/eucalyptus",
+ "-Deuca.var.dir=" EUCALYPTUS_STATE_DIR,
+ "-Deuca.state.dir=" EUCALYPTUS_STATE_DIR,
+ "-Deuca.run.dir=" EUCALYPTUS_RUN_DIR,
+ "-Deuca.lib.dir=" EUCALYPTUS_JAVA_LIB_DIR,
+ "-Deuca.libexec.dir=" EUCALYPTUS_LIBEXEC_DIR,
+ "-Deuca.conf.dir=" EUCALYPTUS_CONF_DIR "/cloud.d",
+ "-Deuca.log.dir=" EUCALYPTUS_LOG_DIR,
+ "-Deuca.jni.dir=" EUCALYPTUS_LIB_DIR,
"-Djava.util.prefs.PreferencesFactory=com.eucalyptus.util.NoopPreferencesFactory",
NULL,
};
@@ -107,8 +107,7 @@
public static boolean trackUsageStatistics = true;
public static String STORAGE_HOST = "127.0.0.1";
- public static String eucaHome = BaseDirectory.HOME.toString( );
- public static final String EUCA_ROOT_WRAPPER = "/usr/lib/eucalyptus/euca_rootwrap";
+ public static final String EUCA_ROOT_WRAPPER = BaseDirectory.LIBEXEC.toString() + "/euca_rootwrap";
public static final String blockSize = "1M";
static { Groovyness.loadConfig("storageprops.groovy"); }
@@ -141,9 +141,8 @@
public static String TRACKER_DIR = BaseDirectory.VAR.toString() + "/bt";
public static String TRACKER_URL = "http://localhost:6969/announce";
public static String TRACKER_PORT = "6969";
- public static final String eucaHome = System.getProperty("euca.home");
- public static final String EUCA_ROOT_WRAPPER = "/usr/lib/eucalyptus/euca_rootwrap";
- public static final String EUCA_MOUNT_WRAPPER = "/usr/lib/eucalyptus/euca_mountwrap";
+ public static final String EUCA_ROOT_WRAPPER = BaseDirectory.LIBEXEC.toString() + "/euca_rootwrap";
+ public static final String EUCA_MOUNT_WRAPPER = BaseDirectory.LIBEXEC.toString() + "/euca_mountwrap";
public static final String EUCA_USER = System.getProperty("euca.user");
//15 minutes
@@ -70,7 +70,8 @@
import com.eucalyptus.scripting.ScriptExecutionFailedException;
public enum BaseDirectory {
- HOME( "euca.home" ), VAR( "euca.var.dir" ), CONF( "euca.conf.dir" ), LIB( "euca.lib.dir" ), LOG( "euca.log.dir" );
+ HOME( "euca.home" ), VAR( "euca.var.dir" ), CONF( "euca.conf.dir" ), LIB( "euca.lib.dir" ), LOG( "euca.log.dir" ),
+ RUN( "euca.run.dir" ), LIBEXEC( "euca.libexec.dir" ), STATE( "euca.state.dir" ), JNI( "euca.jni.dir" );
private static Logger LOGG = Logger.getLogger( BaseDirectory.class );
private String key;
@@ -71,7 +71,7 @@
public enum SubDirectory {
- DB( BaseDirectory.VAR, "db" ){
+ DB( BaseDirectory.STATE, "db" ){
@Override
protected void assertPermissions() {
@@ -83,7 +83,7 @@ protected void assertPermissions() {
}
}
},
- TX( BaseDirectory.HOME, "/var/run/eucalyptus/tx" ) {
+ TX( BaseDirectory.RUN, "/tx" ) {
@Override
protected void assertPermissions() {
@@ -95,10 +95,10 @@ protected void assertPermissions() {
}
}
},
- CLASSCACHE( BaseDirectory.HOME, "/var/run/eucalyptus/classcache" ),
+ CLASSCACHE( BaseDirectory.RUN, "/classcache" ),
WWW( BaseDirectory.CONF, "www" ),
- WEBAPPS( BaseDirectory.VAR, "webapps" ),
- KEYS( BaseDirectory.VAR, "keys" ){
+ WEBAPPS( BaseDirectory.STATE, "webapps" ),
+ KEYS( BaseDirectory.STATE, "keys" ){
@Override
protected void assertPermissions() {
@@ -118,8 +118,8 @@ protected void assertPermissions() {
REPORTS( BaseDirectory.CONF, "reports" ),
CONF( BaseDirectory.CONF, "conf" ),
QUEUE( BaseDirectory.VAR, "queue" ),
- LIB( BaseDirectory.HOME, "/usr/share/eucalyptus" ),
- RUNDB( BaseDirectory.HOME, "/var/run/eucalyptus/db") {
+ LIB( BaseDirectory.LIB, "" ),
+ RUNDB( BaseDirectory.RUN, "/db") {
@Override
protected void assertPermissions() {
@@ -94,14 +94,14 @@
import edu.ucsb.eucalyptus.storage.StorageManager;
import edu.ucsb.eucalyptus.util.StreamConsumer;
import edu.ucsb.eucalyptus.util.SystemUtil;
+import com.eucalyptus.system.BaseDirectory;
public class FileSystemStorageManager implements StorageManager {
public static final String FILE_SEPARATOR = "/";
public static final String lvmRootDirectory = "/dev";
private static boolean initialized = false;
- private static String eucaHome = "/opt/eucalyptus";
- public static final String EUCA_ROOT_WRAPPER = "/usr/lib/eucalyptus/euca_rootwrap";
+ public static final String EUCA_ROOT_WRAPPER = BaseDirectory.LIBEXEC.toString() + "/euca_rootwrap";
public static final int MAX_LOOP_DEVICES = 256;
private static Logger LOG = Logger.getLogger(FileSystemStorageManager.class);
@@ -110,12 +110,7 @@ public FileSystemStorageManager() {
public void checkPreconditions() throws EucalyptusCloudException {
try {
- String eucaHomeDir = System.getProperty("euca.home");
- if(eucaHomeDir == null) {
- throw new EucalyptusCloudException("euca.home not set");
- }
- eucaHome = eucaHomeDir;
- if(!new File(eucaHome + EUCA_ROOT_WRAPPER).exists()) {
+ if(!new File(EUCA_ROOT_WRAPPER).exists()) {
throw new EucalyptusCloudException("root wrapper (euca_rootwrap) does not exist");
}
String returnValue = getLvmVersion();
@@ -429,14 +424,14 @@ public void sendHeaders(final WalrusDataGetRequestType request, DefaultHttpRespo
}
private String removeLoopback(String loDevName) throws EucalyptusCloudException {
- return SystemUtil.run(new String[]{eucaHome + EUCA_ROOT_WRAPPER, "losetup", "-d", loDevName});
+ return SystemUtil.run(new String[]{EUCA_ROOT_WRAPPER, "losetup", "-d", loDevName});
}
private int losetup(String absoluteFileName, String loDevName) {
try
{
Runtime rt = Runtime.getRuntime();
- Process proc = rt.exec(new String[]{eucaHome + EUCA_ROOT_WRAPPER, "losetup", loDevName, absoluteFileName});
+ Process proc = rt.exec(new String[]{EUCA_ROOT_WRAPPER, "losetup", loDevName, absoluteFileName});
StreamConsumer error = new StreamConsumer(proc.getErrorStream());
StreamConsumer output = new StreamConsumer(proc.getInputStream());
error.start();
@@ -454,39 +449,39 @@ private int losetup(String absoluteFileName, String loDevName) {
}
private String findFreeLoopback() throws EucalyptusCloudException {
- return SystemUtil.run(new String[]{eucaHome + EUCA_ROOT_WRAPPER, "losetup", "-f"}).replaceAll("\n", "");
+ return SystemUtil.run(new String[]{EUCA_ROOT_WRAPPER, "losetup", "-f"}).replaceAll("\n", "");
}
private String removeLogicalVolume(String lvName) throws EucalyptusCloudException {
- return SystemUtil.run(new String[]{eucaHome + EUCA_ROOT_WRAPPER, "lvremove", "-f", lvName});
+ return SystemUtil.run(new String[]{EUCA_ROOT_WRAPPER, "lvremove", "-f", lvName});
}
private String reduceVolumeGroup(String vgName, String pvName) throws EucalyptusCloudException {
- return SystemUtil.run(new String[]{eucaHome + EUCA_ROOT_WRAPPER, "vgreduce", vgName, pvName});
+ return SystemUtil.run(new String[]{EUCA_ROOT_WRAPPER, "vgreduce", vgName, pvName});
}
private String removePhysicalVolume(String loDevName) throws EucalyptusCloudException {
- return SystemUtil.run(new String[]{eucaHome + EUCA_ROOT_WRAPPER, "pvremove", loDevName});
+ return SystemUtil.run(new String[]{EUCA_ROOT_WRAPPER, "pvremove", loDevName});
}
private String createVolumeFromLv(String lvName, String volumeKey) throws EucalyptusCloudException {
- return SystemUtil.run(new String[]{eucaHome + EUCA_ROOT_WRAPPER, "dd", "if=" + lvName, "of=" + volumeKey, "bs=1M"});
+ return SystemUtil.run(new String[]{EUCA_ROOT_WRAPPER, "dd", "if=" + lvName, "of=" + volumeKey, "bs=1M"});
}
private String enableLogicalVolume(String lvName) throws EucalyptusCloudException {
- return SystemUtil.run(new String[]{eucaHome + EUCA_ROOT_WRAPPER, "lvchange", "-ay", lvName});
+ return SystemUtil.run(new String[]{EUCA_ROOT_WRAPPER, "lvchange", "-ay", lvName});
}
private String disableLogicalVolume(String lvName) throws EucalyptusCloudException {
- return SystemUtil.run(new String[]{eucaHome + EUCA_ROOT_WRAPPER, "lvchange", "-an", lvName});
+ return SystemUtil.run(new String[]{EUCA_ROOT_WRAPPER, "lvchange", "-an", lvName});
}
private String removeVolumeGroup(String vgName) throws EucalyptusCloudException {
- return SystemUtil.run(new String[]{eucaHome + EUCA_ROOT_WRAPPER, "vgremove", vgName});
+ return SystemUtil.run(new String[]{EUCA_ROOT_WRAPPER, "vgremove", vgName});
}
private String getLvmVersion() throws EucalyptusCloudException {
- return SystemUtil.run(new String[]{eucaHome + EUCA_ROOT_WRAPPER, "lvm", "version"});
+ return SystemUtil.run(new String[]{EUCA_ROOT_WRAPPER, "lvm", "version"});
}
@@ -86,7 +86,7 @@
@Override
public void checkPreconditions() throws EucalyptusCloudException {
String returnValue;
- returnValue = SystemUtil.run(new String[]{OverlayManager.eucaHome + StorageProperties.EUCA_ROOT_WRAPPER, "which", "vblade"});
+ returnValue = SystemUtil.run(new String[]{StorageProperties.EUCA_ROOT_WRAPPER, "which", "vblade"});
if(returnValue.length() == 0) {
throw new EucalyptusCloudException("vblade not found: Is it installed?");
} else {
@@ -98,7 +98,7 @@ public void unexportVolume(int vbladePid) {
try
{
Runtime rt = Runtime.getRuntime();
- Process proc = rt.exec(new String[]{OverlayManager.eucaHome + StorageProperties.EUCA_ROOT_WRAPPER, "kill", String.valueOf(vbladePid)});
+ Process proc = rt.exec(new String[]{StorageProperties.EUCA_ROOT_WRAPPER, "kill", String.valueOf(vbladePid)});
StreamConsumer error = new StreamConsumer(proc.getErrorStream());
StreamConsumer output = new StreamConsumer(proc.getInputStream());
error.start();
@@ -114,7 +114,7 @@ public void loadModule() {
try
{
Runtime rt = Runtime.getRuntime();
- Process proc = rt.exec(new String[]{OverlayManager.eucaHome + StorageProperties.EUCA_ROOT_WRAPPER, "modprobe", "aoe"});
+ Process proc = rt.exec(new String[]{StorageProperties.EUCA_ROOT_WRAPPER, "modprobe", "aoe"});
StreamConsumer error = new StreamConsumer(proc.getErrorStream());
StreamConsumer output = new StreamConsumer(proc.getInputStream());
error.start();
@@ -92,7 +92,7 @@
public class ISCSIManager implements StorageExportManager {
private static Logger LOG = Logger.getLogger(ISCSIManager.class);
- private static String ROOT_WRAP = BaseDirectory.HOME.toString() + StorageProperties.EUCA_ROOT_WRAPPER;
+ private static String ROOT_WRAP = StorageProperties.EUCA_ROOT_WRAPPER;
@Override
public void checkPreconditions() throws EucalyptusCloudException {
String returnValue;
Oops, something went wrong. Retry.

0 comments on commit 59bc3e0

Please sign in to comment.