Skip to content

Commit

Permalink
Merge pull request #32265 from vespa-engine/hmusum/cleanup-applicatio…
Browse files Browse the repository at this point in the history
…n-metadata

Hmusum/cleanup application metadata
  • Loading branch information
hakonhall authored Aug 27, 2024
2 parents 4bd8b71 + 5798aab commit b2076d9
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import com.yahoo.config.provision.ApplicationId;

import java.util.Set;

/**
* Data generated or computed during deployment
*
Expand All @@ -14,9 +12,6 @@ public class DeployData {

private final ApplicationId applicationId;

/** The absolute path to the directory holding the application */
private final String deployedFromDir;

/** Timestamp when a deployment was made */
private final long deployTimestamp;

Expand All @@ -27,21 +22,27 @@ public class DeployData {
private final long generation;
private final long currentlyActiveGeneration;

public DeployData(String deployedFromDir,
ApplicationId applicationId,
public DeployData(ApplicationId applicationId,
Long deployTimestamp,
boolean internalRedeploy,
Long generation,
long currentlyActiveGeneration) {
this.deployedFromDir = deployedFromDir;
this.applicationId = applicationId;
this.deployTimestamp = deployTimestamp;
this.internalRedeploy = internalRedeploy;
this.generation = generation;
this.currentlyActiveGeneration = currentlyActiveGeneration;
}

public String getDeployedFromDir() { return deployedFromDir; }
//TODO: Remove when Vespa 8.401 is oldest supported version
public DeployData(String ignored,
ApplicationId applicationId,
Long deployTimestamp,
boolean internalRedeploy,
Long generation,
long currentlyActiveGeneration) {
this(applicationId, deployTimestamp, internalRedeploy, generation, currentlyActiveGeneration);
}

public long getDeployTimestamp() { return deployTimestamp; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import com.yahoo.config.application.api.ApplicationPackage;
import com.yahoo.config.application.api.ComponentInfo;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.config.application.api.DeploymentInstanceSpec;
import com.yahoo.config.application.api.DeploymentSpec;
import com.yahoo.config.application.api.UnparsedConfigDefinition;
import com.yahoo.config.codegen.DefParser;
import com.yahoo.config.model.application.AbstractApplicationPackage;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.ApplicationName;
import com.yahoo.config.provision.InstanceName;
import com.yahoo.config.provision.Tags;
import com.yahoo.config.provision.TenantName;
import com.yahoo.config.provision.Zone;
import com.yahoo.io.HexDump;
Expand Down Expand Up @@ -72,7 +70,6 @@
import java.util.logging.Logger;

import static com.yahoo.text.Lowercase.toLowerCase;
import static java.util.logging.Level.INFO;


/**
Expand Down Expand Up @@ -137,14 +134,14 @@ public static FilesApplicationPackage fromFileWithDeployData(File appDir, Deploy
}

/** Creates package from a local directory, typically deploy app */
public static FilesApplicationPackage fromFileWithDeployData(File appDir, DeployData deployData,
public static FilesApplicationPackage fromFileWithDeployData(File appDir,
DeployData deployData,
boolean includeSourceFiles) {
return new Builder(appDir).includeSourceFiles(includeSourceFiles).deployData(deployData).build();
}

private static ApplicationMetaData metaDataFromDeployData(File appDir, DeployData deployData) {
return new ApplicationMetaData(deployData.getDeployedFromDir(),
deployData.getDeployTimestamp(),
return new ApplicationMetaData(deployData.getDeployTimestamp(),
deployData.isInternalRedeploy(),
deployData.getApplicationId(),
computeCheckSum(appDir),
Expand Down Expand Up @@ -487,8 +484,7 @@ public File getAppDir() throws IOException {

private static ApplicationMetaData readMetaData(File appDir) {
String originalAppDir = preprocessed.equals(appDir.getName()) ? appDir.getParentFile().getName() : appDir.getName();
ApplicationMetaData defaultMetaData = new ApplicationMetaData("n/a",
0L,
ApplicationMetaData defaultMetaData = new ApplicationMetaData(0L,
false,
ApplicationId.from(TenantName.defaultName(),
ApplicationName.from(originalAppDir),
Expand Down
6 changes: 1 addition & 5 deletions config-model-api/abi-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@
"public"
],
"methods" : [
"public void <init>(java.lang.Long, boolean, com.yahoo.config.provision.ApplicationId, java.lang.String, java.lang.Long, long)",
"public void <init>(java.lang.String, java.lang.Long, boolean, com.yahoo.config.provision.ApplicationId, java.lang.String, java.lang.Long, long)",
"public void <init>(java.lang.String, java.lang.Long, boolean, com.yahoo.config.provision.ApplicationId, com.yahoo.config.provision.Tags, java.lang.String, java.lang.Long, long)",
"public void <init>(java.lang.String, java.lang.String, java.lang.Long, boolean, com.yahoo.config.provision.ApplicationId, java.lang.String, java.lang.Long, long)",
"public java.lang.String getDeployedByUser()",
"public com.yahoo.config.provision.Tags getTags()",
"public java.lang.String getDeployPath()",
"public com.yahoo.config.provision.ApplicationId getApplicationId()",
"public java.lang.Long getDeployTimestamp()",
Expand All @@ -88,7 +85,6 @@
"public java.lang.String toString()",
"public static com.yahoo.config.application.api.ApplicationMetaData fromJsonString(java.lang.String)",
"public com.yahoo.slime.Slime getSlime()",
"public java.lang.String asJsonString()",
"public byte[] asJsonBytes()"
],
"fields" : [ ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
package com.yahoo.config.application.api;

import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Tags;
import com.yahoo.slime.Cursor;
import com.yahoo.slime.Inspector;
import com.yahoo.slime.Slime;
import com.yahoo.slime.SlimeUtils;
import com.yahoo.text.Utf8;

import java.io.IOException;

Expand All @@ -18,17 +16,15 @@
*/
public class ApplicationMetaData {

private final String deployedFromDir;
private final long deployTimestamp;
private final boolean internalRedeploy;
private final ApplicationId applicationId;
private final String checksum;
private final long generation;
private final long previousActiveGeneration;

public ApplicationMetaData(String deployedFromDir, Long deployTimestamp, boolean internalRedeploy,
ApplicationId applicationId, String checksum, Long generation, long previousActiveGeneration) {
this.deployedFromDir = deployedFromDir;
public ApplicationMetaData(Long deployTimestamp, boolean internalRedeploy, ApplicationId applicationId,
String checksum, Long generation, long previousActiveGeneration) {
this.deployTimestamp = deployTimestamp;
this.internalRedeploy = internalRedeploy;
this.applicationId = applicationId;
Expand All @@ -37,36 +33,20 @@ public ApplicationMetaData(String deployedFromDir, Long deployTimestamp, boolean
this.previousActiveGeneration = previousActiveGeneration;
}

@Deprecated // TODO: Remove on Vespa 9
public ApplicationMetaData(String deployedFromDir, Long deployTimestamp, boolean internalRedeploy, ApplicationId applicationId,
Tags ignored, String checksum, Long generation, long previousActiveGeneration) {
this(deployedFromDir, deployTimestamp, internalRedeploy, applicationId, checksum, generation, previousActiveGeneration);
}

@Deprecated // TODO: Remove on Vespa 9
public ApplicationMetaData(String ignored, String deployedFromDir, Long deployTimestamp, boolean internalRedeploy,
//TODO: Remove when Vespa 8.401 is oldest supported version
public ApplicationMetaData(String ignored, Long deployTimestamp, boolean internalRedeploy,
ApplicationId applicationId, String checksum, Long generation, long previousActiveGeneration) {
this(deployedFromDir, deployTimestamp, internalRedeploy, applicationId, Tags.empty(), checksum, generation, previousActiveGeneration);
this(deployTimestamp, internalRedeploy, applicationId, checksum, generation, previousActiveGeneration);
}

/**
* Gets the user who deployed the application.
*
* @return username of the user who ran "deploy-application"
*/
@Deprecated // TODO: Remove in Vespa 9
public String getDeployedByUser() { return "unknown"; }

@Deprecated // TODO: Remove in Vespa 9
public Tags getTags() { return Tags.empty(); }

/**
* Gets the directory where the application was deployed from.
* Will return null if a problem occurred while getting metadata
*
* @return path to raw deploy directory (for the original application)
*/
public String getDeployPath() { return deployedFromDir; }
@Deprecated //TODO: Remove when Vespa 8.401 is oldest supported version
public String getDeployPath() { return "unknown"; }

public ApplicationId getApplicationId() { return applicationId; }

Expand Down Expand Up @@ -98,7 +78,7 @@ public ApplicationMetaData(String ignored, String deployedFromDir, Long deployTi

@Override
public String toString() {
return deployedFromDir + ", " + deployTimestamp + ", " + generation + ", " + checksum + ", " + previousActiveGeneration;
return deployTimestamp + ", " + generation + ", " + checksum + ", " + previousActiveGeneration;
}

public static ApplicationMetaData fromJsonString(String jsonString) {
Expand All @@ -108,8 +88,7 @@ public static ApplicationMetaData fromJsonString(String jsonString) {
Inspector deploy = root.field("deploy");
Inspector app = root.field("application");

return new ApplicationMetaData(deploy.field("from").asString(),
deploy.field("timestamp").asLong(),
return new ApplicationMetaData(deploy.field("timestamp").asLong(),
booleanField("internalRedeploy", false, deploy),
ApplicationId.fromSerializedForm(app.field("id").asString()),
app.field("checksum").asString(),
Expand All @@ -124,7 +103,7 @@ public Slime getSlime() {
Slime slime = new Slime();
Cursor meta = slime.setObject();
Cursor deploy = meta.setObject("deploy");
deploy.setString("from", deployedFromDir);
deploy.setString("from", "unknown");
deploy.setLong("timestamp", deployTimestamp);
deploy.setBool("internalRedeploy", internalRedeploy);
Cursor app = meta.setObject("application");
Expand All @@ -141,10 +120,6 @@ private static boolean booleanField(String fieldName, boolean defaultValue, Insp
return value.asBool();
}

public String asJsonString() {
return Utf8.toString(asJsonBytes());
}

public byte[] asJsonBytes() {
try {
return SlimeUtils.toJsonBytes(getSlime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ protected MockApplicationPackage(File root, String hosts, String services, List<
this.failOnValidateXml = failOnValidateXml;
queryProfileRegistry = new QueryProfileXMLReader().read(asNamedReaderList(queryProfileType),
asNamedReaderList(queryProfile));
applicationMetaData = new ApplicationMetaData("dir",
0L,
applicationMetaData = new ApplicationMetaData(0L,
false,
ApplicationId.from(tenantName,
ApplicationName.from(APPLICATION_NAME),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ public void getConfig(HealthMonitorConfig.Builder builder) {
public void getConfig(ApplicationMetadataConfig.Builder builder) {
if (applicationMetaData != null)
builder.name(applicationMetaData.getApplicationId().application().value()).
path(applicationMetaData.getDeployPath()).
timestamp(applicationMetaData.getDeployTimestamp()).
checksum(applicationMetaData.getChecksum()).
generation(applicationMetaData.getGeneration());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ void testMetaData() throws IOException {
String appPkg = TESTDIR + "app1";
IOUtils.copyDirectory(new File(appPkg), tmp);
ApplicationId applicationId = ApplicationId.from("tenant1", "application1", "instance1");
DeployData deployData = new DeployData("bar",
applicationId,
DeployData deployData = new DeployData(applicationId,
13L,
false,
1337L,
Expand All @@ -240,7 +239,6 @@ void testMetaData() throws IOException {
app.writeMetaData();
FilesApplicationPackage newApp = FilesApplicationPackage.fromFileWithDeployData(tmp, deployData);
ApplicationMetaData meta = newApp.getMetaData();
assertEquals("bar", meta.getDeployPath());
assertEquals(applicationId, meta.getApplicationId());
assertEquals(13L, (long) meta.getDeployTimestamp());
assertEquals(1337L, (long) meta.getGeneration());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,15 +843,14 @@ private void ensureSessionPathDoesNotExist(long sessionId) {
}
}

private ApplicationPackage createApplication(File userDir,
File configApplicationDir,
private ApplicationPackage createApplication(File configApplicationDir,
ApplicationId applicationId,
long sessionId,
Optional<Long> currentlyActiveSessionId,
boolean internalRedeploy,
Optional<DeployLogger> deployLogger) {
long deployTimestamp = System.currentTimeMillis();
DeployData deployData = new DeployData(userDir.getAbsolutePath(), applicationId, deployTimestamp, internalRedeploy,
DeployData deployData = new DeployData(applicationId, deployTimestamp, internalRedeploy,
sessionId, currentlyActiveSessionId.orElse(nonExistingActiveSessionId));
FilesApplicationPackage app = FilesApplicationPackage.fromFileWithDeployData(configApplicationDir, deployData);
validateFileExtensions(applicationId, deployLogger, app);
Expand Down Expand Up @@ -911,8 +910,7 @@ private ApplicationPackage createApplicationPackage(File applicationDirectory,
Optional<Long> activeSessionId = getActiveSessionId(applicationId);
File userApplicationDir = getSessionAppDir(sessionId);
copyApp(applicationDirectory, userApplicationDir);
ApplicationPackage applicationPackage = createApplication(applicationDirectory,
userApplicationDir,
ApplicationPackage applicationPackage = createApplication(userApplicationDir,
applicationId,
sessionId,
activeSessionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
import java.util.Set;
import java.util.logging.Level;

import static com.yahoo.config.model.application.provider.FilesApplicationPackage.fromFileWithDeployData;
import static com.yahoo.config.provision.serialization.AllocatedHostsSerializer.fromJson;
import static com.yahoo.vespa.config.server.session.SessionZooKeeperClient.getSessionPath;
import static com.yahoo.vespa.config.server.zookeeper.ZKApplication.DEFCONFIGS_ZK_SUBPATH;
import static com.yahoo.vespa.config.server.zookeeper.ZKApplication.META_ZK_PATH;
import static com.yahoo.vespa.config.server.zookeeper.ZKApplication.USERAPP_ZK_SUBPATH;
import static com.yahoo.vespa.config.server.zookeeper.ZKApplication.USER_DEFCONFIGS_ZK_SUBPATH;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand All @@ -61,13 +63,12 @@ public class ZooKeeperDeployerTest {
public void setupZK() throws IOException {
zk = new MockCurator();
ZooKeeperDeployer.Client zkc = new ZooKeeperDeployer.Client(zk, new BaseDeployLogger(), appPath);
ApplicationPackage app = FilesApplicationPackage.fromFileWithDeployData(new File("src/test/apps/zkfeed"),
new DeployData("/bar/baz",
ApplicationId.from("default", "appName", "default"),
1345L,
true,
3L,
2L));
ApplicationPackage app = fromFileWithDeployData(new File("src/test/apps/zkfeed"),
new DeployData(ApplicationId.from("default", "appName", "default"),
1345L,
true,
3L,
2L));
Map<Version, FileRegistry> fileRegistries = createFileRegistries();
app.writeMetaData();
zkc.initialize();
Expand Down Expand Up @@ -138,9 +139,8 @@ public void testFeedAppMetaDataToZooKeeper() {
assertTrue(zk.exists(appPath.append(META_ZK_PATH)));
ApplicationMetaData metaData = ApplicationMetaData.fromJsonString(
Utf8.toString(zk.getData(appPath.append(META_ZK_PATH)).get()));
assertTrue(metaData.getChecksum().length() > 0);
assertFalse(metaData.getChecksum().isEmpty());
assertTrue(metaData.isInternalRedeploy());
assertEquals("/bar/baz", metaData.getDeployPath());
assertEquals(1345, metaData.getDeployTimestamp().longValue());
assertEquals(3, metaData.getGeneration().longValue());
assertEquals(2, metaData.getPreviousActiveGeneration());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ name string default=""
user string default="unknown"

# The directory the application was deployed from
# TODO: Remove in Vespa 9
path string default=""

# The application timestamp in ms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public ContentChannel handleRequest(Request request, ResponseHandler handler) {
private static Container container() { return Container.get(); }

static JsonNode renderApplicationConfigs(ApplicationMetadataConfig metaConfig,
ApplicationUserdataConfig userConfig) {
ApplicationUserdataConfig userConfig) {
ObjectNode vespa = jsonMapper.createObjectNode();
vespa.put("version", Vtag.currentVersion.toString());

Expand Down
Loading

0 comments on commit b2076d9

Please sign in to comment.