Skip to content

Commit

Permalink
feat(config): Allow canary config id to be passed in instead of alway…
Browse files Browse the repository at this point in the history
…s randomly generated. (#611)
  • Loading branch information
Matt Duftler committed Sep 7, 2019
1 parent 8aa41e6 commit c29e8d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class CanaryConfig {

@NotNull @Getter @Setter private String name;

@Getter private String id;

@NotNull @Getter private String description;

@NotNull @Getter private String configVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,20 @@ public CanaryConfigUpdateResponse storeCanaryConfig(
canaryConfig.setUpdatedTimestampIso(
Instant.ofEpochMilli(canaryConfig.getUpdatedTimestamp()).toString());

String canaryConfigId = UUID.randomUUID() + "";
if (StringUtils.isEmpty(canaryConfig.getId())) {
// Ensure that the canary config id is stored within the canary config itself.
canaryConfig = canaryConfig.toBuilder().id(UUID.randomUUID() + "").build();
}

String canaryConfigId = canaryConfig.getId();

// TODO(duftler): Serialize the canary config within a canary run?
validateNameAndApplicationAttributes(canaryConfig);

try {
configurationService.loadObject(
resolvedConfigurationAccountName, ObjectType.CANARY_CONFIG, canaryConfigId);

throw new IllegalArgumentException("Canary config '" + canaryConfigId + "' already exists.");
} catch (NotFoundException e) {
configurationService.storeObject(
resolvedConfigurationAccountName,
Expand All @@ -130,8 +136,6 @@ public CanaryConfigUpdateResponse storeCanaryConfig(

return CanaryConfigUpdateResponse.builder().canaryConfigId(canaryConfigId).build();
}

throw new IllegalArgumentException("Canary config '" + canaryConfigId + "' already exists.");
}

@ApiOperation(value = "Update a canary config")
Expand Down Expand Up @@ -170,6 +174,11 @@ public CanaryConfigUpdateResponse updateCanaryConfig(
throw new IllegalArgumentException("Canary config '" + canaryConfigId + "' does not exist.");
}

// Ensure that the canary config id is stored within the canary config itself.
if (StringUtils.isEmpty(canaryConfig.getId())) {
canaryConfig = canaryConfig.toBuilder().id(canaryConfigId).build();
}

configurationService.storeObject(
resolvedConfigurationAccountName,
ObjectType.CANARY_CONFIG,
Expand Down

0 comments on commit c29e8d9

Please sign in to comment.