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: Create the basic struct for Deployment and Manifest yaml (#587)
Date Wed, 04 Oct 2017 21:34:09 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 b6041db  Create the basic struct for Deployment and Manifest yaml (#587)
b6041db is described below

commit b6041db28ce486b0878258472e1498bd13f6ba29
Author: Vincent <shou@us.ibm.com>
AuthorDate: Wed Oct 4 17:34:07 2017 -0400

    Create the basic struct for Deployment and Manifest yaml (#587)
---
 deployers/deploymentreader.go    |  2 +-
 deployers/filesystemreader.go    |  2 +-
 deployers/manifestreader.go      |  6 ++---
 deployers/manifestreader_test.go |  2 +-
 parsers/deploy_parser.go         |  8 +++---
 parsers/deploy_parser_test.go    |  2 +-
 parsers/manifest_parser.go       | 28 ++++++++++-----------
 parsers/manifest_parser_test.go  | 54 ++++++++++++++++++++--------------------
 parsers/yamlparser.go            | 19 +++++---------
 9 files changed, 58 insertions(+), 65 deletions(-)

diff --git a/deployers/deploymentreader.go b/deployers/deploymentreader.go
index 7d8f8b1..9141adb 100644
--- a/deployers/deploymentreader.go
+++ b/deployers/deploymentreader.go
@@ -25,7 +25,7 @@ import (
 
 type DeploymentReader struct {
 	serviceDeployer      *ServiceDeployer
-	DeploymentDescriptor *parsers.DeploymentYAML
+	DeploymentDescriptor *parsers.YAML
 }
 
 func NewDeploymentReader(serviceDeployer *ServiceDeployer) *DeploymentReader {
diff --git a/deployers/filesystemreader.go b/deployers/filesystemreader.go
index c42a068..7937939 100644
--- a/deployers/filesystemreader.go
+++ b/deployers/filesystemreader.go
@@ -42,7 +42,7 @@ func NewFileSystemReader(serviceDeployer *ServiceDeployer) *FileSystemReader
{
 	return &reader
 }
 
-func (reader *FileSystemReader) ReadProjectDirectory(manifest *parsers.ManifestYAML) ([]utils.ActionRecord,
error) {
+func (reader *FileSystemReader) ReadProjectDirectory(manifest *parsers.YAML) ([]utils.ActionRecord,
error) {
 
     utils.PrintOpenWhiskOutputln("Inspecting project directory for actions....")
 
diff --git a/deployers/manifestreader.go b/deployers/manifestreader.go
index bed3230..d94cfee 100644
--- a/deployers/manifestreader.go
+++ b/deployers/manifestreader.go
@@ -41,7 +41,7 @@ func NewManfiestReader(serviceDeployer *ServiceDeployer) *ManifestReader
{
 	return &dep
 }
 
-func (deployer *ManifestReader) ParseManifest() (*parsers.ManifestYAML, *parsers.YAMLParser,
error) {
+func (deployer *ManifestReader) ParseManifest() (*parsers.YAML, *parsers.YAMLParser, error)
{
 	dep := deployer.serviceDeployer
 	manifestParser := parsers.NewYAMLParser()
 	manifest, err := manifestParser.ParseManifest(dep.ManifestPath)
@@ -52,7 +52,7 @@ func (deployer *ManifestReader) ParseManifest() (*parsers.ManifestYAML,
*parsers
 	return manifest, manifestParser, nil
 }
 
-func (reader *ManifestReader) InitRootPackage(manifestParser *parsers.YAMLParser, manifest
*parsers.ManifestYAML) error {
+func (reader *ManifestReader) InitRootPackage(manifestParser *parsers.YAMLParser, manifest
*parsers.YAML) error {
 	packages, err := manifestParser.ComposeAllPackages(manifest, reader.serviceDeployer.ManifestPath)
 	if err != nil {
 		return utils.NewInputYamlFormatError(err.Error())
@@ -63,7 +63,7 @@ func (reader *ManifestReader) InitRootPackage(manifestParser *parsers.YAMLParser
 }
 
 // Wrapper parser to handle yaml dir
-func (deployer *ManifestReader) HandleYaml(sdeployer *ServiceDeployer, manifestParser *parsers.YAMLParser,
manifest *parsers.ManifestYAML) error {
+func (deployer *ManifestReader) HandleYaml(sdeployer *ServiceDeployer, manifestParser *parsers.YAMLParser,
manifest *parsers.YAML) error {
 
 	var err error
 	deps, err := manifestParser.ComposeDependenciesFromAllPackages(manifest, deployer.serviceDeployer.ProjectPath,
deployer.serviceDeployer.ManifestPath)
diff --git a/deployers/manifestreader_test.go b/deployers/manifestreader_test.go
index b86f78f..8b1377f 100644
--- a/deployers/manifestreader_test.go
+++ b/deployers/manifestreader_test.go
@@ -27,7 +27,7 @@ import (
 
 var mr *ManifestReader
 var ps *parsers.YAMLParser
-var ms *parsers.ManifestYAML
+var ms *parsers.YAML
 
 func init() {
 
diff --git a/parsers/deploy_parser.go b/parsers/deploy_parser.go
index 60b0c3f..316655e 100644
--- a/parsers/deploy_parser.go
+++ b/parsers/deploy_parser.go
@@ -24,7 +24,7 @@ import (
     "strings"
 )
 
-func (dm *YAMLParser) UnmarshalDeployment(input []byte, deploy *DeploymentYAML) error {
+func (dm *YAMLParser) UnmarshalDeployment(input []byte, deploy *YAML) error {
 	err := yaml.UnmarshalStrict(input, deploy)
 	if err != nil {
 		return err
@@ -32,7 +32,7 @@ func (dm *YAMLParser) UnmarshalDeployment(input []byte, deploy *DeploymentYAML)
 	return nil
 }
 
-func (dm *YAMLParser) MarshalDeployment(deployment *DeploymentYAML) (output []byte, err error)
{
+func (dm *YAMLParser) MarshalDeployment(deployment *YAML) (output []byte, err error) {
 	data, err := yaml.Marshal(deployment)
 	if err != nil {
 		fmt.Printf("err happened during marshal :%v", err)
@@ -41,8 +41,8 @@ func (dm *YAMLParser) MarshalDeployment(deployment *DeploymentYAML) (output
[]by
 	return data, nil
 }
 
-func (dm *YAMLParser) ParseDeployment(deploymentPath string) (*DeploymentYAML, error) {
-	dplyyaml := DeploymentYAML{}
+func (dm *YAMLParser) ParseDeployment(deploymentPath string) (*YAML, error) {
+	dplyyaml := YAML{}
 	content, err := new(utils.ContentReader).LocalReader.ReadLocal(deploymentPath)
     if err != nil {
         return &dplyyaml, utils.NewInputYamlFileError(err.Error())
diff --git a/parsers/deploy_parser_test.go b/parsers/deploy_parser_test.go
index 86ed25a..781e522 100644
--- a/parsers/deploy_parser_test.go
+++ b/parsers/deploy_parser_test.go
@@ -91,7 +91,7 @@ func TestMissingRootNodeDeploymentYaml(t *testing.T) {
     _, err = p.ParseDeployment(tmpfile.Name())
     assert.NotNil(t, err)
     // go-yaml/yaml prints the wrong line number for mapping values. It should be 3.
-    assert.Contains(t, err.Error(), "field name not found in struct parsers.DeploymentYAML:
Line 1, its neighbour lines, or the lines on the same level")
+    assert.Contains(t, err.Error(), "field name not found in struct parsers.YAML: Line 1,
its neighbour lines, or the lines on the same level")
 }
 
 func TestParseDeploymentYAML_Application(t *testing.T) {
diff --git a/parsers/manifest_parser.go b/parsers/manifest_parser.go
index e6a2023..5ead4b3 100644
--- a/parsers/manifest_parser.go
+++ b/parsers/manifest_parser.go
@@ -36,8 +36,8 @@ import (
 )
 
 // Read existing manifest file or create new if none exists
-func ReadOrCreateManifest() (*ManifestYAML, error) {
-	maniyaml := ManifestYAML{}
+func ReadOrCreateManifest() (*YAML, error) {
+	maniyaml := YAML{}
 
 	if _, err := os.Stat(utils.ManifestFileNameYaml); err == nil {
 		dat, _ := ioutil.ReadFile(utils.ManifestFileNameYaml)
@@ -50,7 +50,7 @@ func ReadOrCreateManifest() (*ManifestYAML, error) {
 }
 
 // Serialize manifest to local file
-func Write(manifest *ManifestYAML, filename string) error {
+func Write(manifest *YAML, filename string) error {
 	output, err := NewYAMLParser().Marshal(manifest)
 	if err != nil {
 		return utils.NewInputYamlFormatError(err.Error())
@@ -66,7 +66,7 @@ func Write(manifest *ManifestYAML, filename string) error {
 	return nil
 }
 
-func (dm *YAMLParser) Unmarshal(input []byte, manifest *ManifestYAML) error {
+func (dm *YAMLParser) Unmarshal(input []byte, manifest *YAML) error {
 	err := yaml.UnmarshalStrict(input, manifest)
 	if err != nil {
 		return err
@@ -74,7 +74,7 @@ func (dm *YAMLParser) Unmarshal(input []byte, manifest *ManifestYAML) error
{
 	return nil
 }
 
-func (dm *YAMLParser) Marshal(manifest *ManifestYAML) (output []byte, err error) {
+func (dm *YAMLParser) Marshal(manifest *YAML) (output []byte, err error) {
 	data, err := yaml.Marshal(manifest)
 	if err != nil {
 		fmt.Printf("err happened during marshal :%v", err)
@@ -83,9 +83,9 @@ func (dm *YAMLParser) Marshal(manifest *ManifestYAML) (output []byte, err
error)
 	return data, nil
 }
 
-func (dm *YAMLParser) ParseManifest(manifestPath string) (*ManifestYAML, error) {
+func (dm *YAMLParser) ParseManifest(manifestPath string) (*YAML, error) {
 	mm := NewYAMLParser()
-	maniyaml := ManifestYAML{}
+	maniyaml := YAML{}
 
 	content, err := utils.Read(manifestPath)
 	if err != nil {
@@ -101,7 +101,7 @@ func (dm *YAMLParser) ParseManifest(manifestPath string) (*ManifestYAML,
error)
 	return &maniyaml, nil
 }
 
-func (dm *YAMLParser) ComposeDependenciesFromAllPackages(manifest *ManifestYAML, projectPath
string, filePath string) (map[string]utils.DependencyRecord, error) {
+func (dm *YAMLParser) ComposeDependenciesFromAllPackages(manifest *YAML, projectPath string,
filePath string) (map[string]utils.DependencyRecord, error) {
 	dependencies := make(map[string]utils.DependencyRecord)
     packages := make(map[string]Package)
 	if manifest.Package.Packagename != "" {
@@ -190,7 +190,7 @@ func (dm *YAMLParser) ComposeDependencies(pkg Package, projectPath string,
fileP
 	return depMap, nil
 }
 
-func (dm *YAMLParser) ComposeAllPackages(manifest *ManifestYAML, filePath string) (map[string]*whisk.Package,
error) {
+func (dm *YAMLParser) ComposeAllPackages(manifest *YAML, filePath string) (map[string]*whisk.Package,
error) {
 	packages := map[string]*whisk.Package{}
     manifestPackages := make(map[string]Package)
 	if manifest.Package.Packagename != "" {
@@ -277,7 +277,7 @@ func (dm *YAMLParser) ComposePackage(pkg Package, packageName string,
filePath s
 	return pag, nil
 }
 
-func (dm *YAMLParser) ComposeSequencesFromAllPackages(namespace string, mani *ManifestYAML)
([]utils.ActionRecord, error) {
+func (dm *YAMLParser) ComposeSequencesFromAllPackages(namespace string, mani *YAML) ([]utils.ActionRecord,
error) {
 	var s1 []utils.ActionRecord = make([]utils.ActionRecord, 0)
     manifestPackages := make(map[string]Package)
 	if mani.Package.Packagename != "" {
@@ -342,7 +342,7 @@ func (dm *YAMLParser) ComposeSequences(namespace string, sequences map[string]Se
 	return s1, nil
 }
 
-func (dm *YAMLParser) ComposeActionsFromAllPackages(manifest *ManifestYAML, filePath string)
([]utils.ActionRecord, error) {
+func (dm *YAMLParser) ComposeActionsFromAllPackages(manifest *YAML, filePath string) ([]utils.ActionRecord,
error) {
 	var s1 []utils.ActionRecord = make([]utils.ActionRecord, 0)
     manifestPackages := make(map[string]Package)
 	if manifest.Package.Packagename != "" {
@@ -535,7 +535,7 @@ func (dm *YAMLParser) ComposeActions(filePath string, actions map[string]Action,
 
 }
 
-func (dm *YAMLParser) ComposeTriggersFromAllPackages(manifest *ManifestYAML, filePath string)
([]*whisk.Trigger, error) {
+func (dm *YAMLParser) ComposeTriggersFromAllPackages(manifest *YAML, filePath string) ([]*whisk.Trigger,
error) {
 	var triggers []*whisk.Trigger = make([]*whisk.Trigger, 0)
     manifestPackages := make(map[string]Package)
 	if manifest.Package.Packagename != "" {
@@ -614,7 +614,7 @@ func (dm *YAMLParser) ComposeTriggers(filePath string, pkg Package) ([]*whisk.Tr
 	return t1, nil
 }
 
-func (dm *YAMLParser) ComposeRulesFromAllPackages(manifest *ManifestYAML) ([]*whisk.Rule,
error) {
+func (dm *YAMLParser) ComposeRulesFromAllPackages(manifest *YAML) ([]*whisk.Rule, error)
{
 	var rules []*whisk.Rule = make([]*whisk.Rule, 0)
     manifestPackages := make(map[string]Package)
 	if manifest.Package.Packagename != "" {
@@ -652,7 +652,7 @@ func (dm *YAMLParser) ComposeRules(pkg Package, packageName string) ([]*whisk.Ru
 	return r1, nil
 }
 
-func (dm *YAMLParser) ComposeApiRecordsFromAllPackages(manifest *ManifestYAML) ([]*whisk.ApiCreateRequest,
error) {
+func (dm *YAMLParser) ComposeApiRecordsFromAllPackages(manifest *YAML) ([]*whisk.ApiCreateRequest,
error) {
 	var requests []*whisk.ApiCreateRequest = make([]*whisk.ApiCreateRequest, 0)
     manifestPackages := make(map[string]Package)
 	if manifest.Package.Packagename != "" {
diff --git a/parsers/manifest_parser_test.go b/parsers/manifest_parser_test.go
index f282153..7e68fc4 100644
--- a/parsers/manifest_parser_test.go
+++ b/parsers/manifest_parser_test.go
@@ -42,16 +42,16 @@ package:
     helloNodejs:
       function: actions/hello.js
       runtime: nodejs:6`
-    // set the zero value of struct ManifestYAML
-    m := ManifestYAML{}
-    // Unmarshal reads/parses manifest data and sets the values of ManifestYAML
+    // set the zero value of struct YAML
+    m := YAML{}
+    // Unmarshal reads/parses manifest data and sets the values of YAML
     // And returns an error if parsing a manifest data fails
     err := NewYAMLParser().Unmarshal([]byte(data), &m)
     if err == nil {
-        // ManifestYAML.Filepath does not get set by Parsers.Unmarshal
+        // YAML.Filepath does not get set by Parsers.Unmarshal
         // as it takes manifest YAML data as a function parameter
         // instead of file name of a manifest file, therefore there is
-        // no way for Unmarshal function to set ManifestYAML.Filepath field
+        // no way for Unmarshal function to set YAML.Filepath field
         // (TODO) Ideally we should change this functionality so that
         // (TODO) filepath is set to the actual path of the manifest file
         expectedResult := ""
@@ -67,7 +67,7 @@ package:
         actualResult = string(len(m.Package.Actions))
         assert.Equal(t, expectedResult, actualResult, "Expected 1 but got " + actualResult)
         // get the action payload from the map of actions which is stored in
-        // ManifestYAML.Package.Actions with the type of map[string]Action
+        // YAML.Package.Actions with the type of map[string]Action
         actionName := "helloNodejs"
         if action, ok := m.Package.Actions[actionName]; ok {
             // location/function of an action should be "actions/hello.js"
@@ -95,7 +95,7 @@ package:
       function: actions/hello.jar
       runtime: java
       main: Hello`
-    m := ManifestYAML{}
+    m := YAML{}
     err := NewYAMLParser().Unmarshal([]byte(data), &m)
     // nothing to test if Unmarshal returns an err
     if err == nil {
@@ -127,7 +127,7 @@ package:
     helloPython:
       function: actions/hello.py
       runtime: python`
-    m := ManifestYAML{}
+    m := YAML{}
     err := NewYAMLParser().Unmarshal([]byte(data), &m)
     // nothing to test if Unmarshal returns an err
     if err == nil {
@@ -154,7 +154,7 @@ package:
     helloSwift:
       function: actions/hello.swift
       runtime: swift`
-    m := ManifestYAML{}
+    m := YAML{}
     err := NewYAMLParser().Unmarshal([]byte(data), &m)
     // nothing to test if Unmarshal returns an err
     if err == nil {
@@ -185,7 +185,7 @@ package:
        inputs:
          name: Amy
          place: Paris`
-    m := ManifestYAML{}
+    m := YAML{}
     err := NewYAMLParser().Unmarshal([]byte(data), &m)
     if err == nil {
         actionName := "helloWithParams"
@@ -212,9 +212,9 @@ func TestUnmarshalForMissingPackage(t *testing.T) {
       runtime: nodejs:6
     helloJava:
       function: actions/hello.java`
-    // set the zero value of struct ManifestYAML
-    m := ManifestYAML{}
-    // Unmarshal reads/parses manifest data and sets the values of ManifestYAML
+    // set the zero value of struct YAML
+    m := YAML{}
+    // Unmarshal reads/parses manifest data and sets the values of YAML
     // And returns an error if parsing a manifest data fails
     err := NewYAMLParser().Unmarshal([]byte(data), &m)
     assert.NotNil(t, err, "Expected some error from Unmarshal but got no error")
@@ -1295,7 +1295,7 @@ func TestMissingRootValueManifestYaml(t *testing.T) {
     p := NewYAMLParser()
     _, err = p.ParseManifest(tmpfile.Name())
     assert.NotNil(t, err)
-    assert.Contains(t, err.Error(), "field actions not found in struct parsers.ManifestYAML:
Line 1, its neighbour lines, or the lines on the same level")
+    assert.Contains(t, err.Error(), "field actions not found in struct parsers.YAML: Line
1, its neighbour lines, or the lines on the same level")
 
 }
 
@@ -1314,9 +1314,9 @@ packages:
       helloPython:
         function: actions/hello.py
         runtime: python`
-    // set the zero value of struct ManifestYAML
-    m := ManifestYAML{}
-    // Unmarshal reads/parses manifest data and sets the values of ManifestYAML
+    // set the zero value of struct YAML
+    m := YAML{}
+    // Unmarshal reads/parses manifest data and sets the values of YAML
     // And returns an error if parsing a manifest data fails
     err := NewYAMLParser().Unmarshal([]byte(data), &m)
     if err == nil {
@@ -1333,7 +1333,7 @@ packages:
                 actualResult = string(len(v.Actions))
                 assert.Equal(t, expectedResult, actualResult, "Expected 1 but got " + actualResult)
                 // get the action payload from the map of actions which is stored in
-                // ManifestYAML.Package.Actions with the type of map[string]Action
+                // YAML.Package.Actions with the type of map[string]Action
                 actionName := "helloNodejs"
                 if action, ok := v.Actions[actionName]; ok {
                     // location/function of an action should be "actions/hello.js"
@@ -1353,7 +1353,7 @@ packages:
                 actualResult = string(len(v.Actions))
                 assert.Equal(t, expectedResult, actualResult, "Expected 1 but got " + actualResult)
                 // get the action payload from the map of actions which is stored in
-                // ManifestYAML.Package.Actions with the type of map[string]Action
+                // YAML.Package.Actions with the type of map[string]Action
                 actionName := "helloPython"
                 if action, ok := v.Actions[actionName]; ok {
                     // location/function of an action should be "actions/hello.js"
@@ -1372,13 +1372,13 @@ packages:
     }
 }
 
-func TestParseManifestYAML_trigger(t *testing.T) {
+func TestParseYAML_trigger(t *testing.T) {
 	data, err := ioutil.ReadFile("../tests/dat/manifest_validate_triggerfeed.yaml")
 	if err != nil {
 		panic(err)
 	}
 
-	var manifest ManifestYAML
+	var manifest YAML
 	err = NewYAMLParser().Unmarshal(data, &manifest)
 	if err != nil {
 		panic(err)
@@ -1399,13 +1399,13 @@ func TestParseManifestYAML_trigger(t *testing.T) {
 	}
 }
 
-func TestParseManifestYAML_rule(t *testing.T) {
+func TestParseYAML_rule(t *testing.T) {
 	data, err := ioutil.ReadFile("../tests/dat/manifest_validate_rule.yaml")
 	if err != nil {
 		panic(err)
 	}
 
-	var manifest ManifestYAML
+	var manifest YAML
 	err = NewYAMLParser().Unmarshal(data, &manifest)
 	if err != nil {
 		panic(err)
@@ -1427,13 +1427,13 @@ func TestParseManifestYAML_rule(t *testing.T) {
 	}
 }
 
-func TestParseManifestYAML_feed(t *testing.T) {
+func TestParseYAML_feed(t *testing.T) {
 	data, err := ioutil.ReadFile("../tests/dat/manifest_validate_feed.yaml")
 	if err != nil {
 		panic(err)
 	}
 
-	var manifest ManifestYAML
+	var manifest YAML
 	err = NewYAMLParser().Unmarshal(data, &manifest)
 	if err != nil {
 		panic(err)
@@ -1463,13 +1463,13 @@ func TestParseManifestYAML_feed(t *testing.T) {
 	}
 }
 
-func TestParseManifestYAML_param(t *testing.T) {
+func TestParseYAML_param(t *testing.T) {
 	data, err := ioutil.ReadFile("../tests/dat/manifest_validate_params.yaml")
 	if err != nil {
 		panic(err)
 	}
 
-	var manifest ManifestYAML
+	var manifest YAML
 	err = NewYAMLParser().Unmarshal(data, &manifest)
 	if err != nil {
 		panic(err)
diff --git a/parsers/yamlparser.go b/parsers/yamlparser.go
index ff0cf99..944f624 100644
--- a/parsers/yamlparser.go
+++ b/parsers/yamlparser.go
@@ -27,8 +27,8 @@ func NewYAMLParser() *YAMLParser {
 }
 
 type ParseYaml interface {
-	Unmarshal(input []byte, deploy *ManifestYAML) error
-	Marshal(manifest *ManifestYAML) (output []byte, err error)
+	Unmarshal(input []byte, deploy *YAML) error
+	Marshal(manifest *YAML) (output []byte, err error)
 
 	//Compose Package entity according to yaml content
 	ComposePackages(manifestpath string) ([]*whisk.Package, error)
@@ -44,7 +44,7 @@ type ParseYaml interface {
 }
 
 type YAMLParser struct {
-	manifests []*ManifestYAML
+	manifests []*YAML
 	lastID    uint32
 }
 
@@ -177,18 +177,11 @@ type Application struct {
 	Package    Package            `yaml:"package"`  // being deprecated, used in deployment.yaml
 }
 
-type DeploymentYAML struct {
-	Application Application       `yaml:"application"` //used in deployment.yaml
+type YAML struct {
+    Application Application       `yaml:"application"` //used in deployment.yaml
     Packages   map[string]Package `yaml:"packages"` //used in deployment.yaml
     Package    Package            `yaml:"package"`
-	Filepath    string      //file path of the yaml file
-}
-
-type ManifestYAML struct {
-	Package  Package `yaml:"package"` //used in both manifest.yaml and deployment.yaml
-	Packages map[string]Package `yaml:"packages"`
-	Filepath string  //file path of the yaml file
-    Application Application       `yaml:"application"` //used in manifest.yaml
+    Filepath    string      //file path of the yaml file
 }
 
 //********************Trigger functions*************************//

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

Mime
View raw message