Search in sources :

Example 6 with HostSpec

use of com.yahoo.config.provision.HostSpec in project vespa by vespa-engine.

the class HostsXmlProvisionerTest method require_basic_works.

@Test
public void require_basic_works() {
    HostsXmlProvisioner hostProvisioner = createProvisioner(threeHosts);
    // 4 services, 2 host aliases, mapping to 2 host.
    List<String> aliases = createAliases();
    Map<String, HostSpec> map = allocate(hostProvisioner, aliases);
    assertCorrectNumberOfHosts(map, 2);
    for (HostSpec hostSpec : map.values()) {
        if (hostSpec.hostname().equals("test2.yahoo.com")) {
            assertThat(hostSpec.aliases().size(), is(2));
        } else {
            assertThat(hostSpec.aliases().size(), is(1));
        }
    }
    assertThat(map.size(), is(2));
    assertTrue(map.keySet().containsAll(aliases));
    // 5 services, 3 host aliases, mapping to 2 host.
    aliases = createAliases(Collections.singletonList("node3"));
    map = allocate(hostProvisioner, aliases);
    assertCorrectNumberOfHosts(map, 2);
    assertThat(map.size(), is(3));
    assertTrue(map.keySet().containsAll(aliases));
    // 5 services, 3 host aliases, mapping to 3 host.
    aliases = createAliases(Collections.singletonList("node4"));
    map = allocate(hostProvisioner, aliases);
    assertThat(map.size(), is(3));
    assertCorrectNumberOfHosts(map, 3);
    assertTrue(map.keySet().containsAll(aliases));
    assertEquals("", System.getProperty("zookeeper.vespa.clients"));
}
Also used : HostSpec(com.yahoo.config.provision.HostSpec) Test(org.junit.Test)

Example 7 with HostSpec

use of com.yahoo.config.provision.HostSpec in project vespa by vespa-engine.

the class NodeRepositoryProvisioner method asSortedHosts.

private List<HostSpec> asSortedHosts(List<Node> nodes) {
    nodes.sort(Comparator.comparingInt(node -> node.allocation().get().membership().index()));
    List<HostSpec> hosts = new ArrayList<>(nodes.size());
    for (Node node : nodes) {
        log.log(LogLevel.DEBUG, () -> "Prepared node " + node.hostname() + " - " + node.flavor());
        hosts.add(new HostSpec(node.hostname(), node.allocation().orElseThrow(IllegalStateException::new).membership(), node.flavor()));
    }
    return hosts;
}
Also used : Capacity(com.yahoo.config.provision.Capacity) ApplicationId(com.yahoo.config.provision.ApplicationId) Inject(com.google.inject.Inject) ClusterSpec(com.yahoo.config.provision.ClusterSpec) Node(com.yahoo.vespa.hosted.provision.Node) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) NodeRepository(com.yahoo.vespa.hosted.provision.NodeRepository) NodeHostFilter(com.yahoo.vespa.hosted.provision.node.filter.NodeHostFilter) ProvisionLogger(com.yahoo.config.provision.ProvisionLogger) Provisioner(com.yahoo.config.provision.Provisioner) NestedTransaction(com.yahoo.transaction.NestedTransaction) LogLevel(com.yahoo.log.LogLevel) ApplicationFilter(com.yahoo.vespa.hosted.provision.node.filter.ApplicationFilter) NodeFlavors(com.yahoo.config.provision.NodeFlavors) Environment(com.yahoo.config.provision.Environment) NodeType(com.yahoo.config.provision.NodeType) Collection(java.util.Collection) HostSpec(com.yahoo.config.provision.HostSpec) Logger(java.util.logging.Logger) HostFilter(com.yahoo.config.provision.HostFilter) List(java.util.List) Flavor(com.yahoo.config.provision.Flavor) Zone(com.yahoo.config.provision.Zone) Clock(java.time.Clock) Optional(java.util.Optional) Comparator(java.util.Comparator) Node(com.yahoo.vespa.hosted.provision.Node) ArrayList(java.util.ArrayList) HostSpec(com.yahoo.config.provision.HostSpec)

