Skip to content

Commit d5623c8

Browse files
committed
Report progress of multiple plugin installs (#51001)
When installing multiple plugins at once, this commit changes the behavior to report installed plugins as we go. In the case of failure, we emit a message that we are rolling back any plugins that were installed successfully, and also that they were successfully rolled back. In the case a plugin is not successfully rolled back, we report this clearly too, alerting the user that there might still be state on disk they would have to clean up.
1 parent 2f13751 commit d5623c8

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

distribution/tools/plugin-cli/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java

+27-11
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import java.util.Collections;
7979
import java.util.HashMap;
8080
import java.util.HashSet;
81+
import java.util.LinkedHashMap;
8182
import java.util.List;
8283
import java.util.Locale;
8384
import java.util.Map;
@@ -230,32 +231,47 @@ void execute(Terminal terminal, List<String> pluginIds, boolean isBatch, Environ
230231
}
231232
}
232233

233-
final List<Path> deleteOnFailure = new ArrayList<>();
234-
final Set<PluginInfo> pluginInfos = new HashSet<>();
234+
final Map<String, List<Path>> deleteOnFailures = new LinkedHashMap<>();
235235
for (final String pluginId : pluginIds) {
236+
terminal.println("-> Installing " + pluginId);
236237
try {
237238
if ("x-pack".equals(pluginId)) {
238239
handleInstallXPack(buildFlavor());
239240
}
240241

242+
final List<Path> deleteOnFailure = new ArrayList<>();
243+
deleteOnFailures.put(pluginId, deleteOnFailure);
244+
241245
final Path pluginZip = download(terminal, pluginId, env.tmpFile(), isBatch);
242246
final Path extractedZip = unzip(pluginZip, env.pluginsFile());
243247
deleteOnFailure.add(extractedZip);
244248
final PluginInfo pluginInfo = installPlugin(terminal, isBatch, extractedZip, env, deleteOnFailure);
245-
pluginInfos.add(pluginInfo);
249+
terminal.println("-> Installed " + pluginInfo.getName());
250+
// swap the entry by plugin id for one with the installed plugin name, it gives a cleaner error message for URL installs
251+
deleteOnFailures.remove(pluginId);
252+
deleteOnFailures.put(pluginInfo.getName(), deleteOnFailure);
246253
} catch (final Exception installProblem) {
247-
try {
248-
IOUtils.rm(deleteOnFailure.toArray(new Path[0]));
249-
} catch (final IOException exceptionWhileRemovingFiles) {
250-
installProblem.addSuppressed(exceptionWhileRemovingFiles);
254+
terminal.println("-> Failed installing " + pluginId);
255+
for (final Map.Entry<String, List<Path>> deleteOnFailureEntry : deleteOnFailures.entrySet()) {
256+
terminal.println("-> Rolling back " + deleteOnFailureEntry.getKey());
257+
boolean success = false;
258+
try {
259+
IOUtils.rm(deleteOnFailureEntry.getValue().toArray(new Path[0]));
260+
success = true;
261+
} catch (final IOException exceptionWhileRemovingFiles) {
262+
final Exception exception = new Exception(
263+
"failed rolling back installation of [" + deleteOnFailureEntry.getKey() + "]",
264+
exceptionWhileRemovingFiles);
265+
installProblem.addSuppressed(exception);
266+
terminal.println("-> Failed rolling back " + deleteOnFailureEntry.getKey());
267+
}
268+
if (success) {
269+
terminal.println("-> Rolled back " + deleteOnFailureEntry.getKey());
270+
}
251271
}
252272
throw installProblem;
253273
}
254274
}
255-
256-
for (final PluginInfo pluginInfo : pluginInfos) {
257-
terminal.println("-> Installed " + pluginInfo.getName());
258-
}
259275
}
260276

261277
Build.Flavor buildFlavor() {

0 commit comments

Comments
 (0)