diff options
author | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2017-12-14 09:11:42 +0100 |
---|---|---|
committer | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2017-12-14 09:11:42 +0100 |
commit | b0b43c5cf8ecf90367f8b7c59177cba8c1a2e985 (patch) | |
tree | e46bbf0e065d3c17fb1957bb0ea4a31e66dfec72 | |
parent | d08fdcafc28581519e1d2f88117f47bc1bc62904 (diff) |
Optional<Duration> again
7 files changed, 9 insertions, 12 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java index 5e0c8ec1f7e..af7c464b8d7 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java @@ -42,8 +42,8 @@ public interface ZoneRegistry { /** Returns a URL with the logs for the given deployment, if loggin is configured for its zone. */ Optional<URI> getLogServerUri(DeploymentId deploymentId); - /** Returns the time to live for deployments in the given zone. */ - Duration getDeploymentTimeToLive(ZoneId zoneId); + /** Returns the time to live for deployments in the given zone, or empty if this is infinite. */ + Optional<Duration> getDeploymentTimeToLive(ZoneId zoneId); /** Returns a URL pointing at monitoring resources for the given deployment. */ URI getMonitoringSystemUri(DeploymentId deploymentId); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentExpirer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentExpirer.java index 5291593e793..5638ff28904 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentExpirer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentExpirer.java @@ -53,7 +53,9 @@ public class DeploymentExpirer extends Maintainer { } public static boolean hasExpired(ZoneRegistry zoneRegistry, Deployment deployment, Instant now) { - return deployment.at().plus(zoneRegistry.getDeploymentTimeToLive(deployment.zone())).isBefore(now); + return zoneRegistry.getDeploymentTimeToLive(deployment.zone()) + .map(timeToLive -> deployment.at().plus(timeToLive).isBefore(now)) + .orElse(false); } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java index 5974833aaf0..98235829620 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java @@ -452,8 +452,8 @@ public class ApplicationApiHandler extends LoggingRequestHandler { response.setString("version", deployment.version().toFullString()); response.setString("revision", deployment.revision().id()); response.setLong("deployTimeEpochMs", deployment.at().toEpochMilli()); - Duration deploymentTimeToLive = controller.zoneRegistry().getDeploymentTimeToLive(deploymentId.zoneId()); - response.setLong("expiryTimeEpochMs", deployment.at().plus(deploymentTimeToLive).toEpochMilli()); + controller.zoneRegistry().getDeploymentTimeToLive(deploymentId.zoneId()) + .ifPresent(deploymentTimeToLive -> response.setLong("expiryTimeEpochMs", deployment.at().plus(deploymentTimeToLive).toEpochMilli())); controller.applications().get(deploymentId.applicationId()).flatMap(application -> application.deploymentJobs().projectId()) .ifPresent(i -> response.setString("screwdriverId", String.valueOf(i))); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ZoneRegistryMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ZoneRegistryMock.java index 95e71e4d63a..2317b7bc6f1 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ZoneRegistryMock.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ZoneRegistryMock.java @@ -102,10 +102,8 @@ public class ZoneRegistryMock extends AbstractComponent implements ZoneRegistry } @Override - public Duration getDeploymentTimeToLive(ZoneId zoneId) { - return deploymentTimeToLive.containsKey(zoneId) - ? deploymentTimeToLive.get(zoneId) - : Duration.ofMillis(Long.MAX_VALUE / 2); + public Optional<Duration> getDeploymentTimeToLive(ZoneId zoneId) { + return Optional.ofNullable(deploymentTimeToLive.get(zoneId)); } @Override diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/deployment.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/deployment.json index e251b03e548..9174e7dd8b2 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/deployment.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/deployment.json @@ -12,7 +12,6 @@ "version": "(ignore)", "revision": "(ignore)", "deployTimeEpochMs": "(ignore)", - "expiryTimeEpochMs": "(ignore)", "screwdriverId": "123", "gitRepository": "repository1", "gitBranch": "master", diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/dev-us-west-1.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/dev-us-west-1.json index 50575afa69d..062f4408518 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/dev-us-west-1.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/dev-us-west-1.json @@ -14,7 +14,6 @@ "version": "6.1.0", "revision": "(ignore)", "deployTimeEpochMs": "(ignore)", - "expiryTimeEpochMs": "(ignore)", "screwdriverId": "123", diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/prod-corp-us-east-1.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/prod-corp-us-east-1.json index fdff97c6b1b..75b257da0ed 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/prod-corp-us-east-1.json +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/prod-corp-us-east-1.json @@ -18,7 +18,6 @@ "version": "6.1.0", "revision": "(ignore)", "deployTimeEpochMs": "(ignore)", - "expiryTimeEpochMs": "(ignore)", "screwdriverId": "123", "gitRepository": "repository1", "gitBranch": "master", |