Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
A
auto-healer-zookeper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
areej.mohammad
auto-healer-zookeper
Commits
22b48b55
Commit
22b48b55
authored
Dec 24, 2025
by
areej.mohammad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit9
parent
c48aa75b
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
1 addition
and
301 deletions
+1
-301
transientworker
transientworker
+1
-0
dependency-reduced-pom.xml
transientworker/dependency-reduced-pom.xml
+0
-43
pom.xml
transientworker/pom.xml
+0
-58
Application.java
transientworker/src/main/java/Application.java
+0
-35
NodeAgent.java
transientworker/src/main/java/NodeAgent.java
+0
-86
Worker.java
transientworker/src/main/java/Worker.java
+0
-70
Application.class
transientworker/target/classes/Application.class
+0
-0
NodeAgent.class
transientworker/target/classes/NodeAgent.class
+0
-0
Worker.class
transientworker/target/classes/Worker.class
+0
-0
pom.properties
transientworker/target/maven-archiver/pom.properties
+0
-3
createdFiles.lst
...-compiler-plugin/compile/default-compile/createdFiles.lst
+0
-3
inputFiles.lst
...en-compiler-plugin/compile/default-compile/inputFiles.lst
+0
-3
original-transientworker-1.0-SNAPSHOT.jar
...ntworker/target/original-transientworker-1.0-SNAPSHOT.jar
+0
-0
transientworker-1.0-SNAPSHOT.jar
transientworker/target/transientworker-1.0-SNAPSHOT.jar
+0
-0
No files found.
transientworker
@
491fde3f
Subproject commit 491fde3f07465db4ae259db2f9df286fc7623f12
transientworker/dependency-reduced-pom.xml
deleted
100644 → 0
View file @
c48aa75b
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.example
</groupId>
<artifactId>
transientworker
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<build>
<plugins>
<plugin>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.11.0
</version>
<configuration>
<source>
17
</source>
<target>
17
</target>
</configuration>
</plugin>
<plugin>
<artifactId>
maven-shade-plugin
</artifactId>
<version>
3.2.4
</version>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
shade
</goal>
</goals>
<configuration>
<transformers>
<transformer>
<mainClass>
Application
</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.target>
17
</maven.compiler.target>
<maven.compiler.source>
17
</maven.compiler.source>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
</project>
transientworker/pom.xml
deleted
100644 → 0
View file @
c48aa75b
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.example
</groupId>
<artifactId>
transientworker
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<properties>
<maven.compiler.source>
17
</maven.compiler.source>
<maven.compiler.target>
17
</maven.compiler.target>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.11.0
</version>
<configuration>
<source>
17
</source>
<target>
17
</target>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-shade-plugin
</artifactId>
<version>
3.2.4
</version>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>
shade
</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"
>
<mainClass>
Application
</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>
org.apache.zookeeper
</groupId>
<artifactId>
zookeeper
</artifactId>
<version>
3.9.1
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
transientworker/src/main/java/Application.java
deleted
100644 → 0
View file @
c48aa75b
/*
* MIT License
*
* Copyright (c) 2019 Michael Pogrebinsky - Distributed Systems & Cloud Computing with Java
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import
org.apache.zookeeper.KeeperException
;
import
java.io.IOException
;
public
class
Application
{
public
static
void
main
(
String
[]
args
)
throws
IOException
,
KeeperException
,
InterruptedException
{
Worker
worker
=
new
Worker
();
worker
.
connectToZookeeper
();
worker
.
work
();
}
}
transientworker/src/main/java/NodeAgent.java
deleted
100644 → 0
View file @
c48aa75b
import
org.apache.zookeeper.*
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.InetAddress
;
import
java.util.List
;
public
class
NodeAgent
implements
Watcher
{
private
static
final
String
ZOOKEEPER_ADDRESS
=
"192.168.144.134:2181"
;
private
static
final
int
SESSION_TIMEOUT
=
3000
;
private
static
final
String
NODES_ROOT
=
"/nodes"
;
private
static
final
String
WORKER_JAR_PATH
=
"C:\\Users\\J.N\\IdeaProjects\\auto-healer-zookeper\\transientworker\\target\\transientworker-1.0-SNAPSHOT.jar"
;
private
ZooKeeper
zooKeeper
;
private
String
myTasksPath
;
public
void
connectToZookeeper
()
throws
IOException
{
this
.
zooKeeper
=
new
ZooKeeper
(
ZOOKEEPER_ADDRESS
,
SESSION_TIMEOUT
,
this
);
}
public
void
registerNodeAndWatchTasks
()
throws
KeeperException
,
InterruptedException
,
IOException
{
ensurePath
(
NODES_ROOT
,
CreateMode
.
PERSISTENT
);
String
ipAddress
=
InetAddress
.
getLocalHost
().
getHostAddress
();
String
nodePath
=
NODES_ROOT
+
"/node_"
+
ipAddress
;
ensurePath
(
nodePath
,
CreateMode
.
PERSISTENT
);
String
activePath
=
nodePath
+
"/active"
;
if
(
zooKeeper
.
exists
(
activePath
,
false
)
==
null
)
{
zooKeeper
.
create
(
activePath
,
new
byte
[]{},
ZooDefs
.
Ids
.
OPEN_ACL_UNSAFE
,
CreateMode
.
EPHEMERAL
);
}
this
.
myTasksPath
=
nodePath
+
"/tasks"
;
ensurePath
(
myTasksPath
,
CreateMode
.
PERSISTENT
);
System
.
out
.
println
(
"Node Registered: "
+
nodePath
+
". Watching tasks at: "
+
myTasksPath
);
watchMyTasks
();
}
private
void
ensurePath
(
String
path
,
CreateMode
mode
)
throws
KeeperException
,
InterruptedException
{
if
(
zooKeeper
.
exists
(
path
,
false
)
==
null
)
{
zooKeeper
.
create
(
path
,
new
byte
[]{},
ZooDefs
.
Ids
.
OPEN_ACL_UNSAFE
,
mode
);
}
}
private
void
watchMyTasks
()
throws
KeeperException
,
InterruptedException
{
List
<
String
>
tasks
=
zooKeeper
.
getChildren
(
myTasksPath
,
this
);
System
.
out
.
println
(
"Current tasks count: "
+
tasks
.
size
());
}
@Override
public
void
process
(
WatchedEvent
event
)
{
if
(
event
.
getType
()
==
Event
.
EventType
.
NodeChildrenChanged
&&
event
.
getPath
().
equals
(
myTasksPath
))
{
handleNewTask
();
}
else
if
(
event
.
getState
()
==
Event
.
KeeperState
.
SyncConnected
)
{
System
.
out
.
println
(
"Connected to Zookeeper"
);
}
}
private
void
handleNewTask
()
{
try
{
startLocalWorker
();
watchMyTasks
();
// إعادة المراقبة
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
void
startLocalWorker
()
throws
IOException
{
File
jarFile
=
new
File
(
WORKER_JAR_PATH
);
ProcessBuilder
pb
=
new
ProcessBuilder
(
"java"
,
"-jar"
,
jarFile
.
getAbsolutePath
());
pb
.
inheritIO
();
pb
.
directory
(
jarFile
.
getParentFile
());
System
.
out
.
println
(
"New worker launched locally!"
);
pb
.
start
();
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
NodeAgent
agent
=
new
NodeAgent
();
agent
.
connectToZookeeper
();
agent
.
registerNodeAndWatchTasks
();
synchronized
(
agent
.
zooKeeper
)
{
agent
.
zooKeeper
.
wait
();
}
}
}
\ No newline at end of file
transientworker/src/main/java/Worker.java
deleted
100644 → 0
View file @
c48aa75b
/*
* MIT License
*
* Copyright (c) 2019 Michael Pogrebinsky - Distributed Systems & Cloud Computing with Java
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import
org.apache.zookeeper.CreateMode
;
import
org.apache.zookeeper.KeeperException
;
import
org.apache.zookeeper.ZooDefs
;
import
org.apache.zookeeper.ZooKeeper
;
import
java.io.IOException
;
import
java.util.Random
;
import
java.util.concurrent.locks.LockSupport
;
public
class
Worker
{
private
static
final
String
ZOOKEEPER_ADDRESS
=
"192.168.144.134:2181"
;
private
static
final
int
SESSION_TIMEOUT
=
3000
;
// Parent Znode where each worker stores an ephemeral child to indicate it is alive
private
static
final
String
AUTOHEALER_ZNODES_PATH
=
"/workers"
;
private
static
final
float
CHANCE_TO_FAIL
=
0.1
F
;
private
final
Random
random
=
new
Random
();
private
ZooKeeper
zooKeeper
;
public
void
connectToZookeeper
()
throws
IOException
{
this
.
zooKeeper
=
new
ZooKeeper
(
ZOOKEEPER_ADDRESS
,
SESSION_TIMEOUT
,
event
->
{
});
}
public
void
work
()
throws
KeeperException
,
InterruptedException
{
addChildZnode
();
while
(
true
)
{
System
.
out
.
println
(
"Working..."
);
LockSupport
.
parkNanos
(
1000
);
if
(
random
.
nextFloat
()
<
CHANCE_TO_FAIL
)
{
System
.
out
.
println
(
"Critical error happened"
);
throw
new
RuntimeException
(
"Oops"
);
}
}
}
private
void
addChildZnode
()
throws
KeeperException
,
InterruptedException
{
zooKeeper
.
create
(
AUTOHEALER_ZNODES_PATH
+
"/worker_"
,
new
byte
[]{},
ZooDefs
.
Ids
.
OPEN_ACL_UNSAFE
,
CreateMode
.
EPHEMERAL_SEQUENTIAL
);
}
}
transientworker/target/classes/Application.class
deleted
100644 → 0
View file @
c48aa75b
File deleted
transientworker/target/classes/NodeAgent.class
deleted
100644 → 0
View file @
c48aa75b
File deleted
transientworker/target/classes/Worker.class
deleted
100644 → 0
View file @
c48aa75b
File deleted
transientworker/target/maven-archiver/pom.properties
deleted
100644 → 0
View file @
c48aa75b
artifactId
=
transientworker
groupId
=
org.example
version
=
1.0-SNAPSHOT
transientworker/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
deleted
100644 → 0
View file @
c48aa75b
Application.class
Worker.class
NodeAgent.class
transientworker/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
deleted
100644 → 0
View file @
c48aa75b
C:\Users\J.N\IdeaProjects\auto-healer-zookeper\transientworker\src\main\java\Application.java
C:\Users\J.N\IdeaProjects\auto-healer-zookeper\transientworker\src\main\java\NodeAgent.java
C:\Users\J.N\IdeaProjects\auto-healer-zookeper\transientworker\src\main\java\Worker.java
transientworker/target/original-transientworker-1.0-SNAPSHOT.jar
deleted
100644 → 0
View file @
c48aa75b
File deleted
transientworker/target/transientworker-1.0-SNAPSHOT.jar
deleted
100644 → 0
View file @
c48aa75b
File deleted
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment