Commit c6037594 authored by mohammad.salama's avatar mohammad.salama

AutoHealer with Worker Ready

parent 0dd9439b
......@@ -3,27 +3,24 @@
<component name="ArtifactsWorkspaceSettings">
<artifacts-to-build>
<artifact name="AutoHealer:jar" />
<artifact name="Worker:jar" />
</artifacts-to-build>
</component>
<component name="ChangeListManager">
<list default="true" id="d4a0b476-92e2-4923-ba69-0da7a4ae9e1f" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/artifacts/AutoHealer_jar.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/artifacts/Worker_jar.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Jars/AutoHealer.jar" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Jars/Worker.jar" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Jars/zcommand.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/ZooKeeper-AutoHealer.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/AutoHealer.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/AutoHealerApplication.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/META-INF/MANIFEST.MF" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/Worker.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/WorkerApplication.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/AutoHealer.jar" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Jars/AutoHealer-Thread.jar" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Worker.jar" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Jars/AutoHealer.jar" beforeDir="false" afterPath="$PROJECT_DIR$/Jars/AutoHealer.jar" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Jars/zcommand.txt" beforeDir="false" afterPath="$PROJECT_DIR$/Jars/zcommand.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Read Me.txt" beforeDir="false" afterPath="$PROJECT_DIR$/Read Me.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/artifacts/AutoHealer_jar/ZooKeeper-AutoHealer.jar" beforeDir="false" afterPath="$PROJECT_DIR$/out/artifacts/AutoHealer_jar/ZooKeeper-AutoHealer.jar" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ZooKeeper-AutoHealer/AutoHealer.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ZooKeeper-AutoHealer/AutoHealer.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ZooKeeper-AutoHealer/AutoHealerApplication.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ZooKeeper-AutoHealer/AutoHealerApplication.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/ZooKeeper-AutoHealer/Worker.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/ZooKeeper-AutoHealer/Worker.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/AutoHealer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/AutoHealer.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/AutoHealerApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/AutoHealerApplication.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Worker.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Worker.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......
File added
No preview for this file type
D:
cd HIAST\FIY\FS\Distributed Systems\Lab\6\ZooKeeper-AutoHealer\Jars
java -Dorg.slf4j.simpleLogger.defaultLogLevel=off -jar AutoHealer.jar 10 ".\Worker.jar"
java -Dorg.slf4j.simpleLogger.defaultLogLevel=off -jar AutoHealer.jar 10 ".Jars\Worker.jar"
Open "Jars" Folder, inside there are two jars and command.txt
command.txt has the commands to run the jars.
\ No newline at end of file
java -Dorg.slf4j.simpleLogger.defaultLogLevel=off -jar .\AutoHealer.jar 10 ".\Worker.jar"
or
java -jar .\AutoHealer.jar 10 ".\Worker.jar"
\ No newline at end of file
File added
......@@ -86,12 +86,12 @@ public class AutoHealer implements Watcher
private void launchWorkersIfNecessary() throws KeeperException, InterruptedException
{
List<String> workerZnodes = zooKeeper.getChildren(AUTOHEALER_ZNODES_PATH, this);
AtomicInteger existingWorkersNumber = new AtomicInteger(workerZnodes.size());
if (existingWorkersNumber.get() > 0)
int existingWorkersNumber = workerZnodes.size();
if (existingWorkersNumber > 0)
{
System.out.println("Last Child Znode Now is : " + workerZnodes.get(existingWorkersNumber.get() -1));
System.out.println("Last Child Znode Now is : " + workerZnodes.get(existingWorkersNumber -1));
}
while (existingWorkersNumber.get() < numberOfWorkers )
/*while (existingWorkersNumber.get() < numberOfWorkers )
{
Thread thread = new Thread(()->
{
......@@ -103,23 +103,25 @@ public class AutoHealer implements Watcher
}
});
thread.start();
}
/*while (existingWorkersNumber < numberOfWorkers )
}*/
while (existingWorkersNumber < numberOfWorkers )
{
try {
try
{
System.out.println("Increasing Workers !!");
startNewWorker();
existingWorkersNumber++;
} catch (IOException e) {
//throw new RuntimeException(e);
}
}*/
while (existingWorkersNumber.get() > numberOfWorkers)
}
while (existingWorkersNumber > numberOfWorkers)
{
String worker = workerZnodes.get(0);
String workerPath = AUTOHEALER_ZNODES_PATH + "/" + worker;
System.out.println("delete node: " + AUTOHEALER_ZNODES_PATH + "/" + worker);
zooKeeper.delete(workerPath, -1);
existingWorkersNumber.getAndDecrement();
existingWorkersNumber--;
workerZnodes.remove(0);
}
}
......@@ -128,7 +130,8 @@ public class AutoHealer implements Watcher
* Helper method to start a single worker
* @throws IOException
*/
private void startNewWorker() throws IOException {
private void startNewWorker() throws IOException
{
File file = new File(pathToProgram);
String command = "java -Dorg.slf4j.simpleLogger.defaultLogLevel=off -jar " + file.getName();
System.out.println(String.format("Launching worker instance : %s ", command));
......
......@@ -13,6 +13,7 @@ public class AutoHealerApplication
int numberOfWorkers = Integer.parseInt(args[0]);
String pathToWorkerProgram = args[1];
AutoHealer autohealer = new AutoHealer(numberOfWorkers, pathToWorkerProgram);
//AutoHealer autohealer = new AutoHealer(10, ".\\Worker.jar");
autohealer.connectToZookeeper();
autohealer.startWatchingWorkers();
autohealer.run();
......
......@@ -27,9 +27,8 @@ public class Worker
public void work() throws KeeperException, InterruptedException {
addChildZnode();
while (true) {
while (true)
{
System.out.println(myName + " is Working...");
LockSupport.parkNanos(1000L);
if (random.nextFloat() < CHANCE_TO_FAIL) {
......@@ -44,7 +43,6 @@ public class Worker
new byte[]{},
ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.EPHEMERAL_SEQUENTIAL);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment