List of usage examples for org.joda.time DateTime now
public static DateTime now()
ISOChronology
in the default time zone. From source file:com.expedia.edw.datapeek.dataProcessors.scomDataProcessor.Scomer.java
License:Open Source License
/*** * Executes a Scom Query and processes the result. * // ww w . j av a2 s. c o m * @param searchQuery * @param earliest * @param latest * @param interval * @param ignoreErrors * @param parentStopwatch * @return * @throws TimeoutException * @throws ScomSearchException */ public ScomResults executeScomQuery(final String searchQuery, final DateTime earliest, final DateTime latest, final int interval, final boolean ignoreErrors, final Stopwatcher parentStopwatch) throws TimeoutException, ScomSearchException { /* Start stopwatch */ final Stopwatcher stopwatch = parentStopwatch.child(); stopwatch.startMeasuring("scomer"); ScomResults results = null; String searchId = null; boolean success = false; try { final String cleanedSearchquery = Scomer.cleanScomQuery(searchQuery, interval); /* Create the Search Job */ final PostSearchResponse response = this.scomService.postSearch(cleanedSearchquery, earliest, latest); /* Get the Search Job Id */ searchId = response.getSid(); /* Abort if no search id was created */ if (searchId == null) { for (final ScomMessageXml message : response.getMessages()) { Scomer.LOGGER.error(message.getMessage()); stopwatch.stopMeasuring("scomer"); stopwatch.finish(); throw new UnknownError("No search id created for search."); } } ScomJobs jobs = null; ScomSearch search = null; int pollCounter = 0; /* * Deadline of when the Search Job needs to be returned (without results) */ final DateTime noJobTimeoutTime = DateTime.now().plus(ScomCallableFactory.NO_JOB_TIMEOUT_MILLIS); while (true) { /* * Get the status of the Search Job. If null is returned, the job must not exist yet */ jobs = this.scomService.getSearchStatus(searchId); pollCounter++; if (jobs != null) { search = jobs.first(); if (search.isDone()) { break; } } else { if (noJobTimeoutTime.isBeforeNow()) { /* Abort the Work Item */ throw new TimeoutException( "Could not retrieve the created Scom Job before timeout expired."); } } try { /* Sleep for a configured amount of time before retrying */ Thread.sleep(ScomCallableFactory.CHECK_JOB_MILLIS); } catch (final InterruptedException e) { Scomer.LOGGER.warn("InterruptedException occured in Scomer", e); } } /* Log all search dimensions */ stopwatch.addDimension("isFailed", search.isFailed()); stopwatch.addMetric("diskUsage", search.getDiskUsage()); stopwatch.addMetric("dropCount", search.getDropCount()); stopwatch.addMetric("eventAvailableCount", search.getEventAvailableCount()); stopwatch.addMetric("eventCount", search.getEventCount()); stopwatch.addMetric("eventFieldCount", search.getEventFieldCount()); stopwatch.addMetric("resultCount", search.getResultCount()); stopwatch.addMetric("scanCount", search.getScanCount()); stopwatch.addMetric("resultPollCount", pollCounter); /* final Check for errors */ final ScomMessages messages = search.getMessages(); if (messages.getFatal() != null) { stopwatch.addMetric("fatalMessagesCount", messages.getFatal().size()); /* Always log fatal messages but don't fail the Work Items */ Scomer.LOGGER.warn("Scom fatal message(s): " + Joiner.on(", ").join(messages.getFatal())); } else { stopwatch.addMetric("fatalMessagesCount", 0); } if (messages.getError() != null) { stopwatch.addMetric("errorMessagesCount", messages.getError().size()); if (!ignoreErrors) { Scomer.LOGGER.warn("Scom error message(s): " + Joiner.on(", ").join(messages.getError())); throw new ScomSearchException(); } } else { stopwatch.addMetric("errorMessagesCount", 0); } if (messages.getWarn() != null) { stopwatch.addMetric("warnMessagesCount", messages.getWarn().size()); if (!ignoreErrors) { Scomer.LOGGER.warn("Scom warn message: " + Joiner.on(", ").join(messages.getWarn())); /* * Test each warning against the whitelist. If it is not whitelisted, throw an exception */ for (final String warning : messages.getWarn()) { for (final String whitelisted : this.warningWhiteList) { if (!warning.matches(whitelisted)) { throw new ScomSearchException(); } } } } } else { stopwatch.addMetric("warnMessagesCount", 0); } if (messages.getInfo() != null) { stopwatch.addMetric("infoMessagesCount", messages.getInfo().size()); } else { stopwatch.addMetric("infoMessagesCount", 0); } /* Get the results (if any) */ if (search.getResultCount() > 0) { results = this.scomService.getSearchResults(searchId); } /* If we made it this far, it was a success */ success = true; } finally { /* Delete the Scom search */ if (searchId != null) { this.scomService.deleteSearch(searchId); } /* Stop the stopwatch */ Scomer.LOGGER.debug("Finished Scomer"); stopwatch.addDimension("success", success); stopwatch.stopMeasuring("scomer", "scomer"); stopwatch.finish(); } return results; }
From source file:com.facebook.presto.atop.AtopSplitManager.java
License:Apache License
@Override public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layoutHandle) { AtopTableLayoutHandle handle = checkType(layoutHandle, AtopTableLayoutHandle.class, "layoutHandle"); AtopTableHandle table = handle.getTableHandle(); List<ConnectorSplit> splits = new ArrayList<>(); DateTime end = DateTime.now().withZone(timeZone); for (Node node : nodeManager.getActiveDatasourceNodes(connectorId.getId())) { DateTime start = end.minusDays(maxHistoryDays - 1).withTimeAtStartOfDay(); while (start.isBefore(end)) { DateTime splitEnd = start.withTime(23, 59, 59, 999); Domain splitDomain = Domain.create( ValueSet.ofRanges(//from w w w. ja va 2 s . co m Range.range(TIMESTAMP, start.getMillis(), true, splitEnd.getMillis(), true)), false); if (handle.getStartTimeConstraint().overlaps(splitDomain) && handle.getEndTimeConstraint().overlaps(splitDomain)) { splits.add(new AtopSplit(table.getTable(), node.getHostAndPort(), start)); } start = start.plusDays(1).withTimeAtStartOfDay(); } } return new FixedSplitSource(connectorId.getId(), splits); }
From source file:com.facebook.presto.execution.executor.TaskExecutorSimulator.java
License:Apache License
public void run() throws Exception { long start = System.nanoTime(); scheduleStatusPrinter(start);/* w w w. ja v a 2 s.co m*/ SimulationController controller = new SimulationController(taskExecutor, TaskExecutorSimulator::printSummaryStats); // Uncomment one of these: // runExperimentOverloadedCluster(controller); // runExperimentMisbehavingQuanta(controller); // runExperimentStarveSlowSplits(controller); runExperimentWithinLevelFairness(controller); System.out.println("Stopped scheduling new tasks. Ending simulation.."); controller.stop(); close(); SECONDS.sleep(5); System.out.println(); System.out.println("Simulation finished at " + DateTime.now() + ". Runtime: " + nanosSince(start)); System.out.println(); printSummaryStats(controller, taskExecutor); }
From source file:com.facebook.presto.execution.QueryStateMachine.java
License:Apache License
public boolean finished() { synchronized (this) { if (endTime == null) { endTime = DateTime.now(); }// www.ja v a 2 s . com } return queryState.setIf(FINISHED, Predicates.not(inDoneState())); }
From source file:com.facebook.presto.execution.QueryStateMachine.java
License:Apache License
public boolean cancel() { synchronized (this) { if (endTime == null) { endTime = DateTime.now(); }/*from w w w . j av a2 s . com*/ } synchronized (this) { if (failureCause == null) { failureCause = new PrestoException(StandardErrorCode.USER_CANCELED.toErrorCode(), "Query was canceled"); } } return queryState.setIf(CANCELED, Predicates.not(inDoneState())); }
From source file:com.facebook.presto.execution.QueryStateMachine.java
License:Apache License
public boolean fail(@Nullable Throwable cause) { synchronized (this) { if (endTime == null) { endTime = DateTime.now(); }// w w w .j av a 2 s.c o m } synchronized (this) { if (cause != null) { if (failureCause == null) { failureCause = cause; } else { failureCause.addSuppressed(cause); } } } return queryState.setIf(FAILED, Predicates.not(inDoneState())); }
From source file:com.facebook.presto.execution.QueryStateMachine.java
License:Apache License
public synchronized void recordHeartbeat() { this.lastHeartbeat = DateTime.now(); }
From source file:com.facebook.presto.execution.QueryStateMachine.java
License:Apache License
public synchronized void recordExecutionStart() { if (executionStartTime == null) { this.executionStartTime = DateTime.now(); } }
From source file:com.facebook.presto.execution.QueryTracker.java
License:Apache License
/** * Remove completed queries after a waiting period *//*from www. j av a 2s .com*/ private void removeExpiredQueries() { DateTime timeHorizon = DateTime.now().minus(minQueryExpireAge.toMillis()); // we're willing to keep queries beyond timeHorizon as long as we have fewer than maxQueryHistory while (expirationQueue.size() > maxQueryHistory) { T query = expirationQueue.peek(); if (query == null) { return; } // expirationQueue is FIFO based on query end time. Stop when we see the // first query that's too young to expire Optional<DateTime> endTime = query.getEndTime(); if (!endTime.isPresent()) { // this shouldn't happen but it is better to be safe here continue; } if (endTime.get().isAfter(timeHorizon)) { return; } // only expire them if they are older than minQueryExpireAge. We need to keep them // around for a while in case clients come back asking for status QueryId queryId = query.getQueryId(); log.debug("Remove query %s", queryId); queries.remove(queryId); expirationQueue.remove(query); } }
From source file:com.facebook.presto.execution.QueryTracker.java
License:Apache License
private void failAbandonedQueries() { for (T query : queries.values()) { try {//ww w . j av a2s. co m if (query.isDone()) { continue; } if (isAbandoned(query)) { log.info("Failing abandoned query %s", query.getQueryId()); query.fail(new PrestoException(ABANDONED_QUERY, format("Query %s has not been accessed since %s: currentTime %s", query.getQueryId(), query.getLastHeartbeat(), DateTime.now()))); } } catch (RuntimeException e) { log.error(e, "Exception failing abandoned query %s", query.getQueryId()); } } }