use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class RegistryCenterServiceImpl method bindNamespaceAndZkCluster.
@Transactional(rollbackFor = { Exception.class })
@Override
public void bindNamespaceAndZkCluster(String namespace, String zkClusterKey, String updatedBy) throws SaturnJobConsoleException {
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));
}
// namespace必须要存在
if (!checkNamespaceExists(namespace)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), ERR_MSG_NS_NOT_FOUND);
}
// 判断其它集群是否有该域
String zkClusterKeyOther = namespaceZkClusterMapping4SqlService.getZkClusterKey(namespace);
if (zkClusterKeyOther != null) {
ZkCluster zkClusterOther = getZkCluster(zkClusterKeyOther);
if (zkClusterOther == null) {
throw new SaturnJobConsoleException("zk cluster 不存在:" + zkClusterKeyOther);
}
if (zkClusterOther.getZkClusterKey().equals(zkClusterKey)) {
throw new SaturnJobConsoleException("Namespace已经存在于此zk集群,不能重复添加");
} else {
throw new SaturnJobConsoleException("Namespace存在于另外的zk集群:" + zkClusterOther.getZkClusterKey() + ",不能重复添加");
}
}
try {
namespaceZkClusterMapping4SqlService.insert(namespace, "", zkClusterKey, updatedBy);
postBindNamespaceAndZkCluster(namespace, currentCluster);
// refresh
notifyRefreshRegCenter();
} catch (Exception e) {
namespaceZkClusterMapping4SqlService.remove(namespace, updatedBy);
throw new SaturnJobConsoleException(e.getMessage());
}
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class RegistryCenterServiceImpl method exportNamespaceInfo.
@Override
public File exportNamespaceInfo(List<String> namespaceList) throws SaturnJobConsoleException {
Set<String> targetNamespaceSet = null;
if (namespaceList != null) {
targetNamespaceSet = Sets.newHashSet(namespaceList);
}
List<RegistryCenterConfiguration> namespaceInfoList = Lists.newLinkedList();
Collection<ZkCluster> zkClusterList = getZkClusterList();
for (ZkCluster zkCluster : zkClusterList) {
List<RegistryCenterConfiguration> namespacesOfZkCluster = zkCluster.getRegCenterConfList();
for (RegistryCenterConfiguration ns : namespacesOfZkCluster) {
if (targetNamespaceSet == null || targetNamespaceSet.contains(ns.getNamespace())) {
namespaceInfoList.add(ns);
}
}
}
return exportNamespaceInfo2Excel(namespaceInfoList);
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class RegistryCenterServiceImpl method refreshNamespaceShardingListenerManagerMap.
/**
* 创建或者移除namespaceShardingManager.
*/
private void refreshNamespaceShardingListenerManagerMap() {
Iterator<Entry<String, ZkCluster>> iterator = zkClusterMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, ZkCluster> next = iterator.next();
ZkCluster zkCluster = next.getValue();
ArrayList<RegistryCenterConfiguration> regCenterConfList = zkCluster.getRegCenterConfList();
if (regCenterConfList == null) {
continue;
}
for (RegistryCenterConfiguration conf : regCenterConfList) {
String nns = conf.getNameAndNamespace();
if (!namespaceShardingListenerManagerMap.containsKey(nns)) {
if (isZKClusterCanBeComputed(conf.getZkClusterKey())) {
createNamespaceShardingManager(conf, nns);
}
} else {
NamespaceShardingManager namespaceShardingManager = namespaceShardingListenerManagerMap.get(nns);
if (!isZKClusterCanBeComputed(conf.getZkClusterKey())) {
namespaceShardingManager.stopWithCurator();
namespaceShardingListenerManagerMap.remove(nns);
}
}
}
}
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class RegistryCenterServiceImpl method getZkClusterInfo.
private Map<String, ZkCluster> getZkClusterInfo() {
LinkedHashMap<String, ZkCluster> newClusterMap = new LinkedHashMap<>();
List<ZkClusterInfo> allZkClusterInfoList = zkClusterInfoService.getAllZkClusterInfo();
if (allZkClusterInfoList != null) {
for (ZkClusterInfo zkClusterInfo : allZkClusterInfoList) {
ZkCluster zkCluster = new ZkCluster();
zkCluster.setZkClusterKey(zkClusterInfo.getZkClusterKey());
zkCluster.setZkAlias(zkClusterInfo.getAlias());
zkCluster.setZkAddr(zkClusterInfo.getConnectString());
zkCluster.setDescription(zkClusterInfo.getDescription());
newClusterMap.put(zkClusterInfo.getZkClusterKey(), zkCluster);
}
}
return newClusterMap;
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class RegistryCenterServiceImpl method connectToZkClusterIfPossible.
private void connectToZkClusterIfPossible(Map<String, ZkCluster> newClusterMap) {
Iterator<Entry<String, ZkCluster>> iterator = newClusterMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, ZkCluster> next = iterator.next();
ZkCluster zkCluster = next.getValue();
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = zkCluster.getCuratorFrameworkOp();
if (curatorFrameworkOp == null) {
createNewConnect(zkCluster);
if (!zkCluster.isOffline()) {
updateExecutorConfigToZkIfNecessary(zkCluster);
}
}
}
}
Aggregations