You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eagle.apache.org by Daniel Zhou <Da...@dataguise.com> on 2015/12/19 00:22:23 UTC

Questions about send JSON to eagle-API

Hi,
I met a trouble when calling the "create policy" API of eagle,

In my java code, I put:

String jsonData = "[{\"tags\":{\"site\":\"Demo\",\"dataSource\":\"hdfsAuditLog\",\"policyId\": \"testPolicy\",\"alertExecutorId\":\"hdfsAuditLogAlertExecutor\", \"policyType\": \"siddhiCEPEngine\"},\"desc\":\"test the api\", \"policyDef\": \"{\"type\": \"siddhiCEPEngine\", \"expression\": \"from hdfsAuditLogEventStream[src =='/test0'] select * insert into outputStream;\"}\",\"notificationDef\":\"[{}]\",\"enabled\":true}]";



The jsonData is pinted as :

[{"tags":{"site":"Demo","dataSource":"hdfsAuditLog","policyId": "testPolicy","alertExecutorId":"hdfsAuditLogAlertExecutor", "policyType": "siddhiCEPEngine"},"desc":"test the api", "policyDef": "{"type": "siddhiCEPEngine", "expression": "from hdfsAuditLogEventStream[src =='/test0'] select * insert into outputStream;"}","notificationDef":"[{}]","enabled":true}]

Which is a valid json .





The response from server is:

Response Code : 200

{"success":false,"exception":"org.codehaus.jackson.JsonParseException: Unexpected character ('t' (code 116)): was expecting comma to separate OBJECT entries\n at [Source: org.apache.catalina.connector.CoyoteInputStream@b7cb2; line: 1,


I'm quite sure that the problems come from "policyDef" part,  because if I leave "policyDef" as null and send out that "jsonData" string , I can get the success response.
Here is the "policyDef" part:
\"policyDef\": \"{\"type\": \"siddhiCEPEngine\", \"expression\": \"from hdfsAuditLogEventStream[src =='/test0'] select * insert into outputStream;\"}\",


Could anyone tell me how to fix it?

Thanks,
Daniel

Re: Questions about send JSON to eagle-API

Posted by "Zhang, Edward (GDI Hadoop)" <yo...@ebay.com>.
Because you use literal json string, you need two more backslash for each
double quote within policyDef.

The resulted jsonData should be like
[{"tags":{"site":"Demo","dataSource":"hdfsAuditLog","policyId":
"testPolicy","alertExecutorId":"hdfsAuditLogAlertExecutor", "policyType":
"siddhiCEPEngine"},"desc":"test the api", "policyDef": "{\"type\":
\"siddhiCEPEngine\", \"expression\": \"from hdfsAuditLogEventStream[src
=='/test0'] select * insert into
outputStream;\"}","notificationDef":"[{}]","enabled":true}]

So String jsonData can be :
String jsonData = 
"[{\"tags\":{\"site\":\"Demo\",\"dataSource\":\"hdfsAuditLog\",\"policyId\"
: \"testPolicy\",\"alertExecutorId\":\"hdfsAuditLogAlertExecutor\",
\"policyType\": \"siddhiCEPEngine\"},\"desc\":\"test the api\",
\"policyDef\": \²{\\\²type\\\": \\\²siddhiCEPEngine\\\",
\\\²expression\\\": \\\"from hdfsAuditLogEventStream[src =='/test0']
select * insert into
outputStream;\\\"}\",\"notificationDef\":\"[{}]\",\"enabled\":true}]²;



But in overall , I don¹t think it is good use literal json string, instead
we can use eagle client API to do that. (But unfortunately eagle does not
provide a public repo to hold the client jars)

you can reference EagleServiceClientImpl::create

Thanks
Edward

On 12/18/15, 15:22, "Daniel Zhou" <Da...@dataguise.com> wrote:

>Hi,
>I met a trouble when calling the "create policy" API of eagle,
>
>In my java code, I put:
>
>String jsonData = 
>"[{\"tags\":{\"site\":\"Demo\",\"dataSource\":\"hdfsAuditLog\",\"policyId\
>": \"testPolicy\",\"alertExecutorId\":\"hdfsAuditLogAlertExecutor\",
>\"policyType\": \"siddhiCEPEngine\"},\"desc\":\"test the api\",
>\"policyDef\": \"{\"type\": \"siddhiCEPEngine\", \"expression\": \"from
>hdfsAuditLogEventStream[src =='/test0'] select * insert into
>outputStream;\"}\",\"notificationDef\":\"[{}]\",\"enabled\":true}]";
>
>
>
>The jsonData is pinted as :
>
>[{"tags":{"site":"Demo","dataSource":"hdfsAuditLog","policyId":
>"testPolicy","alertExecutorId":"hdfsAuditLogAlertExecutor", "policyType":
>"siddhiCEPEngine"},"desc":"test the api", "policyDef": "{"type":
>"siddhiCEPEngine", "expression": "from hdfsAuditLogEventStream[src
>=='/test0'] select * insert into
>outputStream;"}","notificationDef":"[{}]","enabled":true}]
>
>Which is a valid json .
>
>
>
>
>
>The response from server is:
>
>Response Code : 200
>
>{"success":false,"exception":"org.codehaus.jackson.JsonParseException:
>Unexpected character ('t' (code 116)): was expecting comma to separate
>OBJECT entries\n at [Source:
>org.apache.catalina.connector.CoyoteInputStream@b7cb2; line: 1,
>
>
>I'm quite sure that the problems come from "policyDef" part,  because if
>I leave "policyDef" as null and send out that "jsonData" string , I can
>get the success response.
>Here is the "policyDef" part:
>\"policyDef\": \"{\"type\": \"siddhiCEPEngine\", \"expression\": \"from
>hdfsAuditLogEventStream[src =='/test0'] select * insert into
>outputStream;\"}\",
>
>
>Could anyone tell me how to fix it?
>
>Thanks,
>Daniel