/** * #func 计算相对月<br> * #desc amount可以为负数 * * @author hedan * @version 4.0 */ public static Date addMonths(Date date, int amount) { return org.apache.commons.lang.time.DateUtils.addMonths(date, amount); }
public Voting(Work work, Revision revision, SednoUser createdBy) { checkNotNull(work); checkNotNull(revision); checkNotNull(createdBy); this.createdBy = createdBy; this.votingStatus = VotingStatus.IN_PROGRESS; this.votingCards = Lists.newArrayList(); this.revision = revision; this.work = work; this.expirationDate = DateUtils.addMonths(new Date(), 1); }
public Date diff(Integer i) { return DateUtils.addMonths(AbstractDateParamFilter.this.clock.current(), i.intValue()); }
private Date parseDelayParameter(String delay) { if (delay == null) { return null; } if (!possibleDateFacets.contains(delay)) { return null; } int numberPartEnd = 0; for (numberPartEnd=0; numberPartEnd<delay.length(); ++numberPartEnd) { if (!Character.isDigit(delay.charAt(numberPartEnd))) { break; } } int number = (numberPartEnd > 0) ? Integer.parseInt(delay.substring(0, numberPartEnd)) : 1; String unit = delay.substring(numberPartEnd); Date since = new Date(); if ("MONTH".equals(unit) || "MONTHS".equals(unit)) { since = DateUtils.addMonths(since, -number); } else if ("WEEK".equals(unit) || "WEEKS".equals(unit)) { since = DateUtils.addWeeks(since, -number); } else { since = null; } return since; }
private Date parseDelayParameter(String delay) { if (delay == null) { return null; } if (!possibleDateFacets.contains(delay)) { return null; } int numberPartEnd = 0; for (numberPartEnd=0; numberPartEnd<delay.length(); ++numberPartEnd) { if (!Character.isDigit(delay.charAt(numberPartEnd))) { break; } } int number = (numberPartEnd > 0) ? Integer.parseInt(delay.substring(0, numberPartEnd)) : 1; String unit = delay.substring(numberPartEnd); Date since = new Date(); if ("MONTH".equals(unit) || "MONTHS".equals(unit)) { since = DateUtils.addMonths(since, -number); } else if ("WEEK".equals(unit) || "WEEKS".equals(unit)) { since = DateUtils.addWeeks(since, -number); } else { since = null; } return since; }
public static CoveringInfo getMonthlyCoveringInfo(Date from, Date to) { // Move 'from' to end of month, unless its the first day of month boolean coverable = true; if (!from.equals(DateUtils.truncate(from, MONTH))) { from = DateUtils.addMonths(DateUtils.truncate(from, MONTH), 1); coverable = false; } // Move 'to' to beginning of next month, unless its the first day of the month if (!to.equals(DateUtils.truncate(to, MONTH))) { to = DateUtils.truncate(to, MONTH); coverable = false; } int months = 0; while (from.before(to)) { from = DateUtils.addMonths(from, 1); months++; } return new CoveringInfo(months, coverable); }
public static CoveringInfo getMonthlyCoveringInfo(Date from, Date to) { // Move 'from' to end of month, unless its the first day of month boolean coverable = true; if (!from.equals(DateUtils.truncate(from, MONTH))) { from = DateUtils.addMonths(DateUtils.truncate(from, MONTH), 1); coverable = false; } // Move 'to' to beginning of next month, unless its the first day of the month if (!to.equals(DateUtils.truncate(to, MONTH))) { to = DateUtils.truncate(to, MONTH); coverable = false; } int months = 0; while (from.before(to)) { from = DateUtils.addMonths(from, 1); months++; } return new CoveringInfo(months, coverable); }
public static CoveringInfo getYearlyCoveringInfo(Date from, Date to) { CoveringInfo monthlyCoveringInfo = getMonthlyCoveringInfo(from, to); if (monthlyCoveringInfo.getCountBetween() < 12) { return new CoveringInfo(0, false); } boolean coverable = monthlyCoveringInfo.isCoverable(); if (!from.equals(DateUtils.truncate(from, MONTH))) { from = DateUtils.addMonths(DateUtils.truncate(from, MONTH), 1); coverable = false; } Calendar cal = Calendar.getInstance(); cal.setTime(from); int fromMonth = cal.get(MONTH); int beginOffset = (12 - fromMonth % 12) % 12; int endOffset = (monthlyCoveringInfo.getCountBetween() - beginOffset) % 12; if (beginOffset > 0 || endOffset > 0) { coverable = false; } return new CoveringInfo((monthlyCoveringInfo.getCountBetween() - beginOffset - endOffset) / 12, coverable); }
public static CoveringInfo getYearlyCoveringInfo(Date from, Date to) { CoveringInfo monthlyCoveringInfo = getMonthlyCoveringInfo(from, to); if (monthlyCoveringInfo.getCountBetween() < 12) { return new CoveringInfo(0, false); } boolean coverable = monthlyCoveringInfo.isCoverable(); if (!from.equals(DateUtils.truncate(from, MONTH))) { from = DateUtils.addMonths(DateUtils.truncate(from, MONTH), 1); coverable = false; } Calendar cal = Calendar.getInstance(); cal.setTime(from); int fromMonth = cal.get(MONTH); int beginOffset = (12 - fromMonth % 12) % 12; int endOffset = (monthlyCoveringInfo.getCountBetween() - beginOffset) % 12; if (beginOffset > 0 || endOffset > 0) { coverable = false; } return new CoveringInfo((monthlyCoveringInfo.getCountBetween() - beginOffset - endOffset) / 12, coverable); }
public static CoveringInfo getQuarterlyCoveringInfo(Date from, Date to) { CoveringInfo monthlyCoveringInfo = getMonthlyCoveringInfo(from, to); if (monthlyCoveringInfo.getCountBetween() < 3) { return new CoveringInfo(0, false); } boolean coverable = monthlyCoveringInfo.isCoverable(); if (!from.equals(DateUtils.truncate(from, MONTH))) { from = DateUtils.addMonths(DateUtils.truncate(from, MONTH), 1); coverable = false; } Calendar cal = Calendar.getInstance(); cal.setTime(from); int fromMonth = cal.get(MONTH); // Get the start date of the quarter int beginOffset = (3 - fromMonth % 3) % 3; int endOffset = (monthlyCoveringInfo.getCountBetween() - beginOffset) % 3; if (beginOffset > 0 || endOffset > 0) { coverable = false; } return new CoveringInfo((monthlyCoveringInfo.getCountBetween() - beginOffset - endOffset) / 3, coverable); }
public static CoveringInfo getQuarterlyCoveringInfo(Date from, Date to) { CoveringInfo monthlyCoveringInfo = getMonthlyCoveringInfo(from, to); if (monthlyCoveringInfo.getCountBetween() < 3) { return new CoveringInfo(0, false); } boolean coverable = monthlyCoveringInfo.isCoverable(); if (!from.equals(DateUtils.truncate(from, MONTH))) { from = DateUtils.addMonths(DateUtils.truncate(from, MONTH), 1); coverable = false; } Calendar cal = Calendar.getInstance(); cal.setTime(from); int fromMonth = cal.get(MONTH); // Get the start date of the quarter int beginOffset = (3 - fromMonth % 3) % 3; int endOffset = (monthlyCoveringInfo.getCountBetween() - beginOffset) % 3; if (beginOffset > 0 || endOffset > 0) { coverable = false; } return new CoveringInfo((monthlyCoveringInfo.getCountBetween() - beginOffset - endOffset) / 3, coverable); }
conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString()); conf.set("start", DateUtils.formatDateOozieTZ(new Date())); conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1))); conf.set("frequency", "coord:days(1)"); conf.set(OozieClient.USER_NAME, getTestUser()); conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString()); conf.set("wfAppPath", appPathFile.getPath()); conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1))); conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1))); conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString()); conf.set("wfAppPath", appPathFile.getPath()); conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1))); conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1))); DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1))); conf.set(OozieClient.USER_NAME, getTestUser()); conf.set("nominal_time", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1))); coordId = new CoordSubmitXCommand(conf).call(); new CoordMaterializeTransitionXCommand(coordId, 3600).call(); conf.set("wfAppPath", appPathFile.getPath()); conf.set("start", DateUtils.formatDateOozieTZ(new Date())); conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
public void testMessage_withTimedout() throws Exception { Date start = DateUtils.addMonths(new Date(), -1); Date end = DateUtils.addHours(new Date(), 4); // 4 hrs Date createdTime = start; final CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 12); addRecordToCoordActionTable(job1.getId(), 12, CoordinatorAction.Status.TIMEDOUT); final CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 4); addRecordToCoordActionTable(job2.getId(), 4, CoordinatorAction.Status.TIMEDOUT); ExtendedAbandonedCoordCheckerRunnable coordChecked = new ExtendedAbandonedCoordCheckerRunnable(10); coordChecked.run(); String msg = coordChecked.getMessage(); assertTrue(msg.contains(job1.getId())); assertFalse(msg.contains(job2.getId())); }
public void testNoAbandoned() throws Exception { Date start = DateUtils.addMonths(new Date(), -1); Date end = DateUtils.addHours(new Date(), 4); // 4 hrs Date createdTime = start; final CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 6); addRecordToCoordActionTable(job1.getId(), 6, CoordinatorAction.Status.SUCCEEDED, CoordinatorAction.Status.FAILED); final CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, start, end, createdTime, true, false, 6); addRecordToCoordActionTable(job2.getId(), 6, CoordinatorAction.Status.SUCCEEDED, CoordinatorAction.Status.FAILED); ExtendedAbandonedCoordCheckerRunnable coordChecked = new ExtendedAbandonedCoordCheckerRunnable(5); coordChecked.run(); assertNull(coordChecked.getMessage()); }
public void tesAbandonedFailed() throws Exception { Date start = DateUtils.addMonths(new Date(), -1); Date end = DateUtils.addHours(new Date(), 4); // 4 hrs Date createdTime = start; final CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 5); addRecordToCoordActionTable(job1.getId(), 5, CoordinatorAction.Status.FAILED); final CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 4); addRecordToCoordActionTable(job2.getId(), 4, CoordinatorAction.Status.FAILED); ExtendedAbandonedCoordCheckerRunnable coordChecked = new ExtendedAbandonedCoordCheckerRunnable(5); coordChecked.run(); String msg = coordChecked.getMessage(); assertTrue(msg.contains(job1.getId())); assertFalse(msg.contains(job2.getId())); }
public void testMessage_withMixedStatus() throws Exception { Date start = DateUtils.addMonths(new Date(), -1); Date end = DateUtils.addHours(new Date(), 4); // 4 hrs Date createdTime = start; final CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 5); addRecordToCoordActionTable(job1.getId(), 5, CoordinatorAction.Status.FAILED, CoordinatorAction.Status.SUSPENDED, CoordinatorAction.Status.TIMEDOUT); final CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 5); addRecordToCoordActionTable(job2.getId(), 5, CoordinatorAction.Status.FAILED, CoordinatorAction.Status.SUSPENDED, CoordinatorAction.Status.TIMEDOUT); final CoordinatorJobBean job3 = addRecordToCoordJobTable(CoordinatorJob.Status.SUCCEEDED, start, end, createdTime, true, false, 5); addRecordToCoordActionTable(job3.getId(), 5, CoordinatorAction.Status.FAILED, CoordinatorAction.Status.SUSPENDED, CoordinatorAction.Status.TIMEDOUT); ExtendedAbandonedCoordCheckerRunnable coordChecked = new ExtendedAbandonedCoordCheckerRunnable(5); coordChecked.run(); String msg = coordChecked.getMessage(); assertTrue(msg.contains(job1.getId())); assertTrue(msg.contains(job2.getId())); assertFalse(msg.contains(job3.getId())); }
public void testCatchupJob() throws Exception { Date start = DateUtils.addMonths(new Date(), -1); Date end = DateUtils.addHours(new Date(), 4); // 4 hrs Date createdTime = DateUtils.addDays(new Date(), -1); CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 6); addRecordToCoordActionTable(job1.getId(), 6, CoordinatorAction.Status.FAILED); createdTime = DateUtils.addDays(new Date(), -3); CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 4); addRecordToCoordActionTable(job2.getId(), 10, CoordinatorAction.Status.FAILED); new AbandonedCoordCheckerRunnable(5, true).run(); // Only one job should be running. assertEquals(CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, job1.getId()).getStatus(), CoordinatorJob.Status.RUNNING); assertEquals(CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, job2.getId()).getStatus(), CoordinatorJob.Status.KILLED); }
conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString()); conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addDays(new Date(), -1))); conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1))); conf.set(OozieClient.USER_NAME, getTestUser()); reader = IOUtils.getResourceAsReader("wf-credentials.xml", -1);
public void testKill() throws Exception { Date start = DateUtils.addMonths(new Date(), -1); Date end = DateUtils.addHours(new Date(), 4); // 4 hrs Date createdTime = start; CoordinatorJobBean job1 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 6); addRecordToCoordActionTable(job1.getId(), 6, CoordinatorAction.Status.FAILED); CoordinatorJobBean job2 = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, start, end, createdTime, true, false, 4); addRecordToCoordActionTable(job2.getId(), 4, CoordinatorAction.Status.FAILED); new AbandonedCoordCheckerRunnable(5, true).run(); assertEquals(CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, job1.getId()).getStatus(), CoordinatorJob.Status.KILLED); assertEquals(CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, job2.getId()).getStatus(), CoordinatorJob.Status.RUNNING); }