openwhisk

package
v0.0.0-...-8290d16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

* 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.

* 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.

* 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.

* 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.

Example (BadZip)

Issue #62 sample zip

Output:

true
Example (Badcompile)
Output:

{"error":"The action failed to generate or locate a binary. See logs for details."}
error in stdout
error in stderr

XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Badinit_nocompiler)
Output:

500 {"error":"no action defined yet"}
403 {"error":"Missing main/no code to execute."}
502 {"error":"cannot start action: command exited"}
502 {"error":"cannot start action: command exited"}
502 {"error":"cannot start action: command exited"}
500 {"error":"no action defined yet"}
hi
Example (Bininit_nocompiler)
Output:

500 {"error":"no action defined yet"}
200 {"ok":true}
200 {"message":"Hello, Mike!"}
name=Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
200 {"ok":true}
200 {"greetings":"Hello, Mike"}
Hello, Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Cli_compiler)

compile a main

Output:

false
_test/compile/0/bin/exec: application/x-executable
name=Mike
{"message":"Hello, Mike!"}
true
false
Example (CompileError)
Output:

./exec__.go::: syntax error: unexpected error at end of statement
Example (Compile_bin)
Output:

./action/c1/out
./action/c1/out/exec
./action/c1/out/lib
./action/c1/out/lib/action
./action/c1/out/lib/action/__init__.py
./action/c1/out/lib/action/main.py
./action/c1/out/lib/exec.py
Example (Compile_simple)
Output:

500 {"error":"no action defined yet"}
200 {"ok":true}
200 {"message":"Hello, Mike!"}
name=Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Compile_src)
Output:

./action/c2/out
./action/c2/out/action
./action/c2/out/action/action
./action/c2/out/action/action/__init__.py
./action/c2/out/action/action/main.py
./action/c2/out/action/exec.py
./action/c2/out/exec
Example (Compile_withMain)
Output:

500 {"error":"no action defined yet"}
200 {"ok":true}
200 {"hello":"Hello, Mike!"}
name=Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Compile_withZipSrc)
Output:

500 {"error":"no action defined yet"}
200 {"ok":true}
200 {"greetings":"Hello, Mike"}
Main
Hello, Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (ExecutionEnv_check)
Output:

Expected exec.env should start with bad/env
Actual value: exec/env
{"error":"cannot start action: Execution environment version mismatch. See logs for details."}
{"ok":true}
Example (ExecutionEnv_nocheck)
Output:

{"ok":true}
Example (Filetype)
Output:

true
false
true
false
true
false
true
false
true
false
true
false
true
false
true
true
false
Example (Hello)

compile a not-main (hello) function

Output:

_test/compile/1/bin/exec: application/x-executable
name=Mike
{"hello":"Hello, Mike!"}
Example (Jar)
Output:

<nil>
./action/unzip
./action/unzip/exec.jar
<nil>
Example (Json_init)
Output:

{"value":{}}
{"value":{"code":"1\n"}}
{"value":{"code":"1\n","main":"world"}}
{"value":{"code":"MQo=","binary":true}}
{"value":{"code":"MQo=","binary":true,"main":"hello"}}
Example (Main_nocompiler)
Output:

500 {"error":"no action defined yet"}
200 {"ok":true}
200 {"message":"Hello, Mike!"}
name=Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
200 {"ok":true}
200 {"greetings":"Hello, Mike"}
Hello, Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Main_zipinit_nocompiler)
Output:

500 {"error":"no action defined yet"}
200 {"ok":true}
200 {"greetings":"Hello, Mike"}
Hello, Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
200 {"ok":true}
200 {"message":"Hello, Mike!"}
name=Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Package)

compile a function including a package

Output:

_test/compile/2/bin/exec: application/x-executable
Main
Hello, Mike
{"greetings":"Hello, Mike"}
Example (Parse_env)
Output:

map[]
world
world all
Example (Shell_nocompiler)
Output:

500 {"error":"no action defined yet"}
200 {"ok":true}
200 {"hello": "Mike"}
200 {"hello": "world"}
msg=hello Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
msg=hello world
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (StartTestServer)
Output:

{"error":"Missing main/no code to execute."}
{"error":"Error unmarshaling request: invalid character 'X' looking for beginning of value"}
{"error":"no action defined yet"}
{"error":"no action defined yet"}
Example (Venv)
Output:

1 <nil>
2 <nil>
./python
Only in _test/venv/bin: python
3 <nil>
Example (WithMain)
Output:

<nil>
hi
Example (Zip)
Output:

<nil>
./action/unzip
./action/unzip/exec
./action/unzip/lib
./action/unzip/lib/action
./action/unzip/lib/action/__init__.py
./action/unzip/lib/action/main.py
./action/unzip/lib/exec.py
<nil>
Example (Zip_init)
Output:

200 {"ok":true}
200 {"python": "Hello, Mike"}
200 {"python": "Hello, World"}
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Zipinit_nocompiler)
Output:

500 {"error":"no action defined yet"}
200 {"ok":true}
200 {"greetings":"Hello, Mike"}
Hello, Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
200 {"ok":true}
200 {"message":"Hello, Mike!"}
name=Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX

Index

Examples

Constants

View Source
const OutputGuard = "XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX\n"

OutputGuard constant string

Variables

View Source
var Debugging = false

Debugging flag

