use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class JobServiceImpl method saveCronToDb.
private void saveCronToDb(String jobName, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, String newCustomContextStr, String newCron, String updatedBy) throws SaturnJobConsoleException {
String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
JobConfig4DB jobConfig4DB = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (jobConfig4DB == null) {
String errorMsg = "在DB找不到该作业的配置, namespace:" + namespace + " jobName:" + jobName;
log.error(errorMsg);
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), errorMsg);
}
JobConfig4DB newJobConfig4DB = new JobConfig4DB();
SaturnBeanUtils.copyProperties(jobConfig4DB, newJobConfig4DB);
if (newCustomContextStr != null) {
newJobConfig4DB.setCustomContext(newCustomContextStr);
}
if (newCron != null) {
newJobConfig4DB.setCron(newCron);
}
currentJobConfigService.updateNewAndSaveOld2History(newJobConfig4DB, jobConfig4DB, updatedBy);
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class RegistryCenterServiceImpl method createNamespace.
@Transactional(rollbackFor = { Exception.class })
@Override
public void createNamespace(NamespaceDomainInfo namespaceDomainInfo) throws SaturnJobConsoleException {
String namespace = namespaceDomainInfo.getNamespace();
String zkClusterKey = namespaceDomainInfo.getZkCluster();
ZkCluster currentCluster = getZkCluster(zkClusterKey);
if (currentCluster == null) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, "not found zkcluster" + zkClusterKey));
}
if (checkNamespaceExists(namespace)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(ERR_MSG_NS_ALREADY_EXIST, namespace));
}
try {
// 创建 namespaceInfo
NamespaceInfo namespaceInfo = constructNamespaceInfo(namespaceDomainInfo);
namespaceInfoService.create(namespaceInfo);
// 创建 zkcluster 和 namespaceInfo 关系
namespaceZkClusterMapping4SqlService.insert(namespace, "", zkClusterKey, NAMESPACE_CREATOR_NAME);
// refresh
notifyRefreshRegCenter();
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, e.getMessage()));
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class RegistryCenterServiceImpl method updateNamespace.
@Override
public void updateNamespace(NamespaceDomainInfo namespaceDomainInfo) throws SaturnJobConsoleException {
String namespace = namespaceDomainInfo.getNamespace();
if (!checkNamespaceExists(namespace)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), ERR_MSG_NS_NOT_FOUND);
}
try {
// 创建 namespaceInfo
NamespaceInfo namespaceInfo = constructNamespaceInfo(namespaceDomainInfo);
namespaceInfoService.update(namespaceInfo);
// refresh
notifyRefreshRegCenter();
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, e.getMessage()));
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class DashboardRefreshRestApiController method dashboardRefresh.
/**
* 根据ZK集群key,刷新该集群的dashboard信息
*/
@Audit(type = AuditType.REST)
@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();
statisticsRefreshService.refresh(zkClusterKey, true);
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);
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class JobOperationRestApiController method constructJobConfigOfUpdate.
private JobConfig constructJobConfigOfUpdate(String namespace, String jobName, Map<String, Object> reqParams) throws SaturnJobConsoleException {
checkMissingParameter("namespace", namespace);
checkMissingParameter("jobName", jobName);
if (!reqParams.containsKey("jobConfig")) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(INVALID_REQUEST_MSG, "jobConfig", "cannot be blank"));
}
JobConfig jobConfig = new JobConfig();
Map<String, Object> configParams = (Map<String, Object>) reqParams.get("jobConfig");
jobConfig.setJobName(jobName);
jobConfig.setDescription(checkAndGetParametersValueAsString(reqParams, "description", false));
jobConfig.setChannelName(checkAndGetParametersValueAsString(configParams, "channelName", false));
jobConfig.setCron(checkAndGetParametersValueAsString(configParams, "cron", false));
jobConfig.setJobParameter(checkAndGetParametersValueAsString(configParams, "jobParameter", false));
jobConfig.setLoadLevel(checkAndGetParametersValueAsInteger(configParams, "loadLevel", false));
jobConfig.setLocalMode(checkAndGetParametersValueAsBoolean(configParams, "localMode", false));
jobConfig.setPausePeriodDate(checkAndGetParametersValueAsString(configParams, "pausePeriodDate", false));
jobConfig.setPausePeriodTime(checkAndGetParametersValueAsString(configParams, "pausePeriodTime", false));
jobConfig.setPreferList(checkAndGetParametersValueAsString(configParams, "preferList", false));
jobConfig.setQueueName(checkAndGetParametersValueAsString(configParams, "queueName", false));
jobConfig.setShardingItemParameters(checkAndGetParametersValueAsString(configParams, "shardingItemParameters", false));
jobConfig.setShardingTotalCount(checkAndGetParametersValueAsInteger(configParams, "shardingTotalCount", false));
jobConfig.setTimeout4AlarmSeconds(checkAndGetParametersValueAsInteger(configParams, "timeout4AlarmSeconds", false));
jobConfig.setUseDispreferList(checkAndGetParametersValueAsBoolean(configParams, "useDispreferList", false));
jobConfig.setUseSerial(checkAndGetParametersValueAsBoolean(configParams, "useSerial", false));
jobConfig.setJobDegree(checkAndGetParametersValueAsInteger(configParams, "jobDegree", false));
jobConfig.setDependencies(checkAndGetParametersValueAsString(configParams, "dependencies", false));
jobConfig.setTimeZone(checkAndGetParametersValueAsString(configParams, "timeZone", false));
jobConfig.setTimeoutSeconds(checkAndGetParametersValueAsInteger(configParams, "timeoutSeconds", false));
jobConfig.setProcessCountIntervalSeconds(checkAndGetParametersValueAsInteger(configParams, "processCountIntervalSeconds", false));
jobConfig.setGroups(checkAndGetParametersValueAsString(configParams, "groups", false));
jobConfig.setShowNormalLog(checkAndGetParametersValueAsBoolean(configParams, "showNormalLog", false));
jobConfig.setRerun(checkAndGetParametersValueAsBoolean(configParams, "rerun", false));
jobConfig.setFailover(checkAndGetParametersValueAsBoolean(configParams, "failover", false));
jobConfig.setUpStream(checkAndGetParametersValueAsString(configParams, "upStream", false));
jobConfig.setDownStream(checkAndGetParametersValueAsString(configParams, "downStream", false));
return jobConfig;
}
Aggregations