You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@helix.apache.org by dasahcc <gi...@git.apache.org> on 2016/08/18 20:38:03 UTC

[GitHub] helix pull request #47: Support user defined content store per workflow/job ...

GitHub user dasahcc opened a pull request:

    https://github.com/apache/helix/pull/47

    Support user defined content store per workflow/job layer

    1. Add feature to support workflow/job layer key value user defined content store
    2. Add test case for workflow/job layer key-value pair store and verify.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/dasahcc/helix helix-0.6.x

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/helix/pull/47.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #47
    
----
commit 06ae3159dea9fd83bc6f65f5b7fc2548c50fa5b4
Author: Junkai Xue <jx...@linkedin.com>
Date:   2016-08-18T20:33:31Z

    Support user defined content store per workflow/job layer
    
    1. Add feature to support workflow/job layer key value user defined content store
    2. Add test case for workflow/job layer key-value pair store and verify.

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r76099580
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/JobRebalancer.java ---
    @@ -154,6 +154,7 @@ public ResourceAssignment computeBestPossiblePartitionState(ClusterDataCache clu
         // Update rebalancer context, previous ideal state.
         TaskUtil.setJobContext(_manager, jobName, jobCtx);
         TaskUtil.setWorkflowContext(_manager, workflowResource, workflowCtx);
    +    TaskUtil.createUserContentNode(_manager, jobName, new ZNRecord(TaskUtil.USER_CONTENT_NODE));
    --- End diff --
    
    Put the create call here will make it called everytime rebalance() is executed, that should be avoided.  Create should be only happen once, we can create the user content node when workflowRebalancer creates the job's idealState creation.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r76550134
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +221,93 @@ 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(HelixManager manager, String workflowJobResource,
    +      String key, String value) {
    +    String path = Joiner.on("/")
    +        .join(TaskConstants.REBALANCER_CONTEXT_ROOT, workflowJobResource, USER_CONTENT_NODE);
    +    ZNRecord r = manager.getHelixPropertyStore().get(path, null, AccessOption.PERSISTENT);
    +    r.setSimpleField(key, value);
    +    manager.getHelixPropertyStore().set(path, r, AccessOption.PERSISTENT);
    --- End diff --
    
    This will return fail if there are multiple jobs trying to add different key:value pairs at the same time.  However, this case should be allowed and the write confliction should be handled by this method.  Use update() method in property store will handle the concurrent updates, we need to define an updater here though.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix issue #47: Support user defined content store per workflow/job layer

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on the issue:

    https://github.com/apache/helix/pull/47
  
    Could you please add more description on what this commit is trying to do?  


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job ...

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r75893024
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +221,85 @@ protected static void setWorkflowContext(HelixManager manager, String workflowRe
       }
     
       /**
    +   * Intialize the user content store znode setup
    +   * @param manager          a connection to Helix
    +   * @param workflowResource the name of workflow
    +   * @param jobResource      the name of job
    +   * @param record           the initial data
    +   */
    +  protected static void setUserContent(HelixManager manager, String workflowResource,
    --- End diff --
    
    This set usercontent for a workflow, how about the job?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix issue #47: Support user defined content store per workflow/job/task la...

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on the issue:

    https://github.com/apache/helix/pull/47
  
    The remove function will not supported in this patch. Since it will get the map from getSimpleFields,  remove the key, then reset the simple fields back. I dont think it worth of doing that way, since original property store does not support remove function.
    
    We can monitor the usage of this content store. If user prefer to have the remove function. We shall add it from property store layer.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job ...

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r75894524
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +221,85 @@ protected static void setWorkflowContext(HelixManager manager, String workflowRe
       }
     
       /**
    +   * Intialize the user content store znode setup
    +   * @param manager          a connection to Helix
    +   * @param workflowResource the name of workflow
    +   * @param jobResource      the name of job
    +   * @param record           the initial data
    +   */
    +  protected static void setUserContent(HelixManager manager, String workflowResource,
    +      String jobResource, ZNRecord record) {
    +    manager.getHelixPropertyStore().create(Joiner.on("/")
    +            .join(TaskConstants.REBALANCER_CONTEXT_ROOT, workflowResource, TaskUtil.USER_CONTENT_NODE),
    +        record, AccessOption.PERSISTENT);
    +    manager.getHelixPropertyStore().create(Joiner.on("/")
    +            .join(TaskConstants.REBALANCER_CONTEXT_ROOT, jobResource, TaskUtil.USER_CONTENT_NODE),
    +        record, AccessOption.PERSISTENT);
    +  }
    +
    +  /**
    +   * Get user defined workflow level key-value pair data
    +   *
    +   * @param manager          a connection to Helix
    +   * @param workflowResource 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 getWorkflowUserContent(HelixManager manager, String workflowResource,
    --- End diff --
    
    Same here, no need to differentiate get/set methods for workflow and job.  


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/helix/pull/47


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job ...

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r75918344
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/UserContentStore.java ---
    @@ -0,0 +1,97 @@
    +package org.apache.helix.task;
    +
    +/*
    + * 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.HelixException;
    +import org.apache.helix.HelixManager;
    +
    +/**
    + * UserContentStore provides default implementation of user defined key-value pair store per job,
    + * workflow level.
    + *
    + * TODO: This class should be merged to Task interface when Helix bump up to Java 8
    + */
    +public abstract class UserContentStore {
    +
    +  protected enum Scope {
    +    /**
    +     * Define the content store in workflow level
    +     */
    +    WORKFLOW,
    +
    +    /**
    +     * Define the content store in job level
    +     */
    +    JOB
    +  }
    +
    +  private HelixManager _manager;
    +  private String _workflowName;
    +  private String _jobName;
    +
    +  /**
    +   * Default initialization of user content store
    +   * @param manager The Helix manager
    +   * @param workflowName The name of workflow that the task belongs to
    +   * @param jobName The name of job that the task belongs to
    +   */
    +  public void init(HelixManager manager, String workflowName, String jobName) {
    +    _manager = manager;
    +    _workflowName = workflowName;
    +    _jobName = jobName;
    +  }
    +
    +  /**
    +   * Default implementation for user defined put key-value pair
    +   * @param key The key of key-value pair
    +   * @param value The value of key-value pair
    +   * @param scope The scope defines which layer to store
    +   */
    +  public void userDefinedPut(String key, String value, Scope scope) {
    --- End diff --
    
    Ask Keren asked before, if we are using put / get, will user get confused with Java get put methods?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by lei-xia <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r76107997
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/JobRebalancer.java ---
    @@ -154,6 +154,7 @@ public ResourceAssignment computeBestPossiblePartitionState(ClusterDataCache clu
         // Update rebalancer context, previous ideal state.
         TaskUtil.setJobContext(_manager, jobName, jobCtx);
         TaskUtil.setWorkflowContext(_manager, workflowResource, workflowCtx);
    +    TaskUtil.createUserContentNode(_manager, jobName, new ZNRecord(TaskUtil.USER_CONTENT_NODE));
    --- End diff --
    
    Will move this.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job ...

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r75919136
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/UserContentStore.java ---
    @@ -0,0 +1,97 @@
    +package org.apache.helix.task;
    +
    +/*
    + * 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.HelixException;
    +import org.apache.helix.HelixManager;
    +
    +/**
    + * UserContentStore provides default implementation of user defined key-value pair store per job,
    + * workflow level.
    + *
    + * TODO: This class should be merged to Task interface when Helix bump up to Java 8
    + */
    +public abstract class UserContentStore {
    +
    +  protected enum Scope {
    +    /**
    +     * Define the content store in workflow level
    +     */
    +    WORKFLOW,
    +
    +    /**
    +     * Define the content store in job level
    +     */
    +    JOB
    +  }
    +
    +  private HelixManager _manager;
    +  private String _workflowName;
    +  private String _jobName;
    +
    +  /**
    +   * Default initialization of user content store
    +   * @param manager The Helix manager
    +   * @param workflowName The name of workflow that the task belongs to
    +   * @param jobName The name of job that the task belongs to
    +   */
    +  public void init(HelixManager manager, String workflowName, String jobName) {
    +    _manager = manager;
    +    _workflowName = workflowName;
    +    _jobName = jobName;
    +  }
    +
    +  /**
    +   * Default implementation for user defined put key-value pair
    +   * @param key The key of key-value pair
    +   * @param value The value of key-value pair
    +   * @param scope The scope defines which layer to store
    +   */
    +  public void userDefinedPut(String key, String value, Scope scope) {
    +    switch (scope) {
    +    case WORKFLOW:
    +      TaskUtil.addWorkflowUserContent(_manager, _workflowName, key, value);
    +      break;
    +    case JOB:
    +      TaskUtil.addJobContent(_manager, _jobName, key, value);
    +      break;
    +    default:
    +      throw new HelixException("Invalid scope : " + scope.name());
    +    }
    +  }
    +
    +  /**
    +   * Default implementation for user defined get key-value pair
    +   * @param key The key of key-value pair
    +   * @param scope The scope defines which layer that key-value pair stored
    +   * @return Null if key-value pair not found or this content store does not exists. Otherwise,
    +   *         return a String
    +   */
    +  public String userDefinedGet(String key, Scope scope) {
    --- End diff --
    
    Will add that!


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job ...

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r75894867
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/UserContentStore.java ---
    @@ -0,0 +1,97 @@
    +package org.apache.helix.task;
    +
    +/*
    + * 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.HelixException;
    +import org.apache.helix.HelixManager;
    +
    +/**
    + * UserContentStore provides default implementation of user defined key-value pair store per job,
    + * workflow level.
    + *
    + * TODO: This class should be merged to Task interface when Helix bump up to Java 8
    + */
    +public abstract class UserContentStore {
    +
    +  protected enum Scope {
    +    /**
    +     * Define the content store in workflow level
    +     */
    +    WORKFLOW,
    +
    +    /**
    +     * Define the content store in job level
    +     */
    +    JOB
    +  }
    +
    +  private HelixManager _manager;
    +  private String _workflowName;
    +  private String _jobName;
    +
    +  /**
    +   * Default initialization of user content store
    +   * @param manager The Helix manager
    +   * @param workflowName The name of workflow that the task belongs to
    +   * @param jobName The name of job that the task belongs to
    +   */
    +  public void init(HelixManager manager, String workflowName, String jobName) {
    +    _manager = manager;
    +    _workflowName = workflowName;
    +    _jobName = jobName;
    +  }
    +
    +  /**
    +   * Default implementation for user defined put key-value pair
    +   * @param key The key of key-value pair
    +   * @param value The value of key-value pair
    +   * @param scope The scope defines which layer to store
    +   */
    +  public void userDefinedPut(String key, String value, Scope scope) {
    +    switch (scope) {
    +    case WORKFLOW:
    +      TaskUtil.addWorkflowUserContent(_manager, _workflowName, key, value);
    +      break;
    +    case JOB:
    +      TaskUtil.addJobContent(_manager, _jobName, key, value);
    +      break;
    +    default:
    +      throw new HelixException("Invalid scope : " + scope.name());
    +    }
    +  }
    +
    +  /**
    +   * Default implementation for user defined get key-value pair
    +   * @param key The key of key-value pair
    +   * @param scope The scope defines which layer that key-value pair stored
    +   * @return Null if key-value pair not found or this content store does not exists. Otherwise,
    +   *         return a String
    +   */
    +  public String userDefinedGet(String key, Scope scope) {
    --- End diff --
    
    Do we need a delete method?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r76550156
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +221,93 @@ 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(HelixManager manager, String workflowJobResource,
    +      String key, String value) {
    +    String path = Joiner.on("/")
    +        .join(TaskConstants.REBALANCER_CONTEXT_ROOT, workflowJobResource, USER_CONTENT_NODE);
    +    ZNRecord r = manager.getHelixPropertyStore().get(path, null, AccessOption.PERSISTENT);
    +    r.setSimpleField(key, value);
    +    manager.getHelixPropertyStore().set(path, 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(HelixManager manager, String jobResource,
    +      String taskResource, String key, String value) {
    +    String path =
    +        Joiner.on("/").join(TaskConstants.REBALANCER_CONTEXT_ROOT, jobResource, USER_CONTENT_NODE);
    +    ZNRecord r = manager.getHelixPropertyStore().get(path, null, AccessOption.PERSISTENT);
    +    if (r.getMapField(taskResource) == null) {
    +      r.setMapField(taskResource, new HashMap<String, String>());
    +    }
    +    r.getMapField(taskResource).put(key, value);
    +    manager.getHelixPropertyStore().set(path, r, AccessOption.PERSISTENT);
    --- End diff --
    
    same here, we need to use propertyStore.update() instead of set().


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job ...

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r75918144
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +221,85 @@ protected static void setWorkflowContext(HelixManager manager, String workflowRe
       }
     
       /**
    +   * Intialize the user content store znode setup
    +   * @param manager          a connection to Helix
    +   * @param workflowResource the name of workflow
    +   * @param jobResource      the name of job
    +   * @param record           the initial data
    +   */
    +  protected static void setUserContent(HelixManager manager, String workflowResource,
    +      String jobResource, ZNRecord record) {
    +    manager.getHelixPropertyStore().create(Joiner.on("/")
    +            .join(TaskConstants.REBALANCER_CONTEXT_ROOT, workflowResource, TaskUtil.USER_CONTENT_NODE),
    +        record, AccessOption.PERSISTENT);
    +    manager.getHelixPropertyStore().create(Joiner.on("/")
    +            .join(TaskConstants.REBALANCER_CONTEXT_ROOT, jobResource, TaskUtil.USER_CONTENT_NODE),
    +        record, AccessOption.PERSISTENT);
    +  }
    +
    +  /**
    +   * Get user defined workflow level key-value pair data
    +   *
    +   * @param manager          a connection to Helix
    +   * @param workflowResource 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 getWorkflowUserContent(HelixManager manager, String workflowResource,
    --- End diff --
    
    Will merge that.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job ...

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r75918063
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +221,85 @@ protected static void setWorkflowContext(HelixManager manager, String workflowRe
       }
     
       /**
    +   * Intialize the user content store znode setup
    +   * @param manager          a connection to Helix
    +   * @param workflowResource the name of workflow
    +   * @param jobResource      the name of job
    +   * @param record           the initial data
    +   */
    +  protected static void setUserContent(HelixManager manager, String workflowResource,
    +      String jobResource, ZNRecord record) {
    +    manager.getHelixPropertyStore().create(Joiner.on("/")
    --- End diff --
    
    Will merge that.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job ...

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r75917948
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +221,85 @@ protected static void setWorkflowContext(HelixManager manager, String workflowRe
       }
     
       /**
    +   * Intialize the user content store znode setup
    +   * @param manager          a connection to Helix
    +   * @param workflowResource the name of workflow
    +   * @param jobResource      the name of job
    +   * @param record           the initial data
    +   */
    +  protected static void setUserContent(HelixManager manager, String workflowResource,
    --- End diff --
    
    job will be set at same time. It is the initialization for both workflow and job 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r77031851
  
    --- 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);
    --- End diff --
    
    you do not have to read znrecord in your updater again, the znRecord passed to you is supposed to be the lastest record.
    
    What you do in updater is something like:
    
    znRecord.setSimpleField(key, value);
    return znRecord;
    
    The property store will read the lastest znode, call the updater with this znode content, and write back with the new record returned from your updater.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r76098588
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +221,93 @@ protected static void setWorkflowContext(HelixManager manager, String workflowRe
       }
     
       /**
    +   * Intialize the user content store znode setup
    +   * @param manager          a connection to Helix
    +   * @param workflowJobResource the name of workflow or job
    +   * @param record           the initial data
    +   */
    +  protected static void createUserContentNode(HelixManager manager, String workflowJobResource,
    --- End diff --
    
    maybe rename it to createUserContent or initUserContent?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r76099693
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/WorkflowRebalancer.java ---
    @@ -120,6 +120,7 @@ public ResourceAssignment computeBestPossiblePartitionState(ClusterDataCache clu
         }
     
         TaskUtil.setWorkflowContext(_manager, workflow, workflowCtx);
    +    TaskUtil.createUserContentNode(_manager, workflow, new ZNRecord(TaskUtil.USER_CONTENT_NODE));
    --- End diff --
    
    Same as in JobRebalancer, make sure this creation will be only called once


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job ...

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r75894351
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +221,85 @@ protected static void setWorkflowContext(HelixManager manager, String workflowRe
       }
     
       /**
    +   * Intialize the user content store znode setup
    +   * @param manager          a connection to Helix
    +   * @param workflowResource the name of workflow
    +   * @param jobResource      the name of job
    +   * @param record           the initial data
    +   */
    +  protected static void setUserContent(HelixManager manager, String workflowResource,
    +      String jobResource, ZNRecord record) {
    +    manager.getHelixPropertyStore().create(Joiner.on("/")
    --- End diff --
    
    This creates both workflow content node and job content node everytime, which is not needed.  Since the workflow and job directory structure in propertyStore are same /WorkflowOrJobName/usercontent, this method can be generic for both workflow and job, such as
    SetUserContent(HelixManager manager,  String workflowJobResource, ...):
               manager.getHelixPropertyStore().create(Joiner.on("/")            .join(TaskConstants.REBALANCER_CONTEXT_ROOT, workflowJobResource, TaskUtil.USER_CONTENT_NODE),
           record, AccessOption.PERSISTENT);


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r76107770
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +221,93 @@ protected static void setWorkflowContext(HelixManager manager, String workflowRe
       }
     
       /**
    +   * Intialize the user content store znode setup
    +   * @param manager          a connection to Helix
    +   * @param workflowJobResource the name of workflow or job
    +   * @param record           the initial data
    +   */
    +  protected static void createUserContentNode(HelixManager manager, String workflowJobResource,
    +      ZNRecord record) {
    +    manager.getHelixPropertyStore().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(HelixManager manager, String workflowJobResource,
    +      String key, String value) {
    +    String path = Joiner.on("/")
    +        .join(TaskConstants.REBALANCER_CONTEXT_ROOT, workflowJobResource, USER_CONTENT_NODE);
    +    ZNRecord r = manager.getHelixPropertyStore().get(path, null, AccessOption.PERSISTENT);
    +    r.setSimpleField(key, value);
    +    manager.getHelixPropertyStore().set(path, 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(HelixManager manager, String jobResource,
    +      String taskResource, String key, String value) {
    +    String path =
    +        Joiner.on("/").join(TaskConstants.REBALANCER_CONTEXT_ROOT, jobResource, USER_CONTENT_NODE);
    +    ZNRecord r = manager.getHelixPropertyStore().get(path, null, AccessOption.PERSISTENT);
    --- End diff --
    
    the record here definitely should not be null since we create the znode before job started.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix issue #47: Support user defined content store per workflow/job layer

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on the issue:

    https://github.com/apache/helix/pull/47
  
    Update the change.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r76099094
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +221,93 @@ protected static void setWorkflowContext(HelixManager manager, String workflowRe
       }
     
       /**
    +   * Intialize the user content store znode setup
    +   * @param manager          a connection to Helix
    +   * @param workflowJobResource the name of workflow or job
    +   * @param record           the initial data
    +   */
    +  protected static void createUserContentNode(HelixManager manager, String workflowJobResource,
    +      ZNRecord record) {
    +    manager.getHelixPropertyStore().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(HelixManager manager, String workflowJobResource,
    +      String key, String value) {
    +    String path = Joiner.on("/")
    +        .join(TaskConstants.REBALANCER_CONTEXT_ROOT, workflowJobResource, USER_CONTENT_NODE);
    +    ZNRecord r = manager.getHelixPropertyStore().get(path, null, AccessOption.PERSISTENT);
    +    r.setSimpleField(key, value);
    +    manager.getHelixPropertyStore().set(path, 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(HelixManager manager, String jobResource,
    +      String taskResource, String key, String value) {
    +    String path =
    +        Joiner.on("/").join(TaskConstants.REBALANCER_CONTEXT_ROOT, jobResource, USER_CONTENT_NODE);
    +    ZNRecord r = manager.getHelixPropertyStore().get(path, null, AccessOption.PERSISTENT);
    --- End diff --
    
    Is it possible that r == null?  Since you checked r == null in getTaskUserContent


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job ...

Posted by lei-xia <gi...@git.apache.org>.
Github user lei-xia commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r75894819
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/UserContentStore.java ---
    @@ -0,0 +1,97 @@
    +package org.apache.helix.task;
    +
    +/*
    + * 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.HelixException;
    +import org.apache.helix.HelixManager;
    +
    +/**
    + * UserContentStore provides default implementation of user defined key-value pair store per job,
    + * workflow level.
    + *
    + * TODO: This class should be merged to Task interface when Helix bump up to Java 8
    + */
    +public abstract class UserContentStore {
    +
    +  protected enum Scope {
    +    /**
    +     * Define the content store in workflow level
    +     */
    +    WORKFLOW,
    +
    +    /**
    +     * Define the content store in job level
    +     */
    +    JOB
    +  }
    +
    +  private HelixManager _manager;
    +  private String _workflowName;
    +  private String _jobName;
    +
    +  /**
    +   * Default initialization of user content store
    +   * @param manager The Helix manager
    +   * @param workflowName The name of workflow that the task belongs to
    +   * @param jobName The name of job that the task belongs to
    +   */
    +  public void init(HelixManager manager, String workflowName, String jobName) {
    +    _manager = manager;
    +    _workflowName = workflowName;
    +    _jobName = jobName;
    +  }
    +
    +  /**
    +   * Default implementation for user defined put key-value pair
    +   * @param key The key of key-value pair
    +   * @param value The value of key-value pair
    +   * @param scope The scope defines which layer to store
    +   */
    +  public void userDefinedPut(String key, String value, Scope scope) {
    --- End diff --
    
    Name them as  "put"/"get" will be simpler.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix issue #47: Support user defined content store per workflow/job/task la...

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on the issue:

    https://github.com/apache/helix/pull/47
  
    Add support for task level key value pair get/put


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r76108043
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/WorkflowRebalancer.java ---
    @@ -120,6 +120,7 @@ public ResourceAssignment computeBestPossiblePartitionState(ClusterDataCache clu
         }
     
         TaskUtil.setWorkflowContext(_manager, workflow, workflowCtx);
    +    TaskUtil.createUserContentNode(_manager, workflow, new ZNRecord(TaskUtil.USER_CONTENT_NODE));
    --- End diff --
    
    Will fix this.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix issue #47: Support user defined content store per workflow/job layer

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on the issue:

    https://github.com/apache/helix/pull/47
  
    Yes. Updated the description.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] helix pull request #47: Support user defined content store per workflow/job/...

Posted by dasahcc <gi...@git.apache.org>.
Github user dasahcc commented on a diff in the pull request:

    https://github.com/apache/helix/pull/47#discussion_r76108077
  
    --- Diff: helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---
    @@ -220,6 +221,93 @@ protected static void setWorkflowContext(HelixManager manager, String workflowRe
       }
     
       /**
    +   * Intialize the user content store znode setup
    +   * @param manager          a connection to Helix
    +   * @param workflowJobResource the name of workflow or job
    +   * @param record           the initial data
    +   */
    +  protected static void createUserContentNode(HelixManager manager, String workflowJobResource,
    --- End diff --
    
    will fix this.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---