Skip to content

Commit

Permalink
#1877 show pings
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Feb 27, 2024
1 parent bc8f5e8 commit 2afc866
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/main/java/com/rultor/agents/aws/PingsInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,23 @@ public PingsInstance() {
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public Iterable<Directive> process(final XML xml) throws IOException {
final Shell shell = new TalkShells(xml).get();
final String instance = xml.xpath("/talk/ec2/@id").get(0);
final String host = xml.xpath("/talk/shell/host/text()").get(0);
final Directives dirs = new Directives();
int attempt = 0;
while (true) {
try {
new Shell.Empty(new Shell.Safe(shell)).exec("whoami");
Logger.warn(
this, "AWS instance %s is alive at %s",
instance, host
);
break;
// @checkstyle IllegalCatchCheck (1 line)
} catch (final Exception ex) {
Logger.warn(
this, "Failed to ping AWS instance %s at %s (attempt no.%d): %s",
xml.xpath("/talk/ec2/@id").get(0),
xml.xpath("/talk/shell/host/text()").get(0),
attempt,
ex.getMessage()
instance, host, attempt, ex.getMessage()
);
++attempt;
if (attempt > 5) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/agents/daemons/EndsDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Iterable<Directive> process(final XML xml) throws IOException {
final Directives dirs = new Directives();
if (exit == 0) {
Logger.info(
this, "the daemon is still running in %s (%s)",
this, "The daemon is still running in %s (%s)",
dir, xml.xpath("/talk/@name").get(0)
);
} else {
Expand Down

0 comments on commit 2afc866

Please sign in to comment.