Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/multi_tenancy] Delay context restoring for initializing master key and deleting agent #2866

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -95,20 +95,19 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
.build();

try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {

ActionListener<DeleteResponse> wrappedListener = ActionListener.runBefore(actionListener, context::restore);
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) {
Exception cause = SdkClientUtils.unwrapAndConvertToException(throwable);
if (cause instanceof IndexNotFoundException) {
log.info("Failed to get Agent index", cause);
actionListener.onFailure(new OpenSearchStatusException("Failed to get agent index", RestStatus.NOT_FOUND));
wrappedListener.onFailure(new OpenSearchStatusException("Failed to get agent index", RestStatus.NOT_FOUND));
} else {
log.error("Failed to get ML Agent {}", agentId, cause);
actionListener.onFailure(cause);
wrappedListener.onFailure(cause);
}
} else {
try {
Expand All @@ -122,9 +121,14 @@ protected void doExecute(Task task, ActionRequest request, ActionListener<Delete
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
MLAgent mlAgent = MLAgent.parse(parser);
if (TenantAwareHelper
.validateTenantResource(mlFeatureEnabledSetting, tenantId, mlAgent.getTenantId(), actionListener)) {
.validateTenantResource(
mlFeatureEnabledSetting,
tenantId,
mlAgent.getTenantId(),
wrappedListener
)) {
if (mlAgent.getIsHidden() && !isSuperAdmin) {
actionListener
wrappedListener
.onFailure(
new OpenSearchStatusException(
"User doesn't have privilege to perform this operation on this agent",
Expand All @@ -144,30 +148,25 @@ 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) -> {
handleDeleteResponse(response, delThrowable, tenantId, wrappedListener);
});
} catch (Exception e) {
log.error("Failed to delete ML agent: {}", agentId, e);
actionListener.onFailure(e);
wrappedListener.onFailure(e);
}
}
}
} catch (Exception e) {
log.error("Failed to parse ml agent {}", agentId, e);
actionListener.onFailure(e);
wrappedListener.onFailure(e);
}
} else {
actionListener.onFailure(new OpenSearchStatusException("Fail to find ml agent", RestStatus.NOT_FOUND));
wrappedListener.onFailure(new OpenSearchStatusException("Fail to find ml agent", RestStatus.NOT_FOUND));
}
} catch (Exception e) {
log.error("Failed to delete ML agent: {}", agentId, e);
actionListener.onFailure(e);
wrappedListener.onFailure(e);
}
}
});
Expand Down
Loading