Skip to content

Commit

Permalink
Support AssignedRotations that track cluster, rotation, and endpoint …
Browse files Browse the repository at this point in the history
…name.

No functionality changes in this commit, only how we persist and talk about
rotations and endpoints in the applicaiton.  This is preparation of actually
updating the support for multiple endpoints in the controller.
  • Loading branch information
Øyvind Grønnesby committed Jun 25, 2019
1 parent 2da125f commit 4b56d4b
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
import com.yahoo.component.Version;
import com.yahoo.config.application.api.DeploymentSpec;
import com.yahoo.config.application.api.ValidationOverrides;
import com.yahoo.config.model.api.ContainerEndpoint;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.RotationName;
import com.yahoo.config.provision.SystemName;
import com.yahoo.config.provision.zone.ZoneId;
import com.yahoo.vespa.hosted.controller.api.integration.MetricsService.ApplicationMetrics;
import com.yahoo.vespa.hosted.controller.api.integration.deployment.ApplicationVersion;
import com.yahoo.vespa.hosted.controller.api.integration.organization.IssueId;
import com.yahoo.vespa.hosted.controller.api.integration.organization.User;
import com.yahoo.vespa.hosted.controller.application.ApplicationActivity;
import com.yahoo.vespa.hosted.controller.application.AssignedRotation;
import com.yahoo.vespa.hosted.controller.application.Change;
import com.yahoo.vespa.hosted.controller.application.Deployment;
import com.yahoo.vespa.hosted.controller.application.DeploymentJobs;
Expand All @@ -27,14 +30,17 @@
import java.time.Instant;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* An instance of an application.
Expand All @@ -58,8 +64,7 @@ public class Application {
private final OptionalInt majorVersion;
private final ApplicationMetrics metrics;
private final Optional<String> pemDeployKey;
private final Optional<RotationId> legacyRotation;
private final List<RotationId> rotations;
private final List<AssignedRotation> rotations;
private final Map<HostName, RotationStatus> rotationStatus;

/** Creates an empty application */
Expand All @@ -68,26 +73,26 @@ public Application(ApplicationId id, Instant now) {
new DeploymentJobs(OptionalLong.empty(), Collections.emptyList(), Optional.empty(), false),
Change.empty(), Change.empty(), Optional.empty(), Optional.empty(), OptionalInt.empty(),
new ApplicationMetrics(0, 0),
Optional.empty(), Optional.empty(), Collections.emptyList(), Collections.emptyMap());
Optional.empty(), Collections.emptyList(), Collections.emptyMap());
}

/** Used from persistence layer: Do not use */
public Application(ApplicationId id, Instant createdAt, DeploymentSpec deploymentSpec, ValidationOverrides validationOverrides,
List<Deployment> deployments, DeploymentJobs deploymentJobs, Change change,
Change outstandingChange, Optional<IssueId> ownershipIssueId, Optional<User> owner,
OptionalInt majorVersion, ApplicationMetrics metrics, Optional<String> pemDeployKey,
Optional<RotationId> legacyRotation, List<RotationId> rotations, Map<HostName, RotationStatus> rotationStatus) {
List<AssignedRotation> rotations, Map<HostName, RotationStatus> rotationStatus) {
this(id, createdAt, deploymentSpec, validationOverrides,
deployments.stream().collect(Collectors.toMap(Deployment::zone, Function.identity())),
deploymentJobs, change, outstandingChange, ownershipIssueId, owner, majorVersion,
metrics, pemDeployKey, legacyRotation, rotations, rotationStatus);
metrics, pemDeployKey, rotations, rotationStatus);
}

Application(ApplicationId id, Instant createdAt, DeploymentSpec deploymentSpec, ValidationOverrides validationOverrides,
Map<ZoneId, Deployment> deployments, DeploymentJobs deploymentJobs, Change change,
Change outstandingChange, Optional<IssueId> ownershipIssueId, Optional<User> owner,
OptionalInt majorVersion, ApplicationMetrics metrics, Optional<String> pemDeployKey,
Optional<RotationId> legacyRotation, List<RotationId> rotations, Map<HostName, RotationStatus> rotationStatus) {
List<AssignedRotation> rotations, Map<HostName, RotationStatus> rotationStatus) {
this.id = Objects.requireNonNull(id, "id cannot be null");
this.createdAt = Objects.requireNonNull(createdAt, "instant of creation cannot be null");
this.deploymentSpec = Objects.requireNonNull(deploymentSpec, "deploymentSpec cannot be null");
Expand All @@ -101,7 +106,6 @@ public Application(ApplicationId id, Instant createdAt, DeploymentSpec deploymen
this.majorVersion = Objects.requireNonNull(majorVersion, "majorVersion cannot be null");
this.metrics = Objects.requireNonNull(metrics, "metrics cannot be null");
this.pemDeployKey = pemDeployKey;
this.legacyRotation = Objects.requireNonNull(legacyRotation, "legacyRotation cannot be null");
this.rotations = List.copyOf(Objects.requireNonNull(rotations, "rotations cannot be null"));
this.rotationStatus = ImmutableMap.copyOf(Objects.requireNonNull(rotationStatus, "rotationStatus cannot be null"));
}
Expand Down Expand Up @@ -200,11 +204,20 @@ public Optional<ApplicationVersion> oldestDeployedApplication() {

/** Returns the global rotation id of this, if present */
public Optional<RotationId> legacyRotation() {
return legacyRotation;
return rotations.stream()
.map(AssignedRotation::rotationId)
.findFirst();
}

/** Returns all rotations for this application */
public List<RotationId> rotations() {
return rotations.stream()
.map(AssignedRotation::rotationId)
.collect(Collectors.toList());
}

/** Returns all assigned rotations for this application */
public List<AssignedRotation> assignedRotations() {
return rotations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
import com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingEndpoint;
import com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingGenerator;
import com.yahoo.vespa.hosted.controller.application.ApplicationPackage;
import com.yahoo.vespa.hosted.controller.application.AssignedRotation;
import com.yahoo.vespa.hosted.controller.application.Deployment;
import com.yahoo.vespa.hosted.controller.application.DeploymentMetrics;
import com.yahoo.vespa.hosted.controller.application.Endpoint;
import com.yahoo.vespa.hosted.controller.application.EndpointId;
import com.yahoo.vespa.hosted.controller.application.EndpointList;
import com.yahoo.vespa.hosted.controller.application.JobList;
import com.yahoo.vespa.hosted.controller.application.JobStatus;
Expand Down Expand Up @@ -439,7 +441,7 @@ private LockedApplication withRotation(LockedApplication application, ZoneId zon
if (zone.environment() == Environment.prod && application.get().deploymentSpec().globalServiceId().isPresent()) {
try (RotationLock rotationLock = rotationRepository.lock()) {
Rotation rotation = rotationRepository.getOrAssignRotation(application.get(), rotationLock);
application = application.with(rotation.id());
application = application.with(List.of(new AssignedRotation(new ClusterSpec.Id(application.get().deploymentSpec().globalServiceId().get()), EndpointId.default_(), rotation.id())));
store(application); // store assigned rotation even if deployment fails

boolean redirectLegacyDns = redirectLegacyDnsFlag.with(FetchVector.Dimension.APPLICATION_ID, application.get().id().serializedForm())
Expand Down
Loading

0 comments on commit 4b56d4b

Please sign in to comment.