caishunfeng commented on code in PR #11865:
URL: https://github.com/apache/dolphinscheduler/pull/11865#discussion_r973841518


##########
docs/docs/en/guide/task/datasync.md:
##########
@@ -0,0 +1,78 @@
+# DataSync Node
+
+## Overview
+
+[AWS DataSync](https://console.aws.amazon.com/datasync/) is an online data 
transfer service that simplifies, automates, and accelerates moving data 
between on-premises storage systems and AWS Storage services, as well as 
between AWS Storage services.
+
+DataSync can copy data to and from:
+
+- Network File System (NFS) file servers
+- Server Message Block (SMB) file servers
+- Hadoop Distributed File System (HDFS)
+- Object storage systems
+- Amazon Simple Storage Service (Amazon S3) buckets
+- Amazon EFS file systems
+- Amazon FSx for Windows File Server file systems
+- Amazon FSx for Lustre file systems
+- Amazon FSx for OpenZFS file systems
+- Amazon FSx for NetApp ONTAP file systems
+- AWS Snowcone devices
+
+The follow shows the DolphinScheduler DataSync task plugin features:
+
+- Create an AWS DataSync task and execute, continuously get the execution 
status until the task completes.
+
+## Create Task
+
+- Click `Project -> Management-Project -> Name-Workflow Definition`, and click 
the "Create Workflow" button to enter the
+  DAG editing page.
+- Drag from the toolbar <img src="../../../../img/tasks/icons/datasync.png" 
width="15"/> task node to canvas.
+
+## Task Example
+
+First, introduce some general parameters of DolphinScheduler:
+
+- **Node name**: The node name in a workflow definition is unique.

Review Comment:
   use base doc, see 
https://dolphinscheduler.apache.org/en-us/docs/dev/user_doc/guide/task/appendix.html



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-datasync/src/main/java/org/apache/dolphinscheduler/plugin/task/datasync/DatasyncTask.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.dolphinscheduler.plugin.task.datasync;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.PropertyNamingStrategy;
+import org.apache.dolphinscheduler.plugin.task.api.AbstractRemoteTask;
+import org.apache.dolphinscheduler.plugin.task.api.TaskConstants;
+import org.apache.dolphinscheduler.plugin.task.api.TaskException;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.spi.utils.JSONUtils;
+import org.apache.dolphinscheduler.spi.utils.StringUtils;
+import software.amazon.awssdk.services.datasync.model.TaskExecutionStatus;
+
+import java.util.Collections;
+import java.util.List;
+
+import static 
com.fasterxml.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT;
+import static 
com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
+import static 
com.fasterxml.jackson.databind.DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL;
+import static 
com.fasterxml.jackson.databind.MapperFeature.REQUIRE_SETTERS_FOR_GETTERS;
+
+public class DatasyncTask extends AbstractRemoteTask {
+
+    private static final ObjectMapper objectMapper =
+            new ObjectMapper().configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
+                    .configure(ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
+                    .configure(READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
+                    .configure(REQUIRE_SETTERS_FOR_GETTERS, true)
+                    .setPropertyNamingStrategy(new 
PropertyNamingStrategy.UpperCamelCaseStrategy());
+
+    private final TaskExecutionContext taskExecutionContext;
+    private DatasyncParameters parameters;
+    private DatasyncHook hook;
+
+    public DatasyncTask(TaskExecutionContext taskExecutionContext) {
+        super(taskExecutionContext);
+        this.taskExecutionContext = taskExecutionContext;
+    }
+
+    @Override
+    public List<String> getApplicationIds() throws TaskException {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public void init() {
+        logger.info("Datasync task params {}", 
taskExecutionContext.getTaskParams());
+
+        parameters = 
JSONUtils.parseObject(taskExecutionContext.getTaskParams(), 
DatasyncParameters.class);
+        initParams();
+
+        hook = new DatasyncHook();
+    }
+
+    /**
+     * init datasync hook
+     */
+    public void initParams() throws TaskException {
+        if (parameters.isJsonFormat() && 
StringUtils.isNotEmpty(parameters.getJson())) {
+            try {
+                parameters = objectMapper.readValue(parameters.getJson(), 
DatasyncParameters.class);
+                logger.info("Datasync convert task params {}", parameters);
+            } catch (JsonProcessingException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    @Override
+    public void submitApplication() throws TaskException {
+        try {
+            int exitStatusCode = runDatasyncTask();
+            setExitStatusCode(exitStatusCode);
+        } catch (Exception e) {
+            setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE);
+            throw new TaskException("datasync task error", e);
+        }
+    }
+
+    @Override
+    public void cancelApplication() throws TaskException {
+        hook.cancelDatasyncTask();
+    }
+
+
+    @Override
+    public void trackApplicationStatus() throws TaskException {
+        Boolean isFinishedSuccessfully = 
hook.doubleCheckFinishStatus(TaskExecutionStatus.SUCCESS, 
DatasyncHook.doneStatus);

Review Comment:
   Should check applicationId before check status.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-datasync/src/test/java/org/apache/dolphinscheduler/plugin/task/datasync/DatasyncTaskTest.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * 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.dolphinscheduler.plugin.task.datasync;
+
+import static org.mockito.Mockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.doReturn;
+import static org.powermock.api.mockito.PowerMockito.mock;
+import static org.powermock.api.mockito.PowerMockito.spy;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.spi.utils.JSONUtils;
+import org.apache.dolphinscheduler.spi.utils.PropertyUtils;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+
+import static org.mockito.Mockito.any;
+
+import org.powermock.api.support.membermodification.MemberModifier;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import software.amazon.awssdk.http.SdkHttpResponse;
+import software.amazon.awssdk.services.datasync.DataSyncClient;
+import 
software.amazon.awssdk.services.datasync.model.CancelTaskExecutionRequest;
+import 
software.amazon.awssdk.services.datasync.model.CancelTaskExecutionResponse;
+import software.amazon.awssdk.services.datasync.model.CreateTaskRequest;
+import software.amazon.awssdk.services.datasync.model.CreateTaskResponse;
+import 
software.amazon.awssdk.services.datasync.model.StartTaskExecutionRequest;
+import 
software.amazon.awssdk.services.datasync.model.StartTaskExecutionResponse;
+import software.amazon.awssdk.services.datasync.model.TaskExecutionStatus;
+import software.amazon.awssdk.services.datasync.model.TaskStatus;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({
+        JSONUtils.class,
+        PropertyUtils.class,
+        DatasyncHook.class
+})
+@PowerMockIgnore({"javax.*"})
+public class DatasyncTaskTest {
+
+    private static final String mockExeArn = 
"arn:aws:datasync:ap-northeast-3:523202806641:task/task-017642db08fdf6a55/execution/exec-0ac3607778dfc31f5";
+
+    private static final String mockTaskArn = 
"arn:aws:datasync:ap-northeast-3:523202806641:task/task-071ca64ff4c2f0d4a";
+
+    DatasyncHook datasyncHook;
+
+    DatasyncTask datasyncTask;
+
+    @Mock
+    DataSyncClient client;
+    MockedStatic<DatasyncHook> datasyncHookMockedStatic;
+    @Before
+    public void before() throws IllegalAccessException {
+        client = mock(DataSyncClient.class);
+        datasyncHookMockedStatic = mockStatic(DatasyncHook.class);
+        when(DatasyncHook.createClient()).thenReturn(client);
+
+        DatasyncParameters DatasyncParameters = new DatasyncParameters();
+        datasyncTask = initTask(DatasyncParameters);
+        MemberModifier.field(DatasyncTask.class, "hook").set(datasyncTask, 
datasyncHook);
+    }
+
+    @Test
+    public void testCreateTaskJson() {

Review Comment:
   What is the purpose of this test case?  If just test the value from json, it 
seems meanless.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-datasync/src/main/java/org/apache/dolphinscheduler/plugin/task/datasync/DatasyncTask.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.dolphinscheduler.plugin.task.datasync;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.PropertyNamingStrategy;
+import org.apache.dolphinscheduler.plugin.task.api.AbstractRemoteTask;
+import org.apache.dolphinscheduler.plugin.task.api.TaskConstants;
+import org.apache.dolphinscheduler.plugin.task.api.TaskException;
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.spi.utils.JSONUtils;
+import org.apache.dolphinscheduler.spi.utils.StringUtils;
+import software.amazon.awssdk.services.datasync.model.TaskExecutionStatus;
+
+import java.util.Collections;
+import java.util.List;
+
+import static 
com.fasterxml.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT;
+import static 
com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
+import static 
com.fasterxml.jackson.databind.DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL;
+import static 
com.fasterxml.jackson.databind.MapperFeature.REQUIRE_SETTERS_FOR_GETTERS;
+
+public class DatasyncTask extends AbstractRemoteTask {
+
+    private static final ObjectMapper objectMapper =
+            new ObjectMapper().configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
+                    .configure(ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
+                    .configure(READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
+                    .configure(REQUIRE_SETTERS_FOR_GETTERS, true)
+                    .setPropertyNamingStrategy(new 
PropertyNamingStrategy.UpperCamelCaseStrategy());
+
+    private final TaskExecutionContext taskExecutionContext;
+    private DatasyncParameters parameters;
+    private DatasyncHook hook;
+
+    public DatasyncTask(TaskExecutionContext taskExecutionContext) {
+        super(taskExecutionContext);
+        this.taskExecutionContext = taskExecutionContext;
+    }
+
+    @Override
+    public List<String> getApplicationIds() throws TaskException {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public void init() {
+        logger.info("Datasync task params {}", 
taskExecutionContext.getTaskParams());
+
+        parameters = 
JSONUtils.parseObject(taskExecutionContext.getTaskParams(), 
DatasyncParameters.class);
+        initParams();
+
+        hook = new DatasyncHook();
+    }
+
+    /**
+     * init datasync hook
+     */
+    public void initParams() throws TaskException {
+        if (parameters.isJsonFormat() && 
StringUtils.isNotEmpty(parameters.getJson())) {
+            try {
+                parameters = objectMapper.readValue(parameters.getJson(), 
DatasyncParameters.class);
+                logger.info("Datasync convert task params {}", parameters);
+            } catch (JsonProcessingException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    @Override
+    public void submitApplication() throws TaskException {
+        try {
+            int exitStatusCode = runDatasyncTask();
+            setExitStatusCode(exitStatusCode);
+        } catch (Exception e) {
+            setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE);
+            throw new TaskException("datasync task error", e);
+        }
+    }
+
+    @Override
+    public void cancelApplication() throws TaskException {
+        hook.cancelDatasyncTask();

Review Comment:
   Should check applicationId before.



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-datasync/pom.xml:
##########
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <parent>
+        <artifactId>dolphinscheduler-task-plugin</artifactId>
+        <groupId>org.apache.dolphinscheduler</groupId>
+        <version>dev-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>dolphinscheduler-task-datasync</artifactId>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.dolphinscheduler</groupId>
+            <artifactId>dolphinscheduler-spi</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dolphinscheduler</groupId>
+            <artifactId>dolphinscheduler-task-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <!-- 
https://mvnrepository.com/artifact/software.amazon.awssdk/datasync -->
+        <dependency>
+            <groupId>software.amazon.awssdk</groupId>
+            <artifactId>datasync</artifactId>
+            <version>2.17.260</version>
+        </dependency>
+        <!-- 
https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-datasync -->
+        <dependency>
+            <groupId>com.amazonaws</groupId>
+            <artifactId>aws-java-sdk-datasync</artifactId>
+            <version>1.12.289</version>
+        </dependency>
+        <dependency>
+            <groupId>com.amazonaws</groupId>
+            <artifactId>aws-java-sdk-dms</artifactId>
+            <version>1.12.297</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dolphinscheduler</groupId>
+            <artifactId>dolphinscheduler-common</artifactId>
+            <scope>provided</scope>

Review Comment:
   Why import the ds common module?



##########
dolphinscheduler-task-plugin/dolphinscheduler-task-datasync/src/main/java/org/apache/dolphinscheduler/plugin/task/datasync/DatasyncHook.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.dolphinscheduler.plugin.task.datasync;
+
+import lombok.Data;
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.dolphinscheduler.plugin.task.api.TaskConstants;
+import org.apache.dolphinscheduler.spi.utils.PropertyUtils;
+import org.apache.dolphinscheduler.spi.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.datasync.DataSyncClient;
+import 
software.amazon.awssdk.services.datasync.model.CancelTaskExecutionRequest;
+import 
software.amazon.awssdk.services.datasync.model.CancelTaskExecutionResponse;
+import software.amazon.awssdk.services.datasync.model.CreateTaskRequest;
+import software.amazon.awssdk.services.datasync.model.CreateTaskResponse;
+import 
software.amazon.awssdk.services.datasync.model.DescribeTaskExecutionRequest;
+import 
software.amazon.awssdk.services.datasync.model.DescribeTaskExecutionResponse;
+import software.amazon.awssdk.services.datasync.model.DescribeTaskRequest;
+import software.amazon.awssdk.services.datasync.model.DescribeTaskResponse;
+import software.amazon.awssdk.services.datasync.model.FilterRule;
+import software.amazon.awssdk.services.datasync.model.Options;
+import 
software.amazon.awssdk.services.datasync.model.StartTaskExecutionRequest;
+import 
software.amazon.awssdk.services.datasync.model.StartTaskExecutionResponse;
+import software.amazon.awssdk.services.datasync.model.TagListEntry;
+import software.amazon.awssdk.services.datasync.model.TaskExecutionStatus;
+import software.amazon.awssdk.services.datasync.model.TaskSchedule;
+import software.amazon.awssdk.services.datasync.model.TaskStatus;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static 
com.fasterxml.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT;
+import static 
com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
+import static 
com.fasterxml.jackson.databind.DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL;
+import static 
com.fasterxml.jackson.databind.MapperFeature.REQUIRE_SETTERS_FOR_GETTERS;
+
+@Data
+public class DatasyncHook {
+
+    public static TaskExecutionStatus[] doneStatus = 
{TaskExecutionStatus.ERROR, TaskExecutionStatus.SUCCESS, 
TaskExecutionStatus.UNKNOWN_TO_SDK_VERSION};
+    public static TaskStatus[] taskFinishFlags = {TaskStatus.UNAVAILABLE, 
TaskStatus.UNKNOWN_TO_SDK_VERSION};
+    protected final Logger logger = 
LoggerFactory.getLogger(String.format(TaskConstants.TASK_LOG_LOGGER_NAME_FORMAT,
 getClass()));
+    private DataSyncClient client;
+    private String taskArn;
+    private String taskExecArn;
+
+    public DatasyncHook() {
+        client = createClient();
+    }
+
+    protected static DataSyncClient createClient() {
+        final String awsAccessKeyId = 
PropertyUtils.getString(TaskConstants.AWS_ACCESS_KEY_ID);
+        final String awsSecretAccessKey = 
PropertyUtils.getString(TaskConstants.AWS_SECRET_ACCESS_KEY);
+        final String awsRegion = 
PropertyUtils.getString(TaskConstants.AWS_REGION);
+
+        final AwsBasicCredentials basicAWSCredentials = 
AwsBasicCredentials.create(awsAccessKeyId, awsSecretAccessKey);
+        final AwsCredentialsProvider awsCredentialsProvider = 
StaticCredentialsProvider.create(basicAWSCredentials);
+
+        // create a datasync client
+        return 
DataSyncClient.builder().region(Region.of(awsRegion)).credentialsProvider(awsCredentialsProvider).build();
+    }
+
+    public Boolean createDatasyncTask(DatasyncParameters parameters) {
+        logger.info("createDatasyncTask ......");
+        CreateTaskRequest.Builder builder = CreateTaskRequest.builder()
+                .name(parameters.getName())
+                .sourceLocationArn(parameters.getSourceLocationArn())
+                
.destinationLocationArn(parameters.getDestinationLocationArn());
+
+        String cloudWatchLogGroupArn = parameters.getCloudWatchLogGroupArn();
+        if (StringUtils.isNotEmpty(cloudWatchLogGroupArn)) {
+            builder.cloudWatchLogGroupArn(cloudWatchLogGroupArn);
+        }
+        castParamPropertyPackage(parameters, builder);
+
+        CreateTaskResponse task = client.createTask(builder.build());
+        if (task.sdkHttpResponse().isSuccessful()) {
+            taskArn = task.taskArn();
+        }
+        logger.info("finished createDatasyncTask ......");
+        return doubleCheckTaskStatus(TaskStatus.AVAILABLE, taskFinishFlags);
+    }
+
+    public Boolean startDatasyncTask() {
+        logger.info("startDatasyncTask ......");
+        StartTaskExecutionRequest start = 
StartTaskExecutionRequest.builder().taskArn(taskArn).build();
+        StartTaskExecutionResponse response = client.startTaskExecution(start);
+        if (response.sdkHttpResponse().isSuccessful()) {
+            taskExecArn = response.taskExecutionArn();
+        }
+        return doubleCheckExecStatus(TaskExecutionStatus.LAUNCHING, 
doneStatus);
+    }
+
+
+    public Boolean cancelDatasyncTask() {
+        logger.info("cancelTask ......");
+        CancelTaskExecutionRequest cancel = 
CancelTaskExecutionRequest.builder().taskExecutionArn(taskExecArn).build();
+        CancelTaskExecutionResponse response = 
client.cancelTaskExecution(cancel);
+        if (response.sdkHttpResponse().isSuccessful()) {
+            return true;
+        }
+        return false;
+    }
+
+    public TaskStatus queryDatasyncTaskStatus() {
+        logger.info("queryDatasyncTaskStatus ......");
+
+        DescribeTaskRequest request = 
DescribeTaskRequest.builder().taskArn(taskArn).build();
+        DescribeTaskResponse describe = client.describeTask(request);
+
+        if (describe.sdkHttpResponse().isSuccessful()) {
+            logger.info("queryDatasyncTaskStatus ......{}", 
describe.statusAsString());
+            return describe.status();
+        }
+        return null;
+    }
+
+    public TaskExecutionStatus queryDatasyncTaskExecStatus() {
+        logger.info("queryDatasyncTaskExecStatus ......");
+        DescribeTaskExecutionRequest request = 
DescribeTaskExecutionRequest.builder().taskExecutionArn(taskExecArn).build();
+        DescribeTaskExecutionResponse describe = 
client.describeTaskExecution(request);
+
+        if (describe.sdkHttpResponse().isSuccessful()) {
+            logger.info("queryDatasyncTaskExecStatus ......{}", 
describe.statusAsString());
+            return describe.status();
+        }
+        return null;
+    }
+
+    public Boolean doubleCheckTaskStatus(TaskStatus exceptStatus, TaskStatus[] 
stopStatus) {
+
+        List<TaskStatus> stopStatusSet = Arrays.asList(stopStatus);
+        int maxRetry = 5;
+        while (maxRetry > 0) {
+            TaskStatus status = queryDatasyncTaskStatus();
+
+            if (status == null) {
+                maxRetry--;
+                continue;
+            }
+
+            if (exceptStatus.equals(status)) {
+                logger.info("double check success");
+                return true;
+            } else if (stopStatusSet.contains(status)) {
+                break;
+            }
+        }
+        logger.warn("double check error");
+        return false;
+    }
+
+    public Boolean doubleCheckExecStatus(TaskExecutionStatus exceptStatus, 
TaskExecutionStatus[] stopStatus) {

Review Comment:
   What's the meaning of `double check`?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to