Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Fix heron update on k8s. (#2770)
Browse files Browse the repository at this point in the history
  • Loading branch information
cckellogg authored and kramasamy committed Mar 10, 2018
1 parent 3e4a328 commit 34aa6a3
Showing 1 changed file with 17 additions and 2 deletions.
Expand Up @@ -26,6 +26,9 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.squareup.okhttp.Response;

import com.twitter.heron.api.utils.TopologyUtils;
Expand Down Expand Up @@ -146,7 +149,7 @@ boolean restart(int shardId) {
doPatch(newSpec);
} catch (ApiException ae) {
throw new TopologyRuntimeManagementException(
ae.getMessage() + "\netails\n" + ae.getResponseBody());
ae.getMessage() + "\ndetails\n" + ae.getResponseBody());
}

return containersToAdd;
Expand Down Expand Up @@ -176,9 +179,21 @@ public void removeContainers(Set<PackingPlan.ContainerPlan> containersToRemove)
}

private void doPatch(V1beta1StatefulSetSpec patchedSpec) throws ApiException {
client.patchNamespacedStatefulSet(getTopologyName(), getNamespace(), patchedSpec, null);
final String body =
String.format(JSON_PATCH_STATEFUL_SET_REPLICAS_FORMAT,
patchedSpec.getReplicas().toString());
final ArrayList<JsonObject> arr = new ArrayList<>();
arr.add(((JsonElement) deserialize(body, JsonElement.class)).getAsJsonObject());
LOG.fine("Update body: " + arr);
client.patchNamespacedStatefulSet(getTopologyName(), getNamespace(), arr, null);
}

private static final String JSON_PATCH_STATEFUL_SET_REPLICAS_FORMAT =
"{\"op\":\"replace\",\"path\":\"/spec/replicas\",\"value\":%s}";

private Object deserialize(String jsonStr, Class<?> targetClass) {
return (new Gson()).fromJson(jsonStr, targetClass);
}

V1beta1StatefulSet getStatefulSet() throws ApiException {
return client.readNamespacedStatefulSet(getTopologyName(), getNamespace(), null, null, null);
Expand Down

0 comments on commit 34aa6a3

Please sign in to comment.