Search in sources :

Example 1 with HostInfo

use of com.yahoo.config.model.api.HostInfo in project vespa by vespa-engine.

the class HttpProxy method get.

public HttpResponse get(Application application, String hostName, String serviceType, String relativePath) {
    HostInfo host = application.getModel().getHosts().stream().filter(hostInfo -> hostInfo.getHostname().equals(hostName)).findFirst().orElseThrow(() -> new NotFoundException("Failed to find host " + hostName));
    ServiceInfo service = host.getServices().stream().filter(serviceInfo -> serviceType.equals(serviceInfo.getServiceType())).findFirst().orElseThrow(() -> new NotFoundException("Failed to find any service of type " + serviceType + " on host " + hostName));
    // "http" and "state" seems to uniquely identify an interesting HTTP port on each service
    PortInfo port = service.getPorts().stream().filter(portInfo -> portInfo.getTags().stream().collect(Collectors.toSet()).containsAll(Stream.of("http", "state").collect(Collectors.toSet()))).findFirst().orElseThrow(() -> new NotFoundException("Failed to find HTTP state port"));
    return internalGet(host.getHostname(), port.getPort(), relativePath);
}
Also used : ServiceInfo(com.yahoo.config.model.api.ServiceInfo) PortInfo(com.yahoo.config.model.api.PortInfo) NotFoundException(com.yahoo.vespa.config.server.http.NotFoundException) HostInfo(com.yahoo.config.model.api.HostInfo)

Example 2 with HostInfo

use of com.yahoo.config.model.api.HostInfo in project vespa by vespa-engine.

the class MockModel method createContainer.

static MockModel createContainer(String hostname, int statePort) {
    ServiceInfo container = createServiceInfo(hostname, "container", "container", ClusterSpec.Type.container, statePort, "state");
    ServiceInfo serviceNoStatePort = createServiceInfo(hostname, "logserver", "logserver", ClusterSpec.Type.admin, 1234, "logtp");
    HostInfo hostInfo = new HostInfo(hostname, Arrays.asList(container, serviceNoStatePort));
    return new MockModel(Collections.singleton(hostInfo));
}
Also used : ServiceInfo(com.yahoo.config.model.api.ServiceInfo) HostInfo(com.yahoo.config.model.api.HostInfo)

Example 3 with HostInfo

use of com.yahoo.config.model.api.HostInfo in project vespa by vespa-engine.

the class ExampleModelTest method test.

@Test
public void test() {
    List<String> contentNodes = Stream.of("host1", "host2").collect(Collectors.toList());
    List<String> containerNodes = Stream.of("host3", "host4").collect(Collectors.toList());
    ApplicationInfo application = ExampleModel.createApplication("tenant", "app").addServiceCluster("product-controllers", "container-clustercontroller.1", "container-clustercontroller", contentNodes).then().addServiceCluster("product", "searchnode.1", "searchnode", contentNodes).then().addServiceCluster("admin", "slobrok.1", "slobrok", containerNodes).then().addServiceCluster("default", "container.1", "container", containerNodes).then().build();
    assertEquals("tenant.app", application.getApplicationId().toString());
    Collection<HostInfo> hostInfos = application.getModel().getHosts();
    assertEquals(containerNodes.size() + contentNodes.size(), hostInfos.size());
    HostInfo host1 = hostInfos.stream().filter(hostInfo -> hostInfo.getHostname().equals("host1")).findAny().orElseThrow(() -> new RuntimeException());
    ServiceInfo controller1 = host1.getServices().stream().filter(i -> i.getServiceType().equals("container-clustercontroller")).findAny().orElseThrow(() -> new RuntimeException());
    assertEquals("container-clustercontroller", controller1.getServiceType());
    assertEquals("configid/1", controller1.getConfigId());
    HostInfo host4 = hostInfos.stream().filter(hostInfo -> hostInfo.getHostname().equals("host4")).findAny().orElseThrow(() -> new RuntimeException());
    ServiceInfo slobrok2 = host4.getServices().stream().filter(i -> i.getServiceType().equals("slobrok")).findAny().orElseThrow(() -> new RuntimeException());
    assertEquals("configid/2", slobrok2.getConfigId());
}
Also used : ServiceInfo(com.yahoo.config.model.api.ServiceInfo) ApplicationInfo(com.yahoo.config.model.api.ApplicationInfo) HostInfo(com.yahoo.config.model.api.HostInfo) Test(org.junit.Test)

