/** * 按HH:mm:ss.SSS格式,格式化时间间隔 * * 单位为毫秒,必须大于0,可大于1天 * * @see DurationFormatUtils */ public static String formatDuration(long durationMillis) { return DurationFormatUtils.formatDurationHMS(durationMillis); }
/** * <p> * Gets a summary of the split time that the stopwatch recorded as a string. * </p> * * <p> * The format used is ISO 8601-like, <i>hours</i>:<i>minutes</i>:<i>seconds</i>.<i>milliseconds</i>. * </p> * * @return the split time as a String * @since 2.1 */ public String toSplitString() { return DurationFormatUtils.formatDurationHMS(getSplitTime()); }
/** * <p> * Gets a summary of the time that the stopwatch recorded as a string. * </p> * * <p> * The format used is ISO 8601-like, <i>hours</i>:<i>minutes</i>:<i>seconds</i>.<i>milliseconds</i>. * </p> * * @return the time as a String */ @Override public String toString() { return DurationFormatUtils.formatDurationHMS(getTime()); }
/** * 按HH:mm:ss.SSS格式,格式化时间间隔. * * endDate必须大于startDate,间隔可大于1天, * * @see DurationFormatUtils */ public static String formatDuration(@NotNull Date startDate, @NotNull Date endDate) { return DurationFormatUtils.formatDurationHMS(endDate.getTime() - startDate.getTime()); }
@Test(expected = IllegalArgumentException.class) public void testFormatNegativeDurationHMS() throws Exception { DurationFormatUtils.formatDurationHMS(-5000); }
channel.remoteAddress(), DurationFormatUtils.formatDurationHMS( maxLockDuration ) ) );
@Test public void testFormatDurationHMS() { long time = 0; assertEquals("00:00:00.000", DurationFormatUtils.formatDurationHMS(time)); time = 1; assertEquals("00:00:00.001", DurationFormatUtils.formatDurationHMS(time)); time = 15; assertEquals("00:00:00.015", DurationFormatUtils.formatDurationHMS(time)); time = 165; assertEquals("00:00:00.165", DurationFormatUtils.formatDurationHMS(time)); time = 1675; assertEquals("00:00:01.675", DurationFormatUtils.formatDurationHMS(time)); time = 13465; assertEquals("00:00:13.465", DurationFormatUtils.formatDurationHMS(time)); time = 72789; assertEquals("00:01:12.789", DurationFormatUtils.formatDurationHMS(time)); time = 12789 + 32 * 60000; assertEquals("00:32:12.789", DurationFormatUtils.formatDurationHMS(time)); time = 12789 + 62 * 60000; assertEquals("01:02:12.789", DurationFormatUtils.formatDurationHMS(time)); }
@Override public void sendTaskOverdueMail(final Optional<SingularityTask> task, final SingularityTaskId taskId, final SingularityRequest request, final long runTime, final long expectedRuntime) { final Builder<String, Object> templateProperties = ImmutableMap.<String, Object>builder(); templateProperties.put("runTime", DurationFormatUtils.formatDurationHMS(runTime)); templateProperties.put("expectedRunTime", DurationFormatUtils.formatDurationHMS(expectedRuntime)); templateProperties.put("warningThreshold", String.format("%s%%", configuration.getWarnIfScheduledJobIsRunningPastNextRunPct())); templateProperties.put("status", "is overdue to finish"); prepareTaskMail(task, taskId, request, SingularityEmailType.TASK_SCHEDULED_OVERDUE_TO_FINISH, templateProperties.build(), taskManager.getTaskHistoryUpdates(taskId), ExtendedTaskState.TASK_RUNNING, Collections.<SingularityTaskMetadata> emptyList()); }
private ScheduledFuture<?> enqueueHealthcheckWithDelay(final SingularityTask task, long delaySeconds, final boolean inStartup) { LOG.trace("Enqueuing a healthcheck for task {} with delay {}", task.getTaskId(), DurationFormatUtils.formatDurationHMS(TimeUnit.SECONDS.toMillis(delaySeconds))); return executorService.schedule(new Runnable() { @Override public void run() { try { asyncHealthcheck(task); } catch (Throwable t) { LOG.error("Uncaught throwable in async healthcheck", t); exceptionNotifier.notify(String.format("Uncaught throwable in async healthcheck (%s)", t.getMessage()), t, ImmutableMap.of("taskId", task.getTaskId().toString())); reEnqueueOrAbort(task, inStartup); } } }, delaySeconds, TimeUnit.SECONDS); }
private boolean isDeployOverdue(SingularityPendingDeploy pendingDeploy, Optional<SingularityDeploy> deploy) { if (!deploy.isPresent()) { LOG.warn("Can't determine if deploy {} is overdue because it was missing", pendingDeploy); return false; } if (pendingDeploy.getDeployProgress().isPresent() && pendingDeploy.getDeployProgress().get().isStepComplete()) { return false; } final long startTime = getStartTime(pendingDeploy); final long deployDuration = System.currentTimeMillis() - startTime; final long allowedTime = getAllowedMillis(deploy.get()); if (deployDuration > allowedTime) { LOG.warn("Deploy {} is overdue (duration: {}), allowed: {}", pendingDeploy, DurationFormatUtils.formatDurationHMS(deployDuration), DurationFormatUtils.formatDurationHMS(allowedTime)); return true; } else { LOG.trace("Deploy {} is not yet overdue (duration: {}), allowed: {}", pendingDeploy, DurationFormatUtils.formatDurationHMS(deployDuration), DurationFormatUtils.formatDurationHMS(allowedTime)); return false; } }
private void enqueueCheckWithDelay(final SingularityTask task, long delaySeconds, SingularityHealthchecker healthchecker) { LOG.trace("Enqueuing a new task check for task {} with delay {}", task.getTaskId(), DurationFormatUtils.formatDurationHMS(TimeUnit.SECONDS.toMillis(delaySeconds))); ScheduledFuture<?> future = executorService.schedule(getTaskCheck(task, healthchecker), delaySeconds, TimeUnit.SECONDS); taskIdToCheck.put(task.getTaskId().getId(), future); }
private void prepareRequestInCooldownMail(SingularityRequest request) { final List<SingularityEmailDestination> emailDestination = getDestination(request, SingularityEmailType.REQUEST_IN_COOLDOWN); if (emailDestination.isEmpty()) { LOG.debug("Not configured to send request cooldown mail for {}", request); return; } final Map<String, Object> templateProperties = Maps.newHashMap(); populateRequestEmailProperties(templateProperties, request, SingularityEmailType.REQUEST_IN_COOLDOWN); final String subject = String.format("Request %s has entered system cooldown — Singularity", request.getId()); templateProperties.put("numFailures", configuration.getCooldownAfterFailures()); templateProperties.put("cooldownDelayFormat", DurationFormatUtils.formatDurationHMS(TimeUnit.SECONDS.toMillis(configuration.getCooldownMinScheduleSeconds()))); templateProperties.put("cooldownExpiresFormat", DurationFormatUtils.formatDurationHMS(TimeUnit.MINUTES.toMillis(configuration.getCooldownExpiresAfterMinutes()))); final String body = Jade4J.render(requestInCooldownTemplate, templateProperties); queueMail(emailDestination, request, SingularityEmailType.REQUEST_IN_COOLDOWN, Optional.<String> absent(), subject, body); }
/** * Add needed information to the rate limit email Jade context. * @param request SingularityRequest that the rate limit email is about. * @param emailType what the email is about. * @return template properties to add to the Jade context. */ private Map<String, Object> getRateLimitTemplateProperties(SingularityRequest request, final SingularityEmailType emailType) { final Builder<String, Object> templateProperties = ImmutableMap.<String, Object>builder(); templateProperties.put("singularityRequestLink", mailTemplateHelpers.getSingularityRequestLink(request.getId())); templateProperties.put("rateLimitAfterNotifications", Integer.toString(smtpConfiguration.getRateLimitAfterNotifications())); templateProperties.put("rateLimitPeriodFormat", DurationFormatUtils.formatDurationHMS(smtpConfiguration.getRateLimitPeriodMillis())); templateProperties.put("rateLimitCooldownFormat", DurationFormatUtils.formatDurationHMS(smtpConfiguration.getRateLimitCooldownMillis())); templateProperties.put("emailType", emailType.name()); templateProperties.put("requestId", request.getId()); templateProperties.put("color", emailType.getColor()); return templateProperties.build(); }
private void checkTaskExecutionTimeLimit(long now, SingularityTaskId taskId, SingularityRequest request) { final long runtime = now - taskId.getStartedAt(); if (request.getTaskExecutionTimeLimitMillis().or(configuration.getTaskExecutionTimeLimitMillis()).isPresent() && runtime >= request.getTaskExecutionTimeLimitMillis().or(configuration.getTaskExecutionTimeLimitMillis()).get()) { taskManager.createTaskCleanup(new SingularityTaskCleanup( Optional.<String>absent(), TaskCleanupType.TASK_EXCEEDED_TIME_LIMIT, now, taskId, Optional.of(String.format("Task has run for %s, which exceeds the maximum execution time of %s", DurationFormatUtils.formatDurationHMS(runtime), DurationFormatUtils.formatDurationHMS(request.getTaskExecutionTimeLimitMillis().or(configuration.getTaskExecutionTimeLimitMillis()).get())) ), Optional.of(UUID.randomUUID().toString()), Optional.<SingularityTaskShellCommandRequestId>absent()) ); } }
private boolean shouldDefer() { /* If revocationTimeMs == 0, this is an immediate uncache request. * No clients were anchored at the time we made the request. */ if (revocationTimeMs == 0) { return false; } /* Let's check if any clients still have this block anchored. */ boolean anchored = !dataset.datanode.getShortCircuitRegistry(). processBlockMunlockRequest(key); if (!anchored) { LOG.debug("Uncaching {} now that it is no longer in use " + "by any clients.", key); return false; } long delta = revocationTimeMs - Time.monotonicNow(); if (delta < 0) { LOG.warn("Forcibly uncaching {} after {} " + "because client(s) {} refused to stop using it.", key, DurationFormatUtils.formatDurationHMS(revocationTimeMs), dataset.datanode.getShortCircuitRegistry().getClientNames(key)); return false; } LOG.info("Replica {} still can't be uncached because some " + "clients continue to use it. Will wait for {}", key, DurationFormatUtils.formatDurationHMS(delta)); return true; }
LOG.debug("{} is anchored, and can't be uncached now. Scheduling it " + "for uncaching in {} ", key, DurationFormatUtils.formatDurationHMS(revocationPollingMs));
/** * 按HH:mm:ss.SSS格式,格式化时间间隔 * * 单位为毫秒,必须大于0,可大于1天 */ public static String formatDuration(long durationMillis) { return DurationFormatUtils.formatDurationHMS(durationMillis); }
/** * 按HH:mm:ss.SSS格式,格式化时间间隔. endDate必须大于startDate,间隔可大于1天 * * @param startDate * 开始日期 * @param endDate * 结束日期 * @return */ public static String formatDuration(Date startDate, Date endDate) { return DurationFormatUtils.formatDurationHMS(endDate.getTime() - startDate.getTime()); }
private void execute() { long startTime = System.currentTimeMillis(); emailMessageSender.sendServiceAnnouncements(batchSize); long endTime = System.currentTimeMillis(); String timeTaken = DurationFormatUtils.formatDurationHMS(endTime - startTime); LOG.info("TimeTaken={} (H:m:s.S)", timeTaken); } }
@Override public void sendTaskOverdueMail(final Optional<SingularityTask> task, final SingularityTaskId taskId, final SingularityRequest request, final long runTime, final long expectedRuntime) { final Builder<String, Object> templateProperties = ImmutableMap.<String, Object>builder(); templateProperties.put("runTime", DurationFormatUtils.formatDurationHMS(runTime)); templateProperties.put("expectedRunTime", DurationFormatUtils.formatDurationHMS(expectedRuntime)); templateProperties.put("warningThreshold", String.format("%s%%", configuration.getWarnIfScheduledJobIsRunningPastNextRunPct())); templateProperties.put("status", "is overdue to finish"); prepareTaskMail(task, taskId, request, SingularityEmailType.TASK_SCHEDULED_OVERDUE_TO_FINISH, templateProperties.build(), taskManager.getTaskHistoryUpdates(taskId), ExtendedTaskState.TASK_RUNNING, Collections.<SingularityTaskMetadata> emptyList()); }