Search in sources :

Example 1 with RegistryCenterClient

use of com.vip.saturn.job.console.domain.RegistryCenterClient 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 2 with RegistryCenterClient

use of com.vip.saturn.job.console.domain.RegistryCenterClient 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 3 with RegistryCenterClient

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

the class ReuseUtils method reuse.

public static void reuse(String namespace, RegistryCenterService registryCenterService, CuratorRepository curatorRepository, ReuseCallBackWithoutReturn callBack) throws SaturnJobConsoleException {
    try {
        RegistryCenterConfiguration registryCenterConfiguration = registryCenterService.findConfigByNamespace(namespace);
        if (registryCenterConfiguration == null) {
            throw new SaturnJobConsoleException(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);
            callBack.call(curatorFrameworkOp);
        } else {
            throw new SaturnJobConsoleException("Connect zookeeper failed");
        }
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Throwable t) {
        LOGGER.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)

Example 4 with RegistryCenterClient

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

the class HomeController method homepage.

@RequestMapping(method = RequestMethod.GET)
public String homepage(final ModelMap model, HttpServletRequest request) {
    RegistryCenterClient client = getClientInSession(request.getSession());
    if (null != client && client.isConnected()) {
        String ns = client.getCuratorClient().getNamespace();
        model.addAttribute("ns", ns);
    } else {
        model.addAttribute("ns", "");
    }
    model.put("version", version);
    return "home";
}
Also used : RegistryCenterClient(com.vip.saturn.job.console.domain.RegistryCenterClient) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with RegistryCenterClient

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

the class HomeController method overview.

@RequestMapping(value = "overview", method = RequestMethod.GET)
public String overview(String name, final ModelMap model, HttpServletRequest request, final HttpSession session) {
    model.put("containerType", SaturnEnvProperties.CONTAINER_TYPE);
    if (StringUtils.isNoneEmpty(name)) {
        setSession(registryCenterService.connect(name), session);
        RegistryCenterClient client = getClientInSession(session);
        if (null == client || !client.isConnected()) {
            return "redirect:registry_center_page";
        }
        renderShellExecutorInfos(model);
        return "overview";
    }
    RegistryCenterConfiguration config = (RegistryCenterConfiguration) request.getSession().getAttribute(SessionAttributeKeys.ACTIVATED_CONFIG_SESSION_KEY);
    if (config == null) {
        return "redirect:registry_center_page";
    } else {
        setSession(registryCenterService.connect(config.getNameAndNamespace()), session);
        renderShellExecutorInfos(model);
        return "overview";
    }
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) RegistryCenterClient(com.vip.saturn.job.console.domain.RegistryCenterClient) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RegistryCenterClient (com.vip.saturn.job.console.domain.RegistryCenterClient)10 RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)9 CuratorFramework (org.apache.curator.framework.CuratorFramework)6 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)3 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)1 Before (org.junit.Before)1