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/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new 92a6758d6a [INLONG-10373][Manager] Manager client support template 
operation (#10374)
92a6758d6a is described below

commit 92a6758d6a32383f79c557252dc66d0bc24d67fb
Author: fuweng11 <[email protected]>
AuthorDate: Fri Jun 7 17:39:22 2024 +0800

    [INLONG-10373][Manager] Manager client support template operation (#10374)
---
 .../client/api/inner/client/TemplateClient.java    | 123 +++++++++++++++++++++
 .../manager/client/api/service/TemplateApi.java    |  54 +++++++++
 2 files changed, 177 insertions(+)

diff --git 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/TemplateClient.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/TemplateClient.java
new file mode 100644
index 0000000000..c696ddcc02
--- /dev/null
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/inner/client/TemplateClient.java
@@ -0,0 +1,123 @@
+/*
+ * 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 org.apache.inlong.manager.client.api.ClientConfiguration;
+import org.apache.inlong.manager.client.api.service.TemplateApi;
+import org.apache.inlong.manager.client.api.util.ClientUtils;
+import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
+import org.apache.inlong.manager.common.util.Preconditions;
+import org.apache.inlong.manager.pojo.common.PageResult;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.stream.TemplateInfo;
+import org.apache.inlong.manager.pojo.stream.TemplatePageRequest;
+import org.apache.inlong.manager.pojo.stream.TemplateRequest;
+
+import org.apache.commons.lang3.tuple.Pair;
+
+/**
+ * Client for {@link TemplateApi}.
+ */
+public class TemplateClient {
+
+    private final TemplateApi templateApi;
+
+    public TemplateClient(ClientConfiguration configuration) {
+        templateApi = 
ClientUtils.createRetrofit(configuration).create(TemplateApi.class);
+    }
+
+    /**
+     * Create an template.
+     */
+    public Integer save(TemplateRequest request) {
+        Response<Integer> response = 
ClientUtils.executeHttpCall(templateApi.save(request));
+        ClientUtils.assertRespSuccess(response);
+        return response.getData();
+    }
+
+    /**
+     * Query whether the template name exists
+     *
+     * @param templateName template name
+     * @return true: exists, false: does not exist
+     */
+    public Boolean exists(String templateName) {
+        Preconditions.expectNotBlank(templateName, 
ErrorCodeEnum.TEMPLATE_INFO_INCORRECT);
+        Response<Boolean> response = 
ClientUtils.executeHttpCall(templateApi.exists(templateName));
+        ClientUtils.assertRespSuccess(response);
+        return response.getData();
+    }
+
+    /**
+     * Template info that needs to be modified
+     *
+     * @param request template info that needs to be modified
+     * @return whether succeed
+     */
+    public Pair<Boolean, String> update(TemplateRequest request) {
+        Response<Boolean> resp = 
ClientUtils.executeHttpCall(templateApi.update(request));
+
+        if (resp.getData() != null) {
+            return Pair.of(resp.getData(), resp.getErrMsg());
+        } else {
+            return Pair.of(false, resp.getErrMsg());
+        }
+    }
+
+    /**
+     * Get template by the given template name.
+     */
+    public TemplateInfo get(String templateName) {
+        Response<TemplateInfo> response = 
ClientUtils.executeHttpCall(templateApi.get(templateName));
+
+        if (response.isSuccess()) {
+            return response.getData();
+        }
+        if (response.getErrMsg().contains("not exist")) {
+            return null;
+        }
+        throw new RuntimeException(response.getErrMsg());
+    }
+
+    /**
+     * Paging query template info list
+     *
+     * @param request query request
+     * @return template list
+     */
+    public PageResult<TemplateInfo> listByCondition(TemplatePageRequest 
request) {
+        Response<PageResult<TemplateInfo>> response = 
ClientUtils.executeHttpCall(
+                templateApi.listByCondition(request));
+        ClientUtils.assertRespSuccess(response);
+        return response.getData();
+    }
+
+    /**
+     * Delete the specified template
+     *
+     * @param templateName template name
+     * @return whether succeed
+     */
+    public boolean delete(String templateName) {
+        Preconditions.expectNotBlank(templateName, 
ErrorCodeEnum.TEMPLATE_INFO_INCORRECT);
+        Response<Boolean> response = 
ClientUtils.executeHttpCall(templateApi.delete(templateName));
+        ClientUtils.assertRespSuccess(response);
+        return response.getData();
+    }
+
+}
diff --git 
a/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/TemplateApi.java
 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/TemplateApi.java
new file mode 100644
index 0000000000..52e11d80a4
--- /dev/null
+++ 
b/inlong-manager/manager-client/src/main/java/org/apache/inlong/manager/client/api/service/TemplateApi.java
@@ -0,0 +1,54 @@
+/*
+ * 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 org.apache.inlong.manager.pojo.common.PageResult;
+import org.apache.inlong.manager.pojo.common.Response;
+import org.apache.inlong.manager.pojo.stream.TemplateInfo;
+import org.apache.inlong.manager.pojo.stream.TemplatePageRequest;
+import org.apache.inlong.manager.pojo.stream.TemplateRequest;
+
+import retrofit2.Call;
+import retrofit2.http.Body;
+import retrofit2.http.DELETE;
+import retrofit2.http.GET;
+import retrofit2.http.POST;
+import retrofit2.http.Path;
+import retrofit2.http.Query;
+
+public interface TemplateApi {
+
+    @POST("template/save")
+    Call<Response<Integer>> save(@Body TemplateRequest request);
+
+    @GET("template/exist/{templateName}")
+    Call<Response<Boolean>> exists(@Path("templateName") String templateName);
+
+    @POST("template/update")
+    Call<Response<Boolean>> update(@Body TemplateRequest request);
+
+    @GET("template/get")
+    Call<Response<TemplateInfo>> get(@Query("templateName") String 
templateName);
+
+    @POST("template/list")
+    Call<Response<PageResult<TemplateInfo>>> listByCondition(@Body 
TemplatePageRequest request);
+
+    @DELETE("template/delete")
+    Call<Response<Boolean>> delete(@Query("templateName") String templateName);
+
+}

Reply via email to