public static int install(ResourceUtils resolver, Map<String, ?> props, SshMachineLocation machine, String urlToInstall, String target, int numAttempts) {
if (resolver==null) resolver = ResourceUtils.create(machine);
Exception lastError = null;
int retriesRemaining = numAttempts;
int attemptNum = 0;
do {
attemptNum++;
try {
Tasks.setBlockingDetails("Installing "+urlToInstall+" at "+machine);
return machine.installTo(resolver, props, urlToInstall, target);
} catch (Exception e) {
Exceptions.propagateIfFatal(e);
lastError = e;
String stack = StackTraceSimplifier.toString(e);
if (stack.contains("net.schmizz.sshj.sftp.RemoteFile.write")) {
log.warn("Failed to transfer "+urlToInstall+" to "+machine+", retryable error, attempt "+attemptNum+"/"+numAttempts+": "+e);
continue;
}
log.warn("Failed to transfer "+urlToInstall+" to "+machine+", not a retryable error so failing: "+e);
throw Exceptions.propagate(e);
} finally {
Tasks.resetBlockingDetails();
}
} while (retriesRemaining --> 0);
throw Exceptions.propagate(lastError);
}