Created
November 18, 2018 07:08
-
-
Save pdtran3k6/3b427fc1337c58a494c9b161c58c98c6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Checks all elements in {@code metadata} array to see if all | |
* the components are valid. | |
* Ex: If {@code jobIdRegex} is "^application_\\d+_\\d+$", | |
* metadata = [application_1541469337545_0031, 1542325695566, 1542325733637, user1, FAILED] -> true | |
* metadata = [application_1541469337545_0031, 1542325695566, 1542325733637, user2, succeeded] -> false | |
* because status should be upper-cased. | |
* If an element of the array doesn't satisfy its corresponding condition, the metadata is invalid. | |
* @param metadata A String array with metadata components. | |
* @param jobIdRegex Regular expression string to validate metadata. | |
* @return true if all the metadata are in proper format, false otherwise. | |
*/ | |
@VisibleForTesting | |
static boolean isValidHistFileName(String[] metadata, String jobIdRegex) { | |
if (metadata.length != 5) { | |
LOG.error("Missing fields in metadata"); | |
return false; | |
} | |
return metadata[0].matches(jobIdRegex) | |
&& metadata[1].matches("\\d+") | |
&& metadata[2].matches("\\d+") | |
&& metadata[3].matches(metadata[3].toLowerCase()) | |
&& metadata[4].equals(metadata[4].toUpperCase()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment