Feature: Add KV "entry" actions#24
Open
cognifloyd wants to merge 7 commits intoStackStorm-Exchange:masterfrom
Open
Feature: Add KV "entry" actions#24cognifloyd wants to merge 7 commits intoStackStorm-Exchange:masterfrom
cognifloyd wants to merge 7 commits intoStackStorm-Exchange:masterfrom
Conversation
An "entry" is a JSON object with properties. Multiple entries are stored under a JSON serialized object (as created by st2.kv.set_object) in the datastore. You can upsert or delete properties within an entry. And, you can define a fallback entry (which is named "default" by default) to allow getting properties from an entry, and using the fallback entry to provide defaults for any properties that are undfined in the entry. One use-case for objects like this is to store environment-specific (eg dev, stage, prod, etc) variables with global defaults. Each environment would be an entry and "global" could be the fallback entry. The variables would be properties inside the entries. Signed-off-by: Jacob Floyd <cognifloyd@gmail.com>
Signed-off-by: Jacob Floyd <cognifloyd@gmail.com>
plus fix a few typos Signed-off-by: Jacob Floyd <cognifloyd@gmail.com>
It's confusing to have to scroll down in the web UI to remember to include the entry name, so make it required, and use position to tell the webui order the params should be shown in. Signed-off-by: Jacob Floyd <cognifloyd@gmail.com>
Group them under st2.kv.entry.* Signed-off-by: Jacob Floyd <cognifloyd@gmail.com>
Signed-off-by: Jacob Floyd <cognifloyd@gmail.com>
|
Just curious - why "upsert_property" instead of just "set_property" - I think a set would be normally considered an add or update if exists function. |
Member
Author
|
set_property would be more consistent with the others. My original reasons for selecting upsert instead of set don't apply now because I refactored before submitting the PR :P Before I had upsert_entry_property (instead of entry.upsert_property) - trying to indicate that it was being inserted or updated within the entry. I think I'll just rename it to set for consistency :) |
Signed-off-by: Jacob Floyd <cognifloyd@gmail.com>
Member
Author
|
Updated to use set instead of upsert. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An "entry" is a JSON object with properties. Multiple entries are stored under a JSON serialized object (as created by st2.kv.set_object) in the datastore. When you retrieve an "entry", you can specify a fallback "entry" to use for defaults.
For example, consider this object:
{ "myentry": { "prop_a": "overriden" }, "default": { "prop_a": "A", "prop_b": "B", "prop_c": "C" } }If you retrieve
myentrywith thedefaultfallback, you would get this object:{ "prop_a": "overriden", "prop_b": "B", "prop_c": "C" }These are the new actions:
kv.entry.get- Retrieve entry in a JSON serialized object from the datastore. An entry is a standard JSON object with properties.kv.entry.set_property- Update or insert a property in the named entry of a JSON serialized object. Then, serialize and store the updated object. The property's value may be any json-serializable type.kv.entry.append_property- Add the value to the end of an array property in the named entry of a JSON serialized object. Then, serialize and store the updated object. The property must be an array. The value to append can be anything.kv.entry.delete_property- Delete a property from a named entry of a JSON serialized object in the datastore. If the entry is empty, delete it as well.Since more than one action could edit the same KV object at the same time, the edit actions (
set_property,append_property, anddelete_property) all use a distributed lock through the coordination backend (if configured) to serialize edits.My use-case:
I am using this as to provide environment specific config in the datastore. So, I have something like these entries:
default(the fallback),prod,stage,qa,dev. Then various actions or workflows just need to get the entry for the environment they're working with, and not have to worry about selecting from a different default object if it a var is undefined for that environment (The YAQL for selecting from multiple objects like that gets really ugly really fast).This pattern of config with defaults seems common, so am submitting this as part of the st2 pack to make the datastore an even more useful tool with less effort.