VespaModelFactory implements ModelFactory { @Override public Model createModel(ModelContext modelContext) { return buildModel(createDeployState(modelContext, new ValidationParameters(ValidationParameters.IgnoreValidationErrors.TRUE))); } @Inject  VespaModelFactory(ComponentRegistry<ConfigModelPlugin> pluginRegistry,
                             ComponentRegistry<MlModelImporter> modelImporters,
                             Zone zone);  VespaModelFactory(ConfigModelRegistry configModelRegistry);  VespaModelFactory(ConfigModelRegistry configModelRegistry, Clock clock);  VespaModelFactory(Version version, ConfigModelRegistry configModelRegistry, Clock clock, Zone zone); @Override Version version(); @Override Model createModel(ModelContext modelContext); @Override ModelCreateResult createAndValidateModel(ModelContext modelContext, ValidationParameters validationParameters);  }
@Test public void testThatFactoryCanBuildModel() { VespaModelFactory modelFactory = new VespaModelFactory(new NullConfigModelRegistry()); Model model = modelFactory.createModel(testModelContext); assertNotNull(model); assertTrue(model instanceof VespaModel); }
@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>" + " <container id='" + routingClusterName + "' version='1.0'>\n" + " <nodes type='proxy'/>\n" + " </container>\n" + "</services>"; HostProvisioner provisionerToOverride = new HostProvisioner() { @Override public HostSpec allocateHost(String alias) { return new HostSpec(hostName, NodeResources.unspecified(), NodeResources.unspecified(), NodeResources.unspecified(), ClusterMembership.from(ClusterSpec.request(ClusterSpec.Type.admin, new ClusterSpec.Id(routingClusterName)).vespaVersion("6.42").build(), 0), Optional.empty(), Optional.empty(), Optional.empty()); } @Override public List<HostSpec> prepare(ClusterSpec cluster, Capacity capacity, ProvisionLogger logger) { return List.of(new HostSpec(hostName, NodeResources.unspecified(), NodeResources.unspecified(), NodeResources.unspecified(), ClusterMembership.from(ClusterSpec.request(ClusterSpec.Type.container, new ClusterSpec.Id(routingClusterName)).vespaVersion("6.42").build(), 0), Optional.empty(), Optional.empty(), Optional.empty())); } }; 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))); }