Search in sources :

Example 1 with ClusterSpec

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

the class HostResourceTest method assertClusterMembership.

private void assertClusterMembership(HostResource host, ClusterSpec.Type type, String id) {
    ClusterSpec membership = host.primaryClusterMembership().map(ClusterMembership::cluster).orElseThrow(() -> new RuntimeException("No cluster membership!"));
    assertEquals(type, membership.type());
    assertEquals(id, membership.id().value());
}
Also used : ClusterSpec(com.yahoo.config.provision.ClusterSpec)

Example 2 with ClusterSpec

use of com.yahoo.config.provision.ClusterSpec 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 3 with ClusterSpec

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

the class DynamicDockerProvisioningTest method relocate_nodes_from_headroom_hosts.

/**
 * Test relocation of nodes that violate headroom.
 * <p>
 * Setup 4 docker hosts and allocate one container on each (from two different applications)
 * No spares - only headroom (4xd-2)
 * <p>
 * One application is now violating headroom and need relocation
 * <p>
 * Initial allocation of app 1 and 2 --> final allocation (headroom marked as H):
 * <p>
 * | H  |  H  | H   | H   |        |    |    |    |    |
 * | H  |  H  | H1a | H1b |   -->  |    |    |    |    |
 * |    |     | 2a  | 2b  |        | 1a | 1b | 2a | 2b |
 */
@Test
public void relocate_nodes_from_headroom_hosts() {
    ProvisioningTester tester = new ProvisioningTester(new Zone(Environment.perf, RegionName.from("us-east")), flavorsConfig(true));
    tester.makeReadyNodes(4, "host-small", NodeType.host, 32);
    deployZoneApp(tester);
    List<Node> dockerHosts = tester.nodeRepository().getNodes(NodeType.host, Node.State.active);
    Flavor flavor = tester.nodeRepository().getAvailableFlavors().getFlavorOrThrow("d-1");
    // Application 1
    ApplicationId application1 = makeApplicationId("t1", "a1");
    ClusterSpec clusterSpec1 = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("myContent"), Version.fromString("6.100"), false);
    addAndAssignNode(application1, "1a", dockerHosts.get(2).hostname(), flavor, 0, tester);
    addAndAssignNode(application1, "1b", dockerHosts.get(3).hostname(), flavor, 1, tester);
    // Application 2
    ApplicationId application2 = makeApplicationId("t2", "a2");
    ClusterSpec clusterSpec2 = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("myContent"), Version.fromString("6.100"), false);
    addAndAssignNode(application2, "2a", dockerHosts.get(2).hostname(), flavor, 0, tester);
    addAndAssignNode(application2, "2b", dockerHosts.get(3).hostname(), flavor, 1, tester);
    // Redeploy one of the applications
    deployapp(application1, clusterSpec1, flavor, tester, 2);
    // Assert that the nodes are spread across all hosts (to allow headroom)
    Set<String> hostsWithChildren = new HashSet<>();
    for (Node node : tester.nodeRepository().getNodes(NodeType.tenant, Node.State.active)) {
        if (!isInactiveOrRetired(node)) {
            hostsWithChildren.add(node.parentHostname().get());
        }
    }
    Assert.assertEquals(4, hostsWithChildren.size());
}
Also used : Zone(com.yahoo.config.provision.Zone) Node(com.yahoo.vespa.hosted.provision.Node) ClusterSpec(com.yahoo.config.provision.ClusterSpec) ApplicationId(com.yahoo.config.provision.ApplicationId) Flavor(com.yahoo.config.provision.Flavor) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ClusterSpec

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

the class DynamicDockerProvisioningTest method new_docker_nodes_are_marked_as_headroom_violations.

/**
 * Test that new docker nodes that will result in headroom violations are
 * correctly marked as this.
 * <p>
 * When redeploying app1 - should not do anything (as moving app1 to host 0 and 1 would violate headroom).
 * Then redeploy app 2 - should cause a relocation.
 * <p>
 * | H  |  H  | H2a  | H2b  |         | H  |  H  |  H    |  H    |
 * | H  |  H  | H1a  | H1b  |  -->    | H  |  H  |  H1a  |  H1b  |
 * |    |     |  1a  |  1b  |         | 2a | 2b  |  1a   |  1b   |
 */
