diff options
Diffstat (limited to 'config-model-api/src/main/java/com/yahoo/config/application/api')
2 files changed, 25 insertions, 68 deletions
diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationMetaData.java b/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationMetaData.java index c4dee70cd86..480d12b6700 100644 --- a/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationMetaData.java +++ b/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationMetaData.java @@ -2,14 +2,16 @@ package com.yahoo.config.application.api; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.ApplicationName; -import com.yahoo.config.provision.InstanceName; -import com.yahoo.config.provision.TenantName; -import com.yahoo.slime.*; - +import com.yahoo.slime.Cursor; +import com.yahoo.slime.Inspector; +import com.yahoo.slime.JsonDecoder; +import com.yahoo.slime.JsonFormat; +import com.yahoo.slime.Slime; import com.yahoo.text.Utf8; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; /** * Metadata about an application package. @@ -27,32 +29,6 @@ public class ApplicationMetaData { private final long generation; private final long previousActiveGeneration; - // TODO: Remove after September 2019 - public ApplicationMetaData(File appDir, - String deployedByUser, - String deployedFromDir, - Long deployTimestamp, - boolean internalRedeploy, - String checksum, - Long generation, - long previousActiveGeneration) { - this(deployedByUser, deployedFromDir, deployTimestamp, internalRedeploy, - appDir.getName(), checksum, generation, previousActiveGeneration); - } - - // TODO: Remove after September 2019 - public ApplicationMetaData(String deployedByUser, String deployedFromDir, Long deployTimestamp, boolean internalRedeploy, - String applicationName, String checksum, Long generation, long previousActiveGeneration) { - this(deployedByUser, - deployedFromDir, - deployTimestamp, - internalRedeploy, - ApplicationId.from(TenantName.defaultName(), ApplicationName.from(applicationName), InstanceName.from("default")), - checksum, - generation, - previousActiveGeneration); - } - public ApplicationMetaData(String deployedByUser, String deployedFromDir, Long deployTimestamp, boolean internalRedeploy, ApplicationId applicationId, String checksum, Long generation, long previousActiveGeneration) { this.deployedByUser = deployedByUser; @@ -66,15 +42,6 @@ public class ApplicationMetaData { } /** - * Gets the name of the application (name of the directory from which application was deployed. - * Will return null if a problem occurred while getting metadata - * - * @return application name - */ - // TODO: Remove after September 2019 - public String getApplicationName() { return applicationId.application().toString(); } - - /** * Gets the user who deployed the application. * Will return null if a problem occurred while getting metadata * @@ -117,10 +84,6 @@ public class ApplicationMetaData { public boolean isInternalRedeploy() { return internalRedeploy; } /** Returns an md5 hash of the contents of the application package */ - // TODO: Remove after September 2019 - public String getCheckSum() { return checksum; } - - /** Returns an md5 hash of the contents of the application package */ public String getChecksum() { return checksum; } /** Returns the previously active generation at the point when this application was created. */ @@ -140,18 +103,11 @@ public class ApplicationMetaData { Inspector deploy = root.field("deploy"); Inspector app = root.field("application"); - // TODO: Simplify to just ApplicationId.fromSerializedForm(app.field("id").asString()) after September 2019 - ApplicationId applicationId = app.field("id").valid() ? - ApplicationId.fromSerializedForm(app.field("id").asString()) : - ApplicationId.from(TenantName.defaultName(), - ApplicationName.from(app.field("name").asString()), - InstanceName.from("default")); - return new ApplicationMetaData(deploy.field("user").asString(), deploy.field("from").asString(), deploy.field("timestamp").asLong(), booleanField("internalRedeploy", false, deploy), - applicationId, + ApplicationId.fromSerializedForm(app.field("id").asString()), app.field("checksum").asString(), app.field("generation").asLong(), app.field("previousActiveGeneration").asLong()); @@ -170,7 +126,6 @@ public class ApplicationMetaData { deploy.setBool("internalRedeploy", internalRedeploy); Cursor app = meta.setObject("application"); app.setString("id", applicationId.serializedForm()); - app.setString("name", applicationId.application().value()); // TODO: Remove after September 2019 app.setString("checksum", checksum); app.setLong("generation", generation); app.setLong("previousActiveGeneration", previousActiveGeneration); @@ -188,7 +143,7 @@ public class ApplicationMetaData { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { new JsonFormat(false).encode(baos, slime); - return baos.toString("UTF-8"); + return baos.toString(StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException("Unable to encode metadata", e); } diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationPackage.java b/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationPackage.java index db3d391d19b..174f9bb54d7 100644 --- a/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationPackage.java +++ b/config-model-api/src/main/java/com/yahoo/config/application/api/ApplicationPackage.java @@ -36,8 +36,6 @@ import java.util.jar.JarFile; * The class hides detail as to whether the source is local files or ZooKeeper * data in config server. * - * Anyone wanting to access application data should use this interface. - * * @author Vegard Havdal */ public interface ApplicationPackage { @@ -47,7 +45,8 @@ public interface ApplicationPackage { String HOSTS = "hosts.xml"; String SERVICES = "services.xml"; - Path SEARCH_DEFINITIONS_DIR = Path.fromString("searchdefinitions"); + Path SCHEMAS_DIR = Path.fromString("schemas"); + Path SEARCH_DEFINITIONS_DIR = Path.fromString("searchdefinitions"); // Legacy addition to schemas String COMPONENT_DIR = "components"; String SEARCHCHAINS_DIR = "search/chains"; String DOCPROCCHAINS_DIR = "docproc/chains"; @@ -168,7 +167,7 @@ public interface ApplicationPackage { } /** - * Returns inforamtion about a file + * Returns information about a file * * @param relativePath the relative path of the file within this application package. * @return information abut the file, returned whether or not the file exists @@ -206,23 +205,26 @@ public interface ApplicationPackage { Reader getRankingExpression(String name); /** - * Returns the name-payload pairs of any sd files under path/searchdefinitions/ in the given jar bundle - * @param bundle The jar file, which will be closed afterwards by this method. - * @param path For example 'complex/' + * Returns the name-payload pairs of any sd files under path/schemas and path/searchdefinitions/ + * in the given jar bundle. + * + * @param bundle the jar file, which will be closed afterwards by this method + * @param path for example 'complex/' * @return map of the SD payloads * @throws IOException if it is reading sd files fails */ static Map<String, String> getBundleSdFiles(String path, JarFile bundle) throws IOException { - Map<String,String> ret = new LinkedHashMap<>(); + Map<String, String> schemas = new LinkedHashMap<>(); for (Enumeration<JarEntry> e = bundle.entries(); e.hasMoreElements();) { - JarEntry je=e.nextElement(); - if (je.getName().startsWith(path+SEARCH_DEFINITIONS_DIR+"/") && je.getName().endsWith(SD_NAME_SUFFIX)) { - String contents = IOUtils.readAll(new InputStreamReader(bundle.getInputStream(je))); - ret.put(getFileName(je), contents); + JarEntry entry = e.nextElement(); + if ((entry.getName().startsWith(path + SCHEMAS_DIR + "/") || entry.getName().startsWith(path + SEARCH_DEFINITIONS_DIR + "/")) + && entry.getName().endsWith(SD_NAME_SUFFIX)) { + String contents = IOUtils.readAll(new InputStreamReader(bundle.getInputStream(entry))); + schemas.put(getFileName(entry), contents); } } bundle.close(); - return ret; + return schemas; } /** |