jiajunwang commented on a change in pull request #1740:
URL: https://github.com/apache/helix/pull/1740#discussion_r634791356
##########
File path:
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,77 @@ 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");
+ }
+
+ PauseSignal pauseSignal = new PauseSignal();
+ pauseSignal.setPauseCluster(Boolean.toString(true));
Review comment:
nit, Can we make it in the constructor parameter to avoid possible
misusage?
Ultimately, it would be great if we have a super class for all signals. And
the 3 modes are child classes.
Then on set, directly create child class objects.
On read, the super class can have a static method to convert into the child
class according to the internal mode field.
This would help to avoid possible misusage and duplicate code.
##########
File path:
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,77 @@ 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");
+ }
+
+ PauseSignal pauseSignal = new PauseSignal();
+ pauseSignal.setPauseCluster(Boolean.toString(true));
+ pauseSignal.setCancelPendingST(cancelPendingST);
+ pauseSignal.setFromHost(hostname);
+ pauseSignal.setTriggerTime(Instant.now().toString());
+ if (reason != null && !reason.isEmpty()) {
+ pauseSignal.setReason(reason);
+ }
+ if (!accessor.createPause(pauseSignal)) {
Review comment:
There could be a race condition between maintenance node creating and
pause node creating. But it cannot be resolved easily since they are different
paths. Let's add a TODO here that, once we merge the status signal nodes into
one path, then there won't be any more race conditions.
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -130,6 +135,22 @@ public void setHelixVersion(String helixVersion) {
_record.setSimpleField(LiveInstanceProperty.HELIX_VERSION.toString(),
helixVersion);
}
+ /**
+ * Gets the live instance's status.
+ */
+ public String getStatus() {
+ return _record.getSimpleField(LiveInstanceProperty.STATUS.name());
+ }
+
+ /**
+ * Sets the status in simple field.
+ *
+ * @param status status value
+ */
+ public void setStatus(String status) {
Review comment:
Accepts enum?
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -63,4 +72,36 @@ public String getReason() {
public boolean isValid() {
return true;
}
+
+ public void setPauseCluster(String pause) {
+ _record.setSimpleField(PauseSignalProperty.CLUSTER_PAUSE.name(), pause);
+ }
+
+ public String getPauseCluster() {
Review comment:
Same here, return boolean, please.
##########
File path:
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,77 @@ 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");
+ }
+
+ PauseSignal pauseSignal = new PauseSignal();
+ pauseSignal.setPauseCluster(Boolean.toString(true));
+ pauseSignal.setCancelPendingST(cancelPendingST);
+ pauseSignal.setFromHost(hostname);
+ pauseSignal.setTriggerTime(Instant.now().toString());
+ if (reason != null && !reason.isEmpty()) {
+ pauseSignal.setReason(reason);
+ }
+ if (!accessor.createPause(pauseSignal)) {
+ throw new HelixException("Failed to create pause signal");
+ }
+ }
+
+ private void disableClusterPauseMode(String clusterName) {
+ logger.info("Disable cluster pause mode for cluster: {}", clusterName);
+ HelixDataAccessor accessor =
+ new ZKHelixDataAccessor(clusterName, new
ZkBaseDataAccessor<>(_zkClient));
+ PropertyKey pausePropertyKey = accessor.keyBuilder().pause();
+ PauseSignal pauseSignal = accessor.getProperty(pausePropertyKey);
+ if (pauseSignal == null || pauseSignal.getPauseCluster() == null) {
Review comment:
getPauseCluster == false? or !isPauseCluster() ?
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -63,4 +72,36 @@ public String getReason() {
public boolean isValid() {
return true;
}
+
+ public void setPauseCluster(String pause) {
+ _record.setSimpleField(PauseSignalProperty.CLUSTER_PAUSE.name(), pause);
+ }
+
+ public String getPauseCluster() {
+ return _record.getSimpleField(PauseSignalProperty.CLUSTER_PAUSE.name());
+ }
+
+ 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);
+ }
+
+ public void setTriggerTime(String time) {
Review comment:
I suggest taking a long type as the input. This will help to avoid
misusage.
##########
File path: helix-core/src/main/java/org/apache/helix/model/PauseSignal.java
##########
@@ -63,4 +72,36 @@ public String getReason() {
public boolean isValid() {
return true;
}
+
+ public void setPauseCluster(String pause) {
Review comment:
What is this (╯°Д°)╯ ┻━┻
Why not directly passing boolean in? Do you support other pause String? Like
setPauseCluster("Foobar") ???
##########
File path: helix-core/src/main/java/org/apache/helix/model/LiveInstance.java
##########
@@ -52,6 +55,8 @@
private static final Logger _logger =
LoggerFactory.getLogger(LiveInstance.class.getName());
+ public static final String PAUSED_STATUS = "PAUSED";
Review comment:
enum?
##########
File path:
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
##########
@@ -497,6 +500,77 @@ 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");
+ }
+
+ PauseSignal pauseSignal = new PauseSignal();
+ pauseSignal.setPauseCluster(Boolean.toString(true));
+ pauseSignal.setCancelPendingST(cancelPendingST);
+ pauseSignal.setFromHost(hostname);
+ pauseSignal.setTriggerTime(Instant.now().toString());
+ if (reason != null && !reason.isEmpty()) {
+ pauseSignal.setReason(reason);
+ }
+ if (!accessor.createPause(pauseSignal)) {
+ throw new HelixException("Failed to create pause signal");
+ }
+ }
+
+ private void disableClusterPauseMode(String clusterName) {
+ logger.info("Disable cluster pause mode for cluster: {}", clusterName);
+ HelixDataAccessor accessor =
+ new ZKHelixDataAccessor(clusterName, new
ZkBaseDataAccessor<>(_zkClient));
+ PropertyKey pausePropertyKey = accessor.keyBuilder().pause();
+ PauseSignal pauseSignal = accessor.getProperty(pausePropertyKey);
+ if (pauseSignal == null || pauseSignal.getPauseCluster() == null) {
+ throw new HelixException("Cluster pause mode is not enabled for cluster
" + clusterName);
+ }
+
+ if (!accessor.removeProperty(pausePropertyKey)) {
+ throw new HelixException("Failed to disable cluster pause mode for
cluster: " + clusterName);
+ }
+ }
+
+ @Override
+ public ClusterManagementMode getClusterManagementMode(String clusterName) {
+ // TODO: implement logic
+ return null;
Review comment:
If you are not adding this implementation, please delay the API into the
next PR too.
##########
File path:
helix-core/src/main/java/org/apache/helix/model/management/ClusterManagementMode.java
##########
@@ -0,0 +1,70 @@
+package org.apache.helix.model.management;
+
+/*
+ * 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.
+ */
+
+/**
+ * Represents the management mode of the cluster:
+ * 1. what type of mode it targets to be;
+ * 2. what progress status it is now.
+ */
+public class ClusterManagementMode {
Review comment:
You can just make this class enum and list all the possible mode,
NORMAL()
CLUSTER_PAUSE(Status status) // inprogress or completed
CONTROLLER_PAUSE()
MAINTENANCE()
Then you don't need to face a Maintenance mode object with inprogress
status. Which does not make sense.
--
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]