Skip to content

Commit

Permalink
Add exception handling for InstanceNotFoundExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Matsuoka committed Apr 19, 2024
1 parent d027fcd commit da24456
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/io/cryostat/targets/TargetConnectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Semaphore;

import javax.management.InstanceNotFoundException;
import javax.management.remote.JMXServiceURL;
import javax.security.sasl.SaslException;

Expand Down Expand Up @@ -200,6 +201,8 @@ public <T> Uni<T> executeConnectedTaskUni(Target target, ConnectedTask<T> task)
.transform(t -> unwrapNestedException(RuntimeException.class, t))
.onFailure()
.invoke(logger::warn)
.onFailure(this::isInstanceNotFoundFailure)
.transform(t -> new HttpException(400, t))
.onFailure(this::isJmxAuthFailure)
.transform(t -> new HttpException(427, t))
.onFailure(this::isJmxSslFailure)
Expand Down Expand Up @@ -235,6 +238,8 @@ public <T> Uni<T> executeDirect(
.transform(t -> unwrapNestedException(RuntimeException.class, t))
.onFailure()
.invoke(logger::warn)
.onFailure(this::isInstanceNotFoundFailure)
.transform(t -> new HttpException(400, t))
.onFailure(this::isJmxAuthFailure)
.transform(t -> new HttpException(427, t))
.onFailure(this::isJmxSslFailure)
Expand Down Expand Up @@ -458,6 +463,15 @@ private boolean isServiceTypeFailure(Throwable t) {
&& ExceptionUtils.indexOfType(e, SocketTimeoutException.class) >= 0;
}

/** Check if the exception happened because an MBean was not found */
private boolean isInstanceNotFoundFailure(Throwable t) {
if (!(t instanceof Exception)) {
return false;
}
Exception e = (Exception) t;
return ExceptionUtils.indexOfType(e, InstanceNotFoundException.class) >= 0;
}

@Name("io.cryostat.targets.TargetConnectionManager.TargetConnectionOpened")
@Label("Target Connection Opened")
@Category("Cryostat")
Expand Down

0 comments on commit da24456

Please sign in to comment.