Example 4 with HostInfo

use of com.yahoo.config.model.api.HostInfo in project vespa by vespa-engine.

the class InstanceValidatorTest method mockApplicationInfo.

private ApplicationInfo mockApplicationInfo(ApplicationId appId, int numHosts, List<ServiceInfo> serviceInfo) {
    List<HostInfo> hosts = IntStream.range(0, numHosts).mapToObj(i -> new HostInfo("host-" + i + "." + appId.toShortString() + ".yahoo.com", serviceInfo)).collect(Collectors.toList());
    Model model = mock(Model.class);
    when(model.getHosts()).thenReturn(hosts);
    return new ApplicationInfo(appId, 0, model);
}
Also used : IntStream(java.util.stream.IntStream) ApplicationId(com.yahoo.config.provision.ApplicationId) HostInfo(com.yahoo.config.model.api.HostInfo) SuperModelProvider(com.yahoo.config.model.api.SuperModelProvider) SignedIdentityDocument(com.yahoo.vespa.hosted.athenz.instanceproviderservice.identitydocument.SignedIdentityDocument) HashMap(java.util.HashMap) SERVICE_PROPERTIES_DOMAIN_KEY(com.yahoo.vespa.hosted.athenz.instanceproviderservice.instanceconfirmation.InstanceValidator.SERVICE_PROPERTIES_DOMAIN_KEY) Function(java.util.function.Function) IdentityDocument(com.yahoo.vespa.hosted.athenz.instanceproviderservice.identitydocument.IdentityDocument) SERVICE_PROPERTIES_SERVICE_KEY(com.yahoo.vespa.hosted.athenz.instanceproviderservice.instanceconfirmation.InstanceValidator.SERVICE_PROPERTIES_SERVICE_KEY) Map(java.util.Map) KeyProvider(com.yahoo.vespa.hosted.athenz.instanceproviderservice.KeyProvider) ProviderUniqueId(com.yahoo.vespa.hosted.athenz.instanceproviderservice.identitydocument.ProviderUniqueId) SuperModel(com.yahoo.config.model.api.SuperModel) ApplicationInfo(com.yahoo.config.model.api.ApplicationInfo) AutoGeneratedKeyProvider(com.yahoo.vespa.hosted.athenz.instanceproviderservice.AutoGeneratedKeyProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Signature(java.security.Signature) Assert.assertTrue(org.junit.Assert.assertTrue) Utils(com.yahoo.vespa.hosted.athenz.instanceproviderservice.impl.Utils) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Base64(java.util.Base64) List(java.util.List) Stream(java.util.stream.Stream) PrivateKey(java.security.PrivateKey) Assert.assertFalse(org.junit.Assert.assertFalse) Collections(java.util.Collections) Model(com.yahoo.config.model.api.Model) ServiceInfo(com.yahoo.config.model.api.ServiceInfo) Mockito.mock(org.mockito.Mockito.mock) SuperModel(com.yahoo.config.model.api.SuperModel) Model(com.yahoo.config.model.api.Model) ApplicationInfo(com.yahoo.config.model.api.ApplicationInfo) HostInfo(com.yahoo.config.model.api.HostInfo)

Example 5 with HostInfo

use of com.yahoo.config.model.api.HostInfo 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)

Aggregations

HostInfo (com.yahoo.config.model.api.HostInfo)10 ServiceInfo (com.yahoo.config.model.api.ServiceInfo)9 Test (org.junit.Test)4 ApplicationInfo (com.yahoo.config.model.api.ApplicationInfo)3 ApplicationId (com.yahoo.config.provision.ApplicationId)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Model (com.yahoo.config.model.api.Model)2 PortInfo (com.yahoo.config.model.api.PortInfo)2 SuperModel (com.yahoo.config.model.api.SuperModel)2 Zone (com.yahoo.config.provision.Zone)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LogdConfig (com.yahoo.cloud.config.log.LogdConfig)1