@Consumes("application/json")
@Produces({"text/xml","text/plain"})
public Response addAdaptor(@Context ServletContext context,
@QueryParam("viewType") String viewType,
String postBody) {
ChukwaAgent agent = (ChukwaAgent)context.getAttribute("ChukwaAgent");
if (postBody == null) return badRequestResponse("Empty POST body.");
// parse the json.
StringBuilder addCommand = new StringBuilder("add ");
try {
JSONObject reqJson = new JSONObject(postBody);
String dataType = reqJson.getString("DataType");
//TODO: figure out how to set this per-adaptor
//String cluster = reqJson.getString("Cluster");
String adaptorClass = reqJson.getString("AdaptorClass");
String adaptorParams = fetchOptionalString(reqJson, "AdaptorParams");
long offset = fetchOptionalLong(reqJson, "Offset", 0);
addCommand.append(adaptorClass).append(' ');
addCommand.append(dataType);
if (adaptorParams != null)
addCommand.append(' ').append(adaptorParams);
addCommand.append(' ').append(offset);
} catch (JSONException e) {
return badRequestResponse("Invalid JSON passed: '" + postBody + "', error: " + e.getMessage());
}
// add the adaptor
try {
String adaptorId = agent.processAddCommandE(addCommand.toString());
return doGetAdaptor(agent, adaptorId, viewType);
} catch (AdaptorException e) {
return badRequestResponse("Could not add adaptor for postBody: '" + postBody +
"', error: " + e.getMessage());