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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations