diff options
Diffstat (limited to 'config-model/src/main')
4 files changed, 35 insertions, 43 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java index 26c658d9668..300a77d4a6b 100644 --- a/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java +++ b/config-model/src/main/java/com/yahoo/config/model/deploy/DeployState.java @@ -440,7 +440,9 @@ public class DeployState implements ConfigDefinitionStore { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); QueryProfiles queryProfiles = new QueryProfilesBuilder().build(applicationPackage, logger); SemanticRules semanticRules = new SemanticRuleBuilder().build(applicationPackage); - Application application = createApplication(rankProfileRegistry, queryProfiles, validationParameters); + Application application = new ApplicationBuilder(applicationPackage, fileRegistry, logger, properties, + rankProfileRegistry, queryProfiles.getRegistry()) + .build(! validationParameters.ignoreValidationErrors()); return new DeployState(application, rankProfileRegistry, fileRegistry, @@ -465,15 +467,6 @@ public class DeployState implements ConfigDefinitionStore { reindexing); } - private Application createApplication(RankProfileRegistry rankProfileRegistry, - QueryProfiles queryProfiles, - ValidationParameters validationParameters) { - ApplicationBuilder builder = new ApplicationBuilder(applicationPackage, fileRegistry, logger, properties, - rankProfileRegistry, queryProfiles.getRegistry()); - builder.importFromApplicationPackage(); - return builder.build(! validationParameters.ignoreValidationErrors()); - } - } } diff --git a/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java b/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java index d35349afe4a..72a8f004b22 100644 --- a/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java +++ b/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java @@ -95,8 +95,8 @@ public class MockApplicationPackage implements ApplicationPackage { /** Returns the root of this application package relative to the current dir */ protected File root() { return root; } + @SuppressWarnings("deprecation") // not redundant @Override - @SuppressWarnings("deprecation") // NOT redundant public String getApplicationName() { return "mock application"; } @@ -118,23 +118,26 @@ public class MockApplicationPackage implements ApplicationPackage { @Override public List<NamedReader> getSchemas() { ArrayList<NamedReader> readers = new ArrayList<>(); - ApplicationBuilder applicationBuilder = new ApplicationBuilder(this, - new MockFileRegistry(), - new BaseDeployLogger(), - new TestProperties(), - new RankProfileRegistry(), - queryProfileRegistry); - for (String sd : schemas) { - try { - String name = applicationBuilder.addSchema(sd).getName(); - readers.add(new NamedReader(name + ApplicationPackage.SD_NAME_SUFFIX, new StringReader(sd))); - } catch (ParseException e) { - throw new RuntimeException(e); - } - } + for (String sd : schemas) + readers.add(new NamedReader(extractSdName(sd) + ApplicationPackage.SD_NAME_SUFFIX, new StringReader(sd))); return readers; } + /** To avoid either double parsing or supplying a name explicitly */ + private String extractSdName(String sd) { + String s = sd.split("\n")[0]; + if (s.startsWith("schema")) + s = s.substring("schema".length()).trim(); + else if (s.startsWith("search")) + s = s.substring("search".length()).trim(); + else + throw new IllegalArgumentException("Expected the first line of a schema but got '" + sd + "'"); + int end = s.indexOf(' '); + if (end < 0) + end = s.indexOf('}'); + return s.substring(0, end).trim(); + } + @Override public Map<ConfigDefinitionKey, UnparsedConfigDefinition> getAllExistingConfigDefs() { return Collections.emptyMap(); diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java b/config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java index bc6df6121cd..033c0d819a1 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/ApplicationBuilder.java @@ -126,6 +126,8 @@ public class ApplicationBuilder { this.deployLogger = deployLogger; this.properties = properties; this.documentsOnly = documentsOnly; + for (NamedReader reader : applicationPackage.getSchemas()) + addSchema(reader); } /** @@ -136,19 +138,13 @@ public class ApplicationBuilder { * @throws IOException thrown if the file can not be read for some reason * @throws ParseException thrown if the file does not contain a valid search definition */ - public Schema addSchemaFile(String fileName) throws IOException, ParseException { + public Schema add(String fileName) throws IOException, ParseException { File file = new File(fileName); return addSchema(IOUtils.readFile(file), file.getAbsoluteFile().getParent()); } - private Schema addSchemaFile(Path file) throws IOException, ParseException { - return addSchemaFile(file.toString()); - } - - public void importFromApplicationPackage() { - for (NamedReader reader : applicationPackage.getSchemas()) { - importFrom(reader); - } + private Schema add(Path file) throws IOException, ParseException { + return add(file.toString()); } /** @@ -157,7 +153,7 @@ public class ApplicationBuilder { * * @param reader the reader whose content to import */ - private void importFrom(NamedReader reader) { + private void addSchema(NamedReader reader) { try { String schemaName = addSchema(IOUtils.readAll(reader), reader.getName()).getName(); String schemaFileName = stripSuffix(reader.getName(), ApplicationPackage.SD_NAME_SUFFIX); @@ -197,7 +193,7 @@ public class ApplicationBuilder { Schema schema = new SDParser(stream, applicationPackage, fileRegistry, deployLogger, properties, rankProfileRegistry, documentsOnly) .schema(documentTypeManager, schemaDir); - addSchemaFile(schema); + add(schema); return schema; } catch (TokenMgrException e) { throw new ParseException("Unknown symbol: " + e.getMessage()); @@ -214,7 +210,7 @@ public class ApplicationBuilder { * @param schema the object to import * @throws IllegalArgumentException if the given search object has already been processed */ - public void addSchemaFile(Schema schema) { + public void add(Schema schema) { if (schema.getName() == null) throw new IllegalArgumentException("Schema has no name"); schemas.add(schema); @@ -386,7 +382,7 @@ public class ApplicationBuilder { rankProfileRegistry, queryprofileRegistry); for (String fileName : fileNames) { - builder.addSchemaFile(fileName); + builder.add(fileName); } builder.build(true); return builder; @@ -427,7 +423,7 @@ public class ApplicationBuilder { rankProfileRegistry, queryProfileRegistry); for (Iterator<Path> i = Files.list(new File(dir).toPath()).filter(p -> p.getFileName().toString().endsWith(".sd")).iterator(); i.hasNext(); ) { - builder.addSchemaFile(i.next()); + builder.add(i.next()); } builder.build(true); return builder; @@ -492,13 +488,13 @@ public class ApplicationBuilder { * * @param rawSchema the raw object to build from * @return the built {@link ApplicationBuilder} object - * @see #addSchemaFile(Schema) + * @see #add(Schema) */ public static ApplicationBuilder createFromRawSchema(Schema rawSchema, RankProfileRegistry rankProfileRegistry, QueryProfileRegistry queryProfileRegistry) { ApplicationBuilder builder = new ApplicationBuilder(rankProfileRegistry, queryProfileRegistry); - builder.addSchemaFile(rawSchema); + builder.add(rawSchema); builder.build(); return builder; } @@ -508,7 +504,7 @@ public class ApplicationBuilder { * * @param rawSchema the raw object to build from * @return the built {@link Schema} object - * @see #addSchemaFile(Schema) + * @see #add(Schema) */ public static Schema buildFromRawSchema(Schema rawSchema, RankProfileRegistry rankProfileRegistry, diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/Deriver.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/Deriver.java index 475631f9241..cf9d46ae985 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/Deriver.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/Deriver.java @@ -21,7 +21,7 @@ public class Deriver { ApplicationBuilder builder = new ApplicationBuilder(); try { for (String schema : schemas) - builder.addSchemaFile(schema); + builder.add(schema); } catch (ParseException | IOException e) { throw new IllegalArgumentException(e); } |