Preconditions.checkState(remoteStagingLocation == null, "Remote staging location must be null at the start of the loop");
final Map<String, String> templateVariables = Maps.newHashMap(mTemplateDefaults);
templateVariables.put("instanceName", drone.getInstanceName());
templateVariables.put("localDir", drone.getLocalDirectory());
String resolvedRemoteLocation = Files.simplifyPath(Templates.getTemplateResult(remoteFile, templateVariables));
RSyncResult result = new RSyncCommand(mRSyncCommandExecutor, drone.getPrivateKey(), drone.getUser(),
drone.getHost(), drone.getInstance(),
resolvedLocalLocation,
resolvedRemoteLocation,
RSyncCommand.Type.FROM_LOCAL).call();
if(result.getExitCode() == Constants.EXIT_CODE_SUCCESS) {
remoteStagingLocation = resolvedRemoteLocation;
drones.remove(drone);
mLogger.info("Successfully staged " + resolvedLocalLocation + " on " + remoteStagingLocation);
break;
} else {
mDrones.remove(drone);
mLogger.error("Aborting drone during rsync",
new AbortDroneException("Drone " + drone + " exited with "
+ result.getExitCode() + ": " + result));
}
}
if(remoteStagingLocation == null) {
Preconditions.checkState(mDrones.isEmpty(), "If remote staging location is not set all drones should be bad");
mLogger.warn("Unable to stage directory on remote host, all drones must be bad");