You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2020/08/03 11:09:04 UTC
[shardingsphere-elasticjob-ui] branch master updated: Refactor code
This is an automated email from the ASF dual-hosted git repository.
menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob-ui.git
The following commit(s) were added to refs/heads/master by this push:
new 7faa12d Refactor code
new 9eea701 Merge pull request #35 from menghaoranss/refactor-code
7faa12d is described below
commit 7faa12d50d062f7062a17d86b84e12ce88620c8d
Author: menghaoranss <lo...@163.com>
AuthorDate: Mon Aug 3 19:07:08 2020 +0800
Refactor code
---
.../elasticjob/cloud/ui/service/FacadeService.java | 171 ------------------
.../ui/service/state/failover/FailoverService.java | 65 -------
.../cloud/ui/service/state/ready/ReadyService.java | 52 ------
.../ui/service/state/running/RunningService.java | 200 +--------------------
.../ui/service/statistics/TaskResultMetaData.java | 79 --------
.../statistics/util/StatisticTimeUtils.java | 10 --
6 files changed, 5 insertions(+), 572 deletions(-)
diff --git a/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/FacadeService.java b/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/FacadeService.java
index 12cc456..d9d39e7 100644
--- a/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/FacadeService.java
+++ b/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/FacadeService.java
@@ -18,10 +18,7 @@
package org.apache.shardingsphere.elasticjob.cloud.ui.service;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.elasticjob.cloud.config.CloudJobExecutionType;
import org.apache.shardingsphere.elasticjob.cloud.config.pojo.CloudJobConfigurationPOJO;
-import org.apache.shardingsphere.elasticjob.cloud.ui.service.app.CloudAppConfigurationService;
-import org.apache.shardingsphere.elasticjob.cloud.ui.service.app.pojo.CloudAppConfigurationPOJO;
import org.apache.shardingsphere.elasticjob.cloud.ui.service.job.CloudJobConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.ui.service.state.disable.app.DisableAppService;
import org.apache.shardingsphere.elasticjob.cloud.ui.service.state.disable.job.DisableJobService;
@@ -29,20 +26,14 @@ import org.apache.shardingsphere.elasticjob.cloud.ui.service.state.failover.Fail
import org.apache.shardingsphere.elasticjob.cloud.ui.service.state.failover.FailoverTaskInfo;
import org.apache.shardingsphere.elasticjob.cloud.ui.service.state.ready.ReadyService;
import org.apache.shardingsphere.elasticjob.cloud.ui.service.state.running.RunningService;
-import org.apache.shardingsphere.elasticjob.infra.context.ExecutionType;
import org.apache.shardingsphere.elasticjob.infra.context.TaskContext;
-import org.apache.shardingsphere.elasticjob.infra.context.TaskContext.MetaInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
-import java.util.stream.Collectors;
/**
* Mesos facade service.
@@ -52,9 +43,6 @@ import java.util.stream.Collectors;
public final class FacadeService {
@Autowired
- private CloudAppConfigurationService appConfigService;
-
- @Autowired
private CloudJobConfigurationService jobConfigService;
@Autowired
@@ -72,88 +60,6 @@ public final class FacadeService {
@Autowired
private DisableJobService disableJobService;
- /**
- * Start facade service.
- */
- public void start() {
- log.info("Elastic Job: Start facade service");
- runningService.start();
- }
-
- /**
- * Remove launched task from queue.
- *
- * @param taskContexts task running contexts
- */
- public void removeLaunchTasksFromQueue(final List<TaskContext> taskContexts) {
- List<TaskContext> failoverTaskContexts = new ArrayList<>(taskContexts.size());
- Collection<String> readyJobNames = new HashSet<>(taskContexts.size(), 1);
- for (TaskContext each : taskContexts) {
- switch (each.getType()) {
- case FAILOVER:
- failoverTaskContexts.add(each);
- break;
- case READY:
- readyJobNames.add(each.getMetaInfo().getJobName());
- break;
- default:
- break;
- }
- }
- failoverService.remove(failoverTaskContexts.stream().map(TaskContext::getMetaInfo).collect(Collectors.toList()));
- readyService.remove(readyJobNames);
- }
-
- /**
- * Add task to running queue.
- *
- * @param taskContext task running context
- */
- public void addRunning(final TaskContext taskContext) {
- runningService.add(taskContext);
- }
-
- /**
- * Update daemon task status.
- *
- * @param taskContext task running context
- * @param isIdle set to idle or not
- */
- public void updateDaemonStatus(final TaskContext taskContext, final boolean isIdle) {
- runningService.updateIdle(taskContext, isIdle);
- }
-
- /**
- * Remove task from running queue.
- *
- * @param taskContext task running context
- */
- public void removeRunning(final TaskContext taskContext) {
- runningService.remove(taskContext);
- }
-
- /**
- * Record task to failover queue.
- *
- * @param taskContext task running context
- */
- public void recordFailoverTask(final TaskContext taskContext) {
- Optional<CloudJobConfigurationPOJO> cloudJobConfigOptional = jobConfigService.load(taskContext.getMetaInfo().getJobName());
- if (!cloudJobConfigOptional.isPresent()) {
- return;
- }
- if (isDisable(cloudJobConfigOptional.get())) {
- return;
- }
- CloudJobConfigurationPOJO cloudJobConfig = cloudJobConfigOptional.get();
- if (cloudJobConfig.isFailover() || CloudJobExecutionType.DAEMON == cloudJobConfig.getJobExecutionType()) {
- failoverService.add(taskContext);
- }
- }
-
- private boolean isDisable(final CloudJobConfigurationPOJO cloudJobConfig) {
- return disableAppService.isDisabled(cloudJobConfig.getAppName()) || disableJobService.isDisabled(cloudJobConfig.getJobName());
- }
/**
* Add transient job to ready queue.
@@ -175,73 +81,6 @@ public final class FacadeService {
}
/**
- * Load app config by app name.
- *
- * @param appName app name
- * @return cloud app config
- */
- public Optional<CloudAppConfigurationPOJO> loadAppConfig(final String appName) {
- return appConfigService.load(appName);
- }
-
- /**
- * Get failover task id by task meta info.
- *
- * @param metaInfo task meta info
- * @return failover task id
- */
- public Optional<String> getFailoverTaskId(final MetaInfo metaInfo) {
- return failoverService.getTaskId(metaInfo);
- }
-
- /**
- * Add daemon job to ready queue.
- *
- * @param jobName job name
- */
- public void addDaemonJobToReadyQueue(final String jobName) {
- Optional<CloudJobConfigurationPOJO> cloudJobConfig = jobConfigService.load(jobName);
- if (!cloudJobConfig.isPresent()) {
- return;
- }
- if (isDisable(cloudJobConfig.get())) {
- return;
- }
- readyService.addDaemon(jobName);
- }
-
- /**
- * Determine whether the task is running or not.
- *
- * @param taskContext task running context
- * @return true is running, otherwise not
- */
- public boolean isRunning(final TaskContext taskContext) {
- return ExecutionType.FAILOVER != taskContext.getType() && !runningService.getRunningTasks(taskContext.getMetaInfo().getJobName()).isEmpty()
- || ExecutionType.FAILOVER == taskContext.getType() && runningService.isTaskRunning(taskContext.getMetaInfo());
- }
-
- /**
- * Add mapping of the task primary key and host name.
- *
- * @param taskId task primary key
- * @param hostname host name
- */
- public void addMapping(final String taskId, final String hostname) {
- runningService.addMapping(taskId, hostname);
- }
-
- /**
- * Retrieve hostname and then remove task.
- *
- * @param taskId task primary key
- * @return hostname of the removed task
- */
- public String popMapping(final String taskId) {
- return runningService.popMapping(taskId);
- }
-
- /**
* Get all ready tasks.
*
* @return ready tasks
@@ -296,14 +135,4 @@ public final class FacadeService {
public void disableJob(final String jobName) {
disableJobService.add(jobName);
}
-
-
- /**
- * Stop facade service.
- */
- public void stop() {
- log.info("Elastic Job: Stop facade service");
- // TODO stop scheduler
- runningService.clear();
- }
}
diff --git a/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/state/failover/FailoverService.java b/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/state/failover/FailoverService.java
index b98d8ed..333de5e 100644
--- a/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/state/failover/FailoverService.java
+++ b/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/state/failover/FailoverService.java
@@ -18,26 +18,18 @@
package org.apache.shardingsphere.elasticjob.cloud.ui.service.state.failover;
import com.google.common.base.Strings;
-import com.google.common.hash.HashCode;
-import com.google.common.hash.Hashing;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.elasticjob.cloud.ui.config.JobStateConfiguration;
-import org.apache.shardingsphere.elasticjob.cloud.ui.service.state.running.RunningService;
-import org.apache.shardingsphere.elasticjob.infra.context.TaskContext;
import org.apache.shardingsphere.elasticjob.infra.context.TaskContext.MetaInfo;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
/**
* Failover service.
@@ -49,63 +41,6 @@ public final class FailoverService {
@Autowired
private CoordinatorRegistryCenter regCenter;
- @Autowired
- private RunningService runningService;
-
- @Autowired
- private JobStateConfiguration jobStateConfiguration;
-
- /**
- * Add task to failover queue.
- *
- * @param taskContext task running context
- */
- public void add(final TaskContext taskContext) {
- if (regCenter.getNumChildren(FailoverNode.ROOT) > jobStateConfiguration.getQueueSize()) {
- log.warn("Cannot add job, caused by read state queue size is larger than {}.", jobStateConfiguration.getQueueSize());
- return;
- }
- String failoverTaskNodePath = FailoverNode.getFailoverTaskNodePath(taskContext.getMetaInfo().toString());
- if (!regCenter.isExisted(failoverTaskNodePath) && !runningService.isTaskRunning(taskContext.getMetaInfo())) {
- // TODO Whether Daemon-type jobs increase storage and fail immediately?
- regCenter.persist(failoverTaskNodePath, taskContext.getId());
- }
- }
-
- private List<Integer> getAssignedShardingItems(final String jobName, final List<String> taskIdList, final Set<HashCode> assignedTasks) {
- List<Integer> result = new ArrayList<>(taskIdList.size());
- for (String each : taskIdList) {
- MetaInfo metaInfo = MetaInfo.from(each);
- if (assignedTasks.add(Hashing.sha256().newHasher().putString(jobName, StandardCharsets.UTF_8).putInt(metaInfo.getShardingItems().get(0)).hash())
- && !runningService.isTaskRunning(metaInfo)) {
- result.add(metaInfo.getShardingItems().get(0));
- }
- }
- return result;
- }
-
- /**
- * Remove task from the failover queue.
- *
- * @param metaInfoList collection of task meta infos to be removed
- */
- public void remove(final Collection<MetaInfo> metaInfoList) {
- for (MetaInfo each : metaInfoList) {
- regCenter.remove(FailoverNode.getFailoverTaskNodePath(each.toString()));
- }
- }
-
- /**
- * Get task id from failover queue.
- *
- * @param metaInfo task meta info
- * @return failover task id
- */
- public Optional<String> getTaskId(final MetaInfo metaInfo) {
- String failoverTaskNodePath = FailoverNode.getFailoverTaskNodePath(metaInfo.toString());
- return regCenter.isExisted(failoverTaskNodePath) ? Optional.of(regCenter.get(failoverTaskNodePath)) : Optional.empty();
- }
-
/**
* Get all failover tasks.
*
diff --git a/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/state/ready/ReadyService.java b/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/state/ready/ReadyService.java
index b5544a6..40a9d1b 100644
--- a/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/state/ready/ReadyService.java
+++ b/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/state/ready/ReadyService.java
@@ -23,12 +23,10 @@ import org.apache.shardingsphere.elasticjob.cloud.config.CloudJobExecutionType;
import org.apache.shardingsphere.elasticjob.cloud.config.pojo.CloudJobConfigurationPOJO;
import org.apache.shardingsphere.elasticjob.cloud.ui.config.JobStateConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.ui.service.job.CloudJobConfigurationService;
-import org.apache.shardingsphere.elasticjob.cloud.ui.service.state.running.RunningService;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -49,9 +47,6 @@ public final class ReadyService {
private CloudJobConfigurationService configService;
@Autowired
- private RunningService runningService;
-
- @Autowired
private JobStateConfiguration jobStateConfiguration;
@@ -79,53 +74,6 @@ public final class ReadyService {
}
/**
- * Add daemon job to ready queue.
- *
- * @param jobName job name
- */
- public void addDaemon(final String jobName) {
- if (regCenter.getNumChildren(ReadyNode.ROOT) > jobStateConfiguration.getQueueSize()) {
- log.warn("Cannot add daemon job, caused by read state queue size is larger than {}.", jobStateConfiguration.getQueueSize());
- return;
- }
- Optional<CloudJobConfigurationPOJO> cloudJobConfig = configService.load(jobName);
- if (!cloudJobConfig.isPresent() || CloudJobExecutionType.DAEMON != cloudJobConfig.get().getJobExecutionType() || runningService.isJobRunning(jobName)) {
- return;
- }
- regCenter.persist(ReadyNode.getReadyJobNodePath(jobName), "1");
- }
-
- /**
- * Set misfire disabled.
- *
- * @param jobName job name
- */
- public void setMisfireDisabled(final String jobName) {
- Optional<CloudJobConfigurationPOJO> cloudJobConfig = configService.load(jobName);
- if (cloudJobConfig.isPresent() && null != regCenter.getDirectly(ReadyNode.getReadyJobNodePath(jobName))) {
- regCenter.persist(ReadyNode.getReadyJobNodePath(jobName), "1");
- }
- }
-
- /**
- * Remove jobs from ready queue.
- *
- * @param jobNames collection of jobs to be removed
- */
- public void remove(final Collection<String> jobNames) {
- for (String each : jobNames) {
- String readyJobNode = ReadyNode.getReadyJobNodePath(each);
- String timesStr = regCenter.getDirectly(readyJobNode);
- int times = null == timesStr ? 0 : Integer.parseInt(timesStr);
- if (times <= 1) {
- regCenter.remove(readyJobNode);
- } else {
- regCenter.persist(readyJobNode, Integer.toString(times - 1));
- }
- }
- }
-
- /**
* Get all ready tasks.
*
* @return all ready tasks
diff --git a/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/state/running/RunningService.java b/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/state/running/RunningService.java
index 7de20fc..64a0402 100644
--- a/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/state/running/RunningService.java
+++ b/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/state/running/RunningService.java
@@ -18,9 +18,6 @@
package org.apache.shardingsphere.elasticjob.cloud.ui.service.state.running;
import com.google.common.collect.Sets;
-import lombok.Getter;
-import org.apache.shardingsphere.elasticjob.cloud.config.CloudJobExecutionType;
-import org.apache.shardingsphere.elasticjob.cloud.config.pojo.CloudJobConfigurationPOJO;
import org.apache.shardingsphere.elasticjob.cloud.ui.service.job.CloudJobConfigurationService;
import org.apache.shardingsphere.elasticjob.infra.context.TaskContext;
import org.apache.shardingsphere.elasticjob.infra.context.TaskContext.MetaInfo;
@@ -28,14 +25,10 @@ import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
import java.util.stream.Collectors;
/**
@@ -44,14 +37,6 @@ import java.util.stream.Collectors;
@Service
public final class RunningService {
- private static final int TASK_INITIAL_SIZE = 1024;
-
- // TODO Using JMX to export
- @Getter
- private static final ConcurrentHashMap<String, Set<TaskContext>> RUNNING_TASKS = new ConcurrentHashMap<>(TASK_INITIAL_SIZE);
-
- private static final ConcurrentHashMap<String, String> TASK_HOSTNAME_MAPPER = new ConcurrentHashMap<>(TASK_INITIAL_SIZE);
-
@Autowired
private CoordinatorRegistryCenter regCenter;
@@ -59,195 +44,20 @@ public final class RunningService {
private CloudJobConfigurationService configurationService;
/**
- * Start running queue service.
- */
- public void start() {
- clear();
- List<String> jobKeys = regCenter.getChildrenKeys(RunningNode.ROOT);
- for (String each : jobKeys) {
- if (!configurationService.load(each).isPresent()) {
- remove(each);
- continue;
- }
- RUNNING_TASKS.put(each, Sets.newCopyOnWriteArraySet(regCenter.getChildrenKeys(RunningNode.getRunningJobNodePath(each)).stream().map(
- input -> TaskContext.from(regCenter.get(RunningNode.getRunningTaskNodePath(MetaInfo.from(input).toString())))).collect(Collectors.toList())));
- }
- }
-
- /**
- * Add task to running queue.
- *
- * @param taskContext task running context
- */
- public void add(final TaskContext taskContext) {
- if (!configurationService.load(taskContext.getMetaInfo().getJobName()).isPresent()) {
- return;
- }
- getRunningTasks(taskContext.getMetaInfo().getJobName()).add(taskContext);
- if (!isDaemon(taskContext.getMetaInfo().getJobName())) {
- return;
- }
- String runningTaskNodePath = RunningNode.getRunningTaskNodePath(taskContext.getMetaInfo().toString());
- if (!regCenter.isExisted(runningTaskNodePath)) {
- regCenter.persist(runningTaskNodePath, taskContext.getId());
- }
- }
-
- private boolean isDaemon(final String jobName) {
- Optional<CloudJobConfigurationPOJO> cloudJobConfig = configurationService.load(jobName);
- return cloudJobConfig.isPresent() && CloudJobExecutionType.DAEMON == cloudJobConfig.get().getJobExecutionType();
- }
-
- /**
- * Update task to idle state.
- *
- * @param taskContext task running context
- * @param isIdle is idle
- */
- public void updateIdle(final TaskContext taskContext, final boolean isIdle) {
- synchronized (RUNNING_TASKS) {
- Optional<TaskContext> taskContextOptional = findTask(taskContext);
- if (taskContextOptional.isPresent()) {
- taskContextOptional.get().setIdle(isIdle);
- } else {
- add(taskContext);
- }
- }
- }
-
- private Optional<TaskContext> findTask(final TaskContext taskContext) {
- return getRunningTasks(taskContext.getMetaInfo().getJobName()).stream().filter(each -> each.equals(taskContext)).findFirst();
- }
-
- /**
- * Remove job from running queue.
- *
- * @param jobName job name
- */
- public void remove(final String jobName) {
- RUNNING_TASKS.remove(jobName);
- if (!isDaemonOrAbsent(jobName)) {
- return;
- }
- regCenter.remove(RunningNode.getRunningJobNodePath(jobName));
- }
-
- /**
- * Remove task from running queue.
- *
- * @param taskContext task running context
- */
- public void remove(final TaskContext taskContext) {
- getRunningTasks(taskContext.getMetaInfo().getJobName()).remove(taskContext);
- if (!isDaemonOrAbsent(taskContext.getMetaInfo().getJobName())) {
- return;
- }
- regCenter.remove(RunningNode.getRunningTaskNodePath(taskContext.getMetaInfo().toString()));
- String jobRootNode = RunningNode.getRunningJobNodePath(taskContext.getMetaInfo().getJobName());
- if (regCenter.isExisted(jobRootNode) && regCenter.getChildrenKeys(jobRootNode).isEmpty()) {
- regCenter.remove(jobRootNode);
- }
- }
-
- private boolean isDaemonOrAbsent(final String jobName) {
- Optional<CloudJobConfigurationPOJO> cloudJobConfigurationOptional = configurationService.load(jobName);
- return !cloudJobConfigurationOptional.isPresent() || CloudJobExecutionType.DAEMON == cloudJobConfigurationOptional.get().getJobExecutionType();
- }
-
- /**
- * Determine whether the job is running or not.
- *
- * @param jobName job name
- * @return true is running, otherwise not
- */
- public boolean isJobRunning(final String jobName) {
- return !getRunningTasks(jobName).isEmpty();
- }
-
- /**
- * Determine whether the task is running or not.
- *
- * @param metaInfo task meta info
- * @return true is running, otherwise not
- */
- public boolean isTaskRunning(final MetaInfo metaInfo) {
- for (TaskContext each : getRunningTasks(metaInfo.getJobName())) {
- if (each.getMetaInfo().equals(metaInfo)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Get running tasks by job name.
- *
- * @param jobName job name
- * @return collection of the running tasks
- */
- public Collection<TaskContext> getRunningTasks(final String jobName) {
- Set<TaskContext> taskContexts = new CopyOnWriteArraySet<>();
- Collection<TaskContext> result = RUNNING_TASKS.putIfAbsent(jobName, taskContexts);
- return null == result ? taskContexts : result;
- }
-
- /**
* Get all running tasks.
*
* @return collection of all the running tasks
*/
public Map<String, Set<TaskContext>> getAllRunningTasks() {
- Map<String, Set<TaskContext>> result = new HashMap<>(RUNNING_TASKS.size(), 1);
- result.putAll(RUNNING_TASKS);
- return result;
- }
-
- /**
- * Get all running daemon tasks.
- *
- * @return collection of all the running daemon tasks
- */
- public Set<TaskContext> getAllRunningDaemonTasks() {
+ Map<String, Set<TaskContext>> result = new HashMap<>();
List<String> jobKeys = regCenter.getChildrenKeys(RunningNode.ROOT);
for (String each : jobKeys) {
- if (!RUNNING_TASKS.containsKey(each)) {
- remove(each);
- }
- }
- Set<TaskContext> result = Sets.newHashSet();
- for (Map.Entry<String, Set<TaskContext>> each : RUNNING_TASKS.entrySet()) {
- if (isDaemonOrAbsent(each.getKey())) {
- result.addAll(each.getValue());
+ if (!configurationService.load(each).isPresent()) {
+ continue;
}
+ result.put(each, Sets.newCopyOnWriteArraySet(regCenter.getChildrenKeys(RunningNode.getRunningJobNodePath(each)).stream().map(
+ input -> TaskContext.from(regCenter.get(RunningNode.getRunningTaskNodePath(MetaInfo.from(input).toString())))).collect(Collectors.toList())));
}
return result;
}
-
- /**
- * Add mapping of task primary key and hostname.
- *
- * @param taskId task primary key
- * @param hostname host name
- */
- public void addMapping(final String taskId, final String hostname) {
- TASK_HOSTNAME_MAPPER.putIfAbsent(taskId, hostname);
- }
-
- /**
- * Retrieve the hostname and then remove this task from the mapping.
- *
- * @param taskId task primary key
- * @return the host name of the removed task
- */
- public String popMapping(final String taskId) {
- return TASK_HOSTNAME_MAPPER.remove(taskId);
- }
-
- /**
- * Clear the running status.
- */
- public void clear() {
- RUNNING_TASKS.clear();
- TASK_HOSTNAME_MAPPER.clear();
- }
}
diff --git a/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/statistics/TaskResultMetaData.java b/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/statistics/TaskResultMetaData.java
deleted file mode 100644
index e7dde23..0000000
--- a/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/statistics/TaskResultMetaData.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.elasticjob.cloud.ui.service.statistics;
-
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * Task result meta data.
- */
-public final class TaskResultMetaData {
-
- private final AtomicInteger successCount;
-
- private final AtomicInteger failedCount;
-
- public TaskResultMetaData() {
- successCount = new AtomicInteger(0);
- failedCount = new AtomicInteger(0);
- }
-
- /**
- * Increase and get success count.
- *
- * @return success count
- */
- public int incrementAndGetSuccessCount() {
- return successCount.incrementAndGet();
- }
-
- /**
- * Increase and get failed count.
- *
- * @return failed count
- */
- public int incrementAndGetFailedCount() {
- return failedCount.incrementAndGet();
- }
-
- /**
- * Get success count.
- *
- * @return success count
- */
- public int getSuccessCount() {
- return successCount.get();
- }
-
- /**
- * Get failed count.
- *
- * @return failed count
- */
- public int getFailedCount() {
- return failedCount.get();
- }
-
- /**
- * Reset success and failed count.
- */
- public void reset() {
- successCount.set(0);
- failedCount.set(0);
- }
-}
diff --git a/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/statistics/util/StatisticTimeUtils.java b/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/statistics/util/StatisticTimeUtils.java
index 4be71ad..0252c71 100644
--- a/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/statistics/util/StatisticTimeUtils.java
+++ b/shardingsphere-elasticjob-cloud-ui/shardingsphere-elasticjob-cloud-ui-backend/src/main/java/org/apache/shardingsphere/elasticjob/cloud/ui/service/statistics/util/StatisticTimeUtils.java
@@ -34,16 +34,6 @@ public final class StatisticTimeUtils {
* Get the statistical time with the interval unit.
*
* @param interval interval
- * @return Date
- */
- public static Date getCurrentStatisticTime(final StatisticInterval interval) {
- return getStatisticTime(interval, 0);
- }
-
- /**
- * Get the statistical time with the interval unit.
- *
- * @param interval interval
* @param offset offset
* @return Date
*/