jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r635515263
##########
File path:
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,72 @@ public boolean isInMaintenanceMode(String clusterName) {
.exists(keyBuilder.maintenance().getPath(), AccessOption.PERSISTENT);
}
+ @Override
+ public void setClusterManagementMode(ClusterManagementModeRequest request) {
+ ClusterManagementMode.Type mode = request.getMode();
+ String clusterName = request.getClusterName();
+ String reason = request.getReason();
+
+ // TODO: support other modes
+ switch (mode) {
+ case CLUSTER_PAUSE:
+ enableClusterPauseMode(clusterName, request.isCancelPendingST(),
reason);
+ break;
+ case NORMAL:
+ // If from other modes, should check what mode it is in and call the
api accordingly.
+ // If we put all mode config in one znode, one generic method is good
enough.
+ disableClusterPauseMode(clusterName);
+ break;
+ default:
+ throw new IllegalArgumentException("ClusterManagementMode " + mode + "
not supported");
Review comment:
nit "is not supported"?
##########
File path: helix-core/src/main/java/org/apache/helix/HelixAdmin.java
##########
@@ -37,6 +37,8 @@
import org.apache.helix.model.MaintenanceSignal;
import org.apache.helix.model.ResourceConfig;
import org.apache.helix.model.StateModelDefinition;
+import org.apache.helix.api.status.ClusterManagementMode;
+import org.apache.helix.model.management.ClusterManagementModeRequest;
Review comment:
ClusterManagementModeRequest should go to org.apache.helix.api.status
too.
Or maybe we should make both of them in org.apache.helix.**model**.status?
@junkaixue any opinion about the allocation of these 2 classes?
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -130,6 +140,22 @@ public void setHelixVersion(String helixVersion) {
_record.setSimpleField(LiveInstanceProperty.HELIX_VERSION.toString(),
helixVersion);
}
+ /**
+ * Gets the live instance's status.
+ */
+ public String getStatus() {
Review comment:
Return LiveInstanceStatus object?
##########
File path:
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,72 @@ public boolean isInMaintenanceMode(String clusterName) {
.exists(keyBuilder.maintenance().getPath(), AccessOption.PERSISTENT);
}
+ @Override
+ public void setClusterManagementMode(ClusterManagementModeRequest request) {
+ ClusterManagementMode.Type mode = request.getMode();
+ String clusterName = request.getClusterName();
+ String reason = request.getReason();
+
+ // TODO: support other modes
+ switch (mode) {
+ case CLUSTER_PAUSE:
+ enableClusterPauseMode(clusterName, request.isCancelPendingST(),
reason);
+ break;
+ case NORMAL:
+ // If from other modes, should check what mode it is in and call the
api accordingly.
+ // If we put all mode config in one znode, one generic method is good
enough.
+ disableClusterPauseMode(clusterName);
+ break;
+ default:
+ throw new IllegalArgumentException("ClusterManagementMode " + mode + "
not supported");
+ }
+ }
+
+ private void enableClusterPauseMode(String clusterName, boolean
cancelPendingST, String reason) {
+ String hostname = NetworkUtil.getLocalhostName();
+ logger.info(
+ "Enable cluster pause mode for cluster: {}. CancelPendingST: {}.
Reason: {}. From Host: {}",
+ clusterName, cancelPendingST, reason, hostname);
+
+ BaseDataAccessor<ZNRecord> baseDataAccessor = new
ZkBaseDataAccessor<>(_zkClient);
+ HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName,
baseDataAccessor);
+
+ if (baseDataAccessor.exists(accessor.keyBuilder().pause().getPath(),
AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " pause signal already
exits");
Review comment:
nit, but please double-check all the spelling. exits -> exists.
##########
File path:
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,72 @@ public boolean isInMaintenanceMode(String clusterName) {
.exists(keyBuilder.maintenance().getPath(), AccessOption.PERSISTENT);
}
+ @Override
+ public void setClusterManagementMode(ClusterManagementModeRequest request) {
+ ClusterManagementMode.Type mode = request.getMode();
+ String clusterName = request.getClusterName();
+ String reason = request.getReason();
+
+ // TODO: support other modes
+ switch (mode) {
+ case CLUSTER_PAUSE:
+ enableClusterPauseMode(clusterName, request.isCancelPendingST(),
reason);
+ break;
+ case NORMAL:
+ // If from other modes, should check what mode it is in and call the
api accordingly.
+ // If we put all mode config in one znode, one generic method is good
enough.
+ disableClusterPauseMode(clusterName);
+ break;
+ default:
+ throw new IllegalArgumentException("ClusterManagementMode " + mode + "
not supported");
+ }
+ }
+
+ private void enableClusterPauseMode(String clusterName, boolean
cancelPendingST, String reason) {
+ String hostname = NetworkUtil.getLocalhostName();
+ logger.info(
+ "Enable cluster pause mode for cluster: {}. CancelPendingST: {}.
Reason: {}. From Host: {}",
+ clusterName, cancelPendingST, reason, hostname);
+
+ BaseDataAccessor<ZNRecord> baseDataAccessor = new
ZkBaseDataAccessor<>(_zkClient);
+ HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName,
baseDataAccessor);
+
+ if (baseDataAccessor.exists(accessor.keyBuilder().pause().getPath(),
AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " pause signal already
exits");
+ }
+ if (baseDataAccessor.exists(accessor.keyBuilder().maintenance().getPath(),
AccessOption.PERSISTENT)) {
+ throw new HelixConflictException(clusterName + " maintenance signal
already exits");
Review comment:
exits -> exists
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -63,4 +74,33 @@ public String getReason() {
public boolean isValid() {
return true;
}
+
+ public void setClusterPause(boolean pause) {
+ _record.setBooleanField(PauseSignalProperty.CLUSTER_PAUSE.name(), pause);
+ }
+
+ public boolean isClusterPause() {
+ return _record.getBooleanField(PauseSignalProperty.CLUSTER_PAUSE.name(),
false);
+ }
+
+ public void setFromHost(String host) {
+ _record.setSimpleField(PauseSignalProperty.FROM_HOST.name(), host);
+ }
+
+ public String getFromHost() {
+ return _record.getSimpleField(PauseSignalProperty.FROM_HOST.name());
+ }
+
+ public void setCancelPendingST(boolean cancel) {
+ _record.setBooleanField(PauseSignalProperty.CANCEL_PENDING_ST.name(),
cancel);
+ }
+
+ public boolean getCancelPendingST() {
+ return
_record.getBooleanField(PauseSignalProperty.CANCEL_PENDING_ST.name(), false);
Review comment:
Question, I am thinking that shall we default cancel the pending ST?
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -40,7 +40,17 @@
LIVE_INSTANCE,
ZKPROPERTYTRANSFERURL,
RESOURCE_CAPACITY,
- CURRENT_TASK_THREAD_POOL_SIZE
+ CURRENT_TASK_THREAD_POOL_SIZE,
+
+ /** Represents the status of live instance, eg. PAUSED */
+ STATUS
+ }
+
+ /**
+ * Saved values for the {@link LiveInstanceProperty#STATUS} field
+ */
+ public enum LiveInstanceStatus {
+ PAUSED
Review comment:
Question, do we need NORMAL here too?
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]