Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): Allow canary config id to be passed in instead of alway… #611

Merged
merged 1 commit into from
Sep 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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