Skip to content

Commit

Permalink
Fixes issue #160, use latest go-whisk code, restore i18n (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcastro authored and David Liu committed Mar 8, 2017
1 parent 7e7e58a commit 9c14976
Show file tree
Hide file tree
Showing 24 changed files with 553 additions and 1,724 deletions.
17 changes: 8 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM golang:1.7

# Install zip
RUN apt-get -y update && \
apt-get -y install zip
apt-get -y install zip emacs

# Download and install tools
RUN echo "Installing the godep tool"
Expand All @@ -13,17 +13,16 @@ RUN echo "Installing the go-bindata tool"
RUN go get github.com/jteeuwen/go-bindata/...

RUN echo "Installing the openwhisk go-client dependency"
RUN go get github.com/openwhisk/openwhisk-client-go/whisk
RUN go get github.com/openwhisk/openwhisk-client-go/whisk

RUN cd $GOPATH/src/github.com/openwhisk/openwhisk-client-go/whisk && git fetch && git checkout i18n

RUN cd $GOPATH/src/github.com/openwhisk
RUN git clone http://github.com/paulcastro/openwhisk-wskdeploy $GOPATH/src/github.com/openwhisk/openwhisk-wskdeploy

RUN git clone http://github.com/openwhisk/wskdeploy $GOPATH/src/github.com/openwhisk/wskdeploy
RUN cd $GOPATH/src/github.com/openwhisk/openwhisk-wskdeploy && git checkout issue_160

RUN cd $GOPATH/src/github.com/openwhisk/wskdeploy && git checkout development
RUN cd $GOPATH/src/github.com/openwhisk/openwhisk-wskdeploy && go get -t -d ./...

RUN cd $GOPATH/src/github.com/openwhisk/wskdeploy && go get -t -d ./...
RUN cd $GOPATH/src/github.com/openwhisk/openwhisk-wskdeploy && make build

RUN cd $GOPATH/src/github.com/openwhisk/wskdeploy && make build

