Search in sources :

Example 6 with NamespaceDomainInfo

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

the class NamespaceManagementRestApiController method create.

@RequestMapping(value = "/namespaces", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> create(@RequestBody Map<String, Object> reqParams, HttpServletRequest request) throws SaturnJobConsoleException {
    try {
        NamespaceDomainInfo namespaceInfo = constructNamespaceDomainInfo(reqParams);
        restApiService.createNamespace(namespaceInfo);
        // TODO: 改成异步
        registryCenterService.refreshRegCenter();
        return new ResponseEntity<>(HttpStatus.CREATED);
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : 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)

Example 7 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 = restApiService.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)

Example 8 with NamespaceDomainInfo

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

the class NamespaceManagementRestApiControllerTest method createNamespaceFailAsMissingMandetoryParameter.

@Test
public void createNamespaceFailAsMissingMandetoryParameter() throws Exception {
    NamespaceDomainInfo namespaceDomainInfo = new NamespaceDomainInfo();
    namespaceDomainInfo.setNamespace("testns");
    MvcResult result = mvc.perform(post("/rest/v1/namespaces").contentType(MediaType.APPLICATION_JSON).content(gson.toJson(namespaceDomainInfo))).andExpect(status().isBadRequest()).andReturn();
    String message = fetchErrorMessage(result);
    assertEquals("error message not equal", "Invalid request. Missing parameter: {zkCluster}", message);
    namespaceDomainInfo.setZkCluster("default");
    namespaceDomainInfo.setNamespace(null);
    result = mvc.perform(post("/rest/v1/namespaces").contentType(MediaType.APPLICATION_JSON).content(gson.toJson(namespaceDomainInfo))).andExpect(status().isBadRequest()).andReturn();
    message = fetchErrorMessage(result);
    assertEquals("error message not equal", "Invalid request. Missing parameter: {namespace}", message);
}
Also used : NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) AbstractSaturnConsoleTest(com.vip.saturn.job.console.AbstractSaturnConsoleTest)

Example 9 with NamespaceDomainInfo

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

the class NamespaceManagementRestApiControllerTest method querySuccessfully.

@Test
public void querySuccessfully() throws Exception {
    String ns = "testns";
    String zkCluster = "default";
    NamespaceDomainInfo namespaceDomainInfo = new NamespaceDomainInfo();
    namespaceDomainInfo.setNamespace(ns);
    namespaceDomainInfo.setZkCluster(zkCluster);
    given(registryCenterService.getNamespace("testns")).willReturn(namespaceDomainInfo);
    MvcResult result = mvc.perform(get("/rest/v1/namespaces/" + ns)).andExpect(status().isOk()).andReturn();
    String body = result.getResponse().getContentAsString();
    Map<String, Object> resultMap = JSONObject.parseObject(body, Map.class);
    assertEquals("zkcluster not equal", zkCluster, resultMap.get("zkCluster"));
    assertEquals("namespace not equal", ns, resultMap.get("namespace"));
}
Also used : NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) JSONObject(com.alibaba.fastjson.JSONObject) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) AbstractSaturnConsoleTest(com.vip.saturn.job.console.AbstractSaturnConsoleTest)

Example 10 with NamespaceDomainInfo

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

the class NamespaceManagementRestApiControllerTest method createNamespaceSuccessfully.

@Test
public void createNamespaceSuccessfully() throws Exception {
    NamespaceDomainInfo namespaceDomainInfo = new NamespaceDomainInfo();
    namespaceDomainInfo.setNamespace("testns");
    namespaceDomainInfo.setZkCluster("default");
    namespaceDomainInfo.setContent("");
    mvc.perform(post("/rest/v1/namespaces").contentType(MediaType.APPLICATION_JSON).content(gson.toJson(namespaceDomainInfo))).andExpect(status().isCreated());
    ArgumentCaptor<NamespaceDomainInfo> argument = ArgumentCaptor.forClass(NamespaceDomainInfo.class);
    verify(registryCenterService).createNamespace(argument.capture());
    assertTrue("namespaceDomainInfo is not equal", namespaceDomainInfo.equals(argument.getValue()));
}
Also used : NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) AbstractSaturnConsoleTest(com.vip.saturn.job.console.AbstractSaturnConsoleTest)

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