diff options
author | Martin Polden <mpolden@mpolden.no> | 2021-05-11 15:52:58 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2021-05-14 11:33:30 +0200 |
commit | f0e9fb474490b8d09ea3b8cb560c2c856aca322c (patch) | |
tree | 57cfdbd21c9346ff28b722de929e047d21f554c3 /controller-server | |
parent | 0cb1d4e442c191d3f5c12e289c0ecdca29ee8b93 (diff) |
Less copying
Diffstat (limited to 'controller-server')
3 files changed, 22 insertions, 13 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Application.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Application.java index 159e0bb1f0f..f8624b40737 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Application.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Application.java @@ -1,7 +1,6 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller; -import com.google.common.collect.ImmutableSortedMap; import com.yahoo.component.Version; import com.yahoo.config.application.api.DeploymentSpec; import com.yahoo.config.application.api.ValidationOverrides; @@ -21,6 +20,7 @@ import com.yahoo.vespa.hosted.controller.tenant.Tenant; import java.security.PublicKey; import java.time.Instant; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; @@ -29,6 +29,7 @@ import java.util.Optional; import java.util.OptionalInt; import java.util.OptionalLong; import java.util.Set; +import java.util.TreeMap; import java.util.function.Function; import java.util.stream.Collectors; @@ -79,7 +80,15 @@ public class Application { this.deployKeys = Objects.requireNonNull(deployKeys, "deployKeys cannot be null"); this.projectId = Objects.requireNonNull(projectId, "projectId cannot be null"); this.latestVersion = requireNotUnknown(latestVersion); - this.instances = ImmutableSortedMap.copyOf(instances.stream().collect(Collectors.toMap(Instance::name, Function.identity()))); + this.instances = instances.stream().collect( + Collectors.collectingAndThen(Collectors.toMap(Instance::name, + Function.identity(), + (i1, i2) -> { + throw new IllegalArgumentException("Duplicate key " + i1); + }, + TreeMap::new), + Collections::unmodifiableMap) + ); } public TenantAndApplicationId id() { return id; } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Instance.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Instance.java index 025b785a693..0fcb3cd9be4 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Instance.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Instance.java @@ -1,7 +1,6 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller; -import com.google.common.collect.ImmutableMap; import com.yahoo.component.Version; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Environment; @@ -55,8 +54,8 @@ public class Instance { public Instance(ApplicationId id, Collection<Deployment> deployments, Map<JobType, Instant> jobPauses, List<AssignedRotation> rotations, RotationStatus rotationStatus, Change change) { this.id = Objects.requireNonNull(id, "id cannot be null"); - this.deployments = ImmutableMap.copyOf(Objects.requireNonNull(deployments, "deployments cannot be null").stream() - .collect(Collectors.toMap(Deployment::zone, Function.identity()))); + this.deployments = Objects.requireNonNull(deployments, "deployments cannot be null").stream() + .collect(Collectors.toUnmodifiableMap(Deployment::zone, Function.identity())); this.jobPauses = Map.copyOf(Objects.requireNonNull(jobPauses, "deploymentJobs cannot be null")); this.rotations = List.copyOf(Objects.requireNonNull(rotations, "rotations cannot be null")); this.rotationStatus = Objects.requireNonNull(rotationStatus, "rotationStatus cannot be null"); @@ -140,9 +139,9 @@ public class Instance { * (deployments also includes manually deployed environments) */ public Map<ZoneId, Deployment> productionDeployments() { - return ImmutableMap.copyOf(deployments.values().stream() - .filter(deployment -> deployment.zone().environment() == Environment.prod) - .collect(Collectors.toMap(Deployment::zone, Function.identity()))); + return deployments.values().stream() + .filter(deployment -> deployment.zone().environment() == Environment.prod) + .collect(Collectors.toUnmodifiableMap(Deployment::zone, Function.identity())); } /** Returns the instant until which the given job is paused, or empty. */ diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentStatus.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentStatus.java index 3f1e8831e83..5b873f11618 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentStatus.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentStatus.java @@ -22,6 +22,7 @@ import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -92,7 +93,7 @@ public class DeploymentStatus { this.now = requireNonNull(now); List<StepStatus> allSteps = new ArrayList<>(); this.jobSteps = jobDependencies(application.deploymentSpec(), allSteps); - this.allSteps = List.copyOf(allSteps); + this.allSteps = Collections.unmodifiableList(allSteps); } /** The application this deployment status concerns. */ @@ -146,7 +147,7 @@ public class DeploymentStatus { Map.Entry::getValue, DeploymentStatus::union, LinkedHashMap::new), - ImmutableMap::copyOf)); + Collections::unmodifiableMap)); } private Map<JobId, List<Versions>> jobsToRun(Map<InstanceName, Change> changes, boolean eagerTests) { @@ -173,7 +174,7 @@ public class DeploymentStatus { if (step.completedAt(change, firstProductionJobWithDeployment).isEmpty()) jobs.merge(job, List.of(versions), DeploymentStatus::union); }); - return ImmutableMap.copyOf(jobs); + return Collections.unmodifiableMap(jobs); } /** The set of jobs that need to run for the given changes to be considered complete. */ @@ -281,7 +282,7 @@ public class DeploymentStatus { testJobs.merge(firstDeclaredOrElseImplicitTest(testType), List.of(versions), DeploymentStatus::union); }); } - return ImmutableMap.copyOf(testJobs); + return Collections.unmodifiableMap(testJobs); } private JobId firstDeclaredOrElseImplicitTest(JobType testJob) { @@ -306,7 +307,7 @@ public class DeploymentStatus { for (DeploymentSpec.Step step : spec.steps()) previous = fillStep(dependencies, allSteps, step, previous, null); - return ImmutableMap.copyOf(dependencies); + return Collections.unmodifiableMap(dependencies); } /** Adds the primitive steps contained in the given step, which depend on the given previous primitives, to the dependency graph. */ |