use of com.yahoo.config.provision.ClusterMembership in project vespa by vespa-engine.
the class InMemoryProvisioner method allocateHostGroup.
private List<HostSpec> allocateHostGroup(ClusterSpec clusterGroup, String flavor, int nodesInGroup, int startIndex) {
List<HostSpec> allocation = allocations.getOrDefault(clusterGroup, new ArrayList<>());
allocations.put(clusterGroup, allocation);
int nextIndex = nextIndexInCluster.getOrDefault(new Pair<>(clusterGroup.type(), clusterGroup.id()), startIndex);
while (allocation.size() < nodesInGroup) {
if (freeNodes.get(flavor).isEmpty())
throw new IllegalArgumentException("Insufficient capacity of flavor '" + flavor + "'");
Host newHost = freeNodes.removeValue(flavor, 0);
ClusterMembership membership = ClusterMembership.from(clusterGroup, nextIndex++);
allocation.add(new HostSpec(newHost.hostname(), newHost.aliases(), newHost.flavor(), Optional.of(membership)));
}
nextIndexInCluster.put(new Pair<>(clusterGroup.type(), clusterGroup.id()), nextIndex);
while (allocation.size() > nodesInGroup) allocation.remove(0);
return allocation;
}
use of com.yahoo.config.provision.ClusterMembership in project vespa by vespa-engine.
the class HostSystem method allocateHosts.
public Map<HostResource, ClusterMembership> allocateHosts(ClusterSpec cluster, Capacity capacity, int groups, DeployLogger logger) {
List<HostSpec> allocatedHosts = provisioner.prepare(cluster, capacity, groups, new ProvisionDeployLogger(logger));
// TODO: Even if HostResource owns a set of memberships, we need to return a map because the caller needs the current membership.
Map<HostResource, ClusterMembership> retAllocatedHosts = new LinkedHashMap<>();
for (HostSpec spec : allocatedHosts) {
// This is needed for single node host provisioner to work in unit tests for hosted vespa applications.
HostResource host = getExistingHost(spec).orElseGet(() -> addNewHost(spec));
retAllocatedHosts.put(host, spec.membership().orElse(null));
if (!host.getFlavor().isPresent()) {
host.setFlavor(spec.flavor());
log.log(DEBUG, () -> "Host resource " + host.getHostname() + " had no flavor, setting to " + spec.flavor());
}
}
retAllocatedHosts.keySet().forEach(host -> log.log(DEBUG, () -> "Allocated host " + host.getHostname() + " with flavor " + host.getFlavor()));
return retAllocatedHosts;
}
use of com.yahoo.config.provision.ClusterMembership in project vespa by vespa-engine.
the class ContainerModelBuilder method createNodesFromHosts.
private List<Container> createNodesFromHosts(Map<HostResource, ClusterMembership> hosts, ContainerCluster cluster) {
List<Container> nodes = new ArrayList<>();
for (Map.Entry<HostResource, ClusterMembership> entry : hosts.entrySet()) {
String id = "container." + entry.getValue().index();
Container container = new Container(cluster, id, entry.getValue().retired(), entry.getValue().index());
container.setHostResource(entry.getKey());
container.initService();
nodes.add(container);
}
return nodes;
}
use of com.yahoo.config.provision.ClusterMembership in project vespa by vespa-engine.
the class ContainerModelBuilder method getHostResourceFromContentClusters.
/**
* This is used in case we are on hosted Vespa and no nodes tag is supplied:
* If there are content clusters this will pick the first host in the first cluster as the container node.
* If there are no content clusters this will return empty (such that the node can be created by the container here).
*/
private Optional<HostResource> getHostResourceFromContentClusters(ContainerCluster cluster, Element containersElement, ConfigModelContext context) {
Optional<Element> services = servicesRootOf(containersElement);
if (!services.isPresent())
return Optional.empty();
List<Element> contentServices = XML.getChildren(services.get(), "content");
if (contentServices.isEmpty())
return Optional.empty();
Element contentNodesElementOrNull = XML.getChild(contentServices.get(0), "nodes");
NodesSpecification nodesSpec;
if (contentNodesElementOrNull == null)
nodesSpec = NodesSpecification.nonDedicated(1, context.getDeployState().getWantedNodeVespaVersion());
else
nodesSpec = NodesSpecification.from(new ModelElement(contentNodesElementOrNull), context.getDeployState().getWantedNodeVespaVersion());
Map<HostResource, ClusterMembership> hosts = StorageGroup.provisionHosts(nodesSpec, contentServices.get(0).getAttribute("id"), cluster.getRoot().getHostSystem(), context.getDeployLogger());
return Optional.of(hosts.keySet().iterator().next());
}
use of com.yahoo.config.provision.ClusterMembership in project vespa by vespa-engine.
the class ModelProvisioningTest method testClusterMembership.
@Test
public void testClusterMembership() {
String xmlWithNodes = "<?xml version='1.0' encoding='utf-8' ?>" + "<services>" + " <container version='1.0' id='container1'>" + " <nodes count='1'/>" + " </container>" + "</services>";
VespaModelTester tester = new VespaModelTester();
tester.addHosts(1);
VespaModel model = tester.createModel(xmlWithNodes, true);
assertEquals(1, model.getHostSystem().getHosts().size());
HostResource host = model.getHostSystem().getHosts().iterator().next();
assertEquals(1, host.clusterMemberships().size());
ClusterMembership membership = host.clusterMemberships().iterator().next();
assertEquals("container", membership.cluster().type().name());
assertEquals("container1", membership.cluster().id().value());
}
Aggregations