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

pdesai 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 755d4a4  Adds support for api export (#918)
755d4a4 is described below

commit 755d4a4ec2e283e4d0b958a8db9c8a1d3a6a13c9
Author: Pavel Kravchenko <[email protected]>
AuthorDate: Thu Jun 28 20:50:01 2018 +0300

    Adds support for api export (#918)
    
    * add export api support
    
    * Rebasing and bug fixing
    
    * gofmt
    
    * temporary disable export test
    
    * wip
    
    * wip
    
    * enabling TestExportApi test
---
 cmd/export.go                                     | 75 ++++++++++++++++++++++-
 tests/src/integration/export/export_test.go       | 52 +++++++++++++++-
 tests/src/integration/export/manifest_apiexp.yaml | 21 +++++++
 3 files changed, 144 insertions(+), 4 deletions(-)

diff --git a/cmd/export.go b/cmd/export.go
index 5135dba..ba42f72 100644
--- a/cmd/export.go
+++ b/cmd/export.go
@@ -152,9 +152,9 @@ func exportProject(projectName string, targetManifest 
string) error {
                                // TODO: throw if there more than single 
package managed by project
                                // currently will be a mess because triggers 
and rules managed under packages
                                // instead of the top level (similar to OW 
model)
-                               //                              if 
len(maniyaml.Packages) > 1 {
-                               //                                      return 
errors.New("currently can't work with more than one package managed by one 
project")
-                               //                              }
+                               //              if len(maniyaml.Packages) > 1 {
+                               //                  return 
errors.New("currently can't work with more than one package managed by one 
project")
+                               //              }
 
                                // perform the similar check on the list of 
actions from this package
                                // get a list of actions in your namespace
@@ -274,6 +274,75 @@ func exportProject(projectName string, targetManifest 
string) error {
 
        }
 
+       // List API request query parameters
+       apiListReqOptions := new(whisk.ApiListRequestOptions)
+       apiListReqOptions.SpaceGuid = strings.Split(client.Config.AuthToken, 
":")[0]
+       apiListReqOptions.AccessToken = client.Config.ApigwAccessToken
+
+       // Get list of APIs from OW
+       retApiList, _, err := client.Apis.List(apiListReqOptions)
+       if err != nil {
+               return err
+       }
+
+       // iterate over the list of APIs to determine whether any of them part 
of the managed project
+       retApiArray := (*whisk.RetApiArray)(retApiList)
+       for _, api := range retApiArray.Apis {
+
+               apiName := api.ApiValue.Swagger.Info.Title
+               apiBasePath := 
strings.TrimPrefix(api.ApiValue.Swagger.BasePath, "/")
+
+               // run over api paths looking for one pointing to an action 
belonging to the given project
+               for path := range api.ApiValue.Swagger.Paths {
+                       for op, opv := range 
api.ApiValue.Swagger.Paths[path].MakeOperationMap() {
+                               if len(opv.XOpenWhisk.Package) > 0 {
+                                       pkgName := opv.XOpenWhisk.Package
+
+                                       if pkg, ok := 
maniyaml.Packages[pkgName]; ok {
+                                               if pkg.Namespace == 
opv.XOpenWhisk.Namespace {
+
+                                                       // now adding the api 
to the maniyaml
+                                                       if pkg.Apis == nil {
+                                                               pkg.Apis = 
make(map[string]map[string]map[string]map[string]parsers.APIMethodResponse)
+                                                       }
+
+                                                       path = 
strings.TrimPrefix(path, "/")
+
+                                                       apiMethodResponse := 
*new(parsers.APIMethodResponse)
+                                                       splitApiUrl := 
strings.Split(opv.XOpenWhisk.ApiUrl, ".")
+                                                       responseType := 
splitApiUrl[len(splitApiUrl)-1]
+
+                                                       
apiMethodResponse.Method = op
+                                                       
apiMethodResponse.Response = responseType
+
+                                                       if pkgApi, ok := 
pkg.Apis[apiName]; ok {
+                                                               if 
pkgApiBasePath, ok := pkgApi[apiBasePath]; ok {
+                                                                       if _, 
ok := pkgApiBasePath[path]; ok {
+                                                                               
pkg.Apis[apiName][apiBasePath][path][opv.XOpenWhisk.ActionName] = 
apiMethodResponse
+                                                                       } else {
+                                                                               
pkg.Apis[apiName][apiBasePath][path] = map[string]parsers.APIMethodResponse{}
+                                                                               
pkg.Apis[apiName][apiBasePath][path][opv.XOpenWhisk.ActionName] = 
apiMethodResponse
+                                                                       }
+                                                               } else {
+                                                                       
pkg.Apis[apiName][apiBasePath] = 
map[string]map[string]parsers.APIMethodResponse{}
+                                                                       
pkg.Apis[apiName][apiBasePath][path] = map[string]parsers.APIMethodResponse{}
+                                                                       
pkg.Apis[apiName][apiBasePath][path][opv.XOpenWhisk.ActionName] = 
apiMethodResponse
+                                                               }
+                                                       } else {
+                                                               
pkg.Apis[apiName] = map[string]map[string]map[string]parsers.APIMethodResponse{}
+                                                               
pkg.Apis[apiName][apiBasePath] = 
map[string]map[string]parsers.APIMethodResponse{}
+                                                               
pkg.Apis[apiName][apiBasePath][path] = map[string]parsers.APIMethodResponse{}
+                                                               
pkg.Apis[apiName][apiBasePath][path][opv.XOpenWhisk.ActionName] = 
apiMethodResponse
+                                                       }
+
+                                                       
maniyaml.Packages[pkgName] = pkg
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
        // adding dependencies to the first package
        for pkgName := range maniyaml.Packages {
                for bPkg, binding := range bindings {
diff --git a/tests/src/integration/export/export_test.go 
b/tests/src/integration/export/export_test.go
index 6436819..7bc2ccc 100644
--- a/tests/src/integration/export/export_test.go
+++ b/tests/src/integration/export/export_test.go
@@ -1,4 +1,4 @@
-// +build skip_integration
+// +build integration
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -44,6 +44,8 @@ func TestExport(t *testing.T) {
 
        wskdeploy := common.NewWskdeploy()
 
+       defer os.RemoveAll(targetManifestFolder)
+
        _, err := wskdeploy.ManagedDeploymentOnlyManifest(manifestLib1Path)
        assert.Equal(t, nil, err, "Failed to deploy the lib1 manifest file.")
 
@@ -81,6 +83,8 @@ func SkipTestExportHelloWorld(t *testing.T) {
        targetManifestFolder := os.Getenv("GOPATH") + EXPORT_TEST_PATH + "tmp-" 
+ strconv.Itoa(rand.Intn(1000)) + "/"
        targetManifestHelloWorldPath := targetManifestFolder + "manifest-" + 
projectName + ".yaml"
 
+       defer os.RemoveAll(targetManifestFolder)
+
        wskdeploy := common.NewWskdeploy()
 
        _, err := 
wskdeploy.ManagedDeploymentManifestAndProject(manifestHelloWorldPath, 
projectName)
@@ -114,6 +118,9 @@ func TestExport2Pack(t *testing.T) {
        manifest2PackPath := os.Getenv("GOPATH") + EXPORT_TEST_PATH + 
"manifest_2pack.yaml"
        targetManifestFolder := os.Getenv("GOPATH") + EXPORT_TEST_PATH + "tmp-" 
+ strconv.Itoa(rand.Intn(1000)) + "/"
        target2PackManifestPath := targetManifestFolder + 
"exported2packmanifest.yaml"
+
+       defer os.RemoveAll(targetManifestFolder)
+
        projectName := "2pack"
        wskdeploy := common.NewWskdeploy()
 
@@ -135,3 +142,46 @@ func TestExport2Pack(t *testing.T) {
        _, err = wskdeploy.UndeployManifestPathOnly(manifest2PackPath)
        assert.Equal(t, nil, err, "Failed to undeploy")
 }
+
+func TestExportApi(t *testing.T) {
+       projectName := "ApiExp"
+       wskdeploy := common.NewWskdeploy()
+
+       defer os.RemoveAll(targetManifestFolder)
+
+       _, err := 
wskdeploy.ManagedDeploymentManifestAndProject(manifestApiExpPath, projectName)
+       assert.Equal(t, nil, err, "Failed to deploy the ApiExp manifest file.")
+
+       _, err = wskdeploy.ExportProject(projectName, targetApiExpManifestPath)
+       assert.Equal(t, nil, err, "Failed to export project.")
+
+       _, err = os.Stat(manifestApiExpPath)
+       assert.Equal(t, nil, err, "Missing exported manifest file")
+
+       _, err = os.Stat(targetManifestFolder + "api-gateway-test/greeting.js")
+       assert.Equal(t, nil, err, "Missing exported 
api-gateway-test/greeting.js")
+
+       _, err = wskdeploy.UndeployManifestPathOnly(manifestApiExpPath)
+       assert.Equal(t, nil, err, "Failed to undeploy")
+
+       _, err = 
wskdeploy.ManagedDeploymentOnlyManifest(targetApiExpManifestPath)
+       assert.Equal(t, nil, err, "Failed to redeploy the exported manifest 
file.")
+
+       _, err = wskdeploy.UndeployManifestPathOnly(targetApiExpManifestPath)
+       assert.Equal(t, nil, err, "Failed to undeploy the exported manifest 
file")
+}
+
+var (
+       manifestLib1Path = os.Getenv("GOPATH") + 
"/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_lib1.yaml"
+       manifestLib2Path = os.Getenv("GOPATH") + 
"/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_lib2.yaml"
+       manifestExtPath  = os.Getenv("GOPATH") + 
"/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_ext.yaml"
+
+       targetManifestFolder = os.Getenv("GOPATH") + 
"/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/tmp/"
+       targetManifestPath   = targetManifestFolder + "manifest.yaml"
+
+       manifest2PackPath       = os.Getenv("GOPATH") + 
"/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_2pack.yaml"
+       target2PackManifestPath = targetManifestFolder + 
"exported2packmanifest.yaml"
+
+       manifestApiExpPath       = os.Getenv("GOPATH") + 
"/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/export/manifest_apiexp.yaml"
+       targetApiExpManifestPath = targetManifestFolder + 
"exportedapimanifest.yaml"
+)
diff --git a/tests/src/integration/export/manifest_apiexp.yaml 
b/tests/src/integration/export/manifest_apiexp.yaml
new file mode 100644
index 0000000..9efff09
--- /dev/null
+++ b/tests/src/integration/export/manifest_apiexp.yaml
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+# license agreements; and to You under the Apache License, Version 2.0.
+
+packages:
+    api-gateway-test:
+        version: 1.0
+        license: Apache-2.0
+        actions:
+            greeting:
+                web-export: true
+                version: 1.0
+                function: src/greeting.js
+                runtime: nodejs:6
+        # new top-level key for defining groups of named APIs
+        apis:
+            hello-world:
+                hello:
+                    world:
+                        greeting:
+                            method: GET
+                            response: http

Reply via email to