You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by mr...@apache.org on 2017/09/08 15:16:53 UTC

[incubator-openwhisk-wskdeploy] branch master updated: Create binding when dependency name and the origin package name are different (#461)

This is an automated email from the ASF dual-hosted git repository.

mrutkowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-wskdeploy.git


The following commit(s) were added to refs/heads/master by this push:
     new eeaab34  Create binding when dependency name and the origin package name are different (#461)
eeaab34 is described below

commit eeaab34be1c46f0b7ac4d6ebaf46f0f5b22a7275
Author: Ying Chun Guo <gu...@cn.ibm.com>
AuthorDate: Fri Sep 8 23:16:51 2017 +0800

    Create binding when dependency name and the origin package name are different (#461)
---
 deployers/servicedeployer.go            | 26 +++++++++
 tests/usecases/dependency/README.md     | 99 +++++++++++++++++++++++++++++++++
 tests/usecases/dependency/manifest.yaml |  4 +-
 utils/qualifiedname.go                  |  3 +
 4 files changed, 130 insertions(+), 2 deletions(-)

diff --git a/deployers/servicedeployer.go b/deployers/servicedeployer.go
index 4e232d5..c65803f 100644
--- a/deployers/servicedeployer.go
+++ b/deployers/servicedeployer.go
@@ -160,6 +160,7 @@ func (deployer *ServiceDeployer) ConstructUnDeploymentPlan() (*DeploymentApplica
         return deployer.Deployment, err
     }
 
+    deployer.RootPackageName = manifest.Package.Packagename
     manifestReader.InitRootPackage(manifestParser, manifest)
 
     // process file system
@@ -323,6 +324,25 @@ func (deployer *ServiceDeployer) DeployDependencies() error {
                 } else {
                     fmt.Println("Done!")
                 }
+
+                // if the RootPackageName is different from depName
+                // create a binding to the origin package
+                if (depServiceDeployer.RootPackageName != depName) {
+                    bindingPackage := new(whisk.BindingPackage)
+                    bindingPackage.Namespace = pack.Package.Namespace
+                    bindingPackage.Name = depName
+                    pub := false
+                    bindingPackage.Publish = &pub
+
+                    qName, err := utils.ParseQualifiedName(depServiceDeployer.RootPackageName, depServiceDeployer.Deployment.Packages[depServiceDeployer.RootPackageName].Package.Namespace)
+                    utils.Check(err)
+                    bindingPackage.Binding = whisk.Binding{qName.Namespace, qName.EntityName}
+
+                    bindingPackage.Parameters = depRecord.Parameters
+                    bindingPackage.Annotations = depRecord.Annotations
+
+                    deployer.createBinding(bindingPackage)
+		}
             }
         }
     }
@@ -684,6 +704,12 @@ func (deployer *ServiceDeployer) UnDeployDependencies() error {
                     return err
                 }
 
