Example usage for org.joda.time DateTime DateTime

List of usage examples for org.joda.time DateTime DateTime

Introduction

In this page you can find the example usage for org.joda.time DateTime DateTime.

Prototype

public DateTime() 

Source Link

Document

Constructs an instance set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:azkaban.app.Scheduler.java

License:Apache License

/**
 * Schedule this flow to run one time at the specified date
 * //from ww w.j a  v  a  2s  . c  o m
 * @param holder The execution of the flow to run
 */
public ScheduledFuture<?> scheduleNow(FlowExecutionHolder holder) {
    ExecutableFlow flow = holder.getFlow();
    logger.info("Scheduling job '" + flow.getName() + "' for now");

    final ScheduledJob schedJob = new ScheduledJob(flow.getName(), _jobManager, new DateTime(), true);

    // mark the job as scheduled
    _scheduled.put(flow.getName(), schedJob);

    return _executor.schedule(new ScheduledFlow(holder, schedJob), 1, TimeUnit.MILLISECONDS);
}

From source file:azkaban.app.Scheduler.java

License:Apache License

/**
 * Schedule this flow to run one time at the specified date
 * // w w w . ja  v a  2 s. co  m
 * @param holder The execution of the flow to run
 */
public ScheduledFuture<?> scheduleNow(ExecutableFlow flow) {
    final Props parentProps = produceParentProperties(flow);
    FlowExecutionHolder holder = new FlowExecutionHolder(flow, parentProps);
    logger.info("Scheduling job '" + flow.getName() + "' for now");

    final ScheduledJob schedJob = new ScheduledJob(flow.getName(), _jobManager, new DateTime(), true);

    // mark the job as scheduled
    _scheduled.put(flow.getName(), schedJob);

    return _executor.schedule(new ScheduledFlow(holder, schedJob), 1, TimeUnit.MILLISECONDS);
}

From source file:azkaban.app.Scheduler.java

License:Apache License

/**
 * Schedule the given job to run at the next occurance of the partially
 * specified date, and repeating on the given period. For example if the
 * partial date is 12:00pm then the job will kick of the next time it is
 * 12:00pm//from   w ww .j  av  a 2s . c  o  m
 * 
 * @param jobId An id for the job
 * @param partial A description of the date to run on
 * @param period The period on which the job should repeat
 */
public ScheduledFuture<?> schedule(String jobId, ReadablePartial partial, ReadablePeriod period,
        boolean ignoreDep) {
    // compute the next occurrence of this date
    DateTime now = new DateTime();
    DateTime date = now.withFields(partial);
    if (period != null) {
        date = updatedTime(date, period);
    } else if (now.isAfter(date)) {
        // Will try to schedule non recurring for tomorrow
        date = date.plusDays(1);
    }

    if (now.isAfter(date)) {
        // Schedule is non recurring.
        logger.info("Scheduled Job " + jobId + " was originally scheduled for " + _dateFormat.print(date));
        return null;
    }

    logger.info("Scheduling job '" + jobId + "' for " + _dateFormat.print(date)
            + (period != null ? " with a period of " + PeriodFormat.getDefault().print(period) : ""));
    return schedule(new ScheduledJob(jobId, date, period, ignoreDep), true);
}

From source file:azkaban.app.Scheduler.java

License:Apache License

private ScheduledFuture<?> schedule(final ScheduledJob schedJob, boolean saveResults) {
    // fail fast if there is a problem with this job
    _jobManager.validateJob(schedJob.getId());

    Duration wait = new Duration(new DateTime(), schedJob.getScheduledExecution());
    if (wait.getMillis() < -1000) {
        logger.warn("Job " + schedJob.getId() + " is scheduled for "
                + DateTimeFormat.shortDateTime().print(schedJob.getScheduledExecution()) + " which is "
                + (PeriodFormat.getDefault().print(wait.toPeriod()))
                + " in the past, adjusting scheduled date to now.");
        wait = new Duration(0);
    }/*from   ww  w.  ja  v a 2s.co m*/

    // mark the job as scheduled
    _scheduled.put(schedJob.getId(), schedJob);

    if (saveResults) {
        try {
            saveSchedule();
        } catch (IOException e) {
            throw new RuntimeException("Error saving schedule after scheduling job " + schedJob.getId());
        }
    }

    ScheduledRunnable runnable = new ScheduledRunnable(schedJob);
    schedJob.setScheduledRunnable(runnable);
    return _executor.schedule(runnable, wait.getMillis(), TimeUnit.MILLISECONDS);
}

