Skip to content

Commit

Permalink
Add top level exception handling #205
Browse files Browse the repository at this point in the history
* added configurable handling to watchers
  • Loading branch information
jfaltermeier committed Aug 3, 2023
1 parent 0211275 commit c8ac69e
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public enum BandwidthLimiter {
"--maxWatchIdleTime" }, description = "When a kubernetes watcher is idle for more than this time (in milliseconds) we assume that there is a problem and restart.", required = false)
private long maxWatchIdleTime = 1000 * 60 * 60; // 1 Hour

@Option(names = {
"--continueOnException" }, description = "Whether the operator will continue to run in case of unexpected exceptions.", required = false)
private boolean continueOnException;

public boolean isUseKeycloak() {
return useKeycloak;
}
Expand Down Expand Up @@ -206,13 +210,18 @@ public long getMaxWatchIdleTime() {
return maxWatchIdleTime;
}

public boolean isContinueOnException() {
return continueOnException;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((appId == null) ? 0 : appId.hashCode());
result = prime * result + ((bandwidthLimiter == null) ? 0 : bandwidthLimiter.hashCode());
result = prime * result + ((cloudProvider == null) ? 0 : cloudProvider.hashCode());
result = prime * result + (continueOnException ? 1231 : 1237);
result = prime * result + (eagerStart ? 1231 : 1237);
result = prime * result + (enableActivityTracker ? 1231 : 1237);
result = prime * result + (enableMonitor ? 1231 : 1237);
Expand Down Expand Up @@ -254,6 +263,8 @@ public boolean equals(Object obj) {
return false;
if (cloudProvider != other.cloudProvider)
return false;
if (continueOnException != other.continueOnException)
return false;
if (eagerStart != other.eagerStart)
return false;
if (enableActivityTracker != other.enableActivityTracker)
Expand Down Expand Up @@ -341,7 +352,7 @@ public String toString() {
+ requestedStorage + ", keycloakURL=" + keycloakURL + ", keycloakRealm=" + keycloakRealm
+ ", keycloakClientId=" + keycloakClientId + ", leaderLeaseDuration=" + leaderLeaseDuration
+ ", leaderRenewDeadline=" + leaderRenewDeadline + ", leaderRetryPeriod=" + leaderRetryPeriod
+ ", maxWatchIdleTime=" + maxWatchIdleTime + "]";
+ ", maxWatchIdleTime=" + maxWatchIdleTime + ", continueOnException=" + continueOnException + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -158,65 +158,83 @@ protected void initSession(Session resource) {
}

protected void handleAppDefnitionEvent(Watcher.Action action, String uid, String correlationId) {
AppDefinition appDefinition = appDefinitionCache.get(uid);
switch (action) {
case ADDED:
appDefinitionAddedHandler.appDefinitionAdded(appDefinition, correlationId);
break;
case DELETED:
appDefinitionAddedHandler.appDefinitionDeleted(appDefinition, correlationId);
break;
case MODIFIED:
appDefinitionAddedHandler.appDefinitionModified(appDefinition, correlationId);
break;
case ERROR:
appDefinitionAddedHandler.appDefinitionErrored(appDefinition, correlationId);
break;
case BOOKMARK:
appDefinitionAddedHandler.appDefinitionBookmarked(appDefinition, correlationId);
break;
try {
AppDefinition appDefinition = appDefinitionCache.get(uid);
switch (action) {
case ADDED:
appDefinitionAddedHandler.appDefinitionAdded(appDefinition, correlationId);
break;
case DELETED:
appDefinitionAddedHandler.appDefinitionDeleted(appDefinition, correlationId);
break;
case MODIFIED:
appDefinitionAddedHandler.appDefinitionModified(appDefinition, correlationId);
break;
case ERROR:
appDefinitionAddedHandler.appDefinitionErrored(appDefinition, correlationId);
break;
case BOOKMARK:
appDefinitionAddedHandler.appDefinitionBookmarked(appDefinition, correlationId);
break;
}
} catch (Exception e) {
LOGGER.error(formatLogMessage(correlationId, "Error while handling app definitions"), e);
}
}

protected void handleSessionEvent(Watcher.Action action, String uid, String correlationId) {
Session session = sessionCache.get(uid);
switch (action) {
case ADDED:
sessionHandler.sessionAdded(session, correlationId);
break;
case DELETED:
sessionHandler.sessionDeleted(session, correlationId);
break;
case MODIFIED:
sessionHandler.sessionModified(session, correlationId);
break;
case ERROR:
sessionHandler.sessionErrored(session, correlationId);
break;
case BOOKMARK:
sessionHandler.sessionBookmarked(session, correlationId);
break;
try {
Session session = sessionCache.get(uid);
switch (action) {
case ADDED:
sessionHandler.sessionAdded(session, correlationId);
break;
case DELETED:
sessionHandler.sessionDeleted(session, correlationId);
break;
case MODIFIED:
sessionHandler.sessionModified(session, correlationId);
break;
case ERROR:
sessionHandler.sessionErrored(session, correlationId);
break;
case BOOKMARK:
sessionHandler.sessionBookmarked(session, correlationId);
break;
}
} catch (Exception e) {
LOGGER.error(formatLogMessage(correlationId, "Error while handling sessions"), e);
if (!arguments.isContinueOnException()) {
System.exit(-1);
}
}
}

protected void handleWorkspaceEvent(Watcher.Action action, String uid, String correlationId) {
Workspace workspace = workspaceCache.get(uid);
switch (action) {
case ADDED:
workspaceHandler.workspaceAdded(workspace, correlationId);
break;
case DELETED:
workspaceHandler.workspaceDeleted(workspace, correlationId);
break;
case MODIFIED:
workspaceHandler.workspaceModified(workspace, correlationId);
break;
case ERROR:
workspaceHandler.workspaceErrored(workspace, correlationId);
break;
case BOOKMARK:
workspaceHandler.workspaceBookmarked(workspace, correlationId);
break;
try {
Workspace workspace = workspaceCache.get(uid);
switch (action) {
case ADDED:
workspaceHandler.workspaceAdded(workspace, correlationId);
break;
case DELETED:
workspaceHandler.workspaceDeleted(workspace, correlationId);
break;
case MODIFIED:
workspaceHandler.workspaceModified(workspace, correlationId);
break;
case ERROR:
workspaceHandler.workspaceErrored(workspace, correlationId);
break;
case BOOKMARK:
workspaceHandler.workspaceBookmarked(workspace, correlationId);
break;
}
} catch (Exception e) {
LOGGER.error(formatLogMessage(correlationId, "Error while handling workspaces"), e);
if (!arguments.isContinueOnException()) {
System.exit(-1);
}
}
}

Expand All @@ -237,6 +255,9 @@ protected void stopTimedOutSessions() {
}
} catch (Exception e) {
LOGGER.error(formatLogMessage(COR_ID_TIMEOUTPREFIX, correlationId, "Exception in kill after runnable"), e);
if (!arguments.isContinueOnException()) {
System.exit(-1);
}
}
}

Expand Down

0 comments on commit c8ac69e

Please sign in to comment.