1) Fix for issue 324: Managix creates the ClusterControllerService folder in the home directory
2) Made transfer of binaries and subsequent use (to start asterix) as separate jobs with latter dependent on successful completion of the former. 


git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_lsm_stabilization_324@1680 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-events/src/main/resources/events/cc_start/cc_start.sh b/asterix-events/src/main/resources/events/cc_start/cc_start.sh
index 37645bc..003d9cf 100755
--- a/asterix-events/src/main/resources/events/cc_start/cc_start.sh
+++ b/asterix-events/src/main/resources/events/cc_start/cc_start.sh
@@ -2,4 +2,5 @@
 then 
   mkdir -p $LOG_DIR
 fi
+cd $WORKING_DIR
 $ASTERIX_HOME/bin/asterixcc -client-net-ip-address $CLIENT_NET_IP -client-net-port 1098 -cluster-net-ip-address $CLUSTER_NET_IP -cluster-net-port 1099 -http-port 8888  &> $LOG_DIR/cc.log
diff --git a/asterix-events/src/main/resources/events/node_join/nc_join.sh b/asterix-events/src/main/resources/events/node_join/nc_join.sh
index 6b5280b..d8bbbd2 100755
--- a/asterix-events/src/main/resources/events/node_join/nc_join.sh
+++ b/asterix-events/src/main/resources/events/node_join/nc_join.sh
@@ -5,4 +5,5 @@
 then 
   mkdir -p $LOG_DIR
 fi
+cd $WORKING_DIR
 $ASTERIX_HOME/bin/asterixnc -node-id $NC_ID -cc-host $CC_HOST -cc-port 1099 -cluster-net-ip-address $IP_LOCATION  -data-ip-address $IP_LOCATION -iodevices $IO_DEVICES -result-ip-address $IP_LOCATION &> $LOG_DIR/${NC_ID}.log
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CreateCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CreateCommand.java
index fd0af04..567f4d9 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CreateCommand.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/CreateCommand.java
@@ -23,10 +23,10 @@
 
 import org.kohsuke.args4j.Option;
 
+import edu.uci.ics.asterix.event.management.EventrixClient;
 import edu.uci.ics.asterix.event.schema.cluster.Cluster;
 import edu.uci.ics.asterix.event.schema.cluster.Env;
 import edu.uci.ics.asterix.event.schema.cluster.Property;
-import edu.uci.ics.asterix.event.schema.cluster.WorkingDir;
 import edu.uci.ics.asterix.event.schema.pattern.Patterns;
 import edu.uci.ics.asterix.installer.driver.InstallerDriver;
 import edu.uci.ics.asterix.installer.driver.InstallerUtil;
