@Override public String choose(VolumeChooserEnvironment env, String[] options) throws VolumeChooserException { log.trace("{}.choose", getClass().getSimpleName()); // Randomly choose the volume from the preferred volumes String choice = super.choose(env, getPreferredVolumes(env, options)); log.trace("Choice = {}", choice); return choice; }
String[] getPreferredVolumes(VolumeChooserEnvironment env, String[] options) { switch (env.getScope()) { case INIT: // TODO should be possible to read from SiteConfiguration during init log.warn("Not possible to determine preferred volumes at '{}' scope. Using all volumes.", ChooserScope.INIT); return options; case TABLE: return getPreferredVolumesForTable(env, loadConfFactory(env), options); default: return getPreferredVolumesForScope(env, loadConfFactory(env), options); } }
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); }
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); }