Search in sources :

Example 6 with ZkClusterInfo

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);
}
Also used : ZkClusterInfo(com.vip.saturn.job.console.mybatis.entity.ZkClusterInfo) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with 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();
}
Also used : SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) ZkClusterInfo(com.vip.saturn.job.console.mybatis.entity.ZkClusterInfo)

Example 8 with ZkClusterInfo

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);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) ZkClusterInfo(com.vip.saturn.job.console.mybatis.entity.ZkClusterInfo) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Audit(com.vip.saturn.job.console.aop.annotation.Audit) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with ZkClusterInfo

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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp) ZkClusterInfo(com.vip.saturn.job.console.mybatis.entity.ZkClusterInfo) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Aggregations

ZkClusterInfo (com.vip.saturn.job.console.mybatis.entity.ZkClusterInfo)9 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)5 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 Audit (com.vip.saturn.job.console.aop.annotation.Audit)1 RequestResult (com.vip.saturn.job.console.domain.RequestResult)1 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)1 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)1 CuratorFrameworkOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)1 Date (java.util.Date)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1