public SshjClientConnection build() { return new SshjClientConnection(this); }
private SshjClientConnection(Builder builder) { this.hostAndPort = checkNotNull(builder.hostAndPort); this.username = builder.username; this.password = builder.password; this.privateKeyPassphrase = builder.privateKeyPassphrase; this.privateKeyData = builder.privateKeyData; this.privateKeyFile = builder.privateKeyFile; this.strictHostKeyChecking = builder.strictHostKeyChecking; this.connectTimeout = checkInt("connectTimeout", builder.connectTimeout, Integer.MAX_VALUE); this.sessionTimeout = checkInt("sessionTimeout", builder.sessionTimeout, Integer.MAX_VALUE); }
ShellAction(List<String> commands, OutputStream out, OutputStream err, Duration timeout) { this.commands = checkNotNull(commands, "commands"); this.out = out; this.err = err; Duration sessionTimeout = (sshClientConnection.getSessionTimeout() == 0) ? Duration.PRACTICALLY_FOREVER : Duration.millis(sshClientConnection.getSessionTimeout()); this.timeout = (timeout == null) ? sessionTimeout : Duration.min(timeout, sessionTimeout); }
@Override public boolean isConnected() { return sshClientConnection.isConnected() && sshClientConnection.isAuthenticated(); }
protected static Builder fromSSHClientConnection(SshjClientConnection in) { return new Builder().hostAndPort(in.getHostAndPort()).connectTimeout(in.getConnectTimeout()).sessionTimeout( in.getSessionTimeout()).username(in.username).password(in.password).privateKey(in.privateKeyData).privateKeyFile(in.privateKeyFile); } }
@Override public void disconnect() { if (LOG.isTraceEnabled()) LOG.trace("Disconnecting SshjTool {} ({})", this, System.identityHashCode(this)); try { Stopwatch perfStopwatch = Stopwatch.createStarted(); sshClientConnection.clear(); if (LOG.isTraceEnabled()) LOG.trace("SSH Performance: {} disconnect took {}", sshClientConnection.getHostAndPort(), Time.makeTimeStringRounded(perfStopwatch)); } catch (Exception e) { throw Exceptions.propagate(e); } }
sshClientConnection.getHostAndPort(), action.getClass().getSimpleName() != null ? action.getClass().getSimpleName() : action, Time.makeTimeStringRounded(perfStopwatch)});
protected SshjTool(Builder<?,?> builder) { super(builder); sshTries = builder.sshTries; sshTriesTimeout = builder.sshTriesTimeout; backoffLimitedRetryHandler = new BackoffLimitedRetryHandler(sshTries, builder.sshRetryDelay); sshClientConnection = SshjClientConnection.builder() .hostAndPort(HostAndPort.fromParts(host, port)) .username(user) .password(password) .privateKeyPassphrase(privateKeyPassphrase) .privateKeyData(privateKeyData) .privateKeyFile(privateKeyFile) .strictHostKeyChecking(strictHostKeyChecking) .connectTimeout(builder.connectTimeout) .sessionTimeout(builder.sessionTimeout) .build(); if (LOG.isTraceEnabled()) LOG.trace("Created SshTool {} ({})", this, System.identityHashCode(this)); }
ExecAction(String command, OutputStream out, OutputStream err, Duration timeout) { this.command = checkNotNull(command, "command"); this.out = out; this.err = err; Duration sessionTimeout = (sshClientConnection.getSessionTimeout() == 0) ? Duration.PRACTICALLY_FOREVER : Duration.millis(sshClientConnection.getSessionTimeout()); this.timeout = (timeout == null) ? sessionTimeout : Duration.min(timeout, sessionTimeout); }