{"message.commit.token":"bced6483-2c2a-45bf-b351-7d1f2b94f89f",
"message.request.id":"bced6483-2c2a-45bf-b351-7d1f2b94f89f",
"openapi.graph.id":"bee2ab56e9a64d46904e238a264916bc",
"openapi.header.content-type":"application/json",
"openapi.host":"100.64.177.110:8090",
"openapi.method":"POST",
"openapi.remote_addr":"123.123.123.123",
"openapi.request_uri":"/dev/v1/hana",
"openapi.scheme":"https",
"openapi.subgraph.id":"default"}
$.setPortCallback("input",onInput);
$.setPortCallback("hanain",hanaInput);
// ping count
var count = 0;
function isByteArray(data) {
return (typeof data === 'object' && Array.isArray(data)
&& data.length > 0 && typeof data[0] === 'number')
}
function hanaInput(ctx, m) {
// directly send the message from HANA as Response
sendResponse(m, m, null);
}
function sendResponse(s, m, e) {
if ($.output == null) {
// invoke the callback directly
$.sendResponse(s, m, e);
} else {
// let the subsequent operator decide what to do
if (e !== null) {
m.Attributes["message.response.error"] = e;
}
$.output(m);
}
}
function onInput(ctx,s) {
var msg = {};
var inbody = s.Body;
var inattributes = s.Attributes;
// convert the body into string if it is bytes
if (isByteArray(inbody)) {
inbody = String.fromCharCode.apply(null, inbody);
}
// response message
msg.Attributes = {};
for (var key in inattributes) {
// only copy the headers that won't interfere with the recieving operators
if (key.indexOf("openapi.header") < 0 || key === "openapi.header.x-request-key") {
msg.Attributes[key] = inattributes[key];
}
}
// get the request path
var reqpath = inattributes["openapi.request_uri"];
// set header content-type
msg.Attributes["openapi.header.content-type"] = "application/json";
switch (reqpath) {
case "/dev/v1/ping":
msg.Body = {"pong": count++};
sendResponse(s, msg, null);
break;
case "/dev/v1/hana":
data = JSON.parse(inbody);
// check Rows has been received
if ((data["Rows"]) === undefined) {
sendResponse(s, msg, Error("Invalid Input, please specify Rows"));
}
// check if the value Rows is not a number
else if ((isNaN(data["Rows"]) === true)) {
sendResponse(s, msg, Error("Invalid Number "+ data["Rows"].toString()));
}
else {
// build SQL statement
sqlstatement = "SELECT TOP " + data["Rows"].toString() + " * FROM HDB.XRATE_GBP_EUR";
msg.Body = sqlstatement
// send message to sql port for HANA
$.sql(msg);
}
break;
default:
sendResponse(s, msg, Error("Unexpected operation at " + reqpath));
break;
}
}
msg2df <- function(msg) {
print(paste("msg2df Body Names ", names(msg$Body)))
print(paste("msg2df Body Dollar ", msg$Body))
body = msg$Body
df=data.frame(t(sapply(body,c)))
print(paste("msg2df Body DataFrame", df))
return (df)
}
msgheader <- function(msg) {
print(paste("msg2hed Attributes Names ", names(msg$Attributes)))
print(paste("msg2hed Attributes Dollar ", msg$Attributes))
header = list(msg$Attributes)
}
df2msg <- function(df, header) {
attributes = header[[1]]
print(paste("df2msg Attributes ", attributes))
print(paste("df2msg Attributes Names ", names(attributes)))
dfaslist <- setNames(split(df, seq(nrow(df))), rownames(df))
msg <- list(Body=list(dfaslist), Attributes=attributes, Encoding="bar")
}
onInput <- function(msg) {
df <- msg2df(msg)
header <- msgheader(msg)
outMsg <- df2msg(df,header)
print(paste("Output Print ", outMsg))
list(outData=outMsg)
}
api$setPortCallback(c("inData"), c("outData"), "onInput")
vctl util http /app/pipeline-modeler/openapi/service/dev/v1/hana \
-H Content-Type=application/json \
-d '{"Rows":2}' \
-X POST
curl -X POST \
https://<SAP-Data-Intelligence-Cluster.com>/app/pipeline-modeler/openapi/service/dev/v1/hana \
-H 'Authorization: Basic ZGVmYXVsdFx3ZGYwMTpXZWxjb21lMDE=' \
-H 'Content-Type: application/json' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'cache-control: no-cache' \
-d '{"Rows":"3"}'
ab -n 20 -c4 -s 10 -v3 \
-H 'Authorization: Basic ZGVmYXVsdFx3ZGYwMTpXZWxjb21lMDE=' \
-H 'X-Requested-With: XMLHttpRequest' \
-T 'application/json' \
-H 'cache-control: no-cache' \
-p rows.json \
https://<SAP-Data-Intelligence-Cluster.com>/app/pipeline-modeler/openapi/service/dev/v1/hana
Server-Timing →vflow;dur=90.69
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
37 | |
25 | |
17 | |
13 | |
7 | |
7 | |
7 | |
6 | |
6 | |
6 |