openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mrutkow...@apache.org
Subject [incubator-openwhisk-wskdeploy] branch master updated: Support both manifest.yaml and manifest.yml (#310)
Date Thu, 17 Aug 2017 21:12:20 GMT
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 162ad2e  Support both manifest.yaml and manifest.yml (#310)
162ad2e is described below

commit 162ad2e6442792d6f5624694bf5bd07cd6e998d6
Author: David Liu <david.liu@cn.ibm.com>
AuthorDate: Fri Aug 18 05:12:18 2017 +0800

    Support both manifest.yaml and manifest.yml (#310)
    
    * Support both manifest.yaml and manifest.yml
    Mitigate same variable copy around.
    
    * Move shared flags in cmdImp package to utils.
    
    * Add more integration tests for flags.
---
 cmd/init.go                                      |   8 +-
 cmd/report.go                                    |  11 +-
 cmd/root.go                                      | 171 ++++++++++++++++++++---
 cmd/root_test.go                                 |  26 ++--
 cmd/undeploy.go                                  |  16 +--
 cmd/version.go                                   |   4 +-
 cmdImp/rootImp.go                                | 128 -----------------
 cmdImp/shared.go                                 |  32 -----
 cmdImp/undeployImp.go                            |  82 -----------
 main.go                                          |   6 +-
 parsers/manifest_parser.go                       |   6 +-
 parsers/yamlparser.go                            |   2 +-
 tests/src/integration/common/wskdeploy.go        |  36 +++--
 tests/src/integration/common/wskprops.go         |  40 +++---
 tests/src/integration/flagstests/deployment.yml  |  15 ++
 tests/src/integration/flagstests/flags_test.go   |  84 +++++++++++
 tests/src/integration/flagstests/manifest.yaml   |  24 ++++
 tests/src/integration/flagstests/manifest.yml    |  24 ++++
 tests/src/integration/flagstests/src/greeting.js |  11 ++
 utils/flags.go                                   |   9 ++
 20 files changed, 389 insertions(+), 346 deletions(-)

diff --git a/cmd/init.go b/cmd/init.go
index ac17666..1628aa7 100644
--- a/cmd/init.go
+++ b/cmd/init.go
@@ -19,13 +19,11 @@ package cmd
 
 import (
 	"bufio"
-	"os"
-	"path/filepath"
-
-	"github.com/apache/incubator-openwhisk-wskdeploy/cmdImp"
 	"github.com/apache/incubator-openwhisk-wskdeploy/parsers"
 	"github.com/apache/incubator-openwhisk-wskdeploy/utils"
 	"github.com/spf13/cobra"
+	"os"
+	"path/filepath"
 )
 
 var initCmd = &cobra.Command{
@@ -49,7 +47,7 @@ var initCmd = &cobra.Command{
 
 func askName(reader *bufio.Reader, def string) string {
 	if len(def) == 0 {
-		abspath, err := filepath.Abs(cmdImp.ProjectPath)
+		abspath, err := filepath.Abs(utils.Flags.ProjectPath)
 		utils.Check(err)
 		def = filepath.Base(abspath)
 	}
diff --git a/cmd/report.go b/cmd/report.go
index 5fc85e2..e5d6ba1 100644
--- a/cmd/report.go
+++ b/cmd/report.go
@@ -19,17 +19,14 @@ package cmd
 
 import (
 	"fmt"
-
-	"path"
-	"sync"
-
 	"github.com/apache/incubator-openwhisk-client-go/whisk"
-	"github.com/apache/incubator-openwhisk-wskdeploy/cmdImp"
 	"github.com/apache/incubator-openwhisk-wskdeploy/deployers"
 	"github.com/apache/incubator-openwhisk-wskdeploy/utils"
 	"github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
 	"github.com/fatih/color"
 	"github.com/spf13/cobra"
+	"path"
+	"sync"
 )
 
 var wskpropsPath string
@@ -47,12 +44,12 @@ located under current user home.`,
 	Run: func(cmd *cobra.Command, args []string) {
 		// TODO: Work your own magic here
 		if wskpropsPath != "" {
-			client, _ = deployers.NewWhiskClient(wskpropsPath, cmdImp.DeploymentPath, false)
+			client, _ = deployers.NewWhiskClient(wskpropsPath, utils.Flags.DeploymentPath, false)
 		}
 		userHome := utils.GetHomeDirectory()
 		//default to ~/.wskprops
 		propPath := path.Join(userHome, ".wskprops")
-		client, _ = deployers.NewWhiskClient(propPath, cmdImp.DeploymentPath, false)
+		client, _ = deployers.NewWhiskClient(propPath, utils.Flags.DeploymentPath, false)
 		printDeploymentInfo(client)
 	},
 }
diff --git a/cmd/root.go b/cmd/root.go
index 837907e..539bd46 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -21,18 +21,18 @@ import (
 	"fmt"
 	"log"
 	"os"
-
-	"github.com/apache/incubator-openwhisk-wskdeploy/cmdImp"
 	"github.com/apache/incubator-openwhisk-wskdeploy/utils"
 	"github.com/spf13/cobra"
 	"github.com/spf13/viper"
-
+	"github.com/apache/incubator-openwhisk-client-go/whisk"
 	"regexp"
-
 	"encoding/json"
 	"errors"
 	"github.com/apache/incubator-openwhisk-client-go/wski18n"
 	"strings"
+	"path"
+	"github.com/apache/incubator-openwhisk-wskdeploy/deployers"
+	"path/filepath"
 )
 
 var RootCmd = &cobra.Command{
@@ -48,15 +48,8 @@ wskdeploy without any commands or flags deploys openwhisk package in the
current
 	Run: RootCmdImp,
 }
 
-var Deploy = cmdImp.Deploy
-
 func RootCmdImp(cmd *cobra.Command, args []string) {
-	// Set all the parameters passed via the command to the struct of wskdeploy command.
-	deployParams := cmdImp.DeployParams{cmdImp.Verbose, cmdImp.ProjectPath, cmdImp.ManifestPath,
-		cmdImp.DeploymentPath, cmdImp.UseDefaults, cmdImp.UseInteractive}
-	// Call the implementation of wskdeploy command.
-	Deploy(deployParams)
-
+	Deploy()
 }
 
 // Execute adds all child commands to the root command sets flags appropriately.
@@ -113,16 +106,16 @@ func init() {
 	// Cobra supports Persistent Flags, which, if defined here,
 	// will be global for your application.
 
-	RootCmd.PersistentFlags().StringVar(&cmdImp.CfgFile, "config", "", "config file (default
is $HOME/.wskdeploy.yaml)")
+	RootCmd.PersistentFlags().StringVar(&utils.Flags.CfgFile, "config", "", "config file
(default is $HOME/.wskdeploy.yaml)")
 	// Cobra also supports local flags, which will only run
 	// when this action is called directly.
 	RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
-	RootCmd.Flags().StringVarP(&cmdImp.ProjectPath, "pathpath", "p", ".", "path to serverless
project")
-	RootCmd.Flags().StringVarP(&cmdImp.ManifestPath, "manifest", "m", "", "path to manifest
file")
-	RootCmd.Flags().StringVarP(&cmdImp.DeploymentPath, "deployment", "d", "", "path to deployment
file")
-	RootCmd.PersistentFlags().BoolVarP(&cmdImp.UseInteractive, "allow-interactive", "i",
!utils.Flags.WithinOpenWhisk, "allow interactive prompts")
-	RootCmd.PersistentFlags().BoolVarP(&cmdImp.UseDefaults, "allow-defaults", "a", false,
"allow defaults")
-	RootCmd.PersistentFlags().BoolVarP(&cmdImp.Verbose, "verbose", "v", false, "verbose
output")
+	RootCmd.Flags().StringVarP(&utils.Flags.ProjectPath, "pathpath", "p", ".", "path to
serverless project")
+	RootCmd.Flags().StringVarP(&utils.Flags.ManifestPath, "manifest", "m", "", "path to
manifest file")
+	RootCmd.Flags().StringVarP(&utils.Flags.DeploymentPath, "deployment", "d", "", "path
to deployment file")
+	RootCmd.PersistentFlags().BoolVarP(&utils.Flags.UseInteractive, "allow-interactive",
"i", !utils.Flags.WithinOpenWhisk, "allow interactive prompts")
+	RootCmd.PersistentFlags().BoolVarP(&utils.Flags.UseDefaults, "allow-defaults", "a",
false, "allow defaults")
+	RootCmd.PersistentFlags().BoolVarP(&utils.Flags.Verbose, "verbose", "v", false, "verbose
output")
 	RootCmd.PersistentFlags().StringVarP(&utils.Flags.ApiHost, "apihost", "", "", wski18n.T("whisk
API HOST"))
 	RootCmd.PersistentFlags().StringVarP(&utils.Flags.Auth, "auth", "u", "", wski18n.T("authorization
`KEY`"))
 	RootCmd.PersistentFlags().StringVar(&utils.Flags.ApiVersion, "apiversion", "", wski18n.T("whisk
API `VERSION`"))
@@ -130,9 +123,9 @@ func init() {
 
 // initConfig reads in config file and ENV variables if set.
 func initConfig() {
-	if cmdImp.CfgFile != "" {
+	if utils.Flags.CfgFile != "" {
 		// enable ability to specify config file via flag
-		viper.SetConfigFile(cmdImp.CfgFile)
+		viper.SetConfigFile(utils.Flags.CfgFile)
 	}
 
 	viper.SetConfigName(".wskdeploy") // name of config file (without extension)
@@ -144,3 +137,139 @@ func initConfig() {
 		fmt.Println("Using config file:", viper.ConfigFileUsed())
 	}
 }
+
+
+func Deploy() error {
+
+	whisk.SetVerbose(utils.Flags.Verbose)
+
+	projectPath, err := filepath.Abs(utils.Flags.ProjectPath)
+	utils.Check(err)
+
+	if utils.Flags.ManifestPath == "" {
+		if _, err := os.Stat(path.Join(projectPath, "manifest.yaml")); err == nil {
+			utils.Flags.ManifestPath = path.Join(projectPath, deployers.ManifestFileNameYaml)
+			log.Printf("Using %s for deployment \n", utils.Flags.ManifestPath)
+		} else if _, err := os.Stat(path.Join(projectPath, "manifest.yml")); err == nil {
+			utils.Flags.ManifestPath = path.Join(projectPath, deployers.ManifestFileNameYml)
+			log.Printf("Using %s for deployment", utils.Flags.ManifestPath)
+		} else {
+			log.Printf("Manifest file not found at path %s", projectPath)
+			return errors.New("missing manifest.yaml file")
+		}
+	}
+
+	if utils.Flags.DeploymentPath == "" {
+		if _, err := os.Stat(path.Join(projectPath, "deployment.yaml")); err == nil {
+			utils.Flags.DeploymentPath = path.Join(projectPath, deployers.DeploymentFileNameYaml)
+		} else if _, err := os.Stat(path.Join(projectPath, "deployment.yml")); err == nil {
+			utils.Flags.DeploymentPath = path.Join(projectPath, deployers.DeploymentFileNameYml)
+		}
+	}
+
+	if utils.MayExists(utils.Flags.ManifestPath) {
+
+		var deployer = deployers.NewServiceDeployer()
+		deployer.ProjectPath = projectPath
+		deployer.ManifestPath = utils.Flags.ManifestPath
+		deployer.DeploymentPath = utils.Flags.DeploymentPath
+		// perform some quick check here.
+		go func() {
+			deployer.Check()
+		}()
+		deployer.IsDefault = utils.Flags.UseDefaults
+
+		deployer.IsInteractive = utils.Flags.UseInteractive
+
+		// master record of any dependency that has been downloaded
+		deployer.DependencyMaster = make(map[string]utils.DependencyRecord)
+
+		propPath := ""
+		if !utils.Flags.WithinOpenWhisk {
+			userHome := utils.GetHomeDirectory()
+			propPath = path.Join(userHome, ".wskprops")
+		}
+		whiskClient, clientConfig := deployers.NewWhiskClient(propPath, utils.Flags.DeploymentPath,
deployer.IsInteractive)
+		deployer.Client = whiskClient
+		deployer.ClientConfig = clientConfig
+
+		err := deployer.ConstructDeploymentPlan()
+
+		if err != nil {
+			utils.Check(err)
+			return err
+		}
+
+		err = deployer.Deploy()
+		if err != nil {
+			utils.Check(err)
+			return err
+		} else {
+			return nil
+		}
+
+	} else {
+		if utils.Flags.WithinOpenWhisk {
+			utils.PrintOpenWhiskError(wski18n.T("missing manifest.yaml file"))
+			return errors.New("missing manifest.yaml file")
+		} else {
+			log.Println("missing manifest.yaml file")
+			return errors.New("missing manifest.yaml file")
+		}
+	}
+
+}
+
+func Undeploy() error {
+	// TODO: Work your own magic here
+	whisk.SetVerbose(utils.Flags.Verbose)
+
+	if utils.Flags.ManifestPath == "" {
+		if ok, _ := regexp.Match(deployers.ManifestFileNameYml, []byte(utils.Flags.ManifestPath));
ok {
+			utils.Flags.ManifestPath = path.Join(utils.Flags.ProjectPath, deployers.ManifestFileNameYml)
+		} else {
+			utils.Flags.ManifestPath = path.Join(utils.Flags.ProjectPath, deployers.ManifestFileNameYaml)
+		}
+
+	}
+
+	if utils.Flags.DeploymentPath == "" {
+		if ok, _ := regexp.Match(deployers.DeploymentFileNameYml, []byte(utils.Flags.ManifestPath));
ok {
+			utils.Flags.DeploymentPath = path.Join(utils.Flags.ProjectPath, deployers.DeploymentFileNameYml)
+		} else {
+			utils.Flags.DeploymentPath = path.Join(utils.Flags.ProjectPath, deployers.DeploymentFileNameYaml)
+		}
+
+	}
+
+	if utils.FileExists(utils.Flags.ManifestPath) {
+
+		var deployer = deployers.NewServiceDeployer()
+		deployer.ProjectPath = utils.Flags.ProjectPath
+		deployer.ManifestPath = utils.Flags.ManifestPath
+		deployer.DeploymentPath = utils.Flags.DeploymentPath
+
+		deployer.IsInteractive = utils.Flags.UseInteractive
+		deployer.IsDefault = utils.Flags.UseDefaults
+
+		userHome := utils.GetHomeDirectory()
+		propPath := path.Join(userHome, ".wskprops")
+
+		whiskClient, clientConfig := deployers.NewWhiskClient(propPath, utils.Flags.DeploymentPath,
deployer.IsInteractive)
+		deployer.Client = whiskClient
+		deployer.ClientConfig = clientConfig
+
+		verifiedPlan, err := deployer.ConstructUnDeploymentPlan()
+		err = deployer.UnDeploy(verifiedPlan)
+		if err != nil {
+			utils.Check(err)
+			return err
+		} else {
+			return nil
+		}
+
+	} else {
+		log.Println("missing manifest.yaml file")
+		return errors.New("missing manifest.yaml file")
+	}
+}
diff --git a/cmd/root_test.go b/cmd/root_test.go
index e75410d..3bb9ad0 100644
--- a/cmd/root_test.go
+++ b/cmd/root_test.go
@@ -21,7 +21,6 @@ package cmd
 
 import (
 	"bytes"
-	"github.com/apache/incubator-openwhisk-wskdeploy/cmdImp"
 	"github.com/apache/incubator-openwhisk-wskdeploy/utils"
 	"github.com/spf13/cobra"
 	"github.com/stretchr/testify/assert"
@@ -31,17 +30,8 @@ import (
 
 var rootcalled bool
 
-type RootCommand struct {
-}
-
-func (rootCommand *RootCommand) Deploy(params cmdImp.DeployParams) error {
-	rootcalled = true
-	return nil
-}
-
 func functionMock() {
-	rootCommand := &RootCommand{}
-	Deploy = rootCommand.Deploy
+	rootcalled = true
 }
 
 type resulter struct {
@@ -112,13 +102,13 @@ func checkValidAuthInfo(t *testing.T, expected_auth_flags Auth_flags)
{
 }
 
 func checkValidInputInfo(t *testing.T, expected_input Input) {
-	assert.Equal(t, expected_input.CfgFile, cmdImp.CfgFile, "CfgFile does not match.")
-	assert.Equal(t, expected_input.Verbose, cmdImp.Verbose, "Verbose does not match.")
-	assert.Equal(t, expected_input.UseDefaults, cmdImp.UseDefaults, "UseDefaults does not match.")
-	assert.Equal(t, expected_input.UseInteractive, cmdImp.UseInteractive, "ApiHoUseInteractivest
does not match.")
-	assert.Equal(t, expected_input.ProjectPath, cmdImp.ProjectPath, "ProjectPath does not match.")
-	assert.Equal(t, expected_input.DeploymentPath, cmdImp.DeploymentPath, "DeploymentPath does
not match.")
-	assert.Equal(t, expected_input.ManifestPath, cmdImp.ManifestPath, "ManifestPath does not
match.")
+	assert.Equal(t, expected_input.CfgFile, utils.Flags.CfgFile, "CfgFile does not match.")
+	assert.Equal(t, expected_input.Verbose, utils.Flags.Verbose, "Verbose does not match.")
+	assert.Equal(t, expected_input.UseDefaults, utils.Flags.UseDefaults, "UseDefaults does not
match.")
+	assert.Equal(t, expected_input.UseInteractive, utils.Flags.UseInteractive, "ApiHoUseInteractivest
does not match.")
+	assert.Equal(t, expected_input.ProjectPath, utils.Flags.ProjectPath, "ProjectPath does not
match.")
+	assert.Equal(t, expected_input.DeploymentPath, utils.Flags.DeploymentPath, "DeploymentPath
does not match.")
+	assert.Equal(t, expected_input.ManifestPath, utils.Flags.ManifestPath, "ManifestPath does
not match.")
 }
 
 func composeCommand(auth Auth_flags, input Input) string {
diff --git a/cmd/undeploy.go b/cmd/undeploy.go
index 0a8db95..0fcb1ac 100644
--- a/cmd/undeploy.go
+++ b/cmd/undeploy.go
@@ -18,7 +18,7 @@
 package cmd
 
 import (
-	"github.com/apache/incubator-openwhisk-wskdeploy/cmdImp"
+	"github.com/apache/incubator-openwhisk-wskdeploy/utils"
 	"github.com/spf13/cobra"
 )
 
@@ -31,11 +31,7 @@ var undeployCmd = &cobra.Command{
 }
 
 func UndeployCmdImp(cmd *cobra.Command, args []string) {
-	// Set all the parameters passed via the command to the struct of undeploy command.
-	undeployParams := cmdImp.DeployParams{cmdImp.Verbose, cmdImp.ProjectPath, cmdImp.ManifestPath,
-		cmdImp.DeploymentPath, cmdImp.UseDefaults, cmdImp.UseInteractive}
-	// Call the implementation of wskdeploy command.
-	cmdImp.Undeploy(undeployParams)
+	Undeploy()
 }
 
 func init() {
@@ -46,12 +42,12 @@ func init() {
 	// Cobra supports Persistent Flags which will work for this command
 	// and all subcommands, e.g.:
 	// undeployCmd.PersistentFlags().String("foo", "", "A help for foo")
-	undeployCmd.PersistentFlags().StringVar(&cmdImp.CfgFile, "config", "", "config file
(default is $HOME/.wskdeploy.yaml)")
+	undeployCmd.PersistentFlags().StringVar(&utils.Flags.CfgFile, "config", "", "config
file (default is $HOME/.wskdeploy.yaml)")
 	// Cobra supports local flags which will only run when this command
 	// is called directly, e.g.:
 	// undeployCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")=
 	undeployCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
-	undeployCmd.Flags().StringVarP(&cmdImp.ProjectPath, "pathpath", "p", ".", "path to serverless
project")
-	undeployCmd.Flags().StringVarP(&cmdImp.ManifestPath, "manifest", "m", "", "path to manifest
file")
-	undeployCmd.Flags().StringVarP(&cmdImp.DeploymentPath, "deployment", "d", "", "path
to deployment file")
+	undeployCmd.Flags().StringVarP(&utils.Flags.ProjectPath, "pathpath", "p", ".", "path
to serverless project")
+	undeployCmd.Flags().StringVarP(&utils.Flags.ManifestPath, "manifest", "m", "", "path
to manifest file")
+	undeployCmd.Flags().StringVarP(&utils.Flags.DeploymentPath, "deployment", "d", "", "path
to deployment file")
 }
diff --git a/cmd/version.go b/cmd/version.go
index 63f0379..9a996e5 100644
--- a/cmd/version.go
+++ b/cmd/version.go
@@ -19,7 +19,7 @@ package cmd
 
 import (
 	"fmt"
-	"github.com/apache/incubator-openwhisk-wskdeploy/cmdImp"
+	"github.com/apache/incubator-openwhisk-wskdeploy/utils"
 	"github.com/spf13/cobra"
 )
 
@@ -32,6 +32,6 @@ var versionCmd = &cobra.Command{
 	Short: "Print the version number of openwhisk-wskdeploy",
 	Long:  `Print the version number of openwhisk-wskdeploy`,
 	Run: func(cmd *cobra.Command, args []string) {
-		fmt.Printf("openwhisk-wskdeploy version is %s--%s\n", cmdImp.CliBuild, cmdImp.CliVersion)
+		fmt.Printf("openwhisk-wskdeploy version is %s--%s\n", utils.Flags.CliBuild, utils.Flags.CliVersion)
 	},
 }
diff --git a/cmdImp/rootImp.go b/cmdImp/rootImp.go
deleted file mode 100644
index 833e696..0000000
--- a/cmdImp/rootImp.go
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package cmdImp
-
-import (
-	"errors"
-	"github.com/apache/incubator-openwhisk-client-go/whisk"
-	"github.com/apache/incubator-openwhisk-client-go/wski18n"
-	"github.com/apache/incubator-openwhisk-wskdeploy/deployers"
-	"github.com/apache/incubator-openwhisk-wskdeploy/utils"
-	"log"
-	"os"
-	"path"
-	"path/filepath"
-	"regexp"
-)
-
-type DeployParams struct {
-	Verbose        bool
-	ProjectPath    string
-	ManifestPath   string
-	DeploymentPath string
-	UseDefaults    bool
-	UseInteractive bool
-}
-
-func Deploy(params DeployParams) error {
-
-	whisk.SetVerbose(params.Verbose)
-
-	projectPath, err := filepath.Abs(params.ProjectPath)
-	utils.Check(err)
-
-	if params.ManifestPath == "" {
-		if ok, _ := regexp.Match(deployers.ManifestFileNameYml, []byte(params.ManifestPath)); ok
{
-			params.ManifestPath = path.Join(projectPath, deployers.ManifestFileNameYml)
-		} else {
-			params.ManifestPath = path.Join(projectPath, deployers.ManifestFileNameYaml)
-		}
-	} else {
-		if _, err := os.Stat(path.Join(projectPath, "manifest.yaml")); err == nil {
-			params.ManifestPath = path.Join(projectPath, deployers.ManifestFileNameYaml)
-		} else if _, err := os.Stat(path.Join(projectPath, "manifest.yml")); err == nil {
-			params.ManifestPath = path.Join(projectPath, deployers.ManifestFileNameYml)
-		}
-	}
-
-	if params.DeploymentPath == "" {
-		if ok, _ := regexp.Match(deployers.DeploymentFileNameYml, []byte(params.ManifestPath));
ok {
-			params.DeploymentPath = path.Join(projectPath, deployers.DeploymentFileNameYml)
-		} else {
-			params.DeploymentPath = path.Join(projectPath, deployers.DeploymentFileNameYaml)
-		}
-	} else {
-		if _, err := os.Stat(path.Join(projectPath, "deployment.yaml")); err == nil {
-			params.DeploymentPath = path.Join(projectPath, deployers.DeploymentFileNameYaml)
-		} else if _, err := os.Stat(path.Join(projectPath, "deployment.yml")); err == nil {
-			params.DeploymentPath = path.Join(projectPath, deployers.DeploymentFileNameYml)
-		}
-	}
-
-	if utils.MayExists(params.ManifestPath) {
-
-		var deployer = deployers.NewServiceDeployer()
-		deployer.ProjectPath = projectPath
-		deployer.ManifestPath = params.ManifestPath
-		deployer.DeploymentPath = params.DeploymentPath
-		// perform some quick check here.
-		go func() {
-			deployer.Check()
-		}()
-		deployer.IsDefault = params.UseDefaults
-
-		deployer.IsInteractive = params.UseInteractive
-
-		// master record of any dependency that has been downloaded
-		deployer.DependencyMaster = make(map[string]utils.DependencyRecord)
-
-		propPath := ""
-		if !utils.Flags.WithinOpenWhisk {
-			userHome := utils.GetHomeDirectory()
-			propPath = path.Join(userHome, ".wskprops")
-		}
-		whiskClient, clientConfig := deployers.NewWhiskClient(propPath, params.DeploymentPath,
deployer.IsInteractive)
-		deployer.Client = whiskClient
-		deployer.ClientConfig = clientConfig
-
-		err := deployer.ConstructDeploymentPlan()
-
-		if err != nil {
-			utils.Check(err)
-			return err
-		}
-
-		err = deployer.Deploy()
-		if err != nil {
-			utils.Check(err)
-			return err
-		} else {
-			return nil
-		}
-
-	} else {
-		if utils.Flags.WithinOpenWhisk {
-			utils.PrintOpenWhiskError(wski18n.T("missing manifest.yaml file"))
-			return errors.New("missing manifest.yaml file")
-		} else {
-			log.Println("missing manifest.yaml file")
-			return errors.New("missing manifest.yaml file")
-		}
-	}
-
-}
diff --git a/cmdImp/shared.go b/cmdImp/shared.go
deleted file mode 100644
index 45d98a2..0000000
--- a/cmdImp/shared.go
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// shared.go
-package cmdImp
-
-var CfgFile string
-var CliVersion string
-var CliBuild string
-
-// used to configure service deployer for various commands
-// TODO: should move this into utils.Flags
-var Verbose bool
-var ProjectPath string
-var DeploymentPath string
-var ManifestPath string
-var UseDefaults bool
-var UseInteractive bool
diff --git a/cmdImp/undeployImp.go b/cmdImp/undeployImp.go
deleted file mode 100644
index 5543447..0000000
--- a/cmdImp/undeployImp.go
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package cmdImp
-
-import (
-	"errors"
-	"github.com/apache/incubator-openwhisk-client-go/whisk"
-	"github.com/apache/incubator-openwhisk-wskdeploy/deployers"
-	"github.com/apache/incubator-openwhisk-wskdeploy/utils"
-	"log"
-	"path"
-	"regexp"
-)
-
-func Undeploy(params DeployParams) error {
-	// TODO: Work your own magic here
-	whisk.SetVerbose(params.Verbose)
-
-	if params.ManifestPath == "" {
-		if ok, _ := regexp.Match(deployers.ManifestFileNameYml, []byte(params.ManifestPath)); ok
{
-			params.ManifestPath = path.Join(params.ProjectPath, deployers.ManifestFileNameYml)
-		} else {
-			params.ManifestPath = path.Join(params.ProjectPath, deployers.ManifestFileNameYaml)
-		}
-
-	}
-
-	if params.DeploymentPath == "" {
-		if ok, _ := regexp.Match(deployers.DeploymentFileNameYml, []byte(params.ManifestPath));
ok {
-			params.DeploymentPath = path.Join(params.ProjectPath, deployers.DeploymentFileNameYml)
-		} else {
-			params.DeploymentPath = path.Join(params.ProjectPath, deployers.DeploymentFileNameYaml)
-		}
-
-	}
-
-	if utils.FileExists(params.ManifestPath) {
-
-		var deployer = deployers.NewServiceDeployer()
-		deployer.ProjectPath = params.ProjectPath
-		deployer.ManifestPath = params.ManifestPath
-		deployer.DeploymentPath = params.DeploymentPath
-
-		deployer.IsInteractive = params.UseInteractive
-		deployer.IsDefault = params.UseDefaults
-
-		userHome := utils.GetHomeDirectory()
-		propPath := path.Join(userHome, ".wskprops")
-
-		whiskClient, clientConfig := deployers.NewWhiskClient(propPath, params.DeploymentPath,
deployer.IsInteractive)
-		deployer.Client = whiskClient
-		deployer.ClientConfig = clientConfig
-
-		verifiedPlan, err := deployer.ConstructUnDeploymentPlan()
-		err = deployer.UnDeploy(verifiedPlan)
-		if err != nil {
-			utils.Check(err)
-			return err
-		} else {
-			return nil
-		}
-
-	} else {
-		log.Println("missing manifest.yaml file")
-		return errors.New("missing manifest.yaml file")
-	}
-}
diff --git a/main.go b/main.go
index 4a913ec..06c10ca 100644
--- a/main.go
+++ b/main.go
@@ -19,7 +19,7 @@ package main
 
 import (
 	"github.com/apache/incubator-openwhisk-wskdeploy/cmd"
-	"github.com/apache/incubator-openwhisk-wskdeploy/cmdImp"
+	"github.com/apache/incubator-openwhisk-wskdeploy/utils"
 )
 
 func main() {
@@ -34,6 +34,6 @@ var (
 )
 
 func init() {
-	cmdImp.CliVersion = Version
-	cmdImp.CliBuild = Build
+	utils.Flags.CliVersion = Version
+	utils.Flags.CliBuild = Build
 }
diff --git a/parsers/manifest_parser.go b/parsers/manifest_parser.go
index c3e7003..8d7113c 100644
--- a/parsers/manifest_parser.go
+++ b/parsers/manifest_parser.go
@@ -288,9 +288,9 @@ func (dm *YAMLParser) ComposeActions(mani *ManifestYAML, manipath string)
(ar []
 			wskaction.Exec.Kind = action.Runtime
 		}
 
-                // we can specify the name of the action entry point using main
-		if (action.Main != "") {
-                        wskaction.Exec.Main = action.Main
+		// we can specify the name of the action entry point using main
+		if action.Main != "" {
+			wskaction.Exec.Main = action.Main
 		}
 
 		keyValArr := make(whisk.KeyValueArr, 0)
diff --git a/parsers/yamlparser.go b/parsers/yamlparser.go
index b768525..6be7b44 100644
--- a/parsers/yamlparser.go
+++ b/parsers/yamlparser.go
@@ -64,7 +64,7 @@ type Action struct {
 	//Parameters  map[string]interface{} `yaml:parameters` // used in manifest.yaml
 	ExposedUrl string `yaml:"exposedUrl"` // used in manifest.yaml
 	Webexport  string `yaml:"web-export"` // used in manifest.yaml
-        Main       string `yaml:"main"`       // used in manifest.yaml
+	Main       string `yaml:"main"`       // used in manifest.yaml
 }
 
 type Sequence struct {
diff --git a/tests/src/integration/common/wskdeploy.go b/tests/src/integration/common/wskdeploy.go
index 0cf89ea..c22978e 100644
--- a/tests/src/integration/common/wskdeploy.go
+++ b/tests/src/integration/common/wskdeploy.go
@@ -18,38 +18,46 @@
 package common
 
 import (
-    "os"
-    "os/exec"
+	"os"
+	"os/exec"
 )
 
 const cmd = "wskdeploy"
 
 type Wskdeploy struct {
-    Path string
-    Dir  string
+	Path string
+	Dir  string
 }
 
 func NewWskdeploy() *Wskdeploy {
-    return NewWskWithPath(os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/")
+	return NewWskWithPath(os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/")
 }
 
 func NewWskWithPath(path string) *Wskdeploy {
-    var dep Wskdeploy
-    dep.Path = cmd
-    dep.Dir = path
-    return &dep
+	var dep Wskdeploy
+	dep.Path = cmd
+	dep.Dir = path
+	return &dep
 }
 
 func (wskdeploy *Wskdeploy) RunCommand(s ...string) ([]byte, error) {
-    command := exec.Command(wskdeploy.Path, s...)
-    command.Dir = wskdeploy.Dir
-    return command.CombinedOutput()
+	command := exec.Command(wskdeploy.Path, s...)
+	command.Dir = wskdeploy.Dir
+	return command.CombinedOutput()
 }
 
 func (wskdeploy *Wskdeploy) Deploy(manifestPath string, deploymentPath string) ([]byte, error)
{
-    return wskdeploy.RunCommand("-m", manifestPath, "-d", deploymentPath)
+	return wskdeploy.RunCommand("-m", manifestPath, "-d", deploymentPath)
 }
 
 func (wskdeploy *Wskdeploy) Undeploy(manifestPath string, deploymentPath string) ([]byte,
error) {
-    return wskdeploy.RunCommand("undeploy", "-m", manifestPath, "-d", deploymentPath)
+	return wskdeploy.RunCommand("undeploy", "-m", manifestPath, "-d", deploymentPath)
+}
+
+func (wskdeploy *Wskdeploy) DeployProjectPathOnly(projectPath string) ([]byte, error) {
+        return wskdeploy.RunCommand("-p", projectPath)
+}
+
+func (wskdeploy *Wskdeploy) DeployManifestPathOnly(manifestpath string) ([]byte, error) {
+	return wskdeploy.RunCommand("-p", manifestpath)
 }
diff --git a/tests/src/integration/common/wskprops.go b/tests/src/integration/common/wskprops.go
index ebe12e5..aea9889 100644
--- a/tests/src/integration/common/wskprops.go
+++ b/tests/src/integration/common/wskprops.go
@@ -18,33 +18,33 @@
 package common
 
 import (
-    "github.com/spf13/viper"
-    "io/ioutil"
-    "os"
+	"github.com/spf13/viper"
+	"io/ioutil"
+	"os"
 )
 
 type Wskprops struct {
-    APIHost string
-    AuthKey string
+	APIHost string
+	AuthKey string
 }
 
 func GetWskprops() *Wskprops {
-    var dep Wskprops
-    dep.APIHost = ""
-    dep.AuthKey = ""
+	var dep Wskprops
+	dep.APIHost = ""
+	dep.AuthKey = ""
 
-    viper.SetConfigName("whisk")
-    viper.AddConfigPath(os.Getenv("OPENWHISK_HOME"))
+	viper.SetConfigName("whisk")
+	viper.AddConfigPath(os.Getenv("OPENWHISK_HOME"))
 
-    err := viper.ReadInConfig()
-    if err == nil {
-        authPath := viper.GetString("testing.auth")
+	err := viper.ReadInConfig()
+	if err == nil {
+		authPath := viper.GetString("testing.auth")
 
-        b, err := ioutil.ReadFile(authPath)
-        if err == nil {
-            dep.AuthKey = string(b)
-        }
-        dep.APIHost = viper.GetString("router.host")
-    }
-    return &dep
+		b, err := ioutil.ReadFile(authPath)
+		if err == nil {
+			dep.AuthKey = string(b)
+		}
+		dep.APIHost = viper.GetString("router.host")
+	}
+	return &dep
 }
diff --git a/tests/src/integration/flagstests/deployment.yml b/tests/src/integration/flagstests/deployment.yml
new file mode 100644
index 0000000..74b349c
--- /dev/null
+++ b/tests/src/integration/flagstests/deployment.yml
@@ -0,0 +1,15 @@
+application:
+  name: wskdeploy-samples
+  namespace: guest
+  credential: 23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP
+  baseUrl: https://172.17.0.1/api
+
+  package:
+    triggerrule:
+      name: helloworld
+      namespace: guest
+      actions:
+        greeting:
+          inputs:
+            name: Bernie
+            place: Vermont
diff --git a/tests/src/integration/flagstests/flags_test.go b/tests/src/integration/flagstests/flags_test.go
new file mode 100644
index 0000000..0340658
--- /dev/null
+++ b/tests/src/integration/flagstests/flags_test.go
@@ -0,0 +1,84 @@
+// +build integration
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests
+
+import (
+	"github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/common"
+	"github.com/stretchr/testify/assert"
+	"os"
+	"testing"
+)
+
+var wskprops = common.GetWskprops()
+
+// support only projectpath flag
+func TestSupportProjectPath(t *testing.T) {
+	os.Setenv("__OW_API_HOST", wskprops.APIHost)
+	wskdeploy := common.NewWskdeploy()
+	projectPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests"
+	_, err := wskdeploy.DeployProjectPathOnly(projectPath)
+	assert.Equal(t, nil, err, "Failed to deploy based on the projectpath")
+}
+
+// support only projectpath with trailing slash
+func TestSupportProjectPathTrailingSlash(t *testing.T) {
+	os.Setenv("__OW_API_HOST", wskprops.APIHost)
+	wskdeploy := common.NewWskdeploy()
+	projectPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests"
+ "/"
+	_, err := wskdeploy.DeployProjectPathOnly(projectPath)
+	assert.Equal(t, nil, err, "Failed to deploy based on the projectpath")
+}
+// only a yaml manifest
+func TestSupportManifestYamlPath(t *testing.T) {
+	os.Setenv("__OW_API_HOST", wskprops.APIHost)
+	wskdeploy := common.NewWskdeploy()
+	manifestPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests/manifest.yaml"
+	_, err := wskdeploy.DeployManifestPathOnly(manifestPath)
+	assert.Equal(t, nil, err, "Failed to deploy based on the manifestpath")
+}
+
+// only a yml manifest
+func TestSupportManifestYmlPath(t *testing.T) {
+	os.Setenv("__OW_API_HOST", wskprops.APIHost)
+	wskdeploy := common.NewWskdeploy()
+	manifestPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests/manifest.yml"
+	_, err := wskdeploy.DeployManifestPathOnly(manifestPath)
+	assert.Equal(t, nil, err, "Failed to deploy based on the manifestpath")
+}
+
+// manifest yaml and deployment yaml
+func TestSupportManifestYamlDeployment(t *testing.T) {
+	os.Setenv("__OW_API_HOST", wskprops.APIHost)
+	wskdeploy := common.NewWskdeploy()
+	manifestPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests/manifest.yaml"
+	deploymentPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests/deployment.yml"
+	_, err := wskdeploy.Deploy(manifestPath,deploymentPath)
+	assert.Equal(t, nil, err, "Failed to deploy based on the manifestpath and deploymentpath.")
+}
+
+// manifest yml and deployment yaml
+func TestSupportManifestYmlDeployment(t *testing.T) {
+	os.Setenv("__OW_API_HOST", wskprops.APIHost)
+	wskdeploy := common.NewWskdeploy()
+	manifestPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests/manifest.yml"
+	deploymentPath := os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/src/integration/flagstests/deployment.yml"
+	_, err := wskdeploy.Deploy(manifestPath,deploymentPath)
+	assert.Equal(t, nil, err, "Failed to deploy based on the manifestpath and deploymentpath.")
+}
diff --git a/tests/src/integration/flagstests/manifest.yaml b/tests/src/integration/flagstests/manifest.yaml
new file mode 100644
index 0000000..42835a5
--- /dev/null
+++ b/tests/src/integration/flagstests/manifest.yaml
@@ -0,0 +1,24 @@
+package:
+  name: helloworld
+  version: 1.0
+  license: Apache-2.0
+  actions:
+    greeting:
+      web-export: true
+      version: 1.0
+      location: src/greeting.js
+      runtime: nodejs:6
+      inputs:
+        name: string
+        place: string
+      outputs:
+        payload: string
+  triggers:
+    locationUpdate:
+  rules:
+    myRule:
+      trigger: locationUpdate
+      #the action name and the action file greeting.js should consistent.
+      #currently the implementation deside the action name consistent with action file name?
+      action: greeting
+
diff --git a/tests/src/integration/flagstests/manifest.yml b/tests/src/integration/flagstests/manifest.yml
new file mode 100644
index 0000000..42835a5
--- /dev/null
+++ b/tests/src/integration/flagstests/manifest.yml
@@ -0,0 +1,24 @@
+package:
+  name: helloworld
+  version: 1.0
+  license: Apache-2.0
+  actions:
+    greeting:
+      web-export: true
+      version: 1.0
+      location: src/greeting.js
+      runtime: nodejs:6
+      inputs:
+        name: string
+        place: string
+      outputs:
+        payload: string
+  triggers:
+    locationUpdate:
+  rules:
+    myRule:
+      trigger: locationUpdate
+      #the action name and the action file greeting.js should consistent.
+      #currently the implementation deside the action name consistent with action file name?
+      action: greeting
+
diff --git a/tests/src/integration/flagstests/src/greeting.js b/tests/src/integration/flagstests/src/greeting.js
new file mode 100644
index 0000000..eaa6834
--- /dev/null
+++ b/tests/src/integration/flagstests/src/greeting.js
@@ -0,0 +1,11 @@
+/**
+ * Return a simple greeting message for someone.
+ *
+ * @param name A person's name.
+ * @param place Where the person is from.
+ */
+function main(params) {
+    var name = params.name || params.payload || 'stranger';
+    var place = params.place || 'somewhere';
+    return {payload:  'Hello, ' + name + ' from ' + place + '!'};
+}
diff --git a/utils/flags.go b/utils/flags.go
index 6102645..0b18899 100644
--- a/utils/flags.go
+++ b/utils/flags.go
@@ -22,6 +22,15 @@ var Flags struct {
 	ApiHost         string // OpenWhisk API host
 	Auth            string // OpenWhisk API key
 	ApiVersion      string // OpenWhisk version
+	CfgFile         string
+	CliVersion      string
+	CliBuild        string
+	Verbose         bool
+	ProjectPath     string
+	DeploymentPath  string
+	ManifestPath    string
+	UseDefaults     bool
+	UseInteractive  bool
 
 	//action flag definition
 	//from go cli

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

Mime
View raw message