@@ -38,95 +38,87 @@
 
 public class CreateCommand extends AbstractCommand {
 
-	private String asterixInstanceName;
-	private Cluster cluster;
+    private String asterixInstanceName;
+    private Cluster cluster;
 
-	@Override
-	protected void execCommand() throws Exception {
-		InstallerDriver.initConfig();
-		ValidateCommand validateCommand = new ValidateCommand();
-		boolean valid = validateCommand
-				.validateCluster(((CreateConfig) config).clusterPath);
-		if (!valid) {
-			throw new Exception("Cannot create an Asterix instance.");
-		}
-		asterixInstanceName = ((CreateConfig) config).name;
-		InstallerUtil.validateAsterixInstanceNotExists(asterixInstanceName);
-		CreateConfig createConfig = (CreateConfig) config;
-		JAXBContext ctx = JAXBContext.newInstance(Cluster.class);
-		Unmarshaller unmarshaller = ctx.createUnmarshaller();
-		cluster = (Cluster) unmarshaller.unmarshal(new File(
-				createConfig.clusterPath));
-		AsterixInstance asterixInstance = InstallerUtil.createAsterixInstance(
-				asterixInstanceName, cluster);
-		InstallerUtil.evaluateConflictWithOtherInstances(asterixInstance);
-		InstallerUtil.createAsterixZip(asterixInstance, true);
-		List<Property> clusterProperties = new ArrayList<Property>();
-		clusterProperties.add(new Property("ASTERIX_HOME", cluster
-				.getWorkingDir().getDir() + File.separator + "asterix"));
-		StringBuilder javaOpts = new StringBuilder();
-		if (cluster.getJavaOpts() != null) {
-			javaOpts.append(cluster.getJavaOpts());
-		}
-		clusterProperties.add(new Property("JAVA_OPTS", javaOpts.toString()));
-		clusterProperties.add(new Property("CLUSTER_NET_IP", cluster
-				.getMasterNode().getClusterIp()));
-		clusterProperties.add(new Property("CLIENT_NET_IP", cluster
-				.getMasterNode().getClientIp()));
-		clusterProperties.add(new Property("LOG_DIR", cluster.getLogdir()));
-		clusterProperties.add(new Property("JAVA_HOME", cluster.getJavaHome()));
-		clusterProperties.add(new Property("WORKING_DIR", cluster
-				.getWorkingDir().getDir()));
-		cluster.setEnv(new Env(clusterProperties));
+    @Override
+    protected void execCommand() throws Exception {
+        InstallerDriver.initConfig();
+        ValidateCommand validateCommand = new ValidateCommand();
+        boolean valid = validateCommand.validateCluster(((CreateConfig) config).clusterPath);
+        if (!valid) {
+            throw new Exception("Cannot create an Asterix instance.");
+        }
+        asterixInstanceName = ((CreateConfig) config).name;
+        InstallerUtil.validateAsterixInstanceNotExists(asterixInstanceName);
+        CreateConfig createConfig = (CreateConfig) config;
+        JAXBContext ctx = JAXBContext.newInstance(Cluster.class);
+        Unmarshaller unmarshaller = ctx.createUnmarshaller();
+        cluster = (Cluster) unmarshaller.unmarshal(new File(createConfig.clusterPath));
+        AsterixInstance asterixInstance = InstallerUtil.createAsterixInstance(asterixInstanceName, cluster);
+        InstallerUtil.evaluateConflictWithOtherInstances(asterixInstance);
+        InstallerUtil.createAsterixZip(asterixInstance, true);
+        List<Property> clusterProperties = new ArrayList<Property>();
+        clusterProperties.add(new Property("ASTERIX_HOME", cluster.getWorkingDir().getDir() + File.separator
+                + "asterix"));
+        StringBuilder javaOpts = new StringBuilder();
+        if (cluster.getJavaOpts() != null) {
+            javaOpts.append(cluster.getJavaOpts());
+        }
+        clusterProperties.add(new Property("JAVA_OPTS", javaOpts.toString()));
+        clusterProperties.add(new Property("CLUSTER_NET_IP", cluster.getMasterNode().getClusterIp()));
+        clusterProperties.add(new Property("CLIENT_NET_IP", cluster.getMasterNode().getClientIp()));
+        clusterProperties.add(new Property("LOG_DIR", cluster.getLogdir()));
+        clusterProperties.add(new Property("JAVA_HOME", cluster.getJavaHome()));
+        clusterProperties.add(new Property("WORKING_DIR", cluster.getWorkingDir().getDir()));
+        cluster.setEnv(new Env(clusterProperties));
 
-		PatternCreator pc = new PatternCreator();
-		Patterns patterns = pc.getStartAsterixPattern(asterixInstanceName,
-				cluster);
-		InstallerUtil.getEventrixClient(cluster).submit(patterns);
+        EventrixClient eventrixClient = InstallerUtil.getEventrixClient(cluster);
+        PatternCreator pc = new PatternCreator();
 
-		AsterixRuntimeState runtimeState = VerificationUtil
-				.getAsterixRuntimeState(asterixInstance);
-		VerificationUtil.updateInstanceWithRuntimeDescription(asterixInstance,
-				runtimeState, true);
-		ServiceProvider.INSTANCE.getLookupService().writeAsterixInstance(
-				asterixInstance);
-		InstallerUtil.deleteDirectory(InstallerDriver.getManagixHome()
-				+ File.separator + InstallerDriver.ASTERIX_DIR + File.separator
-				+ asterixInstanceName);
-		LOGGER.info(asterixInstance.getDescription(false));
-	}
+        Patterns asterixBinarytrasnferPattern = pc.getAsterixBinaryTransferPattern(asterixInstanceName, cluster);
+        eventrixClient.submit(asterixBinarytrasnferPattern);
 
-	@Override
-	protected CommandConfig getCommandConfig() {
-		return new CreateConfig();
-	}
+        Patterns patterns = pc.getStartAsterixPattern(asterixInstanceName, cluster);
+        eventrixClient.submit(patterns);
 
-	public Cluster getCluster() {
-		return cluster;
-	}
+        AsterixRuntimeState runtimeState = VerificationUtil.getAsterixRuntimeState(asterixInstance);
+        VerificationUtil.updateInstanceWithRuntimeDescription(asterixInstance, runtimeState, true);
+        ServiceProvider.INSTANCE.getLookupService().writeAsterixInstance(asterixInstance);
+        InstallerUtil.deleteDirectory(InstallerDriver.getManagixHome() + File.separator + InstallerDriver.ASTERIX_DIR
+                + File.separator + asterixInstanceName);
+        LOGGER.info(asterixInstance.getDescription(false));
+    }
 
-	public String getAsterixInstanceName() {
-		return asterixInstanceName;
-	}
+    @Override
+    protected CommandConfig getCommandConfig() {
+        return new CreateConfig();
+    }
 
-	@Override
-	protected String getUsageDescription() {
-		return "\nCreates an ASTERIX instance with a specified name."
-				+ "\n\nPost creation, the instance is in ACTIVE state, indicating its "
-				+ "\navailability for executing statements/queries."
-				+ "\n\nUsage arguments/options:"
-				+ "\n-n Name of the ASTERIX instance."
-				+ "\n-c Path to the cluster configuration file";
-	}
+    public Cluster getCluster() {
+        return cluster;
+    }
+
+    public String getAsterixInstanceName() {
+        return asterixInstanceName;
+    }
+
+    @Override
+    protected String getUsageDescription() {
+        return "\nCreates an ASTERIX instance with a specified name."
+                + "\n\nPost creation, the instance is in ACTIVE state, indicating its "
+                + "\navailability for executing statements/queries." + "\n\nUsage arguments/options:"
+                + "\n-n Name of the ASTERIX instance." + "\n-c Path to the cluster configuration file";
+    }
 
 }
 
 class CreateConfig extends CommandConfig {
 
-	@Option(name = "-n", required = true, usage = "Name of Asterix Instance")
-	public String name;
+    @Option(name = "-n", required = true, usage = "Name of Asterix Instance")
+    public String name;
 
-	@Option(name = "-c", required = true, usage = "Path to cluster configuration")
-	public String clusterPath;
+    @Option(name = "-c", required = true, usage = "Path to cluster configuration")
+    public String clusterPath;
 
 }
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StartCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StartCommand.java
index 38bcf33..01fdda4 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StartCommand.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/StartCommand.java
@@ -18,6 +18,7 @@
 
 import org.kohsuke.args4j.Option;
 
