Search in sources :

Example 6 with BulkResponseInfo

use of org.apache.oozie.BulkResponseInfo 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 7 with BulkResponseInfo

use of org.apache.oozie.BulkResponseInfo in project oozie by apache.

the class BulkJobsXCommand method execute.

/* (non-Javadoc)
     * @see org.apache.oozie.command.XCommand#execute()
     */
@Override
protected BulkResponseInfo execute() throws CommandException {
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        BulkResponseInfo bulk = null;
        if (jpaService != null) {
            bulk = jpaService.execute(new BulkJPAExecutor(bulkParams, start, len));
        } else {
            LOG.error(ErrorCode.E0610);
        }
        return bulk;
    } catch (XException ex) {
        throw new CommandException(ex);
    }
}
Also used : BulkResponseInfo(org.apache.oozie.BulkResponseInfo) XException(org.apache.oozie.XException) BulkJPAExecutor(org.apache.oozie.executor.jpa.BulkJPAExecutor) CommandException(org.apache.oozie.command.CommandException) JPAService(org.apache.oozie.service.JPAService)

Example 8 with BulkResponseInfo

use of org.apache.oozie.BulkResponseInfo 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 9 with BulkResponseInfo

use of org.apache.oozie.BulkResponseInfo 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 10 with BulkResponseInfo

use of org.apache.oozie.BulkResponseInfo 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)

Aggregations

BulkResponseInfo (org.apache.oozie.BulkResponseInfo)11 BulkResponseImpl (org.apache.oozie.client.rest.BulkResponseImpl)8 ArrayList (java.util.ArrayList)3 BundleJobBean (org.apache.oozie.BundleJobBean)2 BulkJPAExecutor (org.apache.oozie.executor.jpa.BulkJPAExecutor)2 JPAService (org.apache.oozie.service.JPAService)2 Timestamp (java.sql.Timestamp)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 BaseEngineException (org.apache.oozie.BaseEngineException)1 BundleEngine (org.apache.oozie.BundleEngine)1 XException (org.apache.oozie.XException)1 CommandException (org.apache.oozie.command.CommandException)1 BundleJobInsertJPAExecutor (org.apache.oozie.executor.jpa.BundleJobInsertJPAExecutor)1 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)1 BundleEngineService (org.apache.oozie.service.BundleEngineService)1 JSONObject (org.json.simple.JSONObject)1