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(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:azkaban.sla.SLAManager.java

License:Apache License

private void sendSlaKillEmail(SLA s, ExecutableFlow exflow) {
    String message = null;//from   www. j  a va2 s .c  om
    ExecutableNode exnode;
    switch (s.getRule()) {
    case FINISH:
        if (s.getJobName().equals("")) {
            message = "Flow " + exflow.getFlowId() + " failed to finish with set SLA and is killed. "
                    + String.format("%n");
            message += "Flow started at " + new DateTime(exflow.getStartTime()).toDateTimeISO()
                    + String.format("%n");
            message += "Flow status at " + s.getCheckTime().toDateTimeISO() + " is " + exflow.getStatus();
        } else {
            exnode = exflow.getExecutableNode(s.getJobName());
            message = "Job " + s.getJobName() + " of flow " + exflow.getFlowId()
                    + " failed to finish with set SLA and is killed. " + String.format("%n");
            message += "Job started at " + new DateTime(exnode.getStartTime()).toDateTimeISO()
                    + String.format("%n");
            message += "Job status at " + s.getCheckTime().toDateTimeISO() + " is " + exnode.getStatus();
        }
        break;
    case SUCCESS:
        if (s.getJobName().equals("")) {
            message = "Flow " + exflow.getFlowId() + " didn't finish successfully with set SLA and is killed. "
                    + String.format("%n");
            message += "Flow started at " + new DateTime(exflow.getStartTime()).toDateTimeISO()
                    + String.format("  %n");
            message += "Flow status at " + s.getCheckTime().toDateTimeISO() + " is " + exflow.getStatus();
        } else {
            exnode = exflow.getExecutableNode(s.getJobName());
            message = "Job " + s.getJobName() + " of flow " + exflow.getFlowId()
                    + " didn't finish successfully with set SLA and is killed. " + String.format("%n");
            message += "Job started at " + new DateTime(exnode.getStartTime()).toDateTimeISO()
                    + String.format("%n");
            message += "Job status at " + s.getCheckTime().toDateTimeISO() + " is " + exnode.getStatus();
        }
        break;
    default:
        logger.error("Unknown SLA rules!");
        message = "Unknown SLA was not met!";
        break;
    }
    mailer.sendSlaEmail(s, message);
}

From source file:azkaban.sla.SlaOption.java

License:Apache License

public static String createSlaMessage(SlaOption slaOption, ExecutableFlow flow) {
    String type = slaOption.getType();
    int execId = flow.getExecutionId();
    if (type.equals(SlaOption.TYPE_FLOW_FINISH)) {
        String flowName = (String) slaOption.getInfo().get(SlaOption.INFO_FLOW_NAME);
        String duration = (String) slaOption.getInfo().get(SlaOption.INFO_DURATION);
        String basicinfo = "SLA Alert: Your flow " + flowName + " failed to FINISH within " + duration
                + "</br>";
        String expected = "Here is details : </br>" + "Flow " + flowName + " in execution " + execId
                + " is expected to FINISH within " + duration + " from "
                + fmt.print(new DateTime(flow.getStartTime())) + "</br>";
        String actual = "Actual flow status is " + flow.getStatus();
        return basicinfo + expected + actual;
    } else if (type.equals(SlaOption.TYPE_FLOW_SUCCEED)) {
        String flowName = (String) slaOption.getInfo().get(SlaOption.INFO_FLOW_NAME);
        String duration = (String) slaOption.getInfo().get(SlaOption.INFO_DURATION);
        String basicinfo = "SLA Alert: Your flow " + flowName + " failed to SUCCEED within " + duration
                + "</br>";
        String expected = "Here is details : </br>" + "Flow " + flowName + " in execution " + execId
                + " expected to FINISH within " + duration + " from "
                + fmt.print(new DateTime(flow.getStartTime())) + "</br>";
        String actual = "Actual flow status is " + flow.getStatus();
        return basicinfo + expected + actual;
    } else if (type.equals(SlaOption.TYPE_JOB_FINISH)) {
        String jobName = (String) slaOption.getInfo().get(SlaOption.INFO_JOB_NAME);
        String duration = (String) slaOption.getInfo().get(SlaOption.INFO_DURATION);
        return "SLA Alert: Your job " + jobName + " failed to FINISH within " + duration + " in execution "
                + execId;/*from  www . j ava 2  s . co  m*/
    } else if (type.equals(SlaOption.TYPE_JOB_SUCCEED)) {
        String jobName = (String) slaOption.getInfo().get(SlaOption.INFO_JOB_NAME);
        String duration = (String) slaOption.getInfo().get(SlaOption.INFO_DURATION);
        return "SLA Alert: Your job " + jobName + " failed to SUCCEED within " + duration + " in execution "
                + execId;
    } else {
        return "Unrecognized SLA type " + type;
    }
}

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   w  w  w.  j ava  2 s. 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;
    }/* w w  w  . j  a  va2 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 w w w  .  j a va2  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();
        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.trigger.Condition.java

License:Apache License

public void resetCheckers() {
    for (ConditionChecker checker : checkers.values()) {
        checker.reset();/*  w  ww.ja  v a2  s.  c o  m*/
    }
    updateNextCheckTime();
    logger.info("Done resetting checkers. The next check time will be " + new DateTime(nextCheckTime));
}

From source file:azkaban.trigger.JdbcTriggerImpl.java

License:Apache License

@Override
public List<Trigger> getUpdatedTriggers(final long lastUpdateTime) throws TriggerLoaderException {
    logger.info("Loading triggers changed since " + new DateTime(lastUpdateTime).toString());

    final ResultSetHandler<List<Trigger>> handler = new TriggerResultHandler();

    try {/*  w ww  . j  ava 2  s.c o  m*/
        final List<Trigger> triggers = this.dbOperator.query(GET_UPDATED_TRIGGERS, handler, lastUpdateTime);
        logger.info("Loaded " + triggers.size() + " triggers.");
        return triggers;
    } catch (final SQLException ex) {
        throw new TriggerLoaderException("Loading triggers from db failed.", ex);
    }
}

From source file:azkaban.trigger.JdbcTriggerLoader.java

License:Apache License

@Override
public List<Trigger> getUpdatedTriggers(long lastUpdateTime) throws TriggerLoaderException {
    logger.info("Loading triggers changed since " + new DateTime(lastUpdateTime).toString());
    Connection connection = getConnection();

    QueryRunner runner = new QueryRunner();
    ResultSetHandler<List<Trigger>> handler = new TriggerResultHandler();

    List<Trigger> triggers;

    try {/*from www .  j a  v a2s  .  com*/
        triggers = runner.query(connection, GET_UPDATED_TRIGGERS, handler, lastUpdateTime);
    } catch (SQLException e) {
        logger.error(GET_ALL_TRIGGERS + " failed.");

        throw new TriggerLoaderException("Loading triggers from db failed. ", e);
    } finally {
        DbUtils.closeQuietly(connection);
    }

    logger.info("Loaded " + triggers.size() + " triggers.");

    return triggers;
}

From source file:azkaban.utils.WebUtils.java

License:Apache License

public String formatDateTime(long timestamp) {
    return formatDateTime(new DateTime(timestamp));
}

From source file:azkaban.webapp.servlet.FlowTriggerInstanceServlet.java

License:Apache License

private DateTime getPresentTimeByTimezone(final DateTimeZone timezone) {
    return new DateTime(timezone);
}