Skip to content

Commit 514135d

Browse files
authored
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 12a8006 commit 514135d

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import java.util.Collections;
8282
import java.util.HashMap;
8383
import java.util.HashSet;
84+
import java.util.LinkedHashMap;
8485
import java.util.List;
8586
import java.util.Locale;
8687
import java.util.Map;
@@ -224,32 +225,47 @@ void execute(Terminal terminal, List<String> pluginIds, boolean isBatch, Environ
224225
}
225226
}
226227

227-
final List<Path> deleteOnFailure = new ArrayList<>();
228-
final Set<PluginInfo> pluginInfos = new HashSet<>();
228+
final Map<String, List<Path>> deleteOnFailures = new LinkedHashMap<>();
229229
for (final String pluginId : pluginIds) {
230+
terminal.println("-> Installing " + pluginId);
230231
try {
231232
if ("x-pack".equals(pluginId)) {
232233
handleInstallXPack(buildFlavor());
233234
}
234235

236+
final List<Path> deleteOnFailure = new ArrayList<>();
237+
deleteOnFailures.put(pluginId, deleteOnFailure);
238+
235239
final Path pluginZip = download(terminal, pluginId, env.tmpFile(), isBatch);
236240
final Path extractedZip = unzip(pluginZip, env.pluginsFile());
237241
deleteOnFailure.add(extractedZip);
238242
final PluginInfo pluginInfo = installPlugin(terminal, isBatch, extractedZip, env, deleteOnFailure);
239-
pluginInfos.add(pluginInfo);
243+
terminal.println("-> Installed " + pluginInfo.getName());
244+
// swap the entry by plugin id for one with the installed plugin name, it gives a cleaner error message for URL installs
245+
deleteOnFailures.remove(pluginId);
246+
deleteOnFailures.put(pluginInfo.getName(), deleteOnFailure);
240247
} catch (final Exception installProblem) {
241-
try {
242-
IOUtils.rm(deleteOnFailure.toArray(new Path[0]));
243-
} catch (final IOException exceptionWhileRemovingFiles) {
244-
installProblem.addSuppressed(exceptionWhileRemovingFiles);
248+
terminal.println("-> Failed installing " + pluginId);
249+
for (final Map.Entry<String, List<Path>> deleteOnFailureEntry : deleteOnFailures.entrySet()) {
250+
terminal.println("-> Rolling back " + deleteOnFailureEntry.getKey());
251+
boolean success = false;
252+
try {
253+
IOUtils.rm(deleteOnFailureEntry.getValue().toArray(new Path[0]));
254+
success = true;
255+
} catch (final IOException exceptionWhileRemovingFiles) {
256+
final Exception exception = new Exception(
257+
"failed rolling back installation of [" + deleteOnFailureEntry.getKey() + "]",
258+
exceptionWhileRemovingFiles);
259+
installProblem.addSuppressed(exception);
260+
terminal.println("-> Failed rolling back " + deleteOnFailureEntry.getKey());
261+
}
262+
if (success) {
263+
terminal.println("-> Rolled back " + deleteOnFailureEntry.getKey());
264+
}
245265
}
246266
throw installProblem;
247267
}
248268
}
249-
250-
for (final PluginInfo pluginInfo : pluginInfos) {
251-
terminal.println("-> Installed " + pluginInfo.getName());
252-
}
253269
}
254270

255271
Build.Flavor buildFlavor() {

0 commit comments

Comments
 (0)