This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new f64b992c6 [INLONG-4503][Manager] Fix the error of manager client 
executes the request (#4504)
f64b992c6 is described below

commit f64b992c67450a2ab090c821a1d0382e23887f6a
Author: leosanqing <[email protected]>
AuthorDate: Sat Jun 4 16:01:25 2022 +0800

    [INLONG-4503][Manager] Fix the error of manager client executes the request 
(#4504)
    
    Co-authored-by: healzhou <[email protected]>
---
 .../client/api/inner/InnerInlongManagerClient.java | 39 ++++++++++++++++------
 .../api/impl/InnerInlongManagerClientTest.java     | 16 +++++++++
 .../common/pojo/group/InlongGroupRequest.java      | 11 ++++--
 .../manager/common/pojo/source/StreamSource.java   |  2 +-
 4 files changed, 55 insertions(+), 13 deletions(-)

diff --git 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/InnerInlongManagerClient.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/InnerInlongManagerClient.java
index fb4c870c7..6194a19a8 100644
--- 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/InnerInlongManagerClient.java
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/InnerInlongManagerClient.java
@@ -333,7 +333,7 @@ public class InnerInlongManagerClient {
      */
     public boolean deleteSource(int id) {
         AssertUtils.isTrue(id > 0, "sourceId is illegal");
-        return this.sendDeleteForClass(
+        return this.sendDelete(
                 formatUrl(HTTP_PATH + "/source/delete/" + id),
                 null,
                 Boolean.class
@@ -395,7 +395,7 @@ public class InnerInlongManagerClient {
                 transformRequest.getInlongStreamId(),
                 transformRequest.getTransformName());
 
-        return this.sendDeleteForClass(url, null, Boolean.class);
+        return this.sendDelete(url, null, Boolean.class);
     }
 
     public Integer createSink(SinkRequest sinkRequest) {
@@ -412,7 +412,7 @@ public class InnerInlongManagerClient {
     public boolean deleteSink(int id) {
         AssertUtils.isTrue(id > 0, "sinkId is illegal");
 
-        return this.sendDeleteForClass(
+        return this.sendDelete(
                 formatUrl(HTTP_PATH + "/sink/delete/" + id),
                 null,
                 Boolean.class
@@ -533,7 +533,7 @@ public class InnerInlongManagerClient {
         String path = HTTP_PATH;
         if (async) {
             path += "/group/deleteAsync/" + groupId;
-            String finalGroupId = this.sendDeleteForClass(
+            String finalGroupId = this.sendDelete(
                     formatUrl(path),
                     null,
                     String.class
@@ -541,7 +541,7 @@ public class InnerInlongManagerClient {
             return groupId.equals(finalGroupId);
         } else {
             path += "/group/delete/" + groupId;
-            return this.sendDeleteForClass(
+            return this.sendDelete(
                     formatUrl(path),
                     null,
                     Boolean.class
@@ -584,7 +584,7 @@ public class InnerInlongManagerClient {
      * @return the result of type T
      */
     private <T> T sendGet(String url, TypeReference<Response<T>> 
typeReference) {
-        return executeRequestForResponse("GET", url, null, 
typeReference).getData();
+        return executeRequestWithCheck("GET", url, null, typeReference);
     }
 
     /**
@@ -608,7 +608,7 @@ public class InnerInlongManagerClient {
      * @return the result of type T
      */
     private <T> T sendPost(String url, String content, Class<T> clazz) {
-        return executeRequestForResponse("POST", url, content, 
clazz).getData();
+        return executeRequestWithCheck("POST", url, content, clazz);
     }
 
     /**
@@ -620,7 +620,7 @@ public class InnerInlongManagerClient {
      * @return the result of type T
      */
     private <T> T sendPost(String url, String content, 
TypeReference<Response<T>> typeReference) {
-        return executeRequestForResponse("POST", url, content, 
typeReference).getData();
+        return executeRequestWithCheck("POST", url, content, typeReference);
     }
 
     /**
@@ -655,8 +655,27 @@ public class InnerInlongManagerClient {
      * @param clazz result type
      * @return the result of type T
      */
-    private <T> T sendDeleteForClass(String url, String content, Class<T> 
clazz) {
-        return executeRequestForResponse("DELETE", url, content, 
clazz).getData();
+    private <T> T sendDelete(String url, String content, Class<T> clazz) {
+        return executeRequestWithCheck("DELETE", url, content, clazz);
+    }
+
+    /**
+     * Execute the request, and check the status for the response.
+     */
+    private <T> T executeRequestWithCheck(String method, String url, String 
content, Class<T> clazz) {
+        Response<T> response = executeRequestForResponse(method, url, content, 
clazz);
+        Preconditions.checkState(response.isSuccess(), "Inlong request failed: 
%s", response.getErrMsg());
+        return response.getData();
+    }
+
+    /**
+     * Execute the request, and check the status for the response.
+     */
+    private <T> T executeRequestWithCheck(String method, String url, String 
content,
+            TypeReference<Response<T>> typeReference) {
+        Response<T> response = executeRequestForResponse(method, url, content, 
typeReference);
+        Preconditions.checkState(response.isSuccess(), "Inlong request failed: 
%s", response.getErrMsg());
+        return response.getData();
     }
 
     private <T> Response<T> executeRequestForResponse(String method, String 
url, String content, Class<T> clazz) {
diff --git 
a/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/impl/InnerInlongManagerClientTest.java
 
b/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/impl/InnerInlongManagerClientTest.java
index 839d88555..aac139b3b 100644
--- 
a/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/impl/InnerInlongManagerClientTest.java
+++ 
b/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/impl/InnerInlongManagerClientTest.java
@@ -634,4 +634,20 @@ class InnerInlongManagerClientTest {
         Assertions.assertEquals(JsonUtils.toJsonString(listResponses), 
JsonUtils.toJsonString(sinkListResponses));
     }
 
+    @Test
+    void testListSink4AllTypeShouldThrowException() {
+        stubFor(
+                get(urlMatching("/api/inlong/manager/sink/list.*"))
+                        .willReturn(
+                                okJson(JsonUtils.toJsonString(
+                                        Response.fail("groupId should not 
empty"))
+                                )
+                        )
+        );
+
+        RuntimeException exception = 
Assertions.assertThrows(IllegalStateException.class,
+                () -> innerInlongManagerClient.listSinks("", "11"));
+
+        Assertions.assertTrue(exception.getMessage().contains("groupId should 
not empty"));
+    }
 }
diff --git 
a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/group/InlongGroupRequest.java
 
b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/group/InlongGroupRequest.java
index 79e6c9754..74b6791d2 100644
--- 
a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/group/InlongGroupRequest.java
+++ 
b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/group/InlongGroupRequest.java
@@ -28,8 +28,10 @@ import lombok.NoArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.inlong.manager.common.exceptions.BusinessException;
 import org.apache.inlong.manager.common.util.SmallTools;
+import org.hibernate.validator.constraints.Length;
 
-import javax.validation.constraints.NotNull;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.Pattern;
 import java.util.List;
 
 /**
@@ -44,6 +46,10 @@ import java.util.List;
 public class InlongGroupRequest {
 
     @ApiModelProperty(value = "Inlong group id", required = true)
+    @Length(min = 4, max = 200)
+    @Pattern(regexp = "^(?![0-9]+$)[a-z][a-z0-9_-]{1,200}$",
+            message = "inlongGroupId must starts with a lowercase letter "
+                    + "and contains only lowercase letters, digits, `-` or 
`_`")
     private String inlongGroupId;
 
     @ApiModelProperty(value = "Inlong group name", required = true)
@@ -52,7 +58,7 @@ public class InlongGroupRequest {
     @ApiModelProperty(value = "Inlong group description")
     private String description;
 
-    @NotNull
+    @NotBlank
     @ApiModelProperty(value = "MQ type, high throughput: TUBE, high 
consistency: PULSAR")
     private String mqType;
 
@@ -91,6 +97,7 @@ public class InlongGroupRequest {
     private Integer maxLength;
 
     @ApiModelProperty(value = "Name of responsible person, separated by 
commas")
+    @NotBlank
     private String inCharges;
 
     @ApiModelProperty(value = "Name of followers, separated by commas")
diff --git 
a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/source/StreamSource.java
 
b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/source/StreamSource.java
index a3ae0c089..6a53a1ada 100644
--- 
a/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/source/StreamSource.java
+++ 
b/inlong-manager/manager-common/src/main/java/org/apache/inlong/manager/common/pojo/source/StreamSource.java
@@ -41,8 +41,8 @@ import java.util.List;
 @NoArgsConstructor
 @AllArgsConstructor
 @EqualsAndHashCode(callSuper = true)
-@ApiModel("Stream source info")
 @JsonTypeInfo(use = Id.NAME, visible = true, property = "sourceType")
+@ApiModel("Stream source info")
 public abstract class StreamSource extends StreamNode {
 
     @ApiModelProperty("Source id")

Reply via email to