+import edu.uci.ics.asterix.event.management.EventrixClient;
 import edu.uci.ics.asterix.event.schema.pattern.Patterns;
 import edu.uci.ics.asterix.installer.driver.InstallerDriver;
 import edu.uci.ics.asterix.installer.driver.InstallerUtil;
@@ -37,8 +38,13 @@
         AsterixInstance instance = InstallerUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE);
         InstallerUtil.createAsterixZip(instance, false);
         PatternCreator pc = new PatternCreator();
+        EventrixClient client = InstallerUtil.getEventrixClient(instance.getCluster());
+        Patterns asterixBinaryTransferPattern = pc.getAsterixBinaryTransferPattern(asterixInstanceName,
+                instance.getCluster());
+        client.submit(asterixBinaryTransferPattern);
+
         Patterns patterns = pc.getStartAsterixPattern(asterixInstanceName, instance.getCluster());
-        InstallerUtil.getEventrixClient(instance.getCluster()).submit(patterns);
+        client.submit(patterns);
         InstallerUtil.deleteDirectory(InstallerDriver.getManagixHome() + File.separator + InstallerDriver.ASTERIX_DIR
                 + File.separator + asterixInstanceName);
         AsterixRuntimeState runtimeState = VerificationUtil.getAsterixRuntimeState(instance);
diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/events/PatternCreator.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/events/PatternCreator.java
index f6aeafe..7612ca2 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/events/PatternCreator.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/events/PatternCreator.java
@@ -50,27 +50,37 @@
         p.setDelay(d);
     }
 
-    public Patterns getStartAsterixPattern(String asterixInstanceName, Cluster cluster) throws Exception {
-        String ccLocationId = cluster.getMasterNode().getId();
+    public Patterns getAsterixBinaryTransferPattern(String asterixInstanceName, Cluster cluster) throws Exception {
         String ccLocationIp = cluster.getMasterNode().getClusterIp();
-
         String destDir = cluster.getWorkingDir().getDir() + File.separator + "asterix";
         List<Pattern> ps = new ArrayList<Pattern>();
 
         Pattern copyHyracks = createCopyHyracksPattern(asterixInstanceName, cluster, ccLocationIp, destDir);
         ps.add(copyHyracks);
 
-        Pattern createCC = createCCStartPattern(ccLocationId);
-        addInitialDelay(createCC, 3, "sec");
-        ps.add(createCC);
-
         boolean copyHyracksToNC = !cluster.getWorkingDir().isNFS();
+
         for (Node node : cluster.getNode()) {
             if (copyHyracksToNC) {
                 Pattern copyHyracksForNC = createCopyHyracksPattern(asterixInstanceName, cluster, node.getClusterIp(),
                         destDir);
                 ps.add(copyHyracksForNC);
             }
+        }
+        ps.addAll(createHadoopLibraryTransferPattern(cluster).getPattern());
+        Patterns patterns = new Patterns(ps);
+        return patterns;
+    }
+
+    public Patterns getStartAsterixPattern(String asterixInstanceName, Cluster cluster) throws Exception {
+        String ccLocationId = cluster.getMasterNode().getId();
+        List<Pattern> ps = new ArrayList<Pattern>();
+
+        Pattern createCC = createCCStartPattern(ccLocationId);
+        addInitialDelay(createCC, 3, "sec");
+        ps.add(createCC);
+
+        for (Node node : cluster.getNode()) {
             String iodevices = node.getIodevices() == null ? cluster.getIodevices() : node.getIodevices();
             Pattern createNC = createNCStartPattern(cluster.getMasterNode().getClusterIp(), node.getId(),
                     asterixInstanceName + "_" + node.getId(), iodevices);
@@ -79,7 +89,6 @@
         }
 
         Patterns patterns = new Patterns(ps);
-        patterns.getPattern().addAll(createHadoopLibraryTransferPattern(cluster).getPattern());
         return patterns;
     }