You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openwhisk.apache.org by Michele Sciabarra <op...@sciabarra.com> on 2018/04/22 20:54:36 UTC

Completed support for GoLang actions (and more...)

Hello all,

I am happy to announce I have closed my "TODO" list for Go Actions (and more) providing unit tests in ScalaTests for the images I created.

It has been a long journey, but I recap what I accomplished so far:

1. developed a new "actionloop" protocol allowing for high performing binary actions. It basically  works reading json line by line in stdin,  outputting in fd3, with logs in stdout and stderr
2. The image "actionloop" implements a replacement of the python proxy in go implementing this protocol. Note it works also for bash actions and generic binaries. It is meant to replace (or complement) the docker skeleton
3. The image actionloop-golang supports action loops in GoLang. It accepts either binaries or source actions in the format as in [1]. 
4. The image actionloop-swift supports action loops in Swift. It accepts either binaries or source actions in the format as in [2]
5. As a side effect, I defined (and implemented) a "compiler" protocol for using the runtimes as offline compilers to resolve the warm start problem. Basically the images are also usable as standalone compilers. I used this feature in tests, but it can be also leveraged, for example, in wskdeploy

Where is all this stuff?

1. Submitted PR#8 for complete handover of the actionloop (aka goproxy) to incubator-openwhisk-runtime-go
2. Submitted PR#3 for handover of the swift support to incubator-openwhisk-runtime-swift/
3. Submitter PR#47 including tests for the images actionloop, actionloop-golang-v1.9, actionloop-swift-v4.1

The 3 PR should be reviewed and merged in order but I have checked they should merge cleanly. Luckily they are not so big because the biggest one (the first) has been already reviewed.

Now, I think I should focus on writing documentation for this stuff. I can present it to the next interchange meeting.


[1] Example of Action in GoLang:
package action

import (
    "encoding/json"
    "fmt"
)

func Main(event json.RawMessage) (json.RawMessage, error) {
    var obj map[string]interface{}
    json.Unmarshal(event, &obj)
    name, ok := obj["name"].(string)
    if !ok {
        name = "Stranger"
    }
    fmt.Printf("name=%s\n", name)
    msg := map[string]string{"message": ("Hello, " + name + "!")}
    return json.Marshal(msg)
}

[2] Example of Action in Swift:
func main(args: [String:Any]) -> [String:Any] {
    if let name = args["name"] as? String {
        print(name)
        return [ "main" : "Hello \(name)!" ]
    } else {
        return [ "main" : "Hello swif4!" ]
    }
}
-- 
  Michele Sciabarra
  openwhisk@sciabarra.com

Re: Completed support for GoLang actions (and more...)

Posted by Carlos Santana <cs...@gmail.com>.
This is excellent Michele thanks for the contributions. +1

I certainly will be reviewing the PRs.

I will help out looking into Codable Swift using the new goproxy

I was giving talk this week at a Meetup and mentioned the on going work on
the new go support and there were a few folks very excited about it.

— Carlos

On Sun, Apr 22, 2018 at 4:54 PM Michele Sciabarra <op...@sciabarra.com>
wrote:

> Hello all,
>
> I am happy to announce I have closed my "TODO" list for Go Actions (and
> more) providing unit tests in ScalaTests for the images I created.
>
> It has been a long journey, but I recap what I accomplished so far:
>
> 1. developed a new "actionloop" protocol allowing for high performing
> binary actions. It basically  works reading json line by line in stdin,
> outputting in fd3, with logs in stdout and stderr
> 2. The image "actionloop" implements a replacement of the python proxy in
> go implementing this protocol. Note it works also for bash actions and
> generic binaries. It is meant to replace (or complement) the docker skeleton
> 3. The image actionloop-golang supports action loops in GoLang. It accepts
> either binaries or source actions in the format as in [1].
> 4. The image actionloop-swift supports action loops in Swift. It accepts
> either binaries or source actions in the format as in [2]
> 5. As a side effect, I defined (and implemented) a "compiler" protocol for
> using the runtimes as offline compilers to resolve the warm start problem.
> Basically the images are also usable as standalone compilers. I used this
> feature in tests, but it can be also leveraged, for example, in wskdeploy
>
> Where is all this stuff?
>
> 1. Submitted PR#8 for complete handover of the actionloop (aka goproxy) to
> incubator-openwhisk-runtime-go
> 2. Submitted PR#3 for handover of the swift support to
> incubator-openwhisk-runtime-swift/
> 3. Submitter PR#47 including tests for the images actionloop,
> actionloop-golang-v1.9, actionloop-swift-v4.1
>
> The 3 PR should be reviewed and merged in order but I have checked they
> should merge cleanly. Luckily they are not so big because the biggest one
> (the first) has been already reviewed.
>
> Now, I think I should focus on writing documentation for this stuff. I can
> present it to the next interchange meeting.
>
>
> [1] Example of Action in GoLang:
> package action
>
> import (
>     "encoding/json"
>     "fmt"
> )
>
> func Main(event json.RawMessage) (json.RawMessage, error) {
>     var obj map[string]interface{}
>     json.Unmarshal(event, &obj)
>     name, ok := obj["name"].(string)
>     if !ok {
>         name = "Stranger"
>     }
>     fmt.Printf("name=%s\n", name)
>     msg := map[string]string{"message": ("Hello, " + name + "!")}
>     return json.Marshal(msg)
> }
>
> [2] Example of Action in Swift:
> func main(args: [String:Any]) -> [String:Any] {
>     if let name = args["name"] as? String {
>         print(name)
>         return [ "main" : "Hello \(name)!" ]
>     } else {
>         return [ "main" : "Hello swif4!" ]
>     }
> }
> --
>   Michele Sciabarra
>   openwhisk@sciabarra.com
>