use of com.datatorrent.stram.plan.logical.requests.LogicalPlanRequest in project apex-core by apache.
the class StramWebServices method logicalPlanModification.
// not supported by WebAppProxyServlet, can only be called directly
@POST
@Path(PATH_LOGICAL_PLAN)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject logicalPlanModification(JSONObject request) {
init();
JSONObject response = new JSONObject();
try {
JSONArray jsonArray = request.getJSONArray("requests");
List<LogicalPlanRequest> requests = new ArrayList<>();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObj = (JSONObject) jsonArray.get(i);
LogicalPlanRequest requestObj = (LogicalPlanRequest) Class.forName(LogicalPlanRequest.class.getPackage().getName() + "." + jsonObj.getString("requestType")).newInstance();
@SuppressWarnings("unchecked") Map<String, String> properties = BeanUtils.describe(requestObj);
@SuppressWarnings("unchecked") Iterator<String> keys = jsonObj.keys();
while (keys.hasNext()) {
String key = keys.next();
if (!key.equals("requestType")) {
properties.put(key, jsonObj.get(key).toString());
}
}
BeanUtils.populate(requestObj, properties);
requests.add(requestObj);
}
Future<?> fr = dagManager.logicalPlanModification(requests);
fr.get(3000, TimeUnit.MILLISECONDS);
} catch (Exception ex) {
LOG.error("Error processing plan change", ex);
try {
if (ex instanceof ExecutionException) {
response.put("error", ex.getCause().toString());
} else {
response.put("error", ex.toString());
}
} catch (Exception e) {
// ignore
}
}
return response;
}
use of com.datatorrent.stram.plan.logical.requests.LogicalPlanRequest in project apex-core by apache.
the class StramWebServicesTest method testSubmitLogicalPlanChange.
@Test
public void testSubmitLogicalPlanChange() throws JSONException, Exception {
List<LogicalPlanRequest> requests = new ArrayList<>();
WebResource r = resource();
CreateOperatorRequest request1 = new CreateOperatorRequest();
request1.setOperatorName("operatorName");
request1.setOperatorFQCN("className");
requests.add(request1);
SetOperatorPropertyRequest request2 = new SetOperatorPropertyRequest();
request2.setOperatorName("operatorName");
request2.setPropertyName("propertyName");
request2.setPropertyValue("propertyValue");
requests.add(request2);
ObjectMapper mapper = new ObjectMapper();
final Map<String, Object> m = new HashMap<>();
m.put("requests", requests);
final JSONObject jsonRequest = new JSONObject(mapper.writeValueAsString(m));
ClientResponse response = r.path(StramWebServices.PATH).path(StramWebServices.PATH_LOGICAL_PLAN).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, jsonRequest);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
assertEquals(DummyStreamingContainerManager.lastRequests.size(), 2);
LogicalPlanRequest request = DummyStreamingContainerManager.lastRequests.get(0);
assertTrue(request instanceof CreateOperatorRequest);
request1 = (CreateOperatorRequest) request;
assertEquals(request1.getOperatorName(), "operatorName");
assertEquals(request1.getOperatorFQCN(), "className");
request = DummyStreamingContainerManager.lastRequests.get(1);
assertTrue(request instanceof SetOperatorPropertyRequest);
request2 = (SetOperatorPropertyRequest) request;
assertEquals(request2.getOperatorName(), "operatorName");
assertEquals(request2.getPropertyName(), "propertyName");
assertEquals(request2.getPropertyValue(), "propertyValue");
}
Aggregations