diff options
author | Martin Polden <mpolden@mpolden.no> | 2019-04-01 15:41:01 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2019-04-04 14:31:35 +0200 |
commit | 60bd50c25e6e1e861785563dc9f0fcb56ec14742 (patch) | |
tree | f188be476f47b2aa834afe071824dfaa549d52f6 /controller-server | |
parent | ea56eae3f73af014d90956a96c719b94efc7ed5a (diff) |
Simplify
Diffstat (limited to 'controller-server')
4 files changed, 12 insertions, 14 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java index 1d685895914..71d39f97988 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java @@ -231,14 +231,14 @@ public class ApplicationController { com.yahoo.vespa.hosted.controller.api.identifiers.ApplicationId.validate(id.application().value()); Optional<Tenant> tenant = controller.tenants().get(id.tenant()); - if ( ! tenant.isPresent()) + if (tenant.isEmpty()) throw new IllegalArgumentException("Could not create '" + id + "': This tenant does not exist"); if (get(id).isPresent()) throw new IllegalArgumentException("Could not create '" + id + "': Application already exists"); if (get(dashToUnderscore(id)).isPresent()) // VESPA-1945 throw new IllegalArgumentException("Could not create '" + id + "': Application " + dashToUnderscore(id) + " already exists"); if (tenant.get().type() != Tenant.Type.user) { - if ( ! credentials.isPresent()) + if (credentials.isEmpty()) throw new IllegalArgumentException("Could not create '" + id + "': No credentials provided"); if (id.instance().isDefault()) // Only store the application permits for non-user applications. @@ -269,7 +269,7 @@ public class ApplicationController { throw new IllegalArgumentException("'" + applicationId + "' is a tester application!"); Tenant tenant = controller.tenants().require(applicationId.tenant()); - if (tenant.type() == Tenant.Type.user && ! get(applicationId).isPresent()) + if (tenant.type() == Tenant.Type.user && get(applicationId).isEmpty()) createApplication(applicationId, Optional.empty()); try (Lock deploymentLock = lockForDeployment(applicationId, zone)) { @@ -292,15 +292,15 @@ public class ApplicationController { () -> new IllegalArgumentException("Application package must be given when deploying to " + zone)); platformVersion = options.vespaVersion.map(Version::new).orElse(applicationPackage.deploymentSpec().majorVersion() .flatMap(this::lastCompatibleVersion) - .orElse(controller.systemVersion())); + .orElseGet(controller::systemVersion)); } else { JobType jobType = JobType.from(controller.system(), zone) .orElseThrow(() -> new IllegalArgumentException("No job is known for " + zone + ".")); Optional<JobStatus> job = Optional.ofNullable(application.get().deploymentJobs().jobStatus().get(jobType)); - if ( ! job.isPresent() - || ! job.get().lastTriggered().isPresent() - || job.get().lastCompleted().isPresent() && job.get().lastCompleted().get().at().isAfter(job.get().lastTriggered().get().at())) + if ( job.isEmpty() + || job.get().lastTriggered().isEmpty() + || job.get().lastCompleted().isPresent() && job.get().lastCompleted().get().at().isAfter(job.get().lastTriggered().get().at())) return unexpectedDeployment(applicationId, zone); JobRun triggered = job.get().lastTriggered().get(); platformVersion = preferOldestVersion ? triggered.sourcePlatform().orElse(triggered.platform()) @@ -382,7 +382,7 @@ public class ApplicationController { application = withoutUnreferencedDeploymentJobs(application); store(application); - return(application); + return application; } /** Deploy a system application to given zone */ @@ -440,12 +440,11 @@ public class ApplicationController { return application; } - private ActivateResult unexpectedDeployment(ApplicationId applicationId, ZoneId zone) { - + private ActivateResult unexpectedDeployment(ApplicationId application, ZoneId zone) { Log logEntry = new Log(); logEntry.level = "WARNING"; logEntry.time = clock.instant().toEpochMilli(); - logEntry.message = "Ignoring deployment of " + require(applicationId) + " to " + zone + + logEntry.message = "Ignoring deployment of application '" + application + "' to " + zone + " as a deployment is not currently expected"; PrepareResponse prepareResponse = new PrepareResponse(); prepareResponse.log = Collections.singletonList(logEntry); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DnsMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DnsMaintainer.java index 2fe6af02480..7693f224b56 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DnsMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DnsMaintainer.java @@ -72,7 +72,7 @@ public class DnsMaintainer extends Maintainer { private Optional<Rotation> rotationToCheckOf(Collection<Rotation> rotations) { if (rotations.isEmpty()) return Optional.empty(); List<Rotation> rotationList = new ArrayList<>(rotations); - int index = rotationIndex.getAndUpdate((i)-> { + int index = rotationIndex.getAndUpdate((i) -> { if (i < rotationList.size() - 1) { return ++i; } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/rotation/RotationRepository.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/rotation/RotationRepository.java index a22e5259919..b3953c47c01 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/rotation/RotationRepository.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/rotation/RotationRepository.java @@ -63,7 +63,7 @@ public class RotationRepository { if (application.rotation().isPresent()) { return allRotations.get(application.rotation().get()); } - if (!application.deploymentSpec().globalServiceId().isPresent()) { + if (application.deploymentSpec().globalServiceId().isEmpty()) { throw new IllegalArgumentException("global-service-id is not set in deployment spec"); } long productionZones = application.deploymentSpec().zones().stream() diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DnsMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DnsMaintainerTest.java index 23c7ec537f5..2b8e4f52d23 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DnsMaintainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DnsMaintainerTest.java @@ -4,7 +4,6 @@ package com.yahoo.vespa.hosted.controller.maintenance; import com.yahoo.config.application.api.ValidationId; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.RegionName; -import com.yahoo.vespa.athenz.api.OktaAccessToken; import com.yahoo.vespa.hosted.controller.Application; import com.yahoo.vespa.hosted.controller.ControllerTester; import com.yahoo.vespa.hosted.controller.api.integration.dns.Record; |