Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r77031881
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +222,103 @@ protected static void setWorkflowContext(HelixManager 
manager, String workflowRe
       }
     
       /**
    +   * Intialize the user content store znode setup
    +   * @param propertyStore       zookeeper property store
    +   * @param workflowJobResource the name of workflow or job
    +   * @param record              the initial data
    +   */
    +  protected static void createUserContent(HelixPropertyStore 
propertyStore, String workflowJobResource,
    +      ZNRecord record) {
    +    propertyStore.create(Joiner.on("/")
    +        .join(TaskConstants.REBALANCER_CONTEXT_ROOT, workflowJobResource,
    +            TaskUtil.USER_CONTENT_NODE), record, AccessOption.PERSISTENT);
    +  }
    +
    +  /**
    +   * Get user defined workflow or job level key-value pair data
    +   *
    +   * @param manager             a connection to Helix
    +   * @param workflowJobResource the name of workflow
    +   * @param key                 the key of key-value pair
    +   *
    +   * @return null if there is no such pair, otherwise return a String
    +   */
    +  protected static String getWorkflowJobUserContent(HelixManager manager,
    +      String workflowJobResource, String key) {
    +    ZNRecord r = manager.getHelixPropertyStore().get(Joiner.on("/")
    +            .join(TaskConstants.REBALANCER_CONTEXT_ROOT, 
workflowJobResource, USER_CONTENT_NODE), null,
    +        AccessOption.PERSISTENT);
    +    return r != null ? r.getSimpleField(key) : null;
    +  }
    +
    +  /**
    +   * Add an user defined key-value pair data to workflow or job level
    +   *
    +   * @param manager             a connection to Helix
    +   * @param workflowJobResource the name of workflow or job
    +   * @param key                 the key of key-value pair
    +   * @param value               the value of key-value pair
    +   */
    +  protected static void addWorkflowJobUserContent(final HelixManager 
manager,
    +      String workflowJobResource, final String key, final String value) {
    +    final String path = Joiner.on("/")
    +        .join(TaskConstants.REBALANCER_CONTEXT_ROOT, workflowJobResource, 
USER_CONTENT_NODE);
    +
    +    manager.getHelixPropertyStore().update(path, new 
DataUpdater<ZNRecord>() {
    +      @Override public ZNRecord update(ZNRecord znRecord) {
    +        ZNRecord r = manager.getHelixPropertyStore().get(path, null, 
AccessOption.PERSISTENT);
    +        r.setSimpleField(key, value);
    +        return r;
    +      }
    +    }, AccessOption.PERSISTENT);
    +  }
    +
    +  /**
    +   * Get user defined task level key-value pair data
    +   *
    +   * @param manager      a connection to Helix
    +   * @param jobResource  the name of job
    +   * @param taskResource the name of the task
    +   * @param key          the key of key-value pair
    +   *
    +   * @return null if there is no such pair, otherwise return a String
    +   */
    +  protected static String getTaskUserContent(HelixManager manager, String 
jobResource,
    +      String taskResource, String key) {
    +    ZNRecord r = manager.getHelixPropertyStore().get(
    +        Joiner.on("/").join(TaskConstants.REBALANCER_CONTEXT_ROOT, 
jobResource, USER_CONTENT_NODE),
    +        null, AccessOption.PERSISTENT);
    +    return r != null ? (r.getMapField(taskResource) != null
    +        ? r.getMapField(taskResource).get(key)
    +        : null) : null;
    +  }
    +
    +  /**
    +   * Add an user defined key-value pair data to task level
    +   *
    +   * @param manager       a connection to Helix
    +   * @param jobResource   the name of job
    +   * @param taskResource  the name of task
    +   * @param key           the key of key-value pair
    +   * @param value         the value of key-value pair
    +   */
    +  protected static void addTaskUserContent(final HelixManager manager, 
String jobResource,
    +      final String taskResource, final String key, final String value) {
    +    final String path =
    +        Joiner.on("/").join(TaskConstants.REBALANCER_CONTEXT_ROOT, 
jobResource, USER_CONTENT_NODE);
    +
    +    manager.getHelixPropertyStore().update(path, new 
DataUpdater<ZNRecord>() {
    +      @Override public ZNRecord update(ZNRecord znRecord) {
    +        ZNRecord r = manager.getHelixPropertyStore().get(path, null, 
AccessOption.PERSISTENT);
    --- End diff --
    
    same here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to