refactor(core): consolidate epoch-millisecond conversions (#7161)

This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-10-31 21:59:50 -04:00
1 parent 94d7b2c031
commit d4f87659a7
28 files changed
+107 -91

No files matched your search

@@ -2,13 +2,17 @@ package io.github.hectorvent.floci.core.common;
import java.time.Instant;
/** Converts an Instant to millisecond-precision epoch seconds for AWS JSON timestamps. */
/** Converts Instants and epoch milliseconds to millisecond-precision epoch seconds for AWS JSON timestamps. */
public final class EpochSeconds {
private EpochSeconds() {
}
public static double fromInstant(Instant instant) {
return instant.toEpochMilli() / 1000.0;
return fromMillis(instant.toEpochMilli());
}
public static double fromMillis(long epochMillis) {
return epochMillis / 1000.0;
}
}
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.JsonErrorResponseUtils;
import io.github.hectorvent.floci.services.apigatewayv2.model.*;
import jakarta.enterprise.context.ApplicationScoped;
@@ -515,7 +516,7 @@ public class ApiGatewayV2JsonHandler {
node.put("Name", api.getName());
node.put("ProtocolType", api.getProtocolType());
node.put("ApiEndpoint", api.getApiEndpoint());
node.put("CreatedDate", api.getCreatedDate() / 1000.0);
node.put("CreatedDate", EpochSeconds.fromMillis(api.getCreatedDate()));
node.put("DisableExecuteApiEndpoint", api.isDisableExecuteApiEndpoint());
if (api.getRouteSelectionExpression() != null) {
node.put("RouteSelectionExpression", api.getRouteSelectionExpression());
@@ -663,8 +664,8 @@ public class ApiGatewayV2JsonHandler {
ObjectNode node = objectMapper.createObjectNode();
node.put("StageName", s.getStageName());
node.put("AutoDeploy", s.isAutoDeploy());
node.put("CreatedDate", s.getCreatedDate() / 1000.0);
node.put("LastUpdatedDate", s.getLastUpdatedDate() / 1000.0);
node.put("CreatedDate", EpochSeconds.fromMillis(s.getCreatedDate()));
node.put("LastUpdatedDate", EpochSeconds.fromMillis(s.getLastUpdatedDate()));
if (s.getDeploymentId() != null) node.put("DeploymentId", s.getDeploymentId());
if (s.getStageVariables() != null) {
ObjectNode stageVariables = node.putObject("StageVariables");
@@ -720,7 +721,7 @@ public class ApiGatewayV2JsonHandler {
ObjectNode node = objectMapper.createObjectNode();
node.put("DeploymentId", d.getDeploymentId());
node.put("DeploymentStatus", d.getDeploymentStatus());
node.put("CreatedDate", d.getCreatedDate() / 1000.0);
node.put("CreatedDate", EpochSeconds.fromMillis(d.getCreatedDate()));
if (d.getDescription() != null) node.put("Description", d.getDescription());
return node;
}
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.services.cloudtrail.model.AdvancedEventSelector;
import io.github.hectorvent.floci.services.cloudtrail.model.DataResource;
import io.github.hectorvent.floci.services.cloudtrail.model.EventSelector;
@@ -226,16 +227,16 @@ public class CloudTrailJsonHandler {
ObjectNode resp = mapper.createObjectNode();
resp.put("IsLogging", status.logging());
if (status.startLoggingTime() != null) {
resp.put("StartLoggingTime", status.startLoggingTime() / 1000.0);
resp.put("StartLoggingTime", EpochSeconds.fromMillis(status.startLoggingTime()));
}
if (status.latestDeliveryTime() != null) {
resp.put("LatestDeliveryTime", status.latestDeliveryTime() / 1000.0);
resp.put("LatestDeliveryTime", EpochSeconds.fromMillis(status.latestDeliveryTime()));
}
if (status.latestDeliveryError() != null) {
resp.put("LatestDeliveryError", status.latestDeliveryError());
}
if (status.stopLoggingTime() != null) {
resp.put("StopLoggingTime", status.stopLoggingTime() / 1000.0);
resp.put("StopLoggingTime", EpochSeconds.fromMillis(status.stopLoggingTime()));
}
return Response.ok(resp).build();
}
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.services.cloudwatch.dashboards.CloudWatchDashboardsService;
@@ -457,7 +458,7 @@ public class CloudWatchMetricsJsonHandler {
.put("HistoryData", item.historyData())
.put("HistoryItemType", item.historyItemType())
.put("HistorySummary", item.historySummary())
.put("Timestamp", item.timestamp() / 1000.0);
.put("Timestamp", EpochSeconds.fromMillis(item.timestamp()));
}
if (page.nextToken() != null) {
response.put("NextToken", page.nextToken());
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.ContainerTeardown;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.FileTrees;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
@@ -357,13 +358,13 @@ public class CodeBuildRunner implements ContainerTeardown {
build.setCurrentPhase("COMPLETED");
completePhase(build, "COMPLETED", buildFailed ? "FAILED" : "SUCCEEDED");
build.setEndTime(System.currentTimeMillis() / 1000.0);
build.setEndTime(EpochSeconds.fromMillis(System.currentTimeMillis()));
build.setBuildComplete(true);
build.setBuildStatus(buildFailed ? "FAILED" : "SUCCEEDED");
} catch (Exception e) {
LOG.error("Unexpected error in build " + build.getId(), e);
build.setEndTime(System.currentTimeMillis() / 1000.0);
build.setEndTime(EpochSeconds.fromMillis(System.currentTimeMillis()));
build.setBuildComplete(true);
build.setBuildStatus("FAULT");
build.setCurrentPhase("COMPLETED");
@@ -376,8 +377,8 @@ public class CodeBuildRunner implements ContainerTeardown {
BuildPhase completedPhase = new BuildPhase();
completedPhase.setPhaseType("COMPLETED");
completedPhase.setPhaseStatus("FAILED");
completedPhase.setStartTime(System.currentTimeMillis() / 1000.0);
completedPhase.setEndTime(System.currentTimeMillis() / 1000.0);
completedPhase.setStartTime(EpochSeconds.fromMillis(System.currentTimeMillis()));
completedPhase.setEndTime(EpochSeconds.fromMillis(System.currentTimeMillis()));
completedPhase.setDurationInSeconds(0L);
if (e.getMessage() != null) {
completedPhase.setContexts(List.of(Map.of(
@@ -803,14 +804,14 @@ public class CodeBuildRunner implements ContainerTeardown {
BuildPhase phase = new BuildPhase();
phase.setPhaseType(phaseType);
phase.setPhaseStatus("IN_PROGRESS");
phase.setStartTime(System.currentTimeMillis() / 1000.0);
phase.setStartTime(EpochSeconds.fromMillis(System.currentTimeMillis()));
build.getPhases().add(phase);
build.setCurrentPhase(phaseType);
}
private void completePhase(Build build, String phaseType, String status) {
findPhase(build, phaseType).ifPresent(p -> {
double end = System.currentTimeMillis() / 1000.0;
double end = EpochSeconds.fromMillis(System.currentTimeMillis());
p.setPhaseStatus(status);
p.setEndTime(end);
p.setDurationInSeconds(Math.round(end - p.getStartTime()));
@@ -819,7 +820,7 @@ public class CodeBuildRunner implements ContainerTeardown {
private void completePhaseWithError(Build build, String phaseType, String status, String message) {
findPhase(build, phaseType).ifPresent(p -> {
double end = System.currentTimeMillis() / 1000.0;
double end = EpochSeconds.fromMillis(System.currentTimeMillis());
p.setPhaseStatus(status);
p.setEndTime(end);
p.setDurationInSeconds(Math.round(end - p.getStartTime()));
@@ -834,7 +835,7 @@ public class CodeBuildRunner implements ContainerTeardown {
BuildPhase phase = new BuildPhase();
phase.setPhaseType(phaseType);
phase.setPhaseStatus("SUCCEEDED");
double now = System.currentTimeMillis() / 1000.0;
double now = EpochSeconds.fromMillis(System.currentTimeMillis());
phase.setStartTime(now);
phase.setEndTime(now);
phase.setDurationInSeconds(0L);
@@ -842,14 +843,14 @@ public class CodeBuildRunner implements ContainerTeardown {
}
private void finishStopped(Build build) {
build.setEndTime(System.currentTimeMillis() / 1000.0);
build.setEndTime(EpochSeconds.fromMillis(System.currentTimeMillis()));
build.setBuildComplete(true);
build.setBuildStatus("STOPPED");
build.setCurrentPhase("COMPLETED");
}
private void finishFailed(Build build) {
build.setEndTime(System.currentTimeMillis() / 1000.0);
build.setEndTime(EpochSeconds.fromMillis(System.currentTimeMillis()));
build.setBuildComplete(true);
build.setBuildStatus("FAILED");
build.setCurrentPhase("COMPLETED");
@@ -15,6 +15,7 @@ import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.Base64Url;
import io.github.hectorvent.floci.core.common.CloudFrontEdgeDomain;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.RegionResolver;
@@ -63,6 +64,7 @@ import org.jspecify.annotations.Nullable;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
@@ -3958,7 +3960,7 @@ public class CognitoService implements ResourceProvider {
description.put("AuthenticatorAttachment", credential.getAuthenticatorAttachment());
}
description.put("AuthenticatorTransports", credential.getTransports());
description.put("CreatedAt", credential.getCreatedAtMillis() / 1000.0);
description.put("CreatedAt", EpochSeconds.fromMillis(credential.getCreatedAtMillis()));
description.put("CredentialId", credential.getCredentialId());
description.put("FriendlyCredentialName", credential.getFriendlyCredentialName());
description.put("RelyingPartyId", credential.getRelyingPartyId());
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.eks;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
@@ -81,7 +82,7 @@ public class EksAccessEntryService {
throw new AwsException("InvalidRequestException",
"Access policies can only be associated with STANDARD access entries", 400);
}
double now = clock.millis() / 1000.0;
double now = EpochSeconds.fromMillis(clock.millis());
double associatedAt = stored.accessPolicies().stream()
.filter(existing -> existing.policyArn().equals(request.policyArn()))
.mapToDouble(AssociatedAccessPolicy::associatedAt).findFirst().orElse(now);
@@ -221,7 +222,7 @@ public class EksAccessEntryService {
if (entries.get(key).isPresent()) {
throw new AwsException("ResourceInUseException", "Access entry already exists", 409);
}
double now = clock.millis() / 1000.0;
double now = EpochSeconds.fromMillis(clock.millis());
String entryArn = new AwsArnUtils.Arn(clusterArn.partition(), "eks", clusterArn.region(), clusterArn.accountId(),
"access-entry/" + cluster.getName() + "/" + (role ? "role" : "user") + "/" + arn.accountId() + "/" + name
+ "/" + UUID.randomUUID()).toString();
@@ -1172,17 +1172,13 @@ public class GlueJsonHandler {
Map<String, Object> item = new LinkedHashMap<>();
item.put("Name", ruleset.getName());
putIfNotNull(item, "Description", ruleset.getDescription());
item.put("CreatedOn", epochSeconds(ruleset.getCreatedOn()));
item.put("LastModifiedOn", epochSeconds(ruleset.getLastModifiedOn()));
item.put("CreatedOn", EpochSeconds.fromInstant(ruleset.getCreatedOn()));
item.put("LastModifiedOn", EpochSeconds.fromInstant(ruleset.getLastModifiedOn()));
putIfNotNull(item, "TargetTable", ruleset.getTargetTable());
putIfNotNull(item, "RuleCount", GlueService.dataQualityRuleCount(ruleset.getRuleset()));
return item;
}
private static double epochSeconds(Instant instant) {
return EpochSeconds.fromInstant(instant);
}
private static String iso(Instant instant) {
return instant != null ? instant.toString() : null;
}
@@ -609,9 +609,9 @@ public class GlueTriggerService {
if (name.equals(crawl.crawlerName())) {
Map<String, Object> entry = new LinkedHashMap<>();
entry.put("State", crawl.state());
entry.put("StartedOn", epochSeconds(crawl.startedOn()));
entry.put("StartedOn", EpochSeconds.fromInstant(crawl.startedOn()));
if (crawl.completedOn() != null) {
entry.put("CompletedOn", epochSeconds(crawl.completedOn()));
entry.put("CompletedOn", EpochSeconds.fromInstant(crawl.completedOn()));
}
entry.put("LogGroup", "/aws-glue/crawlers");
entry.put("LogStream", name);
@@ -673,10 +673,6 @@ public class GlueTriggerService {
.getBytes(StandardCharsets.UTF_8)).toString().replace("-", "");
}
private static double epochSeconds(Instant instant) {
return EpochSeconds.fromInstant(instant);
}
/**
* Processes the completions this trigger has not seen yet, in finishing order, and returns the
* completions that fire it. ANY fires on each completion that matches one of its conditions; AND
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.services.lambda.model.EventSourceMapping;
@@ -391,7 +392,7 @@ public class LambdaController {
node.put("MaximumBatchingWindowInSeconds", esm.getMaximumBatchingWindowInSeconds());
}
node.put("State", esm.getState());
node.put("LastModified", (double) esm.getLastModified() / 1000.0);
node.put("LastModified", EpochSeconds.fromMillis(esm.getLastModified()));
// Omitted rather than nulled when unset, so a mapping created without a starting position
// reads back the way AWS returns it - and so Terraform sees the configured value on refresh
// instead of treating the field as unset and forcing a replacement on every plan.
@@ -399,7 +400,7 @@ public class LambdaController {
node.put("StartingPosition", esm.getStartingPosition());
}
if (esm.getStartingPositionTimestamp() != null) {
node.put("StartingPositionTimestamp", (double) esm.getStartingPositionTimestamp() / 1000.0);
node.put("StartingPositionTimestamp", EpochSeconds.fromMillis(esm.getStartingPositionTimestamp()));
}
ArrayNode responseTypes = node.putArray("FunctionResponseTypes");
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
@@ -132,7 +133,7 @@ public class DurableExecutionController {
}
DurableExecution execution = service.stop(ownedArn(headers, arn), error);
ObjectNode response = objectMapper.createObjectNode();
response.put("StopTimestamp", execution.getEndTimestamp() / 1000.0);
response.put("StopTimestamp", EpochSeconds.fromMillis(execution.getEndTimestamp()));
return Response.ok(response).build();
}
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.lambda.durable.model.DurableErrorObject;
import io.github.hectorvent.floci.services.lambda.durable.model.DurableExecution;
@@ -373,7 +374,7 @@ public final class DurableWire {
if (asMillis) {
node.put(member, millis);
} else {
node.put(member, millis / 1000.0);
node.put(member, EpochSeconds.fromMillis(millis));
}
}
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
@@ -30,7 +31,7 @@ public class FunctionEventInvokeConfig {
@JsonProperty("LastModified")
public double getLastModifiedSeconds() {
return lastModifiedMillis / 1000.0;
return EpochSeconds.fromMillis(lastModifiedMillis);
}
// Deserialization counterpart so the timestamp survives a persisted-state reload;
@@ -378,7 +378,7 @@ public class LightsailService implements ResourceProvider {
ObjectNode response = mapper.createObjectNode();
response.put("publicKeyBase64", publicKeyBase64(name));
response.put("privateKeyBase64", privateKeyBase64(name));
response.put("createdAt", epochSeconds(Instant.now()));
response.put("createdAt", EpochSeconds.fromInstant(Instant.now()));
return response;
}
@@ -562,7 +562,7 @@ public class LightsailService implements ResourceProvider {
resource.put("name", name);
resource.put("arn", arn(region, resourceType, name));
resource.put("supportCode", region + "/" + name);
resource.put("createdAt", epochSeconds(now));
resource.put("createdAt", EpochSeconds.fromInstant(now));
resource.set("location", location(region, availabilityZone));
resource.put("resourceType", resourceType);
return resource;
@@ -575,13 +575,13 @@ public class LightsailService implements ResourceProvider {
operation.put("id", id);
operation.put("resourceName", resourceName);
operation.put("resourceType", resourceType);
operation.put("createdAt", epochSeconds(now));
operation.put("createdAt", EpochSeconds.fromInstant(now));
operation.set("location", location(region, region + "a"));
operation.put("isTerminal", true);
operation.put("operationDetails", operationType + " completed locally");
operation.put("operationType", operationType);
operation.put("status", "Succeeded");
operation.put("statusChangedAt", epochSeconds(now));
operation.put("statusChangedAt", EpochSeconds.fromInstant(now));
operationStore.put(operationKey(region, id), operation);
return operation;
}
@@ -879,10 +879,6 @@ public class LightsailService implements ResourceProvider {
return region + ":" + operationId;
}
private static double epochSeconds(Instant instant) {
return EpochSeconds.fromInstant(instant);
}
private static String privateIpFor(String name) {
int value = Math.floorMod(name.hashCode(), 200) + 20;
return "10.0.0." + value;
@@ -704,7 +704,7 @@ public class RedshiftDataService implements Resettable {
} else if (stored.workgroupName == null) {
response.putNull("ClusterIdentifier");
}
response.put("CreatedAt", epochSeconds(stored.createdAt));
response.put("CreatedAt", EpochSeconds.fromInstant(stored.createdAt));
response.put("Database", stored.database);
if (stored.dbUser != null) {
response.put("DbUser", stored.dbUser);
@@ -730,8 +730,8 @@ public class RedshiftDataService implements Resettable {
}
response.put("Id", stored.id);
response.put("Status", stored.status.name());
response.put("CreatedAt", epochSeconds(stored.createdAt));
response.put("UpdatedAt", epochSeconds(stored.updatedAt));
response.put("CreatedAt", EpochSeconds.fromInstant(stored.createdAt));
response.put("UpdatedAt", EpochSeconds.fromInstant(stored.updatedAt));
response.put("Duration", stored.durationNanos);
if (stored.error != null) {
response.put("Error", stored.error);
@@ -1074,8 +1074,8 @@ public class RedshiftDataService implements Resettable {
queryStrings.add(sql);
}
node.put("Status", s.status.name());
node.put("CreatedAt", epochSeconds(s.createdAt));
node.put("UpdatedAt", epochSeconds(s.updatedAt));
node.put("CreatedAt", EpochSeconds.fromInstant(s.createdAt));
node.put("UpdatedAt", EpochSeconds.fromInstant(s.updatedAt));
if (s.statementName != null) {
node.put("StatementName", s.statementName);
}
@@ -1344,10 +1344,6 @@ public class RedshiftDataService implements Resettable {
return offset;
}
static double epochSeconds(Instant instant) {
return EpochSeconds.fromInstant(instant);
}
private String clusterIdentifierOrNull(JsonNode request) {
return textOrNull(request, "ClusterIdentifier");
}
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.services.redshiftdata.RedshiftDataSessions.Scope;
@@ -17,8 +18,6 @@ import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import static io.github.hectorvent.floci.services.redshiftdata.RedshiftDataService.epochSeconds;
final class RedshiftDataSessionListing {
private static final Pattern CLUSTER = Pattern.compile("[a-z][a-z0-9]*(-[a-z0-9]+)*");
private static final Pattern WORKGROUP = Pattern.compile("[a-z0-9-]{3,63}");
@@ -94,9 +93,9 @@ final class RedshiftDataSessionListing {
ObjectNode node = result.addObject();
node.put("SessionId", info.id());
node.put("Status", info.status());
node.put("CreatedAt", epochSeconds(info.createdAt()));
node.put("UpdatedAt", epochSeconds(info.updatedAt()));
node.put("SessionTtl", epochSeconds(info.ttl()));
node.put("CreatedAt", EpochSeconds.fromInstant(info.createdAt()));
node.put("UpdatedAt", EpochSeconds.fromInstant(info.updatedAt()));
node.put("SessionTtl", EpochSeconds.fromInstant(info.ttl()));
node.put("SessionAliveSeconds", info.keepAlive());
node.put("Database", info.database());
node.put("DbUser", info.user());
@@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Base64Url;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
@@ -567,7 +568,7 @@ public class SageMakerService {
}
static double epoch(long millis) {
return millis / 1000.0;
return EpochSeconds.fromMillis(millis);
}
static AwsException validation(String message) {
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.services.ssoadmin.model.ApplicationAccessScope;
import io.github.hectorvent.floci.services.ssoadmin.model.ApplicationAssignment;
@@ -138,7 +139,7 @@ public class SsoAdminJsonHandler {
node.put("Name", updateState.name());
}
node.put("OwnerAccountId", instance.ownerAccountId());
node.put("CreatedDate", instance.createdDateEpochMillis() / 1000.0d);
node.put("CreatedDate", EpochSeconds.fromMillis(instance.createdDateEpochMillis()));
node.put("PrimaryRegion", instance.primaryRegion());
ArrayNode regionNodes = node.putArray("Regions");
service.listRegionsForInstance(instance).forEach(region -> {
@@ -170,7 +171,7 @@ public class SsoAdminJsonHandler {
SsoInstance instance = service.describeInstance(request);
InstanceUpdateState updateState = service.instanceUpdateState(instance);
ObjectNode response = mapper.createObjectNode();
response.put("CreatedDate", instance.createdDateEpochMillis() / 1000.0d);
response.put("CreatedDate", EpochSeconds.fromMillis(instance.createdDateEpochMillis()));
response.put("IdentityStoreId", instance.identityStoreId());
response.put("InstanceArn", instance.instanceArn());
if (updateState.name() != null) {
@@ -558,7 +559,7 @@ public class SsoAdminJsonHandler {
response.put("ApplicationAccount", application.applicationAccount());
response.put("ApplicationArn", application.applicationArn());
response.put("ApplicationProviderArn", application.applicationProviderArn());
response.put("CreatedDate", application.createdDateEpochMillis() / 1000.0d);
response.put("CreatedDate", EpochSeconds.fromMillis(application.createdDateEpochMillis()));
response.put("CreatedFrom", application.createdFrom());
if (application.description() != null) {
response.put("Description", application.description());
@@ -753,7 +754,7 @@ public class SsoAdminJsonHandler {
ObjectNode status = response.putObject("PermissionSetProvisioningStatus");
status.put("RequestId", operation.requestId());
status.put("Status", operation.status());
status.put("CreatedDate", operation.createdDateEpochMillis() / 1000.0d);
status.put("CreatedDate", EpochSeconds.fromMillis(operation.createdDateEpochMillis()));
if (operation.accountId() != null) {
status.put("AccountId", operation.accountId());
}
@@ -772,7 +773,7 @@ public class SsoAdminJsonHandler {
ObjectNode status = response.putObject("PermissionSetProvisioningStatus");
status.put("RequestId", operation.requestId());
status.put("Status", operation.status());
status.put("CreatedDate", operation.createdDateEpochMillis() / 1000.0d);
status.put("CreatedDate", EpochSeconds.fromMillis(operation.createdDateEpochMillis()));
if (operation.accountId() != null) {
status.put("AccountId", operation.accountId());
}
@@ -793,7 +794,7 @@ public class SsoAdminJsonHandler {
ObjectNode status = statuses.addObject();
status.put("RequestId", operation.requestId());
status.put("Status", operation.status());
status.put("CreatedDate", operation.createdDateEpochMillis() / 1000.0d);
status.put("CreatedDate", EpochSeconds.fromMillis(operation.createdDateEpochMillis()));
}
if (page.nextToken() != null) {
response.put("NextToken", page.nextToken());
@@ -836,7 +837,7 @@ public class SsoAdminJsonHandler {
ObjectNode status = response.putObject("AccountAssignmentDeletionStatus");
status.put("RequestId", operation.requestId());
status.put("Status", operation.status());
status.put("CreatedDate", operation.createdDateEpochMillis() / 1000.0d);
status.put("CreatedDate", EpochSeconds.fromMillis(operation.createdDateEpochMillis()));
status.put("TargetId", operation.accountId());
status.put("TargetType", "AWS_ACCOUNT");
status.put("PermissionSetArn", operation.permissionSetArn());
@@ -865,7 +866,7 @@ public class SsoAdminJsonHandler {
ObjectNode status = statuses.addObject();
status.put("RequestId", operation.requestId());
status.put("Status", operation.status());
status.put("CreatedDate", operation.createdDateEpochMillis() / 1000.0d);
status.put("CreatedDate", EpochSeconds.fromMillis(operation.createdDateEpochMillis()));
}
if (page.nextToken() != null) {
response.put("NextToken", page.nextToken());
@@ -881,7 +882,7 @@ public class SsoAdminJsonHandler {
ObjectNode status = response.putObject("AccountAssignmentDeletionStatus");
status.put("RequestId", operation.requestId());
status.put("Status", operation.status());
status.put("CreatedDate", operation.createdDateEpochMillis() / 1000.0d);
status.put("CreatedDate", EpochSeconds.fromMillis(operation.createdDateEpochMillis()));
status.put("TargetId", operation.accountId());
status.put("TargetType", "AWS_ACCOUNT");
status.put("PermissionSetArn", operation.permissionSetArn());
@@ -901,7 +902,7 @@ public class SsoAdminJsonHandler {
ObjectNode status = statuses.addObject();
status.put("RequestId", operation.requestId());
status.put("Status", operation.status());
status.put("CreatedDate", operation.createdDateEpochMillis() / 1000.0d);
status.put("CreatedDate", EpochSeconds.fromMillis(operation.createdDateEpochMillis()));
});
if (page.nextToken() != null) {
response.put("NextToken", page.nextToken());
@@ -923,7 +924,7 @@ public class SsoAdminJsonHandler {
private ObjectNode assignmentOperationNode(AssignmentOperation op) {
ObjectNode node = mapper.createObjectNode();
node.put("RequestId", op.requestId()); node.put("Status", op.status());
node.put("CreatedDate", op.createdDateEpochMillis() / 1000.0d);
node.put("CreatedDate", EpochSeconds.fromMillis(op.createdDateEpochMillis()));
node.put("TargetId", op.accountId()); node.put("TargetType", "AWS_ACCOUNT");
node.put("PermissionSetArn", op.permissionSetArn()); node.put("PrincipalId", op.principalId());
node.put("PrincipalType", op.principalType());
@@ -22,6 +22,7 @@ import io.github.hectorvent.floci.core.common.AwsPartition;
import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.CsvParser;
import io.github.hectorvent.floci.core.common.CustomResourceLiveness;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.RequestContext;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.core.common.ServiceRegistry;
@@ -560,7 +561,7 @@ public class AslExecutor {
if (hasEnded(exec)) {
return;
}
exec.setStopDate(System.currentTimeMillis() / 1000.0);
exec.setStopDate(EpochSeconds.fromMillis(System.currentTimeMillis()));
exec.setStatus("TIMED_OUT");
}
onUpdate.accept(exec, history);
@@ -3505,7 +3506,7 @@ public class AslExecutor {
MapRun mapRun = new MapRun();
mapRun.setMapRunArn(identity.arn());
mapRun.setExecutionArn(context.path("Execution").path("Id").asText(null));
mapRun.setStartDate(System.currentTimeMillis() / 1000.0);
mapRun.setStartDate(EpochSeconds.fromMillis(System.currentTimeMillis()));
mapRun.setItemCount(itemCount);
mapRun.setExecutionCount(executionCount);
// ASL spells an unbounded Map as MaxConcurrency 0, or by omitting it; DescribeMapRun
@@ -3518,7 +3519,7 @@ public class AslExecutor {
/** Kept for every Distributed Map, so the mapRunArn in the history resolves through DescribeMapRun. */
private void recordMapRun(MapRun mapRun, String status, int succeededItems, int failedItems,
int succeededExecutions, int failedExecutions) {
mapRun.setStopDate(System.currentTimeMillis() / 1000.0);
mapRun.setStopDate(EpochSeconds.fromMillis(System.currentTimeMillis()));
mapRun.setStatus(status);
mapRun.setSucceededCount(succeededItems);
mapRun.setFailedCount(failedItems);
@@ -6014,7 +6015,7 @@ public class AslExecutor {
}
exec.setError(error);
exec.setCause(cause);
exec.setStopDate(System.currentTimeMillis() / 1000.0);
exec.setStopDate(EpochSeconds.fromMillis(System.currentTimeMillis()));
exec.setStatus("FAILED");
}
chain.end("ExecutionFailed", failureDetails(error, cause));
@@ -6054,7 +6055,7 @@ public class AslExecutor {
if (hasEnded(exec)) {
return;
}
exec.setStopDate(System.currentTimeMillis() / 1000.0);
exec.setStopDate(EpochSeconds.fromMillis(System.currentTimeMillis()));
exec.setStatus("TIMED_OUT");
}
}
@@ -6074,7 +6075,7 @@ public class AslExecutor {
return;
}
exec.setOutput(output.toString());
exec.setStopDate(System.currentTimeMillis() / 1000.0);
exec.setStopDate(EpochSeconds.fromMillis(System.currentTimeMillis()));
exec.setStatus("SUCCEEDED");
}
chain.end("ExecutionSucceeded",
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.SignedMarkers;
@@ -518,7 +519,7 @@ public class StepFunctionsJsonHandler {
request.path("error").asText(null)
);
ObjectNode response = objectMapper.createObjectNode();
response.put("stopDate", System.currentTimeMillis() / 1000.0);
response.put("stopDate", EpochSeconds.fromMillis(System.currentTimeMillis()));
return Response.ok(response).build();
}
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Base64Url;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.RegionResolver;
@@ -485,7 +486,7 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
}
updated.setRevisionId(UUID.randomUUID().toString());
updated.setUpdateDate(System.currentTimeMillis() / 1000.0);
updated.setUpdateDate(EpochSeconds.fromMillis(System.currentTimeMillis()));
StateMachineVersion version = request.publish()
? addVersion(updated, request.versionDescription())
: null;
@@ -729,7 +730,7 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
if (routingConfiguration != null) {
updated.setRoutingConfiguration(copyRoutingConfiguration(routingConfiguration));
}
updated.setUpdateDate(System.currentTimeMillis() / 1000.0);
updated.setUpdateDate(EpochSeconds.fromMillis(System.currentTimeMillis()));
stateMachineAliasStore.put(aliasArn, updated);
return copyAlias(updated);
}
@@ -1135,7 +1136,7 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
}
exec.setError(error);
exec.setCause(cause);
exec.setStopDate(System.currentTimeMillis() / 1000.0);
exec.setStopDate(EpochSeconds.fromMillis(System.currentTimeMillis()));
exec.setStatus("ABORTED");
}
@@ -1515,7 +1516,7 @@ public class StepFunctionsService implements Resettable, ResourceProvider {
StateMachineVersion version = new StateMachineVersion(
stateMachine.getStateMachineArn() + ":" + next,
next,
System.currentTimeMillis() / 1000.0);
EpochSeconds.fromMillis(System.currentTimeMillis()));
version.setDescription(description);
version.setName(stateMachine.getName());
version.setDefinition(stateMachine.getDefinition());
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.stepfunctions.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.HashMap;
@@ -15,7 +16,7 @@ public class Activity {
private Map<String, String> tags = new HashMap<>();
public Activity() {
this.creationDate = System.currentTimeMillis() / 1000.0;
this.creationDate = EpochSeconds.fromMillis(System.currentTimeMillis());
}
public String getActivityArn() { return activityArn; }
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.stepfunctions.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.ArrayList;
@@ -29,7 +30,7 @@ public class Execution {
private transient Set<ExecutionStatusSubscription> statusSubscriptions;
public Execution() {
this.startDate = System.currentTimeMillis() / 1000.0;
this.startDate = EpochSeconds.fromMillis(System.currentTimeMillis());
}
public String getExecutionArn() { return executionArn; }
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.stepfunctions.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.Map;
@@ -15,7 +16,7 @@ public class HistoryEvent {
private Map<String, Object> details;
public HistoryEvent() {
this.timestamp = System.currentTimeMillis() / 1000.0;
this.timestamp = EpochSeconds.fromMillis(System.currentTimeMillis());
}
public long getId() { return id; }
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.stepfunctions.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.ArrayList;
@@ -32,7 +33,7 @@ public class StateMachine {
private List<StateMachineVersion> versions = new ArrayList<>();
public StateMachine() {
this.creationDate = System.currentTimeMillis() / 1000.0;
this.creationDate = EpochSeconds.fromMillis(System.currentTimeMillis());
}
public String getStateMachineArn() { return stateMachineArn; }
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.stepfunctions.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.ArrayList;
@@ -19,7 +20,7 @@ public class StateMachineAlias {
private double updateDate;
public StateMachineAlias() {
creationDate = System.currentTimeMillis() / 1000.0;
creationDate = EpochSeconds.fromMillis(System.currentTimeMillis());
updateDate = creationDate;
}
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.swf;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.EpochSeconds;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.Resettable;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
@@ -1977,7 +1978,7 @@ public class SwfService implements Resettable {
}
private double now() {
return clock.millis() / 1000.0;
return EpochSeconds.fromMillis(clock.millis());
}
/** SWF task tokens are opaque; a random base64 blob matches how SDKs treat them. */