Search in sources :

Example 31 with RegistryCenterConfiguration

use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.

the class ReuseUtils method reuse.

public static <T> T reuse(String namespace, RegistryCenterService registryCenterService, CuratorRepository curatorRepository, ReuseCallBack<T> callBack) throws SaturnJobConsoleException {
    try {
        RegistryCenterConfiguration registryCenterConfiguration = registryCenterService.findConfigByNamespace(namespace);
        if (registryCenterConfiguration == null) {
            throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, String.format(NAMESPACE_NOT_EXIST_TEMPLATE, namespace));
        }
        RegistryCenterClient registryCenterClient = registryCenterService.connectByNamespace(namespace);
        if (registryCenterClient != null && registryCenterClient.isConnected()) {
            CuratorFramework curatorClient = registryCenterClient.getCuratorClient();
            CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.newCuratorFrameworkOp(curatorClient);
            ThreadLocalCuratorClient.setCuratorClient(curatorClient);
            return callBack.call(curatorFrameworkOp);
        } else {
            throw new SaturnJobConsoleException("Connect zookeeper failed");
        }
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Throwable t) {
        log.error(t.getMessage(), t);
        throw new SaturnJobConsoleException(t);
    } finally {
        ThreadLocalCuratorClient.clear();
    }
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RegistryCenterClient(com.vip.saturn.job.console.domain.RegistryCenterClient)

Aggregations

RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)31 RegistryCenterClient (com.vip.saturn.job.console.domain.RegistryCenterClient)9 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)9 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)7 CuratorFramework (org.apache.curator.framework.CuratorFramework)7 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)4 NamespaceZkClusterMapping (com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping)4 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)4 ArrayList (java.util.ArrayList)3 TreeNode (com.vip.saturn.job.console.domain.TreeNode)2 NamespaceInfo (com.vip.saturn.job.console.mybatis.entity.NamespaceInfo)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 DashboardLeaderHandler (com.vip.saturn.job.console.service.cache.DashboardLeaderHandler)1 NamespaceShardingManager (com.vip.saturn.job.sharding.NamespaceShardingManager)1 File (java.io.File)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1