use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class JobDimensionServiceImpl method savePreferListToDb.
private void savePreferListToDb(String jobName, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, String newJobConfigPreferList) throws SaturnJobConsoleException, SaturnJobConsoleHttpException {
String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
CurrentJobConfig oldCurrentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (oldCurrentJobConfig == null) {
log.error("找不到该作业的配置,namespace jobname is:" + namespace + " " + jobName);
return;
}
CurrentJobConfig newCurrentJobConfig = mapper.map(oldCurrentJobConfig, CurrentJobConfig.class);
newCurrentJobConfig.setPreferList(newJobConfigPreferList);
try {
currentJobConfigService.updateConfigAndSave2History(newCurrentJobConfig, oldCurrentJobConfig, null);
} catch (Exception e) {
log.error("exception is thrown during change perfer list in db", e);
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class JobOperationServiceImpl method deleteJob.
@Transactional
@Override
public void deleteJob(String jobName, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp) throws SaturnJobConsoleException {
try {
String enabledNodePath = JobNodePath.getConfigNodePath(jobName, "enabled");
long creationTime = curatorFrameworkOp.getCtime(enabledNodePath);
long timeDiff = System.currentTimeMillis() - creationTime;
if (timeDiff < SaturnConstants.JOB_CAN_BE_DELETE_TIME_LIMIT) {
String errMessage = "Job cannot be deleted until " + (SaturnConstants.JOB_CAN_BE_DELETE_TIME_LIMIT / 1000) + " seconds after job creation";
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), errMessage);
}
// 1.作业的executor全online的情况,添加toDelete节点,触发监听器动态删除节点
String toDeleteNodePath = JobNodePath.getConfigNodePath(jobName, "toDelete");
if (curatorFrameworkOp.checkExists(toDeleteNodePath)) {
curatorFrameworkOp.deleteRecursive(toDeleteNodePath);
}
curatorFrameworkOp.create(toDeleteNodePath);
for (int i = 0; i < 20; i++) {
// 2.作业的executor全offline的情况,或有几个online,几个offline的情况
String jobServerPath = JobNodePath.getServerNodePath(jobName);
if (!curatorFrameworkOp.checkExists(jobServerPath)) {
// (1)如果不存在$Job/JobName/servers节点,说明该作业没有任何executor接管,可直接删除作业节点
curatorFrameworkOp.deleteRecursive(JobNodePath.getJobNodePath(jobName));
return;
}
// (2)如果该作业servers下没有任何executor,可直接删除作业节点
List<String> executors = curatorFrameworkOp.getChildren(jobServerPath);
if (CollectionUtils.isEmpty(executors)) {
curatorFrameworkOp.deleteRecursive(JobNodePath.getJobNodePath(jobName));
return;
}
// (3)只要该作业没有一个能运行的该作业的executor在线,那么直接删除作业节点
boolean hasOnlineExecutor = false;
for (String executor : executors) {
if (curatorFrameworkOp.checkExists(ExecutorNodePath.getExecutorNodePath(executor, "ip")) && curatorFrameworkOp.checkExists(JobNodePath.getServerStatus(jobName, executor))) {
hasOnlineExecutor = true;
} else {
curatorFrameworkOp.deleteRecursive(JobNodePath.getServerNodePath(jobName, executor));
}
}
if (!hasOnlineExecutor) {
curatorFrameworkOp.deleteRecursive(JobNodePath.getJobNodePath(jobName));
}
Thread.sleep(200);
}
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Throwable t) {
log.error("exception is thrown during delete job", t);
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), t.getMessage(), t);
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class RestApiServiceImpl method getNamespace.
@Override
public NamespaceDomainInfo getNamespace(String namespace) throws SaturnJobConsoleException {
if (namespaceInfoService.selectByNamespace(namespace) == null) {
throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), ERR_MSG_NS_NOT_FOUND);
}
String zkClusterKey = namespaceZkClusterMapping4SqlService.getZkClusterKey(namespace);
if (StringUtils.isBlank(zkClusterKey)) {
throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), ERR_MSG_NS_NOT_FOUND);
}
NamespaceDomainInfo namespaceDomainInfo = new NamespaceDomainInfo();
namespaceDomainInfo.setNamespace(namespace);
namespaceDomainInfo.setZkCluster(zkClusterKey);
return namespaceDomainInfo;
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class RestApiServiceImpl method stopAtOnce.
private void stopAtOnce(String jobName, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp) throws SaturnJobConsoleHttpException {
Collection<JobServer> servers = jobDimensionService.getServers(jobName, curatorFrameworkOp);
if (CollectionUtils.isEmpty(servers)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), NO_EXECUTOR_FOUND);
}
for (JobServer server : servers) {
log.info("stop at once: job:{} executor:{}", jobName, server.getExecutorName());
jobOperationService.stopAtOnceByJobnameAndExecutorName(jobName, server.getExecutorName(), curatorFrameworkOp);
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class DashboardRefreshRestApiController method dashboardRefresh.
/**
* 根据ZK集群key,刷新该集群的dashboard信息
*
* @param zkClusterKey
* @param request
* @return
* @throws SaturnJobConsoleException
*/
@RequestMapping(value = "/dashboard/refresh", method = { RequestMethod.POST, RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> dashboardRefresh(String zkClusterKey, HttpServletRequest request) throws SaturnJobConsoleException {
try {
checkMissingParameter("zkClusterKey", zkClusterKey);
long beforeRefresh = System.currentTimeMillis();
dashboardService.refreshStatistics2DB(zkClusterKey);
long afterRefresh = System.currentTimeMillis();
long takeTime = afterRefresh - beforeRefresh;
return new ResponseEntity<Object>(takeTime, HttpStatus.OK);
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
}
Aggregations