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);
}
}
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"));
}
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());
}
Aggregations