Search in sources :

Example 1 with AllocatedHosts

use of com.yahoo.config.provision.AllocatedHosts in project vespa by vespa-engine.

the class SessionPreparer method prepare.

/**
 * Prepares a session (validates, builds model, writes to zookeeper and distributes files)
 *
 * @param context                     Contains classes needed to read/write session data.
 * @param logger                      For storing logs returned in response to client.
 * @param params                      parameters controlling behaviour of prepare.
 * @param currentActiveApplicationSet Set of currently active applications.
 * @param tenantPath Zookeeper path for the tenant for this session
 * @return the config change actions that must be done to handle the activation of the models prepared.
 */
public ConfigChangeActions prepare(SessionContext context, DeployLogger logger, PrepareParams params, Optional<ApplicationSet> currentActiveApplicationSet, Path tenantPath, Instant now) {
    Preparation preparation = new Preparation(context, logger, params, currentActiveApplicationSet, tenantPath);
    preparation.preprocess();
    try {
        AllocatedHosts allocatedHosts = preparation.buildModels(now);
        preparation.makeResult(allocatedHosts);
        if (!params.isDryRun()) {
            preparation.writeStateZK();
            preparation.writeRotZK();
            preparation.distribute();
        }
        log.log(LogLevel.DEBUG, () -> "time used " + params.getTimeoutBudget().timesUsed() + " : " + params.getApplicationId());
        return preparation.result();
    } catch (OutOfCapacityException e) {
        throw e;
    } catch (IllegalArgumentException e) {
        throw new InvalidApplicationException("Invalid application package", e);
    }
}
Also used : AllocatedHosts(com.yahoo.config.provision.AllocatedHosts) OutOfCapacityException(com.yahoo.config.provision.OutOfCapacityException) InvalidApplicationException(com.yahoo.vespa.config.server.http.InvalidApplicationException)

Example 2 with AllocatedHosts

use of com.yahoo.config.provision.AllocatedHosts in project vespa by vespa-engine.

the class ZKApplicationPackageTest method testBasicZKFeed.

@Test
public void testBasicZKFeed() throws IOException {
    feed(configCurator, new File(APP));
    ZKApplicationPackage zkApp = new ZKApplicationPackage(configCurator, Path.fromString("/0"), Optional.of(new MockNodeFlavors()));
    assertTrue(Pattern.compile(".*<slobroks>.*", Pattern.MULTILINE + Pattern.DOTALL).matcher(IOUtils.readAll(zkApp.getServices())).matches());
    assertTrue(Pattern.compile(".*<alias>.*", Pattern.MULTILINE + Pattern.DOTALL).matcher(IOUtils.readAll(zkApp.getHosts())).matches());
    assertTrue(Pattern.compile(".*<slobroks>.*", Pattern.MULTILINE + Pattern.DOTALL).matcher(IOUtils.readAll(zkApp.getFile(Path.fromString("services.xml")).createReader())).matches());
    DeployState deployState = new DeployState.Builder().applicationPackage(zkApp).build(true);
    assertEquals(deployState.getSearchDefinitions().size(), 5);
    assertEquals(zkApp.searchDefinitionContents().size(), 5);
    assertEquals(IOUtils.readAll(zkApp.getRankingExpression("foo.expression")), "foo()+1\n");
    assertEquals(zkApp.getFiles(Path.fromString(""), "xml").size(), 3);
    assertEquals(zkApp.getFileReference(Path.fromString("components/file.txt")).getAbsolutePath(), "/home/vespa/test/file.txt");
    try (Reader foo = zkApp.getFile(Path.fromString("files/foo.json")).createReader()) {
        assertEquals(IOUtils.readAll(foo), "foo : foo\n");
    }
    try (Reader bar = zkApp.getFile(Path.fromString("files/sub/bar.json")).createReader()) {
        assertEquals(IOUtils.readAll(bar), "bar : bar\n");
    }
    assertTrue(zkApp.getFile(Path.createRoot()).exists());
    assertTrue(zkApp.getFile(Path.createRoot()).isDirectory());
    Version goodVersion = Version.fromIntValues(3, 0, 0);
    assertTrue(zkApp.getFileRegistryMap().containsKey(goodVersion));
    assertFalse(zkApp.getFileRegistryMap().containsKey(Version.fromIntValues(0, 0, 0)));
    assertThat(zkApp.getFileRegistryMap().get(goodVersion).fileSourceHost(), is("dummyfiles"));
    AllocatedHosts readInfo = zkApp.getAllocatedHosts().get();
    assertThat(Utf8.toString(readInfo.toJson()), is(Utf8.toString(ALLOCATED_HOSTS.toJson())));
    assertThat(readInfo.getHosts().iterator().next().flavor(), is(TEST_FLAVOR));
    assertTrue(zkApp.getDeployment().isPresent());
    assertThat(DeploymentSpec.fromXml(zkApp.getDeployment().get()).globalServiceId().get(), is("mydisc"));
}
Also used : AllocatedHosts(com.yahoo.config.provision.AllocatedHosts) DeployState(com.yahoo.config.model.deploy.DeployState) Version(com.yahoo.config.provision.Version) Reader(java.io.Reader) File(java.io.File) Test(org.junit.Test)

