Search in sources :

Example 1 with Version

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));
    }
}
Also used : Version(com.yahoo.config.provision.Version) ModelFactoryRegistry(com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry) ModelFactory(com.yahoo.config.model.api.ModelFactory) Test(org.junit.Test)

Example 2 with Version

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;
}
Also used : InternalServerException(com.yahoo.vespa.config.server.http.InternalServerException) ArrayList(java.util.ArrayList) OutOfCapacityException(com.yahoo.config.provision.OutOfCapacityException) ApplicationLockException(com.yahoo.config.provision.ApplicationLockException) Version(com.yahoo.config.provision.Version) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with Version

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;
}
Also used : Version(com.yahoo.config.provision.Version) ArrayList(java.util.ArrayList)

Example 4 with Version

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"));
}
Also used : ServerCache(com.yahoo.vespa.config.server.ServerCache) Version(com.yahoo.config.provision.Version) ApplicationId(com.yahoo.config.provision.ApplicationId) ModelStub(com.yahoo.vespa.config.server.ModelStub) Test(org.junit.Test)

Example 5 with Version

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());
}
Also used : Version(com.yahoo.config.provision.Version) File(java.io.File) Test(org.junit.Test)

Aggregations

Version (com.yahoo.config.provision.Version)11 Test (org.junit.Test)7 File (java.io.File)5 ModelContext (com.yahoo.config.model.api.ModelContext)2 ApplicationId (com.yahoo.config.provision.ApplicationId)2 TenantName (com.yahoo.config.provision.TenantName)2 ModelFactoryRegistry (com.yahoo.vespa.config.server.modelfactory.ModelFactoryRegistry)2 ArrayList (java.util.ArrayList)2 ConfigserverConfig (com.yahoo.cloud.config.ConfigserverConfig)1 LbServicesConfig (com.yahoo.cloud.config.LbServicesConfig)1 ApplicationInfo (com.yahoo.config.model.api.ApplicationInfo)1 HostProvisioner (com.yahoo.config.model.api.HostProvisioner)1 Model (com.yahoo.config.model.api.Model)1 ModelCreateResult (com.yahoo.config.model.api.ModelCreateResult)1 ModelFactory (com.yahoo.config.model.api.ModelFactory)1 SuperModel (com.yahoo.config.model.api.SuperModel)1 DeployState (com.yahoo.config.model.deploy.DeployState)1 AllocatedHosts (com.yahoo.config.provision.AllocatedHosts)1 ApplicationLockException (com.yahoo.config.provision.ApplicationLockException)1 OutOfCapacityException (com.yahoo.config.provision.OutOfCapacityException)1