helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jiajunw...@apache.org
Subject [helix] branch customizeView updated: Add the CustomizedView Helix property (#723)
Date Wed, 05 Feb 2020 21:19:31 GMT
This is an automated email from the ASF dual-hosted git repository.

jiajunwang pushed a commit to branch customizeView
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/customizeView by this push:
     new 5c25149  Add the CustomizedView Helix property (#723)
5c25149 is described below

commit 5c251491ce68fc73ba46d5513b3e9f8bdcd43eb2
Author: Ali Reza Zamani Zadeh Najari <anajari@linkedin.com>
AuthorDate: Wed Feb 5 13:19:22 2020 -0800

    Add the CustomizedView Helix property (#723)
    
    This commit contains the bare minimum properties for CustomizedView Helix property.
---
 .../org/apache/helix/model/CustomizedView.java     | 98 ++++++++++++++++++++++
 1 file changed, 98 insertions(+)

diff --git a/helix-core/src/main/java/org/apache/helix/model/CustomizedView.java b/helix-core/src/main/java/org/apache/helix/model/CustomizedView.java
new file mode 100644
index 0000000..791829a
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/model/CustomizedView.java
@@ -0,0 +1,98 @@
+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 java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import org.apache.helix.HelixProperty;
+import org.apache.helix.ZNRecord;
+
+/**
+ * Customized view is an aggregation (across all instances)
+ * of customized states for the resource
+ */
+public class CustomizedView extends HelixProperty {
+
+  /**
+   * Instantiate a customized view with the resource it corresponds to
+   * @param resource the name of the resource
+   */
+  public CustomizedView(String resource) {
+    super(new ZNRecord(resource));
+  }
+
+  /**
+   * Instantiate a customized view with a pre-populated record
+   * @param record ZNRecord corresponding to a customized view
+   */
+  public CustomizedView(ZNRecord record) {
+    super(record);
+  }
+
+  /**
+   * For a given replica, specify which partition it corresponds to, where it is served,
and its
+   * current state
+   * @param partition the partition of the replica being served
+   * @param instance the instance serving the replica
+   * @param customState the customized state the replica is in
+   */
+  public void setState(String partition, String instance, String customState) {
+    if (_record.getMapField(partition) == null) {
+      _record.setMapField(partition, new TreeMap<String, String>());
+    }
+    _record.getMapField(partition).put(instance, customState);
+  }
+
+  /**
+   * For a given partition, indicate where and in what customized state each of its replicas
is in
+   * @param partitionName the partition to set
+   * @param customizedStateMap (instance, state) pairs
+   */
+  public void setStateMap(String partitionName, Map<String, String> customizedStateMap)
{
+    _record.setMapField(partitionName, customizedStateMap);
+  }
+
+  /**
+   * Get all the partitions of the resource
+   * @return a set of partition names
+   */
+  public Set<String> getPartitionSet() {
+    return _record.getMapFields().keySet();
+  }
+
+  /**
+   * Get the instance and the state for each partition replica
+   * @param partitionName the partition to look up
+   * @return (instance, state) pairs
+   */
+  public Map<String, String> getStateMap(String partitionName) {
+    return _record.getMapField(partitionName);
+  }
+
+  /**
+   * Get the resource represented by this view
+   * @return the name of the resource
+   */
+  public String getResourceName() {
+    return _record.getId();
+  }
+}


Mime
View raw message