mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-14 22:43:57 +00:00
bug5311: better SSH connection handling in case an unknown/null key was used for launching instance and no explicit key is provided
This commit is contained in:
1 parent
f030ccab1d
commit
85baacb663
1 file changed
+25
-20
+25
-20
@@ -199,27 +199,32 @@ public class AwsInstanceImpl<ShardingKey> implements AwsInstance<ShardingKey> {
|
||||
" with key "+optionalKeyName+
|
||||
" to instance with ID "+getInstanceId());
|
||||
Channel result;
|
||||
try {
|
||||
result = Wait.wait(()->{
|
||||
Session session = null;
|
||||
try {
|
||||
session = createSshSession(sshUserName, optionalKeyName, privateKeyEncryptionPassphrase);
|
||||
session.setUserInfo(new YesUserInfo());
|
||||
session.connect(optionalTimeout.map(d->d.asMillis()).orElse(0l).intValue());
|
||||
return session.openChannel(channelType);
|
||||
} catch (JSchException | IllegalStateException e) {
|
||||
if (session != null) {
|
||||
session.disconnect();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
channel->channel != null,
|
||||
/* retryOnException */ true, optionalTimeout,
|
||||
Duration.ONE_SECOND.times(5), Level.INFO,
|
||||
"Trying to connect to " + getInstanceId() + " with user " + sshUserName + " using SSH");
|
||||
} catch (TimeoutException timeout) {
|
||||
if (!optionalKeyName.isPresent() && !Util.hasLength(getInstance().keyName())) {
|
||||
logger.severe("SSH connection to "+this+" cannot be made because no key name is provided, neither explicitly nor during start-up");
|
||||
result = null;
|
||||
} else {
|
||||
try {
|
||||
result = Wait.wait(()->{
|
||||
Session session = null;
|
||||
try {
|
||||
session = createSshSession(sshUserName, optionalKeyName, privateKeyEncryptionPassphrase);
|
||||
session.setUserInfo(new YesUserInfo());
|
||||
session.connect(optionalTimeout.map(d->d.asMillis()).orElse(0l).intValue());
|
||||
return session.openChannel(channelType);
|
||||
} catch (JSchException | IllegalStateException e) {
|
||||
if (session != null) {
|
||||
session.disconnect();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
channel->channel != null,
|
||||
/* retryOnException */ true, optionalTimeout,
|
||||
Duration.ONE_SECOND.times(5), Level.INFO,
|
||||
"Trying to connect to " + getInstanceId() + " with user " + sshUserName + " using SSH");
|
||||
} catch (TimeoutException timeout) {
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user