You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by jx...@apache.org on 2019/02/26 02:00:30 UTC
[helix] 05/05: [HELIX-796] HELIX: Add fields to MaintenanceSignal
This is an automated email from the ASF dual-hosted git repository.
jxue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
commit 4cd7269e933602de6029534cf20290d7955e0801
Author: narendly <na...@gmail.com>
AuthorDate: Mon Feb 25 17:53:08 2019 -0800
[HELIX-796] HELIX: Add fields to MaintenanceSignal
We need to add extra fields to MaintenanceSignal in order for Helix Controller to determine how the cluster was entered into maintenance mode.
Changelist:
1. Add TRIGGERED_BY and TIMESTAMP fields and getters and setters
---
.../org/apache/helix/model/MaintenanceSignal.java | 70 ++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/helix-core/src/main/java/org/apache/helix/model/MaintenanceSignal.java b/helix-core/src/main/java/org/apache/helix/model/MaintenanceSignal.java
index b678738..56eb826 100644
--- a/helix-core/src/main/java/org/apache/helix/model/MaintenanceSignal.java
+++ b/helix-core/src/main/java/org/apache/helix/model/MaintenanceSignal.java
@@ -1,8 +1,48 @@
package org.apache.helix.model;
+/*
+ * 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 org.apache.helix.ZNRecord;
+/**
+ * A ZNode that signals that the cluster is in maintenance mode.
+ */
public class MaintenanceSignal extends PauseSignal {
+
+ /**
+ * Pre-defined fields set by Helix Controller only.
+ */
+ private enum MaintenanceSignalProperty {
+ TRIGGERED_BY,
+ TIMESTAMP
+ }
+
+ /**
+ * Possible values for TRIGGERED_BY field in MaintenanceSignal.
+ */
+ public enum TriggeringEntity {
+ CONTROLLER,
+ USER, // manually triggered by user
+ UNKNOWN
+ }
+
public MaintenanceSignal(String id) {
super(id);
}
@@ -10,4 +50,34 @@ public class MaintenanceSignal extends PauseSignal {
public MaintenanceSignal(ZNRecord record) {
super(record);
}
+
+ public void setTriggeringEntity(String triggeringEntity) {
+ _record.setSimpleField(MaintenanceSignalProperty.TRIGGERED_BY.name(), triggeringEntity);
+ }
+
+ /**
+ * Returns triggering entity.
+ * @return TriggeringEntity.UNKNOWN if the field does not exist.
+ */
+ public TriggeringEntity getTriggeringEntity() {
+ try {
+ return TriggeringEntity
+ .valueOf(_record.getSimpleField(MaintenanceSignalProperty.TRIGGERED_BY.name()));
+ } catch (Exception e) {
+ return TriggeringEntity.UNKNOWN;
+ }
+ }
+
+ public void setTimestamp(long timestamp) {
+ _record.setLongField(MaintenanceSignalProperty.TIMESTAMP.name(), timestamp);
+ }
+
+ /**
+ * Returns last modified time.
+ * TODO: Consider using modifiedTime in ZK Stat object.
+ * @return -1 if the field does not exist.
+ */
+ public long getTimestamp() {
+ return _record.getLongField(MaintenanceSignalProperty.TIMESTAMP.name(), -1);
+ }
}