From source file:azkaban.app.Scheduler.java

License:Apache License

private DateTime updatedTime(DateTime scheduledDate, ReadablePeriod period) {
    DateTime now = new DateTime();
    DateTime date = new DateTime(scheduledDate);
    int count = 0;
    while (now.isAfter(date)) {
        if (count > 100000) {
            throw new IllegalStateException("100000 increments of period did not get to present time.");
        }/*from w w w.  j av  a2 s  .  c  o  m*/

        if (period == null) {
            break;
        } else {
            date = date.plus(period);
        }

        count += 1;
    }

    return date;
}

From source file:azkaban.app.Scheduler.java

License:Apache License

private Props produceParentProperties(final ExecutableFlow flow) {
    Props parentProps = new Props();

    parentProps.put("azkaban.flow.id", flow.getId());
    parentProps.put("azkaban.flow.uuid", UUID.randomUUID().toString());

    DateTime loadTime = new DateTime();

    parentProps.put("azkaban.flow.start.timestamp", loadTime.toString());
    parentProps.put("azkaban.flow.start.year", loadTime.toString("yyyy"));
    parentProps.put("azkaban.flow.start.month", loadTime.toString("MM"));
    parentProps.put("azkaban.flow.start.day", loadTime.toString("dd"));
    parentProps.put("azkaban.flow.start.hour", loadTime.toString("HH"));
    parentProps.put("azkaban.flow.start.minute", loadTime.toString("mm"));
    parentProps.put("azkaban.flow.start.seconds", loadTime.toString("ss"));
    parentProps.put("azkaban.flow.start.milliseconds", loadTime.toString("SSS"));
    parentProps.put("azkaban.flow.start.timezone", loadTime.toString("ZZZZ"));
    return parentProps;
}

From source file:azkaban.common.web.GuiUtils.java

License:Apache License

public DateTime now() {
    return new DateTime();
}

From source file:azkaban.common.web.GuiUtils.java

License:Apache License

public String getShortTimeZone() {
    return DateTimeZone.getDefault().getShortName(new DateTime().getMillis());
}

From source file:azkaban.common.web.GuiUtils.java

License:Apache License

public DateTime getNow() {
    return new DateTime();
}

From source file:azkaban.flow.ComposedExecutableFlow.java

License:Apache License

@Override
public void execute(Props parentProps, final FlowCallback callback) {
    if (parentProps == null) {
        parentProps = new Props();
    }/*from   w  ww.  j  a  v a  2  s . c o  m*/

    synchronized (sync) {
        if (this.parentProps == null) {
            this.parentProps = parentProps;
        } else if (jobState != Status.COMPLETED && !this.parentProps.equalsProps(parentProps)) {
            throw new IllegalArgumentException(String.format(
                    "%s.execute() called with multiple differing parentProps objects.  "
                            + "Call reset() before executing again with a different Props object. this.parentProps[%s], parentProps[%s]",
                    getClass().getSimpleName(), this.parentProps, parentProps));
        }

        switch (jobState) {
        case READY:
            jobState = Status.RUNNING;
            callbacksToCall.add(callback);
            break;
        case RUNNING:
            callbacksToCall.add(callback);
            return;
        case COMPLETED:
        case SUCCEEDED:
            callback.completed(Status.SUCCEEDED);
            return;
        case FAILED:
            callback.completed(Status.FAILED);
        default:
            return;
        }
    }

    if (startTime == null) {
        startTime = new DateTime();
    }

    try {
        dependee.execute(parentProps, new DependeeCallback());
    } catch (RuntimeException e) {
        final List<FlowCallback> callbacks;
        synchronized (sync) {
            jobState = Status.FAILED;
            callbacks = callbacksToCall;
        }

        callCallbacks(callbacks, Status.FAILED);

        throw e;
    }
}