Search in sources :

Example 1 with NamespaceDomainInfo

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

the class RestApiServiceImpl method getNamespace.

@Override
public NamespaceDomainInfo getNamespace(String namespace) throws SaturnJobConsoleException {
    if (namespaceInfoService.selectByNamespace(namespace) == null) {
        throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), ERR_MSG_NS_NOT_FOUND);
    }
    String zkClusterKey = namespaceZkClusterMapping4SqlService.getZkClusterKey(namespace);
    if (StringUtils.isBlank(zkClusterKey)) {
        throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), ERR_MSG_NS_NOT_FOUND);
    }
    NamespaceDomainInfo namespaceDomainInfo = new NamespaceDomainInfo();
    namespaceDomainInfo.setNamespace(namespace);
    namespaceDomainInfo.setZkCluster(zkClusterKey);
    return namespaceDomainInfo;
}
Also used : NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 2 with NamespaceDomainInfo

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

the class NamespaceManagementRestApiController method constructNamespaceDomainInfo.

private NamespaceDomainInfo constructNamespaceDomainInfo(Map<String, Object> reqParams) throws SaturnJobConsoleException {
    NamespaceDomainInfo namespaceInfo = new NamespaceDomainInfo();
    namespaceInfo.setNamespace(checkAndGetParametersValueAsString(reqParams, "namespace", true));
    namespaceInfo.setZkCluster(checkAndGetParametersValueAsString(reqParams, "zkCluster", true));
    return namespaceInfo;
}
Also used : NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo)

Example 3 with NamespaceDomainInfo

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

the class RegistryCenterServiceImpl method getNamespace.

@Override
public NamespaceDomainInfo getNamespace(String namespace) throws SaturnJobConsoleException {
    if (namespaceInfoService.selectByNamespace(namespace) == null) {
        throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), ERR_MSG_NS_NOT_FOUND);
    }
    String zkClusterKey = namespaceZkClusterMapping4SqlService.getZkClusterKey(namespace);
    if (StringUtils.isBlank(zkClusterKey)) {
        throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), ERR_MSG_NS_NOT_FOUND);
    }
    NamespaceDomainInfo namespaceDomainInfo = new NamespaceDomainInfo();
    namespaceDomainInfo.setNamespace(namespace);
    namespaceDomainInfo.setZkCluster(zkClusterKey);
    return namespaceDomainInfo;
}
Also used : NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 4 with NamespaceDomainInfo

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

the class NamespaceAndJobServiceImpl method createNamespaceAndCloneJobs.

@Override
public void createNamespaceAndCloneJobs(String srcNamespace, String namespace, String zkClusterName, String createBy) throws SaturnJobConsoleException {
    logger.info("start createNamespaceAndCloneJobs, srcNamespace: {}, namespace: {}, zkClusterName: {}", srcNamespace, namespace, zkClusterName);
    NamespaceZkClusterMapping mapping = namespaceZkClusterMappingRepository.selectByNamespace(srcNamespace);
    if (mapping == null) {
        throw new SaturnJobConsoleException("no zkCluster mapping is not found");
    }
    NamespaceDomainInfo namespaceInfo = new NamespaceDomainInfo();
    namespaceInfo.setNamespace(namespace);
    namespaceInfo.setZkCluster(zkClusterName);
    namespaceInfo.setContent("");
    try {
        registryCenterService.createNamespace(namespaceInfo);
        registryCenterService.refreshRegistryCenterForNamespace(zkClusterName, srcNamespace);
    } catch (SaturnJobConsoleHttpException e) {
        if (StringUtils.equals(String.format(ERR_MSG_NS_ALREADY_EXIST, namespace), e.getMessage())) {
            logger.warn("namespace already exists, ignore this exception and move on");
        } else {
            throw e;
        }
    }
    namespaceService.importJobsFromNamespaceToNamespace(srcNamespace, namespace, createBy);
    logger.info("finish createNamespaceAndCloneJobs, srcNamespace: {}, namespace: {}, zkClusterName: {}", srcNamespace, namespace, zkClusterName);
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 5 with NamespaceDomainInfo

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

the class NamespaceManagementRestApiController method query.

@RequestMapping(value = "/namespaces/{namespace:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> query(@PathVariable("namespace") String namespace) throws SaturnJobConsoleException {
    HttpHeaders httpHeaders = new HttpHeaders();
    try {
        checkMissingParameter("namespace", namespace);
        NamespaceDomainInfo namespaceDomainInfo = registryCenterService.getNamespace(namespace);
        return new ResponseEntity<Object>(namespaceDomainInfo, httpHeaders, 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) NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NamespaceDomainInfo (com.vip.saturn.job.console.domain.NamespaceDomainInfo)12 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)7 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)5 ResponseEntity (org.springframework.http.ResponseEntity)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 AbstractSaturnConsoleTest (com.vip.saturn.job.console.AbstractSaturnConsoleTest)3 Test (org.junit.Test)3 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)3 HttpHeaders (org.springframework.http.HttpHeaders)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Audit (com.vip.saturn.job.console.aop.annotation.Audit)1 NamespaceZkClusterMapping (com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping)1