Test extension
This is a flow that implements a k-means clustering operation as a service. As such it can be executed inside any Node-RED environment in a service manner. It also implements the Openwhisk API specification so that it can be executed directly as a custom docker action of Openwhisk. The inputs include arrays of objects and their values and the output returns clusters with three centroids for any given input, using the k-means implementation provided by the clusters npm library.
{
"mode": "multiple",
"data": [
{
"name": "cpu",
"value": [
0.015876524497427744,
0.1902030897354209,
0.005733681579652651,
0.030480619519163435,
0.010371581070262016,
0.012062255039754171,
0.015249307746178593
]
},
{
"name": "memory",
"value": [
27979776,
38883328,
23392256,
22237184,
26570752,
24121344,
22372352
]
}
]
}
In the name variable any type of value can be provided and there is no limit for the amount of objects data array can have. Lastly the mode has two options: multiple and single. The option multiple will create separate clusters for each data entry and the option single will generate a single cluster that will include every value inside the data table.
{
"centroids": [
{
"cpu": [
0.018417176700630984,
0.1902030897354209,
0.00520766094542967
]
},
{
"memory": [
27275264,
38883328,
22822326.85714286
]
}
]
}
The image for the flow can be found here. In order to run the flow correctly port 8080 needs to be exposed to host. Once the container is ready the user will need to execute a POST request at http://localhost:1880/run and wrap around the aforementioned input in a value object.
{"value":{
"mode": "multiple",
"data": [
{
"name": "cpu",
"value": [
0.015876524497427744,
0.1902030897354209,
0.005733681579652651,
0.030480619519163435,
0.010371581070262016,
0.012062255039754171,
0.015249307746178593,
7.264773527105429e-7,
0.0050459685298976376,
0.004886347069983335
]
},
{
"name": "memory",
"value": [
27979776,
38883328,
23392256,
22237184,
26570752,
24121344,
22372352,
22405120,
23105536,
22122496
]
}
]
}}
To deploy the flow as an Openwhisk function the user needs to run the following command:
wsk action create clustering --docker vkatevas/node-red_data_clustering -i
To invoke the action the same input json needs to be included from the first example with the url the command wsk action get clusters --url
provides