StyxIdToFlyteExecNameMapper implements Function<String, String> { @Override public String apply(String styxRunId) { checkArgument( STYX_RUN_ID_REGEX.matcher(styxRunId).matches(), "Not valid styx run id:", styxRunId); var hexEncodedUuid = styxRunId.substring(STYX_ID_PREFIX.length()).replace("-", ""); var uuidBytes = BASE16_ENCODER.decode(hexEncodedUuid); var base32EncodedUuid = BASE32_ENCODER.encode(uuidBytes); var start = ALPHAS.charAt(abs(Arrays.hashCode(uuidBytes) % ALPHAS.length())); return (start + base32EncodedUuid).substring(0, FLYTE_EXEC_NAME_SIZE); }  @Override String apply(String styxRunId);  }
@Test @Parameters(method = "styxRunIds") public void shouldMapStyxRunIdsToDNS1123subdomains(String styxRunId) { var execName = mapper.apply(styxRunId); assertThat(execName, matchesRegex("^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$")); }
@Test @Parameters(method = "styxRunIds") public void shouldMapStyxRunIdsToStringStartingWithLowerAlphabeticChar(String styxRunId) { var execName = mapper.apply(styxRunId); var startChar = execName.charAt(0); assertTrue(Character.isAlphabetic(startChar)); assertTrue(Character.isLowerCase(startChar)); }
@Test @Parameters(method = "styxRunIds") public void shouldMapStyxRunIdsToStringOfRightSize(String styxRunId) { var execName = mapper.apply(styxRunId); assertThat(execName, Matchers.hasLength(20)); }
@Test @Parameters(method = "styxRunIds") public void shouldMapStyxRunIdsDeterministically(String styxRunId) { var execName1 = mapper.apply(styxRunId); var execName2 = mapper.apply(styxRunId); assertTrue(execName1.equals(execName2)); }
@Test @Parameters(method = "invalidStyxRunIds") public void shouldRejectInvalidStyxRunIds(String invalidStyxRunId) { var exception = assertThrows(IllegalArgumentException.class, () -> mapper.apply(invalidStyxRunId)); assertThat(exception.getMessage(), is("Not valid styx run id: [" + invalidStyxRunId + "]")); }