Search in sources :

Example 1 with BulkResponseImpl

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());
}
Also used : BulkResponseImpl(org.apache.oozie.client.rest.BulkResponseImpl) BulkResponseInfo(org.apache.oozie.BulkResponseInfo)

Example 2 with BulkResponseImpl

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());
}
Also used : BulkResponseImpl(org.apache.oozie.client.rest.BulkResponseImpl) BulkResponseInfo(org.apache.oozie.BulkResponseInfo)

Example 3 with BulkResponseImpl

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");
}
Also used : BulkResponseImpl(org.apache.oozie.client.rest.BulkResponseImpl) BulkResponseInfo(org.apache.oozie.BulkResponseInfo)

Example 4 with BulkResponseImpl

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);
}
Also used : BulkResponseImpl(org.apache.oozie.client.rest.BulkResponseImpl) BulkResponseInfo(org.apache.oozie.BulkResponseInfo) ArrayList(java.util.ArrayList)

Example 5 with BulkResponseImpl

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();
}
Also used : Query(javax.persistence.Query) Timestamp(java.sql.Timestamp) Entry(java.util.Map.Entry) BundleJobBean(org.apache.oozie.BundleJobBean) BulkResponseImpl(org.apache.oozie.client.rest.BulkResponseImpl)

Aggregations

BulkResponseImpl (org.apache.oozie.client.rest.BulkResponseImpl)10 BulkResponseInfo (org.apache.oozie.BulkResponseInfo)8 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 BundleJobBean (org.apache.oozie.BundleJobBean)2 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Query (javax.persistence.Query)1 BaseEngineException (org.apache.oozie.BaseEngineException)1 BundleEngine (org.apache.oozie.BundleEngine)1 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)1 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)1 BundleEngineService (org.apache.oozie.service.BundleEngineService)1 JPAService (org.apache.oozie.service.JPAService)1 JSONObject (org.json.simple.JSONObject)1