You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2020/01/02 01:23:06 UTC
[GitHub] [servicecomb-java-chassis] liubao68 commented on a change in pull
request #1504: [SCB-1697] Add schema API in service-center-client
liubao68 commented on a change in pull request #1504: [SCB-1697] Add schema API in service-center-client
URL: https://github.com/apache/servicecomb-java-chassis/pull/1504#discussion_r362354793
##########
File path: clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterClient.java
##########
@@ -422,4 +425,90 @@ public void sendHeartBeats(HeartbeatsRequest heartbeatsRequest) {
"heartbeats fails ", e);
}
}
+
+ /**
+ * Get schemas list of service
+ *
+ * @param serviceId
+ * @return
+ * @throws OperationException
+ */
+ public List<GetSchemaResponse> getServiceSchemasList(String serviceId) {
+ try {
+ HttpResponse response = httpClient
+ .getHttpRequest("/registry/microservices/" + serviceId + "/schemas", null, null);
+ if (response.getStatusCode() == HttpStatus.SC_OK) {
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode jsonNode = mapper.readTree(response.getContent());
+ return mapper.readValue(jsonNode.get("schemas").toString(), new TypeReference<List<GetSchemaResponse>>() {
+ });
+ } else {
+ throw new OperationException(
+ "get service schemas list fails, statusCode = " + response.getStatusCode() + "; message = " + response
+ .getMessage()
+ + "; content = " + response.getContent());
+ }
+ } catch (IOException e) {
+ throw new OperationException(
+ "get service schemas list fails", e);
+ }
+ }
+
+ /**
+ * Get one schema context of service
+ *
+ * @param serviceId
+ * @param schemaId
+ * @return
+ * @throws OperationException
+ */
+ public String getServiceSchemaContext(String serviceId, String schemaId) {
+ try {
+ HttpResponse response = httpClient
+ .getHttpRequest("/registry/microservices/" + serviceId + "/schemas/" + schemaId, null, null);
+ if (response.getStatusCode() == HttpStatus.SC_OK) {
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode jsonNode = mapper.readTree(response.getContent());
+ return jsonNode.get("schema").textValue();
+ } else {
+ throw new OperationException(
+ "get service schema context fails, statusCode = " + response.getStatusCode() + "; message = " + response
+ .getMessage()
+ + "; content = " + response.getContent());
+ }
+ } catch (IOException e) {
+ throw new OperationException(
+ "get service schemas context fails", e);
+ }
+ }
+
+ /**
+ * update schema context of service
+ *
+ * @param serviceId
+ * @param schemaId
+ * @param schemaResponse
+ * @return
+ * @throws OperationException
+ */
+ public Boolean updateServiceSchemaContext(String serviceId, String schemaId, GetSchemaResponse schemaResponse) {
Review comment:
Maybe ```boolean``` is better.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services