use of com.yahoo.config.model.api.ModelContext in project vespa by vespa-engine.
the class ActivatedModelsBuilder method buildModelVersion.
@Override
protected Application buildModelVersion(ModelFactory modelFactory, ApplicationPackage applicationPackage, ApplicationId applicationId, com.yahoo.component.Version wantedNodeVespaVersion, // Ignored since we have this in the app package for activated models
Optional<AllocatedHosts> ignored, Instant now) {
log.log(LogLevel.DEBUG, String.format("Loading model version %s for session %s application %s", modelFactory.getVersion(), appGeneration, applicationId));
ServerCache cache = zkClient.loadServerCache();
ModelContext modelContext = new ModelContextImpl(applicationPackage, Optional.empty(), permanentApplicationPackage.get().applicationPackage(), logger, configDefinitionRepo, getForVersionOrLatest(applicationPackage.getFileRegistryMap(), modelFactory.getVersion()).orElse(new MockFileRegistry()), createStaticProvisioner(applicationPackage.getAllocatedHosts()), createModelContextProperties(applicationId), Optional.empty(), new com.yahoo.component.Version(modelFactory.getVersion().toString()), wantedNodeVespaVersion);
MetricUpdater applicationMetricUpdater = metrics.getOrCreateMetricUpdater(Metrics.createDimensions(applicationId));
return new Application(modelFactory.createModel(modelContext), cache, appGeneration, modelFactory.getVersion(), applicationMetricUpdater, applicationId);
}
use of com.yahoo.config.model.api.ModelContext 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.ModelContext in project vespa by vespa-engine.
the class PreparedModelsBuilder method buildModelVersion.
@Override
protected PreparedModelResult buildModelVersion(ModelFactory modelFactory, ApplicationPackage applicationPackage, ApplicationId applicationId, com.yahoo.component.Version wantedNodeVespaVersion, Optional<AllocatedHosts> allocatedHosts, Instant now) {
Version modelVersion = modelFactory.getVersion();
log.log(LogLevel.DEBUG, "Building model " + modelVersion + " for " + applicationId);
FileDistributionProvider fileDistributionProvider = fileDistributionFactory.createProvider(context.getServerDBSessionDir());
// Use empty on non-hosted systems, use already allocated hosts if available, create connection to a host provisioner otherwise
Optional<HostProvisioner> hostProvisioner = createHostProvisioner(allocatedHosts);
Optional<Model> previousModel = currentActiveApplicationSet.map(set -> set.getForVersionOrLatest(Optional.of(modelVersion), now).getModel());
ModelContext modelContext = new ModelContextImpl(applicationPackage, previousModel, permanentApplicationPackage.applicationPackage(), logger, configDefinitionRepo, fileDistributionProvider.getFileRegistry(), hostProvisioner, properties, getAppDir(applicationPackage), new com.yahoo.component.Version(modelVersion.toString()), wantedNodeVespaVersion);
log.log(LogLevel.DEBUG, "Create and validate model " + modelVersion + " for " + applicationId);
ModelCreateResult result = modelFactory.createAndValidateModel(modelContext, params.ignoreValidationErrors());
validateModelHosts(context.getHostValidator(), applicationId, result.getModel());
log.log(LogLevel.DEBUG, "Done building model " + modelVersion + " for " + applicationId);
return new PreparedModelsBuilder.PreparedModelResult(modelVersion, result.getModel(), fileDistributionProvider, result.getConfigChangeActions());
}
use of com.yahoo.config.model.api.ModelContext in project vespa by vespa-engine.
the class SessionPreparerTest method require_that_rotations_are_read_from_zookeeper_and_used.
@Test
public void require_that_rotations_are_read_from_zookeeper_and_used() throws IOException {
final Version vespaVersion = Version.fromIntValues(1, 2, 3);
final TestModelFactory modelFactory = new TestModelFactory(vespaVersion);
preparer = createPreparer(new ModelFactoryRegistry(Arrays.asList(modelFactory)), HostProvisionerProvider.empty());
final String rotations = "foo.msbe.global.vespa.yahooapis.com";
final ApplicationId applicationId = applicationId("test");
new Rotations(curator, tenantPath).writeRotationsToZooKeeper(applicationId, Collections.singleton(new Rotation(rotations)));
final PrepareParams params = new PrepareParams.Builder().applicationId(applicationId).build();
final File app = new File("src/test/resources/deploy/app");
preparer.prepare(getContext(getApplicationPackage(app)), getLogger(), params, Optional.empty(), tenantPath, Instant.now());
// check that the rotation from zookeeper were used
final ModelContext modelContext = modelFactory.getModelContext();
final Set<Rotation> rotationSet = modelContext.properties().rotations();
assertThat(rotationSet, contains(new Rotation(rotations)));
// Check that the persisted value is still the same
assertThat(readRotationsFromZK(applicationId), contains(new Rotation(rotations)));
}
use of com.yahoo.config.model.api.ModelContext in project vespa by vespa-engine.
the class ModelContextImplTest method testModelContextTest.
@Test
public void testModelContextTest() {
final Rotation rotation = new Rotation("this.is.a.mock.rotation");
final Set<Rotation> rotations = Collections.singleton(rotation);
ModelContext context = new ModelContextImpl(MockApplicationPackage.createEmpty(), Optional.empty(), Optional.empty(), new BaseDeployLogger(), new StaticConfigDefinitionRepo(), new MockFileRegistry(), Optional.empty(), new ModelContextImpl.Properties(ApplicationId.defaultId(), true, Collections.emptyList(), null, false, Zone.defaultZone(), rotations), Optional.empty(), new Version(6), new Version(6));
assertTrue(context.applicationPackage() instanceof MockApplicationPackage);
assertFalse(context.hostProvisioner().isPresent());
assertFalse(context.permanentApplicationPackage().isPresent());
assertFalse(context.previousModel().isPresent());
assertTrue(context.getFileRegistry() instanceof MockFileRegistry);
assertTrue(context.configDefinitionRepo() instanceof StaticConfigDefinitionRepo);
assertThat(context.properties().applicationId(), is(ApplicationId.defaultId()));
assertTrue(context.properties().configServerSpecs().isEmpty());
assertTrue(context.properties().multitenant());
assertTrue(context.properties().zone() instanceof Zone);
assertFalse(context.properties().hostedVespa());
assertThat(context.properties().rotations(), equalTo(rotations));
}
Aggregations