List of usage examples for org.joda.time DateTime getMillis
public long getMillis()
From source file:com.stratio.ingestion.serializer.elasticsearch.TimeStampedEvent.java
License:Apache License
TimeStampedEvent(Event base) { super();/*w w w. j a va2s .com*/ setBody(base.getBody()); Map<String, String> headers = Maps.newHashMap(base.getHeaders()); String timestampHeader = headers.get("@timestamp"); Long ts = null; if (!StringUtils.isBlank(timestampHeader)) { try { ts = Long.parseLong(timestampHeader); headers.put("@timestamp", ISODateTimeFormat.dateTime().withZoneUTC().print(ts)); } catch (RuntimeException ex) { log.trace("Could not parse timestamp as long: {}", timestampHeader); try { ts = ISODateTimeFormat.dateOptionalTimeParser().withZoneUTC().parseMillis(timestampHeader); } catch (RuntimeException ex2) { log.trace("Could not parse timestamp as dateOptionalTime: {}", timestampHeader); } } } if (ts == null) { DateTime now = DateTime.now(); ts = now.getMillis(); headers.put("@timestamp", ISODateTimeFormat.dateTime().withZoneUTC().print(now)); } this.timestamp = ts; setHeaders(headers); }
From source file:com.streamsets.pipeline.lib.parser.syslog.SyslogParser.java
License:Apache License
/** * Parse the RFC3164 date format. This is trickier than it sounds because this * format does not specify a year so we get weird edge cases at year * boundaries. This implementation tries to "do what I mean". * @param ts RFC3164-compatible timestamp to be parsed * @return Typical (for Java) milliseconds since the UNIX epoch *//*from w w w. j ava2 s . c om*/ protected long parseRfc3164Time(String ts) throws OnRecordErrorException { DateTime now = DateTime.now(); int year = now.getYear(); ts = TWO_SPACES.matcher(ts).replaceFirst(" "); DateTime date; try { date = rfc3164Format.parseDateTime(ts); } catch (IllegalArgumentException e) { throw new OnRecordErrorException(Errors.SYSLOG_10, ts, e); } // try to deal with boundary cases, i.e. new year's eve. // rfc3164 dates are really dumb. // NB: cannot handle replaying of old logs or going back to the future DateTime fixed = date.withYear(year); // flume clock is ahead or there is some latency, and the year rolled if (fixed.isAfter(now) && fixed.minusMonths(1).isAfter(now)) { fixed = date.withYear(year - 1); // flume clock is behind and the year rolled } else if (fixed.isBefore(now) && fixed.plusMonths(1).isBefore(now)) { fixed = date.withYear(year + 1); } date = fixed; return date.getMillis(); }
From source file:com.streamsets.pipeline.lib.parser.udp.syslog.SyslogParser.java
License:Apache License
/** * Parse the RFC3164 date format. This is trickier than it sounds because this * format does not specify a year so we get weird edge cases at year * boundaries. This implementation tries to "do what I mean". * @param ts RFC3164-compatible timestamp to be parsed * @return Typical (for Java) milliseconds since the UNIX epoch *//*from w w w.j a va2s. co m*/ protected long parseRfc3164Time(String recordIdentifer, String msg, String ts) throws OnRecordErrorException { DateTime now = DateTime.now(); int year = now.getYear(); ts = TWO_SPACES.matcher(ts).replaceFirst(" "); DateTime date; try { date = rfc3164Format.parseDateTime(ts); } catch (IllegalArgumentException e) { throw throwOnRecordErrorException(recordIdentifer, msg, Errors.SYSLOG_10, ts, e); } // try to deal with boundary cases, i.e. new year's eve. // rfc3164 dates are really dumb. // NB: cannot handle replaying of old logs or going back to the future DateTime fixed = date.withYear(year); // flume clock is ahead or there is some latency, and the year rolled if (fixed.isAfter(now) && fixed.minusMonths(1).isAfter(now)) { fixed = date.withYear(year - 1); // flume clock is behind and the year rolled } else if (fixed.isBefore(now) && fixed.plusMonths(1).isBefore(now)) { fixed = date.withYear(year + 1); } date = fixed; return date.getMillis(); }
From source file:com.tales.storage.hbase.translators.DateTimeToBytesTranslator.java
License:Apache License
@Override public Object translate(Object anObject) { Object returnValue;/*from ww w .j a va 2 s. c om*/ if (anObject == null) { returnValue = this.nullValue; } else { try { DateTime dateTime = ((DateTime) anObject).toDateTime(DateTimeZone.UTC); // at least make it UTC if we are going to loose timezone long timestamp = reverse ? Long.MAX_VALUE - dateTime.getMillis() : dateTime.getMillis(); // NOTE: this looses timezone information returnValue = Bytes.toBytes(timestamp); } catch (ClassCastException e) { throw new TranslationException(e); } } return returnValue; }
From source file:com.tango.elasticsearch.rest.action.unique.UniqueTermsAction.java
License:Apache License
private void prepareRequestsForProcessing(RestRequest request, Map<SearchRequest, String> searchRequestsToCacheKeyMap, List<TermsResult> cachedResponses) throws IOException { SearchRequest searchRequest = RestSearchAction.parseSearchRequest(request); String[] indices = searchRequest.indices(); if (searchRequest.source() == null) { throw new IllegalArgumentException("Empty request source"); }//from w w w . j a va 2 s .com RequestParamsInfo requestParamsInfo = getRequestInfo( new String(searchRequest.source().copyBytesArray().array())); if (request.paramAsBoolean("clearCache", false)) { cache.clear(); } searchRequest.listenerThreaded(false); for (String index : indices) { String cacheKey = ""; if (requestParamsInfo != null) { boolean cachedValueFound = false; int datePostfixStart; while ((datePostfixStart = index.indexOf(INDEX_NAME_PREFIX_DELIMITER)) >= 0) { String dateStr = index.substring(datePostfixStart + 1); try { DateTime dateTime = ES_INDEX_DATE_FORMAT.parseDateTime(dateStr); long indexStart = dateTime.getMillis(); // plus 1 hour long indexEnd = dateTime.plusHours(1).getMillis(); // fully covered if (indexStart >= requestParamsInfo.getFromTime() && indexEnd < requestParamsInfo.getToTime()) { // trying to get from cache cacheKey = index + requestParamsInfo.getRequestCacheKey(); TermsResult cached = getCachedValue(cacheKey); if (cached != null) { cachedValueFound = true; cachedResponses.add(cached); } } break; } catch (IllegalArgumentException ex) { if (logger.isTraceEnabled()) { logger.trace("Error parsing date from " + dateStr + ": " + ex.getMessage(), ex); } } } if (cachedValueFound) { continue; } } SearchRequest oneIndexSearchRequest = new SearchRequest(index); if (searchRequest.source() != null) { oneIndexSearchRequest.source(searchRequest.source().copyBytesArray().array()); } if (searchRequest.extraSource() != null) { oneIndexSearchRequest.extraSource(searchRequest.extraSource().copyBytesArray().array()); } oneIndexSearchRequest.searchType(searchRequest.searchType()); oneIndexSearchRequest.types(searchRequest.types()); oneIndexSearchRequest.routing(searchRequest.routing()); oneIndexSearchRequest.preference(searchRequest.preference()); oneIndexSearchRequest.ignoreIndices(searchRequest.ignoreIndices()); oneIndexSearchRequest.listenerThreaded(false); oneIndexSearchRequest.operationThreading(searchRequest.operationThreading()); searchRequestsToCacheKeyMap.put(oneIndexSearchRequest, cacheKey); } }
From source file:com.thinkbiganalytics.jobrepo.query.model.transform.ModelUtils.java
License:Apache License
/** * Calculate the runtime for a given start/stop * * @return the runtime in millis/*www. ja va2 s.c o m*/ */ public static Long runTime(DateTime start, DateTime stop) { if (start == null) { return 0L; } return (stop != null ? (stop.getMillis() - start.getMillis()) : DateTimeUtil.getNowUTCTime().getMillis() - start.getMillis()); }
From source file:com.thinkbiganalytics.jobrepo.query.model.transform.ModelUtils.java
License:Apache License
/** * Calculate the time since a given stop time * * @return the time in millis/*from ww w .ja v a2 s. c o m*/ */ public static Long timeSince(DateTime start, DateTime stop) { DateTime now = DateTimeUtil.getNowUTCTime(); DateTime startTime = start != null ? start : now; return (stop != null ? (now.getMillis() - stop.getMillis()) : now.getMillis() - startTime.getMillis()); }
From source file:com.thinkbiganalytics.jobrepo.rest.controller.NifiFeedProcessorStatisticsRestControllerV2.java
License:Apache License
@GET @Path("/{feedName}/processor-errors") @Produces(MediaType.APPLICATION_JSON)/*from ww w . jav a 2s . c om*/ @ApiOperation("Returns the list of stats for each processor within the given timeframe relative to now") @ApiResponses(@ApiResponse(code = 200, message = "Returns the list of stats for each processor within the given timeframe relative to now", response = com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NifiFeedProcessorStats.class, responseContainer = "List")) public Response findFeedProcessorErrors(@PathParam("feedName") String feedName, @QueryParam("from") Long fromMillis, @QueryParam("to") Long toMillis, @QueryParam("after") Long timestamp) { this.accessController.checkPermission(AccessController.SERVICES, OperationsAccessControl.ACCESS_OPS); final DateTime endTime = getToDateTime(toMillis); final DateTime startTime = getFromDateTime(fromMillis); NiFiFeedProcessorErrorsContainer container = new NiFiFeedProcessorErrorsContainer(startTime, endTime); List<? extends NifiFeedProcessorErrors> errors = null; if (nifiStatsJmsReceiver.isPersistErrors()) { errors = metadataAccess.read(() -> { if (timestamp != null && timestamp != 0L) { return statsProvider.findFeedProcessorErrorsAfter(feedName, new DateTime(timestamp)); } else { return statsProvider.findFeedProcessorErrors(feedName, startTime, endTime); } }); } else { if (timestamp != null && timestamp != 0L) { errors = nifiStatsJmsReceiver.getErrorsForFeed(feedName, timestamp); } else { errors = nifiStatsJmsReceiver.getErrorsForFeed(feedName, startTime.getMillis(), endTime.getMillis()); } } List<com.thinkbiganalytics.metadata.rest.jobrepo.nifi.NifiFeedProcessorStatsErrors> errorsModel = NifiFeedProcessorStatsTransform .toErrorsModel(errors); container.setErrors(errorsModel); return Response.ok(container).build(); }
From source file:com.thinkbiganalytics.jpa.LongColumnDateTimeMapper.java
License:Apache License
public Long toNonNullValue(DateTime value) { return Long.valueOf(value.getMillis()); }
From source file:com.thinkbiganalytics.metadata.cache.util.TimeUtil.java
License:Apache License
public static Long getTimeNearestFiveSeconds() { DateTime dt = new DateTime().withMillisOfSecond(0); int seconds = dt.getSecondOfMinute(); if (seconds % 5 > 0) { dt = dt.withSecondOfMinute(seconds - (seconds % 5)); }// w w w. j a v a2s . com return dt.getMillis(); }