dasahcc commented on a change in pull request #729: Implement Helix API for 
updating customized state
URL: https://github.com/apache/helix/pull/729#discussion_r376062856
 
 

 ##########
 File path: helix-core/src/main/java/org/apache/helix/model/CustomizedState.java
 ##########
 @@ -0,0 +1,156 @@
+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.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.helix.HelixProperty;
+import org.apache.helix.ZNRecord;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Customized states of partitions in a resource for an instance.
+ */
+public class CustomizedState extends HelixProperty {
+  private static Logger LOG = LoggerFactory.getLogger(CustomizedState.class);
+
+  /**
+   * Lookup keys for the customized state
+   */
+  public enum CustomizedStateProperty {
+    PREVIOUS_STATE,
+    CURRENT_STATE,
+    START_TIME,
+    END_TIME
+  }
+
+  /**
+   * Instantiate a customized state with a resource
+   * @param resourceName name identifying the resource
+   */
+  public CustomizedState(String resourceName) {
+    super(resourceName);
+  }
+
+  /**
+   * Instantiate a customized state with a pre-populated ZNRecord
+   * @param record a ZNRecord corresponding to the customized state
+   */
+  public CustomizedState(ZNRecord record) {
+    super(record);
+  }
+
+  /**
+   * Get the name of the resource
+   * @return String resource identifier
+   */
+  public String getResourceName() {
+    return _record.getId();
+  }
+
+  /**
+   * Get the partitions on this instance and the state that each partition is 
currently in.
+   * @return (partition, state) pairs
+   */
+  public Map<String, String> getPartitionStateMap() {
+    Map<String, String> map = new HashMap<String, String>();
+    Map<String, Map<String, String>> mapFields = _record.getMapFields();
+    for (String partitionName : mapFields.keySet()) {
+      Map<String, String> tempMap = mapFields.get(partitionName);
+      if (tempMap != null) {
 
 Review comment:
   From code perspective, we need to check it. But when we push data to ZK, it 
is better to remove non-reported entries to save spaces.

----------------------------------------------------------------
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]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to