Improve error reporting.
This commit is contained in:
parent
f24b6aca52
commit
3b0fb02fbe
2 changed files with 32 additions and 0 deletions
|
|
@ -21,9 +21,11 @@ package org.jdrupes.vmoperator.manager;
|
|||
import io.kubernetes.client.openapi.ApiException;
|
||||
import io.kubernetes.client.openapi.Configuration;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import org.jgrapes.core.Channel;
|
||||
import org.jgrapes.core.Component;
|
||||
import org.jgrapes.core.annotation.Handler;
|
||||
import org.jgrapes.core.events.HandlingError;
|
||||
import org.jgrapes.core.events.Start;
|
||||
|
||||
/**
|
||||
|
|
@ -74,6 +76,20 @@ public class Controller extends Component {
|
|||
attach(new Reconciler(channel()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Special handling of {@link ApiException} thrown by handlers.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@Handler(channels = Channel.class)
|
||||
public void onHandlingError(HandlingError event) {
|
||||
if (event.throwable() instanceof ApiException exc) {
|
||||
logger.log(Level.WARNING, exc,
|
||||
() -> "Problem accessing kubernetes: " + exc.getResponseBody());
|
||||
event.stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the start event. Has higher priority because it configures
|
||||
* the default Kubernetes client.
|
||||
|
|
|
|||
|
|
@ -32,9 +32,11 @@ import org.apache.commons.cli.Option;
|
|||
import org.apache.commons.cli.Options;
|
||||
import static org.jdrupes.vmoperator.manager.Constants.VM_OP_NAME;
|
||||
import org.jdrupes.vmoperator.util.FsdUtils;
|
||||
import org.jgrapes.core.Channel;
|
||||
import org.jgrapes.core.Component;
|
||||
import org.jgrapes.core.Components;
|
||||
import org.jgrapes.core.annotation.Handler;
|
||||
import org.jgrapes.core.events.HandlingError;
|
||||
import org.jgrapes.core.events.Stop;
|
||||
import org.jgrapes.io.NioDispatcher;
|
||||
import org.jgrapes.util.FileSystemWatcher;
|
||||
|
|
@ -95,6 +97,20 @@ public class Manager extends Component {
|
|||
fire(new WatchFile(config.toPath()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the exception when a handling error is reported.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@Handler(channels = Channel.class, priority = -10_000)
|
||||
@SuppressWarnings("PMD.GuardLogStatement")
|
||||
public void onHandlingError(HandlingError event) {
|
||||
logger.log(Level.WARNING, event.throwable(),
|
||||
() -> "Problem invoking handler with " + event.event() + ": "
|
||||
+ event.message());
|
||||
event.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* On stop.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue