@Test public void rdsSnapshotNameConstraints () { IntStream.range(0, 100).parallel().mapToObj(i -> AwsRDSUtils.generateSnapshotName(randomUUID().toString())).forEach(s -> { assertTrue("Snapshot name cannot exceed 255 letters", s.length() <= 255); assertNotNull("Snapshot name cannot be null", s); assertNotEquals("Snapshot name cannot be blank", "", s); assertFalse("Cannot contain two consecutive hypens", s.contains("--")); assertFalse("Cannot end with a hypen", s.endsWith("-")); assertTrue("Unexpected name pattern (Can contain letters, numbers, and hyphens)" + s, Pattern.compile("^[A-Za-z0-9-]+$") .matcher(s) .matches()); }); }
public static String generateSnapshotName (@NotNull String identifier) { String timestamp = new DateTimeFormatterBuilder().appendInstant(3).toFormatter().format(Instant.now()); String output = String.format("ChaosSnapshot-%s-%s", identifier, timestamp).replace(":", "-").replace(",", "-") .replaceAll("\\.", "-") .replaceAll("--+", "-"); int identifierTrim = 0; while (!isValidSnapshotName(output)) { output = String.format("ChaosSnapshot-%s-%s", identifier.substring(0, identifier.length() - ++identifierTrim), timestamp).replace(":", "-").replace(",", "-") .replaceAll("\\.", "-") .replaceAll("--+", "-"); if (identifierTrim == identifier.length()) { throw new ChaosException(AwsChaosErrorCode.INVALID_SNAPSHOT_NAME); } } return output; }
AwsRDSUtils { public static String generateSnapshotName (@NotNull String identifier) { String timestamp = new DateTimeFormatterBuilder().appendInstant(3).toFormatter().format(Instant.now()); String output = String.format("ChaosSnapshot-%s-%s", identifier, timestamp).replace(":", "-").replace(",", "-") .replaceAll("\\.", "-") .replaceAll("--+", "-"); int identifierTrim = 0; while (!isValidSnapshotName(output)) { output = String.format("ChaosSnapshot-%s-%s", identifier.substring(0, identifier.length() - ++identifierTrim), timestamp).replace(":", "-").replace(",", "-") .replaceAll("\\.", "-") .replaceAll("--+", "-"); if (identifierTrim == identifier.length()) { throw new ChaosException(AwsChaosErrorCode.INVALID_SNAPSHOT_NAME); } } return output; } }
AwsRDSUtils { public static String generateSnapshotName (@NotNull String identifier) { String timestamp = new DateTimeFormatterBuilder().appendInstant(3).toFormatter().format(Instant.now()); String output = String.format("ChaosSnapshot-%s-%s", identifier, timestamp).replace(":", "-").replace(",", "-") .replaceAll("\\.", "-") .replaceAll("--+", "-"); int identifierTrim = 0; while (!isValidSnapshotName(output)) { output = String.format("ChaosSnapshot-%s-%s", identifier.substring(0, identifier.length() - ++identifierTrim), timestamp).replace(":", "-").replace(",", "-") .replaceAll("\\.", "-") .replaceAll("--+", "-"); if (identifierTrim == identifier.length()) { throw new ChaosException(AwsChaosErrorCode.INVALID_SNAPSHOT_NAME); } } return output; } private  AwsRDSUtils(); }
AwsRDSUtils { public static String generateSnapshotName (@NotNull String identifier) { String timestamp = new DateTimeFormatterBuilder().appendInstant(3).toFormatter().format(Instant.now()); String output = String.format("ChaosSnapshot-%s-%s", identifier, timestamp).replace(":", "-").replace(",", "-") .replaceAll("\\.", "-") .replaceAll("--+", "-"); int identifierTrim = 0; while (!isValidSnapshotName(output)) { output = String.format("ChaosSnapshot-%s-%s", identifier.substring(0, identifier.length() - ++identifierTrim), timestamp).replace(":", "-").replace(",", "-") .replaceAll("\\.", "-") .replaceAll("--+", "-"); if (identifierTrim == identifier.length()) { throw new ChaosException(AwsChaosErrorCode.INVALID_SNAPSHOT_NAME); } } return output; } private  AwsRDSUtils(); static String generateSnapshotName(@NotNull String identifier); static boolean isChaosSnapshot(String snapshotIdentifier); static Instant getInstantFromNameSegment(String segment); }
AwsRDSUtils { public static String generateSnapshotName (@NotNull String identifier) { String timestamp = new DateTimeFormatterBuilder().appendInstant(3).toFormatter().format(Instant.now()); String output = String.format("ChaosSnapshot-%s-%s", identifier, timestamp).replace(":", "-").replace(",", "-") .replaceAll("\\.", "-") .replaceAll("--+", "-"); int identifierTrim = 0; while (!isValidSnapshotName(output)) { output = String.format("ChaosSnapshot-%s-%s", identifier.substring(0, identifier.length() - ++identifierTrim), timestamp).replace(":", "-").replace(",", "-") .replaceAll("\\.", "-") .replaceAll("--+", "-"); if (identifierTrim == identifier.length()) { throw new ChaosException(AwsChaosErrorCode.INVALID_SNAPSHOT_NAME); } } return output; } private  AwsRDSUtils(); static String generateSnapshotName(@NotNull String identifier); static boolean isChaosSnapshot(String snapshotIdentifier); static Instant getInstantFromNameSegment(String segment);  }