use of com.yahoo.config.provision.Version in project vespa by vespa-engine.
the class ModelFactoryRegistryTest method testThatLatestVersionIsSelected.
@Test
public void testThatLatestVersionIsSelected() {
Version versionA = Version.fromIntValues(5, 38, 4);
Version versionB = Version.fromIntValues(5, 58, 1);
Version versionC = Version.fromIntValues(5, 48, 44);
Version versionD = Version.fromIntValues(5, 18, 44);
TestFactory a = new TestFactory(versionA);
TestFactory b = new TestFactory(versionB);
TestFactory c = new TestFactory(versionC);
TestFactory d = new TestFactory(versionD);
for (int i = 0; i < 100; i++) {
List<ModelFactory> randomOrder = Arrays.asList(a, b, c, d);
Collections.shuffle(randomOrder);
ModelFactoryRegistry registry = new ModelFactoryRegistry(randomOrder);
assertThat(registry.getFactory(versionA), is(a));
assertThat(registry.getFactory(versionB), is(b));
assertThat(registry.getFactory(versionC), is(c));
assertThat(registry.getFactory(versionD), is(d));
}
}
use of com.yahoo.config.provision.Version in project vespa by vespa-engine.
the class ModelsBuilder method buildModels.
/**
* Builds all applicable model versions
*
* @param allocatedHosts the newest version (major and minor) (which is loaded first) decides the allocated hosts
* and assigns to this SettableOptional such that it can be used after this method returns
*/
public List<MODELRESULT> buildModels(ApplicationId applicationId, com.yahoo.component.Version wantedNodeVespaVersion, ApplicationPackage applicationPackage, SettableOptional<AllocatedHosts> allocatedHosts, Instant now) {
Set<Version> versions = modelFactoryRegistry.allVersions();
// If the application specifies a major, load models only for that
Optional<Integer> requestedMajorVersion = applicationPackage.getMajorVersion();
if (requestedMajorVersion.isPresent())
versions = filterByMajorVersion(requestedMajorVersion.get(), versions);
// Load models by one major version at the time as new major versions are allowed to be non-loadable
// in the case where an existing application is incompatible with a new major version
// (which is possible by the definition of major)
List<Integer> majorVersions = versions.stream().map(Version::getMajor).distinct().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
List<MODELRESULT> allApplicationModels = new ArrayList<>();
for (int i = 0; i < majorVersions.size(); i++) {
try {
allApplicationModels.addAll(buildModelVersion(filterByMajorVersion(majorVersions.get(i), versions), applicationId, wantedNodeVespaVersion, applicationPackage, allocatedHosts, now));
// skip old config models if requested after we have found a major version which works
if (allApplicationModels.size() > 0 && allApplicationModels.get(0).getModel().skipOldConfigModels(now))
break;
} catch (OutOfCapacityException | ApplicationLockException e) {
// caused by the state of the system, not the model version/application combination
throw e;
} catch (RuntimeException e) {
boolean isOldestMajor = i == majorVersions.size() - 1;
if (isOldestMajor) {
if (e instanceof NullPointerException || e instanceof NoSuchElementException) {
log.log(LogLevel.WARNING, "Unexpected error when building model ", e);
throw new InternalServerException(applicationId + ": Error loading model", e);
} else {
log.log(LogLevel.WARNING, "Input error when building model ", e);
throw new IllegalArgumentException(applicationId + ": Error loading model", e);
}
} else {
log.log(Level.INFO, applicationId + ": Skipping major version " + majorVersions.get(i), e);
}
}
}
return allApplicationModels;
}
use of com.yahoo.config.provision.Version in project vespa by vespa-engine.
the class ModelsBuilder method buildModelVersion.
private List<MODELRESULT> buildModelVersion(Set<Version> versions, ApplicationId applicationId, com.yahoo.component.Version wantedNodeVespaVersion, ApplicationPackage applicationPackage, SettableOptional<AllocatedHosts> allocatedHosts, Instant now) {
Version latest = findLatest(versions);
// load latest application version
MODELRESULT latestModelVersion = buildModelVersion(modelFactoryRegistry.getFactory(latest), applicationPackage, applicationId, wantedNodeVespaVersion, allocatedHosts.asOptional(), now);
// Update with additional clusters allocated
allocatedHosts.set(latestModelVersion.getModel().allocatedHosts());
if (latestModelVersion.getModel().skipOldConfigModels(now))
return Collections.singletonList(latestModelVersion);
// load old model versions
List<MODELRESULT> allApplicationVersions = new ArrayList<>();
allApplicationVersions.add(latestModelVersion);
// clusters and the node repository provisioner as fallback.
for (Version version : versions) {
// already loaded
if (version.equals(latest))
continue;
MODELRESULT modelVersion = buildModelVersion(modelFactoryRegistry.getFactory(version), applicationPackage, applicationId, wantedNodeVespaVersion, allocatedHosts.asOptional(), now);
// Update with additional clusters allocated
allocatedHosts.set(modelVersion.getModel().allocatedHosts());
allApplicationVersions.add(modelVersion);
}
return allApplicationVersions;
}
use of com.yahoo.config.provision.Version in project vespa by vespa-engine.
the class ApplicationTest method testThatApplicationIsInitialized.
@Test
public void testThatApplicationIsInitialized() throws IOException, SAXException {
ApplicationId appId = ApplicationId.from(TenantName.defaultName(), ApplicationName.from("foobar"), InstanceName.defaultName());
ServerCache cache = new ServerCache();
Version vespaVersion = Version.fromIntValues(1, 2, 3);
Application app = new Application(new ModelStub(), cache, 1337, vespaVersion, MetricUpdater.createTestUpdater(), appId);
assertThat(app.getApplicationGeneration(), is(1337l));
assertNotNull(app.getModel());
assertThat(app.getCache(), is(cache));
assertThat(app.getId().application().value(), is("foobar"));
assertThat(app.getVespaVersion(), is(vespaVersion));
assertThat(app.toString(), is("application 'foobar', generation 1337, vespa version 1.2.3"));
}
use of com.yahoo.config.provision.Version in project vespa by vespa-engine.
the class VersionStateTest method upgrade.
@Test
public void upgrade() throws IOException {
Version unknownVersion = Version.fromIntValues(0, 0, 0);
File versionFile = tempDir.newFile();
VersionState state = new VersionState(versionFile);
assertThat(state.storedVersion(), is(unknownVersion));
assertTrue(state.isUpgraded());
state.saveNewVersion();
assertFalse(state.isUpgraded());
IOUtils.writeFile(versionFile, "badversion", false);
assertThat(state.storedVersion(), is(unknownVersion));
assertTrue(state.isUpgraded());
IOUtils.writeFile(versionFile, "5.0.0", false);
assertThat(state.storedVersion(), is(Version.fromIntValues(5, 0, 0)));
assertTrue(state.isUpgraded());
state.saveNewVersion();
assertThat(state.currentVersion(), is(state.storedVersion()));
assertFalse(state.isUpgraded());
}
Aggregations