Java Code Examples for com.google.protobuf.util.Durations#fromMillis()

The following examples show how to use com.google.protobuf.util.Durations#fromMillis() . 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 File: DefaultHealthService.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public Details getServerStatus() {
    RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
    Duration uptime = Durations.fromMillis(rb.getUptime());

    if (!leaderActivator.isLeader()) {
        return Details.newBuilder()
                .setStatus(NOT_SERVING)
                .setLeader(false)
                .setActive(false)
                .setUptime(uptime)
                .build();
    }

    boolean active = leaderActivator.isActivated();

    List<ServiceActivation> serviceActivations = activationLifecycle.getServiceActionTimesMs().stream()
            .sorted(Comparator.comparing(Pair::getRight))
            .map(pair -> ServiceActivation.newBuilder()
                    .setName(pair.getLeft())
                    .setActivationTime(Durations.fromMillis(pair.getRight()))
                    .build())
            .collect(Collectors.toList());

    Details.Builder details = Details.newBuilder()
            .setStatus(SERVING)
            .setCell(cellInfoResolver.getCellName())
            .setLeader(true)
            .setActive(active)
            .setUptime(uptime)
            .setElectionTimestamp(Timestamps.fromMillis(leaderActivator.getElectionTimestamp()))
            .setActivationTimestamp(Timestamps.fromMillis(leaderActivator.getActivationEndTimestamp()))
            .addAllServiceActivationTimes(serviceActivations);

    if (active) {
        details.setActivationTime(Durations.fromMillis(leaderActivator.getActivationTime()));
    }

    return details.build();
}
 
Example 2
Source File: RemoteSpawnRunnerTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void accountingAddsDurationsForStages() {
  SpawnMetrics.Builder builder =
      SpawnMetrics.Builder.forRemoteExec()
          .setQueueTime(Duration.ofSeconds(1))
          .setSetupTime(Duration.ofSeconds(2))
          .setExecutionWallTime(Duration.ofSeconds(2))
          .setProcessOutputsTime(Duration.ofSeconds(2));
  Timestamp queued = Timestamp.getDefaultInstance();
  com.google.protobuf.Duration oneSecond = Durations.fromMillis(1000);
  Timestamp workerStart = Timestamps.add(queued, oneSecond);
  Timestamp executionStart = Timestamps.add(workerStart, oneSecond);
  Timestamp executionCompleted = Timestamps.add(executionStart, oneSecond);
  Timestamp outputUploadStart = Timestamps.add(executionCompleted, oneSecond);
  Timestamp outputUploadComplete = Timestamps.add(outputUploadStart, oneSecond);
  ExecutedActionMetadata executedMetadata =
      ExecutedActionMetadata.newBuilder()
          .setWorker("test worker")
          .setQueuedTimestamp(queued)
          .setWorkerStartTimestamp(workerStart)
          .setExecutionStartTimestamp(executionStart)
          .setExecutionCompletedTimestamp(executionCompleted)
          .setOutputUploadStartTimestamp(outputUploadStart)
          .setOutputUploadCompletedTimestamp(outputUploadComplete)
          .build();
  RemoteSpawnRunner.spawnMetricsAccounting(builder, executedMetadata);
  SpawnMetrics spawnMetrics = builder.build();
  // remote queue time is accumulated
  assertThat(spawnMetrics.queueTime()).isEqualTo(Duration.ofSeconds(2));
  // setup time is substituted
  assertThat(spawnMetrics.setupTime()).isEqualTo(Duration.ofSeconds(1));
  // execution time is unspecified, assume substituted
  assertThat(spawnMetrics.executionWallTime()).isEqualTo(Duration.ofSeconds(1));
  // ProcessOutputs time is unspecified, assume substituted
  assertThat(spawnMetrics.processOutputsTime()).isEqualTo(Duration.ofSeconds(1));
}
 
Example 3
Source File: TimeUtil.java    From live-transcribe-speech-engine with Apache License 2.0 4 votes vote down vote up
public static com.google.protobuf.Duration convert(Duration d) {
  return Durations.fromMillis(d.getMillis());
}