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

[WIP] example of trait-based Dropshot server #5653

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sunshowers
Copy link
Contributor

@sunshowers sunshowers commented Apr 29, 2024

As discussed in #5247.

This PR converts the Nexus internal API to being a trait-based server, using the patched copy of Dropshot in oxidecomputer/dropshot#984. Thought converting a non-trivial but still relatively simple API would be able to give us a better sense of what we want the eventual API to look like.

The main advantage is that this lets you generate the internal API without having to compile all of Nexus. This is not only faster, I believe it completely solves issues where there are circular dependencies between different APIs. (For example, currently there's a Nexus internal API -> sled-agent -> Nexus internal API dependency, and changing the APIs can be extremely painful. With this approach, the API crates don't depend on each other -- only the implementation crates do.)

Another advantage is that it's pretty easy to write multiple implementations of the same API. So, for example, the simulated sled-agent can implement the same trait as the real one.

Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
path = "/sled-agents/{sled_id}",
}]
async fn sled_agent_get(
rqctx: RequestContext<Self>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Static dispatch is nicer because

  • you don't have to prove that the trait is object-safe
  • you can also add non-endpoint methods and other items to the trait
  • you don't need to use async-trait, leading to a nicer IDE/rust-analyzer experience.

Comment on lines -70 to -113
api.register(sled_agent_get)?;
api.register(sled_agent_put)?;
api.register(sled_firewall_rules_request)?;
api.register(switch_put)?;
api.register(rack_initialization_complete)?;
api.register(cpapi_instances_put)?;
api.register(cpapi_disks_put)?;
api.register(cpapi_volume_remove_read_only_parent)?;
api.register(cpapi_disk_remove_read_only_parent)?;
api.register(cpapi_producers_post)?;
api.register(cpapi_assigned_producers_list)?;
api.register(cpapi_collectors_post)?;
api.register(cpapi_artifact_download)?;

api.register(cpapi_upstairs_repair_start)?;
api.register(cpapi_upstairs_repair_finish)?;
api.register(cpapi_upstairs_repair_progress)?;
api.register(cpapi_downstairs_client_stop_request)?;
api.register(cpapi_downstairs_client_stopped)?;

api.register(saga_list)?;
api.register(saga_view)?;

api.register(ipv4_nat_changeset)?;

api.register(bgtask_list)?;
api.register(bgtask_view)?;
api.register(bgtask_activate)?;

api.register(blueprint_list)?;
api.register(blueprint_view)?;
api.register(blueprint_delete)?;
api.register(blueprint_target_view)?;
api.register(blueprint_target_set)?;
api.register(blueprint_target_set_enabled)?;
api.register(blueprint_regenerate)?;
api.register(blueprint_import)?;

api.register(sled_list_uninitialized)?;
api.register(sled_add)?;
api.register(sled_expunge)?;

api.register(probes_get)?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now automatically handled!

Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
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.

None yet

1 participant