-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve AppName.java to fix Airflow issue with inconsistent data runs
- Loading branch information
Showing
3 changed files
with
60 additions
and
17 deletions.
There are no files selected for viewing
28 changes: 27 additions & 1 deletion
28
gbif/coordinator/tasks/src/main/java/org/gbif/pipelines/common/airflow/AppName.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 |
---|---|---|
@@ -1,14 +1,40 @@ | ||
package org.gbif.pipelines.common.airflow; | ||
|
||
import java.util.Arrays; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.gbif.api.model.pipelines.StepType; | ||
import org.gbif.pipelines.common.PipelinesException; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class AppName { | ||
|
||
private static final Set<String> IGNORE_SET = Set.of("to"); | ||
|
||
/** | ||
* A lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.'. | ||
* Must start and end with an alphanumeric character and its max lentgh is 64 characters. | ||
*/ | ||
public static String get(StepType type, UUID datasetKey, int attempt) { | ||
return String.join("_", type.name(), datasetKey.toString(), String.valueOf(attempt)); | ||
String joined = | ||
String.join("-", shortenType(type), datasetKey.toString(), String.valueOf(attempt)); | ||
if (joined.length() >= 64) { | ||
throw new PipelinesException("Spark name can't be normalized, cause run_id length > 64 char"); | ||
} | ||
return joined; | ||
} | ||
|
||
private static String shortenType(StepType type) { | ||
return Arrays.stream(type.name().split("_")) | ||
.map( | ||
s -> { | ||
int l = s.length() > 4 ? 5 : s.length(); | ||
return s.toLowerCase().substring(0, l); | ||
}) | ||
.filter(s -> !IGNORE_SET.contains(s)) | ||
.collect(Collectors.joining("-")); | ||
} | ||
} |
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