Example 8 with HostSpec

use of com.yahoo.config.provision.HostSpec in project vespa by vespa-engine.

the class InactiveAndFailedExpirerTest method inactive_and_failed_times_out.

@Test
public void inactive_and_failed_times_out() {
    ProvisioningTester tester = new ProvisioningTester(new Zone(Environment.prod, RegionName.from("us-east")));
    List<Node> nodes = tester.makeReadyNodes(2, "default");
    // Allocate then deallocate 2 nodes
    ClusterSpec cluster = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("test"), Version.fromString("6.42"), false);
    List<HostSpec> preparedNodes = tester.prepare(applicationId, cluster, Capacity.fromNodeCount(2), 1);
    tester.activate(applicationId, new HashSet<>(preparedNodes));
    assertEquals(2, tester.getNodes(applicationId, Node.State.active).size());
    tester.deactivate(applicationId);
    List<Node> inactiveNodes = tester.getNodes(applicationId, Node.State.inactive).asList();
    assertEquals(2, inactiveNodes.size());
    // Inactive times out
    tester.advanceTime(Duration.ofMinutes(14));
    new InactiveExpirer(tester.nodeRepository(), tester.clock(), Duration.ofMinutes(10), new JobControl(tester.nodeRepository().database())).run();
    assertEquals(0, tester.nodeRepository().getNodes(Node.State.inactive).size());
    List<Node> dirty = tester.nodeRepository().getNodes(Node.State.dirty);
    assertEquals(2, dirty.size());
    assertFalse(dirty.get(0).allocation().isPresent());
    assertFalse(dirty.get(1).allocation().isPresent());
    // One node is set back to ready
    Node ready = tester.nodeRepository().setReady(Collections.singletonList(dirty.get(0)), Agent.system, getClass().getSimpleName()).get(0);
    assertEquals("Allocated history is removed on readying", Arrays.asList(History.Event.Type.provisioned, History.Event.Type.readied), ready.history().events().stream().map(History.Event::type).collect(Collectors.toList()));
    // Dirty times out for the other one
    tester.advanceTime(Duration.ofMinutes(14));
    new DirtyExpirer(tester.nodeRepository(), tester.clock(), Duration.ofMinutes(10), new JobControl(tester.nodeRepository().database())).run();
    assertEquals(0, tester.nodeRepository().getNodes(NodeType.tenant, Node.State.dirty).size());
    List<Node> failed = tester.nodeRepository().getNodes(NodeType.tenant, Node.State.failed);
    assertEquals(1, failed.size());
    assertEquals(1, failed.get(0).status().failCount());
}
Also used : Zone(com.yahoo.config.provision.Zone) Node(com.yahoo.vespa.hosted.provision.Node) ProvisioningTester(com.yahoo.vespa.hosted.provision.provisioning.ProvisioningTester) ClusterSpec(com.yahoo.config.provision.ClusterSpec) HostSpec(com.yahoo.config.provision.HostSpec) Test(org.junit.Test)

Example 9 with HostSpec

use of com.yahoo.config.provision.HostSpec in project vespa by vespa-engine.

the class Activator method updateFrom.

/**
 * Returns the input nodes with the changes resulting from applying the settings in hosts to the given list of nodes.
 */
private List<Node> updateFrom(Collection<HostSpec> hosts, List<Node> nodes) {
    List<Node> updated = new ArrayList<>();
    for (Node node : nodes) {
        HostSpec hostSpec = getHost(node.hostname(), hosts);
        node = hostSpec.membership().get().retired() ? node.retire(nodeRepository.clock().instant()) : node.unretire();
        node = node.with(node.allocation().get().with(hostSpec.membership().get()));
        if (// Docker nodes may change flavor
        hostSpec.flavor().isPresent())
            node = node.with(hostSpec.flavor().get());
        updated.add(node);
    }
    return updated;
}
Also used : Node(com.yahoo.vespa.hosted.provision.Node) ArrayList(java.util.ArrayList) HostSpec(com.yahoo.config.provision.HostSpec)

