use of org.apache.oozie.client.rest.BulkResponseImpl in project oozie by apache.
the class TestBulkMonitorJPAExecutor method testBundleId.
public void testBundleId() throws Exception {
String request = "bundle=" + bundleId + ";actionstatus=FAILED;" + "startcreatedtime=2012-07-21T00:00Z;endcreatedtime=2012-07-22T02:00Z";
BulkResponseInfo response = _execQuery(request);
List<BulkResponseImpl> brList = response.getResponses();
// only 1 action satisfies the
assertEquals(1, brList.size());
// conditions
assertEquals(1, response.getTotal());
BulkResponseImpl br = brList.get(0);
assertEquals(bundleId, br.getBundle().getId());
assertEquals("Coord1", br.getCoordinator().getAppName());
assertEquals(CoordinatorAction.Status.FAILED, br.getAction().getStatus());
assertEquals(DateUtils.parseDateUTC(CREATE_TIME).toString(), br.getAction().getCreatedTime().toString());
}
use of org.apache.oozie.client.rest.BulkResponseImpl in project oozie by apache.
the class TestBulkMonitorJPAExecutor method testSingleRecord.
public void testSingleRecord() throws Exception {
String request = "bundle=" + bundleName + ";actionstatus=FAILED;" + "startcreatedtime=2012-07-21T00:00Z;endcreatedtime=2012-07-22T02:00Z;" + "startscheduledtime=2012-07-20T23:00Z;endscheduledtime=2012-07-22T03:00Z";
BulkResponseInfo response = _execQuery(request);
List<BulkResponseImpl> brList = response.getResponses();
// only 1 action satisfies the
assertEquals(1, brList.size());
// conditions
assertEquals(1, response.getTotal());
BulkResponseImpl br = brList.get(0);
assertEquals(bundleName, br.getBundle().getAppName());
assertEquals("Coord1", br.getCoordinator().getAppName());
assertEquals(CoordinatorAction.Status.FAILED, br.getAction().getStatus());
assertEquals(DateUtils.parseDateUTC(CREATE_TIME).toString(), br.getAction().getCreatedTime().toString());
}
use of org.apache.oozie.client.rest.BulkResponseImpl in project oozie by apache.
the class TestBulkMonitorJPAExecutor method testMultipleCoordinators.
public void testMultipleCoordinators() throws Exception {
// there are 3 coordinators but giving range as only two of them
String request = "bundle=" + bundleName + ";coordinators=Coord1,Coord2;actionstatus=KILLED";
BulkResponseInfo response = _execQuery(request);
List<BulkResponseImpl> brList = response.getResponses();
// 2 actions satisfy the conditions
assertEquals(2, brList.size());
assertEquals(2, response.getTotal());
assertEquals(brList.get(0).getAction().getId(), "Coord1@2");
assertEquals(brList.get(1).getAction().getId(), "Coord2@1");
}
use of org.apache.oozie.client.rest.BulkResponseImpl in project oozie by apache.
the class TestBulkMonitorJPAExecutor method testDefaultStatus.
public void testDefaultStatus() throws Exception {
// adding coordinator action #4 to Coord#3
addRecordToCoordActionTable("Coord3", 1, CoordinatorAction.Status.FAILED, "coord-action-get.xml", 0);
String request = "bundle=" + bundleName + ";";
BulkResponseInfo response = _execQuery(request);
List<BulkResponseImpl> brList = response.getResponses();
// 4 actions satisfy the conditions
assertEquals(4, brList.size());
assertEquals(4, response.getTotal());
List<String> possibleStatus = new ArrayList<String>(Arrays.asList("FAILED", "KILLED"));
List<String> resultStatus = new ArrayList<String>();
resultStatus.add(brList.get(0).getAction().getStatus().toString());
resultStatus.add(brList.get(1).getAction().getStatus().toString());
assertEquals(possibleStatus, resultStatus);
}
use of org.apache.oozie.client.rest.BulkResponseImpl in project oozie by apache.
the class BulkJPAExecutor method actionQuery.
/**
* Compose the coord action level query comprising bundle id/appname filter and coord action
* status filter (if specified) and start-time or nominal-time filter (if specified)
* @param em
* @param bundles
* @param times
* @param responseList
* @return Query string
* @throws ParseException
*/
@SuppressWarnings("unchecked")
private String actionQuery(final List<String> coords, final List<String> params, List<String> statuses, EntityManager em, List<BundleJobBean> bundles, Map<String, Timestamp> times, List<BulkResponseImpl> responseList) throws ParseException {
Query q = em.createNamedQuery("BULK_MONITOR_ACTIONS_QUERY");
StringBuilder getActions = new StringBuilder(q.toString());
int offset = getActions.indexOf("ORDER");
StringBuilder conditionClause = new StringBuilder();
if (coords != null) {
PARAM_TYPE type = getParamType(coords.get(0), 'C');
if (type == PARAM_TYPE.NAME) {
conditionClause.append(inClause(coords.size(), "appName", 'c', "param"));
params.addAll(coords);
} else if (type == PARAM_TYPE.ID) {
conditionClause.append(inClause(coords.size(), "id", 'c', "param"));
params.addAll(coords);
}
}
// Query: Select <columns> from CoordinatorActionBean a, CoordinatorJobBean c WHERE a.jobId = c.id
// AND c.bundleId = :bundleId AND c.appName/id IN (...) AND a.statusStr IN (...)
conditionClause.append(statusClause(statuses));
offset = getActions.indexOf("ORDER");
getActions.insert(offset - 1, conditionClause);
// Query: Select <columns> from CoordinatorActionBean a, CoordinatorJobBean c WHERE a.jobId = c.id
// AND c.bundleId = :bundleId AND c.appName/id IN (...) AND a.statusStr IN (...)
// AND a.createdTimestamp >= startCreated _or_ a.createdTimestamp <= endCreated
// AND a.nominalTimestamp >= startNominal _or_ a.nominalTimestamp <= endNominal
timesClause(getActions, offset, times);
q = em.createQuery(getActions.toString());
Iterator<Entry<String, Timestamp>> iter = times.entrySet().iterator();
while (iter.hasNext()) {
Entry<String, Timestamp> time = iter.next();
q.setParameter(time.getKey(), time.getValue());
}
// pagination
q.setFirstResult(start - 1);
q.setMaxResults(len);
if (coords != null) {
fillParameters(q, "param", coords);
}
if (statuses != null) {
fillParameters(q, "status", statuses);
}
// repeatedly execute above query for each bundle
for (BundleJobBean bundle : bundles) {
q.setParameter("bundleId", bundle.getId());
List<Object[]> response = q.getResultList();
for (Object[] r : response) {
BulkResponseImpl br = getResponseFromObject(bundle, r);
responseList.add(br);
}
}
return q.toString();
}
Aggregations