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;
}
}
}
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;
}
}
}
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();
}
}
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";
}
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";
}
}
Aggregations