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

Cleanup and pull in recent Java SDK features #28

Conversation

AnotherDaniel
Copy link
Contributor

Cargo.toml Show resolved Hide resolved
@@ -23,6 +23,58 @@ use crate::cloudevents::cloud_event::CloudEventAttributeValue;
use crate::cloudevents::cloud_event::Data as CloudEventData;
use crate::cloudevents::CloudEvent as CloudEventProto;

use crate::uprotocol::umessage::UMessage;
use crate::uri::serializer::{LongUriSerializer, UriSerializer};
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO it'd be nice if we're only using LongUriSerializer to only have to use that one, i.e. only have to:

use crate::uri::serializer::{LongUriSerializer};

I think we can achieve that by modifying this line:

use crate::uri::serializer::{SerializationError, UriSerializer};

to

pub use crate::uri::serializer::{SerializationError, UriSerializer};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addendum - this doesn't really work for some reason, dependent code still won't compile without explicitly use-ing the Trait implementation. I guess I'll revert this change for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad! Looks like this is not possible in Rust. We have to bring the trait into scope explicitly with a use. Seems this is a conscious design decision to help when multiple traits define things with the same names and helps readability to understand where a function could be coming from.


impl From<UMessage> for cloudevents::Event {
fn from(source_event: UMessage) -> Self {
let source = source_event.source.get_or_default();
Copy link
Contributor

@PLeVasseur PLeVasseur Jan 30, 2024

Choose a reason for hiding this comment

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

I noticed leaning on getting default and unwraps throughout.

I'm wondering if we should be doing any additional error checking and make it TryFrom instead to reflect that it may fail?

I suppose it depends on the context in which this will be used as well.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have a try_from now - However, next I will have to spend some quality time revisiting the test setup for cloudevent.rs, stay tuned for another change in that area.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests redone, looking a bit more robust

attributes: UAttributes,
method: UUri,
request: UPayload,
options: CallOptions,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

let payload = response?; // Directly returns in case of error
Any::try_from(payload)
let message = response?; // Directly returns in case of error
Any::try_from(message.payload.unwrap())
Copy link
Contributor

Choose a reason for hiding this comment

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

Funnily enough, I was doing the same thing over in this PR 😆

We should probably be a little more careful here, similar to what I did on that PR s.t. we don't accidentally panic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pulled that in - and apologies for waltzing over your work there!

let any = RpcMapper::pack_any(&status)?;
Ok(any.try_into().unwrap())
let payload =
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, funny we both did this haha

Kai gave some good feedback on that PR on how to handle this nicely, perhaps you could reference that?

/// # Returns
///
/// Returns `true` if the `UAuthority` can be represented in micro format, `false` otherwise.
pub fn is_micro_form_authority(authority: &UAuthority) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

This one I would pause on tho. IMHO it makes more sense to merge the PR I've got going for this functionality. That PR goes into a lot more detail in checking also that the fields from the UUri are able to fit the specified number of bits & bytes available.

If the PR I have for checking micro form goes through, that can then be mirrored back to up-java.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed!

@PLeVasseur
Copy link
Contributor

PLeVasseur commented Jan 30, 2024

Overall good to stay in sync with up-java, but I'd recommend removing this bit here for is_micro_form_authority() since this other PR I have does further checking into buffer size & available number of bytes.

I'll go close this other PR doing just the invoke_method() -> UMessage bit.

If you could remove that bit, I think we're good 👍

Copy link

@stevenhartley stevenhartley left a comment

Choose a reason for hiding this comment

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

Mapping error for priority that needs fixing

if let Some(token) = &attributes.token {
event.set_extension("token", ExtensionValue::String(token.to_string()));
}
if let Ok(priority) = attributes.priority.enum_value() {

Choose a reason for hiding this comment

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

CloudEvent priority needs to be "CS1", "CS2" i.e string. I'm adding the mapping in core-api now so you can pull from proto but it is not an integer. eclipse-uprotocol/up-core-api#98

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the changes to achieve this - not yet based off the referenced PR, but manually. Will change that bit as soon as up-core-api#98 is merged.

@stevenhartley
Copy link

@dakrbo let me know when this is ready for merge (lint & test failed)

@AnotherDaniel
Copy link
Contributor Author

AnotherDaniel commented Feb 5, 2024 via email

@AnotherDaniel
Copy link
Contributor Author

Ok; I did the test case rework that was necessary - now this needs a new/current tag in up-core-api, with the recent protobuf-options changes in. @stevenhartley are you planning to do a tag there soon?

@stevenhartley
Copy link

Yes I will do a release this week, not waiting for the other changes that I want to review at the generic uProtocol meeting on Thursday.

@@ -41,7 +51,7 @@ pub trait UTransport {
///
/// # Returns
/// Returns () on success, otherwise an Err(UStatus) with the appropriate failure information.
async fn send(
async fn send_parts(
Copy link
Contributor

Choose a reason for hiding this comment

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

FMPOV we do not need this function now that we use UMessage as the input parameter.
However, it seems that we are missing the Receive function required by the spec ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree and fixed

@@ -47,7 +47,7 @@ pub trait UTransport {
/// On success, returns a tuple containing the received `UPayload` and `UAttributes` wrapped in `Ok(_)`.
/// If receiving the message fails, it returns `Err(UStatus)`,
/// where `UStatus` contains a `UCode` indicating the specific error or failure reason.
async fn receive(&self, topic: UUri) -> Result<(UPayload, UAttributes), UStatus>;
async fn receive(&self, topic: UUri) -> Result<UMessage, UStatus>;
Copy link
Contributor

Choose a reason for hiding this comment

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

The doc comment still refers to the original types. Which also is a good example for why you should not mention the types of parameters in the doc comments at all (they are obvious from the generated documentation anyway) ;-)

@sophokles73
Copy link
Contributor

sophokles73 commented Feb 9, 2024

@AnotherDaniel There is no doubt that the changes in this PR are relevant and helpful 👍
However, the PR contains quite a few changes which do not necessarily seem to be related to each other. This makes it quite hard to review and rebase, because it touches on so many areas. For the future, I would suggest to try to keep the scope of a PR small and consistent and try to only change things that are in scope. That will make it much easier to get things reviewed and merged.

Oh, and before I forget: you should probably make sure that you squash your changes into a few consistent commits before having the PR merged ...

@AnotherDaniel
Copy link
Contributor Author

I'm still mentally working my way down from the all-encompassing initial commit, but point taken :)

@AnotherDaniel
Copy link
Contributor Author

AnotherDaniel commented Feb 14, 2024

@PLeVasseur , I had to do a number on the MicroUriSerializer code, to make it work with up-core-api v1.5.6 - sorry to get in the way of of your #18 there, probably you can update that one to the same up-core-api and then take over my changes?
@sophokles73 I'm on the fence about also removing the remaining UAuthority::get_name() method; but without that using the name field of UAuthority always feels ugly. WDYT?

@sophokles73
Copy link
Contributor

Why do you want to remove the getters from UAuthority in the first place? Aren't they useful anymore?

@AnotherDaniel
Copy link
Contributor Author

They now come with the generated code...

@sophokles73
Copy link
Contributor

@AnotherDaniel can you rebase this PR?

Copy link
Contributor

@sophokles73 sophokles73 left a comment

Choose a reason for hiding this comment

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

LGTM

@AnotherDaniel
Copy link
Contributor Author

@stevenhartley the changes you requested wrt up-core-api 1.5.6 (umessage option strings) are in now

@stevenhartley stevenhartley merged commit 141a139 into eclipse-uprotocol:main Feb 14, 2024
3 checks passed
@AnotherDaniel AnotherDaniel deleted the update_and_sync_recent_changes branch February 15, 2024 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants