jiangpengcheng opened a new pull request #4986:
URL: https://github.com/apache/openwhisk/pull/4986


   ## Description
   Add action versioning feature for actions
   
   ## Design
   
   Newly created/updated actions will include a `version` in their document id, 
like `whisk.system/[email protected]`, so they will not replace old versions.
   
   And to be compatible with current actions whose id doesn't contain `version` 
info, I added a new view `action-versions` in CouchDB which can use action's 
fullyQualifiedName to get all its versions and related ids:
   
   ```javascript
   function (doc) {
     var isAction = function (doc) { return (doc.exec !== undefined) };
     if (isAction(doc)) try {
       var value = {
         namespace: doc.namespace,
         name: doc.name,
         id: doc._id,
         version: doc.version,
       };
       emit([doc.namespace + "/" + doc.name], value);
     } catch (e) {}
   }
   ```
   
   and before update/get/invoke/delete an action, this view will be queried 
first to get the docId of action, and then using the docId to fetch action from 
database:
   
   - create/update:
    1. get docId for the given action'name and version parameter, if no 
`version` is specified, the latest version will be choosed
    2. if there is a docId returned in step1, fetch action using that docId, 
and created a new action based on old action and user's input, save it to 
database
    3. if there is no docId, just created a new action based on user's input 
and save it
   
   - get:
    1. get docId for the given action'name and version parameter, if no 
`version` is specified, the latest version will be choosed
    2. get action using docId got in step1, or return 404 error if no docId 
returned
   
   - invoke:
    1. get docId for the given action'name and version parameter, if no 
`version` is specified, the latest version will be choosed
    2. pass the docId to `ActivationMessage`
    3. invoker can get action using docId passed with `ActivationMessage` 
directly
   
   - delete:
    1.  get docId for the given action'name and version parameter, if no 
`version` is specified, get all docIds
    2. delete action using docId(s) got by step1
   
   With this view, the old style of docId for actions is also compatible with 
this PR
   
   And for performance reason, there is a cache layer for querying this view 
from database
   
   Other than actions, there is also some tiny changes to `trigger` and `rule`, 
since in current master, `trigger`, `rule` and `action` can not using same name 
by follow same docId style, while with this PR, actions will use a different 
way for their docId(`name + version`), so triggers and rules may use same name 
with some actions.
   
   So before save `trigger` and `rule`, it will also fetch the 
`action-versions` view first, and if there are some docIds returned, which 
means that entity name is occupied, openwhisk should return a `Conflict` error 
with message `Resource by this name exists but is not in this collection.`
   
   ## TODO
   
   - [ ] support action versioning for webactions
   
   - [ ] support action versioning for sequence actions and conductor actions
   
   - [ ] support action versioning for trigger and rule
   
   ## Related issue and scope
   <!--- Please include a link to a related issue if there is one. -->
   - [x] I opened an issue to propose and discuss this change (#4580)
   
   ## My changes affect the following components
   <!--- Select below all system components are affected by your change. -->
   <!--- Enter an `x` in all applicable boxes. -->
   - [ ] API
   - [x] Controller
   - [ ] Message Bus (e.g., Kafka)
   - [ ] Loadbalancer
   - [ ] Invoker
   - [ ] Intrinsic actions (e.g., sequences, conductors)
   - [x] Data stores (e.g., CouchDB)
   - [ ] Tests
   - [ ] Deployment
   - [x] CLI
   - [ ] General tooling
   - [ ] Documentation
   
   ## Types of changes
   <!--- What types of changes does your code introduce? Use `x` in all the 
boxes that apply: -->
   - [ ] Bug fix (generally a non-breaking change which closes an issue).
   - [ ] Enhancement or new feature (adds new functionality).
   - [x] Breaking change (a bug fix or enhancement which changes existing 
behavior).
   
   ## Checklist:
   <!--- Please review the points below which help you make sure you've covered 
all aspects of the change you're making. -->
   
   - [x] I signed an [Apache 
CLA](https://github.com/apache/openwhisk/blob/master/CONTRIBUTING.md).
   - [x] I reviewed the [style 
guides](https://github.com/apache/openwhisk/wiki/Contributing:-Git-guidelines#code-readiness)
 and followed the recommendations (Travis CI will check :).
   - [x] I added tests to cover my changes.
   - [x] My changes require further changes to the documentation.
   - [ ] I updated the documentation where necessary.
   
   


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


Reply via email to