Skip to content

Commit

Permalink
Merge pull request #21661 from vespa-engine/jonmv/check-wanted-versio…
Browse files Browse the repository at this point in the history
…n-instead

Check wanted version instead of newest built model
  • Loading branch information
jonmv authored Mar 11, 2022
2 parents e45640d + 970c9c0 commit ff15841
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public interface Model {
/** Returns the version of this model. */
default Version version() { return Version.emptyVersion; }

/** Returns the wanted node version of this model. */
default Version wantedNodeVersion() { return Version.emptyVersion; }

/** Returns the provisioned hosts of this. */
default Provisioned provisioned() { return new Provisioned(); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri
public static final Logger log = Logger.getLogger(VespaModel.class.getName());

private final Version version;
private final Version wantedNodeVersion;
private final ConfigModelRepo configModelRepo = new ConfigModelRepo();
private final AllocatedHosts allocatedHosts;

Expand Down Expand Up @@ -170,6 +171,7 @@ private VespaModel(ConfigModelRegistry configModelRegistry, DeployState deploySt
throws IOException, SAXException {
super("vespamodel");
version = deployState.getVespaVersion();
wantedNodeVersion = deployState.getWantedNodeVespaVersion();
fileReferencesRepository = new FileReferencesRepository(deployState.getFileRegistry());
rankingConstants = new RankingConstants(deployState.getFileRegistry(), Optional.empty());
validationOverrides = deployState.validationOverrides();
Expand Down Expand Up @@ -407,6 +409,11 @@ public Version version() {
return version;
}

@Override
public Version wantedNodeVersion() {
return wantedNodeVersion;
}

/**
* Resolves config of the given type and config id, by first instantiating the correct {@link com.yahoo.config.ConfigInstance.Builder},
* calling {@link #getConfig(com.yahoo.config.ConfigInstance.Builder, String)}. The default values used will be those of the config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,10 @@ public Set<FileReference> listFileReferences(ApplicationId applicationId) {
@Override
public boolean compatibleWith(Optional<Version> vespaVersion, ApplicationId application) {
if (vespaVersion.isEmpty()) return true;
Version latestDeployed = applicationMapper.getForVersion(application, Optional.empty(), clock.instant())
.getVespaVersion();
boolean compatibleMajor = !incompatibleMajorVersions.value().contains(latestDeployed.getMajor());
return compatibleMajor || vespaVersion.get().getMajor() == latestDeployed.getMajor();
Version wantedVersion = applicationMapper.getForVersion(application, Optional.empty(), clock.instant())
.getModel().wantedNodeVersion();
boolean compatibleMajor = ! incompatibleMajorVersions.value().contains(wantedVersion.getMajor());
return compatibleMajor || vespaVersion.get().getMajor() == wantedVersion.getMajor();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.component.Version;
import com.yahoo.component.Vtag;
import com.yahoo.concurrent.InThreadExecutorService;
import com.yahoo.concurrent.StripedExecutor;
import com.yahoo.config.model.NullConfigModelRegistry;
import com.yahoo.config.model.application.provider.FilesApplicationPackage;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.TenantName;
import com.yahoo.text.Utf8;
Expand Down Expand Up @@ -50,6 +52,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.IntStream;

import static com.yahoo.vespa.config.server.application.TenantApplications.RemoveApplicationWaiter;
Expand Down Expand Up @@ -151,37 +154,41 @@ public void require_that_application_ids_can_be_deleted() {
assertEquals(0, repo.activeApplications().size());
}

private static ApplicationSet createSet(ApplicationId id, Version version) throws IOException, SAXException {
VespaModel model = new VespaModel(new NullConfigModelRegistry(),
new DeployState.Builder().wantedNodeVespaVersion(version)
.applicationPackage(FilesApplicationPackage.fromFile(new File("src/test/apps/app")))
.build());
return ApplicationSet.from(new Application(model,
new ServerCache(),
1,
Version.emptyVersion,
MetricUpdater.createTestUpdater(),
id));
}

@Test
public void major_version_compatibility() throws Exception {
InMemoryFlagSource flagSource = new InMemoryFlagSource();
TenantApplications applications = createZKAppRepo(flagSource);
ApplicationId app1 = createApplicationId("myapp");
applications.createApplication(app1);
applications.createPutTransaction(app1, 1).commit();
VespaModel model = new VespaModel(FilesApplicationPackage.fromFile(new File("src/test/apps/app")));
Function<Version, ApplicationSet> createApplicationSet = (version) -> {
return ApplicationSet.from(new Application(model,
new ServerCache(),
1,
version,
MetricUpdater.createTestUpdater(),
app1));
};

Version deployedVersion0 = Version.fromString("6.1");
applications.activateApplication(createApplicationSet.apply(deployedVersion0), 1);
applications.activateApplication(createSet(app1, deployedVersion0), 1);
assertTrue("Empty version is compatible", applications.compatibleWith(Optional.empty(), app1));

Version nodeVersion0 = Version.fromString("6.0");
assertTrue("Lower version is compatible", applications.compatibleWith(Optional.of(nodeVersion0), app1));

Version deployedVersion1 = Version.fromString("7.1");
applications.activateApplication(createApplicationSet.apply(deployedVersion1), 1);
applications.activateApplication(createSet(app1, deployedVersion1), 1);
assertTrue("New major is compatible", applications.compatibleWith(Optional.of(nodeVersion0), app1));

flagSource.withListFlag(PermanentFlags.INCOMPATIBLE_MAJOR_VERSIONS.id(), List.of(8), Integer.class);
Version deployedVersion2 = Version.fromString("8.1");
applications.activateApplication(createApplicationSet.apply(deployedVersion2), 1);
applications.activateApplication(createSet(app1, deployedVersion2), 1);
assertFalse("New major is incompatible", applications.compatibleWith(Optional.of(nodeVersion0), app1));

Version nodeVersion1 = Version.fromString("8.0");
Expand Down

0 comments on commit ff15841

Please sign in to comment.