private String[] parsePreferred(String property, String preferredVolumes, String[] options) { log.trace("Found {} = {}", property, preferredVolumes); Set<String> preferred = Arrays.stream(StringUtils.split(preferredVolumes, ',')) .map(String::trim).collect(Collectors.toSet()); if (preferred.isEmpty()) { String msg = "No volumes could be parsed from '" + property + "', which had a value of '" + preferredVolumes + "'"; throw new VolumeChooserException(msg); } // preferred volumes should also exist in the original options (typically, from // instance.volumes) Set<String> optionsList = Arrays.stream(options).collect(Collectors.toSet()); if (!preferred.stream().allMatch(optionsList::contains)) { String msg = "Some volumes in " + preferred + " are not valid volumes from " + optionsList; throw new VolumeChooserException(msg); } return preferred.toArray(new String[preferred.size()]); }
@Override public String choose(VolumeChooserEnvironment env, String[] options) { final String choice; choice = chooser.choose(env, options); if (!(ArrayUtils.contains(options, choice))) { String msg = "The configured volume chooser, '" + chooser.getClass() + "', or one of its delegates returned a volume not in the set of options provided"; throw new VolumeChooserException(msg); } return choice; }
String msg = "Failed to create instance for " + key + " configured to use " + className + " via " + property; throw new VolumeChooserException(msg, e);
private String[] getPreferredVolumesForScope(VolumeChooserEnvironment env, ServerConfigurationFactory confFactory, String[] options) { ChooserScope scope = env.getScope(); String property = getPropertyNameForScope(scope); log.trace("Looking up property {} for scope: {}", property, scope); AccumuloConfiguration systemConfiguration = confFactory.getSystemConfiguration(); String preferredVolumes = systemConfiguration.get(property); // fall back to global default scope if this scope isn't configured (and not already default // scope) if ((preferredVolumes == null || preferredVolumes.isEmpty()) && scope != ChooserScope.DEFAULT) { log.debug("{} not found; using {}", property, DEFAULT_SCOPED_PREFERRED_VOLUMES); preferredVolumes = systemConfiguration.get(DEFAULT_SCOPED_PREFERRED_VOLUMES); // only if the custom property is not set to we fall back to the default scoped preferred // volumes if (preferredVolumes == null || preferredVolumes.isEmpty()) { String msg = "Property " + property + " or " + DEFAULT_SCOPED_PREFERRED_VOLUMES + " must be a subset of " + Arrays.toString(options) + " to use the " + getClass().getSimpleName(); throw new VolumeChooserException(msg); } property = DEFAULT_SCOPED_PREFERRED_VOLUMES; } return parsePreferred(property, preferredVolumes, options); }
protected VolumeManagerImpl(Map<String,Volume> volumes, Volume defaultVolume, AccumuloConfiguration conf, Configuration hadoopConf) { this.volumesByName = volumes; this.defaultVolume = defaultVolume; // We may have multiple directories used in a single FileSystem (e.g. testing) this.volumesByFileSystemUri = HashMultimap.create(); invertVolumesByFileSystem(volumesByName, volumesByFileSystemUri); ensureSyncIsEnabled(); // if they supplied a property and we cannot load it, then fail hard VolumeChooser chooser1; try { chooser1 = Property.createInstanceFromPropertyName(conf, Property.GENERAL_VOLUME_CHOOSER, VolumeChooser.class, null); } catch (NullPointerException npe) { chooser1 = null; // null chooser handled below } if (chooser1 == null) { throw new VolumeChooserException( "Failed to load volume chooser specified by " + Property.GENERAL_VOLUME_CHOOSER); } chooser = chooser1; this.hadoopConf = hadoopConf; }
private VolumeChooser getVolumeChooserForScope(VolumeChooserEnvironment env, ServerConfigurationFactory confFactory) { ChooserScope scope = env.getScope(); String property = getPropertyNameForScope(scope); log.trace("Looking up property {} for scope: {}", property, scope); AccumuloConfiguration systemConfiguration = confFactory.getSystemConfiguration(); String clazz = systemConfiguration.get(property); // fall back to global default scope if this scope isn't configured (and not already default // scope) if ((clazz == null || clazz.isEmpty()) && scope != ChooserScope.DEFAULT) { log.debug("{} not found; using {}", property, DEFAULT_SCOPED_VOLUME_CHOOSER); clazz = systemConfiguration.get(DEFAULT_SCOPED_VOLUME_CHOOSER); if (clazz == null || clazz.isEmpty()) { String msg = "Property " + property + " or " + DEFAULT_SCOPED_VOLUME_CHOOSER + " must be a valid " + VolumeChooser.class.getSimpleName() + " to use the " + getClass().getSimpleName(); throw new VolumeChooserException(msg); } property = DEFAULT_SCOPED_VOLUME_CHOOSER; } String context = null; return createVolumeChooser(context, clazz, property, scope, scopeSpecificChooserCache); }
private String[] getPreferredVolumesForTable(VolumeChooserEnvironment env, ServerConfigurationFactory confFactory, String[] options) { log.trace("Looking up property {} + for Table id: {}", TABLE_PREFERRED_VOLUMES, env.getTableId()); final TableConfiguration tableConf = confFactory.getTableConfiguration(env.getTableId()); String preferredVolumes = tableConf.get(TABLE_PREFERRED_VOLUMES); // fall back to global default scope, so setting only one default is necessary, rather than a // separate default for TABLE scope than other scopes if (preferredVolumes == null || preferredVolumes.isEmpty()) { preferredVolumes = confFactory.getSystemConfiguration().get(DEFAULT_SCOPED_PREFERRED_VOLUMES); } // throw an error if volumes not specified or empty if (preferredVolumes == null || preferredVolumes.isEmpty()) { String msg = "Property " + TABLE_PREFERRED_VOLUMES + " or " + DEFAULT_SCOPED_PREFERRED_VOLUMES + " must be a subset of " + Arrays.toString(options) + " to use the " + getClass().getSimpleName(); throw new VolumeChooserException(msg); } return parsePreferred(TABLE_PREFERRED_VOLUMES, preferredVolumes, options); }
private VolumeChooser getVolumeChooserForTable(VolumeChooserEnvironment env, ServerConfigurationFactory confFactory) { log.trace("Looking up property {} for table id: {}", TABLE_VOLUME_CHOOSER, env.getTableId()); final TableConfiguration tableConf = confFactory.getTableConfiguration(env.getTableId()); String clazz = tableConf.get(TABLE_VOLUME_CHOOSER); // fall back to global default scope, so setting only one default is necessary, rather than a // separate default for TABLE scope than other scopes if (clazz == null || clazz.isEmpty()) { clazz = confFactory.getSystemConfiguration().get(DEFAULT_SCOPED_VOLUME_CHOOSER); } if (clazz == null || clazz.isEmpty()) { String msg = "Property " + TABLE_VOLUME_CHOOSER + " or " + DEFAULT_SCOPED_VOLUME_CHOOSER + " must be a valid " + VolumeChooser.class.getSimpleName() + " to use the " + getClass().getSimpleName(); throw new VolumeChooserException(msg); } String context = getTableContext(tableConf); // can be null return createVolumeChooser(context, clazz, TABLE_VOLUME_CHOOSER, env.getTableId(), tableSpecificChooserCache); }