Search in sources :

Example 1 with HostProvisioner

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

the class DeployStateTest method testProvisionerIsSet.

@Test
public void testProvisionerIsSet() {
    DeployState.Builder builder = new DeployState.Builder();
    HostProvisioner provisioner = new InMemoryProvisioner(true, "foo.yahoo.com");
    builder.modelHostProvisioner(provisioner);
    DeployState state = builder.build(true);
    assertThat(state.getProvisioner(), is(provisioner));
}
Also used : InMemoryProvisioner(com.yahoo.config.model.provision.InMemoryProvisioner) HostProvisioner(com.yahoo.config.model.api.HostProvisioner) Test(org.junit.Test)

Example 2 with HostProvisioner

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

the class VespaModelTester method createModel.

/**
 * Creates a model using the hosts already added to this
 *
 * @param services the services xml string
 * @param failOnOutOfCapacity whether we should get an exception when not enough hosts of the requested flavor
 *        is available or if we should just silently receive a smaller allocation
 * @return the resulting model
 */
public VespaModel createModel(String services, boolean failOnOutOfCapacity, int startIndexForClusters, String... retiredHostNames) {
    VespaModelCreatorWithMockPkg modelCreatorWithMockPkg = new VespaModelCreatorWithMockPkg(null, services, ApplicationPackageUtils.generateSearchDefinition("type1"));
    ApplicationPackage appPkg = modelCreatorWithMockPkg.appPkg;
    HostProvisioner provisioner = hosted ? new InMemoryProvisioner(hostsByFlavor, failOnOutOfCapacity, startIndexForClusters, retiredHostNames) : new SingleNodeProvisioner();
    DeployProperties properties = new DeployProperties.Builder().hostedVespa(hosted).applicationId(applicationId).build();
    DeployState deployState = new DeployState.Builder().applicationPackage(appPkg).modelHostProvisioner(provisioner).properties(properties).build(true);
    return modelCreatorWithMockPkg.create(false, deployState, configModelRegistry);
}
Also used : SingleNodeProvisioner(com.yahoo.config.model.provision.SingleNodeProvisioner) VespaModelCreatorWithMockPkg(com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg) DeployState(com.yahoo.config.model.deploy.DeployState) InMemoryProvisioner(com.yahoo.config.model.provision.InMemoryProvisioner) DeployProperties(com.yahoo.config.model.deploy.DeployProperties) ApplicationPackage(com.yahoo.config.application.api.ApplicationPackage) HostProvisioner(com.yahoo.config.model.api.HostProvisioner)

Example 3 with HostProvisioner

use of com.yahoo.config.model.api.HostProvisioner 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 4 with HostProvisioner

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

the class PreparedModelsBuilder method createHostProvisioner.

// This method is an excellent demonstration of what happens when one is too liberal with Optional
// -bratseth, who had to write the below  :-\
private Optional<HostProvisioner> createHostProvisioner(Optional<AllocatedHosts> allocatedHosts) {
    Optional<HostProvisioner> nodeRepositoryProvisioner = createNodeRepositoryProvisioner(properties);
    if (!allocatedHosts.isPresent())
        return nodeRepositoryProvisioner;
    Optional<HostProvisioner> staticProvisioner = createStaticProvisioner(allocatedHosts);
    // Since we have hosts allocated this means we are on non-hosted
    if (!staticProvisioner.isPresent())
        return Optional.empty();
    // The following option should not be possible, but since there is a right action for it we can take it
    if (!nodeRepositoryProvisioner.isPresent())
        return Optional.of(new StaticProvisioner(allocatedHosts.get()));
    // previously unallocated cluster. This allows future models to stop allocate certain clusters.
    return Optional.of(new StaticProvisioner(allocatedHosts.get(), nodeRepositoryProvisioner.get()));
}
Also used : StaticProvisioner(com.yahoo.vespa.config.server.provision.StaticProvisioner) HostProvisioner(com.yahoo.config.model.api.HostProvisioner)

Example 5 with HostProvisioner

use of com.yahoo.config.model.api.HostProvisioner 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());
}
Also used : ModelCreateResult(com.yahoo.config.model.api.ModelCreateResult) ModelContextImpl(com.yahoo.vespa.config.server.deploy.ModelContextImpl) ModelContext(com.yahoo.config.model.api.ModelContext) Version(com.yahoo.config.provision.Version) Model(com.yahoo.config.model.api.Model) FileDistributionProvider(com.yahoo.vespa.config.server.filedistribution.FileDistributionProvider) HostProvisioner(com.yahoo.config.model.api.HostProvisioner)

Aggregations

HostProvisioner (com.yahoo.config.model.api.HostProvisioner)5 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)2 Model (com.yahoo.config.model.api.Model)2 ModelContext (com.yahoo.config.model.api.ModelContext)2 ModelCreateResult (com.yahoo.config.model.api.ModelCreateResult)2 InMemoryProvisioner (com.yahoo.config.model.provision.InMemoryProvisioner)2 Test (org.junit.Test)2 Version (com.yahoo.component.Version)1 MockModelContext (com.yahoo.config.model.MockModelContext)1 NullConfigModelRegistry (com.yahoo.config.model.NullConfigModelRegistry)1 ConfigServerSpec (com.yahoo.config.model.api.ConfigServerSpec)1 HostInfo (com.yahoo.config.model.api.HostInfo)1 ServiceInfo (com.yahoo.config.model.api.ServiceInfo)1 DeployProperties (com.yahoo.config.model.deploy.DeployProperties)1 DeployState (com.yahoo.config.model.deploy.DeployState)1 SingleNodeProvisioner (com.yahoo.config.model.provision.SingleNodeProvisioner)1 MockApplicationPackage (com.yahoo.config.model.test.MockApplicationPackage)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1 ApplicationName (com.yahoo.config.provision.ApplicationName)1 Capacity (com.yahoo.config.provision.Capacity)1