Search in sources :

Example 1 with CallbackService

use of org.apache.oozie.service.CallbackService in project oozie by apache.

the class CallbackServlet method doGet.

/**
 * GET callback
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String queryString = request.getQueryString();
    CallbackService callbackService = Services.get().get(CallbackService.class);
    if (!callbackService.isValid(queryString)) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0402, queryString);
    }
    String actionId = callbackService.getActionId(queryString);
    if (actionId == null) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0402, queryString);
    }
    log = XLog.getLog(getClass());
    setLogInfo(actionId);
    log.debug("Received a CallbackServlet.doGet() with query string " + queryString);
    DagEngine dagEngine = Services.get().get(DagEngineService.class).getSystemDagEngine();
    try {
        log.info(XLog.STD, "callback for action [{0}]", actionId);
        dagEngine.processCallback(actionId, callbackService.getExternalStatus(queryString), null);
    } catch (DagEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
}
Also used : CallbackService(org.apache.oozie.service.CallbackService) DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) DagEngineService(org.apache.oozie.service.DagEngineService)

Example 2 with CallbackService

use of org.apache.oozie.service.CallbackService in project oozie by apache.

the class TestCallbackService method testCallbacks.

public void testCallbacks() throws Exception {
    CallbackService cs = Services.get().get(CallbackService.class);
    assertNotNull(cs);
    String callback = cs.createCallBackUrl("a", "@STATUS");
    assertTrue(callback.contains("http://"));
    assertTrue(callback.contains("id=a"));
    assertTrue(callback.contains("status=@STATUS"));
    callback = callback.replace("@STATUS", "OK");
    assertEquals("a", cs.getActionId(callback));
    assertEquals("OK", cs.getExternalStatus(callback));
}
Also used : CallbackService(org.apache.oozie.service.CallbackService)

Example 3 with CallbackService

use of org.apache.oozie.service.CallbackService in project oozie by apache.

the class CallbackServlet method doPost.

/**
 * POST callback
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String queryString = request.getQueryString();
    CallbackService callbackService = Services.get().get(CallbackService.class);
    if (!callbackService.isValid(queryString)) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0402, queryString);
    }
    String actionId = callbackService.getActionId(queryString);
    if (actionId == null) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0402, queryString);
    }
    log = XLog.getLog(getClass());
    setLogInfo(actionId);
    log.debug("Received a CallbackServlet.doPost() with query string " + queryString);
    validateContentType(request, RestConstants.TEXT_CONTENT_TYPE);
    try {
        log.info(XLog.STD, "callback for action [{0}]", actionId);
        String data = IOUtils.getReaderAsString(request.getReader(), maxDataLen);
        Properties props = PropertiesUtils.stringToProperties(data);
        DagEngine dagEngine = Services.get().get(DagEngineService.class).getSystemDagEngine();
        dagEngine.processCallback(actionId, callbackService.getExternalStatus(queryString), props);
    } catch (IOException ex) {
        if (ex.getMessage().startsWith("stream exceeds limit")) {
            // TODO, WE MUST SET THE ACTION TO ERROR
            throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0403, "data too long");
        } else {
            throw ex;
        }
    } catch (DagEngineException ex) {
        throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ex);
    }
}
Also used : CallbackService(org.apache.oozie.service.CallbackService) DagEngineException(org.apache.oozie.DagEngineException) DagEngine(org.apache.oozie.DagEngine) DagEngineService(org.apache.oozie.service.DagEngineService) IOException(java.io.IOException) Properties(java.util.Properties)

Example 4 with CallbackService

use of org.apache.oozie.service.CallbackService in project oozie by apache.

the class TestCallbackService method testService.

public void testService() throws Exception {
    CallbackService cs = Services.get().get(CallbackService.class);
    assertNotNull(cs);
}
Also used : CallbackService(org.apache.oozie.service.CallbackService)

Aggregations

CallbackService (org.apache.oozie.service.CallbackService)4 DagEngine (org.apache.oozie.DagEngine)2 DagEngineException (org.apache.oozie.DagEngineException)2 DagEngineService (org.apache.oozie.service.DagEngineService)2 IOException (java.io.IOException)1 Properties (java.util.Properties)1