Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change to use ClassNameInventory file naming convention #690

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/emissary/admin/PlaceStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public class PlaceStarter {

static {
try {
classConf = ConfigUtil.getMasterClassNames();
classConf = ConfigUtil.getClassNameInventory();
} catch (IOException | EmissaryException iox) {
logger.error("Missing MasterClassNames.cfg: all places will become " + defaultClassName
logger.error("Missing ClassNameInventory.cfg: all places will become " + defaultClassName
+ " which is probably not what you want. Config is now " + System.getProperty(ConfigUtil.CONFIG_DIR_PROPERTY), iox);
System.exit(1);
}
Expand Down Expand Up @@ -185,7 +185,7 @@ public static String getClassString(final String theLocation) {
}
final List<String> classStringList = classConf.findEntries(thePlaceName);
if (classStringList.isEmpty()) {
logger.error("Need a CLASS config entry for {} check entry in emissary.admin.MasterClassNames.cfg, using default "
logger.error("Need a CLASS config entry for {} check entry in emissary.admin.ClassNameInventory.cfg, using default "
+ "{} which is probably not what you want.", thePlaceName, defaultClassName);
return defaultClassName;
}
Expand Down
44 changes: 22 additions & 22 deletions src/main/java/emissary/config/ConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class ConfigUtil {
/** Constant string for files that end with {@value} */
public static final String JS_FILE_ENDING = ResourceReader.JS_SUFFIX;

/** Constant string for master files name prefix */
public static final String MASTER_FILE_PREFIX = "emissary.admin.MasterClassNames";
/** Constant string for inventory files name prefix */
public static final String INVENTORY_FILE_PREFIX = "emissary.admin.ClassNameInventory";

/**
* This property specifies the config override directory. When present, we look here first for config info. If not
Expand Down Expand Up @@ -532,39 +532,39 @@ public static InputStream getConfigData(final String f) throws IOException {
}

/**
* Gets all MasterClassNames from configured file.
* Gets all ClassNameInventory from configured file.
* <p>
* For a single entry in 'emissary.config.dir' or comma separated list of config directories, every file that starts
* with 'emissary.admin.MasterClassNames' will be combined into a Configurator. This means files like
* 'emissary.admin.MasterClassNames.cfg', 'emissary.admin.MasterClassNames-module1.cfg' and
* 'emissary.admin.MasterClassNames-whatever.cfg' will be used. The concept of flavoring no longer applies to the
* MasterClassNames.
* with 'emissary.admin.ClassNameInventory' will be combined into a Configurator. This means files like
* 'emissary.admin.ClassNameInventory.cfg', 'emissary.admin.ClassNameInventory-module1.cfg' and
* 'emissary.admin.ClassNameInventory-whatever.cfg' will be used. The concept of flavoring no longer applies to the
* ClassNameInventory.
*
* @return Configurator with all emissary.admin.MasterClassNames
* @return Configurator with all emissary.admin.ClassNameInventory
* @throws IOException If there is some I/O problem.
* @throws EmissaryException If no config files are found.
*/
public static Configurator getMasterClassNames() throws IOException, EmissaryException {
final List<File> masterClassNames = new ArrayList<>();
public static Configurator getClassNameInventory() throws IOException, EmissaryException {
final List<File> classNameInventory = new ArrayList<>();
for (final String dir : getConfigDirs()) {
final File[] files = new File(dir).listFiles((dir1, name) -> name.startsWith(MASTER_FILE_PREFIX) && name.endsWith(CONFIG_FILE_ENDING));
// sort the files, to put emissary.admin.MasterClassNames.cfg before emissary.admin.MasterClassNames-blah.cfg
final File[] files = new File(dir).listFiles((dir1, name) -> name.startsWith(INVENTORY_FILE_PREFIX) && name.endsWith(CONFIG_FILE_ENDING));
// sort the files, to put emissary.admin.ClassNameInventory.cfg before emissary.admin.ClassNameInventory-blah.cfg
if (files != null) {
Arrays.sort(files);
masterClassNames.addAll(Arrays.asList(files));
classNameInventory.addAll(Arrays.asList(files));
}
}
// check to make sure we have at least one
if (masterClassNames.isEmpty()) {
throw new EmissaryException(String.format("No %s%s files found. No places to start.", MASTER_FILE_PREFIX, CONFIG_FILE_ENDING));
if (classNameInventory.isEmpty()) {
throw new EmissaryException(String.format("No %s%s files found. No places to start.", INVENTORY_FILE_PREFIX, CONFIG_FILE_ENDING));
}

ServiceConfigGuide scg = null;
for (final File f : masterClassNames) {
for (final File f : classNameInventory) {
if (!f.exists() || !f.canRead()) {
logger.warn("Could not read MasterClassNames from {}", f.getAbsolutePath());
logger.warn("Could not read ClassNameInventory from {}", f.getAbsolutePath());
} else {
logger.debug("Reading MasterClassNames from {}", f.getAbsolutePath());
logger.debug("Reading ClassNameInventory from {}", f.getAbsolutePath());
}
if (null != configFlavors) {
final String cfgFlavor = getFlavorsFromCfgFile(f);
Expand All @@ -573,14 +573,14 @@ public static Configurator getMasterClassNames() throws IOException, EmissaryExc
}
}
if (scg == null) { // first one
scg = new ServiceConfigGuide(Files.newInputStream(f.toPath()), "MasterClassNames");
scg = new ServiceConfigGuide(Files.newInputStream(f.toPath()), "ClassNameInventory");
} else {
final Set<String> existingKeys = scg.entryKeys();
final Configurator scgToMerge = new ServiceConfigGuide(Files.newInputStream(f.toPath()), "MasterClassNames");
final Configurator scgToMerge = new ServiceConfigGuide(Files.newInputStream(f.toPath()), "ClassNameInventory");
boolean noErrorsForFile = true;
for (final String key : scgToMerge.entryKeys()) {
if (existingKeys.contains(key)) {
logger.error("Tried to overwrite existing key from MasterClassNames:{} in {}", key, f.getAbsolutePath());
logger.error("Tried to overwrite existing key from ClassNameInventory:{} in {}", key, f.getAbsolutePath());
noErrorsForFile = false;
// System.exit(43); // this is swallowed in JettyServer in jetty 6
}
Expand Down Expand Up @@ -614,7 +614,7 @@ static String getFlavorsFromCfgFile(final File f) {
return "";
}
if (parts.length > 2) {
logger.warn("Filename {} had multiple - characters, using the last to determin the flavor", filename);
logger.warn("Filename {} had multiple - characters, using the last to determine the flavor", filename);
}
return parts[parts.length - 1].replaceAll(".cfg", "");
}
Expand Down
70 changes: 35 additions & 35 deletions src/test/java/emissary/config/ConfigUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,31 +380,31 @@ void testInitializeWithMultipleConfigDirs() throws EmissaryException, IOExceptio
}

@Test
void testMasterClassNamesOneFile() throws IOException, EmissaryException {
void testClassNameInventoryOneFile() throws IOException, EmissaryException {
// read in current file
// figure out number of entries

emissary.config.ConfigUtil.initialize();

final Configurator c = ConfigUtil.getMasterClassNames();
final Configurator c = ConfigUtil.getClassNameInventory();
assertNotNull(c, "Configurator should not be null");
}

@Test
void testMasterClassNamesMultipleFiles() throws IOException, EmissaryException {
void testClassNameInventoryMultipleFiles() throws IOException, EmissaryException {
final String contents1 = "DevNullPlace = \"emissary.place.sample.DevNullPlace\"\n";
createFileAndPopulate(CDIR, "emissary.admin.MasterClassNames-core.cfg", contents1);
createFileAndPopulate(CDIR, "emissary.admin.ClassNameInventory-core.cfg", contents1);

final String one = "Dev2NullPlace = \"emissary.place.donotpickme.DevNullPlace\"\n";
final String two = "DirectoryPlace = \"emissary.directory.DirectoryPlace\"";
createFileAndPopulate(CDIR, "emissary.admin.MasterClassNames-modeone.cfg", one + two);
createFileAndPopulate(CDIR, "emissary.admin.ClassNameInventory-modeone.cfg", one + two);

final String three = "Dev3NullPlace = \"emissary.place.iamtheone.DevNullPlace\"\n";
createFileAndPopulate(CDIR, "emissary.admin.MasterClassNames-modetwo.cfg", three);
createFileAndPopulate(CDIR, "emissary.admin.ClassNameInventory-modetwo.cfg", three);

emissary.config.ConfigUtil.initialize();

final Configurator c = ConfigUtil.getMasterClassNames();
final Configurator c = ConfigUtil.getClassNameInventory();
assertNotNull(c, "Configurator should not be null");
assertEquals(4, c.entryKeys().size(), "Should have 4 entries");
assertEquals("emissary.place.sample.DevNullPlace", c.findStringEntry("DevNullPlace"), "Should have set DevNullPlace");
Expand All @@ -413,54 +413,54 @@ void testMasterClassNamesMultipleFiles() throws IOException, EmissaryException {
}

@Test
void testNoMasterClassNamesFilesExist() throws EmissaryException, IOException {
void testNoClassNameInventoryFilesExist() throws EmissaryException, IOException {

final Path noCfgsFolder = createTmpSubDir("folder_with_no_cfg_files");

System.setProperty(CONFIG_DIR_PROPERTY, String.valueOf(noCfgsFolder.toAbsolutePath()));
emissary.config.ConfigUtil.initialize();

EmissaryException thrown = assertThrows(EmissaryException.class, () -> {
final Configurator c = ConfigUtil.getMasterClassNames();
final Configurator c = ConfigUtil.getClassNameInventory();
});

assertTrue(thrown.getMessage().contains("No places to start."));
}

@Test
void testOldMasterClassNamesFileExistsButIsIgnored() throws EmissaryException, IOException {
void testOldClassNameInventoryFileExistsButIsIgnored() throws EmissaryException, IOException {

// create a config file using old/deprecated file name convention MasterClassNames.cfg
// create a config file using old/deprecated file name convention ClassNameInventory.cfg
final Path oldCfgsFolder = createTmpSubDir("folder_with_old_cfg_file_name");

final String contents = "DevNullPlace = \"emissary.place.sample.DevNullPlace\"\n";
createFileAndPopulate(oldCfgsFolder, "MasterClassNames.cfg", contents);
createFileAndPopulate(oldCfgsFolder, "ClassNameInventory.cfg", contents);

System.setProperty(CONFIG_DIR_PROPERTY, String.valueOf(oldCfgsFolder.toAbsolutePath()));
emissary.config.ConfigUtil.initialize();

EmissaryException thrown = assertThrows(EmissaryException.class, () -> {
final Configurator c = ConfigUtil.getMasterClassNames();
final Configurator c = ConfigUtil.getClassNameInventory();
});

assertTrue(thrown.getMessage().contains("No places to start."));
}

@Test
void testOneMasterClassNamesMultipleDirs() throws IOException, EmissaryException {
void testOneClassNameInventoryMultipleDirs() throws IOException, EmissaryException {
// setup
final Path cfgDir1 = createTmpSubDir("cfg1AB");
final Path cfgDir2 = createTmpSubDir("cfg2AB");
final String one = "DevNullPlace = \"emissary.place.donotpickme.DevNullPlace\"\n";
createFileAndPopulate(cfgDir1, "emissary.admin.MasterClassNames-cfgDir1.cfg", one);
createFileAndPopulate(cfgDir1, "emissary.admin.ClassNameInventory-cfgDir1.cfg", one);
final String two = "BlahBlahPlace = \"emissary.place.donotpickme.DevNullPlace\"\n";
createFileAndPopulate(cfgDir2, "emissary.admin.MasterClassNames-cfgDir2.cfg", two);
createFileAndPopulate(cfgDir2, "emissary.admin.ClassNameInventory-cfgDir2.cfg", two);
final String origConfigDirProp = System.getProperty(CONFIG_DIR_PROPERTY);
System.setProperty(CONFIG_DIR_PROPERTY, cfgDir1.toAbsolutePath() + "," + cfgDir2.toAbsolutePath());

// run
ConfigUtil.initialize();
final Configurator c = ConfigUtil.getMasterClassNames();
final Configurator c = ConfigUtil.getClassNameInventory();

// assert
assertNotNull(c, "Should have a configurator");
Expand All @@ -474,20 +474,20 @@ void testOneMasterClassNamesMultipleDirs() throws IOException, EmissaryException
}

@Test
void testSameMasterClassNamesMultipleDirs() throws IOException, EmissaryException {
void testSameClassNameInventoryMultipleDirs() throws IOException, EmissaryException {
// setup
final Path cfgDir1 = createTmpSubDir("cfg1ABC");
final Path cfgDir2 = createTmpSubDir("cfg2ABC");
final String one = "DevNullPlace = \"emissary.place.first.DevNullPlace\"\n";
createFileAndPopulate(cfgDir1, "emissary.admin.MasterClassNames-sames.cfg", one);
createFileAndPopulate(cfgDir1, "emissary.admin.ClassNameInventory-sames.cfg", one);
final String two = "Dev2NullPlace = \"emissary.place.second.DevNullPlace\"\n";
createFileAndPopulate(cfgDir2, "emissary.admin.MasterClassNames-sames.cfg", two);
createFileAndPopulate(cfgDir2, "emissary.admin.ClassNameInventory-sames.cfg", two);
final String origConfigDirProp = System.getProperty(CONFIG_DIR_PROPERTY);
System.setProperty(CONFIG_DIR_PROPERTY, cfgDir1.toAbsolutePath() + "," + cfgDir2.toAbsolutePath());
emissary.config.ConfigUtil.initialize();

// run
final Configurator c = ConfigUtil.getMasterClassNames();
final Configurator c = ConfigUtil.getClassNameInventory();

// assert
assertNotNull(c, "Should have a configurator");
Expand All @@ -502,27 +502,27 @@ void testSameMasterClassNamesMultipleDirs() throws IOException, EmissaryExceptio


@Test
void testMultipleMasterClassNamesMultipleDirs() throws IOException, EmissaryException {
void testMultipleClassNameInventoryMultipleDirs() throws IOException, EmissaryException {
// setup
final Path cfgDir1 = createTmpSubDir("cfg1ABCD");
final Path cfgDir2 = createTmpSubDir("cfg2ABCD");
final Path cfgDir3 = createTmpSubDir("cfg3ABCD");
final String one = "DevNullPlace = \"emissary.place.first.DevNullPlace\"\n";
createFileAndPopulate(cfgDir1, "emissary.admin.MasterClassNames-sames.cfg", one);
createFileAndPopulate(cfgDir1, "emissary.admin.ClassNameInventory-sames.cfg", one);
final String two = "BlahBlahPlace = \"emissary.place.second.DevNullPlace\"\n";
final String three = "Dev2NullPlace = \"emissary.place.second.DevNullPlace2\"\n";
createFileAndPopulate(cfgDir2, "emissary.admin.MasterClassNames-sames.cfg", two + three);
createFileAndPopulate(cfgDir2, "emissary.admin.ClassNameInventory-sames.cfg", two + three);
final String four = "BleeBleeNullPlace = \"emissary.place.second.BleeNullPlace\"\n";
createFileAndPopulate(cfgDir2, "emissary.admin.MasterClassNames-sames-two.cfg", four);
createFileAndPopulate(cfgDir2, "emissary.admin.ClassNameInventory-sames-two.cfg", four);
final String five = "BleeCheesePlace = \"emissary.place.second.BleeCheesePlace\"\n";
createFileAndPopulate(cfgDir3, "emissary.admin.MasterClassNames-three.cfg", five);
createFileAndPopulate(cfgDir3, "emissary.admin.ClassNameInventory-three.cfg", five);

final String origConfigDirProp = System.getProperty(CONFIG_DIR_PROPERTY);
System.setProperty(CONFIG_DIR_PROPERTY, cfgDir1.toAbsolutePath() + "," + cfgDir2.toAbsolutePath() + "," + cfgDir3.toAbsolutePath());
emissary.config.ConfigUtil.initialize();

// run
final Configurator c = ConfigUtil.getMasterClassNames();
final Configurator c = ConfigUtil.getClassNameInventory();

// assert
assertNotNull(c, "Should have a configurator");
Expand All @@ -538,13 +538,13 @@ void testMultipleMasterClassNamesMultipleDirs() throws IOException, EmissaryExce
}

@Test
void testMasterClassNamesWarnsOnFlavor() throws IOException, EmissaryException {
void testClassNameInventoryWarnsOnFlavor() throws IOException, EmissaryException {
final String contents2 = "DevNullPlace = \"emissary.place.second.DevNullPlace\"\n";
createFileAndPopulate(CDIR, "emissary.admin.MasterClassNames-NORM.cfg", contents2);
createFileAndPopulate(CDIR, "emissary.admin.ClassNameInventory-NORM.cfg", contents2);
System.setProperty(ConfigUtil.CONFIG_FLAVOR_PROPERTY, "NORM");

emissary.config.ConfigUtil.initialize();
ConfigUtil.getMasterClassNames();
ConfigUtil.getClassNameInventory();

// Confirm logs contain flavor message
assertTrue(
Expand All @@ -558,7 +558,7 @@ void testMasterClassNamesWarnsOnFlavor() throws IOException, EmissaryException {

@Test
void testGetFlavorFromFile() {
final String flavor = ConfigUtil.getFlavorsFromCfgFile(Paths.get(CDIR.toString() + "emissary.admin.MasterClassNames-flavor1.cfg").toFile());
final String flavor = ConfigUtil.getFlavorsFromCfgFile(Paths.get(CDIR.toString() + "emissary.admin.ClassNameInventory-flavor1.cfg").toFile());
assertEquals("flavor1", flavor, "Flavors didn't match");
}

Expand Down Expand Up @@ -589,22 +589,22 @@ void testGetFlavorMultipleHyphens() {
}

@Test
void testDuplicateEntryInMasterClassNamesThrowsIOException() throws IOException, EmissaryException {
void testDuplicateEntryInClassNameInventoryThrowsIOException() throws IOException, EmissaryException {
// setup
final Path cfgDir1 = createTmpSubDir("cfg1ABCDE");
final Path cfgDir2 = createTmpSubDir("cfg2ABCDE");
final String one = "DevNullPlace = \"emissary.place.first.DevNullPlace\"\n";
createFileAndPopulate(cfgDir1, "emissary.admin.MasterClassNames.cfg", one);
createFileAndPopulate(cfgDir1, "emissary.admin.ClassNameInventory.cfg", one);
final String two = "BlahBlahPlace = \"emissary.place.second.DevNullPlace\"\n";
final String three = "DevNullPlace = \"emissary.place.second.DevNullPlace2\"\n";
createFileAndPopulate(cfgDir2, "emissary.admin.MasterClassNames-hasdups.cfg", two + three);
createFileAndPopulate(cfgDir2, "emissary.admin.ClassNameInventory-hasdups.cfg", two + three);

final String origConfigDirProp = System.getProperty(CONFIG_DIR_PROPERTY);
System.setProperty(CONFIG_DIR_PROPERTY, cfgDir1.toAbsolutePath() + "," + cfgDir2.toAbsolutePath());
emissary.config.ConfigUtil.initialize();

// run
final Configurator c = ConfigUtil.getMasterClassNames();
final Configurator c = ConfigUtil.getClassNameInventory();
// clean up quick so other test don't fail
System.setProperty(CONFIG_DIR_PROPERTY, origConfigDirProp);
emissary.config.ConfigUtil.initialize();
Expand Down
Loading