use of com.yahoo.config.model.api.ServiceInfo 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());
}
use of com.yahoo.config.model.api.ServiceInfo in project vespa by vespa-engine.
the class InstanceValidatorTest method application_has_same_domain_and_service.
@Test
public void application_has_same_domain_and_service() {
Map<String, String> properties = new HashMap<>();
properties.put(SERVICE_PROPERTIES_DOMAIN_KEY, domain);
properties.put(SERVICE_PROPERTIES_SERVICE_KEY, service);
ServiceInfo serviceInfo = new ServiceInfo("serviceName", "type", Collections.emptyList(), properties, "confId", "hostName");
SuperModelProvider superModelProvider = mockSuperModelProvider(mockApplicationInfo(applicationId, 5, Collections.singletonList(serviceInfo)));
InstanceValidator instanceValidator = new InstanceValidator(null, superModelProvider);
assertTrue(instanceValidator.isSameIdentityAsInServicesXml(applicationId, domain, service));
}
use of com.yahoo.config.model.api.ServiceInfo 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);
}
use of com.yahoo.config.model.api.ServiceInfo 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)));
}
use of com.yahoo.config.model.api.ServiceInfo in project vespa by vespa-engine.
the class ConfigChangeActionsSlimeConverter method servicesToSlime.
private static void servicesToSlime(Cursor entryCursor, Set<ServiceInfo> services) {
Cursor servicesCursor = entryCursor.setArray("services");
for (ServiceInfo service : services) {
Cursor serviceCursor = servicesCursor.addObject();
serviceCursor.setString("serviceName", service.getServiceName());
serviceCursor.setString("serviceType", service.getServiceType());
serviceCursor.setString("configId", service.getConfigId());
serviceCursor.setString("hostName", service.getHostName());
}
}
Aggregations