diff --git a/src/main/java/io/github/hectorvent/floci/core/common/EpochSeconds.java b/src/main/java/io/github/hectorvent/floci/core/common/EpochSeconds.java index 7092dee083..eb7dfd8168 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/EpochSeconds.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/EpochSeconds.java @@ -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; } } diff --git a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2JsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2JsonHandler.java index 04a545d05f..29969c9986 100644 --- a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2JsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2JsonHandler.java @@ -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; } diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailJsonHandler.java index 08ffda9b6f..bc050e249a 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailJsonHandler.java @@ -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(); } diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudwatch/metrics/CloudWatchMetricsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/cloudwatch/metrics/CloudWatchMetricsJsonHandler.java index b10d675f74..a43ac5c08e 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudwatch/metrics/CloudWatchMetricsJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudwatch/metrics/CloudWatchMetricsJsonHandler.java @@ -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()); diff --git a/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildRunner.java b/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildRunner.java index af35d80ddf..553acf8dd6 100644 --- a/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildRunner.java +++ b/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildRunner.java @@ -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"); diff --git a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java index dfe7e8e85e..b61b052cb9 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java +++ b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java @@ -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()); diff --git a/src/main/java/io/github/hectorvent/floci/services/eks/EksAccessEntryService.java b/src/main/java/io/github/hectorvent/floci/services/eks/EksAccessEntryService.java index 9987d311f2..79cfd3e56d 100644 --- a/src/main/java/io/github/hectorvent/floci/services/eks/EksAccessEntryService.java +++ b/src/main/java/io/github/hectorvent/floci/services/eks/EksAccessEntryService.java @@ -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(); diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/GlueJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/glue/GlueJsonHandler.java index 849dbdbf6c..e1619dce2b 100644 --- a/src/main/java/io/github/hectorvent/floci/services/glue/GlueJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/glue/GlueJsonHandler.java @@ -1172,17 +1172,13 @@ public class GlueJsonHandler { Map 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; } diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/GlueTriggerService.java b/src/main/java/io/github/hectorvent/floci/services/glue/GlueTriggerService.java index 589ee08636..065b6e67f1 100644 --- a/src/main/java/io/github/hectorvent/floci/services/glue/GlueTriggerService.java +++ b/src/main/java/io/github/hectorvent/floci/services/glue/GlueTriggerService.java @@ -609,9 +609,9 @@ public class GlueTriggerService { if (name.equals(crawl.crawlerName())) { Map 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 diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java index 176404ca7d..a5100e5dc2 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaController.java @@ -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"); diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionController.java b/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionController.java index 0b21d58169..8df5078273 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionController.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionController.java @@ -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(); } diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableWire.java b/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableWire.java index fce0d83b93..56e9f38803 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableWire.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableWire.java @@ -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)); } } diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/model/FunctionEventInvokeConfig.java b/src/main/java/io/github/hectorvent/floci/services/lambda/model/FunctionEventInvokeConfig.java index 79edc3d8bc..57c2901076 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/model/FunctionEventInvokeConfig.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/model/FunctionEventInvokeConfig.java @@ -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; diff --git a/src/main/java/io/github/hectorvent/floci/services/lightsail/LightsailService.java b/src/main/java/io/github/hectorvent/floci/services/lightsail/LightsailService.java index 34843f3791..ce61a14407 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lightsail/LightsailService.java +++ b/src/main/java/io/github/hectorvent/floci/services/lightsail/LightsailService.java @@ -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; diff --git a/src/main/java/io/github/hectorvent/floci/services/redshiftdata/RedshiftDataService.java b/src/main/java/io/github/hectorvent/floci/services/redshiftdata/RedshiftDataService.java index 6864b615db..e639256ea0 100644 --- a/src/main/java/io/github/hectorvent/floci/services/redshiftdata/RedshiftDataService.java +++ b/src/main/java/io/github/hectorvent/floci/services/redshiftdata/RedshiftDataService.java @@ -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"); } diff --git a/src/main/java/io/github/hectorvent/floci/services/redshiftdata/RedshiftDataSessionListing.java b/src/main/java/io/github/hectorvent/floci/services/redshiftdata/RedshiftDataSessionListing.java index 3895673aa1..99338dfc58 100644 --- a/src/main/java/io/github/hectorvent/floci/services/redshiftdata/RedshiftDataSessionListing.java +++ b/src/main/java/io/github/hectorvent/floci/services/redshiftdata/RedshiftDataSessionListing.java @@ -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()); diff --git a/src/main/java/io/github/hectorvent/floci/services/sagemaker/SageMakerService.java b/src/main/java/io/github/hectorvent/floci/services/sagemaker/SageMakerService.java index 55251785c5..58af642956 100644 --- a/src/main/java/io/github/hectorvent/floci/services/sagemaker/SageMakerService.java +++ b/src/main/java/io/github/hectorvent/floci/services/sagemaker/SageMakerService.java @@ -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) { diff --git a/src/main/java/io/github/hectorvent/floci/services/ssoadmin/SsoAdminJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/ssoadmin/SsoAdminJsonHandler.java index cf56262f14..192c2c8efd 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ssoadmin/SsoAdminJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/ssoadmin/SsoAdminJsonHandler.java @@ -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()); diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java index f9bbc7f6c3..0a8e459acb 100644 --- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java +++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java @@ -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", diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsJsonHandler.java index c44050aded..3ab051e30a 100644 --- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsJsonHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsJsonHandler.java @@ -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(); } diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java index 28ca99b6c6..bc768e3780 100644 --- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java +++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsService.java @@ -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()); diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/Activity.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/Activity.java index 8f8efd8646..382008787f 100644 --- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/Activity.java +++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/Activity.java @@ -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 tags = new HashMap<>(); public Activity() { - this.creationDate = System.currentTimeMillis() / 1000.0; + this.creationDate = EpochSeconds.fromMillis(System.currentTimeMillis()); } public String getActivityArn() { return activityArn; } diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/Execution.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/Execution.java index 7fecbc7c6e..0b4be6bb84 100644 --- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/Execution.java +++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/Execution.java @@ -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 statusSubscriptions; public Execution() { - this.startDate = System.currentTimeMillis() / 1000.0; + this.startDate = EpochSeconds.fromMillis(System.currentTimeMillis()); } public String getExecutionArn() { return executionArn; } diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/HistoryEvent.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/HistoryEvent.java index 12a503d441..a6493fe5d6 100644 --- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/HistoryEvent.java +++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/HistoryEvent.java @@ -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 details; public HistoryEvent() { - this.timestamp = System.currentTimeMillis() / 1000.0; + this.timestamp = EpochSeconds.fromMillis(System.currentTimeMillis()); } public long getId() { return id; } diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/StateMachine.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/StateMachine.java index 57536a7aca..158ae8b840 100644 --- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/StateMachine.java +++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/StateMachine.java @@ -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 versions = new ArrayList<>(); public StateMachine() { - this.creationDate = System.currentTimeMillis() / 1000.0; + this.creationDate = EpochSeconds.fromMillis(System.currentTimeMillis()); } public String getStateMachineArn() { return stateMachineArn; } diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/StateMachineAlias.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/StateMachineAlias.java index 4293584617..7435e13093 100644 --- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/StateMachineAlias.java +++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/model/StateMachineAlias.java @@ -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; } diff --git a/src/main/java/io/github/hectorvent/floci/services/swf/SwfService.java b/src/main/java/io/github/hectorvent/floci/services/swf/SwfService.java index 715a9eb3ab..029b864f54 100644 --- a/src/main/java/io/github/hectorvent/floci/services/swf/SwfService.java +++ b/src/main/java/io/github/hectorvent/floci/services/swf/SwfService.java @@ -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. */ diff --git a/src/test/java/io/github/hectorvent/floci/core/common/EpochSecondsTest.java b/src/test/java/io/github/hectorvent/floci/core/common/EpochSecondsTest.java index 51cb8ed837..e9d70f2aac 100644 --- a/src/test/java/io/github/hectorvent/floci/core/common/EpochSecondsTest.java +++ b/src/test/java/io/github/hectorvent/floci/core/common/EpochSecondsTest.java @@ -20,6 +20,13 @@ class EpochSecondsTest { assertEquals(-0.001, EpochSeconds.fromInstant(Instant.ofEpochSecond(-1, 999_999_999))); } + @Test + void convertsLongEpochMillisWithoutLosingMillisecondFraction() { + assertEquals(1_790_312_384.592, EpochSeconds.fromMillis(1_790_312_384_592L)); + assertEquals(-0.001, EpochSeconds.fromMillis(-1L)); + assertEquals(0.001, EpochSeconds.fromMillis(1L)); + } + @Test void retainsNullAndOverflowFailures() { assertThrows(NullPointerException.class, () -> EpochSeconds.fromInstant(null));