junkaixue commented on code in PR #2687:
URL: https://github.com/apache/helix/pull/2687#discussion_r1379074539


##########
helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementService.java:
##########
@@ -144,6 +148,26 @@ public MaintenanceManagementService(ZKHelixDataAccessor 
dataAccessor,
     _namespace = namespace;
   }
 
+  @VisibleForTesting
+  MaintenanceManagementService(MaintenanceManagementServiceBuilder builder) {

Review Comment:
   This is not right way of using builder. Use builder we don't want them to 
create instance from constructor and it should be private constructor. 
   



##########
helix-core/src/main/java/org/apache/helix/util/InstanceValidationUtil.java:
##########
@@ -239,6 +240,23 @@ public static boolean hasErrorPartitions(HelixDataAccessor 
dataAccessor, String
     return false;
   }
 
+  /**
+   * Checks if the specified instance is marked for an ongoing instance 
operation. Currently,
+   * this method only checks for evacuation.
+   *
+   * @param dataAccessor The accessor for retrieving Helix data properties.
+   * @param instanceName An instance to be evaluated.
+   * @return
+   */
+  public static boolean isOperationSetForInstance(HelixDataAccessor 
dataAccessor,
+      String instanceName) {
+    PropertyKey.Builder propertyKeyBuilder = dataAccessor.keyBuilder();
+    InstanceConfig instanceConfig =
+        
dataAccessor.getProperty(propertyKeyBuilder.instanceConfig(instanceName));
+    return InstanceConstants.InstanceOperation.EVACUATE.name()

Review Comment:
   Why only evacuate? How about disabled.



##########
helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/InstancesAccessor.java:
##########
@@ -260,10 +271,44 @@ private Response batchGetStoppableInstances(String 
clusterId, JsonNode node, boo
         }
       }
 
+      if (node.get(InstancesProperties.stoppable_check_list.name()) != null) {
+        List<String> list = OBJECT_MAPPER.readValue(
+            
node.get(InstancesProperties.stoppable_check_list.name()).toString(),
+            OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, 
String.class));
+
+        if (ALL_STOPPABLE_CHECK_LIST.equals(list)) {
+          stoppableCheckList = HealthCheck.STOPPABLE_CHECK_LIST;
+        } else {
+          try {
+            stoppableCheckList =
+                
list.stream().map(HealthCheck::valueOf).collect(Collectors.toList());
+          } catch (IllegalArgumentException e) {
+            String message =
+                "'stoppable_check_list' has invalid check names: " + list
+                    + ". Supported checks: " + 
HealthCheck.STOPPABLE_CHECK_LIST;
+            _logger.error(message, e);
+            return badRequest(message);
+          }
+        }
+      } else {
+        // By default, if stoppable_check_list is unset, all checks are 
performed to maintain
+        // backward compatibility with existing clients.
+        stoppableCheckList = HealthCheck.STOPPABLE_CHECK_LIST;
+      }

Review Comment:
   This restructure the logic, it is not very clean. We can discuss offline.



