@Test public void generateSnapshotName () { IntStream.range(0, 100).parallel().forEach(i -> { String identifier = randomUUID().toString(); String snapshotName = AwsRDSUtils.generateSnapshotName(identifier); assertTrue(AwsRDSUtils.isChaosSnapshot(snapshotName)); }); IntStream.range(0, 100).parallel().forEach(i -> { String identifier = randomUUID().toString() + "-"; String snapshotName = AwsRDSUtils.generateSnapshotName(identifier); assertTrue(AwsRDSUtils.isChaosSnapshot(snapshotName)); }); IntStream.range(0, 100).parallel().forEach(i -> { String identifier = randomUUID().toString() + "--" + randomUUID().toString(); String snapshotName = AwsRDSUtils.generateSnapshotName(identifier); assertTrue(AwsRDSUtils.isChaosSnapshot(snapshotName)); }); IntStream.range(0, 100).parallel().forEach(i -> { StringBuilder identifier = new StringBuilder(randomUUID().toString()); while (identifier.length() < 300) { identifier.append(randomUUID().toString()); } String snapshotName = AwsRDSUtils.generateSnapshotName(identifier.toString()); assertTrue(AwsRDSUtils.isChaosSnapshot(snapshotName)); }); }
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);  }