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 ¶
- Constants
- Variables
- func Debug(format string, args ...interface{})
- func DebugLimit(msg string, in []byte, limit int)
- func IsBangPath(buf []byte) bool
- func IsElf(buf []byte) bool
- func IsExe(buf []byte) bool
- func IsExecutable(buf []byte, runtime string) bool
- func IsGz(buf []byte) bool
- func IsMach64(buf []byte) bool
- func IsZip(buf []byte) bool
- func UnTar(src []byte, dest string) error
- func Unzip(src []byte, dest string) error
- func UnzipOrSaveJar(src []byte, dest string, jarFile string) error
- func Zip(dir string) ([]byte, error)
- type ActionAck
- type ActionProxy
- func (ap *ActionProxy) CompileAction(main string, srcDir string, binDir string) error
- func (ap *ActionProxy) ExtractAction(buf *[]byte, suffix string) (string, error)
- func (ap *ActionProxy) ExtractAndCompile(buf *[]byte, main string) (string, error)
- func (ap *ActionProxy) ExtractAndCompileIO(r io.Reader, w io.Writer, main string, env string)
- func (ap *ActionProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (ap *ActionProxy) SetEnv(env map[string]interface{})
- func (ap *ActionProxy) Start(port int)
- func (ap *ActionProxy) StartLatestAction() error
- type ErrResponse
- type Executor
Examples ¶
- Package (BadZip)
- Package (Badcompile)
- Package (Badinit_nocompiler)
- Package (Bininit_nocompiler)
- Package (Cli_compiler)
- Package (CompileError)
- Package (Compile_bin)
- Package (Compile_simple)
- Package (Compile_src)
- Package (Compile_withMain)
- Package (Compile_withZipSrc)
- Package (ExecutionEnv_check)
- Package (ExecutionEnv_nocheck)
- Package (Filetype)
- Package (Hello)
- Package (Jar)
- Package (Json_init)
- Package (Main_nocompiler)
- Package (Main_zipinit_nocompiler)
- Package (Package)
- Package (Parse_env)
- Package (Shell_nocompiler)
- Package (StartTestServer)
- Package (Venv)
- Package (WithMain)
- Package (Zip)
- Package (Zip_init)
- Package (Zipinit_nocompiler)
- NewExecutor (Ack)
- NewExecutor (Badack)
- NewExecutor (Badack2)
- NewExecutor (Bc)
- NewExecutor (Env)
- NewExecutor (Failed)
- NewExecutor (Hello)
- NewExecutor (Helloack)
Constants ¶
const OutputGuard = "XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX\n"
OutputGuard constant string
Variables ¶
var Debugging = false
Debugging flag
var DefaultTimeoutStart = 5 * time.Millisecond
DefaultTimeoutStart to wait for a process to start
var Version = "1.17.1"
Version number - internal
Functions ¶
func DebugLimit ¶
DebugLimit emits a debug message with a limit in length
func IsExecutable ¶
IsExecutable check if it is an executable, according the current runtime
func UnzipOrSaveJar ¶
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
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 ¶
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