use of org.spearce_voltpatches.jgit.transport.OpenSshConfig in project voltdb by VoltDB.
the class ExportOnServerVerifier method verifySetup.
boolean verifySetup(String[] args) throws Exception {
String[] remoteHosts = args[0].split(",");
final String homeDir = System.getProperty("user.home");
final String sshDir = homeDir + File.separator + ".ssh";
final String sshConfigPath = sshDir + File.separator + "config";
//Oh yes...
loadAllPrivateKeys(new File(sshDir));
OpenSshConfig sshConfig = null;
if (new File(sshConfigPath).exists()) {
sshConfig = new OpenSshConfig(new File(sshConfigPath));
}
final String defaultKnownHosts = sshDir + "/known_hosts";
if (new File(defaultKnownHosts).exists()) {
m_jsch.setKnownHosts(defaultKnownHosts);
}
for (String hostString : remoteHosts) {
String[] split = hostString.split(":");
String host = split[0];
RemoteHost rh = new RemoteHost();
rh.path = split[1];
String user = System.getProperty("user.name");
int port = 22;
File identityFile = null;
String configHost = host;
if (sshConfig != null) {
OpenSshConfig.Host hostConfig = sshConfig.lookup(host);
if (hostConfig.getUser() != null) {
user = hostConfig.getUser();
}
if (hostConfig.getPort() != -1) {
port = hostConfig.getPort();
}
if (hostConfig.getIdentityFile() != null) {
identityFile = hostConfig.getIdentityFile();
}
if (hostConfig.getHostName() != null) {
configHost = hostConfig.getHostName();
}
}
Session session = null;
if (identityFile != null) {
JSch jsch = new JSch();
jsch.addIdentity(identityFile.getAbsolutePath());
session = jsch.getSession(user, configHost, port);
} else {
session = m_jsch.getSession(user, configHost, port);
}
rh.session = session;
session.setConfig("StrictHostKeyChecking", "no");
session.setDaemonThread(true);
session.connect();
final ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
rh.channel = channel;
channel.connect();
touchActiveTracker(rh);
m_hosts.add(rh);
}
m_partitions = Integer.parseInt(args[1]);
for (int i = 0; i < m_partitions; i++) {
m_rowTxnIds.put(i, new TreeMap<Long, Long>());
m_maxPartTxId.put(i, Long.MIN_VALUE);
m_checkedUpTo.put(i, 0);
m_readUpTo.put(i, new AtomicLong(0));
}
m_clientPath = new File(args[2]);
if (!m_clientPath.exists() || !m_clientPath.isDirectory()) {
if (!m_clientPath.mkdir()) {
throw new IOException("Issue with transaction ID path");
}
}
for (RemoteHost rh : m_hosts) {
boolean existsOrIsDir = true;
try {
SftpATTRS stat = rh.channel.stat(rh.path);
if (!stat.isDir()) {
existsOrIsDir = false;
}
} catch (SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
existsOrIsDir = false;
} else {
Throwables.propagate(e);
}
}
if (!existsOrIsDir) {
rh.channel.mkdir(rh.path);
}
}
boolean skinny = false;
if (args.length > 3 && args[3] != null && !args[3].trim().isEmpty()) {
skinny = Boolean.parseBoolean(args[3].trim().toLowerCase());
}
return skinny;
}
Aggregations