Example usage for org.joda.time LocalTime getChronology

List of usage examples for org.joda.time LocalTime getChronology

Introduction

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

Prototype

public Chronology getChronology() 

Source Link

Document

Gets the chronology of the time.

Usage

From source file:ezbake.azkaban.manager.ScheduleManager.java

License:Apache License

/**
 * Schedules a flow to run in Azkaban//from  w w w  . ja v  a 2  s . c om
 *
 * @param projectName The project name containing the flow to execute
 * @param flow        The flow to execute
 * @param projectId   The ID of the project
 * @return {@link ezbake.azkaban.manager.result.SchedulerResult} containing the results of the scheduling
 */
public SchedulerResult scheduleFlow(String projectName, String flow, String projectId) {
    try {
        final List<NameValuePair> postPairs = new ArrayList<>();
        postPairs.add(new BasicNameValuePair("ajax", "scheduleFlow"));
        postPairs.add(new BasicNameValuePair("session.id", sessionId));
        postPairs.add(new BasicNameValuePair("projectName", projectName));
        postPairs.add(new BasicNameValuePair("projectId", projectId));
        postPairs.add(new BasicNameValuePair("flow", flow));
        postPairs.add(new BasicNameValuePair("scheduleDate", scheduleDate));

        // Create the time if one wasn't provided
        if (scheduleTime == null) {
            // Need to add 2 minutes because Azkaban won't actually schedule it if it's scheduled to run at the
            // current time or in the past.  If we only added one minute there's a race condition for the code
            // submitting before the clock rolls over to the next minute.
            final LocalTime now = LocalTime.now().plusMinutes(2);
            scheduleTime = now.getHourOfDay() + "," + now.getMinuteOfHour() + ","
                    + ((now.getHourOfDay() > 12) ? "pm" : "am") + ","
                    + now.getChronology().getZone().toString();

            logger.warn("time option not provided.  Using: " + scheduleTime);
        }
        postPairs.add(new BasicNameValuePair("scheduleTime", scheduleTime));

        if (period != null) {
            postPairs.add(new BasicNameValuePair("is_recurring", "on"));
            postPairs.add(new BasicNameValuePair("period", period));
        }

        logger.info("Attempting to schedule {}.{} on {} at {} reoccuring {}", projectName, flow, scheduleDate,
                scheduleTime, (period != null ? period : "never"));

        final HttpPost post = new HttpPost(schedulerUri);
        post.setEntity(new UrlEncodedFormEntity(postPairs));

        final String json = HttpManager.post(post);
        return (SchedulerResult) JsonUtil.deserialize(json, SchedulerResult.class);
    } catch (Exception ex) {
        ex.printStackTrace();
        return new SchedulerResult(ex.getMessage());
    }
}

From source file:ezbake.azkaban.manager.ScheduleManager.java

License:Apache License

public static void main(String[] args) throws IOException, InterruptedException, TException {
    final OptionsBean bean = new OptionsBean();
    final CmdLineParser parser = new CmdLineParser(bean);

    try {/*from   w ww .  j  a  v  a 2  s .co  m*/
        parser.parseArgument(args);

        String time;
        if (bean.scheduleTime == null) {
            // Need to add 2 minutes because Azkaban won't actually schedule it if it's scheduled to run at the
            // current time or in the past.  If we only added one minute there's a race condition for the code
            // submitting before the clock rolls over to the next minute.
            final LocalTime now = LocalTime.now().plusMinutes(2);
            time = now.getHourOfDay() + "," + now.getMinuteOfHour() + ","
                    + ((now.getHourOfDay() > 12) ? "pm" : "am") + ","
                    + now.getChronology().getZone().toString();

            System.out.println("time option not provided.  Using: " + time);
        } else {
            time = bean.scheduleTime;
        }

        final ScheduleManager azkabanScheduler = new ScheduleManager(new URI(bean.endPoint), bean.username,
                bean.password);
        azkabanScheduler.scheduleDate = bean.scheduleDate;
        azkabanScheduler.scheduleTime = time;

        if (bean.period != null) {
            azkabanScheduler.setPeriod(bean.period);
        }

        final SchedulerResult result = azkabanScheduler.scheduleFlow(bean.name, bean.flow, bean.projectId);

        if (result.hasError()) {
            System.err.println(result.getError());
        } else {
            System.out.println(
                    "Scheduled flow <" + bean.flow + "> :" + result.getStatus() + " | " + result.getMessage());
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
        parser.printUsage(System.err);
    }
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.TimeColumnLocalTimeMapper.java

License:Apache License

@Override
public Time toNonNullValue(LocalTime value) {

    DateTime zonedValue = new LocalDateTime(1970, 1, 1, value.getHourOfDay(), value.getMinuteOfHour(),
            value.getSecondOfMinute(), value.getMillisOfSecond(), value.getChronology()).toDateTime();

    final Time time = new Time(zonedValue.getMillis());
    return time;//ww w  .  j  a  va  2 s  .c  o  m
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.TimeColumnTimeOfDayMapper.java

License:Apache License

@Override
public TimeOfDay fromNonNullValue(Time value) {

    DateTime dateTime = new DateTime(value.getTime());
    LocalTime localTime = dateTime.toLocalTime();

    final TimeOfDay timeOfDay = new TimeOfDay(localTime.getHourOfDay(), localTime.getMinuteOfHour(),
            localTime.getSecondOfMinute(), localTime.getMillisOfSecond(), localTime.getChronology());
    return timeOfDay;
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.TimestampColumnLocalTimeMapper.java

License:Apache License

@Override
public Timestamp toNonNullValue(LocalTime value) {

    DateTime zonedValue = new LocalDateTime(1970, 1, 1, value.getHourOfDay(), value.getMinuteOfHour(),
            value.getSecondOfMinute(), value.getMillisOfSecond(), value.getChronology()).toDateTime();

    final Timestamp timestamp = new Timestamp(zonedValue.getMillis());
    return timestamp;
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.TimestampColumnTimeOfDayMapper.java

License:Apache License

@Override
public TimeOfDay fromNonNullValue(Timestamp value) {

    DateTime dateTime = new DateTime(value.getTime());
    LocalTime localTime = dateTime.toLocalTime();

    final TimeOfDay timeOfDay = new TimeOfDay(localTime.getHourOfDay(), localTime.getMinuteOfHour(),
            localTime.getSecondOfMinute(), localTime.getMillisOfSecond(), localTime.getChronology());
    return timeOfDay;
}