Search in sources :

Example 1 with RegistryCenterConfiguration

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;
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) ArrayList(java.util.ArrayList) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster)

Example 2 with RegistryCenterConfiguration

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());
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) JobSettings(com.vip.saturn.job.console.domain.JobSettings) CurrentJobConfig(com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ArrayList(java.util.ArrayList) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) Date(java.util.Date) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 3 with RegistryCenterConfiguration

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;
        }
    }
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) CuratorFramework(org.apache.curator.framework.CuratorFramework) RegistryCenterClient(com.vip.saturn.job.console.domain.RegistryCenterClient)

Example 4 with RegistryCenterConfiguration

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;
        }
    }
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) CuratorFramework(org.apache.curator.framework.CuratorFramework) RegistryCenterClient(com.vip.saturn.job.console.domain.RegistryCenterClient)

Example 5 with RegistryCenterConfiguration

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);
                    }
                }
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) NamespaceShardingManager(com.vip.saturn.job.sharding.NamespaceShardingManager) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster)

Aggregations

RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)25 RegistryCenterClient (com.vip.saturn.job.console.domain.RegistryCenterClient)9 CuratorFramework (org.apache.curator.framework.CuratorFramework)8 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)6 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)6 NamespaceZkClusterMapping (com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping)3 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)3 TreeNode (com.vip.saturn.job.console.domain.TreeNode)2 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)2 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JobSettings (com.vip.saturn.job.console.domain.JobSettings)1 RequestResult (com.vip.saturn.job.console.domain.RequestResult)1 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)1 NamespaceInfo (com.vip.saturn.job.console.mybatis.entity.NamespaceInfo)1 ZkClusterInfo (com.vip.saturn.job.console.mybatis.entity.ZkClusterInfo)1 DashboardLeaderTreeCache (com.vip.saturn.job.console.service.helper.DashboardLeaderTreeCache)1 NamespaceShardingManager (com.vip.saturn.job.sharding.NamespaceShardingManager)1 File (java.io.File)1