Search in sources :

Example 1 with DefaultSchedule

use of jp.ossc.nimbus.service.scheduler2.DefaultSchedule in project nimbus by nimbus-org.

the class ScheduleManagerServlet method processAddResponse.

/**
 * スケジュール追加リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processAddResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
    String masterId = getParameter(req, "masterId");
    Date time = null;
    try {
        time = getDateParameter(req, "time", "yyyyMMddHHmmssSSS", true);
    } catch (ParseException e) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'time' is illegal." + e.toString());
        return;
    }
    String taskName = getParameter(req, "taskName");
    String input = getParameter(req, "input");
    String[] depends = getParameterValues(req, "depends");
    ScheduleDepends[] dependsArray = null;
    if (depends != null) {
        dependsArray = new ScheduleDepends[depends.length];
        for (int i = 0; i < dependsArray.length; i++) {
            dependsArray[i] = new DefaultScheduleDepends(depends[i], false);
        }
    }
    String executorKey = getParameter(req, "executorKey");
    String executorType = getParameter(req, "executorType");
    Long retryInterval = getLongParameter(req, "retryInterval");
    Date retryEndTime = null;
    try {
        retryEndTime = getDateParameter(req, "retryEndTime", "yyyyMMddHHmmssSSS", false);
    } catch (ParseException e) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'retryEndTime' is illegal." + e.toString());
        return;
    }
    Long maxDelayTime = getLongParameter(req, "maxDelayTime");
    Exception exception = null;
    DefaultSchedule schedule = null;
    try {
        schedule = new DefaultSchedule(masterId, null, time, taskName, input, dependsArray, null, null, null, executorKey, executorType, retryInterval == null ? 0l : retryInterval.longValue(), retryEndTime, maxDelayTime == null ? 0l : maxDelayTime.longValue());
        scheduleManager.addSchedule(schedule);
    } catch (ScheduleManageException e) {
        exception = e;
    }
    final StringBuilder buf = new StringBuilder();
    if ("json".equals(responseType)) {
        resp.setContentType("application/json;charset=UTF-8");
        Map jsonMap = new HashMap();
        if (exception == null) {
            jsonMap.put("schedule", schedule);
        } else {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            exception.printStackTrace(pw);
            pw.flush();
            jsonMap.put("exception", sw.toString());
        }
        buf.append(toStringConverter.convertToObject(jsonConverter.convertToStream(jsonMap)));
    } else {
        if (exception != null) {
            resp.setContentType("text/html;charset=UTF-8");
            buf.append(exception(exception));
        } else {
            processScheduleResponse(req, resp, responseType);
            return;
        }
    }
    resp.getWriter().println(buf.toString());
}
Also used : DefaultScheduleDepends(jp.ossc.nimbus.service.scheduler2.DefaultScheduleDepends) ScheduleDepends(jp.ossc.nimbus.service.scheduler2.ScheduleDepends) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DefaultScheduleDepends(jp.ossc.nimbus.service.scheduler2.DefaultScheduleDepends) DefaultSchedule(jp.ossc.nimbus.service.scheduler2.DefaultSchedule) ScheduleManageException(jp.ossc.nimbus.service.scheduler2.ScheduleManageException) Date(java.util.Date) ServletException(javax.servlet.ServletException) ParseException(java.text.ParseException) ScheduleManageException(jp.ossc.nimbus.service.scheduler2.ScheduleManageException) IOException(java.io.IOException) StringWriter(java.io.StringWriter) ParseException(java.text.ParseException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) PrintWriter(java.io.PrintWriter)

Aggregations

IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ServletException (javax.servlet.ServletException)1 DefaultSchedule (jp.ossc.nimbus.service.scheduler2.DefaultSchedule)1 DefaultScheduleDepends (jp.ossc.nimbus.service.scheduler2.DefaultScheduleDepends)1 ScheduleDepends (jp.ossc.nimbus.service.scheduler2.ScheduleDepends)1 ScheduleManageException (jp.ossc.nimbus.service.scheduler2.ScheduleManageException)1