List of usage examples for org.joda.time DateTime now
public static DateTime now()
ISOChronology
in the default time zone. From source file:au.edu.uq.cmm.paul.servlet.WebUIController.java
License:Open Source License
private Date determineCutoff(Model model, String olderThan, String age) { if (olderThan.isEmpty() && age.isEmpty()) { model.addAttribute("message", "Either an expiry date or an age must be supplied"); return null; }/*from ww w . j a v a 2s .c om*/ String[] parts = age.split("\\s", 2); DateTime cutoff; if (olderThan.isEmpty()) { int value; try { value = Integer.parseInt(parts[0]); } catch (NumberFormatException ex) { model.addAttribute("message", "Age quantity is not an integer"); return null; } BaseSingleFieldPeriod p; switch (parts.length == 1 ? "" : parts[1]) { case "minute": case "minutes": p = Minutes.minutes(value); break; case "hour": case "hours": p = Hours.hours(value); break; case "day": case "days": p = Days.days(value); break; case "week": case "weeks": p = Weeks.weeks(value); break; case "month": case "months": p = Months.months(value); break; case "year": case "years": p = Years.years(value); break; default: model.addAttribute("message", "Unrecognized age time-unit"); return null; } cutoff = DateTime.now().minus(p); } else { cutoff = parseTimestamp(olderThan); if (cutoff == null) { model.addAttribute("message", "Unrecognizable expiry date"); return null; } } if (cutoff.isAfter(new DateTime())) { model.addAttribute("message", "Supplied or computed expiry date is in the future!"); return null; } model.addAttribute("computedDate", FORMATS[0].print(cutoff)); return cutoff.toDate(); }
From source file:au.org.utsoac.model.BaseEntity.java
License:Apache License
@PrePersist public void prePersist() { DateTime now = DateTime.now(); this.creationTime = now; this.modificationTime = now; }
From source file:au.org.utsoac.model.BaseEntity.java
License:Apache License
@PreUpdate public void preUpdate() { this.modificationTime = DateTime.now(); }
From source file:AuditGenerator.SeedData.java
private static void createAudit(String date, String childId, String parentId, int statusIndex, int siteId, int referringUrlId) throws SQLException, InterruptedException { String sql;//from w w w. j a v a2 s. com String currentSeverityId = "1"; DateTime currentTime = DateTime.now(); int randomSecond = randomGenerator.nextInt(100000); currentTime = currentTime.minusSeconds(randomSecond); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); String due = currentTime.toString(fmt); String thisSiteId = "" + siteId; if (referringUrlId == -1) { if (statusIndex == 0 || statusIndex == 1) { System.out.println("statusIndex " + statusIndex); sql = "INSERT into " + dbName + ".audits (created_at, updated_at, status, site_id, due_at, published_at,audit_type_id) VALUES ('" + date + "', '" + date + "', 'published', " + thisSiteId + ",'" + due + "', '" + date + "',1)"; } else { sql = "INSERT into " + dbName + ".audits (created_at, updated_at, status, site_id,referral_url_id, due_at,audit_type_id) VALUES ('" + date + "', '" + date + "', 'unaudited', " + thisSiteId + ",'" + due + "',1)"; } } else { if (statusIndex == 0 || statusIndex == 1) { System.out.println("statusIndex " + statusIndex); sql = "INSERT into " + dbName + ".audits (created_at, updated_at, status, site_id, referral_url_id, due_at, published_at,audit_type_id) VALUES ('" + date + "', '" + date + "', 'published', " + thisSiteId + "," + referringUrlId + ",'" + due + "', '" + date + "',1)"; } else { sql = "INSERT into " + dbName + ".audits (created_at, updated_at, status, site_id,referral_url_id, due_at,audit_type_id) VALUES ('" + date + "', '" + date + "', 'unaudited', " + thisSiteId + "," + referringUrlId + ",'" + due + "',1)"; } } //Grab audit ID from insert int auditId = sqlHandler.getSQLResponse(sql); String typePMMSQL = "INSERT INTO " + dbName + ".audit_audit_types (audit_id, audit_type_id, created_at, updated_at) VALUES (" + auditId + ", 1, '" + date + "','" + date + "')"; sqlHandler.executeStatement(typePMMSQL); ArrayList addContent = new ArrayList<String>(); addContent.add(4); Iterator it = addContent.iterator(); while (it.hasNext()) { int nextContent = (int) it.next(); String sql3 = "INSERT INTO " + dbName + ".audit_content_types (audit_id, content_type_id, created_at, updated_at) VALUES (" + auditId + ", " + nextContent + ", '" + date + "', '" + date + "')"; System.out.println(sql3); sqlHandler.executeStatement(sql3); //severities are related to content type String sql4 = "INSERT INTO " + dbName + ".audit_client_content_type_severities (audit_id, severity_id, content_type_id, client_organization_id, created_at, updated_at)" + "VALUES (" + auditId + ", " + currentSeverityId + "," + nextContent + ", " + childId + ", '" + date + "', '" + date + "')"; System.out.println(sql4); sqlHandler.executeStatement(sql4); if (parentId != null && statusIndex == 1) { String parentContentSQL = "INSERT INTO " + dbName + ".audit_client_content_type_severities (audit_id, severity_id, content_type_id, client_organization_id, created_at, updated_at)" + "VALUES (" + auditId + ", " + currentSeverityId + "," + nextContent + ", " + parentId + ", '" + date + "', '" + date + "')"; sqlHandler.executeStatement(parentContentSQL); } } if (statusIndex == 1) { String thisResolution = "cleared"; String sql5; if ("Under Review".equals(thisResolution)) { sql5 = "INSERT INTO " + dbName + ".audit_client_merchant_resolutions " + "(audit_id, severity_id, status, author_organization_id, created_at, updated_at)" + "VALUES (" + auditId + ", " + currentSeverityId + ", '" + thisResolution + "', " + childId + ", '" + date + "', '" + date + "')"; } else { sql5 = "INSERT INTO " + dbName + ".audit_client_merchant_resolutions " + "(audit_id, severity_id, status, author_organization_id, recipient_organization_id, published_at, created_at, updated_at)" + "VALUES (" + auditId + ", " + currentSeverityId + ", '" + thisResolution + "', " + childId + ", " + parentId + ", '" + date + "', '" + date + "', '" + date + "')"; } System.out.println("merchant res sql " + sql5); sqlHandler.executeStatement(sql5); } // create one or more notes Random r = new Random(); int noteCount = r.nextInt(6 - 1) + 1; for (int i = 0; i < noteCount; i++) { generateNotes(auditId, i); } generateAuditChange(auditId); }
From source file:AuditGenerator.SeedData.java
private static void createMultiAudit(String date, String childId, String parentId1, String parentId2, int statusIndex, int siteId) { String sql;//from w ww.j av a 2 s .c om String currentSeverityId = "1"; DateTime currentTime = DateTime.now(); int randomSecond = randomGenerator.nextInt(100000); currentTime = currentTime.minusSeconds(randomSecond); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); String due = currentTime.toString(fmt); String thisSiteId = "" + siteId; if (statusIndex == 0 || statusIndex == 1) { System.out.println("statusIndex " + statusIndex); sql = "INSERT into " + dbName + ".audits (created_at, updated_at, status, site_id, due_at, published_at) VALUES ('" + date + "', '" + date + "', 'published', " + thisSiteId + ", '" + due + "', '" + date + "')"; } else { sql = "INSERT into " + dbName + ".audits (created_at, updated_at, status, site_id, due_at) VALUES ('" + date + "', '" + date + "', 'unaudited', " + thisSiteId + ", '" + due + "')"; } //Grab audit ID from insert int auditId = sqlHandler.getSQLResponse(sql); String typePMMSQL = "INSERT INTO " + dbName + ".audit_audit_types (audit_id, audit_type_id, created_at, updated_at) VALUES (" + auditId + ", 1, '" + date + "','" + date + "')"; sqlHandler.executeStatement(typePMMSQL); ArrayList addContent = new ArrayList<String>(); addContent.add(4); Iterator it = addContent.iterator(); while (it.hasNext()) { int nextContent = (int) it.next(); String sql3 = "INSERT INTO " + dbName + ".audit_content_types (audit_id, content_type_id, created_at, updated_at) VALUES (" + auditId + ", " + nextContent + ", '" + date + "', '" + date + "')"; System.out.println(sql3); sqlHandler.executeStatement(sql3); //severities are related to content type String sql4 = "INSERT INTO " + dbName + ".audit_client_content_type_severities (audit_id, severity_id, content_type_id, client_organization_id, created_at, updated_at)" + "VALUES (" + auditId + ", " + currentSeverityId + "," + nextContent + ", " + childId + ", '" + date + "', '" + date + "')"; System.out.println(sql4); sqlHandler.executeStatement(sql4); if (parentId1 != null && statusIndex == 1) { String parentContentSQL = "INSERT INTO " + dbName + ".audit_client_content_type_severities (audit_id, severity_id, content_type_id, client_organization_id, created_at, updated_at)" + "VALUES (" + auditId + ", " + currentSeverityId + "," + nextContent + ", " + parentId1 + ", '" + date + "', '" + date + "')"; String parentContent2SQL = "INSERT INTO " + dbName + ".audit_client_content_type_severities (audit_id, severity_id, content_type_id, client_organization_id, created_at, updated_at)" + "VALUES (" + auditId + ", " + currentSeverityId + "," + nextContent + ", " + parentId2 + ", '" + date + "', '" + date + "')"; sqlHandler.executeStatement(parentContentSQL); sqlHandler.executeStatement(parentContent2SQL); } } if (statusIndex == 1) { String thisResolution = "cleared"; String sql5, sql6; if ("Under Review".equals(thisResolution)) { sql5 = "INSERT INTO " + dbName + ".audit_client_merchant_resolutions " + "(audit_id, severity_id, status, author_organization_id, created_at, updated_at)" + "VALUES (" + auditId + ", " + currentSeverityId + ", '" + thisResolution + "', " + childId + ", '" + date + "', '" + date + "')"; sql6 = ""; } else { sql5 = "INSERT INTO " + dbName + ".audit_client_merchant_resolutions " + "(audit_id, severity_id, status, author_organization_id, recipient_organization_id, published_at, created_at, updated_at)" + "VALUES (" + auditId + ", " + currentSeverityId + ", '" + thisResolution + "', " + childId + ", " + parentId1 + ", '" + date + "', '" + date + "', '" + date + "')"; sql6 = "INSERT INTO " + dbName + ".audit_client_merchant_resolutions " + "(audit_id, severity_id, status, author_organization_id, recipient_organization_id, published_at, created_at, updated_at)" + "VALUES (" + auditId + ", " + currentSeverityId + ", '" + thisResolution + "', " + childId + ", " + parentId2 + ", '" + date + "', '" + date + "', '" + date + "')"; } System.out.println("merchant res sql " + sql5); sqlHandler.executeStatement(sql5); sqlHandler.executeStatement(sql6); } }
From source file:azkaban.executor.ExecutionLogsDao.java
License:Apache License
private void uploadLogPart(final DatabaseTransOperator transOperator, final int execId, final String name, final int attempt, final int startByte, final int endByte, final EncodingType encType, final byte[] buffer, final int length) throws SQLException, IOException { final String INSERT_EXECUTION_LOGS = "INSERT INTO execution_logs " + "(exec_id, name, attempt, enc_type, start_byte, end_byte, " + "log, upload_time) VALUES (?,?,?,?,?,?,?,?)"; byte[] buf = buffer; if (encType == EncodingType.GZIP) { buf = GZIPUtils.gzipBytes(buf, 0, length); } else if (length < buf.length) { buf = Arrays.copyOf(buffer, length); }// w ww . ja va 2s . co m transOperator.update(INSERT_EXECUTION_LOGS, execId, name, attempt, encType.getNumVal(), startByte, startByte + length, buf, DateTime.now().getMillis()); }
From source file:azkaban.executor.JdbcExecutorLoader.java
License:Apache License
private void uploadLogPart(Connection connection, int execId, String name, int attempt, int startByte, int endByte, EncodingType encType, byte[] buffer, int length) throws SQLException, IOException { final String INSERT_EXECUTION_LOGS = "INSERT INTO execution_logs " + "(exec_id, name, attempt, enc_type, start_byte, end_byte, " + "log, upload_time) VALUES (?,?,?,?,?,?,?,?)"; QueryRunner runner = new QueryRunner(); byte[] buf = buffer; if (encType == EncodingType.GZIP) { buf = GZIPUtils.gzipBytes(buf, 0, length); } else if (length < buf.length) { buf = Arrays.copyOf(buffer, length); }/*from w w w .j a v a 2s . c o m*/ runner.update(connection, INSERT_EXECUTION_LOGS, execId, name, attempt, encType.getNumVal(), startByte, startByte + length, buf, DateTime.now().getMillis()); }
From source file:azkaban.executor.RunningExecutionsUpdater.java
License:Apache License
private void handleException(final Entry<Optional<Executor>, List<ExecutableFlow>> entry, final Executor executor, final ExecutorManagerException e, final ArrayList<ExecutableFlow> finalizeFlows) { logger.error("Failed to get update from executor " + executor.getHost(), e); boolean sendUnresponsiveEmail = false; final boolean executorRemoved = isExecutorRemoved(executor.getId()); for (final ExecutableFlow flow : entry.getValue()) { final Pair<ExecutionReference, ExecutableFlow> pair = this.runningExecutions.get() .get(flow.getExecutionId()); this.updaterStage.set("Failed to get update for flow " + pair.getSecond().getExecutionId()); if (executorRemoved) { logger.warn("Finalizing execution " + flow.getExecutionId() + ". Executor is removed"); finalizeFlows.add(flow);/*from ww w. ja va 2 s . c o m*/ } else { final ExecutionReference ref = pair.getFirst(); ref.setNextCheckTime(DateTime.now().getMillis() + this.errorThreshold); ref.setNumErrors(ref.getNumErrors() + 1); if (ref.getNumErrors() == this.numErrorsBeforeUnresponsiveEmail || ref.getNumErrors() % this.numErrorsBetweenUnresponsiveEmail == 0) { // if any of the executions has failed many enough updates, alert sendUnresponsiveEmail = true; } } } if (sendUnresponsiveEmail) { final Alerter mailAlerter = this.alerterHolder.get("email"); mailAlerter.alertOnFailedUpdate(executor, entry.getValue(), e); } }
From source file:azkaban.executor.RunningExecutionsUpdater.java
License:Apache License
private Map<Optional<Executor>, List<ExecutableFlow>> getFlowToExecutorMap() { final HashMap<Optional<Executor>, List<ExecutableFlow>> exFlowMap = new HashMap<>(); for (final Pair<ExecutionReference, ExecutableFlow> runningFlow : this.runningExecutions.get().values()) { final ExecutionReference ref = runningFlow.getFirst(); final ExecutableFlow flow = runningFlow.getSecond(); final Optional<Executor> executor = ref.getExecutor(); // We can set the next check time to prevent the checking of certain // flows. if (ref.getNextCheckTime() >= DateTime.now().getMillis()) { continue; }/*from w w w. jav a2 s . co m*/ List<ExecutableFlow> flows = exFlowMap.get(executor); if (flows == null) { flows = new ArrayList<>(); exFlowMap.put(executor, flows); } flows.add(flow); } return exFlowMap; }
From source file:azkaban.migration.schedule2trigger.Schedule2Trigger.java
License:Apache License
@SuppressWarnings("unchecked") private static void file2ScheduleTrigger() throws Exception { TriggerLoader triggerLoader = new JdbcTriggerLoader(props); for (File scheduleFile : outputDir.listFiles()) { logger.info("Trying to load schedule from " + scheduleFile.getAbsolutePath()); if (scheduleFile.isFile()) { Props schedProps = new Props(null, scheduleFile); String flowName = schedProps.getString("flowName"); String projectName = schedProps.getString("projectName"); int projectId = schedProps.getInt("projectId"); long firstSchedTimeLong = schedProps.getLong("firstScheduleTimeLong"); // DateTime firstSchedTime = new DateTime(firstSchedTimeLong); String timezoneId = schedProps.getString("timezone"); DateTimeZone timezone = DateTimeZone.forID(timezoneId); ReadablePeriod period = Utils.parsePeriodString(schedProps.getString("period")); // DateTime lastModifyTime = DateTime.now(); long nextExecTimeLong = schedProps.getLong("nextExecTimeLong"); // DateTime nextExecTime = new DateTime(nextExecTimeLong); long submitTimeLong = schedProps.getLong("submitTimeLong"); // DateTime submitTime = new DateTime(submitTimeLong); String submitUser = schedProps.getString("submitUser"); ExecutionOptions executionOptions = null; if (schedProps.containsKey("executionOptionsObj")) { String executionOptionsObj = schedProps.getString("executionOptionsObj"); executionOptions = ExecutionOptions .createFromObject(JSONUtils.parseJSONFromString(executionOptionsObj)); } else { executionOptions = new ExecutionOptions(); }//from w w w . ja va 2 s. c om List<azkaban.sla.SlaOption> slaOptions = null; if (schedProps.containsKey("slaOptionsObj")) { slaOptions = new ArrayList<azkaban.sla.SlaOption>(); List<Map<String, Object>> settingsObj = (List<Map<String, Object>>) JSONUtils .parseJSONFromString(schedProps.getString("slaOptionsObj")); for (Map<String, Object> sla : settingsObj) { String type = (String) sla.get("type"); Map<String, Object> info = (Map<String, Object>) sla.get("info"); List<String> actions = (List<String>) sla.get("actions"); azkaban.sla.SlaOption slaOption = new azkaban.sla.SlaOption(type, actions, info); slaOptions.add(slaOption); } } azkaban.scheduler.Schedule schedule = new azkaban.scheduler.Schedule(-1, projectId, projectName, flowName, "ready", firstSchedTimeLong, timezone, period, DateTime.now().getMillis(), nextExecTimeLong, submitTimeLong, submitUser, executionOptions, slaOptions); Trigger t = scheduleToTrigger(schedule); logger.info("Ready to insert trigger " + t.getDescription()); triggerLoader.addTrigger(t); } } }