Skip to content

Commit

Permalink
chore(upgradeconfigbin): Upgrades configbin v1 to configbin v2. (#784)
Browse files Browse the repository at this point in the history
Upgrade ConfigBin v1 to ConfigBin v2.
  • Loading branch information
dwest-netflix committed Aug 19, 2020
1 parent cadcbca commit 0d1d754
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
Expand Up @@ -21,22 +21,26 @@
import retrofit.http.*;

public interface ConfigBinRemoteService {
@GET("/{ownerApp}/{configType}")
String list(@Path("ownerApp") String ownerApp, @Path("configType") String configType);

@DELETE("/{ownerApp}/{configType}/{configName}")
@GET("/browse/{ownerApp}/{configType}?pageSize=1000&showDeleted=false")
String list(
@Path("ownerApp") String ownerApp,
@Path("configType") String configType,
@Query("nextPageId") String nextPageId);

@DELETE("/{ownerApp}/{configType}/{configName}?user=kayenta&comment=spinnaker")
Response delete(
@Path("ownerApp") String ownerApp,
@Path("configType") String configType,
@Path("configName") String configName);

@GET("/payload/{ownerApp}/{configType}/{configName}")
@GET("/{ownerApp}/{configType}/{configName}")
String get(
@Path("ownerApp") String ownerApp,
@Path("configType") String configType,
@Path("configName") String configName);

@POST("/{ownerApp}/{configType}/{configName}")
@POST("/{ownerApp}/{configType}/{configName}?overwrite=true&user=kayenta&comment=spinnaker")
Response post(
@Path("ownerApp") String ownerApp,
@Path("configType") String configType,
Expand Down
Expand Up @@ -165,7 +165,7 @@ public <T> void storeObject(
credentials, CanaryConfigIndexAction.UPDATE, correlationId);
}
} catch (Exception e) {
log.error("Update failed on path {}: {}", objectKey, e);
log.error("Update failed on path {}", objectKey, e);

if (objectType == ObjectType.CANARY_CONFIG) {
canaryConfigIndex.removeFailedPendingUpdate(
Expand Down Expand Up @@ -285,27 +285,44 @@ public List<Map<String, Object>> listObjectKeys(
String ownerApp = credentials.getOwnerApp();
String configType = credentials.getConfigType();
ConfigBinRemoteService remoteService = credentials.getRemoteService();
String jsonBody =
AuthenticatedRequest.allowAnonymous(
() ->
retry.retry(
() -> remoteService.list(ownerApp, configType), MAX_RETRIES, RETRY_BACKOFF));

try {
List<String> ids =
kayentaObjectMapper.readValue(jsonBody, new TypeReference<List<String>>() {});

if (ids.size() > 0) {
return ids.stream().map(i -> metadataFor(credentials, i)).collect(Collectors.toList());
List<String> ids = new ArrayList<>();
boolean hasNext = true;
String pageId = null;
while (hasNext) {
try {
final String currentPage = pageId;
String jsonBody =
AuthenticatedRequest.allowAnonymous(
() ->
retry.retry(
() -> remoteService.list(ownerApp, configType, currentPage),
MAX_RETRIES,
RETRY_BACKOFF));
ConfigBinListResponse response =
kayentaObjectMapper.readValue(jsonBody, ConfigBinListResponse.class);
hasNext = response.hasNext;
pageId = response.nextPageId;
ids.addAll(
response.nameVersions.stream().map(nv -> nv.configName).collect(Collectors.toList()));
} catch (IOException e) {
log.error("List failed on path {}", ownerApp, e);
return Collections.emptyList();
}
} catch (IOException e) {
log.error("List failed on path {}: {}", ownerApp, e);
}

return Collections.emptyList();
return ids.stream().map(i -> metadataFor(credentials, i)).collect(Collectors.toList());
}
}

private static class ConfigBinListResponse {
public List<ConfigBinPrefixResponse> nameVersions;
public String nextPageId;
public boolean hasNext;
}

private static class ConfigBinPrefixResponse {
public String configName;
}

private Map<String, Object> metadataFor(ConfigBinNamedAccountCredentials credentials, String id) {
// TODO: (mgraff) Should factor out to a common method, or just call .load()
ConfigBinRemoteService remoteService = credentials.getRemoteService();
Expand All @@ -328,7 +345,7 @@ private Map<String, Object> metadataFor(ConfigBinNamedAccountCredentials credent
try {
config = kayentaObjectMapper.readValue(json, CanaryConfig.class);
} catch (Throwable e) {
log.error("Read failed on path {}: {}", id, e);
log.error("Read failed on path {}", id, e);
throw new IllegalStateException(e);
}
return new ImmutableMap.Builder<String, Object>()
Expand Down

0 comments on commit 0d1d754

Please sign in to comment.