Java Code Examples for org.apache.commons.lang.time.DateUtils
The following examples show how to use
org.apache.commons.lang.time.DateUtils. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: elexis-3-core Source File: LocalDocumentService.java License: Eclipse Public License 1.0 | 6 votes |
private void deleteBackupFilesOlderThen(File backupDir, int days){ try { if (backupDir.isDirectory()) { Collection<File> filesToDelete = FileUtils.listFiles(backupDir, new AgeFileFilter(DateUtils.addDays(new Date(), days * -1)), TrueFileFilter.TRUE); for (File file : filesToDelete) { boolean success = FileUtils.deleteQuietly(file); if (!success) { LoggerFactory.getLogger(getClass()) .warn("Cannot delete old backup file at: " + file.getAbsolutePath()); } } } } catch (Exception e) { LoggerFactory.getLogger(getClass()).warn("Cannot delete old backup files.", e); } }
Example 2
Source Project: eagle Source File: KafkaMessageDistributionBolt.java License: Apache License 2.0 | 6 votes |
@Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { String site = config.getString("dataSourceConfig.site"); String topic = config.getString("dataSourceConfig.topic"); this.baseMetricDimension = new HashMap<>(); this.baseMetricDimension.put("site", site); this.baseMetricDimension.put("topic", topic); registry = new MetricRegistry(); this.granularity = DEFAULT_METRIC_GRANULARITY; if (config.hasPath("dataSourceConfig.kafkaDistributionDataIntervalMin")) { this.granularity = config.getInt("dataSourceConfig.kafkaDistributionDataIntervalMin") * DateUtils.MILLIS_PER_MINUTE; } String host = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST); int port = config.getInt(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT); String username = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME); String password = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD); listener = new EagleServiceReporterMetricListener(host, port, username, password); }
Example 3
Source Project: AlgoTrader Source File: MarketDataServiceImpl.java License: GNU General Public License v2.0 | 6 votes |
protected void handlePersistTick(Tick tick) throws IOException { Security security = tick.getSecurity(); // persist ticks only between marketOpen & close if (DateUtil.compareToTime(security.getSecurityFamily().getMarketOpen()) >= 0 && DateUtil.compareToTime(security.getSecurityFamily().getMarketClose()) <= 0) { // get the current Date rounded to MINUTES Date date = DateUtils.round(DateUtil.getCurrentEPTime(), Calendar.MINUTE); tick.setDateTime(date); // write the tick to file CsvTickWriter csvWriter = this.csvWriters.get(security); if (csvWriter == null) { csvWriter = new CsvTickWriter(security.getIsin()); this.csvWriters.put(security, csvWriter); } csvWriter.write(tick); // write the tick to the DB (even if not valid) getTickDao().create(tick); } }
Example 4
Source Project: datawave Source File: BaseQueryMetricHandler.java License: Apache License 2.0 | 6 votes |
public QueryMetricsSummaryResponse processQueryMetricsSummary(List<T> queryMetrics) throws IOException { QueryMetricsSummaryResponse summary = new QueryMetricsSummaryResponse(); Date now = new Date(); Date hour1 = DateUtils.addHours(now, -1); Date hour6 = DateUtils.addHours(now, -6); Date hour12 = DateUtils.addHours(now, -12); Date day1 = DateUtils.addDays(now, -1); Date day7 = DateUtils.addDays(now, -7); Date day30 = DateUtils.addDays(now, -30); Date day60 = DateUtils.addDays(now, -60); Date day90 = DateUtils.addDays(now, -90); for (T metric : queryMetrics) { try { binSummary(metric, summary, hour1, hour6, hour12, day1, day7, day30, day60, day90); } catch (Exception e1) { log.error(e1.getMessage()); } } return summary; }
Example 5
Source Project: kfs Source File: AccountRule.java License: GNU Affero General Public License v3.0 | 6 votes |
/** * This method checks to see if the account expiration date is today's date or earlier * * @param newAccount * @return fails if the expiration date is null or after today's date */ protected boolean checkAccountExpirationDateValidTodayOrEarlier(Account newAccount) { // get today's date, with no time component Date todaysDate = new Date(getDateTimeService().getCurrentDate().getTime()); todaysDate.setTime(DateUtils.truncate(todaysDate, Calendar.DAY_OF_MONTH).getTime()); // TODO: convert this to using Wes' Kuali KfsDateUtils once we're using Date's instead of Timestamp // get the expiration date, if any Date expirationDate = newAccount.getAccountExpirationDate(); if (ObjectUtils.isNull(expirationDate)) { putFieldError("accountExpirationDate", KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID); return false; } // when closing an account, the account expiration date must be the current date or earlier expirationDate.setTime(DateUtils.truncate(expirationDate, Calendar.DAY_OF_MONTH).getTime()); if (expirationDate.after(todaysDate)) { putFieldError("accountExpirationDate", KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID); return false; } return true; }
Example 6
Source Project: kfs Source File: RetirementInfoServiceTest.java License: GNU Affero General Public License v3.0 | 6 votes |
private AssetRetirementGlobalDetail createRetirementDetail(String docNumber, int daysToAdd, String docStatus) { AssetRetirementGlobalDetail globalDetail = new AssetRetirementGlobalDetail(); globalDetail.setDocumentNumber(docNumber); AssetRetirementGlobal retirementGlobal = new AssetRetirementGlobal() { @Override public void refreshReferenceObject(String referenceObjectName) { } }; retirementGlobal.setRetirementDate(new java.sql.Date(DateUtils.addDays(dateTimeService.getCurrentDate(), daysToAdd).getTime())); FinancialSystemDocumentHeader header = new FinancialSystemDocumentHeader(); header.setFinancialDocumentStatusCode(docStatus); retirementGlobal.setDocumentHeader(header); globalDetail.setAssetRetirementGlobal(retirementGlobal); return globalDetail; }
Example 7
Source Project: qmq Source File: SendMessageTask.java License: Apache License 2.0 | 6 votes |
@Override public Void call() { LOG.info("{} start...", dataSourceInfo.getUrl()); stop = false; String name = Thread.currentThread().getName(); try { Thread.currentThread().setName(dataSourceInfo.getUrl()); long begin = System.currentTimeMillis(); while ((!isStop() && !timeout(begin))) { Date since = DateUtils.addSeconds(new Date(), -DEFAULT_TIME_INTEL); List<MsgQueue> errorMessages = messageClientStore.findErrorMsg(this.dataSource, since); if (errorMessages == null || errorMessages.isEmpty()) { break; } logRemainMsg(errorMessages); processErrorMessages(errorMessages, since); } } catch (Exception e) { throw new RuntimeException("process message error, url: " + dataSourceInfo.getUrl(), e); } finally { stop = true; Thread.currentThread().setName(name); LOG.info("{} finish", dataSourceInfo.getUrl()); } return null; }
Example 8
Source Project: openhab1-addons Source File: DateTimeUtils.java License: Eclipse Public License 2.0 | 6 votes |
/** * Converts the time (hour.minute) to a calendar object. */ public static Calendar timeToCalendar(Calendar calendar, double time) { if (time < 0.0) { return null; } Calendar cal = (Calendar) calendar.clone(); int hour = 0; int minute = 0; if (time == 24.0) { cal.add(Calendar.DAY_OF_MONTH, 1); } else { hour = (int) time; minute = (int) ((time * 100) - (hour * 100)); } cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minute); return DateUtils.truncate(cal, Calendar.MINUTE); }
Example 9
Source Project: eagle Source File: ServiceAuditDAOImpl.java License: Apache License 2.0 | 6 votes |
@Override public List<GenericAuditEntity> findUserServiceAuditByAction(String userID, String action) throws Exception { try { IEagleServiceClient client = new EagleServiceClientImpl(connector); String query = AuditConstants.AUDIT_SERVICE_ENDPOINT + "[@userID=\"" + userID + "\" AND @actionTaken=\"" + action + "\"]{*}"; GenericServiceAPIResponseEntity<GenericAuditEntity> response = client.search().startTime(0).endTime(10 * DateUtils.MILLIS_PER_DAY).pageSize(Integer.MAX_VALUE).query(query).send(); client.close(); if (response.getException() != null) { throw new Exception("Exception in querying eagle service: " + response.getException()); } return response.getObj(); } catch (Exception exception) { LOG.error("Exception in retrieving audit entry: " + exception); throw new IllegalStateException(exception); } }
Example 10
Source Project: piggymetrics Source File: RecipientRepositoryTest.java License: MIT License | 6 votes |
@Test public void shouldNotFindReadyForRemindWhenNotificationIsNotActive() { NotificationSettings remind = new NotificationSettings(); remind.setActive(false); remind.setFrequency(Frequency.WEEKLY); remind.setLastNotified(DateUtils.addDays(new Date(), -30)); Recipient recipient = new Recipient(); recipient.setAccountName("test"); recipient.setEmail("[email protected]"); recipient.setScheduledNotifications(ImmutableMap.of( NotificationType.REMIND, remind )); repository.save(recipient); List<Recipient> found = repository.findReadyForRemind(); assertTrue(found.isEmpty()); }
Example 11
Source Project: piggymetrics Source File: RecipientRepositoryTest.java License: MIT License | 6 votes |
@Test public void shouldNotFindReadyForBackupWhenFrequencyIsQuaterly() { NotificationSettings remind = new NotificationSettings(); remind.setActive(true); remind.setFrequency(Frequency.QUARTERLY); remind.setLastNotified(DateUtils.addDays(new Date(), -91)); Recipient recipient = new Recipient(); recipient.setAccountName("test"); recipient.setEmail("[email protected]"); recipient.setScheduledNotifications(ImmutableMap.of( NotificationType.BACKUP, remind )); repository.save(recipient); List<Recipient> found = repository.findReadyForBackup(); assertFalse(found.isEmpty()); }
Example 12
Source Project: cloud-portal Source File: DashboardController.java License: MIT License | 6 votes |
private void addProvisioningHistoryToMap(ProvisionLog provisionLog, Map<Long, Integer> provisioningHistoryMap) { Date date = provisionLog.getDate(); if (date.after(this.dateBefore)) { Date calculatedDate = DateUtils.truncate(date, Calendar.DAY_OF_MONTH); // NOSONAR long timeInMillis = calculatedDate.getTime(); Integer counter = provisioningHistoryMap.get(timeInMillis); if (counter == null) { counter = 0; } counter = counter + 1; provisioningHistoryMap.put(timeInMillis, counter); } }
Example 13
Source Project: hadoop Source File: RMContainerImpl.java License: Apache License 2.0 | 6 votes |
private static void updateAttemptMetrics(RMContainerImpl container) { // If this is a preempted container, update preemption metrics Resource resource = container.getContainer().getResource(); RMAppAttempt rmAttempt = container.rmContext.getRMApps() .get(container.getApplicationAttemptId().getApplicationId()) .getCurrentAppAttempt(); if (ContainerExitStatus.PREEMPTED == container.finishedStatus .getExitStatus()) { rmAttempt.getRMAppAttemptMetrics().updatePreemptionInfo(resource, container); } if (rmAttempt != null) { long usedMillis = container.finishTime - container.creationTime; long memorySeconds = resource.getMemory() * usedMillis / DateUtils.MILLIS_PER_SECOND; long vcoreSeconds = resource.getVirtualCores() * usedMillis / DateUtils.MILLIS_PER_SECOND; long gcoreSeconds = resource.getGpuCores() * usedMillis / DateUtils.MILLIS_PER_SECOND; rmAttempt.getRMAppAttemptMetrics() .updateAggregateAppResourceUsage(memorySeconds,vcoreSeconds, gcoreSeconds); } }
Example 14
Source Project: hadoop Source File: SchedulerApplicationAttempt.java License: Apache License 2.0 | 6 votes |
synchronized AggregateAppResourceUsage getRunningAggregateAppResourceUsage() { long currentTimeMillis = System.currentTimeMillis(); // Don't walk the whole container list if the resources were computed // recently. if ((currentTimeMillis - lastMemoryAggregateAllocationUpdateTime) > MEM_AGGREGATE_ALLOCATION_CACHE_MSECS) { long memorySeconds = 0; long vcoreSeconds = 0; long gcoreSeconds = 0; for (RMContainer rmContainer : this.liveContainers.values()) { long usedMillis = currentTimeMillis - rmContainer.getCreationTime(); Resource resource = rmContainer.getContainer().getResource(); memorySeconds += resource.getMemory() * usedMillis / DateUtils.MILLIS_PER_SECOND; vcoreSeconds += resource.getVirtualCores() * usedMillis / DateUtils.MILLIS_PER_SECOND; gcoreSeconds += resource.getGpuCores() * usedMillis / DateUtils.MILLIS_PER_SECOND; } lastMemoryAggregateAllocationUpdateTime = currentTimeMillis; lastMemorySeconds = memorySeconds; lastVcoreSeconds = vcoreSeconds; lastGcoreSeconds = gcoreSeconds; } return new AggregateAppResourceUsage(lastMemorySeconds, lastVcoreSeconds, lastGcoreSeconds); }
Example 15
Source Project: cachecloud Source File: HighchartPoint.java License: Apache License 2.0 | 6 votes |
public static HighchartPoint getFromAppCommandStats(AppCommandStats appCommandStats, Date currentDate, int diffDays) throws ParseException { Date collectDate = getDateTime(appCommandStats.getCollectTime()); if (!DateUtils.isSameDay(currentDate, collectDate)) { return null; } //显示用的时间 String date = null; try { date = DateUtil.formatDate(collectDate, "yyyy-MM-dd HH:mm"); } catch (Exception e) { date = DateUtil.formatDate(collectDate, "yyyy-MM-dd HH"); } // y坐标 long commandCount = appCommandStats.getCommandCount(); // x坐标 //为了显示在一个时间范围内 if (diffDays > 0) { collectDate = DateUtils.addDays(collectDate, diffDays); } return new HighchartPoint(collectDate.getTime(), commandCount, date); }
Example 16
Source Project: oxAuth Source File: CibaPingModeJwtAuthRequestTests.java License: MIT License | 6 votes |
/** * Creates a new JwtAuthorizationRequest using default configuration and params. */ private JwtAuthorizationRequest createJwtRequest(String keyStoreFile, String keyStoreSecret, String dnName, String userId, String keyId, SignatureAlgorithm signatureAlgorithm) throws Exception { OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName); String clientId = registerResponse.getClientId(); int now = (int)(System.currentTimeMillis() / 1000); JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest( null, signatureAlgorithm, cryptoProvider); jwtAuthorizationRequest.setClientNotificationToken("notification-token-123"); jwtAuthorizationRequest.setAud(issuer); jwtAuthorizationRequest.setLoginHint(userId); jwtAuthorizationRequest.setNbf(now); jwtAuthorizationRequest.setScopes(Collections.singletonList("openid")); jwtAuthorizationRequest.setIss(clientId); jwtAuthorizationRequest.setBindingMessage("1234"); jwtAuthorizationRequest.setExp((int)(DateUtils.addMinutes(new Date(), 5).getTime() / 1000)); jwtAuthorizationRequest.setIat(now); jwtAuthorizationRequest.setJti(UUID.randomUUID().toString()); jwtAuthorizationRequest.setKeyId(keyId); return jwtAuthorizationRequest; }
Example 17
Source Project: smarthome Source File: DateTimeUtils.java License: Eclipse Public License 2.0 | 5 votes |
/** * Returns the end of day from the calendar object. */ public static Calendar endOfDayDate(Calendar calendar) { Calendar cal = (Calendar) calendar.clone(); cal = DateUtils.ceiling(cal, Calendar.DATE); cal.add(Calendar.MILLISECOND, -1); return cal; }
Example 18
Source Project: kfs Source File: PriorYearAccount.java License: GNU Affero General Public License v3.0 | 5 votes |
/** * This method determines whether the account is expired or not. Note that if Expiration Date is the same date as testDate, then * this will return false. It will only return true if the account expiration date is one day earlier than testDate or earlier. * Note that this logic ignores all time components when doing the comparison. It only does the before/after comparison based on * date values, not time-values. * * @param testDate - Calendar instance with the date to test the Account's Expiration Date against. This is most commonly set to * today's date. * @return true or false based on the logic outlined above */ @Override public boolean isExpired(Calendar testDate) { if (LOG.isDebugEnabled()) { LOG.debug("entering isExpired(" + testDate + ")"); } // dont even bother trying to test if the accountExpirationDate is null if (this.accountExpirationDate == null) { return false; } // remove any time-components from the testDate testDate = DateUtils.truncate(testDate, Calendar.DAY_OF_MONTH); // get a calendar reference to the Account Expiration // date, and remove any time components Calendar acctDate = Calendar.getInstance(); acctDate.setTime(this.accountExpirationDate); acctDate = DateUtils.truncate(acctDate, Calendar.DAY_OF_MONTH); // if the Account Expiration Date is before the testDate if (acctDate.before(testDate)) { return true; } else { return false; } }
Example 19
Source Project: datawave Source File: DateIndexDataTypeHandler.java License: Apache License 2.0 | 5 votes |
/** * Construct a date index entry * * @param shardId * @param dataType * @param type * @param dateField * @param dateValue * @param visibility * @return The key and value */ public KeyValue getDateIndexEntry(String shardId, String dataType, String type, String dateField, String dateValue, ColumnVisibility visibility) { Date date = null; try { // get the date to be indexed date = dateNormalizer.denormalize(dateValue); } catch (Exception e) { log.error("Failed to normalize date value (skipping): " + dateValue, e); return null; } // set the time to 00:00:00 (for key timestamp) date = DateUtils.truncate(date, Calendar.DATE); // format the date and the shardId date as yyyyMMdd String rowDate = DateIndexUtil.format(date); String shardDate = ShardIdFactory.getDateString(shardId); ColumnVisibility biased = new ColumnVisibility(flatten(visibility)); // The row is the date plus the shard partition String row = rowDate + '_' + getDateIndexShardPartition(rowDate, type, shardDate, dataType, dateField, new String(biased.getExpression())); // the colf is the type (e.g. LOAD or ACTIVITY) // the colq is the event date yyyyMMdd \0 the datatype \0 the field name String colq = shardDate + '\0' + dataType + '\0' + dateField; // the value is a bitset denoting the shard Value shardList = createDateIndexValue(ShardIdFactory.getShard(shardId)); // create the key Key key = new Key(row, type, colq, biased, date.getTime()); if (log.isTraceEnabled()) { log.trace("Dateate index key: " + key + " for shardId " + shardId); } return new KeyValue(key, shardList); }
Example 20
Source Project: sep4j Source File: SepShowcases.java License: Apache License 2.0 | 5 votes |
/** * if the cell is of String type * * @param birthDayString * @throws ParseException */ public void setBirthDay(String birthDayString) throws ParseException { if (birthDayString == null) { return; } birthDay = DateUtils.parseDate(birthDayString, new String[] { "yyyy-MM-dd" }); }
Example 21
Source Project: Eagle Source File: DefaultDeduplicator.java License: Apache License 2.0 | 5 votes |
public AlertDeduplicationStatus checkDedup(EntityTagsUniq key){ long current = key.timestamp; if(!entites.containsKey(key)){ entites.put(key, current); return AlertDeduplicationStatus.NEW; } long last = entites.get(key); if(current - last >= dedupIntervalMin * DateUtils.MILLIS_PER_MINUTE){ entites.put(key, current); return AlertDeduplicationStatus.DUPLICATED; } return AlertDeduplicationStatus.IGNORED; }
Example 22
Source Project: datawave Source File: ShardedTableMapFileTest.java License: Apache License 2.0 | 5 votes |
private SortedMap<Text,String> simulateMissingSplitsForDay(int daysAgo, String tableName) throws IOException { // start with a well distributed set of shards per day for 3 days SortedMap<Text,String> locations = createDistributedLocations(tableName); // for shards from "daysAgo", remove them String day = DateHelper.format(System.currentTimeMillis() - (daysAgo * DateUtils.MILLIS_PER_DAY)); for (int currShard = 0; currShard < SHARDS_PER_DAY; currShard++) { locations.remove(new Text(day + "_" + currShard)); } return locations; }
Example 23
Source Project: kfs Source File: CustomerInvoiceDocumentServiceImpl.java License: GNU Affero General Public License v3.0 | 5 votes |
/** * get the date before the given amount of days */ protected Date getPastDate(Integer amount){ Integer pastDateAmount = -1 * amount; java.util.Date today = this.getDateTimeService().getCurrentDate(); java.util.Date pastDate = DateUtils.addDays(today, pastDateAmount); return KfsDateUtils.convertToSqlDate(pastDate); }
Example 24
Source Project: datawave Source File: TestShardGenerator.java License: Apache License 2.0 | 5 votes |
private Map<Text,String> simulateTabletAssignments(String[] tableNames) { Map<Text,String> locations = new TreeMap<>(); long now = System.currentTimeMillis(); HashSet<String> alreadyUsed = new HashSet<>(); int daysInGroup = 1; for (int daysAgo = -2; daysAgo < numDays - 1; daysAgo++) { if (daysInGroup % daysWithoutCollisions == 0) { alreadyUsed = new HashSet<>(); } daysInGroup++; String today = DateHelper.format(now - (daysAgo * DateUtils.MILLIS_PER_DAY)); for (int currShard = 1; currShard < shardsPerDay; currShard++) { // don't assign the same tserver to two shards within one day String tserver = getAnotherRandomTserver(); while (alreadyUsed.contains(tserver)) { tserver = getAnotherRandomTserver(); } alreadyUsed.add(tserver); for (String tableName : tableNames) { locations.put(new Text(today + "_" + currShard), tserver); } } } return locations; }
Example 25
Source Project: usergrid Source File: ESSuiteTest.java License: Apache License 2.0 | 5 votes |
private static void setupCommits( Injector injector ) throws Exception { // Commits shouldn't have the same createDate b/c of issues with sorting them Date now = new Date(); commitDao = injector.getInstance( CommitDao.class ); Commit commit = new BasicCommit( COMMIT_ID_1, // commitId MODULE_ID_1, // moduleId "742e2a76a6ba161f9efb87ce58a9187e", // warMD5 now, // createDate "/some/dummy/path" ); commitDao.save( commit ); commit = new BasicCommit( COMMIT_ID_2, // commitId MODULE_ID_2, // moduleId "395cfdfc3b77242a6f957d6d92da8958", // warMD5 DateUtils.addMinutes( now, 1 ), // createDate "/some/dummy/path" ); commitDao.save( commit ); commit = new BasicCommit( COMMIT_ID_3, // commitId MODULE_ID_2, // moduleId "b9860ffa5e39b6f7123ed8c72c4b7046", // warMD5 DateUtils.addMinutes( now, 2 ), // createDate "/some/dummy/path" ); commitDao.save( commit ); }
Example 26
Source Project: datawave Source File: ShardTableQueryMetricHandler.java License: Apache License 2.0 | 5 votes |
@Override public QueryMetricsSummaryResponse getTotalQueriesSummaryCounts(Date begin, Date end, DatawavePrincipal datawavePrincipal) { QueryMetricsSummaryResponse response = new QueryMetricsSummaryResponse(); try { enableLogs(false); // this method is open to any user datawavePrincipal = callerPrincipal; Collection<? extends Collection<String>> authorizations = datawavePrincipal.getAuthorizations(); QueryImpl query = new QueryImpl(); query.setBeginDate(begin); query.setEndDate(end); query.setQueryLogicName(QUERY_METRICS_LOGIC_NAME); query.setQuery("USER > 'A' && USER < 'ZZZZZZZ'"); query.setQueryName(QUERY_METRICS_LOGIC_NAME); query.setColumnVisibility(visibilityString); query.setQueryAuthorizations(AuthorizationsUtil.buildAuthorizationString(authorizations)); query.setExpirationDate(DateUtils.addDays(new Date(), 1)); query.setPagesize(1000); query.setUserDN(datawavePrincipal.getShortName()); query.setId(UUID.randomUUID()); query.setParameters(ImmutableMap.of(QueryOptions.INCLUDE_GROUPING_CONTEXT, "true")); List<QueryMetric> queryMetrics = getQueryMetrics(response, query, datawavePrincipal); response = processQueryMetricsSummary(queryMetrics); } catch (IOException e) { log.error(e.getMessage(), e); } finally { enableLogs(true); } return response; }
Example 27
Source Project: datawave Source File: ShardTableQueryMetricHandler.java License: Apache License 2.0 | 5 votes |
@Override public QueryMetricsSummaryHtmlResponse getTotalQueriesSummary(Date begin, Date end, DatawavePrincipal datawavePrincipal) { QueryMetricsSummaryHtmlResponse response = new QueryMetricsSummaryHtmlResponse(); try { enableLogs(false); enableLogs(true); // this method is open to any user datawavePrincipal = callerPrincipal; Collection<? extends Collection<String>> authorizations = datawavePrincipal.getAuthorizations(); QueryImpl query = new QueryImpl(); query.setBeginDate(begin); query.setEndDate(end); query.setQueryLogicName(QUERY_METRICS_LOGIC_NAME); query.setQuery("USER > 'A' && USER < 'ZZZZZZZ'"); query.setQueryName(QUERY_METRICS_LOGIC_NAME); query.setColumnVisibility(visibilityString); query.setQueryAuthorizations(AuthorizationsUtil.buildAuthorizationString(authorizations)); query.setExpirationDate(DateUtils.addDays(new Date(), 1)); query.setPagesize(1000); query.setUserDN(datawavePrincipal.getShortName()); query.setId(UUID.randomUUID()); query.setParameters(ImmutableMap.of(QueryOptions.INCLUDE_GROUPING_CONTEXT, "true")); List<QueryMetric> queryMetrics = getQueryMetrics(response, query, datawavePrincipal); response = processQueryMetricsHtmlSummary(queryMetrics); } catch (IOException e) { log.error(e.getMessage(), e); } finally { enableLogs(true); } return response; }
Example 28
Source Project: datawave Source File: DiscoveryLogic.java License: Apache License 2.0 | 5 votes |
public static BatchScanner configureBatchScannerForDiscovery(DiscoveryQueryConfiguration config, ScannerFactory scannerFactory, String tableName, Collection<Range> seekRanges, Set<Text> columnFamilies, Multimap<String,String> literals, Multimap<String,String> patterns, Multimap<String,LiteralRange<String>> ranges, boolean reverseIndex) throws TableNotFoundException { // if we have no ranges, then nothing to scan if (seekRanges.isEmpty()) { return null; } BatchScanner bs = scannerFactory.newScanner(tableName, config.getAuthorizations(), config.getNumQueryThreads(), config.getQuery()); bs.setRanges(seekRanges); if (!columnFamilies.isEmpty()) { for (Text family : columnFamilies) { bs.fetchColumnFamily(family); } } // The begin date from the query may be down to the second, for doing lookups in the index we want to use the day because // the times in the index table have been truncated to the day. Date begin = DateUtils.truncate(config.getBeginDate(), Calendar.DAY_OF_MONTH); // we don't need to bump up the end date any more because it's not apart of the range set on the scanner Date end = config.getEndDate(); LongRange dateRange = new LongRange(begin.getTime(), end.getTime()); ShardIndexQueryTableStaticMethods.configureGlobalIndexDateRangeFilter(config, bs, dateRange); ShardIndexQueryTableStaticMethods.configureGlobalIndexDataTypeFilter(config, bs, config.getDatatypeFilter()); configureIndexMatchingIterator(config, bs, literals, patterns, ranges, reverseIndex); IteratorSetting discoveryIteratorSetting = new IteratorSetting(config.getBaseIteratorPriority() + 50, DiscoveryIterator.class); discoveryIteratorSetting.addOption(REVERSE_INDEX, Boolean.toString(reverseIndex)); discoveryIteratorSetting.addOption(SEPARATE_COUNTS_BY_COLVIS, config.getSeparateCountsByColVis().toString()); if (config.getShowReferenceCount()) { discoveryIteratorSetting.addOption(SHOW_REFERENCE_COUNT, config.getShowReferenceCount().toString()); } bs.addScanIterator(discoveryIteratorSetting); return bs; }
Example 29
Source Project: smarthome Source File: DateTimeUtils.java License: Eclipse Public License 2.0 | 5 votes |
private static Calendar adjustTime(Calendar cal, int minutes) { if (minutes > 0) { Calendar cTime = Calendar.getInstance(); cTime = DateUtils.truncate(cal, Calendar.DAY_OF_MONTH); cTime.add(Calendar.MINUTE, minutes); return cTime; } return cal; }
Example 30
Source Project: datawave Source File: ShardIndexQueryTable.java License: Apache License 2.0 | 5 votes |
public static BatchScanner configureBatchScannerForDiscovery(ShardQueryConfiguration config, ScannerFactory scannerFactory, String tableName, Collection<Range> ranges, Collection<String> literals, Collection<String> patterns, boolean reverseIndex, boolean uniqueTermsOnly, Collection<String> expansionFields) throws TableNotFoundException { // if we have no ranges, then nothing to scan if (ranges.isEmpty()) { return null; } BatchScanner bs = scannerFactory.newScanner(tableName, config.getAuthorizations(), config.getNumQueryThreads(), config.getQuery()); bs.setRanges(ranges); // The begin date from the query may be down to the second, for doing lookups in the index we want to use the day because // the times in the index table have been truncated to the day. Date begin = DateUtils.truncate(config.getBeginDate(), Calendar.DAY_OF_MONTH); // we don't need to bump up the end date any more because it's not apart of the range set on the scanner Date end = config.getEndDate(); LongRange dateRange = new LongRange(begin.getTime(), end.getTime()); ShardIndexQueryTableStaticMethods.configureGlobalIndexDateRangeFilter(config, bs, dateRange); ShardIndexQueryTableStaticMethods.configureGlobalIndexDataTypeFilter(config, bs, config.getDatatypeFilter()); ShardIndexQueryTableStaticMethods.configureGlobalIndexTermMatchingIterator(config, bs, literals, patterns, reverseIndex, uniqueTermsOnly, expansionFields); bs.addScanIterator(new IteratorSetting(config.getBaseIteratorPriority() + 50, DiscoveryIterator.class)); return bs; }