private StoragePlugin create(String name, StoragePluginConfig pluginConfig) throws ExecutionSetupException {
StoragePlugin plugin = null;
Constructor<? extends StoragePlugin> c = availablePlugins.get(pluginConfig.getClass());
if (c == null) {
throw new ExecutionSetupException(String.format("Failure finding StoragePlugin constructor for config %s",
pluginConfig));
}
try {
plugin = c.newInstance(pluginConfig, context, name);
return plugin;
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
Throwable t = e instanceof InvocationTargetException ? ((InvocationTargetException) e).getTargetException() : e;
if (t instanceof ExecutionSetupException)
throw ((ExecutionSetupException) t);
throw new ExecutionSetupException(String.format(
"Failure setting up new storage plugin configuration for config %s", pluginConfig), t);
}
}