You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@heron.apache.org by ni...@apache.org on 2020/08/17 06:08:10 UTC

[incubator-heron] 01/01: Updated to fix scale issue

This is an automated email from the ASF dual-hosted git repository.

nicknezis pushed a commit to branch nicknezis/scale-fix
in repository https://gitbox.apache.org/repos/asf/incubator-heron.git

commit 987d291a7e28bdf6fc81381720c363a419fbb30a
Author: Nicholas Nezis <ni...@gmail.com>
AuthorDate: Mon Aug 17 02:07:19 2020 -0400

    Updated to fix scale issue
---
 .../heron/scheduler/kubernetes/V1Controller.java      | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java b/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java
index 619562f..663ab0f 100644
--- a/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java
+++ b/heron/schedulers/src/java/org/apache/heron/scheduler/kubernetes/V1Controller.java
@@ -32,6 +32,7 @@ import java.util.logging.Logger;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
+import com.google.protobuf.Api;
 import org.apache.heron.api.utils.TopologyUtils;
 import org.apache.heron.scheduler.TopologyRuntimeManagementException;
 import org.apache.heron.scheduler.TopologySubmissionException;
@@ -159,11 +160,8 @@ public class V1Controller extends KubernetesController {
     final int currentContainerCount = statefulSet.getSpec().getReplicas();
     final int newContainerCount = currentContainerCount + containersToAdd.size();
 
-    final V1StatefulSetSpec newSpec = new V1StatefulSetSpec();
-    newSpec.setReplicas(newContainerCount);
-
     try {
-      doPatch(newSpec);
+      patchStatefulsetReplicas(newContainerCount);
     } catch (ApiException ae) {
       throw new TopologyRuntimeManagementException(
           ae.getMessage() + "\ndetails\n" + ae.getResponseBody());
@@ -184,28 +182,25 @@ public class V1Controller extends KubernetesController {
     final int currentContainerCount = statefulSet.getSpec().getReplicas();
     final int newContainerCount = currentContainerCount - containersToRemove.size();
 
-    final V1StatefulSetSpec newSpec = new V1StatefulSetSpec();
-    newSpec.setReplicas(newContainerCount);
-
     try {
-      doPatch(newSpec);
+      patchStatefulsetReplicas(newContainerCount);
     } catch (ApiException e) {
       throw new TopologyRuntimeManagementException(
           e.getMessage() + "\ndetails\n" + e.getResponseBody());
     }
   }
 
-  private void doPatch(V1StatefulSetSpec patchedSpec) throws ApiException {
+  private void patchStatefulsetReplicas(int replicas) throws ApiException {
     final String body =
-            String.format(JSON_PATCH_STATEFUL_SET_REPLICAS_FORMAT,
-                    patchedSpec.getReplicas().toString());
+            String.format(JSON_PATCH_STATEFUL_SET_INT_REPLICAS_FORMAT,
+                    replicas);
     final V1Patch patch = new V1Patch(body);
     appsClient.patchNamespacedStatefulSet(getTopologyName(),
             getNamespace(), patch, null, null, null, null);
   }
 
   private static final String JSON_PATCH_STATEFUL_SET_REPLICAS_FORMAT =
-      "{\"op\":\"replace\",\"path\":\"/spec/replicas\",\"value\":%s}";
+          "[{\"op\":\"replace\",\"path\":\"/spec/replicas\",\"value\":%d}]";
 
   V1StatefulSet getStatefulSet() throws ApiException {
     return appsClient.readNamespacedStatefulSet(getTopologyName(), getNamespace(),