diff options
author | Jon Bratseth <jonbratseth@yahoo.com> | 2018-02-19 09:18:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-19 09:18:42 +0100 |
commit | 02e2b00608d8ffd3f6c0cbf090bdb4895a347173 (patch) | |
tree | e2d0e2598287d1c5deaec7fecf86bc9f9e7c5d37 | |
parent | 9626077ed7ff8f6f6b048b55eeeb3a3999452f01 (diff) | |
parent | 7be2c8809e4324ee119f684b30c55f45747d3b3a (diff) |
Merge pull request #5043 from vespa-engine/musum/remove-RuleConfigDeriver
Remove dead code
5 files changed, 0 insertions, 247 deletions
diff --git a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java index 391d284a325..9bfcd4ecb6d 100644 --- a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java +++ b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationPackage.java @@ -8,7 +8,6 @@ import com.yahoo.config.application.XmlPreProcessor; import com.yahoo.config.application.api.ApplicationMetaData; import com.yahoo.config.application.api.ComponentInfo; import com.yahoo.config.application.api.DeployLogger; -import com.yahoo.config.application.api.RuleConfigDeriver; import com.yahoo.config.application.api.UnparsedConfigDefinition; import com.yahoo.config.codegen.DefParser; import com.yahoo.config.application.api.ApplicationFile; @@ -669,11 +668,6 @@ public class FilesApplicationPackage implements ApplicationPackage { } @Override - public ApplicationPackage preprocess(Zone zone, RuleConfigDeriver ignored, DeployLogger logger) throws IOException, TransformerException, ParserConfigurationException, SAXException { - return preprocess(zone, logger); - } - - @Override public ApplicationPackage preprocess(Zone zone, DeployLogger logger) throws IOException, TransformerException, ParserConfigurationException, SAXException { IOUtils.recursiveDeleteDir(preprocessedDir); IOUtils.copyDirectory(appDir, preprocessedDir, -1, (dir, name) -> ! name.equals(preprocessed) && 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 c2f6dbcbf4b..fe6f7da2092 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 @@ -271,23 +271,6 @@ public interface ApplicationPackage { * will not mutate the existing application package. * * @param zone A valid {@link Zone} instance, used to decide which parts of services to keep and remove - * @param ruleConfigDeriver ignored - * @param logger A {@link DeployLogger} to add output that will be returned to the user - * - * @return A new application package instance pointing to a new location - */ - // TODO: Remove when last version in use is 6.202 - default ApplicationPackage preprocess(Zone zone, RuleConfigDeriver ruleConfigDeriver, DeployLogger logger) - throws IOException, TransformerException, ParserConfigurationException, SAXException { - throw new UnsupportedOperationException("This application package does not support preprocessing"); - } - - /** - * Preprocess an application for a given zone and return a new application package pointing to the preprocessed - * application package. This is the entry point for the multi environment application package support. This method - * will not mutate the existing application package. - * - * @param zone A valid {@link Zone} instance, used to decide which parts of services to keep and remove * @param logger A {@link DeployLogger} to add output that will be returned to the user * * @return A new application package instance pointing to a new location diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/RuleConfigDeriver.java b/config-model-api/src/main/java/com/yahoo/config/application/api/RuleConfigDeriver.java deleted file mode 100644 index 49cdd281809..00000000000 --- a/config-model-api/src/main/java/com/yahoo/config/application/api/RuleConfigDeriver.java +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.config.application.api; - -/** - * Interface to hide dependency on prelude from application package module due to semantic rules - * rewriting. - * - * @author lulf - * @since 5.22 - */ -// TODO: This is not used any more. Do a phased removal while keeping config model compatibility -public interface RuleConfigDeriver { - void derive(String ruleBaseDir, String outputDir) throws Exception; -} diff --git a/container-search/src/main/java/com/yahoo/prelude/semantics/config/RuleConfigDeriver.java b/container-search/src/main/java/com/yahoo/prelude/semantics/config/RuleConfigDeriver.java deleted file mode 100644 index b9fd6fbd51d..00000000000 --- a/container-search/src/main/java/com/yahoo/prelude/semantics/config/RuleConfigDeriver.java +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.semantics.config; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.List; - -import com.yahoo.io.IOUtils; -import com.yahoo.io.reader.NamedReader; -import com.yahoo.prelude.semantics.RuleBase; -import com.yahoo.prelude.semantics.RuleImporter; -import com.yahoo.prelude.semantics.parser.ParseException; - -/** - * Reads the rule base files in the given directory and creates a - * semantic-rules.cfg file containing those rule bases in the given output dir. - * - * @author bratseth - */ -// Note: This is not used by the config model any more and can be removed -public class RuleConfigDeriver { - - public void derive(String ruleBaseDir, String outputDir) throws IOException, ParseException { - // Validate output dir - File outputDirFile=new File(outputDir); - if (!outputDirFile.exists()) - throw new IOException("Output dir " + outputDirFile.getAbsolutePath() + - " does not exist"); - - List<RuleBase> ruleBases = derive(ruleBaseDir); - // Convert file to config - exportConfig(ruleBases,outputDir); - } - - public List<RuleBase> derive(String ruleBaseDir) throws IOException, ParseException { - // Validate the rule bases - boolean ignoreAutomatas=true; // Don't fail if they are not available in config - List<RuleBase> ruleBases = new RuleImporter(ignoreAutomatas).importDir(ruleBaseDir); - ensureZeroOrOneDefault(ruleBases); - return ruleBases; - } - - public List<RuleBase> derive(List<NamedReader> readers) throws IOException, ParseException { - // Validate the rule bases - boolean ignoreAutomatas = true; // Don't fail if they are not available in config - List<RuleBase> ruleBases = new ArrayList<>(); - RuleImporter importer = new RuleImporter(ignoreAutomatas); - for (NamedReader reader : readers) { - ruleBases.add(importer.importFromReader(reader, reader.getName(), null)); - } - ensureZeroOrOneDefault(ruleBases); - return ruleBases; - } - - private void ensureZeroOrOneDefault(List<RuleBase> ruleBases) throws ParseException { - String defaultName=null; - for (RuleBase ruleBase : ruleBases) { - if (defaultName != null && ruleBase.isDefault()) - throw new ParseException("Both '" + defaultName + "' and '" + ruleBase.getName() + - "' is marked as default, there can only be one"); - if (ruleBase.isDefault()) - defaultName = ruleBase.getName(); - } - } - - private void exportConfig(List<RuleBase> ruleBases, String outputDir) - throws IOException { - BufferedWriter writer=null; - try { - writer=IOUtils.createWriter(outputDir + "/semantic-rules.cfg","utf-8",false); - writer.write("rulebase[" + ruleBases.size() + "]\n"); - for (int i=0; i<ruleBases.size(); i++) { - RuleBase ruleBase= ruleBases.get(i); - writer.write("rulebase[" + i + "].name \"" + ruleBase.getName() + "\"\n"); - writer.write("rulebase[" + i + "].rules \""); - writeRuleBaseAsLine(ruleBase.getSource(),writer); - writer.write("\"\n"); - } - } - finally { - IOUtils.closeWriter(writer); - } - } - - private void writeRuleBaseAsLine(String file, Writer writer) throws IOException { - BufferedReader reader=null; - try { - reader=IOUtils.createReader(file,"utf-8"); - String line; - while (null!=(line=reader.readLine())) { - writer.write(line); - writer.write("\\n"); - } - } - finally { - IOUtils.closeReader(reader); - } - } - - public static void main(String[] args) { - if(args.length<2){ - System.out.println("USAGE: RuleConfigDeriver ruleBaseDir outputDir"); - System.exit(1); - } - - try { - new RuleConfigDeriver().derive(args[0],args[1]); - } - catch (Exception e) { - System.out.println("ERROR: " + collectMessage(e)); - System.exit(1); - } - } - - private static String collectMessage(Throwable e) { - if (e.getCause()==null) - return messageOrName(e); - else - return messageOrName(e) + ": " + collectMessage(e.getCause()); - } - - private static String messageOrName(Throwable e) { - if (e.getMessage()!=null) - return e.getMessage(); - else - return e.getClass().getName(); - } - -} diff --git a/container-search/src/test/java/com/yahoo/prelude/semantics/config/test/RuleConfigDeriverTestCase.java b/container-search/src/test/java/com/yahoo/prelude/semantics/config/test/RuleConfigDeriverTestCase.java deleted file mode 100644 index 49cb8017074..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/semantics/config/test/RuleConfigDeriverTestCase.java +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.semantics.config.test; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import com.yahoo.io.IOUtils; -import com.yahoo.io.reader.NamedReader; -import com.yahoo.prelude.semantics.config.RuleConfigDeriver; -import com.yahoo.prelude.semantics.parser.ParseException; - -/** - * Tests the rule config deriver by reusing the files in ../test/inheritingrules - * - * @author bratseth - */ -public class RuleConfigDeriverTestCase extends junit.framework.TestCase { - - private final String root="src/test/java/com/yahoo/prelude/semantics/test/rulebases/"; - - public RuleConfigDeriverTestCase(String name) { - super(name); - } - - public void testRuleConfig() throws IOException, ParseException { - new File("temp/ruleconfigderiver/").mkdirs(); - new RuleConfigDeriver().derive(root + "inheritingrules/","temp/ruleconfigderiver"); - assertEqualFiles(root + "semantic-rules.cfg","temp/ruleconfigderiver/semantic-rules.cfg"); - } - - public void testRuleConfigFromReader() throws IOException, ParseException { - FileReader reader = new FileReader(new File(root) + "/numbers.sr"); - NamedReader namedReader = new NamedReader("numbers", reader); - List<NamedReader> readers = new ArrayList<>(); - readers.add(namedReader); - RuleConfigDeriver deriver = new RuleConfigDeriver(); - deriver.derive(readers); - } - - protected void assertEqualFiles(String correctFileName,String checkFileName) - throws java.io.IOException { - BufferedReader correct=null; - BufferedReader check=null; - try { - correct=IOUtils.createReader(correctFileName); - check = IOUtils.createReader(checkFileName); - String correctLine; - int lineNumber=1; - while ( null != (correctLine=correct.readLine())) { - String checkLine=check.readLine(); - assertNotNull("Too few lines, in " + checkFileName + - ", first missing is\n" + lineNumber + - ": " + correctLine,checkLine); - assertTrue("\nIn " + checkFileName + ":\n" + - "Expected line " + lineNumber + ":\n" + - correctLine.replaceAll("\\\\n","\n") + - "\nGot line " + lineNumber + ":\n" + - checkLine.replaceAll("\\\\n","\n") + "\n", - correctLine.trim().equals(checkLine.trim())); - lineNumber++; - } - assertNull("Excess line(s) in " + checkFileName + " starting at " + - lineNumber, - check.readLine()); - - } - finally { - IOUtils.closeReader(correct); - IOUtils.closeReader(check); - } - } - -} |