use of com.dangdang.ddframe.job.lite.internal.storage.JobNodePath in project elastic-job by dangdangdotcom.
the class ServerStatisticsAPIImpl method getJob.
private ServerInfo getJob(final String serverIp, final String jobName) {
ServerInfo result = new ServerInfo();
JobNodePath jobNodePath = new JobNodePath(jobName);
result.setJobName(jobName);
result.setIp(serverIp);
result.setHostName(regCenter.get(jobNodePath.getServerNodePath(serverIp, "hostName")));
result.setSharding(regCenter.get(jobNodePath.getServerNodePath(serverIp, "sharding")));
String status = regCenter.get(jobNodePath.getServerNodePath(serverIp, "status"));
boolean disabled = regCenter.isExisted(jobNodePath.getServerNodePath(serverIp, "disabled"));
boolean paused = regCenter.isExisted(jobNodePath.getServerNodePath(serverIp, "paused"));
boolean shutdown = regCenter.isExisted(jobNodePath.getServerNodePath(serverIp, "shutdown"));
result.setStatus(ServerInfo.ServerStatus.getServerStatus(status, disabled, paused, shutdown));
return result;
}
use of com.dangdang.ddframe.job.lite.internal.storage.JobNodePath in project elastic-job by dangdangdotcom.
the class JobSettingsAPIImpl method getJobSettings.
@Override
public JobSettings getJobSettings(final String jobName) {
JobSettings result = new JobSettings();
JobNodePath jobNodePath = new JobNodePath(jobName);
LiteJobConfiguration liteJobConfig = LiteJobConfigurationGsonFactory.fromJson(regCenter.get(jobNodePath.getConfigNodePath()));
String jobType = liteJobConfig.getTypeConfig().getJobType().name();
buildSimpleJobSettings(jobName, result, liteJobConfig);
if (JobType.DATAFLOW.name().equals(jobType)) {
buildDataflowJobSettings(result, (DataflowJobConfiguration) liteJobConfig.getTypeConfig());
}
if (JobType.SCRIPT.name().equals(jobType)) {
buildScriptJobSettings(result, (ScriptJobConfiguration) liteJobConfig.getTypeConfig());
}
return result;
}
use of com.dangdang.ddframe.job.lite.internal.storage.JobNodePath in project elastic-job by dangdangdotcom.
the class JobStatisticsAPIImpl method getServerStatus.
private ServerInfo.ServerStatus getServerStatus(final String jobName, final String serverIp) {
JobNodePath jobNodePath = new JobNodePath(jobName);
String status = regCenter.get(jobNodePath.getServerNodePath(serverIp, "status"));
boolean disabled = regCenter.isExisted(jobNodePath.getServerNodePath(serverIp, "disabled"));
boolean paused = regCenter.isExisted(jobNodePath.getServerNodePath(serverIp, "paused"));
boolean shutdown = regCenter.isExisted(jobNodePath.getServerNodePath(serverIp, "shutdown"));
return ServerInfo.ServerStatus.getServerStatus(status, disabled, paused, shutdown);
}
use of com.dangdang.ddframe.job.lite.internal.storage.JobNodePath in project elastic-job by dangdangdotcom.
the class JobStatisticsAPIImpl method getJobStatus.
private JobBriefInfo.JobStatus getJobStatus(final String jobName) {
JobNodePath jobNodePath = new JobNodePath(jobName);
List<String> servers = regCenter.getChildrenKeys(jobNodePath.getServerNodePath());
int okCount = 0;
int crashedCount = 0;
int disabledCount = 0;
for (String each : servers) {
switch(getServerStatus(jobName, each)) {
case READY:
case RUNNING:
okCount++;
break;
case DISABLED:
case PAUSED:
disabledCount++;
break;
case CRASHED:
case SHUTDOWN:
crashedCount++;
break;
default:
break;
}
}
return JobBriefInfo.JobStatus.getJobStatus(okCount, crashedCount, disabledCount, servers.size());
}
use of com.dangdang.ddframe.job.lite.internal.storage.JobNodePath in project elastic-job by dangdangdotcom.
the class JobOperateTemplate method operate.
/**
* 作业操作.
*
* @param jobName 作业名称
* @param serverIp 作业服务器IP地址
* @param callback 作业操作的回调方法
* @return 操作失败的作业服务器IP地址列表(作业维度操作)或作业名称列表(IP维度操作)
*/
public Collection<String> operate(final Optional<String> jobName, final Optional<String> serverIp, final JobOperateCallback callback) {
Preconditions.checkArgument(jobName.isPresent() || serverIp.isPresent(), "At least indicate jobName or serverIp.");
Collection<String> result;
if (jobName.isPresent() && serverIp.isPresent()) {
boolean isSuccess = callback.doOperate(jobName.get(), serverIp.get());
if (!isSuccess) {
result = new ArrayList<>(1);
result.add(serverIp.get());
} else {
result = Collections.emptyList();
}
} else if (jobName.isPresent()) {
JobNodePath jobNodePath = new JobNodePath(jobName.get());
List<String> ipList = regCenter.getChildrenKeys(jobNodePath.getServerNodePath());
result = new ArrayList<>(ipList.size());
for (String each : ipList) {
boolean isSuccess = callback.doOperate(jobName.get(), each);
if (!isSuccess) {
result.add(each);
}
}
} else {
List<String> jobNames = regCenter.getChildrenKeys("/");
result = new ArrayList<>(jobNames.size());
for (String each : jobNames) {
boolean isSuccess = callback.doOperate(each, serverIp.get());
if (!isSuccess) {
result.add(each);
}
}
}
return result;
}
Aggregations