##########
helix-core/src/main/java/org/apache/helix/util/InstanceValidationUtil.java:
##########
@@ -451,9 +474,11 @@ public static boolean 
siblingNodesActiveReplicaCheck(HelixDataAccessor dataAcces
         if (stateByInstanceMap.containsKey(instanceName)) {
           int numHealthySiblings = 0;
           for (Map.Entry<String, String> entry : 
stateByInstanceMap.entrySet()) {
-            if (!entry.getKey().equals(instanceName) && (toBeStoppedInstances 
== null
-                || !toBeStoppedInstances.contains(entry.getKey())) && 
!unhealthyStates.contains(
-                entry.getValue())) {
+            String siblingInstanceName = entry.getKey();
+            if (!siblingInstanceName.equals(instanceName) && 
(toBeStoppedInstances == null
+                || !toBeStoppedInstances.contains(siblingInstanceName))
+                && !unhealthyStates.contains(entry.getValue()) && 
!isOperationSetForInstance(
+                dataAccessor, siblingInstanceName)) {

Review Comment:
   This increase the dimension of checks. Why not just let the instances 
already in operation in toBeStoppedInstances? Semantically it makes sense as 
well.



##########
helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementServiceBuilder.java:
##########
@@ -0,0 +1,127 @@
+package org.apache.helix.rest.clusterMaintenanceService;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.helix.ConfigAccessor;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.rest.client.CustomRestClient;
+import org.apache.helix.rest.server.json.instance.StoppableCheck;
+
+
+public class MaintenanceManagementServiceBuilder {
+  private ConfigAccessor _configAccessor;
+  private boolean _skipZKRead;
+  private String _namespace;
+  private ZKHelixDataAccessor _dataAccessor;
+  private CustomRestClient _customRestClient;
+  private boolean _continueOnFailure;
+  private Set<StoppableCheck.Category> _skipHealthCheckCategories = 
Collections.emptySet();
+  private List<HealthCheck> _stoppableHealthCheckList = 
Collections.emptyList();
+
+  public ConfigAccessor getConfigAccessor() {
+    return _configAccessor;
+  }
+
+  public boolean isSkipZKRead() {
+    return _skipZKRead;
+  }
+
+  public String getNamespace() {
+    return _namespace;
+  }
+
+  public ZKHelixDataAccessor getDataAccessor() {
+    return _dataAccessor;
+  }
+
+  public CustomRestClient getCustomRestClient() {
+    return _customRestClient;
+  }
+
+  public boolean isContinueOnFailure() {
+    return _continueOnFailure;
+  }
+
+  public Set<StoppableCheck.Category> getSkipHealthCheckCategories() {
+    return _skipHealthCheckCategories;
+  }
+
+  public List<HealthCheck> getStoppableHealthCheckList() {
+    return _stoppableHealthCheckList;
+  }
+
+  public MaintenanceManagementServiceBuilder setConfigAccessor(ConfigAccessor 
configAccessor) {
+    _configAccessor = configAccessor;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setSkipZKRead(boolean skipZKRead) 
{
+    _skipZKRead = skipZKRead;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setNamespace(String namespace) {
+    _namespace = namespace;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setDataAccessor(
+      ZKHelixDataAccessor dataAccessor) {
+    _dataAccessor = dataAccessor;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setCustomRestClient(
+      CustomRestClient customRestClient) {
+    _customRestClient = customRestClient;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setContinueOnFailure(boolean 
continueOnFailure) {
+    _continueOnFailure = continueOnFailure;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setSkipHealthCheckCategories(
+      Set<StoppableCheck.Category> skipHealthCheckCategories) {
+    _skipHealthCheckCategories = skipHealthCheckCategories;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setStoppableHealthCheckList(
+      List<HealthCheck> stoppableHealthCheckList) {
+    _stoppableHealthCheckList = stoppableHealthCheckList;
+    return this;
+  }
+
+  public MaintenanceManagementService createMaintenanceManagementService() {

Review Comment:
   Java convention we split this as build() method and validate method.



##########
helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementServiceBuilder.java:
##########
@@ -0,0 +1,127 @@
+package org.apache.helix.rest.clusterMaintenanceService;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.helix.ConfigAccessor;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
+import org.apache.helix.rest.client.CustomRestClient;
+import org.apache.helix.rest.server.json.instance.StoppableCheck;
+
+
+public class MaintenanceManagementServiceBuilder {
+  private ConfigAccessor _configAccessor;
+  private boolean _skipZKRead;
+  private String _namespace;
+  private ZKHelixDataAccessor _dataAccessor;
+  private CustomRestClient _customRestClient;
+  private boolean _continueOnFailure;
+  private Set<StoppableCheck.Category> _skipHealthCheckCategories = 
Collections.emptySet();
+  private List<HealthCheck> _stoppableHealthCheckList = 
Collections.emptyList();
+
+  public ConfigAccessor getConfigAccessor() {
+    return _configAccessor;
+  }
+
+  public boolean isSkipZKRead() {
+    return _skipZKRead;
+  }
+
+  public String getNamespace() {
+    return _namespace;
+  }
+
+  public ZKHelixDataAccessor getDataAccessor() {
+    return _dataAccessor;
+  }
+
+  public CustomRestClient getCustomRestClient() {
+    return _customRestClient;
+  }
+
+  public boolean isContinueOnFailure() {
+    return _continueOnFailure;
+  }
+
+  public Set<StoppableCheck.Category> getSkipHealthCheckCategories() {
+    return _skipHealthCheckCategories;
+  }
+
+  public List<HealthCheck> getStoppableHealthCheckList() {
+    return _stoppableHealthCheckList;
+  }
+
+  public MaintenanceManagementServiceBuilder setConfigAccessor(ConfigAccessor 
configAccessor) {
+    _configAccessor = configAccessor;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setSkipZKRead(boolean skipZKRead) 
{
+    _skipZKRead = skipZKRead;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setNamespace(String namespace) {
+    _namespace = namespace;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setDataAccessor(
+      ZKHelixDataAccessor dataAccessor) {
+    _dataAccessor = dataAccessor;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setCustomRestClient(
+      CustomRestClient customRestClient) {
+    _customRestClient = customRestClient;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setContinueOnFailure(boolean 
continueOnFailure) {
+    _continueOnFailure = continueOnFailure;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setSkipHealthCheckCategories(
+      Set<StoppableCheck.Category> skipHealthCheckCategories) {
+    _skipHealthCheckCategories = skipHealthCheckCategories;
+    return this;
+  }
+
+  public MaintenanceManagementServiceBuilder setStoppableHealthCheckList(
+      List<HealthCheck> stoppableHealthCheckList) {
+    _stoppableHealthCheckList = stoppableHealthCheckList;
+    return this;
+  }
+
+  public MaintenanceManagementService createMaintenanceManagementService() {
+    if (_configAccessor == null || _namespace == null || _dataAccessor == null
+        || _customRestClient == null) {
+      throw new IllegalArgumentException(
+          "One or more of following mandatory arguments are not set: 
'_configAccessor', "
+              + "'_namespace', '_dataAccessor', '_customRestClient'.");
+    }
+    return new MaintenanceManagementService(this);
+  }
+}

Review Comment:
   Add a new line here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to