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