csudharsanan commented on code in PR #2792:
URL: https://github.com/apache/helix/pull/2792#discussion_r1586834604


##########
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java:
##########
@@ -1085,6 +1085,139 @@ public ClusterManagementMode 
getClusterManagementMode(String clusterName) {
         : new ClusterManagementMode(status.getManagementMode(), 
status.getManagementModeStatus());
   }
 
+  private enum SetPartitionToErrorFailureReason {
+    INSTANCE_NOT_ALIVE("%s is not alive in cluster %s"),
+    INSTANCE_NON_EXISTENT("%s does not exist in cluster %s"),
+    RESOURCE_NON_EXISTENT("resource %s is not added to cluster %s"),
+    PARTITION_NON_EXISTENT("not all %s exist in cluster %s"),
+    PARTITION_ALREADY_IN_ERROR("%s is NOT found in cluster %s or is already in 
ERROR state"),
+    STATE_MODEL_NON_EXISTENT("%s is NOT found in cluster %s");
+
+    private String message;
+
+    SetPartitionToErrorFailureReason(String message) {
+      this.message = message;
+    }
+
+    public String getMessage(String resourceName, List<String> partitionNames, 
String instanceName,
+        String errorStateEntity, String clusterName) {
+      return String.format("Can't set to Error State for %s.%s on %s, because 
" + message, resourceName,
+          partitionNames, instanceName, errorStateEntity, clusterName);
+    }
+  }
+
+  @Override
+  public void setPartitionToError(String clusterName, String instanceName, 
String resourceName,
+      List<String> partitionNames) {
+    logger.info("Set partitions {} for resource {} on instance {} in cluster 
{} to ERROR state.",
+        partitionNames == null ? "NULL" : 
HelixUtil.serializeByComma(partitionNames), resourceName, instanceName,
+        clusterName);
+    HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new 
ZkBaseDataAccessor<ZNRecord>(_zkClient));
+    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
+
+    // check the instance is alive
+    LiveInstance liveInstance = 
accessor.getProperty(keyBuilder.liveInstance(instanceName));
+    if (liveInstance == null) {
+      // check if the instance exists in the cluster
+      String instanceConfigPath = 
PropertyPathBuilder.instanceConfig(clusterName, instanceName);
+      throw new HelixException(String.format(
+          (_zkClient.exists(instanceConfigPath) ? 
SetPartitionToErrorFailureReason.INSTANCE_NOT_ALIVE
+              : 
SetPartitionToErrorFailureReason.INSTANCE_NON_EXISTENT).getMessage(resourceName,
 partitionNames,
+              instanceName, instanceName, clusterName)));
+    }
+
+    // check resource exists in ideal state
+    IdealState idealState = 
accessor.getProperty(keyBuilder.idealStates(resourceName));
+      if (idealState == null) {
+      throw new 
HelixException(String.format(SetPartitionToErrorFailureReason.RESOURCE_NON_EXISTENT
+          .getMessage(resourceName, partitionNames, instanceName, 
resourceName, clusterName)));
+    }
+
+    // check partition exists in resource
+    Set<String> partitionsToBeSetToError = new HashSet<String>(partitionNames);
+    Set<String> partitions =
+        (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED) ? 
idealState.getRecord()
+            .getMapFields().keySet() : 
idealState.getRecord().getListFields().keySet();
+    if (!partitions.containsAll(partitionsToBeSetToError)) {
+      throw new 
HelixException(String.format(SetPartitionToErrorFailureReason.PARTITION_NON_EXISTENT
+          .getMessage(resourceName, partitionNames, instanceName, 
partitionNames.toString(),
+              clusterName)));
+    }
+
+  // check partition is not already in ERROR state
+  String sessionId = liveInstance.getEphemeralOwner();

Review Comment:
   updated the PR



-- 
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: reviews-unsubscr...@helix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org
For additional commands, e-mail: reviews-h...@helix.apache.org

Reply via email to