private void createActivity(JobMetaData meta, Allocation alloc, int lastvmId) {

		HashMap<Integer, HashMap<Integer, String>> allocs = alloc
				.getAllocations();

		// First get the VM that will combine the mid results
		System.out.println("DEBUG: Last VM still is " + lastvmId);
		allocs.remove(lastvmId);
		SlaveVM lastvm = this.pool.getVMById(lastvmId);
		WaitForResultsJob wait = new WaitForResultsJob(allocs.keySet().size());
		ArrayList<Integer> midresults = new ArrayList<Integer>();
		
		System.out.println("DEBUG: Allocation minus lastVM: " + allocs);


		// Now create the activities for all other VMs, they should forward to
		// the final VM
		for (Integer vmId : allocs.keySet()) {
				ArrayList<IJob> list = new ArrayList<IJob>();

				SlaveVM vm = this.pool.getVMById(vmId);
				// These files will be passed to the CombineJob of the final VM
				midresults.add(Integer.valueOf(vm.getIp().getHostAddress()
						.replaceAll("[.:]", "")));

				SocketSender sender = new SocketSender(true, vm.getIp());

				ArrayList<Integer> filelist = new ArrayList<Integer>();
				HashMap<Integer, String> files = allocs.get(vm.getId());
				System.out.println("Files for VM " + vm.getId() + ": " + files);
				filelist.addAll(files.keySet());
				DownloadJob d = new DownloadJob(filelist, meta.getSender());
				CombineJob c = new CombineJob(filelist);
				ForwardJob f = new ForwardJob(false); // don't send tar
				c.setIP(meta.getSender());
				f.setIP(lastvm.getIp());
				f.setRemoteFileName((vm.getIp().getHostAddress()
						.replaceAll("[.:]", "")));
				list.add(d);
				list.add(c);
				list.add(f);

				Activity activity = new Activity(list);
				activity.setClient(meta.getSender());
				activity.setVM(vm);

				try {
					System.out.println("Sending Activity to " + vm.getId()
							+ "@" + vm.getIp().getHostAddress());
					sender.send(activity, true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			
		}

		wait.setIP(meta.getSender());
		CombineJob combine = new CombineJob(midresults);
		combine.setIP(meta.getSender());
		CompressJob comp = new CompressJob();
		ForwardJob f = new ForwardJob(true);
		comp.setIP(meta.getSender());
		f.setIP(meta.getSender());
		f.setRemoteFileName(meta.getSender().getHostName());
		ArrayList<IJob> finallist = new ArrayList<IJob>();
		finallist.add(wait);
		finallist.add(combine);
		finallist.add(comp);
		finallist.add(f);

		Activity activity = new Activity(finallist);
		activity.setClient(meta.getSender());
		activity.setVM(lastvm);

		SocketSender sender = new SocketSender(true, lastvm.getIp());

		try {
			System.out.println("Sending Activity to " + lastvm.getId() + "@"
					+ lastvm.getIp().getHostAddress());
			sender.send(activity, true);
		} catch (Exception e) {
			e.printStackTrace();
		}

		monitor.moveJobToRunning(meta.getId());
	}