Search in sources :

Example 6 with BulkResponseImpl

use of org.apache.oozie.client.rest.BulkResponseImpl in project oozie by apache.

the class BulkJPAExecutor method execute.

@Override
public BulkResponseInfo execute(EntityManager em) throws JPAExecutorException {
    List<BulkResponseImpl> responseList = new ArrayList<BulkResponseImpl>();
    Map<String, Timestamp> actionTimes = new HashMap<String, Timestamp>();
    try {
        List<String> coords = bulkFilter.get(BulkResponseImpl.BULK_FILTER_COORD);
        List<String> statuses = bulkFilter.get(BulkResponseImpl.BULK_FILTER_STATUS);
        List<String> params = new ArrayList<String>();
        // Lightweight Query 1 on Bundle level to fetch the bundle job(s)
        // corresponding to names or ids
        List<BundleJobBean> bundleBeans = bundleQuery(em);
        // Join query between coordinator job and coordinator action tables
        // to get entries for specific bundleId only
        String conditions = actionQuery(coords, params, statuses, em, bundleBeans, actionTimes, responseList);
        // Query to get the count of records
        long total = countQuery(statuses, params, conditions, em, bundleBeans, actionTimes);
        BulkResponseInfo bulk = new BulkResponseInfo(responseList, start, len, total);
        return bulk;
    } catch (Exception e) {
        throw new JPAExecutorException(ErrorCode.E0603, e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) BulkResponseInfo(org.apache.oozie.BulkResponseInfo) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) ParseException(java.text.ParseException) BulkResponseImpl(org.apache.oozie.client.rest.BulkResponseImpl) BundleJobBean(org.apache.oozie.BundleJobBean)

Example 7 with BulkResponseImpl

use of org.apache.oozie.client.rest.BulkResponseImpl in project oozie by apache.

the class BulkJPAExecutor method getResponseFromObject.

private BulkResponseImpl getResponseFromObject(BundleJobBean bundleBean, Object[] arr) {
    BulkResponseImpl bean = new BulkResponseImpl();
    CoordinatorJobBean coordBean = new CoordinatorJobBean();
    CoordinatorActionBean actionBean = new CoordinatorActionBean();
    if (arr[0] != null) {
        actionBean.setId((String) arr[0]);
    }
    if (arr[1] != null) {
        actionBean.setActionNumber((Integer) arr[1]);
    }
    if (arr[2] != null) {
        actionBean.setErrorCode((String) arr[2]);
    }
    if (arr[3] != null) {
        actionBean.setErrorMessage((String) arr[3]);
    }
    if (arr[4] != null) {
        actionBean.setExternalId((String) arr[4]);
    }
    if (arr[5] != null) {
        actionBean.setExternalStatus((String) arr[5]);
    }
    if (arr[6] != null) {
        actionBean.setStatus(CoordinatorAction.Status.valueOf((String) arr[6]));
    }
    if (arr[7] != null) {
        actionBean.setCreatedTime(DateUtils.toDate((Timestamp) arr[7]));
    }
    if (arr[8] != null) {
        actionBean.setNominalTime(DateUtils.toDate((Timestamp) arr[8]));
    }
    if (arr[9] != null) {
        actionBean.setMissingDependenciesBlob((StringBlob) arr[9]);
    }
    if (arr[10] != null) {
        coordBean.setId((String) arr[10]);
        actionBean.setJobId((String) arr[10]);
    }
    if (arr[11] != null) {
        coordBean.setAppName((String) arr[11]);
    }
    if (arr[12] != null) {
        coordBean.setStatus(CoordinatorJob.Status.valueOf((String) arr[12]));
    }
    bean.setBundle(bundleBean);
    bean.setCoordinator(coordBean);
    bean.setAction(actionBean);
    return bean;
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) BulkResponseImpl(org.apache.oozie.client.rest.BulkResponseImpl) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) Timestamp(java.sql.Timestamp)

Example 8 with BulkResponseImpl

use of org.apache.oozie.client.rest.BulkResponseImpl in project oozie by apache.

the class V1JobsServlet method getBulkJobs.

@SuppressWarnings("unchecked")
private JSONObject getBulkJobs(HttpServletRequest request) throws XServletException, IOException {
    JSONObject json = new JSONObject();
    try {
        // REST API
        String bulkFilter = request.getParameter(RestConstants.JOBS_BULK_PARAM);
        String startStr = request.getParameter(RestConstants.OFFSET_PARAM);
        String lenStr = request.getParameter(RestConstants.LEN_PARAM);
        String timeZoneId = request.getParameter(RestConstants.TIME_ZONE_PARAM) == null ? "GMT" : request.getParameter(RestConstants.TIME_ZONE_PARAM);
        int start = (startStr != null) ? Integer.parseInt(startStr) : 1;
        start = (start < 1) ? 1 : start;
        int len = (lenStr != null) ? Integer.parseInt(lenStr) : 50;
        len = (len < 1) ? 50 : len;
        BundleEngine bundleEngine = Services.get().get(BundleEngineService.class).getBundleEngine(getUser(request));
        BulkResponseInfo bulkResponse = bundleEngine.getBulkJobs(bulkFilter, start, len);
        List<BulkResponseImpl> responsesToJson = bulkResponse.getResponses();
        json.put(JsonTags.BULK_RESPONSES, BulkResponseImpl.toJSONArray(responsesToJson, timeZoneId));
        json.put(JsonTags.BULK_RESPONSE_TOTAL, bulkResponse.getTotal());
        json.put(JsonTags.BULK_RESPONSE_OFFSET, bulkResponse.getStart());
        json.put(JsonTags.BULK_RESPONSE_LEN, bulkResponse.getLen());
    } catch (BaseEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
    return json;
}
Also used : JSONObject(org.json.simple.JSONObject) BulkResponseImpl(org.apache.oozie.client.rest.BulkResponseImpl) BundleEngineService(org.apache.oozie.service.BundleEngineService) BulkResponseInfo(org.apache.oozie.BulkResponseInfo) BaseEngineException(org.apache.oozie.BaseEngineException) BundleEngine(org.apache.oozie.BundleEngine)

Example 9 with BulkResponseImpl

use of org.apache.oozie.client.rest.BulkResponseImpl in project oozie by apache.

the class TestBulkMonitorJPAExecutor method testBundleIdWithCoordId.

public void testBundleIdWithCoordId() throws Exception {
    // fetching coord Ids
    JPAService jpaService = Services.get().get(JPAService.class);
    List<String> coordIds = jpaService.execute(new CoordJobsGetFromParentIdJPAExecutor(bundleId, 10));
    // there are 3 coordinators but giving range as only two of them
    String coordIdsStr = coordIds.get(0) + "," + coordIds.get(1);
    String request = "bundle=" + bundleId + ";coordinators=" + coordIdsStr + ";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) JPAService(org.apache.oozie.service.JPAService)

Example 10 with BulkResponseImpl

use of org.apache.oozie.client.rest.BulkResponseImpl in project oozie by apache.

the class TestBulkMonitorJPAExecutor method testMultipleRecords.

public void testMultipleRecords() throws Exception {
    String request = "bundle=" + bundleName + ";actionstatus=FAILED,KILLED;" + "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();
    // 3 actions satisfy the conditions
    assertEquals(3, brList.size());
    assertEquals(3, response.getTotal());
    List<String> possibleStatus = new ArrayList<String>(Arrays.asList("KILLED", "FAILED"));
    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)

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