/** * {@inheritDoc}. * * <p> * This implementation simply delegate the functionality to the internal {@link ConfigStore}/version * </p> */ @Override public Config getOwnConfig(ConfigKeyPath configKey) { return this.cs.getOwnConfig(configKey, this.version); }
/** * {@inheritDoc}. * * <p> * This implementation simply delegate the functionality to the internal {@link ConfigStore}/version * </p> */ @Override public Collection<ConfigKeyPath> getChildren(ConfigKeyPath configKey) { return this.cs.getChildren(configKey, this.version); }
public List<ConfigKeyPath> getOwnImports(ConfigKeyPath configKey, Optional<Config> runtimeConfig) { if (runtimeConfig.isPresent()) { return this.cs.getOwnImports(configKey, this.version, runtimeConfig); } return this.cs.getOwnImports(configKey, this.version); }
@Test public void testSystemPropertyResolution() { ConfigStore mockConfigStore = mock(ConfigStore.class, Mockito.RETURNS_SMART_NULLS); when(mockConfigStore.getCurrentVersion()).thenReturn(version); ConfigStoreTopologyInspector mockTopology = mock(ConfigStoreTopologyInspector.class, Mockito.RETURNS_SMART_NULLS); ConfigStoreBackedValueInspector valueInspector = new ConfigStoreBackedValueInspector(mockConfigStore, version, mockTopology); ConfigKeyPath testConfigKeyPath = SingleLinkedListConfigKeyPath.ROOT.createChild("a"); when(mockConfigStore.getOwnConfig(testConfigKeyPath.getParent(), version)).thenReturn(ConfigFactory.empty()); when(mockConfigStore.getOwnConfig(testConfigKeyPath, version)).thenReturn( ConfigFactory.parseString("configProp = ${?" + VALUE_INSPECTOR_SYS_PROP_KEY + "}")); Assert.assertEquals(valueInspector.getResolvedConfig(testConfigKeyPath).getString("configProp"), VALUE_INSPECTOR_SYS_PROP_VALUE); }
@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; }
public static boolean isAncestorOrSame(ConfigKeyPath descendant, ConfigKeyPath ancestor) { Preconditions.checkNotNull(descendant, "input can not be null"); Preconditions.checkNotNull(ancestor, "input can not be null"); if (descendant.equals(ancestor)) return true; if (descendant.isRootPath()) return false; return isAncestorOrSame(descendant.getParent(), ancestor); }
@Override public ConfigKeyPath apply(String input) { if (input == null) { return null; } ConfigKeyPath configKey = SingleLinkedListConfigKeyPath.ROOT; for (String file : Splitter.on(SingleLinkedListConfigKeyPath.PATH_DELIMETER).omitEmptyStrings().split(input)) { configKey = configKey.createChild(file); } return configKey; } }
/** * {@inheritDoc}. * * <p> * This implementation simply delegate the functionality to the internal {@link ConfigStore}/version * if the internal {@link ConfigStore} is {@link ConfigStoreWithBatchFetches}, otherwise, will call * configuration store for each config key path and put the result into {@link Map} * </p> */ @Override public Map<ConfigKeyPath, Config> getOwnConfigs(Collection<ConfigKeyPath> configKeys) { if (this.cs instanceof ConfigStoreWithBatchFetches) { ConfigStoreWithBatchFetches batchStore = (ConfigStoreWithBatchFetches) this.cs; return batchStore.getOwnConfigs(configKeys, this.version); } Map<ConfigKeyPath, Config> result = new HashMap<>(); for (ConfigKeyPath configKey : configKeys) { result.put(configKey, this.cs.getOwnConfig(configKey, this.version)); } return result; }
/** * 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()); } }
private void mockupConfigValueForKey(ConfigKeyPath configKey){ final String generalKey = "generalKey"; Map<String, String> valueMap = new HashMap<>(); // key in all the nodes valueMap.put(generalKey, "valueOf_" +generalKey +"_"+configKey.getOwnPathName() ); // key in self node valueMap.put("keyOf_" + configKey.getOwnPathName(), "valueOf_" + configKey.getOwnPathName()); when(mockConfigStore.getOwnConfig(configKey, version)).thenReturn(ConfigFactory.parseMap(valueMap)); }
private static void checkMatchingSchemeAndAuthority(URI configKeyURI, ConfigStore cs) { Preconditions.checkNotNull(configKeyURI, "input can not be null"); Preconditions.checkNotNull(cs, "input can not be null"); Preconditions.checkArgument(configKeyURI.getScheme().equals(cs.getStoreURI().getScheme()), "Scheme name not match"); boolean authorityCheck = configKeyURI.getAuthority() == null || configKeyURI.getAuthority().equals(cs.getStoreURI().getAuthority()); Preconditions.checkArgument(authorityCheck, "Authority not match"); }
public Collection<ConfigKeyPath> getImportedByRecursively(ConfigKeyPath configKey, Optional<Config> runtimeConfig) { if (this.cs instanceof ConfigStoreWithImportedByRecursively) { return ((ConfigStoreWithImportedByRecursively) this.cs).getImportedByRecursively(configKey, this.version, runtimeConfig); } throw new UnsupportedOperationException("Internal ConfigStore does not support this operation"); } }
public List<ConfigKeyPath> getImportsRecursively(ConfigKeyPath configKey, Optional<Config> runtimeConfig) { if (this.cs instanceof ConfigStoreWithResolution) { return ((ConfigStoreWithResolution) this.cs).getImportsRecursively(configKey, this.version, runtimeConfig); } throw new UnsupportedOperationException("Internal ConfigStore does not support this operation"); }
public Collection<ConfigKeyPath> getImportedBy(ConfigKeyPath configKey, Optional<Config> runtimeConfig) { if (this.cs instanceof ConfigStoreWithImportedBy) { return ((ConfigStoreWithImportedBy) this.cs).getImportedBy(configKey, this.version, runtimeConfig); } throw new UnsupportedOperationException("Internal ConfigStore does not support this operation"); }
/** * Creates a {@link FileSystem} given a user specified configKey. */ private FileSystem createFileSystem(URI configKey) throws ConfigStoreCreationException { try { return FileSystem.get(createFileSystemURI(configKey), new Configuration()); } catch (IOException | URISyntaxException e) { throw new ConfigStoreCreationException(configKey, e); } }
/** * Build the {@link ConfigKeyPath} based on the absolute/relative path * @param input - absolute/relative file path * @return - {@link ConfigKeyPath} corresponding to the input */ public static ConfigKeyPath getConfigKeyPath(String input) { ConfigKeyPath result = SingleLinkedListConfigKeyPath.ROOT; String[] paths = input.split("/"); for (String p : paths) { // in case input start with "/", some elements could be "", which should be skip if (p.equals("")) { continue; } result = result.createChild(p); } return result; }
/** * 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); }
@SuppressWarnings("rawtypes") public ConfigStoreFactoryRegister() { ServiceLoader<ConfigStoreFactory> loader = ServiceLoader.load(ConfigStoreFactory.class); for (ConfigStoreFactory f : loader) { this.configStoreFactoryMap.put(f.getScheme(), f); LOG.info("Created the config store factory with scheme name " + f.getScheme()); } }
/** * * @param configKeyURI - URI provided by client , which could missing authority/store root directory * @param cs - ConfigStore corresponding to the input URI. Require input URI's scheme/authority name * match ConfigStore's scheme/authority * @return - {@link ConfigKeyPath} for the relative path */ public static ConfigKeyPath buildConfigKeyPath(URI configKeyURI, ConfigStore cs) { checkMatchingSchemeAndAuthority(configKeyURI, cs); // Example store root is etl-hdfs://eat1-nertznn01.grid.linkedin.com:9000/user/mitu/HdfsBasedConfigTest URI relative = cs.getStoreURI().relativize(configKeyURI); return getConfigKeyPath(relative.getPath()); }