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

Fix class loader issue for notifications response #38

Closed
wants to merge 5 commits into from
Closed

Fix class loader issue for notifications response #38

wants to merge 5 commits into from

Conversation

joshuali925
Copy link
Member

Signed-off-by: Joshua Li joshuali925@gmail.com

Description

fix from @dai-chen:
Recreate the response object from ActionResponse as specific notifications response in notifications plugin interface to avoid classloader issue when passing response between plugins

Issues Resolved

#37

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
@joshuali925 joshuali925 added the bug Something isn't working label Jul 14, 2021
dai-chen
dai-chen previously approved these changes Jul 14, 2021
Copy link
Contributor

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this as a start.

Try to refactor this where you don't need to override fun onResponse manually in every instance.

I think I want to be able to write this:

wrapper.execute(
    SEND_NOTIFICATION_ACTION_TYPE,
    SendNotificationRequest(eventSource, channelMessage, channelIds, threadContext),
    object: SomeNewType<ActionResponse, SendNotificationResponse>
}

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be refactored, and definitely needs tests to be merged.

@dai-chen
Copy link
Contributor

dai-chen commented Jul 14, 2021

I love this as a start.

Try to refactor this where you don't need to override fun onResponse manually in every instance.

I think I want to be able to write this:

wrapper.execute(
    SEND_NOTIFICATION_ACTION_TYPE,
    SendNotificationRequest(eventSource, channelMessage, channelIds, threadContext),
    object: SomeNewType<ActionResponse, SendNotificationResponse>
}

I was trying to extract a wrapActionListener method though had problem with recreateObject() function which requires reified type (generic type didn't work). Let me give it another try. Thanks!

Signed-off-by: Joshua Li <joshuali925@gmail.com>
Signed-off-by: Joshua Li <joshuali925@gmail.com>
@dblock
Copy link
Member

dblock commented Jul 14, 2021

@joshuali925 excellent!

Is it worth putting this into a method (e.g. executeAction) that takes DELETE_NOTIFICATION_CONFIG_ACTION_TYPE, and DeleteNotificationConfigResponse or are we trying too hard?

client.execute(
            DELETE_NOTIFICATION_CONFIG_ACTION_TYPE,
            request,
            listener
            wrapActionListener(listener) { response -> recreateObject(response) { DeleteNotificationConfigResponse(it) } }
        )

I almost think that maybe this entire implementation is a map of DELETE_NOTIFICATION_CONFIG_ACTION_TYPE -> DeleteNotificationConfigResponse, but it's getting very meta. 🤔

Signed-off-by: Joshua Li <joshuali925@gmail.com>
@joshuali925
Copy link
Member Author

@dblock agree that could look cleaner, but in sendNotification the client is wrapped with SecureClientWrapper before calling execute. I assume we'll need to make this an exception if we generalize the execute function, and i'm not sure if there will be other exceptions in the future. Anyways I'll also defer to @dai-chen since he is coming up with the fixes and refactoring

val threadContext: String? =
client.threadPool().threadContext.getTransient<String>(OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT)
val wrapper = SecureClientWrapper(client) // Executing request in privileged mode
wrapper.execute(
SEND_NOTIFICATION_ACTION_TYPE,
SendNotificationRequest(eventSource, channelMessage, channelIds, threadContext),
wrapActionListener(listener) { response -> recreateObject(response) { SendNotificationResponse(it) } }
)

@dai-chen
Copy link
Contributor

Closing for #40

@dai-chen dai-chen closed this Jul 19, 2021
@dai-chen
Copy link
Contributor

@dblock agree that could look cleaner, but in sendNotification the client is wrapped with SecureClientWrapper before calling execute. I assume we'll need to make this an exception if we generalize the execute function, and i'm not sure if there will be other exceptions in the future. Anyways I'll also defer to @dai-chen since he is coming up with the fixes and refactoring

val threadContext: String? =
client.threadPool().threadContext.getTransient<String>(OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT)
val wrapper = SecureClientWrapper(client) // Executing request in privileged mode
wrapper.execute(
SEND_NOTIFICATION_ACTION_TYPE,
SendNotificationRequest(eventSource, channelMessage, channelIds, threadContext),
wrapActionListener(listener) { response -> recreateObject(response) { SendNotificationResponse(it) } }
)

@joshuali925 @dblock I tried this idea but the code was not clean as I thought. This is mostly because of generic types and number fo params required by each execute call. I would suggest keeping it as is for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants