use of com.vip.saturn.job.console.mybatis.entity.ZkClusterInfo in project Saturn by vipshop.
the class ZkClusterInfoServiceImpl method createZkCluster.
@Transactional
@Override
public int createZkCluster(String clusterKey, String alias, String connectString, String description, String createdBy) {
ZkClusterInfo zkClusterInfo = new ZkClusterInfo();
Date now = new Date();
zkClusterInfo.setCreateTime(now);
zkClusterInfo.setCreatedBy(createdBy);
zkClusterInfo.setLastUpdateTime(now);
zkClusterInfo.setLastUpdatedBy(createdBy);
zkClusterInfo.setZkClusterKey(clusterKey);
zkClusterInfo.setAlias(alias);
zkClusterInfo.setConnectString(connectString);
zkClusterInfo.setDescription(description);
return zkClusterInfoRepository.insert(zkClusterInfo);
}
use of com.vip.saturn.job.console.mybatis.entity.ZkClusterInfo in project Saturn by vipshop.
the class DiscoveryRestApiController method getZkConnStr.
/**
* 返回ZK连接串
*/
private String getZkConnStr(String namespace) throws SaturnJobConsoleHttpException {
if (StringUtils.isBlank(namespace)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(MISSING_REQUEST_MSG, "namespace"));
}
String zkClusterKey = namespaceZkclusterMapping4SqlService.getZkClusterKey(namespace);
if (zkClusterKey == null) {
throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), "The namespace:[" + namespace + "] is not registered in Saturn.");
}
ZkClusterInfo zkClusterInfo = zkClusterInfoService.getByClusterKey(zkClusterKey);
if (zkClusterInfo == null) {
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "The clusterKey: [" + zkClusterKey + "] is not configured in db for " + namespace);
}
return zkClusterInfo.getConnectString();
}
use of com.vip.saturn.job.console.mybatis.entity.ZkClusterInfo in project Saturn by vipshop.
the class ZkDiscoveryRestApiController method discoverZk.
@Audit(type = AuditType.REST)
@RequestMapping(value = "/discoverZk", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> discoverZk(String namespace, HttpServletRequest request) throws SaturnJobConsoleException {
HttpHeaders headers = new HttpHeaders();
try {
checkMissingParameter("namespace", namespace);
String zkClusterKey = namespaceZkclusterMapping4SqlService.getZkClusterKey(namespace);
if (zkClusterKey == null) {
throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), "The namespace:[" + namespace + "] is not registered in Saturn.");
}
ZkClusterInfo zkClusterInfo = zkClusterInfoService.getByClusterKey(zkClusterKey);
if (zkClusterInfo == null) {
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "The clusterKey: [" + zkClusterKey + "] is not configured in db for " + namespace);
}
return new ResponseEntity<Object>(zkClusterInfo.getConnectString(), headers, HttpStatus.OK);
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
}
use of com.vip.saturn.job.console.mybatis.entity.ZkClusterInfo in project Saturn by vipshop.
the class NamespaceZkClusterMappingServiceImpl method initNamespaceZkClusterMapping.
@Override
public void initNamespaceZkClusterMapping(String createdBy) throws SaturnJobConsoleException {
try {
List<ZkClusterInfo> allZkClusterInfo = zkClusterInfoService.getAllZkClusterInfo();
if (allZkClusterInfo != null) {
for (ZkClusterInfo zkClusterInfo : allZkClusterInfo) {
String zkClusterKey = zkClusterInfo.getZkClusterKey();
String connectString = zkClusterInfo.getConnectString();
CuratorFramework curatorFramework = null;
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.connectOnly(connectString, null);
if (curatorFrameworkOp != null) {
curatorFramework = curatorFrameworkOp.getCuratorFramework();
}
if (curatorFramework != null) {
// not offline
updateNamepsaceAndZKClusterMapping(createdBy, zkClusterKey, curatorFramework);
}
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e);
}
}
Aggregations