Search in sources :

Example 6 with ScheduleManageException

use of jp.ossc.nimbus.service.scheduler2.ScheduleManageException 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)

Example 7 with ScheduleManageException

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

the class ScheduleManagerServlet method processDependedResponse.

/**
 * 依存されているスケジュール(後続スケジュール)の検索リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processDependedResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
    String id = getParameter(req, "id");
    if (id == null) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'id' is null.");
        return;
    }
    Exception exception = null;
    List schedules = null;
    try {
        schedules = scheduleManager.findDependedSchedules(id);
    } 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("schedules", schedules);
        } 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 {
        resp.setContentType("text/html;charset=UTF-8");
        if (exception != null) {
            buf.append(exception(exception));
        } else {
            int[] states = null;
            try {
                states = getIntParameterValues(req, "state");
            } catch (Exception e) {
            }
            buf.append("<html>");
            buf.append(header(HEADER_OTHER));
            buf.append("<body>");
            try {
                buf.append(schedules(req, schedules, states));
            } catch (Exception e) {
                resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter is illegal. " + e.getMessage());
                return;
            }
            buf.append("</body>");
            buf.append("</html>");
        }
    }
    resp.getWriter().println(buf.toString());
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) ScheduleManageException(jp.ossc.nimbus.service.scheduler2.ScheduleManageException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) ServletException(javax.servlet.ServletException) ParseException(java.text.ParseException) ScheduleManageException(jp.ossc.nimbus.service.scheduler2.ScheduleManageException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 8 with ScheduleManageException

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

the class ScheduleManagerServlet method processScheduleTypeResponse.

/**
 * スケジュール種別取得リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processScheduleTypeResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
    Exception exception = null;
    Map typeMap = null;
    try {
        typeMap = scheduleManager.getScheduleMakerMap();
    } 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) {
            Object[] types = typeMap == null ? null : typeMap.keySet().toArray();
            if (types != null) {
                Arrays.sort(types);
            }
            jsonMap.put("scheduleType", types);
        } 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 {
    }
    resp.getWriter().println(buf.toString());
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) ScheduleManageException(jp.ossc.nimbus.service.scheduler2.ScheduleManageException) ServletException(javax.servlet.ServletException) ParseException(java.text.ParseException) ScheduleManageException(jp.ossc.nimbus.service.scheduler2.ScheduleManageException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 9 with ScheduleManageException

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

the class ScheduleManagerServlet method processExecutableScheduleResponse.

/**
 * 実行可能スケジュール検索リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processExecutableScheduleResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
    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[] executorTypes = getParameterValues(req, "executorType");
    String executorKey = getParameter(req, "executorKey");
    List schedules = null;
    Exception exception = null;
    try {
        schedules = scheduleManager.findExecutableSchedules(time, executorTypes, executorKey);
    } 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("schedules", schedules);
        } 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 {
        resp.setContentType("text/html;charset=UTF-8");
        if (exception != null) {
            buf.append(exception(exception));
        } else {
            buf.append("<html>");
            buf.append(header(HEADER_SCHEDULE));
            buf.append("<body>");
            buf.append(scheduleSearchCondition(getCurrentPath(req), "", "", "", "", null, null, null));
            try {
                buf.append(schedules(req, schedules, null));
            } catch (Exception e) {
                resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter is illegal. " + e.getMessage());
                return;
            }
            buf.append("</body>");
            buf.append("</html>");
        }
    }
    resp.getWriter().println(buf.toString());
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException) ScheduleManageException(jp.ossc.nimbus.service.scheduler2.ScheduleManageException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Date(java.util.Date) ServletException(javax.servlet.ServletException) ParseException(java.text.ParseException) ScheduleManageException(jp.ossc.nimbus.service.scheduler2.ScheduleManageException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 10 with ScheduleManageException

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

the class ScheduleManagerServlet method processRescheduleResponse.

/**
 * スケジュール時刻変更リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processRescheduleResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
    String[] id = getParameterValues(req, "id");
    if (id == null) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'id' is null.");
        return;
    }
    Date[] time = null;
    try {
        time = getDateParameterValues(req, "time", "yyyyMMddHHmmssSSS", true, id.length);
    } catch (ParseException e) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'time' is illegal." + e.toString());
        return;
    }
    String[] output = getParameterValues(req, "output");
    Map isChanged = new LinkedHashMap();
    Exception exception = null;
    try {
        for (int i = 0; i < id.length; i++) {
            if (scheduleManager.reschedule(id[i], time[i], output[i])) {
                isChanged.put(id[i], Boolean.TRUE);
            } else {
                isChanged.put(id[i], Boolean.FALSE);
            }
        }
    } 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) {
            List result = new ArrayList();
            Iterator entries = isChanged.entrySet().iterator();
            while (entries.hasNext()) {
                Map.Entry entry = (Map.Entry) entries.next();
                Map map = new HashMap(2);
                map.put("id", entry.getKey());
                map.put("result", entry.getValue());
                result.add(map);
            }
            jsonMap.put("result", result);
        } 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 : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) 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) LinkedHashMap(java.util.LinkedHashMap) StringWriter(java.io.StringWriter) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) 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)17 PrintWriter (java.io.PrintWriter)17 StringWriter (java.io.StringWriter)17 ParseException (java.text.ParseException)17 HashMap (java.util.HashMap)17 LinkedHashMap (java.util.LinkedHashMap)17 Map (java.util.Map)17 TreeMap (java.util.TreeMap)17 ServletException (javax.servlet.ServletException)17 ScheduleManageException (jp.ossc.nimbus.service.scheduler2.ScheduleManageException)17 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Date (java.util.Date)9 Iterator (java.util.Iterator)4 ScheduleMaster (jp.ossc.nimbus.service.scheduler2.ScheduleMaster)3 DefaultSchedule (jp.ossc.nimbus.service.scheduler2.DefaultSchedule)2 Calendar (java.util.Calendar)1 DefaultScheduleDepends (jp.ossc.nimbus.service.scheduler2.DefaultScheduleDepends)1 Schedule (jp.ossc.nimbus.service.scheduler2.Schedule)1 ScheduleDepends (jp.ossc.nimbus.service.scheduler2.ScheduleDepends)1