use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class JobConfigInitializationServiceImpl method getRegistryCenterConfigurations.
@Override
public List<RegistryCenterConfiguration> getRegistryCenterConfigurations() throws SaturnJobConsoleException {
Collection<ZkCluster> zkClusterList = registryCenterService.getZkClusterList();
List<RegistryCenterConfiguration> rccs = new ArrayList<>();
if (zkClusterList != null) {
for (ZkCluster zkCluster : zkClusterList) {
if (zkCluster != null && !zkCluster.isOffline()) {
rccs.addAll(zkCluster.getRegCenterConfList());
}
}
}
return rccs;
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class JobConfigInitializationServiceImpl method exportToDbByZkCluster.
private void exportToDbByZkCluster(String userName, ZkCluster tmp, ExportJobConfigPageStatus exportJobConfigPageStatus) throws SaturnJobConsoleException {
log.info(" start to export db by single zkCluster, zkCluster Addr is :{}", tmp.getZkAddr());
ZkCluster zkCluster = tmp;
ArrayList<RegistryCenterConfiguration> oldRccs = zkCluster.getRegCenterConfList();
ArrayList<RegistryCenterConfiguration> rccs = new ArrayList<RegistryCenterConfiguration>(oldRccs);
for (RegistryCenterConfiguration rcc : rccs) {
List<String> jobNames = getAllUnSystemJobs(rcc.getNamespace(), zkCluster.getCuratorFramework());
for (String jobName : jobNames) {
try {
JobSettings jobSettings = getJobSettings(jobName, rcc, zkCluster.getCuratorFramework());
CurrentJobConfig current = mapper.map(jobSettings, CurrentJobConfig.class);
current.setCreateBy(userName);
current.setCreateTime(new Date());
current.setLastUpdateBy(userName);
current.setLastUpdateTime(new Date());
current.setNamespace(rcc.getNamespace());
currentJobConfigService.create(current);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e.getMessage());
}
}
exportJobConfigPageStatus.setSuccessJobNum(exportJobConfigPageStatus.getSuccessJobNum() + jobNames.size());
exportJobConfigPageStatus.setSuccessNamespaceNum(exportJobConfigPageStatus.getSuccessNamespaceNum() + 1);
temporarySharedStatusService.update(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS, gson.toJson(exportJobConfigPageStatus));
}
log.info("export db by single zkCluster successfully, zkCluster Addr is :{}", tmp.getZkAddr());
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method connect.
@Override
public RegistryCenterClient connect(final String nameAndNameSpace) {
final RegistryCenterClient registryCenterClient = new RegistryCenterClient();
registryCenterClient.setNameAndNamespace(nameAndNameSpace);
if (nameAndNameSpace == null) {
return registryCenterClient;
}
synchronized (getNnsLock(nameAndNameSpace)) {
if (!registryCenterClientMap.containsKey(nameAndNameSpace)) {
RegistryCenterConfiguration registryCenterConfiguration = findConfig(nameAndNameSpace);
if (registryCenterConfiguration == null) {
return registryCenterClient;
}
String zkAddressList = registryCenterConfiguration.getZkAddressList();
String namespace = registryCenterConfiguration.getNamespace();
String digest = registryCenterConfiguration.getDigest();
registryCenterClient.setZkAddr(zkAddressList);
CuratorFramework client = curatorRepository.connect(zkAddressList, namespace, digest);
if (client == null) {
return registryCenterClient;
}
registryCenterClient.setConnected(client.getZookeeperClient().isConnected());
registryCenterClient.setCuratorClient(client);
registryCenterClientMap.put(nameAndNameSpace, registryCenterClient);
return registryCenterClient;
} else {
RegistryCenterClient registryCenterClient2 = registryCenterClientMap.get(nameAndNameSpace);
if (registryCenterClient2 != null) {
if (registryCenterClient2.getCuratorClient() != null) {
registryCenterClient2.setConnected(registryCenterClient2.getCuratorClient().getZookeeperClient().isConnected());
} else {
registryCenterClient2.setConnected(false);
}
return registryCenterClient2;
}
return registryCenterClient;
}
}
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method connectByNamespace.
@Override
public RegistryCenterClient connectByNamespace(String namespace) {
RegistryCenterConfiguration registryCenterConfiguration = findConfigByNamespace(namespace);
if (registryCenterConfiguration == null) {
return new RegistryCenterClient();
}
String nns = registryCenterConfiguration.getNameAndNamespace();
if (nns == null) {
return new RegistryCenterClient();
}
String zkAddressList = registryCenterConfiguration.getZkAddressList();
String digest = registryCenterConfiguration.getDigest();
synchronized (getNnsLock(nns)) {
if (!registryCenterClientMap.containsKey(nns)) {
final RegistryCenterClient registryCenterClient = new RegistryCenterClient();
registryCenterClient.setNameAndNamespace(nns);
registryCenterClient.setZkAddr(zkAddressList);
CuratorFramework client = curatorRepository.connect(zkAddressList, namespace, digest);
if (client == null) {
return registryCenterClient;
}
registryCenterClient.setConnected(client.getZookeeperClient().isConnected());
registryCenterClient.setCuratorClient(client);
registryCenterClientMap.put(nns, registryCenterClient);
return registryCenterClient;
} else {
RegistryCenterClient registryCenterClient = registryCenterClientMap.get(nns);
if (registryCenterClient == null) {
registryCenterClient = new RegistryCenterClient();
registryCenterClient.setNameAndNamespace(namespace);
registryCenterClient.setZkAddr(zkAddressList);
} else {
if (registryCenterClient.getCuratorClient() != null) {
registryCenterClient.setConnected(registryCenterClient.getCuratorClient().getZookeeperClient().isConnected());
} else {
registryCenterClient.setConnected(false);
}
}
return registryCenterClient;
}
}
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method refreshNamespaceShardingListenerManagerMap.
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) {
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);
}
}
}
}
}
}
Aggregations