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 [email protected] or file a JIRA ticket
with INFRA.
---