@Test
public void new_docker_nodes_are_marked_as_headroom_violations() {
    ProvisioningTester tester = new ProvisioningTester(new Zone(Environment.perf, RegionName.from("us-east")), flavorsConfig(true));
    tester.makeReadyNodes(4, "host-small", NodeType.host, 32);
    deployZoneApp(tester);
    List<Node> dockerHosts = tester.nodeRepository().getNodes(NodeType.host, Node.State.active);
    Flavor flavorD2 = tester.nodeRepository().getAvailableFlavors().getFlavorOrThrow("d-2");
    Flavor flavorD1 = tester.nodeRepository().getAvailableFlavors().getFlavorOrThrow("d-1");
    // Application 1
    ApplicationId application1 = makeApplicationId("t1", "1");
    ClusterSpec clusterSpec1 = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("myContent"), Version.fromString("6.100"), false);
    String hostParent2 = dockerHosts.get(2).hostname();
    String hostParent3 = dockerHosts.get(3).hostname();
    addAndAssignNode(application1, "1a", hostParent2, flavorD2, 0, tester);
    addAndAssignNode(application1, "1b", hostParent3, flavorD2, 1, tester);
    // Application 2
    ApplicationId application2 = makeApplicationId("t2", "2");
    ClusterSpec clusterSpec2 = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("myContent"), Version.fromString("6.100"), false);
    addAndAssignNode(application2, "2a", hostParent2, flavorD1, 0, tester);
    addAndAssignNode(application2, "2b", hostParent3, flavorD1, 1, tester);
    // Assert allocation placement - prior to re-deployment
    assertApplicationHosts(tester.nodeRepository().getNodes(application1), hostParent2, hostParent3);
    assertApplicationHosts(tester.nodeRepository().getNodes(application2), hostParent2, hostParent3);
    // Redeploy application 1
    deployapp(application1, clusterSpec1, flavorD2, tester, 2);
    // Re-assert allocation placement
    assertApplicationHosts(tester.nodeRepository().getNodes(application1), hostParent2, hostParent3);
    assertApplicationHosts(tester.nodeRepository().getNodes(application2), hostParent2, hostParent3);
    // Redeploy application 2
    deployapp(application2, clusterSpec2, flavorD1, tester, 2);
    // Now app2 should have re-located
    assertApplicationHosts(tester.nodeRepository().getNodes(application1), hostParent2, hostParent3);
    assertApplicationHosts(tester.nodeRepository().getNodes(application2), dockerHosts.get(0).hostname(), dockerHosts.get(1).hostname());
}
Also used : Zone(com.yahoo.config.provision.Zone) Node(com.yahoo.vespa.hosted.provision.Node) ClusterSpec(com.yahoo.config.provision.ClusterSpec) ApplicationId(com.yahoo.config.provision.ApplicationId) Flavor(com.yahoo.config.provision.Flavor) Test(org.junit.Test)

Example 5 with ClusterSpec

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

the class NodePrioritizerTest method relocated_nodes_are_preferred.

@Test
public void relocated_nodes_are_preferred() {
    List<Node> nodes = new ArrayList<>();
    Node parent = createParent("parent");
    Node b = createNode(parent, "b", "d2");
    nodes.add(b);
    // Only one node - should be obvious what to prefer
    Assert.assertTrue(NodePrioritizer.isPreferredNodeToBeReloacted(nodes, b, parent));
    // Two equal nodes - choose lexically
    Node a = createNode(parent, "a", "d2");
    nodes.add(a);
    Assert.assertTrue(NodePrioritizer.isPreferredNodeToBeReloacted(nodes, a, parent));
    Assert.assertFalse(NodePrioritizer.isPreferredNodeToBeReloacted(nodes, b, parent));
    // Smallest node should be preferred
    Node c = createNode(parent, "c", "d1");
    nodes.add(c);
    Assert.assertTrue(NodePrioritizer.isPreferredNodeToBeReloacted(nodes, c, parent));
    // Unallocated over allocated
    ClusterSpec spec = ClusterSpec.from(ClusterSpec.Type.content, ClusterSpec.Id.from("mycluster"), ClusterSpec.Group.from(0), Version.fromString("6.142.22"), false);
    c = c.allocate(ApplicationId.defaultId(), ClusterMembership.from(spec, 0), Instant.now());
    nodes.remove(c);
    nodes.add(c);
    Node d = createNode(parent, "d", "d1");
    nodes.add(d);
    Assert.assertTrue(NodePrioritizer.isPreferredNodeToBeReloacted(nodes, d, parent));
    Assert.assertFalse(NodePrioritizer.isPreferredNodeToBeReloacted(nodes, c, parent));
    // Container over content
    ClusterSpec spec2 = ClusterSpec.from(ClusterSpec.Type.container, ClusterSpec.Id.from("mycluster"), ClusterSpec.Group.from(0), Version.fromString("6.142.22"), false);
    d = d.allocate(ApplicationId.defaultId(), ClusterMembership.from(spec2, 0), Instant.now());
    nodes.remove(d);
    nodes.add(d);
    Assert.assertFalse(NodePrioritizer.isPreferredNodeToBeReloacted(nodes, c, parent));
    Assert.assertTrue(NodePrioritizer.isPreferredNodeToBeReloacted(nodes, d, parent));
}
Also used : Node(com.yahoo.vespa.hosted.provision.Node) ArrayList(java.util.ArrayList) ClusterSpec(com.yahoo.config.provision.ClusterSpec) Test(org.junit.Test)

Aggregations

ClusterSpec (com.yahoo.config.provision.ClusterSpec)32 Node (com.yahoo.vespa.hosted.provision.Node)23 ApplicationId (com.yahoo.config.provision.ApplicationId)20 Test (org.junit.Test)18 Zone (com.yahoo.config.provision.Zone)14 MockDeployer (com.yahoo.vespa.hosted.provision.testutils.MockDeployer)10 HashSet (java.util.HashSet)10 Flavor (com.yahoo.config.provision.Flavor)9 HostSpec (com.yahoo.config.provision.HostSpec)9 Capacity (com.yahoo.config.provision.Capacity)7 ArrayList (java.util.ArrayList)6 Version (com.yahoo.component.Version)5 ClusterMembership (com.yahoo.config.provision.ClusterMembership)5 List (java.util.List)5 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 Environment (com.yahoo.config.provision.Environment)3 NodeType (com.yahoo.config.provision.NodeType)3 RegionName (com.yahoo.config.provision.RegionName)3