Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a comment and rename some variables #9329

Merged
merged 1 commit into from May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -58,4 +58,5 @@ private boolean handlerNeedsProtection(Handler<?> handler) {
private boolean hasNonMbusBinding(Handler<?> handler) {
return handler.getServerBindings().stream().anyMatch(binding -> ! binding.startsWith("mbus"));
}

}
Expand Up @@ -174,11 +174,11 @@ public Map<HostResource, ClusterMembership> provision(HostSystem hostSystem,
}

private static Optional<NodeResources> getFlavor(ModelElement nodesElement) {
ModelElement flavor = nodesElement.child("resources");
if (flavor != null) {
return Optional.of(new NodeResources(flavor.requiredDoubleAttribute("vcpu"),
parseGbAmount(flavor.requiredStringAttribute("memory")),
parseGbAmount(flavor.requiredStringAttribute("disk"))));
ModelElement resources = nodesElement.child("resources");
if (resources != null) {
return Optional.of(new NodeResources(resources.requiredDoubleAttribute("vcpu"),
parseGbAmount(resources.requiredStringAttribute("memory")),
parseGbAmount(resources.requiredStringAttribute("disk"))));
}
else if (nodesElement.stringAttribute("flavor") != null) { // legacy fallback
return Optional.of(NodeResources.fromLegacyName(nodesElement.stringAttribute("flavor")));
Expand Down
Expand Up @@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
Expand All @@ -18,10 +19,6 @@
public class Flavor {

private boolean configured;

/** The hardware resources of this flavor */
private NodeResources resources;

private final String name;
private final int cost;
private final boolean isStock;
Expand All @@ -36,6 +33,9 @@ public class Flavor {
private List<Flavor> replacesFlavors;
private int idealHeadroom; // Note: Not used after Vespa 6.282

/** The hardware resources of this flavor */
private NodeResources resources;

/**
* Creates a Flavor, but does not set the replacesFlavors.
*
Expand All @@ -44,7 +44,6 @@ public class Flavor {
public Flavor(FlavorsConfig.Flavor flavorConfig) {
this.configured = true;
this.name = flavorConfig.name();
this.replacesFlavors = new ArrayList<>();
this.cost = flavorConfig.cost();
this.isStock = flavorConfig.stock();
this.type = Type.valueOf(flavorConfig.environment());
Expand All @@ -55,12 +54,14 @@ public Flavor(FlavorsConfig.Flavor flavorConfig) {
this.bandwidth = flavorConfig.bandwidth();
this.description = flavorConfig.description();
this.retired = flavorConfig.retired();
this.replacesFlavors = new ArrayList<>();
this.idealHeadroom = flavorConfig.idealHeadroom();
this.resources = new NodeResources(minCpuCores, minMainMemoryAvailableGb, minDiskAvailableGb);
}

/** Create a Flavor from a Flavor spec and all other fields set to Docker defaults */
public Flavor(NodeResources resources) {
Objects.requireNonNull(resources, "Resources cannot be null");
if (resources.allocateByLegacyName())
throw new IllegalArgumentException("Can not create flavor '" + resources.legacyName() + "' from a flavor: " +
"Non-docker flavors must be of a configured flavor");
Expand All @@ -77,6 +78,7 @@ public Flavor(NodeResources resources) {
this.description = "";
this.retired = false;
this.replacesFlavors = Collections.emptyList();
this.idealHeadroom = 0;
this.resources = resources;
}

Expand Down
Expand Up @@ -44,6 +44,13 @@
*/
public class NodeSerializer {

// WARNING: Since there are multiple config servers in a cluster and they upgrade one by one
// (and rewrite all nodes on startup),
// changes to the serialized format must be made such that what is serialized on version N+1
// can be read by version N:
// - ADDING FIELDS: Always ok
// - REMOVING FIELDS: Stop reading the field first. Stop writing it on a later version.

/** The configured node flavors */
private final NodeFlavors flavors;

Expand Down
Expand Up @@ -41,28 +41,28 @@ public int decideSize(Capacity requestedCapacity, ClusterSpec.Type clusterType)
}
}

public NodeResources decideFlavor(Capacity requestedCapacity, ClusterSpec cluster) {
Optional<NodeResources> requestedFlavor = requestedCapacity.nodeResources();
if (requestedFlavor.isPresent() && ! requestedFlavor.get().allocateByLegacyName())
return requestedFlavor.get();
public NodeResources decideNodeResources(Capacity requestedCapacity, ClusterSpec cluster) {
Optional<NodeResources> requestedResources = requestedCapacity.nodeResources();
if (requestedResources.isPresent() && ! requestedResources.get().allocateByLegacyName())
return requestedResources.get();

NodeResources defaultFlavor = NodeResources.fromLegacyName(zone.defaultFlavor(cluster.type()));
if (requestedFlavor.isEmpty())
return defaultFlavor;
NodeResources defaultResources = NodeResources.fromLegacyName(zone.defaultFlavor(cluster.type()));
if (requestedResources.isEmpty())
return defaultResources;

// Flavor is specified and is allocateByLegacyName: Handle legacy flavor specs
if (zone.system() == SystemName.cd)
return flavors.exists(requestedFlavor.get().legacyName().get()) ? requestedFlavor.get() : defaultFlavor;
return flavors.exists(requestedResources.get().legacyName().get()) ? requestedResources.get() : defaultResources;
else {
switch (zone.environment()) {
case dev: case test: case staging: return defaultFlavor;
case dev: case test: case staging: return defaultResources;
default:
// Check existence of the legacy specified flavor
flavors.getFlavorOrThrow(requestedFlavor.get().legacyName().get());
flavors.getFlavorOrThrow(requestedResources.get().legacyName().get());
// Return this spec containing the legacy flavor name, not the flavor's capacity object
// which describes the flavors capacity, as the point of legacy allocation is to match
// by name, not by resources
return requestedFlavor.get();
return requestedResources.get();
}
}
}
Expand Down
Expand Up @@ -96,7 +96,7 @@ public List<HostSpec> prepare(ApplicationId application, ClusterSpec cluster, Ca
if (zone.environment().isManuallyDeployed() && nodeCount < requestedCapacity.nodeCount())
logger.log(Level.INFO, "Requested " + requestedCapacity.nodeCount() + " nodes for " + cluster +
", downscaling to " + nodeCount + " nodes in " + zone.environment());
NodeResources flavor = capacityPolicies.decideFlavor(requestedCapacity, cluster);
NodeResources flavor = capacityPolicies.decideNodeResources(requestedCapacity, cluster);
log.log(LogLevel.DEBUG, () -> "Decided flavor for requested tenant nodes: " + flavor);
boolean exclusive = capacityPolicies.decideExclusivity(cluster.isExclusive());
effectiveGroups = wantedGroups > nodeCount ? nodeCount : wantedGroups; // cannot have more groups than nodes
Expand Down
Expand Up @@ -133,7 +133,7 @@ public void trusted_nodes_for_children_of_docker_host() {
List<Node> dockerHostNodes = tester.makeReadyNodes(2, "default", NodeType.host);
Node dockerHostNodeUnderTest = dockerHostNodes.get(0);
List<Node> dockerNodes = tester.makeReadyVirtualDockerNodes(5, new NodeResources(1, 1, 1),
dockerHostNodeUnderTest.hostname());
dockerHostNodeUnderTest.hostname());

List<NodeAcl> acls = tester.nodeRepository().getNodeAcls(dockerHostNodeUnderTest, true);

Expand Down