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