Search in sources :

Example 21 with HostSpec

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

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

the class HostsXmlProvisionerTest method assertCorrectNumberOfHosts.

private void assertCorrectNumberOfHosts(Map<String, HostSpec> hostToServiceMap, int expectedHostCount) {
    Set<String> hostSet = new HashSet<>();
    for (HostSpec host : hostToServiceMap.values()) {
        hostSet.add(host.hostname());
    }
    assertThat(hostSet.size(), is(expectedHostCount));
}
Also used : HostSpec(com.yahoo.config.provision.HostSpec) HashSet(java.util.HashSet)

Example 23 with HostSpec

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

the class SingleNodeProvisionerTest method assertCorrectNumberOfHost.

private void assertCorrectNumberOfHost(Map<String, HostSpec> hostToServiceMap, int expectedHostCount) {
    Set<String> hostSet = new HashSet<>();
    for (HostSpec host : hostToServiceMap.values()) {
        hostSet.add(host.hostname());
    }
    assertThat(hostSet.size(), is(expectedHostCount));
}
Also used : HostSpec(com.yahoo.config.provision.HostSpec) HashSet(java.util.HashSet)

Example 24 with HostSpec

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

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

the class ProvisioningTest method prepare.

private SystemState prepare(ApplicationId application, int container0Size, int container1Size, int content0Size, int content1Size, boolean required, String flavor, Version wantedVersion, ProvisioningTester tester) {
    // "deploy prepare" with a two container clusters and a storage cluster having of two groups
    ClusterSpec containerCluster0 = ClusterSpec.request(ClusterSpec.Type.container, ClusterSpec.Id.from("container0"), wantedVersion, false);
    ClusterSpec containerCluster1 = ClusterSpec.request(ClusterSpec.Type.container, ClusterSpec.Id.from("container1"), wantedVersion, false);
    ClusterSpec contentCluster0 = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("content0"), wantedVersion, false);
    ClusterSpec contentCluster1 = ClusterSpec.request(ClusterSpec.Type.content, ClusterSpec.Id.from("content1"), wantedVersion, false);
    Set<HostSpec> container0 = prepare(application, containerCluster0, container0Size, 1, required, flavor, tester);
    Set<HostSpec> container1 = prepare(application, containerCluster1, container1Size, 1, required, flavor, tester);
    Set<HostSpec> content0 = prepare(application, contentCluster0, content0Size, 1, required, flavor, tester);
    Set<HostSpec> content1 = prepare(application, contentCluster1, content1Size, 1, required, flavor, tester);
    Set<HostSpec> allHosts = new HashSet<>();
    allHosts.addAll(container0);
    allHosts.addAll(container1);
    allHosts.addAll(content0);
    allHosts.addAll(content1);
    Function<Integer, Capacity> capacity = count -> Capacity.fromNodeCount(count, Optional.empty(), required);
    int expectedContainer0Size = tester.capacityPolicies().decideSize(capacity.apply(container0Size));
    int expectedContainer1Size = tester.capacityPolicies().decideSize(capacity.apply(container1Size));
    int expectedContent0Size = tester.capacityPolicies().decideSize(capacity.apply(content0Size));
    int expectedContent1Size = tester.capacityPolicies().decideSize(capacity.apply(content1Size));
    assertEquals("Hosts in each group cluster is disjunct and the total number of unretired nodes is correct", expectedContainer0Size + expectedContainer1Size + expectedContent0Size + expectedContent1Size, tester.nonRetired(allHosts).size());
    // Check cluster/group sizes
    assertEquals(expectedContainer0Size, tester.nonRetired(container0).size());
    assertEquals(expectedContainer1Size, tester.nonRetired(container1).size());
    assertEquals(expectedContent0Size, tester.nonRetired(content0).size());
    assertEquals(expectedContent1Size, tester.nonRetired(content1).size());
    // Check cluster membership
    tester.assertMembersOf(containerCluster0, container0);
    tester.assertMembersOf(containerCluster1, container1);
    tester.assertMembersOf(contentCluster0, content0);
    tester.assertMembersOf(contentCluster1, content1);
    return new SystemState(allHosts, container0, container1, content0, content1);
}
Also used : 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) ClusterSpec(com.yahoo.config.provision.ClusterSpec) Node(com.yahoo.vespa.hosted.provision.Node) ConfigserverConfig(com.yahoo.cloud.config.ConfigserverConfig) Function(java.util.function.Function) RegionName(com.yahoo.config.provision.RegionName) NameResolver(com.yahoo.vespa.hosted.provision.persistence.NameResolver) TenantName(com.yahoo.config.provision.TenantName) Curator(com.yahoo.vespa.curator.Curator) HashSet(java.util.HashSet) ReservationExpirer(com.yahoo.vespa.hosted.provision.maintenance.ReservationExpirer) History(com.yahoo.vespa.hosted.provision.node.History) NestedTransaction(com.yahoo.transaction.NestedTransaction) Duration(java.time.Duration) NodeList(com.yahoo.vespa.hosted.provision.NodeList) Assert.fail(org.junit.Assert.fail) NodeFlavors(com.yahoo.config.provision.NodeFlavors) Iterator(java.util.Iterator) Environment(com.yahoo.config.provision.Environment) Predicate(java.util.function.Predicate) OutOfCapacityException(com.yahoo.config.provision.OutOfCapacityException) JobControl(com.yahoo.vespa.hosted.provision.maintenance.JobControl) HostSpec(com.yahoo.config.provision.HostSpec) FlavorsConfig(com.yahoo.config.provisioning.FlavorsConfig) MockNameResolver(com.yahoo.vespa.hosted.provision.testutils.MockNameResolver) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) HostFilter(com.yahoo.config.provision.HostFilter) List(java.util.List) Agent(com.yahoo.vespa.hosted.provision.node.Agent) Ignore(org.junit.Ignore) Flavor(com.yahoo.config.provision.Flavor) Assert.assertFalse(org.junit.Assert.assertFalse) Zone(com.yahoo.config.provision.Zone) Optional(java.util.Optional) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Capacity(com.yahoo.config.provision.Capacity) ClusterSpec(com.yahoo.config.provision.ClusterSpec) HostSpec(com.yahoo.config.provision.HostSpec) HashSet(java.util.HashSet)

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