You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by he...@apache.org on 2022/08/17 06:35:58 UTC

[inlong] branch master updated: [INLONG-5559][Manager] Supplement the workflow approver API in the manager client (#5572)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4c9693228 [INLONG-5559][Manager] Supplement the workflow approver API in the manager client (#5572)
4c9693228 is described below

commit 4c9693228fa69526593d34b8fdf27acf9fcc2ac6
Author: leosanqing <st...@qq.com>
AuthorDate: Wed Aug 17 14:35:54 2022 +0800

    [INLONG-5559][Manager] Supplement the workflow approver API in the manager client (#5572)
---
 .../client/api/inner/client/ClientFactory.java     |   3 +
 .../api/inner/client/WorkflowApproverClient.java   | 128 +++++++++++++++++++++
 .../client/api/service/WorkflowApproverApi.java    |  50 ++++++++
 .../client/api/inner/ClientFactoryTest.java        |   6 +-
 .../api/inner/WorkflowApproverClientTest.java      | 102 ++++++++++++++++
 5 files changed, 288 insertions(+), 1 deletion(-)

diff --git a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java
index bd8589cb1..47a5901ae 100644
--- a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java
+++ b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/ClientFactory.java
@@ -44,6 +44,8 @@ public class ClientFactory {
 
     private final UserClient userClient;
 
+    private final WorkflowApproverClient workflowApproverClient;
+
     public ClientFactory(ClientConfiguration configuration) {
         groupClient = new InlongGroupClient(configuration);
         streamClient = new InlongStreamClient(configuration);
@@ -54,5 +56,6 @@ public class ClientFactory {
         workflowClient = new WorkflowClient(configuration);
         dataNodeClient = new DataNodeClient(configuration);
         userClient = new UserClient(configuration);
+        workflowApproverClient = new WorkflowApproverClient(configuration);
     }
 }
diff --git a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/WorkflowApproverClient.java b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/WorkflowApproverClient.java
new file mode 100644
index 000000000..2976f488a
--- /dev/null
+++ b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/WorkflowApproverClient.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.client.api.inner.client;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.github.pagehelper.PageInfo;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.inlong.manager.client.api.ClientConfiguration;
+import org.apache.inlong.manager.client.api.service.WorkflowApproverApi;
+import org.apache.inlong.manager.client.api.util.ClientUtils;
+import org.apache.inlong.manager.common.util.JsonUtils;
+import org.apache.inlong.manager.common.util.Preconditions;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.workflow.ApproverPageRequest;
+import org.apache.inlong.manager.pojo.workflow.ApproverRequest;
+import org.apache.inlong.manager.pojo.workflow.ApproverResponse;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Client for {@link org.apache.inlong.manager.client.api.service.WorkflowApproverApi}.
+ */
+@Slf4j
+public class WorkflowApproverClient {
+
+    private final WorkflowApproverApi workflowApproverApi;
+
+    public WorkflowApproverClient(ClientConfiguration configuration) {
+        workflowApproverApi = ClientUtils.createRetrofit(configuration)
+                .create(WorkflowApproverApi.class);
+    }
+
+    /**
+     * Save workflow approver
+     *
+     * @param request approver request
+     */
+    public Integer save(ApproverRequest request) {
+        Preconditions.checkNotEmpty(request.getProcessName(), "process name cannot be empty");
+        Preconditions.checkNotEmpty(request.getTaskName(), "task name cannot be empty");
+        Preconditions.checkNotEmpty(request.getApprovers(), "approvers cannot be empty");
+
+        Response<Integer> response = ClientUtils.executeHttpCall(workflowApproverApi.save(request));
+        ClientUtils.assertRespSuccess(response);
+
+        return response.getData();
+    }
+
+    /**
+     * Get workflow approver by ID
+     *
+     * @param id approver id
+     * @return approver info
+     */
+    public ApproverResponse get(Integer id) {
+        Preconditions.checkNotNull(id, "id cannot be null");
+
+        Response<ApproverResponse> response = ClientUtils.executeHttpCall(workflowApproverApi.get(id));
+        ClientUtils.assertRespSuccess(response);
+
+        return response.getData();
+    }
+
+    /**
+     * List the workflow approvers according to the query request
+     *
+     * @param request page query request
+     * @return approver list
+     */
+    public List<ApproverResponse> listByCondition(ApproverPageRequest request) {
+        Preconditions.checkNotNull(request.getPageNum(), "page num cannot be null");
+        Preconditions.checkNotNull(request.getPageSize(), "page size cannot be null");
+
+        Map<String, Object> requestMap = JsonUtils.OBJECT_MAPPER.convertValue(request,
+                new TypeReference<Map<String, Object>>() {
+                });
+        Response<PageInfo<ApproverResponse>> response = ClientUtils.executeHttpCall(
+                workflowApproverApi.listByCondition(requestMap));
+        ClientUtils.assertRespSuccess(response);
+
+        return response.getData().getList();
+    }
+
+    /**
+     * Delete workflow approver by ID
+     *
+     * @param id approver id
+     */
+    public Boolean delete(Integer id) {
+        Preconditions.checkNotNull(id, "id cannot be null");
+
+        Response<Boolean> response = ClientUtils.executeHttpCall(workflowApproverApi.delete(id));
+        ClientUtils.assertRespSuccess(response);
+
+        return response.getData();
+    }
+
+    /**
+     * Update workflow approve.
+     *
+     * @param request approver request
+     */
+    public Integer update(ApproverRequest request) {
+        Preconditions.checkNotNull(request.getId(), "id cannot be null");
+
+        Response<Integer> response = ClientUtils.executeHttpCall(workflowApproverApi.update(request));
+        ClientUtils.assertRespSuccess(response);
+
+        return response.getData();
+    }
+
+}
diff --git a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/WorkflowApproverApi.java b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/WorkflowApproverApi.java
new file mode 100644
index 000000000..8573b6a85
--- /dev/null
+++ b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/WorkflowApproverApi.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.client.api.service;
+
+import com.github.pagehelper.PageInfo;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.workflow.ApproverRequest;
+import org.apache.inlong.manager.pojo.workflow.ApproverResponse;
+import retrofit2.Call;
+import retrofit2.http.Body;
+import retrofit2.http.GET;
+import retrofit2.http.POST;
+import retrofit2.http.Path;
+import retrofit2.http.Query;
+
+import java.util.Map;
+
+public interface WorkflowApproverApi {
+
+    @POST("workflow/approver/save")
+    Call<Response<Integer>> save(@Body ApproverRequest request);
+
+    @GET("workflow/approver/get/{id}")
+    Call<Response<ApproverResponse>> get(@Path("id") Integer id);
+
+    @GET("workflow/approver/list")
+    Call<Response<PageInfo<ApproverResponse>>> listByCondition(@Query("map") Map<String, Object> map);
+
+    @POST("workflow/approver/update")
+    Call<Response<Integer>> update(@Body ApproverRequest request);
+
+    @POST("workflow/approver/delete/{id}")
+    Call<Response<Boolean>> delete(@Path("id") Integer id);
+
+}
diff --git a/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/ClientFactoryTest.java b/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/ClientFactoryTest.java
index 26910e33b..f8fdcf9ea 100644
--- a/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/ClientFactoryTest.java
+++ b/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/ClientFactoryTest.java
@@ -111,6 +111,9 @@ class ClientFactoryTest {
 
     private static final int SERVICE_PORT = 8085;
     private static WireMockServer wireMockServer;
+
+    static ClientFactory clientFactory;
+
     private static InlongGroupClient groupClient;
     private static InlongStreamClient streamClient;
     private static StreamSourceClient sourceClient;
@@ -129,7 +132,8 @@ class ClientFactoryTest {
         ClientConfiguration configuration = new ClientConfiguration();
         configuration.setAuthentication(new DefaultAuthentication("admin", "inlong"));
         InlongClientImpl inlongClient = new InlongClientImpl(serviceUrl, configuration);
-        ClientFactory clientFactory = ClientUtils.getClientFactory(inlongClient.getConfiguration());
+        clientFactory = ClientUtils.getClientFactory(inlongClient.getConfiguration());
+
         groupClient = clientFactory.getGroupClient();
         streamClient = clientFactory.getStreamClient();
         sourceClient = clientFactory.getSourceClient();
diff --git a/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/WorkflowApproverClientTest.java b/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/WorkflowApproverClientTest.java
new file mode 100644
index 000000000..5cbd3ba6b
--- /dev/null
+++ b/inlong-manager/manager-client/src/test/java/org/apache/inlong/manager/client/api/inner/WorkflowApproverClientTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.manager.client.api.inner;
+
+import com.github.pagehelper.PageInfo;
+import com.google.common.collect.Lists;
+import org.apache.inlong.manager.client.api.inner.client.WorkflowApproverClient;
+import org.apache.inlong.manager.common.util.JsonUtils;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.workflow.ApproverPageRequest;
+import org.apache.inlong.manager.pojo.workflow.ApproverRequest;
+import org.apache.inlong.manager.pojo.workflow.ApproverResponse;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
+
+/**
+ * Tests for {@link org.apache.inlong.manager.client.api.inner.client.WorkflowApproverClient}
+ */
+class WorkflowApproverClientTest extends ClientFactoryTest {
+
+    private static final WorkflowApproverClient workflowApproverClient = clientFactory.getWorkflowApproverClient();
+
+    @Test
+    void testSave() {
+        stubFor(
+                post(urlMatching("/inlong/manager/api/workflow/approver/save.*"))
+                        .willReturn(
+                                okJson(JsonUtils.toJsonString(
+                                        Response.success(11))
+                                )
+                        )
+        );
+        ApproverRequest approverRequest = ApproverRequest.builder()
+                .processName("test")
+                .approvers("user1,user2")
+                .taskName("task1")
+                .version(1)
+                .build();
+
+        Integer workflowApproverId = workflowApproverClient.save(approverRequest);
+        Assertions.assertEquals(11, workflowApproverId);
+    }
+
+    @Test
+    void testListByCondition() {
+        stubFor(
+                get(urlMatching("/inlong/manager/api/workflow/approver/list.*"))
+                        .willReturn(
+                                okJson(JsonUtils.toJsonString(
+                                        Response.success(
+                                                PageInfo.of(
+                                                        Lists.newArrayList(
+                                                                ApproverResponse.builder()
+                                                                        .taskName("task1")
+                                                                        .approvers("user1,user2")
+                                                                        .id(1)
+                                                                        .build(),
+                                                                ApproverResponse.builder()
+                                                                        .taskName("task2")
+                                                                        .approvers("user1,user2")
+                                                                        .id(2)
+                                                                        .build()
+                                                        ))))
+                                )
+                        )
+        );
+
+        ApproverPageRequest request = ApproverPageRequest.builder()
+                .processName("process1")
+                .approver("user1")
+                .build();
+        request.setPageNum(1);
+        request.setPageSize(10);
+
+        List<ApproverResponse> approverResponseList = workflowApproverClient.listByCondition(request);
+
+        Assertions.assertEquals(2, approverResponseList.size());
+    }
+}