+		// delete binding pkg if the origin package name is different
+                if (depServiceDeployer.RootPackageName != depName) {
+                    _, err := deployer.Client.Packages.Delete(depName)
+                    utils.Check(err)
+                }
+
                 if err := depServiceDeployer.unDeployAssets(plan); err != nil {
                     errString := wski18n.T("Undeployment of dependency {{.depName}} did not complete sucessfully.\n",
                         map[string]interface{}{"depName": depName})
diff --git a/tests/usecases/dependency/README.md b/tests/usecases/dependency/README.md
new file mode 100644
index 0000000..f37f707
--- /dev/null
+++ b/tests/usecases/dependency/README.md
@@ -0,0 +1,99 @@
+# Show case for dependencies
+
+This is a show case for `wskdeploy`. This package shows how to deploy a package with dependencies to existing system packages or external resources.
+
+Below is the `dependencies` segement in `manifest.yaml`.
+```
+dependencies:
+  hellowhisk:
+    location: github.com/paulcastro/hellowhisk
+  newpkg:
+    location: github.com/daisy-ycguo/wskdeploy-test/helloworld
+  myCloudant:
+    location: /whisk.system/cloudant
+    inputs:
+      dbname: myGreatDB
+    annotations:
+      myAnnotation: Here it is
+```
+
+It defines three dependencies:
+- `hellowhisk` is a dependency to an external package whose source code is in a git repo `https://github.com/paulcastro/hellowhisk`. `wskdeploy` will deploy the package according to the manifest and deployment files in the root folder of `https://github.com/paulcastro/hellowhisk`.
+- `newpkg` is a dependency to an external package whose source code is in a sub folder `helloworld` in git repo `https://github.com/daisy-ycguo/wskdeploy-test`. `wskdeploy` will deploy the package according to the manifest and deployment files in the folder `helloworld` in `https://github.com/daisy-ycguo/wskdeploy-test`. When `wskdeploy` notices the dependency name `newpkg` is different from the original package name `myhelloworld`, it will create a package binding `newpkg` to `myhellowo [...]
+```
+sequences:
+  mySequence:
+    actions: hellowhisk/greeting, hellowhisk/httpGet, newpkg/helloworld
+```
+- `myCloudant` is a binding to the existing system package `/whisk.system/cloudant`.  `wskdeploy` will create a package binding `myCloudant` to `/whisk.system/cloudant` with the input parameters and annotations.
+
+To install this show case, try this:
+```
+$ wskdeploy -m ./tests/usecases/dependency/manifest.yaml
+Deploying package opentest ... Done!
+Deploying dependency newpkg ... 
+Deploying package myhelloworld ... Done!
+Deploying action myhelloworld/helloworld ... Done!
+Done!
+Deploying package binding newpkg ... Done!
+Deploying dependency myCloudant ... 
+Deploying package binding myCloudant ... Done!
+Deploying dependency hellowhisk ... 
+Deploying package hellowhisk ... Done!
+Deploying action hellowhisk/httpGet ... Done!
+Deploying action hellowhisk/greeting ... Done!
+Done!
+Deploying action opentest/mySequence ... Done!
+Done!
+Deploying rule myRule ... Done!
+Deploying rule myCloudantRule ... Done!
+```
+
+To verify all the assets are deployed in OpenWhisk, try this:
+```
+$ wsk list
+Entities in namespace: <your_name_space>
+packages
+/<your_name_space>/hellowhisk                                    private
+/<your_name_space>/myCloudant                                    private
+/<your_name_space>/newpkg                                        private
+/<your_name_space>/myhelloworld                                  private
+/<your_name_space>/opentest                                      private
+actions
+/<your_name_space>/opentest/mySequence                           private sequence
+/<your_name_space>/hellowhisk/greeting                           private nodejs:6
+/<your_name_space>/hellowhisk/httpGet                            private swift:3
+/<your_name_space>/myhelloworld/helloworld                       private nodejs:6
+triggers
+/<your_name_space>/myTrigger                                     private
+rules
+/<your_name_space>/myCloudantRule                                private
+/<your_name_space>/myRule                                        private
+```
+To verify package `hellowhisk` is deployed, try this:
+```
+$ wsk package get --summary hellowhisk
+package /<your_name_space>/hellowhisk
+ action /<your_name_space>/hellowhisk/greeting
+ action /<your_name_space>/hellowhisk/httpGet
+```
+To verify package `myhelloworld` is deployed, try this:
+```
+$ wsk package get --summary myhelloworld
+package /<your_name_space>/myhelloworld
+ action /<your_name_space>/myhelloworld/helloworld
+```
+To verify a package binding `newpkg` is installed, try this:
+```
+$ wsk package get --summary newpkg
+package /<your_name_space>/newpkg
+ action /<your_name_space>/newpkg/helloworld
+```
+To verify a package binding `mycloudant` is installed, try this:
+```
+$ wsk package get --summary myCloudant
+```
+To uninstall this show case, try this:
+```
+$ wskdeploy undeploy -m ./tests/usecases/dependency/manifest.yaml
+```
diff --git a/tests/usecases/dependency/manifest.yaml b/tests/usecases/dependency/manifest.yaml
index 9b12035..680f1a1 100644
--- a/tests/usecases/dependency/manifest.yaml
+++ b/tests/usecases/dependency/manifest.yaml
@@ -3,7 +3,7 @@ package:
   dependencies:
     hellowhisk:
       location: github.com/paulcastro/hellowhisk
-    myhelloworld:
+    newpkg:
       location: github.com/daisy-ycguo/wskdeploy-test/helloworld
     myCloudant:
       location: /whisk.system/cloudant
@@ -13,7 +13,7 @@ package:
         myAnnotation: Here it is
   sequences:
     mySequence:
-      actions: hellowhisk/greeting, hellowhisk/httpGet, myhelloworld/helloworld
+      actions: hellowhisk/greeting, hellowhisk/httpGet, newpkg/helloworld
   triggers:
     myTrigger:
   rules:
diff --git a/utils/qualifiedname.go b/utils/qualifiedname.go
index 81dd2a8..9a25bd5 100644
--- a/utils/qualifiedname.go
+++ b/utils/qualifiedname.go
@@ -72,6 +72,9 @@ func ParseQualifiedName(name string, defaultNamespace string) (QualifiedName, er
 		}
 
 		qualifiedName.EntityName = name
+		if (defaultNamespace == "") {
+			defaultNamespace = "_"
+		}
 		qualifiedName.Namespace = defaultNamespace
 	}
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].