Search in sources :

Example 11 with ScheduleManageException

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

the class ScheduleManagerServlet method processChangeRetryEndTimeResponse.

/**
 * リトライ終了時刻変更リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processChangeRetryEndTimeResponse(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", false, id.length);
    } catch (ParseException e) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'time' is illegal." + e.toString());
        return;
    }
    if (time == null) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'time' is null.");
        return;
    }
    Exception exception = null;
    try {
        for (int i = 0; i < id.length; i++) {
            scheduleManager.setRetryEndTime(id[i], time[i]);
        }
    } 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) {
            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) 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 12 with ScheduleManageException

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

the class ScheduleManagerServlet method processAddFromMasterResponse.

/**
 * スケジュールマスタからのスケジュール追加リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processAddFromMasterResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
    String masterId = getParameter(req, "masterId");
    String masterGroupId = getParameter(req, "masterGroupId");
    if (masterId == null && masterGroupId == null) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'masterId' and 'masterGroupId' is null.");
        return;
    }
    boolean isNullInput = isNullParameter(req, "input");
    String input = getParameter(req, "input");
    Date date = null;
    try {
        date = getDateParameter(req, "date", "yyyyMMdd", true);
    } catch (ParseException e) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'date' is illegal." + e.toString());
        return;
    }
    Date startTime = null;
    try {
        startTime = getDateParameter(req, "startTime", "HHmmssSSS", false);
    } catch (ParseException e) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'startTime' is illegal." + e.toString());
        return;
    }
    Date endTime = null;
    try {
        endTime = getDateParameter(req, "endTime", "HHmmssSSS", false);
    } catch (ParseException e) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'endTime' is illegal." + e.toString());
        return;
    }
    Date retryEndTime = null;
    try {
        retryEndTime = getDateParameter(req, "retryEndTime", "HHmmssSSS", false);
    } catch (ParseException e) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'retryEndTime' is illegal." + e.toString());
        return;
    }
    boolean isNullExecutorKey = isNullParameter(req, "executorKey");
    String executorKey = getParameter(req, "executorKey");
    Exception exception = null;
    List schedules = null;
    try {
        List scheduleMasters = null;
        if (masterId != null) {
            scheduleMasters = new ArrayList();
            ScheduleMaster scheduleMaster = scheduleManager.findScheduleMaster(masterId);
            if (scheduleMaster == null) {
                exception = new Exception("ScheduleMaster not found. masterId=" + masterId);
            } else {
                scheduleMasters.add(scheduleMaster);
            }
        } else {
            scheduleMasters = scheduleManager.findScheduleMasters(masterGroupId);
            if (scheduleMasters == null || scheduleMasters.size() == 0) {
                exception = new Exception("ScheduleMaster not found. masterGroupId=" + masterGroupId);
            }
        }
        for (int i = 0; i < scheduleMasters.size(); i++) {
            ScheduleMaster scheduleMaster = (ScheduleMaster) scheduleMasters.get(i);
            if (isNullInput) {
                scheduleMaster.setInput(null);
            } else if (input != null) {
                scheduleMaster.setInput(input);
            }
            if (startTime != null) {
                scheduleMaster.setStartTime(startTime);
            }
            if (endTime != null) {
                scheduleMaster.setEndTime(endTime);
            }
            if (retryEndTime != null) {
                scheduleMaster.setRetryEndTime(retryEndTime);
            }
            if (isNullExecutorKey) {
                scheduleMaster.setExecutorKey(null);
            } else if (executorKey != null) {
                scheduleMaster.setExecutorKey(executorKey);
            }
            scheduleMaster.setTemplate(false);
        }
        if (scheduleMasters.size() != 0) {
            schedules = scheduleManager.makeSchedule(date, scheduleMasters);
        }
    } 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 {
        if (exception != null) {
            resp.setContentType("text/html;charset=UTF-8");
            buf.append(exception(exception));
        } else {
            processScheduleMasterResponse(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) ScheduleMaster(jp.ossc.nimbus.service.scheduler2.ScheduleMaster) StringWriter(java.io.StringWriter) 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)

Example 13 with ScheduleManageException

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

the class ScheduleManagerServlet method processChangeMaxDelayTimeResponse.

/**
 * 最大遅延時間変更リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processChangeMaxDelayTimeResponse(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;
    }
    long[] time = null;
    try {
        time = getLongParameterValues(req, "time");
    } catch (NumberFormatException e) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'time' is illegal." + e.toString());
        return;
    }
    Exception exception = null;
    try {
        for (int i = 0; i < id.length; i++) {
            scheduleManager.setMaxDelayTime(id[i], time[i]);
        }
    } 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) {
            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 : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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 14 with ScheduleManageException

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

the class ScheduleManagerServlet method processChangeExecutorKeyResponse.

/**
 * 実行キー変更リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processChangeExecutorKeyResponse(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;
    }
    String[] executorKey = getParameterValues(req, "executorKey");
    Exception exception = null;
    try {
        for (int i = 0; i < id.length; i++) {
            scheduleManager.setExecutorKey(id[i], executorKey[i]);
        }
    } 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) {
            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 : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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 15 with ScheduleManageException

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

the class ScheduleManagerServlet method processChangeStateResponse.

/**
 * スケジュール状態変更リクエスト処理を行う。<p>
 *
 * @param req HTTPリクエスト
 * @param resp HTTPレスポンス
 * @param responseType レスポンス種別
 * @exception ServletException
 * @exception IOException
 */
protected void processChangeStateResponse(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;
    }
    int[] oldState = getIntParameterValues(req, "oldState");
    int[] newState = getIntParameterValues(req, "newState");
    if (newState == null) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'newState' is null.");
        return;
    }
    String[] output = getParameterValues(req, "output", false);
    Map isChanged = new LinkedHashMap();
    Exception exception = null;
    try {
        if (oldState == null) {
            for (int i = 0; i < id.length; i++) {
                if (output == null || output[i] == null) {
                    if (scheduleManager.changeState(id[i], newState[i])) {
                        isChanged.put(id[i], Boolean.TRUE);
                    } else {
                        isChanged.put(id[i], Boolean.FALSE);
                    }
                } else {
                    if (scheduleManager.changeState(id[i], newState[i], "null".equals(output[i]) ? null : output[i])) {
                        isChanged.put(id[i], Boolean.TRUE);
                    } else {
                        isChanged.put(id[i], Boolean.FALSE);
                    }
                }
            }
        } else {
            for (int i = 0; i < id.length; i++) {
                if (output == null || output[i] == null) {
                    if (scheduleManager.changeState(id[i], oldState[i], newState[i])) {
                        isChanged.put(id[i], Boolean.TRUE);
                    } else {
                        isChanged.put(id[i], Boolean.FALSE);
                    }
                } else {
                    if (scheduleManager.changeState(id[i], oldState[i], newState[i], "null".equals(output[i]) ? null : 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) 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) 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