/** * Get path object using zipped file system and relative path */ private Path getDatasetDirForKey(ConfigKeyPath configKey) throws VersionDoesNotExistException { return this.fs.getPath(this.storePrefix, configKey.getAbsolutePathString()); } }
/** * Retrieves the name of a dataset from a given {@link ConfigKeyPath}, relative to the store root. */ private static String getDatasetFromConfigKey(ConfigKeyPath configKey) { return StringUtils.removeStart(configKey.getAbsolutePathString(), SingleLinkedListConfigKeyPath.PATH_DELIMETER); }
@Override public String getAbsolutePathString() { if (this.isRootPath()) { return this.getOwnPathName() + PATH_DELIMETER; } // first level children do not need to add "/" if (this.parent.isRootPath()) return this.parent.getAbsolutePathString() + this.ownName; return this.parent.getAbsolutePathString() + PATH_DELIMETER + this.ownName; }
return new URI(cs.getStoreURI().getScheme(), null, configKeyPath.getAbsolutePathString(), null, null); Path absPath = new Path(storeRoot.getPath(), configKeyPath.getAbsolutePathString().substring(1)); // remote the first "/"; return new URI(storeRoot.getScheme(), storeRoot.getAuthority(), absPath.toString(), null, null); } catch (URISyntaxException e) {
@Test public void testGetOwnImportsWithResolution() throws IOException, URISyntaxException, ConfigStoreCreationException { String datasetName = "dataset-test-get-own-imports-resolution"; Path datasetPath = new Path(CONFIG_DIR_PATH, datasetName); try { this.fs.mkdirs(datasetPath); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(this.fs.create(new Path(datasetPath, "includes.conf")), Charsets.UTF_8)); writer.write("/path/to/${?" + TAG_NAME_SYS_PROP_KEY + "}"); writer.close(); ConfigKeyPath datasetConfigKey = SingleLinkedListConfigKeyPath.ROOT.createChild(datasetName); List<ConfigKeyPath> imports = this._simpleHadoopFilesystemConfigStore.getOwnImports(datasetConfigKey, VERSION); Assert.assertEquals(imports.size(), 1); Assert.assertEquals(imports.get(0).getAbsolutePathString(), "/path/to/" + TAG_NAME_SYS_PROP_VALUE); } finally { if (this.fs.exists(datasetPath)) { this.fs.delete(datasetPath, true); } } }
@Test public void testGetOwnImports() throws IOException, URISyntaxException, ConfigStoreCreationException { String datasetName = "dataset-test-get-own-imports"; String tagKey1 = "/path/to/tag1"; String tagKey2 = "/path/to/tag2"; Path datasetPath = new Path(CONFIG_DIR_PATH, datasetName); try { this.fs.mkdirs(datasetPath); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(this.fs.create(new Path(datasetPath, "includes.conf")), Charsets.UTF_8)); writer.write(tagKey1); writer.newLine(); writer.write(tagKey2); writer.close(); ConfigKeyPath datasetConfigKey = SingleLinkedListConfigKeyPath.ROOT.createChild(datasetName); List<ConfigKeyPath> imports = this._simpleHadoopFilesystemConfigStore.getOwnImports(datasetConfigKey, VERSION); Assert.assertEquals(imports.size(), 2); Assert.assertEquals(imports.get(0).getAbsolutePathString(), tagKey2); Assert.assertEquals(imports.get(1).getAbsolutePathString(), tagKey1); } finally { if (this.fs.exists(datasetPath)) { this.fs.delete(datasetPath, true); } } }
@Test public void testGetOwnImportsWithRuntimeConfigResolution() throws IOException, URISyntaxException, ConfigStoreCreationException { String datasetName = "dataset-test-get-own-imports-resolution"; Path datasetPath = new Path(CONFIG_DIR_PATH, datasetName); Properties prop = new Properties(); prop.put(TAG_NAME_RUNTIME_PROP_KEY, TAG_NAME_RUNTIME_PROP_VALUE); Optional<Config> runtimeConfig = Optional.fromNullable(ConfigUtils.propertiesToConfig(prop)); try { this.fs.mkdirs(datasetPath); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(this.fs.create(new Path(datasetPath, "includes.conf")), Charsets.UTF_8)); writer.write("/path/to/${?" + TAG_NAME_RUNTIME_PROP_KEY + "}"); writer.close(); ConfigKeyPath datasetConfigKey = SingleLinkedListConfigKeyPath.ROOT.createChild(datasetName); List<ConfigKeyPath> imports = this._simpleHadoopFilesystemConfigStore.getOwnImports(datasetConfigKey, VERSION, runtimeConfig); Assert.assertEquals(imports.size(), 1); Assert.assertEquals(imports.get(0).getAbsolutePathString(), "/path/to/" + TAG_NAME_RUNTIME_PROP_VALUE); } finally { if (this.fs.exists(datasetPath)) { this.fs.delete(datasetPath, true); } } }
@Test public void testNonRoot() { ConfigKeyPath data = SingleLinkedListConfigKeyPath.ROOT.createChild("data"); Assert.assertEquals(data.getAbsolutePathString(), "/data"); ConfigKeyPath profile = data.createChild("databases").createChild("identity").createChild("profile"); Assert.assertEquals(profile.toString(), "/data/databases/identity/profile"); }
private Config getResolvedConfigRecursive(ConfigKeyPath configKey, Set<String> alreadyLoadedPaths, Optional<Config> runtimeConfig) { if (this.cs instanceof ConfigStoreWithResolution) { return ((ConfigStoreWithResolution) this.cs).getResolvedConfig(configKey, this.version); } if (!alreadyLoadedPaths.add(configKey.getAbsolutePathString())) { return ConfigFactory.empty(); } Config initialConfig = this.getOwnConfig(configKey); if (configKey.isRootPath()) { return initialConfig; } List<ConfigKeyPath> ownImports = this.topology.getOwnImports(configKey, runtimeConfig); // merge with other configs from imports if (ownImports != null) { for (ConfigKeyPath p : ownImports) { initialConfig = initialConfig.withFallback(this.getResolvedConfigRecursive(p, alreadyLoadedPaths, runtimeConfig)); } } // merge with configs from parent for Non root initialConfig = initialConfig .withFallback(this.getResolvedConfigRecursive(configKey.getParent(), alreadyLoadedPaths, runtimeConfig)); return initialConfig; }
/** * Get path object using zipped file system and relative path */ private Path getDatasetDirForKey(ConfigKeyPath configKey) throws VersionDoesNotExistException { return this.fs.getPath(this.storePrefix, configKey.getAbsolutePathString()); } }
/** * Retrieves the name of a dataset from a given {@link ConfigKeyPath}, relative to the store root. */ private static String getDatasetFromConfigKey(ConfigKeyPath configKey) { return StringUtils.removeStart(configKey.getAbsolutePathString(), SingleLinkedListConfigKeyPath.PATH_DELIMETER); }
@Override public String getAbsolutePathString() { if (this.isRootPath()) { return this.getOwnPathName() + PATH_DELIMETER; } // first level children do not need to add "/" if (this.parent.isRootPath()) return this.parent.getAbsolutePathString() + this.ownName; return this.parent.getAbsolutePathString() + PATH_DELIMETER + this.ownName; }
return new URI(cs.getStoreURI().getScheme(), null, configKeyPath.getAbsolutePathString(), null, null); Path absPath = new Path(storeRoot.getPath(), configKeyPath.getAbsolutePathString().substring(1)); // remote the first "/"; return new URI(storeRoot.getScheme(), storeRoot.getAuthority(), absPath.toString(), null, null); } catch (URISyntaxException e) {
private Config getResolvedConfigRecursive(ConfigKeyPath configKey, Set<String> alreadyLoadedPaths, Optional<Config> runtimeConfig) { if (this.cs instanceof ConfigStoreWithResolution) { return ((ConfigStoreWithResolution) this.cs).getResolvedConfig(configKey, this.version); } if (!alreadyLoadedPaths.add(configKey.getAbsolutePathString())) { return ConfigFactory.empty(); } Config initialConfig = this.getOwnConfig(configKey); if (configKey.isRootPath()) { return initialConfig; } List<ConfigKeyPath> ownImports = this.topology.getOwnImports(configKey, runtimeConfig); // merge with other configs from imports if (ownImports != null) { for (ConfigKeyPath p : ownImports) { initialConfig = initialConfig.withFallback(this.getResolvedConfigRecursive(p, alreadyLoadedPaths, runtimeConfig)); } } // merge with configs from parent for Non root initialConfig = initialConfig .withFallback(this.getResolvedConfigRecursive(configKey.getParent(), alreadyLoadedPaths, runtimeConfig)); return initialConfig; }