diff --git a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/ValidateCommand.java b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/ValidateCommand.java
index 8d9804c..42c0d38 100644
--- a/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/ValidateCommand.java
+++ b/asterix-installer/src/main/java/edu/uci/ics/asterix/installer/command/ValidateCommand.java
@@ -132,18 +132,9 @@
 			}
 		}
 
-		if (valid) {
-			checkJavaVersion(cluster);
-		}
 		return valid;
 	}
 
-	private void checkJavaVersion(Cluster cluster) throws Exception {
-		PatternCreator pc = new PatternCreator();
-		Patterns patterns = pc.getClusterInfoPattern(cluster);
-		InstallerUtil.getEventrixClient(cluster).submit(patterns);
-	}
-
 	private void validateClusterProperties(Cluster cluster) {
 		List<String> tempDirs = new ArrayList<String>();
 		if (cluster.getLogdir() != null
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 46b909c..fc53304 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
@@ -41,401 +41,449 @@
 
 public class PatternCreator {
 
-    private ILookupService lookupService = ServiceProvider.INSTANCE.getLookupService();
+	private ILookupService lookupService = ServiceProvider.INSTANCE
+			.getLookupService();
 
-    private void addInitialDelay(Pattern p, int delay, String unit) {
-        Delay d = new Delay(new Value(null, "" + delay), unit);
-        p.setDelay(d);
-    }
+	private void addInitialDelay(Pattern p, int delay, String unit) {
+		Delay d = new Delay(new Value(null, "" + delay), unit);
+		p.setDelay(d);
+	}
 
-    public Patterns getStartAsterixPattern(String asterixInstanceName, Cluster cluster) throws Exception {
-        String ccLocationId = cluster.getMasterNode().getId();
-        String ccLocationIp = cluster.getMasterNode().getIp();
+	public Patterns getStartAsterixPattern(String asterixInstanceName,
+			Cluster cluster) throws Exception {
+		String ccLocationId = cluster.getMasterNode().getId();
+		String ccLocationIp = cluster.getMasterNode().getIp();
 
-        String destDir = cluster.getWorkingDir().getDir() + File.separator + "asterix";
-        List<Pattern> ps = new ArrayList<Pattern>();
+		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 copyHyracks = createCopyHyracksPattern(asterixInstanceName,
+				cluster, ccLocationIp, destDir);
+		ps.add(copyHyracks);
 
-        Pattern createCC = createCCStartPattern(ccLocationId);
-        addInitialDelay(createCC, 2, "sec");
-        ps.add(createCC);
+		Pattern createCC = createCCStartPattern(ccLocationId);
+		addInitialDelay(createCC, 2, "sec");
+		ps.add(createCC);
 
-        boolean copyHyracksToNC = !cluster.getWorkingDir().isNFS();
-        for (Node node : cluster.getNode()) {
-            if (copyHyracksToNC) {
-                Pattern copyHyracksForNC = createCopyHyracksPattern(asterixInstanceName, cluster, node.getIp(), destDir);
-                ps.add(copyHyracksForNC);
-            }
-            Pattern createNC = createNCStartPattern(cluster.getMasterNode().getIp(), node.getId(), asterixInstanceName
-                    + "_" + node.getId());
-            addInitialDelay(createNC, 4, "sec");
-            ps.add(createNC);
-        }
+		boolean copyHyracksToNC = !cluster.getWorkingDir().isNFS();
+		for (Node node : cluster.getNode()) {
+			if (copyHyracksToNC) {
+				Pattern copyHyracksForNC = createCopyHyracksPattern(
+						asterixInstanceName, cluster, node.getIp(), destDir);
+				ps.add(copyHyracksForNC);
+			}
+			Pattern createNC = createNCStartPattern(cluster.getMasterNode()
+					.getIp(), node.getId(),
+					asterixInstanceName + "_" + node.getId());
+			addInitialDelay(createNC, 4, "sec");
+			ps.add(createNC);
+		}
 
-        Patterns patterns = new Patterns(ps);
-        patterns.getPattern().addAll(createHadoopLibraryTransferPattern(cluster).getPattern());
-        return patterns;
-    }
+		Patterns patterns = new Patterns(ps);
+		patterns.getPattern().addAll(
+				createHadoopLibraryTransferPattern(cluster).getPattern());
+		return patterns;
+	}
 
-    public Patterns getClusterInfoPattern(Cluster cluster) throws Exception {
-        List<Pattern> ps = new ArrayList<Pattern>();
-        String pargs = "";
-        List<Node> nodeList = cluster.getNode();
-        nodeList.add(new Node(cluster.getMasterNode().getId(), cluster.getMasterNode().getIp(), null, null, null, null,
-                null));
-        for (Node node : nodeList) {
-            Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
-            Event event = new Event("node_info", nodeid, pargs);
-            ps.add(new Pattern(null, 1, null, event));
-        }
-        return new Patterns(ps);
-    }
+	public Patterns getStopCommandPattern(StopCommand stopCommand)
+			throws Exception {
+		List<Pattern> ps = new ArrayList<Pattern>();
+		AsterixInstance asterixInstance = lookupService
+				.getAsterixInstance(stopCommand.getAsterixInstanceName());
+		Cluster cluster = asterixInstance.getCluster();
 
-    public Patterns getStopCommandPattern(StopCommand stopCommand) throws Exception {
-        List<Pattern> ps = new ArrayList<Pattern>();
-        AsterixInstance asterixInstance = lookupService.getAsterixInstance(stopCommand.getAsterixInstanceName());
-        Cluster cluster = asterixInstance.getCluster();
+		String ccLocation = cluster.getMasterNode().getId();
+		Pattern createCC = createCCStopPattern(ccLocation);
+		addInitialDelay(createCC, 5, "sec");
+		ps.add(createCC);
 
-        String ccLocation = cluster.getMasterNode().getId();
-        Pattern createCC = createCCStopPattern(ccLocation);
-        addInitialDelay(createCC, 5, "sec");
-        ps.add(createCC);
+		String asterixInstanceName = stopCommand.getAsterixInstanceName();
+		int nodeControllerIndex = 1;
+		for (Node node : cluster.getNode()) {
+			Pattern createNC = createNCStopPattern(node.getId(),
+					asterixInstanceName + "_" + nodeControllerIndex);
+			ps.add(createNC);
+			nodeControllerIndex++;
+		}
 
-        String asterixInstanceName = stopCommand.getAsterixInstanceName();
-        int nodeControllerIndex = 1;
-        for (Node node : cluster.getNode()) {
-            Pattern createNC = createNCStopPattern(node.getId(), asterixInstanceName + "_" + nodeControllerIndex);
-            ps.add(createNC);
-            nodeControllerIndex++;
-        }
+		Patterns patterns = new Patterns(ps);
+		return patterns;
+	}
 
-        Patterns patterns = new Patterns(ps);
-        return patterns;
-    }
+	public Patterns getBackUpAsterixPattern(AsterixInstance instance,
+			Backup backupConf) throws Exception {
+		BackupType backupType = BackupInfo.getBackupType(backupConf);
+		Patterns patterns = null;
+		switch (backupType) {
+		case HDFS:
+			patterns = getHDFSBackUpAsterixPattern(instance, backupConf);
+			break;
+		case LOCAL:
+			patterns = getLocalBackUpAsterixPattern(instance, backupConf);
+			break;
+		}
+		return patterns;
+	}
 
-    public Patterns getBackUpAsterixPattern(AsterixInstance instance, Backup backupConf) throws Exception {
-        BackupType backupType = BackupInfo.getBackupType(backupConf);
-        Patterns patterns = null;
-        switch (backupType) {
-            case HDFS:
-                patterns = getHDFSBackUpAsterixPattern(instance, backupConf);
-                break;
-            case LOCAL:
-                patterns = getLocalBackUpAsterixPattern(instance, backupConf);
-                break;
-        }
-        return patterns;
-    }
+	public Patterns getRestoreAsterixPattern(AsterixInstance instance,
+			BackupInfo backupInfo) throws Exception {
+		BackupType backupType = backupInfo.getBackupType();
+		Patterns patterns = null;
+		switch (backupType) {
+		case HDFS:
+			patterns = getHDFSRestoreAsterixPattern(instance, backupInfo);
+			break;
+		case LOCAL:
+			patterns = getLocalRestoreAsterixPattern(instance, backupInfo);
+			break;
+		}
+		return patterns;
+	}
 
-    public Patterns getRestoreAsterixPattern(AsterixInstance instance, BackupInfo backupInfo) throws Exception {
-        BackupType backupType = backupInfo.getBackupType();
-        Patterns patterns = null;
-        switch (backupType) {
-            case HDFS:
-                patterns = getHDFSRestoreAsterixPattern(instance, backupInfo);
-                break;
-            case LOCAL:
-                patterns = getLocalRestoreAsterixPattern(instance, backupInfo);
-                break;
-        }
-        return patterns;
-    }
+	private Patterns getHDFSBackUpAsterixPattern(AsterixInstance instance,
+			Backup backupConf) throws Exception {
+		Cluster cluster = instance.getCluster();
+		String clusterStore = instance.getCluster().getStore();
+		String hdfsUrl = backupConf.getHdfs().getUrl();
+		String hadoopVersion = backupConf.getHdfs().getVersion();
+		String hdfsBackupDir = backupConf.getBackupDir();
+		VerificationUtil.verifyBackupRestoreConfiguration(hdfsUrl,
+				hadoopVersion, hdfsBackupDir);
+		String workingDir = cluster.getWorkingDir().getDir();
+		String backupId = "" + instance.getBackupInfo().size();
+		String nodeStore;
+		String pargs;
+		List<Pattern> patternList = new ArrayList<Pattern>();
+		for (Node node : cluster.getNode()) {
+			Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
+			nodeStore = node.getStore() == null ? clusterStore : node
+					.getStore();
+			pargs = workingDir + " " + instance.getName() + " " + nodeStore
+					+ " " + backupId + " " + hdfsBackupDir + " " + "hdfs" + " "
+					+ node.getId() + " " + hdfsUrl + " " + hadoopVersion;
+			Event event = new Event("backup", nodeid, pargs);
+			patternList.add(new Pattern(null, 1, null, event));
+		}
+		return new Patterns(patternList);
+	}
 
-    private Patterns getHDFSBackUpAsterixPattern(AsterixInstance instance, Backup backupConf) throws Exception {
-        Cluster cluster = instance.getCluster();
-        String clusterStore = instance.getCluster().getStore();
-        String hdfsUrl = backupConf.getHdfs().getUrl();
-        String hadoopVersion = backupConf.getHdfs().getVersion();
-        String hdfsBackupDir = backupConf.getBackupDir();
-        VerificationUtil.verifyBackupRestoreConfiguration(hdfsUrl, hadoopVersion, hdfsBackupDir);
-        String workingDir = cluster.getWorkingDir().getDir();
-        String backupId = "" + instance.getBackupInfo().size();
-        String nodeStore;
-        String pargs;
-        List<Pattern> patternList = new ArrayList<Pattern>();
-        for (Node node : cluster.getNode()) {
-            Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
-            nodeStore = node.getStore() == null ? clusterStore : node.getStore();
-            pargs = workingDir + " " + instance.getName() + " " + nodeStore + " " + backupId + " " + hdfsBackupDir
-                    + " " + "hdfs" + " " + node.getId() + " " + hdfsUrl + " " + hadoopVersion;
-            Event event = new Event("backup", nodeid, pargs);
-            patternList.add(new Pattern(null, 1, null, event));
-        }
-        return new Patterns(patternList);
-    }
+	private Patterns getLocalBackUpAsterixPattern(AsterixInstance instance,
+			Backup backupConf) throws Exception {
+		Cluster cluster = instance.getCluster();
+		String clusterStore = instance.getCluster().getStore();
+		String backupDir = backupConf.getBackupDir();
+		String workingDir = cluster.getWorkingDir().getDir();
+		String backupId = "" + instance.getBackupInfo().size();
+		String nodeStore;
+		String pargs;
+		List<Pattern> patternList = new ArrayList<Pattern>();
+		for (Node node : cluster.getNode()) {
+			Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
+			nodeStore = node.getStore() == null ? clusterStore : node
+					.getStore();
+			pargs = workingDir + " " + instance.getName() + " " + nodeStore
+					+ " " + backupId + " " + backupDir + " " + "local" + " "
+					+ node.getId();
+			Event event = new Event("backup", nodeid, pargs);
+			patternList.add(new Pattern(null, 1, null, event));
+		}
+		return new Patterns(patternList);
+	}
 
-    private Patterns getLocalBackUpAsterixPattern(AsterixInstance instance, Backup backupConf) throws Exception {
-        Cluster cluster = instance.getCluster();
-        String clusterStore = instance.getCluster().getStore();
-        String backupDir = backupConf.getBackupDir();
-        String workingDir = cluster.getWorkingDir().getDir();
-        String backupId = "" + instance.getBackupInfo().size();
-        String nodeStore;
-        String pargs;
-        List<Pattern> patternList = new ArrayList<Pattern>();
-        for (Node node : cluster.getNode()) {
-            Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
-            nodeStore = node.getStore() == null ? clusterStore : node.getStore();
-            pargs = workingDir + " " + instance.getName() + " " + nodeStore + " " + backupId + " " + backupDir + " "
-                    + "local" + " " + node.getId();
-            Event event = new Event("backup", nodeid, pargs);
-            patternList.add(new Pattern(null, 1, null, event));
-        }
-        return new Patterns(patternList);
-    }
+	public Patterns getHDFSRestoreAsterixPattern(AsterixInstance instance,
+			BackupInfo backupInfo) throws Exception {
+		Cluster cluster = instance.getCluster();
+		String clusterStore = instance.getCluster().getStore();
+		String hdfsUrl = backupInfo.getBackupConf().getHdfs().getUrl();
+		String hadoopVersion = backupInfo.getBackupConf().getHdfs()
+				.getVersion();
+		String hdfsBackupDir = backupInfo.getBackupConf().getBackupDir();
+		VerificationUtil.verifyBackupRestoreConfiguration(hdfsUrl,
+				hadoopVersion, hdfsBackupDir);
+		String workingDir = cluster.getWorkingDir().getDir();
+		int backupId = backupInfo.getId();
+		String nodeStore;
+		String pargs;
+		List<Pattern> patternList = new ArrayList<Pattern>();
+		for (Node node : cluster.getNode()) {
+			Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
+			nodeStore = node.getStore() == null ? clusterStore : node
+					.getStore();
+			pargs = workingDir + " " + instance.getName() + " " + nodeStore
+					+ " " + backupId + " " + hdfsBackupDir + " " + "hdfs" + " "
+					+ node.getId() + " " + hdfsUrl + " " + hadoopVersion;
+			Event event = new Event("restore", nodeid, pargs);
+			patternList.add(new Pattern(null, 1, null, event));
+		}
+		return new Patterns(patternList);
+	}
 
-    public Patterns getHDFSRestoreAsterixPattern(AsterixInstance instance, BackupInfo backupInfo) throws Exception {
-        Cluster cluster = instance.getCluster();
-        String clusterStore = instance.getCluster().getStore();
-        String hdfsUrl = backupInfo.getBackupConf().getHdfs().getUrl();
-        String hadoopVersion = backupInfo.getBackupConf().getHdfs().getVersion();
-        String hdfsBackupDir = backupInfo.getBackupConf().getBackupDir();
-        VerificationUtil.verifyBackupRestoreConfiguration(hdfsUrl, hadoopVersion, hdfsBackupDir);
-        String workingDir = cluster.getWorkingDir().getDir();
-        int backupId = backupInfo.getId();
-        String nodeStore;
-        String pargs;
-        List<Pattern> patternList = new ArrayList<Pattern>();
-        for (Node node : cluster.getNode()) {
-            Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
-            nodeStore = node.getStore() == null ? clusterStore : node.getStore();
-            pargs = workingDir + " " + instance.getName() + " " + nodeStore + " " + backupId + " " + hdfsBackupDir
-                    + " " + "hdfs" + " " + node.getId() + " " + hdfsUrl + " " + hadoopVersion;
-            Event event = new Event("restore", nodeid, pargs);
-            patternList.add(new Pattern(null, 1, null, event));
-        }
-        return new Patterns(patternList);
-    }
+	public Patterns getLocalRestoreAsterixPattern(AsterixInstance instance,
+			BackupInfo backupInfo) throws Exception {
+		Cluster cluster = instance.getCluster();
+		String clusterStore = instance.getCluster().getStore();
+		String backupDir = backupInfo.getBackupConf().getBackupDir();
+		String workingDir = cluster.getWorkingDir().getDir();
+		int backupId = backupInfo.getId();
+		String nodeStore;
+		String pargs;
+		List<Pattern> patternList = new ArrayList<Pattern>();
+		for (Node node : cluster.getNode()) {
+			Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
+			nodeStore = node.getStore() == null ? clusterStore : node
+					.getStore();
+			pargs = workingDir + " " + instance.getName() + " " + nodeStore
+					+ " " + backupId + " " + backupDir + " " + "local" + " "
+					+ node.getId();
+			Event event = new Event("restore", nodeid, pargs);
+			patternList.add(new Pattern(null, 1, null, event));
+		}
+		return new Patterns(patternList);
+	}
 
-    public Patterns getLocalRestoreAsterixPattern(AsterixInstance instance, BackupInfo backupInfo) throws Exception {
-        Cluster cluster = instance.getCluster();
-        String clusterStore = instance.getCluster().getStore();
-        String backupDir = backupInfo.getBackupConf().getBackupDir();
-        String workingDir = cluster.getWorkingDir().getDir();
-        int backupId = backupInfo.getId();
-        String nodeStore;
-        String pargs;
-        List<Pattern> patternList = new ArrayList<Pattern>();
-        for (Node node : cluster.getNode()) {
-            Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
-            nodeStore = node.getStore() == null ? clusterStore : node.getStore();
-            pargs = workingDir + " " + instance.getName() + " " + nodeStore + " " + backupId + " " + backupDir + " "
-                    + "local" + " " + node.getId();
-            Event event = new Event("restore", nodeid, pargs);
-            patternList.add(new Pattern(null, 1, null, event));
-        }
-        return new Patterns(patternList);
-    }
+	public Patterns createHadoopLibraryTransferPattern(Cluster cluster)
+			throws Exception {
+		List<Pattern> patternList = new ArrayList<Pattern>();
+		String workingDir = cluster.getWorkingDir().getDir();
+		String hadoopVersion = InstallerDriver.getConfiguration().getBackup()
+				.getHdfs().getVersion();
+		File hadoopDir = new File(InstallerDriver.getManagixHome()
+				+ File.separator + InstallerDriver.MANAGIX_INTERNAL_DIR
+				+ File.separator + "hadoop-" + hadoopVersion);
+		if (!hadoopDir.exists()) {
+			throw new IllegalStateException("Hadoop version :" + hadoopVersion
+					+ " not supported");
+		}
 
-    public Patterns createHadoopLibraryTransferPattern(Cluster cluster) throws Exception {
-        List<Pattern> patternList = new ArrayList<Pattern>();
-        String workingDir = cluster.getWorkingDir().getDir();
-        String hadoopVersion = InstallerDriver.getConfiguration().getBackup().getHdfs().getVersion();
-        File hadoopDir = new File(InstallerDriver.getManagixHome() + File.separator
-                + InstallerDriver.MANAGIX_INTERNAL_DIR + File.separator + "hadoop-" + hadoopVersion);
-        if (!hadoopDir.exists()) {
-            throw new IllegalStateException("Hadoop version :" + hadoopVersion + " not supported");
-        }
+		Nodeid nodeid = new Nodeid(new Value(null,
+				EventDriver.CLIENT_NODE.getId()));
+		String username = cluster.getUsername() != null ? cluster.getUsername()
+				: System.getProperty("user.name");
+		String pargs = username + " " + hadoopDir.getAbsolutePath() + " "
+				+ cluster.getMasterNode().getIp() + " " + workingDir;
+		Event event = new Event("directory_transfer", nodeid, pargs);
+		Pattern p = new Pattern(null, 1, null, event);
+		addInitialDelay(p, 2, "sec");
+		patternList.add(p);
 
-        Nodeid nodeid = new Nodeid(new Value(null, EventDriver.CLIENT_NODE.getId()));
-        String username = cluster.getUsername() != null ? cluster.getUsername() : System.getProperty("user.name");
-        String pargs = username + " " + hadoopDir.getAbsolutePath() + " " + cluster.getMasterNode().getIp() + " "
-                + workingDir;
-        Event event = new Event("directory_transfer", nodeid, pargs);
-        Pattern p = new Pattern(null, 1, null, event);
-        addInitialDelay(p, 2, "sec");
-        patternList.add(p);
+		boolean copyToNC = !cluster.getWorkingDir().isNFS();
+		if (copyToNC) {
+			for (Node node : cluster.getNode()) {
+				nodeid = new Nodeid(new Value(null, node.getId()));
+				pargs = cluster.getUsername() + " "
+						+ hadoopDir.getAbsolutePath() + " " + node.getIp()
+						+ " " + workingDir;
+				event = new Event("directory_transfer", nodeid, pargs);
+				p = new Pattern(null, 1, null, event);
+				addInitialDelay(p, 2, "sec");
+				patternList.add(p);
+			}
+		}
+		Patterns patterns = new Patterns(patternList);
+		return patterns;
+	}
 
-        boolean copyToNC = !cluster.getWorkingDir().isNFS();
-        if (copyToNC) {
-            for (Node node : cluster.getNode()) {
-                nodeid = new Nodeid(new Value(null, node.getId()));
-                pargs = cluster.getUsername() + " " + hadoopDir.getAbsolutePath() + " " + node.getIp() + " "
-                        + workingDir;
-                event = new Event("directory_transfer", nodeid, pargs);
-                p = new Pattern(null, 1, null, event);
-                addInitialDelay(p, 2, "sec");
-                patternList.add(p);
-            }
-        }
-        Patterns patterns = new Patterns(patternList);
-        return patterns;
-    }
+	public Patterns createDeleteInstancePattern(AsterixInstance instance)
+			throws Exception {
+		List<Pattern> patternList = new ArrayList<Pattern>();
+		patternList.addAll(createRemoveAsterixStoragePattern(instance)
+				.getPattern());
+		if (instance.getBackupInfo() != null
+				&& instance.getBackupInfo().size() > 0) {
+			List<BackupInfo> backups = instance.getBackupInfo();
+			Set<String> removedBackupDirsHDFS = new HashSet<String>();
+			Set<String> removedBackupDirsLocal = new HashSet<String>();
 
-    public Patterns createDeleteInstancePattern(AsterixInstance instance) throws Exception {
-        List<Pattern> patternList = new ArrayList<Pattern>();
-        patternList.addAll(createRemoveAsterixStoragePattern(instance).getPattern());
-        if (instance.getBackupInfo() != null && instance.getBackupInfo().size() > 0) {
-            List<BackupInfo> backups = instance.getBackupInfo();
-            Set<String> removedBackupDirsHDFS = new HashSet<String>();
-            Set<String> removedBackupDirsLocal = new HashSet<String>();
+			String backupDir;
+			for (BackupInfo binfo : backups) {
+				backupDir = binfo.getBackupConf().getBackupDir();
+				switch (binfo.getBackupType()) {
+				case HDFS:
+					if (removedBackupDirsHDFS.contains(backups)) {
+						continue;
+					}
+					patternList.addAll(createRemoveHDFSBackupPattern(instance,
+							backupDir).getPattern());
+					removedBackupDirsHDFS.add(backupDir);
+					break;
 
-            String backupDir;
-            for (BackupInfo binfo : backups) {
-                backupDir = binfo.getBackupConf().getBackupDir();
-                switch (binfo.getBackupType()) {
-                    case HDFS:
-                        if (removedBackupDirsHDFS.contains(backups)) {
-                            continue;
-                        }
-                        patternList.addAll(createRemoveHDFSBackupPattern(instance, backupDir).getPattern());
-                        removedBackupDirsHDFS.add(backupDir);
-                        break;
+				case LOCAL:
+					if (removedBackupDirsLocal.contains(backups)) {
+						continue;
+					}
+					patternList.addAll(createRemoveLocalBackupPattern(instance,
+							backupDir).getPattern());
+					removedBackupDirsLocal.add(backupDir);
+					break;
+				}
 
-                    case LOCAL:
-                        if (removedBackupDirsLocal.contains(backups)) {
-                            continue;
-                        }
-                        patternList.addAll(createRemoveLocalBackupPattern(instance, backupDir).getPattern());
-                        removedBackupDirsLocal.add(backupDir);
-                        break;
-                }
+			}
+		}
+		patternList.addAll(createRemoveAsterixLogDirPattern(instance)
+				.getPattern());
+		Patterns patterns = new Patterns(patternList);
+		return patterns;
+	}
 
-            }
-        }
-        patternList.addAll(createRemoveAsterixLogDirPattern(instance).getPattern());
-        Patterns patterns = new Patterns(patternList);
-        return patterns;
-    }
+	private Patterns createRemoveHDFSBackupPattern(AsterixInstance instance,
+			String hdfsBackupDir) throws Exception {
+		List<Pattern> patternList = new ArrayList<Pattern>();
+		Cluster cluster = instance.getCluster();
+		String hdfsUrl = InstallerDriver.getConfiguration().getBackup()
+				.getHdfs().getUrl();
+		String hadoopVersion = InstallerDriver.getConfiguration().getBackup()
+				.getHdfs().getVersion();
+		String workingDir = cluster.getWorkingDir().getDir();
+		Node launchingNode = cluster.getNode().get(0);
+		Nodeid nodeid = new Nodeid(new Value(null, launchingNode.getId()));
+		String pathToDelete = hdfsBackupDir + File.separator
+				+ instance.getName();
+		String pargs = workingDir + " " + hadoopVersion + " " + hdfsUrl + " "
+				+ pathToDelete;
+		Event event = new Event("hdfs_delete", nodeid, pargs);
+		patternList.add(new Pattern(null, 1, null, event));
+		Patterns patterns = new Patterns(patternList);
+		return patterns;
+	}
 
-    private Patterns createRemoveHDFSBackupPattern(AsterixInstance instance, String hdfsBackupDir) throws Exception {
-        List<Pattern> patternList = new ArrayList<Pattern>();
-        Cluster cluster = instance.getCluster();
-        String hdfsUrl = InstallerDriver.getConfiguration().getBackup().getHdfs().getUrl();
-        String hadoopVersion = InstallerDriver.getConfiguration().getBackup().getHdfs().getVersion();
-        String workingDir = cluster.getWorkingDir().getDir();
-        Node launchingNode = cluster.getNode().get(0);
-        Nodeid nodeid = new Nodeid(new Value(null, launchingNode.getId()));
-        String pathToDelete = hdfsBackupDir + File.separator + instance.getName();
-        String pargs = workingDir + " " + hadoopVersion + " " + hdfsUrl + " " + pathToDelete;
-        Event event = new Event("hdfs_delete", nodeid, pargs);
-        patternList.add(new Pattern(null, 1, null, event));
-        Patterns patterns = new Patterns(patternList);
-        return patterns;
-    }
+	private Patterns createRemoveLocalBackupPattern(AsterixInstance instance,
+			String localBackupDir) throws Exception {
+		List<Pattern> patternList = new ArrayList<Pattern>();
+		Cluster cluster = instance.getCluster();
 
-    private Patterns createRemoveLocalBackupPattern(AsterixInstance instance, String localBackupDir) throws Exception {
-        List<Pattern> patternList = new ArrayList<Pattern>();
-        Cluster cluster = instance.getCluster();
+		String pathToDelete = localBackupDir + File.separator
+				+ instance.getName();
+		String pargs = pathToDelete;
+		List<String> removedBackupDirs = new ArrayList<String>();
+		for (Node node : cluster.getNode()) {
+			if (removedBackupDirs.contains(node.getIp())) {
+				continue;
+			}
+			Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
+			Event event = new Event("file_delete", nodeid, pargs);
+			patternList.add(new Pattern(null, 1, null, event));
+			removedBackupDirs.add(node.getIp());
+		}
 
-        String pathToDelete = localBackupDir + File.separator + instance.getName();
-        String pargs = pathToDelete;
-        List<String> removedBackupDirs = new ArrayList<String>();
-        for (Node node : cluster.getNode()) {
-            if (removedBackupDirs.contains(node.getIp())) {
-                continue;
-            }
-            Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
-            Event event = new Event("file_delete", nodeid, pargs);
-            patternList.add(new Pattern(null, 1, null, event));
-            removedBackupDirs.add(node.getIp());
-        }
+		Patterns patterns = new Patterns(patternList);
+		return patterns;
+	}
 
-        Patterns patterns = new Patterns(patternList);
-        return patterns;
-    }
+	public Patterns createRemoveAsterixWorkingDirPattern(
+			AsterixInstance instance) throws Exception {
+		List<Pattern> patternList = new ArrayList<Pattern>();
+		Cluster cluster = instance.getCluster();
+		String workingDir = cluster.getWorkingDir().getDir();
+		String pargs = workingDir;
+		Nodeid nodeid = new Nodeid(new Value(null, cluster.getMasterNode()
+				.getId()));
+		Event event = new Event("file_delete", nodeid, pargs);
+		patternList.add(new Pattern(null, 1, null, event));
 
-    public Patterns createRemoveAsterixWorkingDirPattern(AsterixInstance instance) throws Exception {
-        List<Pattern> patternList = new ArrayList<Pattern>();
-        Cluster cluster = instance.getCluster();
-        String workingDir = cluster.getWorkingDir().getDir();
-        String pargs = workingDir;
-        Nodeid nodeid = new Nodeid(new Value(null, cluster.getMasterNode().getId()));
-        Event event = new Event("file_delete", nodeid, pargs);
-        patternList.add(new Pattern(null, 1, null, event));
+		if (!cluster.getWorkingDir().isNFS()) {
+			for (Node node : cluster.getNode()) {
+				nodeid = new Nodeid(new Value(null, node.getId()));
+				event = new Event("file_delete", nodeid, pargs);
+				patternList.add(new Pattern(null, 1, null, event));
+			}
+		}
+		Patterns patterns = new Patterns(patternList);
+		return patterns;
+	}
 
-        if (!cluster.getWorkingDir().isNFS()) {
-            for (Node node : cluster.getNode()) {
-                nodeid = new Nodeid(new Value(null, node.getId()));
-                event = new Event("file_delete", nodeid, pargs);
-                patternList.add(new Pattern(null, 1, null, event));
-            }
-        }
-        Patterns patterns = new Patterns(patternList);
-        return patterns;
-    }
+	private Patterns createRemoveAsterixLogDirPattern(AsterixInstance instance)
+			throws Exception {
+		List<Pattern> patternList = new ArrayList<Pattern>();
+		Cluster cluster = instance.getCluster();
+		String pargs = instance.getCluster().getLogdir();
+		Nodeid nodeid = new Nodeid(new Value(null, cluster.getMasterNode()
+				.getId()));
+		Event event = new Event("file_delete", nodeid, pargs);
+		patternList.add(new Pattern(null, 1, null, event));
 
-    private Patterns createRemoveAsterixLogDirPattern(AsterixInstance instance) throws Exception {
-        List<Pattern> patternList = new ArrayList<Pattern>();
-        Cluster cluster = instance.getCluster();
-        String pargs = instance.getCluster().getLogdir();
-        Nodeid nodeid = new Nodeid(new Value(null, cluster.getMasterNode().getId()));
-        Event event = new Event("file_delete", nodeid, pargs);
-        patternList.add(new Pattern(null, 1, null, event));
+		if (!cluster.getWorkingDir().isNFS()) {
+			for (Node node : cluster.getNode()) {
+				nodeid = new Nodeid(new Value(null, node.getId()));
+				event = new Event("file_delete", nodeid, pargs);
+				patternList.add(new Pattern(null, 1, null, event));
+			}
+		}
+		Patterns patterns = new Patterns(patternList);
+		return patterns;
+	}
 
-        if (!cluster.getWorkingDir().isNFS()) {
-            for (Node node : cluster.getNode()) {
-                nodeid = new Nodeid(new Value(null, node.getId()));
-                event = new Event("file_delete", nodeid, pargs);
-                patternList.add(new Pattern(null, 1, null, event));
-            }
-        }
-        Patterns patterns = new Patterns(patternList);
-        return patterns;
-    }
+	private Patterns createRemoveAsterixStoragePattern(AsterixInstance instance)
+			throws Exception {
+		List<Pattern> patternList = new ArrayList<Pattern>();
+		Cluster cluster = instance.getCluster();
+		String pargs = null;
 
-    private Patterns createRemoveAsterixStoragePattern(AsterixInstance instance) throws Exception {
-        List<Pattern> patternList = new ArrayList<Pattern>();
-        Cluster cluster = instance.getCluster();
-        String pargs = null;
+		for (Node node : cluster.getNode()) {
+			Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
+			String[] nodeStores;
+			if (node.getStore() != null) {
+				nodeStores = node.getStore().trim().split(",");
+				for (String ns : nodeStores) {
+					pargs = ns + File.separator + instance.getName();
+				}
+			} else {
+				nodeStores = cluster.getStore().trim().split(",");
+				for (String ns : nodeStores) {
+					pargs = ns + File.separator + node.getId() + File.separator
+							+ instance.getName();
+				}
+			}
+			Event event = new Event("file_delete", nodeid, pargs);
+			patternList.add(new Pattern(null, 1, null, event));
+		}
+		Patterns patterns = new Patterns(patternList);
+		return patterns;
+	}
 
-        for (Node node : cluster.getNode()) {
-            Nodeid nodeid = new Nodeid(new Value(null, node.getId()));
-            String[] nodeStores;
-            if (node.getStore() != null) {
-                nodeStores = node.getStore().trim().split(",");
-                for (String ns : nodeStores) {
-                    pargs = ns + File.separator + instance.getName();
-                }
-            } else {
-                nodeStores = cluster.getStore().trim().split(",");
-                for (String ns : nodeStores) {
-                    pargs = ns + File.separator + node.getId() + File.separator + instance.getName();
-                }
-            }
-            Event event = new Event("file_delete", nodeid, pargs);
-            patternList.add(new Pattern(null, 1, null, event));
-        }
-        Patterns patterns = new Patterns(patternList);
-        return patterns;
-    }
+	private Pattern createCopyHyracksPattern(String instanceName,
+			Cluster cluster, String destinationIp, String destDir) {
+		Nodeid nodeid = new Nodeid(new Value(null,
+				EventDriver.CLIENT_NODE.getId()));
+		String username = cluster.getUsername() != null ? cluster.getUsername()
+				: System.getProperty("user.name");
+		String asterixZipName = InstallerDriver.getAsterixZip()
+				.substring(
+						InstallerDriver.getAsterixZip().lastIndexOf(
+								File.separator) + 1);
+		String fileToTransfer = new File(InstallerDriver.getAsterixDir()
+				+ File.separator + instanceName + File.separator
+				+ asterixZipName).getAbsolutePath();
+		String pargs = username + " " + fileToTransfer + " " + destinationIp
+				+ " " + destDir + " " + "unpack";
+		Event event = new Event("file_transfer", nodeid, pargs);
+		return new Pattern(null, 1, null, event);
+	}
 
-    private Pattern createCopyHyracksPattern(String instanceName, Cluster cluster, String destinationIp, String destDir) {
-        Nodeid nodeid = new Nodeid(new Value(null, EventDriver.CLIENT_NODE.getId()));
-        String username = cluster.getUsername() != null ? cluster.getUsername() : System.getProperty("user.name");
-        String asterixZipName = InstallerDriver.getAsterixZip().substring(
-                InstallerDriver.getAsterixZip().lastIndexOf(File.separator) + 1);
-        String fileToTransfer = new File(InstallerDriver.getAsterixDir() + File.separator + instanceName
-                + File.separator + asterixZipName).getAbsolutePath();
-        String pargs = username + " " + fileToTransfer + " " + destinationIp + " " + destDir + " " + "unpack";
-        Event event = new Event("file_transfer", nodeid, pargs);
-        return new Pattern(null, 1, null, event);
-    }
+	private Pattern createCCStartPattern(String hostId) {
+		Nodeid nodeid = new Nodeid(new Value(null, hostId));
+		Event event = new Event("cc_start", nodeid, "");
+		return new Pattern(null, 1, null, event);
+	}
 
-    private Pattern createCCStartPattern(String hostId) {
-        Nodeid nodeid = new Nodeid(new Value(null, hostId));
-        Event event = new Event("cc_start", nodeid, "");
-        return new Pattern(null, 1, null, event);
-    }
+	public Pattern createCCStopPattern(String hostId) {
+		Nodeid nodeid = new Nodeid(new Value(null, hostId));
+		Event event = new Event("cc_failure", nodeid, null);
+		return new Pattern(null, 1, null, event);
+	}
 
-    public Pattern createCCStopPattern(String hostId) {
-        Nodeid nodeid = new Nodeid(new Value(null, hostId));
-        Event event = new Event("cc_failure", nodeid, null);
-        return new Pattern(null, 1, null, event);
-    }
+	public Pattern createNCStartPattern(String ccHost, String hostId,
+			String nodeControllerId) {
+		Nodeid nodeid = new Nodeid(new Value(null, hostId));
+		Event event = new Event("node_join", nodeid, ccHost + " "
+				+ nodeControllerId);
+		return new Pattern(null, 1, null, event);
+	}
 
-    public Pattern createNCStartPattern(String ccHost, String hostId, String nodeControllerId) {
-        Nodeid nodeid = new Nodeid(new Value(null, hostId));
-        Event event = new Event("node_join", nodeid, ccHost + " " + nodeControllerId);
-        return new Pattern(null, 1, null, event);
-    }
-
-    public Pattern createNCStopPattern(String hostId, String nodeControllerId) {
-        Nodeid nodeid = new Nodeid(new Value(null, hostId));
-        Event event = new Event("node_failure", nodeid, nodeControllerId);
-        return new Pattern(null, 1, null, event);
-    }
+	public Pattern createNCStopPattern(String hostId, String nodeControllerId) {
+		Nodeid nodeid = new Nodeid(new Value(null, hostId));
+		Event event = new Event("node_failure", nodeid, nodeControllerId);
+		return new Pattern(null, 1, null, event);
+	}
 
 }
