๐ฑ Function
In GreenCloud we operate a system that runs small functions repeatedly. These functions are based around containers that are delivered and executed on remote devices.
A Function can be created using the CLI and is generally not something that is viewed by the end user. The main purpose of the function is to act as a logical construct to represent the software/code that the software developer has written.
When a software developer asks to initiate a function - they will create a task which will also have a related Function to execute.
A Function consists of -:
Name - a non unique character string used to represent the function.
Language - the language that the function is written in.
At the time of writing GreenCloud supports -:
๐ GOLANG โ go (1.21)
๐ PYTHON โ py (3.12)
๐ NODEJS โ js (18)
๐ CSHARP โ cs (6)
๐ RUBY โ rb (2.7.5)
๐ RUST โ rs (1.7.8)
We are looking to add C / C++ and WASM in the near future.
Createโ
Use this endpoint to create a function to use in the GreenCloud system. The response from a succesful call is an HTTP 201 in which the body of the response contains the ID of the newly created function.
When choosing your language 'lang' make sure to use uppercase (this is different to creating a function via the CLI).
When setting your 'type' make sure to use uppercase as well.
Endpointโ
Request Headersโ
| Key | Value | Required |
|---|---|---|
Authorization | Valid Access Token | true |
Content-Type | application/json | true |
Request Bodyโ
| Key | Example | Requirements |
|---|---|---|
name | MyFunction | required alphanum |
description | My function description | optional printascii max=80 |
tag | [tag id, tag id, tag id] | optional dive unique alphanum |
lang | GO | required oneof=GO PY JS CS RB RS |
type | DOCKER | required oneof=DOCKER |
Example Requestโ
{
"name": "MyFunction",
"description":"My function description",
"tag": ['63fe131f02975e4956238b39', '63fe131f02975e4956238b40'],
"lang": "GO",
"type": "DOCKER"
}
Example Responseโ
{
"id": "63f47d24dab5eb85451f3b61",
}
Editโ
Use this endpoint to edit the meta data about a function. You will need to pass the id of the function on the URL. The parameters that you can edit are the name, description and tags of the function.
Endpointโ
https://api.greencloud.dev/v1/function/[functionId]
Request Headersโ
| Key | Value | Required |
|---|---|---|
Authorization | Valid Access Token | true |
Content-Type | application/json | true |
Request Parametersโ
| Value | Example | Required |
|---|---|---|
| function id | 63f47d24dab5eb85451f3b61 | true |
Request Bodyโ
| Key | Example | Requirements |
|---|---|---|
name | MyFunction | optional alphanum |
description | My function description | optional printascii max=80 |
tag | [tag id, tag id, tag id] | optional dive unique alphanum |
Example Requestโ
{
"name": "MyFunction",
"description":"My function description",
"tag": ['63fe131f02975e4956238b39', '63fe131f02975e4956238b40'],
}
Example Responseโ
Empty body
Getโ
If you need to retrieve details about a particular function, use this endpoint by passing the function's ID as a URL parameter. The endpoint will provide you with a list of information related to the function.
Endpointโ
https://api.greencloud.dev/v1/function/[functionId]
Request Headersโ
| Key | Value | Required |
|---|---|---|
Authorization | Valid Access Token | true |
Request Parametersโ
| Value | Example | Required |
|---|---|---|
| function id | 63f47d24dab5eb85451f3b61 | true |
Example Requestโ
Empty body
Example Responseโ
{
"name": "MyFunction",
"description": "My function description",
"type": "docker",
"lang": "go",
"tags": [
{
"id": "63ed33eac79248a54ee04831",
"name": "greencloud",
"color": "#00ff80"
}
],
"capabilities": {
"timeout": 10,
"cpuCount": 0,
"memSize": 0,
"networkLatency": 0,
"privileged": true
},
"metrics": {
"todaysTasks": 0,
"pendingTasks": 0,
"weekTasks": 0,
"completedTasks": 0
}
}
Listโ
Use this endpoint to get a list of functions in your GreenCloud account.
Endpointโ
Request Headersโ
| Key | Value | Required |
|---|---|---|
Authorization | Valid Access Token | true |
Example Requestโ
Empty body
Example Responseโ
[
{
id: "6404b3da46551827c611ffe5",
name: "MyFunction",
description: "My function description",
lang: "go",
tags: [
{
id: "63ed33eac79248a54ee04831",
name: "greencloud",
color: "#00ff80",
},
],
createdAt: "1678029786"
},
{
id: "6404b3da46551827c611ffe6",
name: "MyFunction2",
description: "My 2nd function description",
lang: "go",
tags: [
{
id: "63ed33eac79248a54ee04831",
name: "greencloud",
color: "#00ff80",
},
],
createdAt: "1676489715"
},
]
List By Tagโ
Use this endpoint to get a list of functions by tag. Note that you need to pass the tag you are interested in as a query parameter. We introduced Tags into GreenCloud as a means to be able to better manage your GreenCloud assets. Please see the Tag documentation for more details.
Endpointโ
https://api.greencloud.dev/v1/function/list?tag=[tagId]
Request Headersโ
| Key | Value | Required |
|---|---|---|
Authorization | Valid Access Token | true |
Request Parametersโ
| Value | Example | Required |
|---|---|---|
| tag id | 63f47d24dab5eb85451f3b61 | true |
Example Requestโ
Empty body
[
{
id: "6404b3da46551827c611ffe5",
name: "MyFunction",
description: "My function description",
lang: "go",
tags: [
{
id: "63ed33eac79248a54ee04831",
name: "greencloud",
color: "#00ff80",
},
],
createdAt: "1678029786"
},
{
id: "6404b3da46551827c611ffe6",
name: "MyFunction2",
description: "My 2nd function description",
lang: "go",
tags: [
{
id: "63ed33eac79248a54ee04831",
name: "greencloud",
color: "#00ff80",
},
],
createdAt: "1676489715"
},
]
Toggle Pauseโ
Use this endpoint to pause or unpause the execution of your function and all calls to it. This is useful if, for example, you want to want to pause your function while you make updates to it, or you have collected sample data for a specific time period and want to pause your function until your next data collection period. If you have created a public URL this will not be accessible while your function is paused, but will resume when you unpause your function.
Endpointโ
https://api.greencloud.dev/v1/function/[functionId]/togglePause
Request Headersโ
| Key | Value | Required |
|---|---|---|
Authorization | Valid Access Token | true |
Request Parametersโ
| Value | Example | Required |
|---|---|---|
| function id | 63f47d24dab5eb85451f3b61 | true |
Example Requestโ
Empty body
Example Responseโ
Empty body
Deleteโ
Use this endpoint to delete a function from the GreenCloud system.
Endpointโ
https://api.greencloud.dev/v1/function/[functionId]
Request Headersโ
| Key | Value | Required |
|---|---|---|
Authorization | Valid Access Token | true |
Request Parametersโ
| Value | Example | Required |
|---|---|---|
| function id | 63f47d24dab5eb85451f3b61 | true |
Example Requestโ
Empty body
Example Responseโ
Empty body
Get Capabilitiesโ
Use this endpoint to get capabilities of a function on the GreenCloud system.
Endpointโ
https://api.greencloud.dev/v1/function/[functionId]/capabilities
Request Headersโ
| Key | Value | Required |
|---|---|---|
Authorization | Valid Access Token | true |
Request Parametersโ
| Value | Example | Required |
|---|---|---|
| function id | 63f47d24dab5eb85451f3b61 | true |
Example Requestโ
Empty body
Example Responseโ
{
"timeout": 10
"cpuCount": 0,
"memSize": 0,
"networkLatency": 0,
"privileged": true
}
Set Capabilitiesโ
In GreenCloud, because of the disparate nature of the machines that will be connecting to the Dispatcher, we use something called Capabailities to be able to clearly utilise the best suited machine to the computational task that the function requires. This is the purpose of Capabilities. In setting the capabilities of a function you can restrict the machines that that function executes on. The purpose of this is to run on the most optimal machine for the function.
Endpointโ
https://api.greencloud.dev/v1/function/[functionId]/capabilities
Request Headersโ
| Key | Value | Required |
|---|---|---|
Authorization | Valid Access Token | true |
Content-Type | application/json | true |
Request Parametersโ
| Value | Example | Required |
|---|---|---|
| function id | 63f47d24dab5eb85451f3b61 | true |
Request Bodyโ
| Key | Example | Requirements |
|---|---|---|
timeout | 10 | optional numeric gte=10 lte=120 |
cpuCount | 1 | optional numeric gte=0 lte=4 |
memSize | 1024 | optional numeric gte=0 lte=2048 |
privilaged | true | optional bool |
Example Requestโ
{
"timeout": 10
"cpuCount": 1,
"memSize": 1024,
"privileged": true
}
Example Responseโ
Empty body