-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from stelin/main
Update cluster
- Loading branch information
Showing
69 changed files
with
832 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ava/io/openjob/worker/task/TaskQueue.java → ...ava/io/openjob/common/task/TaskQueue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package io.openjob.worker.task; | ||
package io.openjob.common.task; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ver-cluster/src/main/java/io/openjob/server/cluster/executor/WorkerHeartbeatExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.openjob.server.cluster.executor; | ||
|
||
import io.openjob.common.request.WorkerHeartbeatRequest; | ||
import io.openjob.common.task.TaskQueue; | ||
import io.openjob.server.cluster.service.WorkerHeartbeatService; | ||
import io.openjob.server.cluster.task.WorkerHeartConsumer; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author stelin [email protected] | ||
* @since 1.0.3 | ||
*/ | ||
@Slf4j | ||
@Component | ||
public class WorkerHeartbeatExecutor { | ||
private final TaskQueue<WorkerHeartbeatRequest> queue; | ||
|
||
/** | ||
* New | ||
*/ | ||
public WorkerHeartbeatExecutor() { | ||
this.queue = new TaskQueue<>(0L, 64); | ||
|
||
//Consumer | ||
WorkerHeartConsumer consumer = new WorkerHeartConsumer( | ||
0L, | ||
1, | ||
8, | ||
"Openjob-heartbeat-executor", | ||
50, | ||
"Openjob-heartbeat-consumer", | ||
this.queue | ||
); | ||
consumer.start(); | ||
} | ||
|
||
/** | ||
* Submit request | ||
* | ||
* @param request request | ||
*/ | ||
public void submit(WorkerHeartbeatRequest request) { | ||
try { | ||
this.queue.submit(request); | ||
} catch (InterruptedException e) { | ||
log.error("Worker heartbeat submit failed!", e); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...erver-cluster/src/main/java/io/openjob/server/cluster/executor/WorkerTaskLogExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.openjob.server.cluster.executor; | ||
|
||
import io.openjob.common.request.WorkerJobInstanceTaskLogRequest; | ||
import io.openjob.common.task.TaskQueue; | ||
import io.openjob.server.cluster.task.WorkerTaskLogConsumer; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author stelin [email protected] | ||
* @since 1.0.3 | ||
*/ | ||
@Slf4j | ||
@Component | ||
public class WorkerTaskLogExecutor { | ||
private final TaskQueue<WorkerJobInstanceTaskLogRequest> queue; | ||
|
||
/** | ||
* New | ||
*/ | ||
public WorkerTaskLogExecutor() { | ||
this.queue = new TaskQueue<>(0L, 64); | ||
|
||
// Consumer | ||
WorkerTaskLogConsumer consumer = new WorkerTaskLogConsumer( | ||
0L, | ||
1, | ||
16, | ||
"Openjob-log-executor", | ||
50, | ||
"Openjob-log-consumer", | ||
this.queue | ||
); | ||
consumer.start(); | ||
} | ||
|
||
/** | ||
* Submit request | ||
* | ||
* @param request request | ||
*/ | ||
public void submit(WorkerJobInstanceTaskLogRequest request) { | ||
try { | ||
this.queue.submit(request); | ||
} catch (InterruptedException e) { | ||
log.error("Worker task log submit failed!", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,8 @@ | |
* @author stelin [email protected] | ||
* @since 1.0.0 | ||
*/ | ||
@Component | ||
@Slf4j | ||
@Component | ||
public class FailManager { | ||
private final ServerDAO serverDAO; | ||
private final JobSlotsDAO jobSlotsDAO; | ||
|
@@ -69,7 +69,7 @@ public void fail(Node stopNode) { | |
failDTO.setServerId(stopNode.getServerId()); | ||
failDTO.setAkkaAddress(stopNode.getAkkaAddress()); | ||
|
||
// Akka message for join. | ||
// Akka message for fail. | ||
this.sendClusterStopMessage(failDTO, stopNode); | ||
} | ||
} catch (InterruptedException interruptedException) { | ||
|
@@ -135,7 +135,9 @@ public void shutdown(Node stopNode) { | |
*/ | ||
private void migrateSlots(Node stopNode) { | ||
List<JobSlots> currentJobSlots = this.jobSlotsDAO.listJobSlotsByServerId(stopNode.getServerId()); | ||
List<Server> servers = this.serverDAO.listServers(ServerStatusEnum.OK.getStatus()); | ||
List<Server> servers = this.serverDAO.listServers(ServerStatusEnum.OK.getStatus()) | ||
.stream().filter(s -> !s.getId().equals(stopNode.getServerId())) | ||
.collect(Collectors.toList()); | ||
|
||
// Exclude current server. | ||
int serverCount = servers.size(); | ||
|
@@ -154,27 +156,23 @@ private void migrateSlots(Node stopNode) { | |
for (int i = 0; i < servers.size(); i++) { | ||
Server s = servers.get(i); | ||
|
||
// Ignore current server. | ||
if (s.getId().equals(stopNode.getServerId())) { | ||
break; | ||
} | ||
|
||
// Last server. | ||
if (i + 1 == servers.size()) { | ||
List<Long> lastSlotsId = currentJobSlots.subList(index, currentJobSlots.size() - index) | ||
List<Long> lastSlotsId = currentJobSlots.subList(index, currentJobSlots.size()) | ||
.stream() | ||
.map(JobSlots::getId) | ||
.collect(Collectors.toList()); | ||
migrationSlots.put(s.getId(), lastSlotsId); | ||
break; | ||
} | ||
|
||
index += slotsSize; | ||
|
||
List<Long> slotIds = currentJobSlots.subList(index, slotsSize) | ||
int segmentSize = (i + 1) * slotsSize; | ||
List<Long> slotIds = currentJobSlots.subList(index, segmentSize) | ||
.stream() | ||
.map(JobSlots::getId) | ||
.collect(Collectors.toList()); | ||
|
||
index = segmentSize; | ||
migrationSlots.put(s.getId(), slotIds); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.