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

RDSK-2417 Remove ResourceType #184

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

benjirewis
Copy link
Member

@benjirewis benjirewis commented Nov 28, 2023

@@ -17,6 +17,7 @@ class MySummation : public Summation {
};
void reconfigure(Dependencies deps, ResourceConfig cfg) override;
static std::vector<std::string> validate(ResourceConfig cfg);
void stop(const AttributeMap& extra) override{};
Copy link
Member Author

Choose a reason for hiding this comment

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

There were quite a few places I had to add stop due to it being a purely virtual method (I don't really understand how #182 was merged without these changes). I would say I'm against having every resource implement its own stop method, and would rather use a noop default method for the time being. IMO there should be an ActuatingComponent class or something that inherits from Component with virtual is_moving and stop methods, but that might be work for another ticket? Let me know if I'm missing some reason for the purely virtual stop.

Copy link
Member

Choose a reason for hiding this comment

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

There's a ticket to address this here, I think the current proposal is to have a StoppableResource class that can be inherited from.

I understand the inconvenience of having to implement a no-op stop for sure but I'm not convinced that having stop default is better. It's (trivially) less work and a bit less pointy, but it also makes it possible for people to potentially do Quite Bad things by failing to implement stop when it is necessary. My preference would be to back out the stop changes here and just focus on the ResourceType removal, and then make the more principled change in a separate PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

My bad; totally missed that ticket! Totally understand the concern; I'll remove all stop changes from this PR for now, thanks for the context.

@benjirewis benjirewis requested a review from stuqdog November 28, 2023 22:03
@benjirewis benjirewis marked this pull request as ready for review November 28, 2023 22:03
@benjirewis benjirewis requested a review from a team as a code owner November 28, 2023 22:03
@benjirewis benjirewis requested review from njooma and removed request for a team November 28, 2023 22:03
@benjirewis benjirewis changed the title RDSK-2417 Remove ResourceType and add missing stop methods RDSK-2417 Remove ResourceType and make stop default to a noop Nov 28, 2023
@benjirewis benjirewis changed the title RDSK-2417 Remove ResourceType and make stop default to a noop RDSK-2417 Remove ResourceType Nov 29, 2023
Copy link
Member

@acmorrow acmorrow left a comment

Choose a reason for hiding this comment

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

Overall this looks good, with a question about the changes in utils.cpp.

Meanwhile, do we have any rough idea how many modules on the registry this breaking change will affect? I know that at least the triton module will need an update.

@benjirewis
Copy link
Member Author

with a question about the changes in utils.cpp.

Sorry I don't see any GH comments in the utils.cpp file; which question are you referring to?

do we have any rough idea how many modules on the registry this breaking change will affect

I think it will break basically all C++ modules in the registry.

Comment on lines +28 to +47
std::string resource_subtype;
std::vector<ResourceName> resource_names;
for (auto& kv : Registry::registered_models()) {
const std::shared_ptr<ModelRegistration> reg = kv.second;
if (reg->api().to_string() == resource->dynamic_api().to_string()) {
resource_type = reg->api().resource_subtype();
resource_type = reg->api().resource_type();
resource_subtype = reg->api().resource_subtype();
} else {
continue;
}

if (resource_type.empty()) {
resource_type = resource->name();
if (resource_subtype.empty()) {
resource_subtype = resource->name();
}

ResourceName r;
*r.mutable_namespace_() = kRDK;
*r.mutable_type() = resource->type().to_string();
*r.mutable_name() = resource->name();
*r.mutable_subtype() = resource_type;
*r.mutable_type() = resource_type;
*r.mutable_subtype() = resource_subtype;
Copy link
Member

Choose a reason for hiding this comment

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

@benjirewis - These are the lines I was referring to in my comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry I still must be missing a comment or something; I'm still not sure what your question is.

I realize the code here is a little funky; basically we were creating a resource name with namespace set to "rdk", type set to the ResourceType of the Resource (a field that no longer exists), subtype set to the subtype of the API registration (although we were using a local variable named resource_type), and name set to resource->name(). Now we set namespace to "rdk", type to the type of the API registration, subtype to the subtype of the API registration, and name to resource->name(). I do wonder if I should be setting resource_type to something in the event that (reg->api().to_string() != resource->dynamic_api().to_string()); maybe @stuqdog will know.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see. You needed to change it because resource->type() is no longer a thing. At first I didn't see that and I couldn't see what it was that required changes here due to the removal of ResourceType.

I do agree that the code is pretty funky. Hopefully @stuqdog can clarify whether what you have here is OK or needs the handling you suggest, as I'm not certain either.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the slow response. I think what we have here is correct. In the event that (reg->api().to_string() != resource->dynamic_api().to_string()) then the registered model we're looking at is not of the provided resource type and so we continue on line 34. This isn't a case where we're creating a ResourceName that lacks a resource_type but rather a case where we aren't creating a ResourceName at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah cool that makes sense! Thanks for context.

@acmorrow
Copy link
Member

do we have any rough idea how many modules on the registry this breaking change will affect

I think it will break basically all C++ modules in the registry.

It definitely will. I'm just wondering if we know somehow how many modules that might be, and, if so, how many are viam produced (100%?).

@benjirewis
Copy link
Member Author

It definitely will. I'm just wondering if we know somehow how many modules that might be, and, if so, how many are viam produced (100%?)

Yeah good idea let me look into that; modules will break even more with #185, so it'll be good to get a sense of which modules we need to fix now.

Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

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

lgtm!

@benjirewis
Copy link
Member Author

Gonna wait until we have a list of all C++ modules this change might break before merging.

Copy link
Member

@njooma njooma left a comment

Choose a reason for hiding this comment

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

Love seeing all the red

@benjirewis benjirewis merged commit 27072e0 into viamrobotics:main Nov 30, 2023
2 checks passed
@benjirewis benjirewis deleted the remove-resource-type branch November 30, 2023 19:03
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.

5 participants