Skip to content

Commit

Permalink
Delay context restoring for initializing master key and deleting agent
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Aug 30, 2024
1 parent ab045f6 commit fe781fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ private void handleGetDataObjectResponse(
AtomicReference<Exception> exceptionRef,
CountDownLatch latch
) {
context.restore();
log.debug("Completed Get MASTER_KEY Request, for tenant id:{}", tenantId);

if (throwable != null) {
handleGetDataObjectFailure(throwable, exceptionRef, latch);
} else {
handleGetDataObjectSuccess(response, tenantId, exceptionRef, latch, context);
}
context.restore();
}

private void handleGetDataObjectFailure(Throwable throwable, AtomicReference<Exception> exceptionRef, CountDownLatch latch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
sdkClient
.getDataObjectAsync(getDataObjectRequest, client.threadPool().executor(GENERAL_THREAD_POOL))
.whenComplete((r, throwable) -> {
context.restore();
log.debug("Completed Get Agent Request, Agent id:{}", agentId);
if (throwable != null) {
context.restore();
Exception cause = SdkClientUtils.unwrapAndConvertToException(throwable);
if (cause instanceof IndexNotFoundException) {
log.info("Failed to get Agent index", cause);
Expand All @@ -124,6 +124,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
if (TenantAwareHelper
.validateTenantResource(mlFeatureEnabledSetting, tenantId, mlAgent.getTenantId(), actionListener)) {
if (mlAgent.getIsHidden() && !isSuperAdmin) {
context.restore();
actionListener
.onFailure(
new OpenSearchStatusException(
Expand All @@ -144,15 +145,12 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
.build(),
client.threadPool().executor(GENERAL_THREAD_POOL)
)
.whenComplete(
(response, delThrowable) -> handleDeleteResponse(
response,
delThrowable,
tenantId,
actionListener
)
);
.whenComplete((response, delThrowable) -> {
context.restore();
handleDeleteResponse(response, delThrowable, tenantId, actionListener);
});
} catch (Exception e) {
context.restore();
log.error("Failed to delete ML agent: {}", agentId, e);
actionListener.onFailure(e);
}
Expand Down

0 comments on commit fe781fb

Please sign in to comment.