Skip to content

Commit

Permalink
add host functions for cluster data (flash sale support) (#188)
Browse files Browse the repository at this point in the history
* add pipeline name to filter

* add host functions for cluster data

* add APIs for wasm cluster data

* update document

* revise host functions to allow zeros in string

* improve test coverage

* fix typo

* revert 1st commit, pass pipeline through meta data

* updated according to comments
  • Loading branch information
localvar committed Aug 31, 2021
1 parent f209820 commit e1d0a82
Show file tree
Hide file tree
Showing 19 changed files with 1,295 additions and 110 deletions.
3 changes: 2 additions & 1 deletion cmd/client/command/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const (
statusObjectURL = apiURL + "/status/objects/%s"
statusObjectsURL = apiURL + "/status/objects"

wasmURL = apiURL + "/wasm/code"
wasmCodeURL = apiURL + "/wasm/code"
wasmDataURL = apiURL + "/wasm/data/%s/%s"

// MeshTenantsURL is the mesh tenant prefix.
MeshTenantsURL = apiURL + "/mesh/tenants"
Expand Down
78 changes: 73 additions & 5 deletions cmd/client/command/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package command

import (
"fmt"
"net/http"

"github.com/spf13/cobra"
Expand All @@ -27,19 +28,86 @@ import (
func WasmCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "wasm",
Short: "Manage WebAssembly code",
Short: "Manage WebAssembly code and data",
}

cmd.AddCommand(updateWasmCmd())
cmd.AddCommand(wasmReloadCodeCmd())
cmd.AddCommand(wasmDeleteDataCmd())
cmd.AddCommand(wasmApplyDataCmd())
cmd.AddCommand(wasmListDataCmd())
return cmd
}

func updateWasmCmd() *cobra.Command {
func wasmReloadCodeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "update",
Use: "reload-code",
Short: "Notify Easegress to reload WebAssembly code",
Run: func(cmd *cobra.Command, args []string) {
handleRequest(http.MethodPost, makeURL(wasmURL), nil, cmd)
handleRequest(http.MethodPost, makeURL(wasmCodeURL), nil, cmd)
},
}

return cmd
}

func wasmDeleteDataCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete-data",
Short: "Delete all shared data of a WasmHost filter",
Example: "egctl wasm clear-data <pipeline> <filter>",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 2 {
return nil
}
return fmt.Errorf("requires pipeline and filter name")
},

Run: func(cmd *cobra.Command, args []string) {
handleRequest(http.MethodDelete, makeURL(wasmDataURL, args[0], args[1]), nil, cmd)
},
}

return cmd
}

func wasmApplyDataCmd() *cobra.Command {
var specFile string

cmd := &cobra.Command{
Use: "apply-data",
Short: "Apply shared data to a WasmHost filter",
Example: "egctl wasm apply-data <pipeline> <filter> -f <YAML file>",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 2 {
return nil
}
return fmt.Errorf("requires pipeline and filter name")
},

Run: func(cmd *cobra.Command, args []string) {
buf, _ := readFromFileOrStdin(specFile, cmd)
handleRequest(http.MethodPut, makeURL(wasmDataURL, args[0], args[1]), buf, cmd)
},
}
cmd.Flags().StringVarP(&specFile, "file", "f", "", "A yaml file specifying the object.")

return cmd
}

func wasmListDataCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list-data",
Short: "List shared data of a WasmHost filter",
Example: "egctl wasm list-data <pipeline> <filter>",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 2 {
return nil
}
return fmt.Errorf("requires pipeline and filter name")
},

Run: func(cmd *cobra.Command, args []string) {
handleRequest(http.MethodGet, makeURL(wasmDataURL, args[0], args[1]), nil, cmd)
},
}

Expand Down

0 comments on commit e1d0a82

Please sign in to comment.