Skip to content

Commit

Permalink
Fix ItFramework extractJobName (apache#29876)
Browse files Browse the repository at this point in the history
Fix extractJobName not filter suffix after createJobName with randomChars introduced
  • Loading branch information
Abacn authored Dec 27, 2023
1 parent cfa4fe7 commit dda2ffa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.beam.sdk.PipelineResult;
import org.apache.beam.sdk.PipelineRunner;
import org.apache.beam.sdk.options.PipelineOptions;
Expand Down Expand Up @@ -115,7 +117,13 @@ public static String createJobName(String prefix, int randomChars) {

/** Get raw job name (without prefix) from a jobName generated by createJobName. */
public static String extractJobName(String nameWithPrefix) {
return nameWithPrefix.substring(0, nameWithPrefix.lastIndexOf("-"));
Pattern pattern = Pattern.compile("-\\d{17}"); // yyyyMMddHHmmssSSS
Matcher matcher = pattern.matcher(nameWithPrefix);
if (matcher.find()) {
return nameWithPrefix.substring(0, matcher.start());
} else {
throw new IllegalArgumentException("Unexpected job name: " + nameWithPrefix);
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ public void testCreateExtractJobName() {
String name = "create-job-name";
assertEquals(name, extractJobName(createJobName(name)));
}

@Test
public void testCreateExtractJobNameWithRandomChars() {
String name = "create-job-name";
assertEquals(name, extractJobName(createJobName(name, 8)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ protected LaunchInfo.Builder getJobInfoBuilder(LaunchConfig options, JobState st
// config pipelineName
String pipelineName = PipelineUtils.extractJobName(options.jobName());
String overrideName = null;
if (pipelineName.endsWith("write")) {
if (pipelineName.startsWith("write")) {
overrideName = System.getProperty(WRITE_PIPELINE_NAME_OVERWRITE);
} else if (pipelineName.endsWith("read")) {
} else if (pipelineName.startsWith("read")) {
overrideName = System.getProperty(READ_PIPELINE_NAME_OVERWRITE);
}
if (!Strings.isNullOrEmpty(overrideName)) {
Expand Down

0 comments on commit dda2ffa

Please sign in to comment.