Example 10 with HostSpec

use of com.yahoo.config.provision.HostSpec in project vespa by vespa-engine.

the class DynamicDockerProvisioningTest method spare_capacity_used_only_when_replacement.

@Test
public void spare_capacity_used_only_when_replacement() {
    // Use spare capacity only when replacement (i.e one node is failed)
    // Test should allocate as much capacity as possible, verify that it is not possible to allocate one more unit
    // Verify that there is still capacity (available spare)
    // Fail one node and redeploy, Verify that one less node is empty.
    ProvisioningTester tester = new ProvisioningTester(new Zone(Environment.prod, RegionName.from("us-east")), flavorsConfig());
    // Only run test if there _is_ spare capacity
    if (tester.provisioner().getSpareCapacityProd() == 0) {
        return;
    }
    // Setup test
    ApplicationId application1 = tester.makeApplicationId();
    tester.makeReadyNodes(5, "host-small", NodeType.host, 32);
    deployZoneApp(tester);
    Flavor flavor = tester.nodeRepository().getAvailableFlavors().getFlavorOrThrow("d-3");
    // Deploy initial state (can max deploy 3 nodes due to redundancy requirements)
    List<HostSpec> hosts = tester.prepare(application1, ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("myContent"), Version.fromString("6.100"), false), 3, 1, flavor.canonicalName());
    tester.activate(application1, ImmutableSet.copyOf(hosts));
    DockerHostCapacity capacity = new DockerHostCapacity(tester.nodeRepository().getNodes(Node.State.values()));
    assertThat(capacity.freeCapacityInFlavorEquivalence(flavor), greaterThan(0));
    List<Node> initialSpareCapacity = findSpareCapacity(tester);
    assertThat(initialSpareCapacity.size(), is(2));
    try {
        hosts = tester.prepare(application1, ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("myContent"), Version.fromString("6.100"), false), 4, 1, flavor.canonicalName());
        fail("Was able to deploy with 4 nodes, should not be able to use spare capacity");
    } catch (OutOfCapacityException e) {
    }
    tester.fail(hosts.get(0));
    hosts = tester.prepare(application1, ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("myContent"), Version.fromString("6.100"), false), 3, 1, flavor.canonicalName());
    tester.activate(application1, ImmutableSet.copyOf(hosts));
    List<Node> finalSpareCapacity = findSpareCapacity(tester);
    assertThat(finalSpareCapacity.size(), is(1));
}
Also used : Zone(com.yahoo.config.provision.Zone) Node(com.yahoo.vespa.hosted.provision.Node) OutOfCapacityException(com.yahoo.config.provision.OutOfCapacityException) ApplicationId(com.yahoo.config.provision.ApplicationId) HostSpec(com.yahoo.config.provision.HostSpec) Flavor(com.yahoo.config.provision.Flavor) Test(org.junit.Test)

Aggregations

HostSpec (com.yahoo.config.provision.HostSpec)33 Test (org.junit.Test)18 Zone (com.yahoo.config.provision.Zone)14 ApplicationId (com.yahoo.config.provision.ApplicationId)13 Node (com.yahoo.vespa.hosted.provision.Node)12 ClusterSpec (com.yahoo.config.provision.ClusterSpec)10 HashSet (java.util.HashSet)7 NestedTransaction (com.yahoo.transaction.NestedTransaction)6 Version (com.yahoo.component.Version)5 Capacity (com.yahoo.config.provision.Capacity)5 Flavor (com.yahoo.config.provision.Flavor)5 List (java.util.List)5 ClusterMembership (com.yahoo.config.provision.ClusterMembership)4 Environment (com.yahoo.config.provision.Environment)4 OutOfCapacityException (com.yahoo.config.provision.OutOfCapacityException)4 Collections (java.util.Collections)4 RegionName (com.yahoo.config.provision.RegionName)3 NodeList (com.yahoo.vespa.hosted.provision.NodeList)3 JobControl (com.yahoo.vespa.hosted.provision.maintenance.JobControl)3 Agent (com.yahoo.vespa.hosted.provision.node.Agent)3