Example 3 with AllocatedHosts

use of com.yahoo.config.provision.AllocatedHosts in project vespa by vespa-engine.

the class VespaModelTestCase method testNoMultitenantHostExported.

@Test
public void testNoMultitenantHostExported() throws IOException, SAXException {
    ApplicationPackage applicationPackage = new MockApplicationPackage.Builder().withServices("<services version='1.0'><admin version='3.0'><nodes count='1' /></admin></services>").build();
    DeployState deployState = new DeployState.Builder().applicationPackage(applicationPackage).modelHostProvisioner(new InMemoryProvisioner(true, "host1.yahoo.com")).properties(new DeployProperties.Builder().configServerSpecs(Arrays.asList(new Configserver.Spec("cfghost", 1234, 1235, 1236))).multitenant(true).build()).build(true);
    VespaModel model = new VespaModel(new NullConfigModelRegistry(), deployState);
    AllocatedHosts info = model.allocatedHosts();
    assertEquals("Admin version 3 is ignored, and there are no other hosts to borrow for admin services", 0, info.getHosts().size());
}
Also used : AllocatedHosts(com.yahoo.config.provision.AllocatedHosts) NullConfigModelRegistry(com.yahoo.config.model.NullConfigModelRegistry) DeployState(com.yahoo.config.model.deploy.DeployState) InMemoryProvisioner(com.yahoo.config.model.provision.InMemoryProvisioner) DeployProperties(com.yahoo.config.model.deploy.DeployProperties) VespaModel(com.yahoo.vespa.model.VespaModel) FilesApplicationPackage(com.yahoo.config.model.application.provider.FilesApplicationPackage) ApplicationPackage(com.yahoo.config.application.api.ApplicationPackage) MockApplicationPackage(com.yahoo.config.model.test.MockApplicationPackage) Test(org.junit.Test)

Aggregations

AllocatedHosts (com.yahoo.config.provision.AllocatedHosts)3 DeployState (com.yahoo.config.model.deploy.DeployState)2 Test (org.junit.Test)2 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)1 NullConfigModelRegistry (com.yahoo.config.model.NullConfigModelRegistry)1 FilesApplicationPackage (com.yahoo.config.model.application.provider.FilesApplicationPackage)1 DeployProperties (com.yahoo.config.model.deploy.DeployProperties)1 InMemoryProvisioner (com.yahoo.config.model.provision.InMemoryProvisioner)1 MockApplicationPackage (com.yahoo.config.model.test.MockApplicationPackage)1 OutOfCapacityException (com.yahoo.config.provision.OutOfCapacityException)1 Version (com.yahoo.config.provision.Version)1 InvalidApplicationException (com.yahoo.vespa.config.server.http.InvalidApplicationException)1 VespaModel (com.yahoo.vespa.model.VespaModel)1 File (java.io.File)1 Reader (java.io.Reader)1