use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class NamespaceAndJobServiceImpl method createNamespaceAndCloneJobs.
@Override
public void createNamespaceAndCloneJobs(String srcNamespace, String namespace, String zkClusterName, String createBy) throws SaturnJobConsoleException {
logger.info("start createNamespaceAndCloneJobs, srcNamespace: {}, namespace: {}, zkClusterName: {}", srcNamespace, namespace, zkClusterName);
NamespaceZkClusterMapping mapping = namespaceZkClusterMappingRepository.selectByNamespace(srcNamespace);
if (mapping == null) {
throw new SaturnJobConsoleException("no zkCluster mapping is not found");
}
NamespaceDomainInfo namespaceInfo = new NamespaceDomainInfo();
namespaceInfo.setNamespace(namespace);
namespaceInfo.setZkCluster(zkClusterName);
namespaceInfo.setContent("");
try {
registryCenterService.createNamespace(namespaceInfo);
registryCenterService.refreshRegistryCenterForNamespace(zkClusterName, srcNamespace);
} catch (SaturnJobConsoleHttpException e) {
if (StringUtils.equals(String.format(ERR_MSG_NS_ALREADY_EXIST, namespace), e.getMessage())) {
logger.warn("namespace already exists, ignore this exception and move on");
} else {
throw e;
}
}
namespaceService.importJobsFromNamespaceToNamespace(srcNamespace, namespace, createBy);
logger.info("finish createNamespaceAndCloneJobs, srcNamespace: {}, namespace: {}, zkClusterName: {}", srcNamespace, namespace, zkClusterName);
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class NamespaceZkClusterMappingServiceImpl method migrateNamespaceToNewZk.
@Transactional(rollbackFor = { SaturnJobConsoleException.class })
@Override
public void migrateNamespaceToNewZk(String namespace, String zkClusterKeyNew, String lastUpdatedBy, boolean updateDBOnly) throws SaturnJobConsoleException {
try {
log.info("Start to migrate namespace: [{}] to zk cluster:[{}]", namespace, zkClusterKeyNew);
if (updateDBOnly) {
namespaceZkclusterMapping4SqlService.update(namespace, null, zkClusterKeyNew, lastUpdatedBy);
} else {
String zkClusterKey = namespaceZkclusterMapping4SqlService.getZkClusterKey(namespace);
if (zkClusterKey != null && zkClusterKey.equals(zkClusterKeyNew)) {
// see migrateNamespaceListToNewZk before modify
throw new SaturnJobConsoleException("The namespace(" + namespace + ") is in " + zkClusterKey);
}
ZkCluster zkCluster = registryCenterService.getZkCluster(zkClusterKeyNew);
if (zkCluster == null) {
throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " is not exists");
}
if (zkCluster.isOffline()) {
throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " zkCluster is offline");
}
String zkAddr = zkCluster.getZkAddr();
CuratorRepository.CuratorFrameworkOp targetCuratorFrameworkOpByRoot = registryCenterService.connectOnly(zkAddr, null);
if (targetCuratorFrameworkOpByRoot == null) {
throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " zkCluster is offline");
}
CuratorFramework targetCuratorFrameworkByRoot = targetCuratorFrameworkOpByRoot.getCuratorFramework();
CuratorRepository.CuratorFrameworkOp targetCuratorFrameworkOpByNamespace = registryCenterService.connectOnly(zkAddr, namespace);
CuratorFramework targetCuratorFrameworkByNamespace = targetCuratorFrameworkOpByNamespace.getCuratorFramework();
try {
String namespaceNodePath = "/" + namespace;
if (targetCuratorFrameworkByRoot.checkExists().forPath(namespaceNodePath) != null) {
targetCuratorFrameworkByRoot.delete().deletingChildrenIfNeeded().forPath(namespaceNodePath);
}
String jobsNodePath = namespaceNodePath + JobNodePath.get$JobsNodePath();
targetCuratorFrameworkByRoot.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(jobsNodePath);
persistJobsToTargetZkCluster(namespace, targetCuratorFrameworkOpByNamespace);
} finally {
targetCuratorFrameworkByRoot.close();
targetCuratorFrameworkByNamespace.close();
}
namespaceZkclusterMapping4SqlService.update(namespace, null, zkClusterKeyNew, lastUpdatedBy);
log.info("Update zkcluster mapping between ns:[{}] and zk:[{}] in DB successfully", namespace, zkClusterKeyNew);
}
} catch (SaturnJobConsoleException e) {
log.error("Fail to migrate namespace:[" + namespace + "] to zk [" + zkClusterKeyNew + "]", e);
throw e;
} catch (Exception e) {
log.error("Fail to migrate namespace:[" + namespace + "] to zk [" + zkClusterKeyNew + "] with unexpected exception", e);
throw new SaturnJobConsoleException(e.getMessage(), e);
} finally {
log.info("Finish migrate namespace:[{}] to zk zkcluster:[{}]", namespace, zkClusterKeyNew);
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class NamespaceZkClusterMappingServiceImpl method getNamespaceZkClusterMappingList.
@Override
public List<NamespaceZkClusterMappingVo> getNamespaceZkClusterMappingList() throws SaturnJobConsoleException {
List<NamespaceZkClusterMappingVo> result = new ArrayList<>();
List<NamespaceZkClusterMapping> namespaceZkClusterMappingList = namespaceZkclusterMapping4SqlService.getAllMappings();
if (namespaceZkClusterMappingList != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (NamespaceZkClusterMapping tmp : namespaceZkClusterMappingList) {
try {
if (tmp.getIsDeleted() == 0) {
NamespaceZkClusterMappingVo vo = new NamespaceZkClusterMappingVo();
vo.setNamespace(tmp.getNamespace());
vo.setZkClusterKey(tmp.getZkClusterKey());
vo.setCreateTime(sdf.format(tmp.getCreateTime()));
vo.setCreatedBy(tmp.getCreatedBy());
vo.setLastUpdateTime(sdf.format(tmp.getLastUpdateTime()));
vo.setLastUpdatedBy(tmp.getLastUpdatedBy());
result.add(vo);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
return result;
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class MarathonServiceImpl method getContainerScaleJobShardingItemParameters.
private String getContainerScaleJobShardingItemParameters(ContainerToken containerToken, String appId, Integer instances) throws SaturnJobConsoleException {
try {
String auth = Base64.encodeBase64String((containerToken.getUserName() + ":" + containerToken.getPassword()).getBytes("UTF-8"));
String url = "";
if (SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI != null && SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI.endsWith("/")) {
url = SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI + "v2/apps/" + appId + "?force=true";
} else {
url = SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI + "/v2/apps/" + appId + "?force=true";
}
return "0=curl -X PUT -H \"Content-Type:application/json\" -H \"Authorization:Basic " + auth + "\" --data '{\"instances\":" + instances + "}' " + url;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e);
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class AuthorizationManageServiceImpl method addUserRole.
@Transactional(rollbackFor = Exception.class)
@Override
public void addUserRole(UserRole userRole) throws SaturnJobConsoleException {
validateUser(userRole);
// check role is existing
String roleKey = userRole.getRoleKey();
Role role = roleRepository.selectByKey(roleKey);
if (role == null) {
throw new SaturnJobConsoleException(String.format("角色key(%s)不存在", roleKey));
}
// insert or update userRole
UserRole pre = userRoleRepository.selectWithNotFilterDeleted(userRole);
if (pre == null) {
userRoleRepository.insert(userRole);
} else {
userRoleRepository.update(pre, userRole);
}
}
Aggregations