use of jp.ossc.nimbus.service.scheduler2.ScheduleMaster in project nimbus by nimbus-org.
the class ScheduleManagerServlet method processIsMakeScheduleResponse.
/**
* スケジュール作成判定リクエスト処理を行う。<p>
*
* @param req HTTPリクエスト
* @param resp HTTPレスポンス
* @param responseType レスポンス種別
* @exception ServletException
* @exception IOException
*/
protected void processIsMakeScheduleResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
String masterId = getParameter(req, "masterId");
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 from = null;
try {
from = getDateParameter(req, "from", "yyyyMMdd", false);
} catch (ParseException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'from' is illegal." + e.toString());
return;
}
Date to = null;
try {
to = getDateParameter(req, "to", "yyyyMMdd", false);
} catch (ParseException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter 'to' is illegal." + e.toString());
return;
}
Exception exception = null;
boolean isMake = false;
Map masterIdDayMap = new TreeMap();
try {
if (masterId != null) {
ScheduleMaster scheduleMaster = scheduleManager.findScheduleMaster(masterId);
ScheduleMaker scheduleMaker = scheduleMaster != null ? scheduleManager.getScheduleMaker(scheduleMaster.getScheduleType()) : null;
if (scheduleMaster == null) {
exception = new Exception("scheduleMaster not found. masterId=" + masterId);
} else {
Map dayMap = new TreeMap();
masterIdDayMap.put(scheduleMaster.getId(), dayMap);
if (from == null && to == null) {
isMake = scheduleMaker.isMakeSchedule(date, scheduleMaster);
dayMap.put(date, isMake ? Boolean.TRUE : Boolean.FALSE);
} else {
if (to == null) {
to = date;
} else if (from == null) {
from = date;
}
Calendar current = Calendar.getInstance();
current.setTime(from);
Calendar toCal = Calendar.getInstance();
toCal.setTime(to);
while (current.before(toCal) || current.equals(toCal)) {
Date today = current.getTime();
isMake = scheduleMaker.isMakeSchedule(today, scheduleMaster);
dayMap.put(today, isMake ? Boolean.TRUE : Boolean.FALSE);
current.add(Calendar.DAY_OF_YEAR, 1);
}
}
}
} else {
List scheduleMasters = scheduleManager.findAllScheduleMasters();
if (from == null && to == null) {
for (int i = 0; i < scheduleMasters.size(); i++) {
ScheduleMaster scheduleMaster = (ScheduleMaster) scheduleMasters.get(i);
ScheduleMaker scheduleMaker = scheduleManager.getScheduleMaker(scheduleMaster.getScheduleType());
isMake = scheduleMaker.isMakeSchedule(date, scheduleMaster);
Map map = (Map) masterIdDayMap.get(scheduleMaster.getId());
if (map == null) {
map = new TreeMap();
masterIdDayMap.put(scheduleMaster.getId(), map);
}
map.put(date, isMake ? Boolean.TRUE : Boolean.FALSE);
}
} else {
if (to == null) {
to = date;
} else if (from == null) {
from = date;
}
Calendar current = Calendar.getInstance();
current.setTime(from);
Calendar toCal = Calendar.getInstance();
toCal.setTime(to);
while (current.before(toCal) || current.equals(toCal)) {
Date today = current.getTime();
for (int i = 0; i < scheduleMasters.size(); i++) {
ScheduleMaster scheduleMaster = (ScheduleMaster) scheduleMasters.get(i);
ScheduleMaker scheduleMaker = scheduleManager.getScheduleMaker(scheduleMaster.getScheduleType());
isMake = scheduleMaker.isMakeSchedule(today, scheduleMaster);
Map map = (Map) masterIdDayMap.get(scheduleMaster.getId());
if (map == null) {
map = new TreeMap();
masterIdDayMap.put(scheduleMaster.getId(), map);
}
map.put(today, isMake ? Boolean.TRUE : Boolean.FALSE);
}
current.add(Calendar.DAY_OF_YEAR, 1);
}
}
}
} 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 = masterIdDayMap.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
Map resultMap = new HashMap(2);
resultMap.put("masterId", entry.getKey());
List resultList = new ArrayList();
Iterator entries2 = ((Map) entry.getValue()).entrySet().iterator();
while (entries2.hasNext()) {
Map.Entry entry2 = (Map.Entry) entries2.next();
Map resultMap2 = new HashMap(2);
resultMap2.put("date", entry2.getKey());
resultMap2.put("isMake", entry2.getValue());
resultList.add(resultMap2);
}
resultMap.put("result", resultList);
result.add(resultMap);
}
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 {
resp.setContentType("text/html;charset=UTF-8");
if (exception != null) {
buf.append(exception(exception));
} else {
buf.append("<html>");
buf.append(header(HEADER_OTHER));
buf.append("<body>");
buf.append(scheduleMasterIsMakeCondition(getCurrentPath(req), masterId, from, to));
buf.append(scheduleMasterIsMake(getCurrentPath(req), masterIdDayMap));
buf.append("</body>");
buf.append("</html>");
}
}
resp.getWriter().println(buf.toString());
}
use of jp.ossc.nimbus.service.scheduler2.ScheduleMaster in project nimbus by nimbus-org.
the class ScheduleManagerServlet method scheduleMasters.
/**
* スケジュール管理画面HTMLのスケジュールマスタデータ部分HTMLを生成する。<p>
*
* @param action サーブレットパス(FormタグのAction文字列)
* @param schedules スケジュールオブジェクトのリスト
* @return スケジュール管理画面HTMLのスケジュールマスタデータ部分HTML
*/
private String scheduleMasters(HttpServletRequest req, List scheduleMasters) {
String action = getCurrentPath(req);
final StringBuilder buf = new StringBuilder();
buf.append("<table border=\"1\">");
buf.append("<tr bgcolor=\"#cccccc\">");
buf.append(th("MasterId"));
buf.append(th("addSchedule"));
buf.append(th("MasterGroupIds"));
buf.append(th("TaskName"));
buf.append(th("ScheduleType"));
buf.append(th("Input"));
buf.append(th("StartTime"));
buf.append(th("EndTime"));
buf.append(th("RepeatInterval"));
buf.append(th("RetryInterval"));
buf.append(th("RetryEndTime"));
buf.append(th("MaxDelayTime"));
buf.append(th("Enable"));
buf.append(th("ExecutorKey"));
buf.append(th("ExecutorType"));
buf.append(th("Template"));
buf.append("</tr>");
if (scheduleMasters != null) {
int count = 0;
for (int i = 0; i < scheduleMasters.size(); i++) {
ScheduleMaster scheduleMaster = (ScheduleMaster) scheduleMasters.get(i);
buf.append("<tr>");
String masterId = format(scheduleMaster.getId());
buf.append(td(masterId));
String input = format(scheduleMaster.getInput());
String startTime = formatTime(scheduleMaster.getStartTime());
String endTime = formatTime(scheduleMaster.getEndTime());
String retryEndTime = formatTime(scheduleMaster.getRetryEndTime());
String executorKey = format(scheduleMaster.getExecutorKey());
final StringBuilder tdBuf = new StringBuilder();
if (isAddEnabled()) {
String dateName = "date_" + count;
tdBuf.append("Date[yyyyMMdd]:" + text(dateName, dateName, "", 10) + " ");
String startTimeName = "startTime_" + count;
tdBuf.append("StartTime[HHmmssSSS]:" + text(startTimeName, startTimeName, startTime, 10) + " ");
String endTimeName = "endTime_" + count;
tdBuf.append("EndTime[HHmmssSSS]:" + text(endTimeName, endTimeName, endTime, 10) + "<br>");
String retryEndTimeName = "retryEndTime_" + count;
tdBuf.append("RetryEndTime[HHmmssSSS]:" + text(retryEndTimeName, retryEndTimeName, retryEndTime, 10) + " ");
String inputName = "input_" + count;
tdBuf.append("Input:" + textarea(inputName, inputName, input, 50, 3, false) + " ");
String executorKeyName = "executorKey_" + count;
tdBuf.append("ExecutorKey:" + text(executorKeyName, executorKeyName, executorKey, 10) + " ");
buf.append(td(tdBuf.toString() + " " + button("AddSchedule", "javascript:addScheduleOne('" + masterId + "','" + inputName + "','" + dateName + "','" + startTimeName + "','" + endTimeName + "','" + retryEndTimeName + "','" + executorKeyName + "');")));
}
buf.append(td(format(scheduleMaster.getGroupIds())));
buf.append(td(format(scheduleMaster.getTaskName())));
buf.append(td(format(scheduleMaster.getScheduleType())));
buf.append(td(textarea(input, 50, 3)));
buf.append(td(startTime));
buf.append(td(endTime));
buf.append(td(scheduleMaster.getRepeatInterval()));
buf.append(td(scheduleMaster.getRetryInterval()));
buf.append(td(retryEndTime));
buf.append(td(scheduleMaster.getMaxDelayTime()));
buf.append(td(scheduleMaster.isEnabled()));
buf.append(td(executorKey));
buf.append(td(format(scheduleMaster.getExecutorType())));
buf.append(td(scheduleMaster.isTemplate()));
buf.append("</tr>");
count++;
}
}
buf.append("</table>");
if (isAddEnabled()) {
buf.append("<form name=\"addFromMaster\" id=\"addFromMaster\" action=\"" + action + "\" method=\"post\">");
buf.append(hidden("masterId", null, ""));
buf.append(hidden("input", null, ""));
buf.append(hidden("date", null, ""));
buf.append(hidden("startTime", null, ""));
buf.append(hidden("endTime", null, ""));
buf.append(hidden("retryEndTime", null, ""));
buf.append(hidden("executorKey", null, ""));
buf.append(hidden("action", null, "addFromMaster"));
buf.append(hidden("search_masterId", null, format(getParameter(req, "search_masterId"))));
buf.append(hidden("search_masterGroupId", null, format(getParameter(req, "search_masterGroupId"))));
buf.append("</form>");
}
return buf.toString();
}
use of jp.ossc.nimbus.service.scheduler2.ScheduleMaster in project nimbus by nimbus-org.
the class ScheduleMakeActionService method execute.
/**
* リソースの内容を読み込んで、指定されたスケジュールマスタから、現在時刻で開始するスケジュールを作成する。<p>
* リソースのフォーマットは、以下。<br>
* <pre>
* masterId
* </pre>
* masterIdは、作成するスケジュールのマスタIDを指定する。<br>
*
* @param context コンテキスト
* @param actionId アクションID
* @param resource リソース
* @return 生成されたスケジュールのリスト
*/
public Object execute(TestContext context, String actionId, Reader resource) throws Exception {
BufferedReader br = new BufferedReader(resource);
String masterId = null;
try {
masterId = br.readLine();
if (masterId == null) {
throw new Exception("Unexpected EOF on masterId");
}
} finally {
br.close();
br = null;
}
Date now = new Date();
final DefaultScheduleMaster master = (DefaultScheduleMaster) scheduleManager.findScheduleMaster(masterId);
if (master == null) {
throw new Exception("ScheduleMaster not found. masterId=" + masterId);
}
final Calendar cal = Calendar.getInstance();
Date startTime = master.getStartTime();
long offset = 0;
if (startTime != null) {
cal.setTime(now);
final int year = cal.get(Calendar.YEAR);
final int day = cal.get(Calendar.DAY_OF_YEAR);
cal.clear();
cal.setTime(startTime);
cal.set(Calendar.YEAR, year);
cal.set(Calendar.DAY_OF_YEAR, day + (cal.get(Calendar.DAY_OF_YEAR) - 1));
offset = now.getTime() - cal.getTimeInMillis();
cal.clear();
cal.setTime(now);
cal.set(Calendar.DAY_OF_YEAR, 1);
startTime = cal.getTime();
}
master.setStartTime(startTime);
final Date endTime = master.getEndTime();
if (endTime != null) {
master.setEndTime(new Date(endTime.getTime() + offset));
}
final Date retryEndTime = master.getRetryEndTime();
if (retryEndTime != null) {
master.setRetryEndTime(new Date(retryEndTime.getTime() + offset));
}
return scheduleManager.makeSchedule(now, master);
}
use of jp.ossc.nimbus.service.scheduler2.ScheduleMaster 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.ScheduleMaster in project nimbus by nimbus-org.
the class ScheduleManagerServlet method processScheduleMasterResponse.
/**
* スケジュールマスタ検索リクエスト処理を行う。<p>
*
* @param req HTTPリクエスト
* @param resp HTTPレスポンス
* @param responseType レスポンス種別
* @exception ServletException
* @exception IOException
*/
protected void processScheduleMasterResponse(HttpServletRequest req, HttpServletResponse resp, String responseType) throws ServletException, IOException {
String masterId = getParameter(req, "search_masterId");
String masterGroupId = getParameter(req, "search_masterGroupId");
Exception exception = null;
List scheduleMasters = null;
if (masterId != null && masterId.length() != 0) {
try {
ScheduleMaster scheduleMaster = scheduleManager.findScheduleMaster(masterId);
if (scheduleMaster != null) {
scheduleMasters = new ArrayList(1);
scheduleMasters.add(scheduleMaster);
}
} catch (ScheduleManageException e) {
exception = e;
}
} else if (masterGroupId != null && masterGroupId.length() != 0) {
try {
scheduleMasters = scheduleManager.findScheduleMasters(masterGroupId);
} catch (ScheduleManageException e) {
exception = e;
}
} else {
try {
scheduleMasters = scheduleManager.findAllScheduleMasters();
} 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("scheduleMasters", scheduleMasters);
} 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_MASTER));
buf.append("<body>");
buf.append(scheduleMasterSearchCondition(getCurrentPath(req), masterId, masterGroupId));
buf.append(scheduleMasters(req, scheduleMasters));
buf.append("</body>");
buf.append("</html>");
}
}
resp.getWriter().println(buf.toString());
}
Aggregations