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 2018/02/27 23:47:56 UTC

[incubator-openwhisk-wskdeploy] branch master updated: removing support for use-default flag (#759)

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 33a9616  removing support for use-default flag (#759)
33a9616 is described below

commit 33a96160db5b873c394695d5c6c52cca051e39f5
Author: Priti Desai <pd...@us.ibm.com>
AuthorDate: Tue Feb 27 15:47:53 2018 -0800

    removing support for use-default flag (#759)
---
 cmd/root.go                               |   5 -
 cmd/root_test.go                          |   6 -
 deployers/filesystemreader.go             | 208 ------------------------------
 deployers/manifestreader.go               |  22 +---
 deployers/servicedeployer.go              |  25 ----
 tests/src/integration/common/wskdeploy.go |   1 -
 utils/flags.go                            |   1 -
 7 files changed, 5 insertions(+), 263 deletions(-)

diff --git a/cmd/root.go b/cmd/root.go
index 792a4b3..aeec488 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -124,7 +124,6 @@ func init() {
 	RootCmd.Flags().StringVarP(&utils.Flags.DeploymentPath, "deployment", "d", "", wski18n.T(wski18n.ID_CMD_FLAG_DEPLOYMENT))
 	RootCmd.PersistentFlags().BoolVarP(&utils.Flags.Strict, "strict", "s", false, wski18n.T(wski18n.ID_CMD_FLAG_STRICT))
 	RootCmd.PersistentFlags().BoolVarP(&utils.Flags.UseInteractive, "allow-interactive", "i", false, wski18n.T(wski18n.ID_CMD_FLAG_INTERACTIVE))
-	RootCmd.PersistentFlags().BoolVarP(&utils.Flags.UseDefaults, "allow-defaults", "a", false, wski18n.T(wski18n.ID_CMD_FLAG_DEFAULTS))
 	RootCmd.PersistentFlags().BoolVarP(&utils.Flags.Verbose, "verbose", "v", false, wski18n.T(wski18n.ID_CMD_FLAG_VERBOSE))
 	RootCmd.PersistentFlags().StringVarP(&utils.Flags.ApiHost, "apihost", "", "", wski18n.T(wski18n.ID_CMD_FLAG_API_HOST))
 	RootCmd.PersistentFlags().StringVarP(&utils.Flags.Namespace, "namespace", "n", "", wski18n.T(wski18n.ID_CMD_FLAG_NAMESPACE))
@@ -211,8 +210,6 @@ func Deploy() error {
 		deployer.ProjectPath = projectPath
 		deployer.ManifestPath = utils.Flags.ManifestPath
 		deployer.DeploymentPath = utils.Flags.DeploymentPath
-		deployer.IsDefault = utils.Flags.UseDefaults
-
 		deployer.IsInteractive = utils.Flags.UseInteractive
 
 		// master record of any dependency that has been downloaded
@@ -314,9 +311,7 @@ func Undeploy() error {
 		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
 
 		clientConfig, error := deployers.NewWhiskConfig(utils.Flags.CfgFile, utils.Flags.DeploymentPath, utils.Flags.ManifestPath, deployer.IsInteractive)
 		if error != nil {
diff --git a/cmd/root_test.go b/cmd/root_test.go
index 75c1469..c370e60 100644
--- a/cmd/root_test.go
+++ b/cmd/root_test.go
@@ -74,7 +74,6 @@ type Input struct {
 	ProjectPath    string
 	DeploymentPath string
 	ManifestPath   string
-	UseDefaults    bool
 	UseInteractive bool
 }
 
@@ -89,7 +88,6 @@ func initializeParameters() {
 
 	expected_input.CfgFile = os.Getenv("GOPATH") + "/src/github.com/apache/incubator-openwhisk-wskdeploy/tests/dat/wskprops"
 	expected_input.Verbose = true
-	expected_input.UseDefaults = true
 	expected_input.UseInteractive = true
 	expected_input.ProjectPath = "fake_project_path"
 	expected_input.DeploymentPath = "fake_deployment_path"
@@ -105,7 +103,6 @@ func checkValidAuthInfo(t *testing.T, expected_auth_flags Auth_flags) {
 func checkValidInputInfo(t *testing.T, expected_input Input) {
 	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.")
@@ -138,9 +135,6 @@ func composeCommand(auth Auth_flags, input Input) string {
 	if input.Verbose {
 		cmd = cmd + "-v "
 	}
-	if input.UseDefaults {
-		cmd = cmd + "-a "
-	}
 	if input.UseInteractive {
 		cmd = cmd + "-i "
 	}
diff --git a/deployers/filesystemreader.go b/deployers/filesystemreader.go
deleted file mode 100644
index bc91a63..0000000
--- a/deployers/filesystemreader.go
+++ /dev/null
@@ -1,208 +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 deployers
-
-import (
-	"errors"
-	"os"
-	"path/filepath"
-	"strings"
-
-	"github.com/apache/incubator-openwhisk-client-go/whisk"
-	"github.com/apache/incubator-openwhisk-wskdeploy/parsers"
-	"github.com/apache/incubator-openwhisk-wskdeploy/utils"
-	"github.com/apache/incubator-openwhisk-wskdeploy/wskderrors"
-	"github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
-	"github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
-)
-
-// name of directory that can contain source code
-const FileSystemSourceDirectoryName = "actions"
-
-type FileSystemReader struct {
-	serviceDeployer *ServiceDeployer
-}
-
-func NewFileSystemReader(serviceDeployer *ServiceDeployer) *FileSystemReader {
-	var reader FileSystemReader
-	reader.serviceDeployer = serviceDeployer
-
-	return &reader
-}
-
-// TODO(#748) This function adds actions to a "Default" package which is not a concept we support
-func (reader *FileSystemReader) ReadProjectDirectory(manifest *parsers.YAML) ([]utils.ActionRecord, error) {
-
-	// Inform user of what reader is doing
-	dbgMsg := wski18n.T(wski18n.ID_DEBUG_PROJECT_SEARCH_X_path_X_key_X,
-		map[string]interface{}{
-			wski18n.KEY_PATH: reader.serviceDeployer.ProjectPath,
-			wski18n.KEY_KEY:  wski18n.ACTIONS})
-	wskprint.PrintlnOpenWhiskVerbose(utils.Flags.Verbose, dbgMsg)
-
-	projectPathCount, err := reader.getFilePathCount(reader.serviceDeployer.ProjectPath)
-	actions := make([]utils.ActionRecord, 0)
-
-	if err != nil {
-		return actions, err
-	}
-
-	err = filepath.Walk(reader.serviceDeployer.ProjectPath, func(fpath string, f os.FileInfo, err error) error {
-		if fpath != reader.serviceDeployer.ProjectPath {
-			pathCount, err := reader.getFilePathCount(fpath)
-			if err != nil {
-				return wskderrors.NewFileReadError(fpath, err.Error())
-			}
-
-			if !f.IsDir() {
-				if pathCount-projectPathCount == 1 || strings.HasPrefix(fpath, reader.serviceDeployer.ProjectPath+"/"+FileSystemSourceDirectoryName) {
-					ext := filepath.Ext(fpath)
-
-					// TODO(#692) do not hardcoded known extensions here, create a util that associates
-					// known extensions to runtime types
-					foundFile := false
-					switch ext {
-					case ".swift":
-						foundFile = true
-					case ".js":
-						foundFile = true
-					case ".py":
-						foundFile = true
-					}
-
-					if foundFile == true {
-						_, action, err := reader.CreateActionFromFile(reader.serviceDeployer.ManifestPath, fpath)
-						if err != nil {
-							return wskderrors.NewFileReadError(fpath, err.Error())
-						}
-
-						var record utils.ActionRecord
-						record.Action = action
-						// TODO(#748) This function adds actions to a "Default" package which is not a concept we support
-						//record.Packagename = manifest.Package.Packagename
-						record.Filepath = fpath
-
-						actions = append(actions, record)
-					}
-				}
-			} else if strings.HasPrefix(fpath, reader.serviceDeployer.ProjectPath+"/"+FileSystemSourceDirectoryName) {
-				// Inform user of what reader is doing
-				dbgMsg := wski18n.T(wski18n.ID_DEBUG_PROJECT_SEARCH_X_path_X_key_X,
-					map[string]interface{}{
-						wski18n.KEY_PATH: filepath.Base(fpath),
-						wski18n.KEY_KEY:  wski18n.ACTION_CODE})
-				wskprint.PrintlnOpenWhiskVerbose(utils.Flags.Verbose, dbgMsg)
-
-				// TODO(#694) It appears there is no code to do what the debug message suggests
-				// TODO(#694) continued: i.e., searching for Action code...
-
-			} else {
-				return filepath.SkipDir
-			}
-
-		}
-		return err
-	})
-
-	if err != nil {
-		return actions, err
-	}
-
-	return actions, nil
-
-}
-
-func (reader *FileSystemReader) CreateActionFromFile(manipath, filePath string) (string, *whisk.Action, error) {
-	ext := filepath.Ext(filePath)
-	baseName := filepath.Base(filePath)
-	name := strings.TrimSuffix(baseName, filepath.Ext(baseName))
-	action := new(whisk.Action)
-
-	// TODO(#692) same TODO as above, that is create util for matching exts. to runtimes in common util pkg.
-	// process source code files
-	if ext == ".swift" || ext == ".js" || ext == ".py" {
-
-		kind := "nodejs:default"
-
-		switch ext {
-		case ".swift":
-			kind = "swift:default"
-		case ".js":
-			kind = "nodejs:default"
-		case ".py":
-			kind = "python"
-		}
-
-		dat, err := new(utils.ContentReader).LocalReader.ReadLocal(filePath)
-		if err != nil {
-			return name, action, wskderrors.NewFileReadError(filePath, err.Error())
-		}
-
-		action.Exec = new(whisk.Exec)
-		code := string(dat)
-		action.Exec.Code = &code
-		action.Exec.Kind = kind
-		action.Name = name
-		pub := false
-		action.Publish = &pub
-		return name, action, nil
-	}
-
-	// TODO(#691) create new named error
-	// If the action is not supported, we better to return an error.
-	return "", nil, errors.New("Unsupported action type.")
-}
-
-func (reader *FileSystemReader) getFilePathCount(path string) (int, error) {
-	absPath, err := filepath.Abs(path)
-	if err != nil {
-		return 0, err
-	}
-
-	pathList := strings.Split(absPath, "/")
-	return len(pathList) - 1, nil
-}
-
-func (reader *FileSystemReader) SetFileActions(actions []utils.ActionRecord) error {
-
-	dep := reader.serviceDeployer
-
-	dep.mt.Lock()
-	defer dep.mt.Unlock()
-
-	for _, fileAction := range actions {
-		existAction, exists := reader.serviceDeployer.Deployment.Packages[fileAction.Packagename].Actions[fileAction.Action.Name]
-
-		if exists == true {
-			if existAction.Filepath == fileAction.Filepath || existAction.Filepath == "" {
-				// we're adding a filesystem detected action so just updated code and filepath if needed
-				existAction.Action.Exec.Code = fileAction.Action.Exec.Code
-				existAction.Filepath = fileAction.Filepath
-			} else {
-				// TODO(#691) create new named error
-				// Action exists, but references two different sources
-				return errors.New("Conflict detected for action named " + existAction.Action.Name + ". Found two locations for source file: " + existAction.Filepath + " and " + fileAction.Filepath)
-			}
-		} else {
-			// not a new action so to actions in package
-			reader.serviceDeployer.Deployment.Packages[fileAction.Packagename].Actions[fileAction.Action.Name] = fileAction
-		}
-	}
-
-	return nil
-}
diff --git a/deployers/manifestreader.go b/deployers/manifestreader.go
index a7d1c69..f9fc599 100644
--- a/deployers/manifestreader.go
+++ b/deployers/manifestreader.go
@@ -169,24 +169,12 @@ func (reader *ManifestReader) SetPackages(packages map[string]*whisk.Package) er
 	defer dep.mt.Unlock()
 
 	for _, pkg := range packages {
-		depPkg, exist := dep.Deployment.Packages[pkg.Name]
+		_, exist := dep.Deployment.Packages[pkg.Name]
 		if exist {
-			if dep.IsDefault == true {
-				existPkg := depPkg.Package
-				existPkg.Annotations = pkg.Annotations
-				existPkg.Namespace = pkg.Namespace
-				existPkg.Parameters = pkg.Parameters
-				existPkg.Publish = pkg.Publish
-				existPkg.Version = pkg.Version
-
-				dep.Deployment.Packages[pkg.Name].Package = existPkg
-				return nil
-			} else {
-				// TODO(): i18n of error message (or create a new named error)
-				// TODO(): Is there a better way to handle an existing dependency of same name?
-				err := errors.New("Package [" + pkg.Name + "] exists already.")
-				return wskderrors.NewYAMLParserErr(reader.serviceDeployer.ManifestPath, err)
-			}
+			// TODO(): i18n of error message (or create a new named error)
+			// TODO(): Is there a better way to handle an existing dependency of same name?
+			err := errors.New("Package [" + pkg.Name + "] exists already.")
+			return wskderrors.NewYAMLParserErr(reader.serviceDeployer.ManifestPath, err)
 		}
 		newPack := NewDeploymentPackage()
 		newPack.Package = pkg
diff --git a/deployers/servicedeployer.go b/deployers/servicedeployer.go
index 69f0bae..579d038 100644
--- a/deployers/servicedeployer.go
+++ b/deployers/servicedeployer.go
@@ -86,7 +86,6 @@ type ServiceDeployer struct {
 	Client         *whisk.Client
 	mt             sync.RWMutex
 	IsInteractive  bool
-	IsDefault      bool
 	ManifestPath   string
 	ProjectPath    string
 	DeploymentPath string
@@ -155,15 +154,6 @@ func (deployer *ServiceDeployer) ConstructDeploymentPlan() error {
 
 	manifestReader.InitPackages(manifestParser, manifest, deployer.ManagedAnnotation)
 
-	if deployer.IsDefault == true {
-		fileReader := NewFileSystemReader(deployer)
-		fileActions, err := fileReader.ReadProjectDirectory(manifest)
-		if err != nil {
-			return err
-		}
-		fileReader.SetFileActions(fileActions)
-	}
-
 	// process manifest file
 	err = manifestReader.HandleYaml(deployer, manifestParser, manifest, deployer.ManagedAnnotation)
 	if err != nil {
@@ -236,21 +226,6 @@ func (deployer *ServiceDeployer) ConstructUnDeploymentPlan() (*DeploymentProject
 
 	manifestReader.InitPackages(manifestParser, manifest, whisk.KeyValue{})
 
-	// process file system
-	if deployer.IsDefault == true {
-		fileReader := NewFileSystemReader(deployer)
-		fileActions, err := fileReader.ReadProjectDirectory(manifest)
-		if err != nil {
-			return deployer.Deployment, err
-		}
-
-		err = fileReader.SetFileActions(fileActions)
-		if err != nil {
-			return deployer.Deployment, err
-		}
-
-	}
-
 	// process manifest file
 	err = manifestReader.HandleYaml(deployer, manifestParser, manifest, whisk.KeyValue{})
 	if err != nil {
diff --git a/tests/src/integration/common/wskdeploy.go b/tests/src/integration/common/wskdeploy.go
index eff1920..e8d943b 100644
--- a/tests/src/integration/common/wskdeploy.go
+++ b/tests/src/integration/common/wskdeploy.go
@@ -180,7 +180,6 @@ func (wskdeploy *Wskdeploy) GetDeploymentObjects(manifestPath string, deployment
 	deployer.ProjectPath = filepath.Dir(manifestPath)
 	deployer.ManifestPath = manifestPath
 	deployer.DeploymentPath = deploymentPath
-	deployer.IsDefault = false
 	deployer.DependencyMaster = make(map[string]utils.DependencyRecord)
 
 	//create client config with namespace, apihost, authkey and etc.
diff --git a/utils/flags.go b/utils/flags.go
index 4ec1a62..e55983e 100644
--- a/utils/flags.go
+++ b/utils/flags.go
@@ -35,7 +35,6 @@ type WskDeployFlags struct {
 	ProjectPath      string
 	DeploymentPath   string
 	ManifestPath     string
-	UseDefaults      bool
 	UseInteractive   bool
 	Strict           bool // strict flag to support user defined runtime version.
 	Key              string

-- 
To stop receiving notification emails like this one, please contact
mrutkowski@apache.org.