List of usage examples for org.joda.time DateTime now
public static DateTime now()
ISOChronology
in the default time zone. From source file:azkaban.reportal.util.Reportal.java
License:Apache License
public void updateSchedules(Reportal report, ScheduleManager scheduleManager, User user, Flow flow) throws ScheduleManagerException { // Clear previous schedules removeSchedules(scheduleManager);/* www .j a v a 2s .c om*/ // Add new schedule if (schedule) { int hour = (Integer.parseInt(scheduleHour) % 12) + (scheduleAmPm.equalsIgnoreCase("pm") ? 12 : 0); int minute = Integer.parseInt(scheduleMinute) % 60; DateTimeZone timeZone = scheduleTimeZone.equalsIgnoreCase("UTC") ? DateTimeZone.UTC : DateTimeZone.getDefault(); DateTime firstSchedTime = DateTimeFormat.forPattern("MM/dd/yyyy").withZone(timeZone) .parseDateTime(scheduleDate); firstSchedTime = firstSchedTime.withHourOfDay(hour).withMinuteOfHour(minute).withSecondOfMinute(0) .withMillisOfSecond(0); ReadablePeriod period = null; if (scheduleRepeat) { int intervalQuantity = Integer.parseInt(scheduleIntervalQuantity); if (scheduleInterval.equals("y")) { period = Years.years(intervalQuantity); } else if (scheduleInterval.equals("m")) { period = Months.months(intervalQuantity); } else if (scheduleInterval.equals("w")) { period = Weeks.weeks(intervalQuantity); } else if (scheduleInterval.equals("d")) { period = Days.days(intervalQuantity); } else if (scheduleInterval.equals("h")) { period = Hours.hours(intervalQuantity); } else if (scheduleInterval.equals("M")) { period = Minutes.minutes(intervalQuantity); } } ExecutionOptions options = new ExecutionOptions(); options.getFlowParameters().put("reportal.execution.user", user.getUserId()); options.getFlowParameters().put("reportal.title", report.title); options.getFlowParameters().put("reportal.render.results.as.html", report.renderResultsAsHtml ? "true" : "false"); options.setMailCreator(ReportalMailCreator.REPORTAL_MAIL_CREATOR); scheduleManager.scheduleFlow(-1, project.getId(), project.getName(), flow.getId(), "ready", firstSchedTime.getMillis(), firstSchedTime.getZone(), period, DateTime.now().getMillis(), firstSchedTime.getMillis(), firstSchedTime.getMillis(), user.getUserId(), options, null); } }
From source file:azkaban.trigger.builtin.SlaChecker.java
License:Apache License
private Boolean isSlaMissed(ExecutableFlow flow) { String type = slaOption.getType(); logger.info("flow is " + flow.getStatus()); if (flow.getStartTime() < 0) { return Boolean.FALSE; }// w w w .ja v a 2 s. c o m Status status; if (type.equals(SlaOption.TYPE_FLOW_FINISH)) { if (checkTime < flow.getStartTime()) { ReadablePeriod duration = Utils .parsePeriodString((String) slaOption.getInfo().get(SlaOption.INFO_DURATION)); DateTime startTime = new DateTime(flow.getStartTime()); DateTime nextCheckTime = startTime.plus(duration); this.checkTime = nextCheckTime.getMillis(); } status = flow.getStatus(); if (checkTime < DateTime.now().getMillis()) { return !isFlowFinished(status); } } else if (type.equals(SlaOption.TYPE_FLOW_SUCCEED)) { if (checkTime < flow.getStartTime()) { ReadablePeriod duration = Utils .parsePeriodString((String) slaOption.getInfo().get(SlaOption.INFO_DURATION)); DateTime startTime = new DateTime(flow.getStartTime()); DateTime nextCheckTime = startTime.plus(duration); this.checkTime = nextCheckTime.getMillis(); } status = flow.getStatus(); if (checkTime < DateTime.now().getMillis()) { return !isFlowSucceeded(status); } else { return status.equals(Status.FAILED) || status.equals(Status.KILLED); } } else if (type.equals(SlaOption.TYPE_JOB_FINISH)) { String jobName = (String) slaOption.getInfo().get(SlaOption.INFO_JOB_NAME); ExecutableNode node = flow.getExecutableNode(jobName); if (node.getStartTime() < 0) { return Boolean.FALSE; } if (checkTime < node.getStartTime()) { ReadablePeriod duration = Utils .parsePeriodString((String) slaOption.getInfo().get(SlaOption.INFO_DURATION)); DateTime startTime = new DateTime(node.getStartTime()); DateTime nextCheckTime = startTime.plus(duration); this.checkTime = nextCheckTime.getMillis(); } status = node.getStatus(); if (checkTime < DateTime.now().getMillis()) { return !isJobFinished(status); } } else if (type.equals(SlaOption.TYPE_JOB_SUCCEED)) { String jobName = (String) slaOption.getInfo().get(SlaOption.INFO_JOB_NAME); ExecutableNode node = flow.getExecutableNode(jobName); if (node.getStartTime() < 0) { return Boolean.FALSE; } if (checkTime < node.getStartTime()) { ReadablePeriod duration = Utils .parsePeriodString((String) slaOption.getInfo().get(SlaOption.INFO_DURATION)); DateTime startTime = new DateTime(node.getStartTime()); DateTime nextCheckTime = startTime.plus(duration); this.checkTime = nextCheckTime.getMillis(); } status = node.getStatus(); if (checkTime < DateTime.now().getMillis()) { return !isJobFinished(status); } else { return status.equals(Status.FAILED) || status.equals(Status.KILLED); } } return Boolean.FALSE; }
From source file:azkaban.trigger.JdbcTriggerImpl.java
License:Apache License
/** * TODO: Don't understand why we need synchronized here. *//*ww w. j av a2s . co m*/ @Override public synchronized void addTrigger(final Trigger t) throws TriggerLoaderException { logger.info("Inserting trigger " + t.toString() + " into db."); final SQLTransaction<Long> insertAndGetLastID = transOperator -> { transOperator.update(ADD_TRIGGER, DateTime.now().getMillis()); // This commit must be called in order to unlock trigger table and have last insert ID. transOperator.getConnection().commit(); return transOperator.getLastInsertId(); }; try { final long id = this.dbOperator.transaction(insertAndGetLastID); t.setTriggerId((int) id); updateTrigger(t); logger.info("uploaded trigger " + t.getDescription()); } catch (final SQLException ex) { logger.error("Adding Trigger " + t.getTriggerId() + " failed."); throw new TriggerLoaderException("trigger id is not properly created.", ex); } }
From source file:azkaban.trigger.JdbcTriggerLoader.java
License:Apache License
private synchronized void addTrigger(Connection connection, Trigger t, EncodingType encType) throws TriggerLoaderException { QueryRunner runner = new QueryRunner(); long id;/*ww w . j ava 2 s.com*/ try { runner.update(connection, ADD_TRIGGER, DateTime.now().getMillis()); connection.commit(); id = runner.query(connection, LastInsertID.LAST_INSERT_ID, new LastInsertID()); if (id == -1l) { logger.error("trigger id is not properly created."); throw new TriggerLoaderException("trigger id is not properly created."); } t.setTriggerId((int) id); updateTrigger(t); logger.info("uploaded trigger " + t.getDescription()); } catch (SQLException e) { throw new TriggerLoaderException("Error creating trigger.", e); } }
From source file:azkaban.trigger.Trigger.java
License:Apache License
public Trigger(String submitUser, String source, Condition triggerCondition, Condition expireCondition, List<TriggerAction> actions, List<TriggerAction> expireActions) { this.lastModifyTime = DateTime.now().getMillis(); this.submitTime = DateTime.now().getMillis(); this.submitUser = submitUser; this.source = source; this.triggerCondition = triggerCondition; this.expireCondition = expireCondition; this.actions = actions; this.expireActions = expireActions; }
From source file:azkaban.trigger.Trigger.java
License:Apache License
public Trigger(String submitUser, String source, Condition triggerCondition, Condition expireCondition, List<TriggerAction> actions) { this.lastModifyTime = DateTime.now().getMillis(); this.submitTime = DateTime.now().getMillis(); this.submitUser = submitUser; this.source = source; this.triggerCondition = triggerCondition; this.expireCondition = expireCondition; this.actions = actions; this.expireActions = new ArrayList<TriggerAction>(); }
From source file:azkaban.viewer.reportal.ReportalServlet.java
License:Apache License
private void handleListReportal(HttpServletRequest req, HttpServletResponse resp, Session session) throws ServletException, IOException { Page page = newPage(req, resp, session, "azkaban/viewer/reportal/reportallistpage.vm"); preparePage(page, session);/*from www . ja v a 2 s. c o m*/ List<Project> projects = ReportalHelper.getReportalProjects(server); page.add("ReportalHelper", ReportalHelper.class); page.add("user", session.getUser()); String startDate = DateTime.now().minusWeeks(1).toString("yyyy-MM-dd"); String endDate = DateTime.now().toString("yyyy-MM-dd"); page.add("startDate", startDate); page.add("endDate", endDate); if (!projects.isEmpty()) { page.add("projects", projects); } else { page.add("projects", false); } page.render(); }
From source file:azkaban.webapp.servlet.ScheduleServlet.java
License:Apache License
private void writeScheduleData(List<HashMap<String, Object>> output, Schedule schedule) throws ScheduleManagerException { Map<String, Object> stats = SchedulerStatistics.getStatistics(schedule.getScheduleId(), (AzkabanWebServer) getApplication()); HashMap<String, Object> data = new HashMap<String, Object>(); data.put("scheduleid", schedule.getScheduleId()); data.put("flowname", schedule.getFlowName()); data.put("projectname", schedule.getProjectName()); data.put("time", schedule.getFirstSchedTime()); DateTime time = DateTime.now(); long period = 0; if (schedule.getPeriod() != null) { period = time.plus(schedule.getPeriod()).getMillis() - time.getMillis(); }/*from w ww .j a v a 2 s.c o m*/ data.put("period", period); int length = 3600 * 1000; if (stats.get("average") != null && stats.get("average") instanceof Integer) { length = (int) (Integer) stats.get("average"); if (length == 0) { length = 3600 * 1000; } } data.put("length", length); data.put("history", false); data.put("stats", stats); output.add(data); }
From source file:azkaban.webapp.servlet.ScheduleServlet.java
License:Apache License
private void ajaxLoadHistory(HttpServletRequest req, HttpServletResponse resp, User user) throws ServletException, IOException { resp.setContentType(JSON_MIME_TYPE); long today = DateTime.now().withTime(0, 0, 0, 0).getMillis(); long startTime = getLongParam(req, "startTime"); DateTime start = new DateTime(startTime); // Ensure start time is 12:00 AM startTime = start.withTime(0, 0, 0, 0).getMillis(); boolean useCache = false; if (startTime < today) { useCache = true;/*from w ww . j a va2 s . c o m*/ } long endTime = startTime + 24 * 3600 * 1000; int loadAll = getIntParam(req, "loadAll"); // Cache file String cacheDir = getApplication().getServerProps().getString("cache.directory", "cache"); File cacheDirFile = new File(cacheDir, "schedule-history"); File cache = new File(cacheDirFile, startTime + ".cache"); cache.getParentFile().mkdirs(); if (useCache) { // Determine if cache exists boolean cacheExists = false; synchronized (this) { cacheExists = cache.exists() && cache.isFile(); } if (cacheExists) { // Send the cache instead InputStream cacheInput = new BufferedInputStream(new FileInputStream(cache)); try { IOUtils.copy(cacheInput, resp.getOutputStream()); return; } finally { IOUtils.closeQuietly(cacheInput); } } } // Load data if not cached List<ExecutableFlow> history = null; try { AzkabanWebServer server = (AzkabanWebServer) getApplication(); ExecutorManagerAdapter executorManager = server.getExecutorManager(); history = executorManager.getExecutableFlows(null, null, null, 0, startTime, endTime, -1, -1); } catch (ExecutorManagerException e) { logger.error(e); } HashMap<String, Object> ret = new HashMap<String, Object>(); List<HashMap<String, Object>> output = new ArrayList<HashMap<String, Object>>(); ret.put("items", output); for (ExecutableFlow historyItem : history) { // Check if it is an scheduled execution if (historyItem.getScheduleId() >= 0 || loadAll != 0) { writeHistoryData(output, historyItem); } } // Make sure we're ready to cache it, otherwise output and return synchronized (this) { if (!useCache || cache.exists()) { JSONUtils.toJSON(ret, resp.getOutputStream(), false); return; } } // Create cache file File cacheTemp = new File(cacheDirFile, startTime + ".tmp"); cacheTemp.createNewFile(); OutputStream cacheOutput = new BufferedOutputStream(new FileOutputStream(cacheTemp)); try { OutputStream outputStream = new SplitterOutputStream(cacheOutput, resp.getOutputStream()); // Write to both the cache file and web output JSONUtils.toJSON(ret, outputStream, false); } finally { IOUtils.closeQuietly(cacheOutput); } // Move cache file synchronized (this) { cacheTemp.renameTo(cache); } }
From source file:azkaban.webapp.servlet.ScheduleServlet.java
License:Apache License
private void ajaxScheduleFlow(HttpServletRequest req, HashMap<String, Object> ret, User user) throws ServletException { String projectName = getParam(req, "projectName"); String flowName = getParam(req, "flow"); int projectId = getIntParam(req, "projectId"); Project project = projectManager.getProject(projectId); if (project == null) { ret.put("message", "Project " + projectName + " does not exist"); ret.put("status", "error"); return;//from w w w . jav a2 s. c o m } if (!hasPermission(project, user, Type.SCHEDULE)) { ret.put("status", "error"); ret.put("message", "Permission denied. Cannot execute " + flowName); return; } Flow flow = project.getFlow(flowName); if (flow == null) { ret.put("status", "error"); ret.put("message", "Flow " + flowName + " cannot be found in project " + project); return; } String scheduleTime = getParam(req, "scheduleTime"); String scheduleDate = getParam(req, "scheduleDate"); DateTime firstSchedTime; try { firstSchedTime = parseDateTime(scheduleDate, scheduleTime); } catch (Exception e) { ret.put("error", "Invalid date and/or time '" + scheduleDate + " " + scheduleTime); return; } ReadablePeriod thePeriod = null; try { if (hasParam(req, "is_recurring") && getParam(req, "is_recurring").equals("on")) { thePeriod = Schedule.parsePeriodString(getParam(req, "period")); } } catch (Exception e) { ret.put("error", e.getMessage()); } ExecutionOptions flowOptions = null; try { flowOptions = HttpRequestUtils.parseFlowOptions(req); } catch (Exception e) { ret.put("error", e.getMessage()); } List<SlaOption> slaOptions = null; Schedule schedule = scheduleManager.scheduleFlow(-1, projectId, projectName, flowName, "ready", firstSchedTime.getMillis(), firstSchedTime.getZone(), thePeriod, DateTime.now().getMillis(), firstSchedTime.getMillis(), firstSchedTime.getMillis(), user.getUserId(), flowOptions, slaOptions); logger.info("User '" + user.getUserId() + "' has scheduled " + "[" + projectName + flowName + " (" + projectId + ")" + "]."); projectManager.postProjectEvent(project, EventType.SCHEDULE, user.getUserId(), "Schedule " + schedule.toString() + " has been added."); ret.put("status", "success"); ret.put("message", projectName + "." + flowName + " scheduled."); }