View Source
var DefaultTimeoutStart = 5 * time.Millisecond

DefaultTimeoutStart to wait for a process to start

View Source
var Version = "1.17.1"

Version number - internal

Functions

func Debug

func Debug(format string, args ...interface{})

Debug emits a debug message

func DebugLimit

func DebugLimit(msg string, in []byte, limit int)

DebugLimit emits a debug message with a limit in length

func IsBangPath

func IsBangPath(buf []byte) bool

IsBangPath checks for a shell executable

func IsElf

func IsElf(buf []byte) bool

IsElf checks for a Linux executable

func IsExe

func IsExe(buf []byte) bool

IsExe checks for a Windows executable

func IsExecutable

func IsExecutable(buf []byte, runtime string) bool

IsExecutable check if it is an executable, according the current runtime

func IsGz

func IsGz(buf []byte) bool

IsGz checks if the given file is a valid tar.gz file

func IsMach64

func IsMach64(buf []byte) bool

IsMach64 checks for OSX executable

func IsZip

func IsZip(buf []byte) bool

IsZip checks if it is a zip file

func UnTar

func UnTar(src []byte, dest string) error

func Unzip

func Unzip(src []byte, dest string) error

Unzip extracts file and directories in the given destination folder

func UnzipOrSaveJar

func UnzipOrSaveJar(src []byte, dest string, jarFile string) error

UnzipOrSaveJar checks if is is a jar file looking if there is a META-INF folder in it if it is a jar file, save it as the file jarFile Otherwise unzip the files in the destination dir

func Zip

func Zip(dir string) ([]byte, error)

Zip a directory

Types

type ActionAck

type ActionAck struct {
	Ok bool `json:"ok"`
}

ActionAck is the expected data structure for the action acknowledgement

type ActionProxy

type ActionProxy struct {
	// contains filtered or unexported fields
}

ActionProxy is the container of the data specific to a server

func NewActionProxy

func NewActionProxy(baseDir string, compiler string, outFile *os.File, errFile *os.File) *ActionProxy

NewActionProxy creates a new action proxy that can handle http requests

func (*ActionProxy) CompileAction

func (ap *ActionProxy) CompileAction(main string, srcDir string, binDir string) error

CompileAction will compile an anction in source format invoking a compiler

func (*ActionProxy) ExtractAction

func (ap *ActionProxy) ExtractAction(buf *[]byte, suffix string) (string, error)

ExtractAction accept a byte array and write it to a file it handles zip files extracting the content it stores in a new directory under ./action/XXX/suffix where x is incremented every time it returns the file if a file or the directory if it was a zip file

func (*ActionProxy) ExtractAndCompile

func (ap *ActionProxy) ExtractAndCompile(buf *[]byte, main string) (string, error)

ExtractAndCompile decode the buffer and if a compiler is defined, compile it also

func (*ActionProxy) ExtractAndCompileIO

func (ap *ActionProxy) ExtractAndCompileIO(r io.Reader, w io.Writer, main string, env string)

ExtractAndCompileIO read in input and write in output to use the runtime as a compiler "on-the-fly"

func (*ActionProxy) ServeHTTP

func (ap *ActionProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*ActionProxy) SetEnv

func (ap *ActionProxy) SetEnv(env map[string]interface{})

SetEnv sets the environment

func (*ActionProxy) Start

func (ap *ActionProxy) Start(port int)

Start creates a proxy to execute actions

func (*ActionProxy) StartLatestAction

func (ap *ActionProxy) StartLatestAction() error

StartLatestAction tries to start the more recently uploaded action if valid, otherwise remove it and fallback to the previous, if any

type ErrResponse

type ErrResponse struct {
	Error string `json:"error"`
}

ErrResponse is the response when there are errors

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

Executor is the container and the guardian of a child process It starts a command, feeds input and output, read logs and control its termination

func NewExecutor

func NewExecutor(logout *os.File, logerr *os.File, command string, env map[string]string, args ...string) (proc *Executor)

NewExecutor creates a child subprocess using the provided command line, writing the logs in the given file. You can then start it getting a communication channel

Example (Ack)
Output:

Command exited abruptly during initialization.
hi
Example (Badack)
Output:

invalid character 'b' looking for beginning of value
Example (Badack2)
Output:

The action did not initialize properly.
Example (Bc)
Output:

<nil>
4
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Env)
Output:

<nil>
{ "env": "TEST_HELLO=WORLD TEST_HI=ALL"}
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Failed)
Output:

command exited
command exited
command exited
command exited
Example (Hello)
Output:

<nil>
{"hello": "Mike"}
msg=hello Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
Example (Helloack)
Output:

<nil>
{"hello": "Mike"}
msg=hello Mike
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX
XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX

func (*Executor) Exited

func (proc *Executor) Exited() bool

Exited checks if the underlying command exited

func (*Executor) Interact

func (proc *Executor) Interact(in []byte) ([]byte, error)

Interact interacts with the underlying process

func (*Executor) Start

func (proc *Executor) Start(waitForAck bool) error

Start execution of the command if the flag ack is true, wait forever for an acknowledgement if the flag ack is false wait a bit to check if the command exited returns an error if the program fails

func (*Executor) Stop

func (proc *Executor) Stop()

Stop will kill the process and close the channels

Directories

Path Synopsis
_test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL