-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature][Core] shell batch cancel task #7612
Merged
hailin0
merged 6 commits into
apache:dev
from
zhangshenghang:feature-shell-batch-cancel
Sep 10, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9c432ee
[feature]init
zhangshenghang f21ee94
[feature]init
zhangshenghang 24a3784
[feature]init
zhangshenghang 6917918
[feature]add doc
zhangshenghang b1ad21b
add check
zhangshenghang 8e6c6e0
Merge branch 'dev' into feature-shell-batch-cancel
zhangshenghang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
...t/java/org/apache/seatunnel/core/starter/seatunnel/SeaTunnelConnectorBatchCancelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* 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.seatunnel.core.starter.seatunnel; | ||
|
||
import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import org.apache.seatunnel.common.utils.JsonUtils; | ||
import org.apache.seatunnel.e2e.common.TestResource; | ||
import org.apache.seatunnel.e2e.common.TestSuiteBase; | ||
import org.apache.seatunnel.e2e.common.container.EngineType; | ||
import org.apache.seatunnel.e2e.common.container.TestContainer; | ||
import org.apache.seatunnel.e2e.common.junit.DisabledOnContainer; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.condition.DisabledOnOs; | ||
import org.junit.jupiter.api.condition.OS; | ||
import org.testcontainers.containers.Container; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@DisabledOnContainer( | ||
value = {}, | ||
type = {EngineType.SPARK, EngineType.FLINK}, | ||
disabledReason = "Only support for seatunnel") | ||
@DisabledOnOs(OS.WINDOWS) | ||
@Slf4j | ||
public class SeaTunnelConnectorBatchCancelTest extends TestSuiteBase implements TestResource { | ||
|
||
@Override | ||
public void startUp() throws Exception {} | ||
|
||
@Override | ||
public void tearDown() throws Exception {} | ||
|
||
@TestTemplate | ||
public void task(TestContainer container) throws IOException, InterruptedException { | ||
// Start test task | ||
CompletableFuture.supplyAsync( | ||
() -> { | ||
try { | ||
container.executeJob("/batch_cancel_task_1.conf"); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return null; | ||
}); | ||
CompletableFuture.supplyAsync( | ||
() -> { | ||
try { | ||
container.executeJob("/batch_cancel_task_2.conf"); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return null; | ||
}); | ||
|
||
// Wait for the task to start | ||
Thread.sleep(15000); | ||
|
||
// Get the task id | ||
Container.ExecResult execResult = container.executeBaseCommand(new String[] {"-l"}); | ||
String regex = "(\\d+)\\s+"; | ||
Pattern pattern = Pattern.compile(regex); | ||
List<String> runningJobId = | ||
Arrays.stream(execResult.getStdout().toString().split("\n")) | ||
.filter(s -> s.contains("batch_cancel_task")) | ||
.map( | ||
s -> { | ||
Matcher matcher = pattern.matcher(s); | ||
return matcher.find() ? matcher.group(1) : null; | ||
}) | ||
.filter(jobId -> jobId != null) | ||
.collect(Collectors.toList()); | ||
Assertions.assertEquals(2, runningJobId.size()); | ||
|
||
// Verify that the status is Running | ||
for (String jobId : runningJobId) { | ||
zhangshenghang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Container.ExecResult execResult1 = | ||
container.executeBaseCommand(new String[] {"-j", jobId}); | ||
String stdout = execResult1.getStdout(); | ||
ObjectNode jsonNodes = JsonUtils.parseObject(stdout); | ||
Assertions.assertEquals(jsonNodes.get("jobStatus").asText(), "RUNNING"); | ||
} | ||
|
||
// Execute batch cancellation tasks | ||
String[] batchCancelCommand = | ||
Stream.concat(Arrays.stream(new String[] {"-can"}), runningJobId.stream()) | ||
.toArray(String[]::new); | ||
Assertions.assertEquals(0, container.executeBaseCommand(batchCancelCommand).getExitCode()); | ||
|
||
// Verify whether the cancellation is successful | ||
for (String jobId : runningJobId) { | ||
Container.ExecResult execResult1 = | ||
container.executeBaseCommand(new String[] {"-j", jobId}); | ||
String stdout = execResult1.getStdout(); | ||
ObjectNode jsonNodes = JsonUtils.parseObject(stdout); | ||
Assertions.assertEquals(jsonNodes.get("jobStatus").asText(), "CANCELED"); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...-e2e/seatunnel-core-e2e/seatunnel-starter-e2e/src/test/resources/batch_cancel_task_1.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# | ||
# 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. | ||
# | ||
###### | ||
###### This config file is a demonstration of streaming processing in seatunnel config | ||
###### | ||
|
||
env { | ||
parallelism = 1 | ||
job.mode = "STREAMING" | ||
checkpoint.interval = 3000 | ||
} | ||
|
||
source { | ||
# This is a example source plugin **only for test and demonstrate the feature source plugin** | ||
FakeSource { | ||
result_table_name = "fake" | ||
row.num = 10000 | ||
split.num = 5 | ||
split.read-interval = 3000 | ||
schema = { | ||
fields { | ||
id = "int" | ||
name = "string" | ||
age = "int" | ||
} | ||
} | ||
} | ||
} | ||
|
||
transform { | ||
} | ||
|
||
sink { | ||
Console { | ||
source_table_name = "fake" | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...-e2e/seatunnel-core-e2e/seatunnel-starter-e2e/src/test/resources/batch_cancel_task_2.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# | ||
# 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. | ||
# | ||
###### | ||
###### This config file is a demonstration of streaming processing in seatunnel config | ||
###### | ||
|
||
env { | ||
parallelism = 1 | ||
job.mode = "STREAMING" | ||
checkpoint.interval = 3000 | ||
} | ||
|
||
source { | ||
# This is a example source plugin **only for test and demonstrate the feature source plugin** | ||
FakeSource { | ||
result_table_name = "fake" | ||
row.num = 10000 | ||
split.num = 5 | ||
split.read-interval = 3000 | ||
schema = { | ||
fields { | ||
id = "int" | ||
name = "string" | ||
age = "int" | ||
} | ||
} | ||
} | ||
} | ||
|
||
transform { | ||
} | ||
|
||
sink { | ||
Console { | ||
source_table_name = "fake" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you support rest api?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hailin0 Supported in #7522