List of usage examples for org.joda.time DateTime getMillis
public long getMillis()
From source file:arjdbc.jdbc.RubyJdbcConnection.java
License:Open Source License
protected void setTimestampParameter(final ThreadContext context, final Connection connection, final PreparedStatement statement, final int index, IRubyObject value, final IRubyObject column, final int type) throws SQLException { if (value.isNil()) statement.setNull(index, Types.TIMESTAMP); else {/*from w ww. ja v a 2 s. com*/ value = DateTimeUtils.getTimeInDefaultTimeZone(context, value); if (value instanceof RubyTime) { final RubyTime timeValue = (RubyTime) value; final DateTime dateTime = timeValue.getDateTime(); final Timestamp timestamp = new Timestamp(dateTime.getMillis()); if (type != Types.DATE) { // 1942-11-30T01:02:03.123_456 // getMillis already set nanos to: 123_000_000 final int usec = (int) timeValue.getUSec(); // 456 on JRuby if (usec >= 0) { timestamp.setNanos(timestamp.getNanos() + usec * 1000); } } statement.setTimestamp(index, timestamp, getTimeZoneCalendar(dateTime.getZone().getID())); } else if (value instanceof RubyString) { // yyyy-[m]m-[d]d hh:mm:ss[.f...] final Timestamp timestamp = Timestamp.valueOf(value.toString()); statement.setTimestamp(index, timestamp); // assume local time-zone } else { // DateTime ( ActiveSupport::TimeWithZone.to_time ) final RubyFloat timeValue = value.convertToFloat(); // to_f final Timestamp timestamp = convertToTimestamp(timeValue); statement.setTimestamp(index, timestamp, getTimeZoneCalendar("GMT")); } } }
From source file:arjdbc.jdbc.RubyJdbcConnection.java
License:Open Source License
protected void setTimeParameter(final ThreadContext context, final Connection connection, final PreparedStatement statement, final int index, IRubyObject value, final IRubyObject column, final int type) throws SQLException { if (value.isNil()) statement.setNull(index, Types.TIME); else {/* w w w.jav a2 s .co m*/ value = getTimeInDefaultTimeZone(context, value); if (value instanceof RubyTime) { final RubyTime timeValue = (RubyTime) value; final DateTime dateTime = timeValue.getDateTime(); final Time time = new Time(dateTime.getMillis()); statement.setTime(index, time, getTimeZoneCalendar(dateTime.getZone().getID())); } else if (value instanceof RubyString) { final Time time = Time.valueOf(value.toString()); statement.setTime(index, time); // assume local time-zone } else { // DateTime ( ActiveSupport::TimeWithZone.to_time ) final RubyFloat timeValue = value.convertToFloat(); // to_f final Time time = new Time(timeValue.getLongValue() * 1000); // millis // java.sql.Time is expected to be only up to second precision statement.setTime(index, time, getTimeZoneCalendar("GMT")); } } }
From source file:au.id.hazelwood.xmltvguidebuilder.grabber.Grabber.java
License:Apache License
private List<Event> getEvents(Config config, String channelTag, DateTime from, DateTime to) { List<Event> events = new ArrayList<>(); DateTime subFrom = from; while (subFrom.isBefore(to)) { DateTime subTo = subFrom.plusDays(1); if (subTo.isAfter(to)) { subTo = to;/*from ww w .ja v a 2 s . com*/ } LOGGER.debug("Fetching events between {} and {}", subFrom, subTo); try { Events subEvents = getForObject(EVENTS_URI, Events.class, channelTag, subFrom.getMillis(), subTo.getMillis(), config.getRegionId()); LOGGER.debug("Found {} events between {} and {}", subEvents.getEvents().size(), subFrom, subTo); events.addAll(subEvents.getEvents()); } catch (Exception e) { LOGGER.debug("Failed to get events between {} and {}"); } subFrom = subTo; } return events; }
From source file:azkaban.migration.scheduler.Schedule.java
License:Apache License
public boolean updateTime() { if (new DateTime(nextExecTime).isAfterNow()) { return true; }//from w ww .java 2 s .c o m if (period != null) { DateTime nextTime = getNextRuntime(nextExecTime, timezone, period); this.nextExecTime = nextTime.getMillis(); return true; } return false; }
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);/*from www. j ava 2s. co m*/ // 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.BasicTimeChecker.java
License:Apache License
private long calculateNextCheckTime() { DateTime date = new DateTime(nextCheckTime).withZone(timezone); int count = 0; while (!date.isAfterNow()) { if (count > 100000) { throw new IllegalStateException("100000 increments of period did not get to present time."); }/*from www . j a va 2s .c o m*/ if (period == null) { break; } else { date = date.plus(period); } count += 1; if (!skipPastChecks) { continue; } } return date.getMillis(); }
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; }/*from ww w .java 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.builtin.SlaChecker.java
License:Apache License
private Boolean isSlaGood(ExecutableFlow flow) { String type = slaOption.getType(); logger.info("flow is " + flow.getStatus()); if (flow.getStartTime() < 0) { return Boolean.FALSE; }//from www .j a v a 2s . 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(); 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(); return isFlowSucceeded(status); } 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(); 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(); return isJobSucceeded(status); } return Boolean.FALSE; }
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 w w . j a va 2s . 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 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;// w w w . jav a2 s. co 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."); }