RUN cd $GOPATH/src/github.com/openwhisk/wskdeploy && make install
RUN cd $GOPATH/src/github.com/openwhisk/openwhisk-wskdeploy && make install
19 changes: 10 additions & 9 deletions cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ func printDeploymentInfo(*whisk.Client) error {
go func() {
defer wg.Done()
troptions := &whisk.TriggerListOptions{0, 0, false}
triggers, _, err := client.Triggers.List(troptions)
_, _, err := client.Triggers.List(troptions)
utils.Check(err)
printTriggerList(triggers)
//printTriggerList(triggers)

}()

Expand All @@ -128,8 +128,8 @@ func printList(collection interface{}) {
switch collection := collection.(type) {
case []whisk.Action:
printActionList(collection)
case []whisk.TriggerFromServer:
printTriggerList(collection)
//case []whisk.Trigger
// printTriggerList(collection)
case []whisk.Package:
printPackageList(collection)
case []whisk.Rule:
Expand All @@ -145,7 +145,7 @@ func printRuleList(rules []whisk.Rule) {
fmt.Fprintf(color.Output, "%s\n", boldString("rules"))
for _, rule := range rules {
publishState := wski18n.T("private")
if rule.Publish {
if *rule.Publish {
publishState = wski18n.T("shared")
}
fmt.Printf("%-70s %s\n", fmt.Sprintf("/%s/%s", rule.Namespace, rule.Name), publishState)
Expand All @@ -156,7 +156,7 @@ func printPackageList(packages []whisk.Package) {
fmt.Fprintf(color.Output, "%s\n", boldString("packages"))
for _, xPackage := range packages {
publishState := wski18n.T("private")
if xPackage.Publish {
if *xPackage.Publish {
publishState = wski18n.T("shared")
}
fmt.Printf("%-70s %s\n", fmt.Sprintf("/%s/%s", xPackage.Namespace, xPackage.Name), publishState)
Expand All @@ -167,15 +167,16 @@ func printActionList(actions []whisk.Action) {
fmt.Fprintf(color.Output, "%s\n", boldString("actions"))
for _, action := range actions {
publishState := wski18n.T("private")
if action.Publish {
if *action.Publish {
publishState = wski18n.T("shared")
}
kind := getValueString(action.Annotations, "exec")
fmt.Printf("%-70s %s %s\n", fmt.Sprintf("/%s/%s", action.Namespace, action.Name), publishState, kind)
}
}

func printTriggerList(triggers []whisk.TriggerFromServer) {
/*
func printTriggerList(triggers whisk.Trigger) {
fmt.Fprintf(color.Output, "%s\n", boldString("triggers"))
for _, trigger := range triggers {
publishState := wski18n.T("private")
Expand All @@ -184,7 +185,7 @@ func printTriggerList(triggers []whisk.TriggerFromServer) {
}
fmt.Printf("%-70s %s\n", fmt.Sprintf("/%s/%s", trigger.Namespace, trigger.Name), publishState)
}
}
}*/

func getValueString(keyValueArr whisk.KeyValueArr, key string) string {
var value interface{}
Expand Down
6 changes: 4 additions & 2 deletions deployers/filesystemreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ func (reader *FileSystemReader) CreateActionFromFile(manipath, filePath string)
utils.Check(err)

action.Exec = new(whisk.Exec)
action.Exec.Code = string(dat)
code := string(dat)
action.Exec.Code = &code
action.Exec.Kind = kind
action.Name = name
action.Publish = false
pub := false
action.Publish = &pub
return name, action, nil
}
// If the action is not supported, we better to return an error.
Expand Down
16 changes: 11 additions & 5 deletions deployers/manifestreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (deployer *ManifestReader) HandleYaml(manifestParser *parsers.YAMLParser, m
return nil
}

func (reader *ManifestReader) SetPackage(pkg *whisk.SentPackageNoPublish) error {
func (reader *ManifestReader) SetPackage(pkg *whisk.Package) error {

dep := reader.serviceDeployer

Expand Down Expand Up @@ -114,8 +114,11 @@ func (reader *ManifestReader) SetActions(actions []utils.ActionRecord) error {
existAction.Action.Exec.Kind = manifestAction.Action.Exec.Kind
}

if manifestAction.Action.Exec.Code != "" {
existAction.Action.Exec.Code = manifestAction.Action.Exec.Code
if manifestAction.Action.Exec.Code != nil {
code := *manifestAction.Action.Exec.Code
if code != "" {
existAction.Action.Exec.Code = manifestAction.Action.Exec.Code
}
}

existAction.Action.Annotations = manifestAction.Action.Annotations
Expand Down Expand Up @@ -155,8 +158,11 @@ func (reader *ManifestReader) checkAction(action utils.ActionRecord) error {
return errors.New("Error: Action " + action.Action.Name + " has no kind set")
}

if action.Action.Exec.Code == "" && action.Action.Exec.Kind != "sequence" {
return errors.New("Error: Action " + action.Action.Name + " has no source code")
if action.Action.Exec.Code != nil {
code := *action.Action.Exec.Code
if code == "" && action.Action.Exec.Kind != "sequence" {
return errors.New("Error: Action " + action.Action.Name + " has no source code")
}
}

return nil
Expand Down
31 changes: 16 additions & 15 deletions deployers/servicedeployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewDeploymentApplication() *DeploymentApplication {
}

type DeploymentPackage struct {
Package *whisk.SentPackageNoPublish
Package *whisk.Package
Actions map[string]utils.ActionRecord
Sequences map[string]utils.ActionRecord
}
Expand Down Expand Up @@ -287,8 +287,8 @@ func (deployer *ServiceDeployer) DeployRules() error {
return nil
}

func (deployer *ServiceDeployer) createPackage(packa *whisk.SentPackageNoPublish) {
fmt.Print("Deploying pacakge " + packa.Name + " ... ")
func (deployer *ServiceDeployer) createPackage(packa *whisk.Package) {
fmt.Print("Deploying package " + packa.Name + " ... ")
_, _, err := deployer.Client.Packages.Insert(packa, true)
if err != nil {
wskErr := err.(*whisk.WskError)
Expand All @@ -307,14 +307,14 @@ func (deployer *ServiceDeployer) createTrigger(trigger *whisk.Trigger) {
}

func (deployer *ServiceDeployer) createFeedAction(trigger *whisk.Trigger, feedName string) {
fmt.Println("Deploying trigger feed " + trigger.Name + " ... ")
// to hold and modify trigger parameters, not passed by ref?
params := make(map[string]interface{})

// check for strings that are JSON
for _, keyVal := range trigger.Parameters {
fmt.Println("Checking trigger param " + keyVal.Key + " with value " + keyVal.Value.(string))
if b, isJson := utils.IsJSON(keyVal.Value.(string)); isJson {
fmt.Println("Setting JSON for trigger param " + keyVal.Key)
fmt.Println(keyVal.Key + " is JSON " + keyVal.Value.(string))
params[keyVal.Key] = b
} else {
params[keyVal.Key] = keyVal.Value
Expand All @@ -325,10 +325,11 @@ func (deployer *ServiceDeployer) createFeedAction(trigger *whisk.Trigger, feedNa
params["lifecycleEvent"] = "CREATE"
params["triggerName"] = "/" + deployer.Client.Namespace + "/" + trigger.Name

pub := true
t := &whisk.Trigger{
Name: trigger.Name,
Annotations: trigger.Annotations,
Publish: true,
Publish: &pub,
}

_, _, err := deployer.Client.Triggers.Insert(t, false)
Expand All @@ -343,7 +344,7 @@ func (deployer *ServiceDeployer) createFeedAction(trigger *whisk.Trigger, feedNa

namespace := deployer.Client.Namespace
deployer.Client.Namespace = qName.Namespace
_, _, err = deployer.Client.Actions.Invoke(qName.EntityName, params, true)
_, _, err = deployer.Client.Actions.Invoke(qName.EntityName, params, true, false)
deployer.Client.Namespace = namespace

if err != nil {
Expand All @@ -356,16 +357,16 @@ func (deployer *ServiceDeployer) createFeedAction(trigger *whisk.Trigger, feedNa

func (deployer *ServiceDeployer) createRule(rule *whisk.Rule) {
// The rule's trigger should include the namespace with pattern /namespace/trigger
rule.Trigger = deployer.getQualifiedName(rule.Trigger, deployer.ClientConfig.Namespace)
rule.Trigger = deployer.getQualifiedName(rule.Trigger.(string), deployer.ClientConfig.Namespace)
// The rule's action should include the namespace and package with pattern /namespace/package/action
// please refer https://github.com/openwhisk/openwhisk/issues/1577

// if it contains a slash, then the action is qualified by a package name
if strings.Contains(rule.Action, "/") {
rule.Action = deployer.getQualifiedName(rule.Action, deployer.ClientConfig.Namespace)
if strings.Contains(rule.Action.(string), "/") {
rule.Action = deployer.getQualifiedName(rule.Action.(string), deployer.ClientConfig.Namespace)
} else {
// if not, we assume the action is inside the root package
rule.Action = deployer.getQualifiedName(strings.Join([]string{deployer.RootPackageName, rule.Action}, "/"), deployer.ClientConfig.Namespace)
rule.Action = deployer.getQualifiedName(strings.Join([]string{deployer.RootPackageName, rule.Action.(string)}, "/"), deployer.ClientConfig.Namespace)
}
fmt.Print("Deploying rule " + rule.Name + " ... ")
_, _, err := deployer.Client.Rules.Insert(rule, true)
Expand All @@ -390,7 +391,7 @@ func (deployer *ServiceDeployer) createAction(pkgname string, action *whisk.Acti
action.Name = strings.Join([]string{pkgname, action.Name}, "/")
}
fmt.Print("Deploying action " + action.Name + " ... ")
_, _, err := deployer.Client.Actions.Insert(action, false, true)
_, _, err := deployer.Client.Actions.Insert(action, false)
if err != nil {
wskErr := err.(*whisk.WskError)
fmt.Printf("Got error creating action with error message: %v and error code: %v.\n", wskErr.Error(), wskErr.ExitCode)
Expand Down Expand Up @@ -520,7 +521,7 @@ func (deployer *ServiceDeployer) UnDeployRules(deployment *DeploymentApplication
return nil
}

func (deployer *ServiceDeployer) deletePackage(packa *whisk.SentPackageNoPublish) {
func (deployer *ServiceDeployer) deletePackage(packa *whisk.Package) {
fmt.Print("Removing package " + packa.Name + " ... ")
_, err := deployer.Client.Packages.Delete(packa.Name)
if err != nil {
Expand Down Expand Up @@ -565,7 +566,7 @@ func (deployer *ServiceDeployer) deleteFeedAction(trigger *whisk.Trigger, feedNa

namespace := deployer.Client.Namespace
deployer.Client.Namespace = qName.Namespace
_, _, err = deployer.Client.Actions.Invoke(qName.EntityName, parameters, true)
_, _, err = deployer.Client.Actions.Invoke(qName.EntityName, parameters, true, true)
deployer.Client.Namespace = namespace

if err != nil {
Expand Down Expand Up @@ -693,7 +694,7 @@ func (deployer *ServiceDeployer) printDeploymentAssets(assets *DeploymentApplica
fmt.Println("\n Rules")
for _, rule := range assets.Rules {
fmt.Println("* rule: " + rule.Name)
fmt.Println(" - trigger: " + rule.Trigger + "\n - action: " + rule.Action)
fmt.Println(" - trigger: " + rule.Trigger.(string) + "\n - action: " + rule.Action.(string))
}

fmt.Println("")
Expand Down
4 changes: 2 additions & 2 deletions deployers/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func (vf *Verifier) Filter(deployer *ServiceDeployer, target *DeploymentApplicat
}

// Convert whisk.package to whisk.SentPackageNoPublish
func convert(pa *whisk.Package) (sentpackage *whisk.SentPackageNoPublish, err error) {
sp := &whisk.SentPackageNoPublish{}
func convert(pa *whisk.Package) (sentpackage *whisk.Package, err error) {
sp := &whisk.Package{}
sp.Name = pa.Name
sp.Annotations = pa.Annotations
sp.Parameters = pa.Parameters
Expand Down
19 changes: 12 additions & 7 deletions parsers/manifest_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ func (dm *YAMLParser) ParseManifest(mani string) *ManifestYAML {
}

// Is we consider multi pacakge in one yaml?
func (dm *YAMLParser) ComposePackage(mani *ManifestYAML) (*whisk.SentPackageNoPublish, error) {
func (dm *YAMLParser) ComposePackage(mani *ManifestYAML) (*whisk.Package, error) {
//mani := dm.ParseManifest(manipath)
pag := &whisk.SentPackageNoPublish{}
pag := &whisk.Package{}
pag.Name = mani.Package.Packagename
//The namespace for this package is absent, so we use default guest here.
pag.Namespace = mani.Package.Namespace
pag.Publish = false
pub := false
pag.Publish = &pub

keyValArr := make(whisk.KeyValueArr, 0)
for name, value := range mani.Package.Inputs {
Expand Down Expand Up @@ -110,7 +111,8 @@ func (dm *YAMLParser) ComposeSequences(namespace string, mani *ManifestYAML) ([]

wskaction.Exec.Components = components
wskaction.Name = key
wskaction.Publish = false
pub := false
wskaction.Publish = &pub
wskaction.Namespace = namespace

record := utils.ActionRecord{wskaction, mani.Package.Packagename, key}
Expand All @@ -134,7 +136,8 @@ func (dm *YAMLParser) ComposeActions(mani *ManifestYAML, manipath string) ([]uti
action.Location = filePath
dat, err := new(utils.ContentReader).LocalReader.ReadLocal(filePath)
utils.Check(err)
wskaction.Exec.Code = string(dat)
code := string(dat)
wskaction.Exec.Code = &code

ext := path.Ext(filePath)
kind := "nodejs:default"
Expand Down Expand Up @@ -169,7 +172,8 @@ func (dm *YAMLParser) ComposeActions(mani *ManifestYAML, manipath string) ([]uti
}

wskaction.Name = key
wskaction.Publish = false
pub := false
wskaction.Publish = &pub

record := utils.ActionRecord{wskaction, mani.Package.Packagename, action.Location}
s1 = append(s1, record)
Expand All @@ -187,7 +191,8 @@ func (dm *YAMLParser) ComposeTriggers(manifest *ManifestYAML) ([]*whisk.Trigger,
wsktrigger := new(whisk.Trigger)
wsktrigger.Name = trigger.Name
wsktrigger.Namespace = trigger.Namespace
wsktrigger.Publish = false
pub := false
wsktrigger.Publish = &pub

keyValArr := make(whisk.KeyValueArr, 0)
if trigger.Source != "" {
Expand Down
13 changes: 8 additions & 5 deletions parsers/yamlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ func (trigger *Trigger) ComposeWskTrigger(kvarr []whisk.KeyValue) *whisk.Trigger
wsktrigger := new(whisk.Trigger)
wsktrigger.Name = trigger.Name
wsktrigger.Namespace = trigger.Namespace
wsktrigger.Publish = false
pub := false
wsktrigger.Publish = &pub
wsktrigger.Annotations = kvarr
return wsktrigger
}
Expand All @@ -151,18 +152,20 @@ func (rule *Rule) ComposeWskRule() *whisk.Rule {
wskrule := new(whisk.Rule)
wskrule.Name = rule.Name
//wskrule.Namespace = rule.Namespace
wskrule.Publish = false
pub := false
wskrule.Publish = &pub
wskrule.Trigger = rule.Trigger
wskrule.Action = rule.Action
return wskrule
}

//********************Package functions*************************//
func (pkg *Package) ComposeWskPackage() *whisk.SentPackageNoPublish {
wskpag := new(whisk.SentPackageNoPublish)
func (pkg *Package) ComposeWskPackage() *whisk.Package {
wskpag := new(whisk.Package)
wskpag.Name = pkg.Packagename
wskpag.Namespace = pkg.Namespace
wskpag.Publish = false
pub := false
wskpag.Publish = &pub
wskpag.Version = pkg.Version
return wskpag
}
Expand Down
Loading

0 comments on commit 9c14976

Please sign in to comment.