Search in sources :

Example 16 with ClusterSpec

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

the class VespaModelFactoryTest method hostedVespaZoneApplicationAllocatesNodesFromNodeRepo.

@Test
public void hostedVespaZoneApplicationAllocatesNodesFromNodeRepo() {
    String hostName = "test-host-name";
    String routingClusterName = "routing-cluster";
    String hosts = "<?xml version='1.0' encoding='utf-8' ?>\n" + "<hosts>\n" + "  <host name='" + hostName + "'>\n" + "    <alias>proxy1</alias>\n" + "  </host>\n" + "</hosts>";
    String services = "<?xml version='1.0' encoding='utf-8' ?>\n" + "<services version='1.0' xmlns:deploy='vespa'>\n" + "    <admin version='2.0'>\n" + "        <adminserver hostalias='proxy1' />\n" + "    </admin>" + "    <jdisc id='" + routingClusterName + "' version='1.0'>\n" + "        <nodes type='proxy'/>\n" + "    </jdisc>\n" + "</services>";
    HostProvisioner provisionerToOverride = new HostProvisioner() {

        @Override
        public HostSpec allocateHost(String alias) {
            return new HostSpec(hostName, Collections.emptyList(), ClusterMembership.from(ClusterSpec.from(ClusterSpec.Type.admin, new ClusterSpec.Id(routingClusterName), ClusterSpec.Group.from(0), Version.fromString("6.42"), false), 0));
        }

        @Override
        public List<HostSpec> prepare(ClusterSpec cluster, Capacity capacity, int groups, ProvisionLogger logger) {
            return Collections.singletonList(new HostSpec(hostName, Collections.emptyList(), ClusterMembership.from(ClusterSpec.from(ClusterSpec.Type.container, new ClusterSpec.Id(routingClusterName), ClusterSpec.Group.from(0), Version.fromString("6.42"), false), 0)));
        }
    };
    ModelContext modelContext = createMockModelContext(hosts, services, provisionerToOverride);
    Model model = new VespaModelFactory(new NullConfigModelRegistry()).createModel(modelContext);
    List<HostInfo> allocatedHosts = new ArrayList<>(model.getHosts());
    assertThat(allocatedHosts.size(), is(1));
    HostInfo hostInfo = allocatedHosts.get(0);
    assertThat(hostInfo.getHostname(), is(hostName));
    assertTrue("Routing service should run on host " + hostName, hostInfo.getServices().stream().map(ServiceInfo::getConfigId).anyMatch(configId -> configId.contains(routingClusterName)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Capacity(com.yahoo.config.provision.Capacity) InstanceName(com.yahoo.config.provision.InstanceName) ApplicationName(com.yahoo.config.provision.ApplicationName) Version(com.yahoo.component.Version) ApplicationId(com.yahoo.config.provision.ApplicationId) ClusterMembership(com.yahoo.config.provision.ClusterMembership) HostInfo(com.yahoo.config.model.api.HostInfo) ClusterSpec(com.yahoo.config.provision.ClusterSpec) TenantName(com.yahoo.config.provision.TenantName) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Assert.assertThat(org.junit.Assert.assertThat) ProvisionLogger(com.yahoo.config.provision.ProvisionLogger) MockModelContext(com.yahoo.config.model.MockModelContext) Before(org.junit.Before) ApplicationPackage(com.yahoo.config.application.api.ApplicationPackage) Rotation(com.yahoo.config.provision.Rotation) ModelContext(com.yahoo.config.model.api.ModelContext) Assert.assertNotNull(org.junit.Assert.assertNotNull) HostSpec(com.yahoo.config.provision.HostSpec) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MockApplicationPackage(com.yahoo.config.model.test.MockApplicationPackage) NullConfigModelRegistry(com.yahoo.config.model.NullConfigModelRegistry) List(java.util.List) HostProvisioner(com.yahoo.config.model.api.HostProvisioner) ConfigServerSpec(com.yahoo.config.model.api.ConfigServerSpec) Zone(com.yahoo.config.provision.Zone) ModelCreateResult(com.yahoo.config.model.api.ModelCreateResult) Optional(java.util.Optional) Collections(java.util.Collections) Model(com.yahoo.config.model.api.Model) ServiceInfo(com.yahoo.config.model.api.ServiceInfo) HostName(com.yahoo.config.provision.HostName) ArrayList(java.util.ArrayList) ClusterSpec(com.yahoo.config.provision.ClusterSpec) HostSpec(com.yahoo.config.provision.HostSpec) MockModelContext(com.yahoo.config.model.MockModelContext) ModelContext(com.yahoo.config.model.api.ModelContext) ServiceInfo(com.yahoo.config.model.api.ServiceInfo) NullConfigModelRegistry(com.yahoo.config.model.NullConfigModelRegistry) Capacity(com.yahoo.config.provision.Capacity) ProvisionLogger(com.yahoo.config.provision.ProvisionLogger) Model(com.yahoo.config.model.api.Model) ApplicationId(com.yahoo.config.provision.ApplicationId) HostInfo(com.yahoo.config.model.api.HostInfo) HostProvisioner(com.yahoo.config.model.api.HostProvisioner) Test(org.junit.Test)

Example 17 with ClusterSpec

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

the class AclProvisioningTest method allocateNodes.

private List<Node> allocateNodes(Capacity capacity, ApplicationId applicationId) {
    ClusterSpec cluster = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("test"), Version.fromString("6.42"), false);
    List<HostSpec> prepared = tester.prepare(applicationId, cluster, capacity, 1);
    tester.activate(applicationId, new HashSet<>(prepared));
    return tester.getNodes(applicationId, Node.State.active).asList();
}
Also used : ClusterSpec(com.yahoo.config.provision.ClusterSpec) HostSpec(com.yahoo.config.provision.HostSpec)

Example 18 with ClusterSpec

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

the class DynamicDockerProvisioningTest method do_not_relocate_nodes_from_spare_if_no_where_to_reloacte_them.

/**
 * Test redeployment of nodes that violates spare headroom - but without alternatives
 * <p>
 * Setup 2 docker hosts and allocate one app with a container on each
 * No headroom defined - only 2 spares.
 * <p>
 * Initial allocation of app 1 --> final allocation:
 * <p>
 * |    |    |        |    |    |
 * |    |    |   -->  |    |    |
 * | 1a | 1b |        | 1a | 1b |
 */
@Test
public void do_not_relocate_nodes_from_spare_if_no_where_to_reloacte_them() {
    ProvisioningTester tester = new ProvisioningTester(new Zone(Environment.prod, RegionName.from("us-east")), flavorsConfig());
    tester.makeReadyNodes(2, "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(0).hostname(), flavor, 0, tester);
    addAndAssignNode(application1, "1b", dockerHosts.get(1).hostname(), flavor, 1, tester);
    // Redeploy both applications (to be agnostic on which hosts are picked as spares)
    deployapp(application1, clusterSpec1, flavor, tester, 2);
    // Assert that we have two spare nodes (two hosts that are don't have allocations)
    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(2, 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 19 with ClusterSpec

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

the class DynamicDockerProvisioningTest method reloacte_failed_nodes.

/**
 * Test an allocation workflow:
 * <p>
 * 5 Hosts of capacity 3 (2 spares)
 * - Allocate app with 3 nodes
 * - Allocate app with 2 nodes
 * - Fail host and check redistribution
 */
@Test
public void reloacte_failed_nodes() {
    ProvisioningTester tester = new ProvisioningTester(new Zone(Environment.prod, RegionName.from("us-east")), flavorsConfig());
    tester.makeReadyNodes(5, "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);
    deployapp(application1, clusterSpec1, flavor, tester, 3);
    // Application 2
    ApplicationId application2 = makeApplicationId("t2", "a2");
    ClusterSpec clusterSpec2 = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("myContent"), Version.fromString("6.100"), false);
    deployapp(application2, clusterSpec2, flavor, tester, 2);
    // Application 3
    ApplicationId application3 = makeApplicationId("t3", "a3");
    ClusterSpec clusterSpec3 = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("myContent"), Version.fromString("6.100"), false);
    deployapp(application3, clusterSpec3, flavor, tester, 2);
    // App 2 and 3 should have been allocated to the same nodes - fail on of the parent hosts from there
    String parent = tester.nodeRepository().getNodes(application2).stream().findAny().get().parentHostname().get();
    tester.nodeRepository().failRecursively(parent, Agent.system, "Testing");
    // Redeploy all applications
    deployapp(application1, clusterSpec1, flavor, tester, 3);
    deployapp(application2, clusterSpec2, flavor, tester, 2);
    deployapp(application3, clusterSpec3, flavor, tester, 2);
    Map<Integer, Integer> numberOfChildrenStat = new HashMap<>();
    for (Node node : dockerHosts) {
        int nofChildren = tester.nodeRepository().getChildNodes(node.hostname()).size();
        if (!numberOfChildrenStat.containsKey(nofChildren)) {
            numberOfChildrenStat.put(nofChildren, 0);
        }
        numberOfChildrenStat.put(nofChildren, numberOfChildrenStat.get(nofChildren) + 1);
    }
    assertEquals(3l, (long) numberOfChildrenStat.get(3));
    assertEquals(1l, (long) numberOfChildrenStat.get(0));
    assertEquals(1l, (long) numberOfChildrenStat.get(1));
}
Also used : HashMap(java.util.HashMap) 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 20 with ClusterSpec

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

the class DynamicDockerProvisioningTest method addAndAssignNode.

private Node addAndAssignNode(ApplicationId id, String hostname, String parentHostname, Flavor flavor, int index, ProvisioningTester tester) {
    Node node1a = Node.create("open1", Collections.singleton("127.0.0.100"), new HashSet<>(), hostname, Optional.of(parentHostname), flavor, NodeType.tenant);
    ClusterSpec clusterSpec = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("myContent"), Version.fromString("6.100"), false).with(Optional.of(ClusterSpec.Group.from(0)));
    ClusterMembership clusterMembership1 = ClusterMembership.from(clusterSpec, index);
    Node node1aAllocation = node1a.allocate(id, clusterMembership1, Instant.now());
    tester.nodeRepository().addNodes(Collections.singletonList(node1aAllocation));
    NestedTransaction transaction = new NestedTransaction().add(new CuratorTransaction(tester.getCurator()));
    tester.nodeRepository().activate(Collections.singletonList(node1aAllocation), transaction);
    transaction.commit();
    return node1aAllocation;
}
Also used : ClusterMembership(com.yahoo.config.provision.ClusterMembership) CuratorTransaction(com.yahoo.vespa.curator.transaction.CuratorTransaction) Node(com.yahoo.vespa.hosted.provision.Node) NestedTransaction(com.yahoo.transaction.NestedTransaction) ClusterSpec(com.yahoo.config.provision.ClusterSpec)

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