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

Start to split AppExecutor, call events on restart of resources #7206

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Jan 22, 2025

Description

This PR is a start towards making ApplicationExecutor less of a monster. The new DcpExecutor is about 400 lines smaller.

  • Add ApplicationOrchestrator. The orchestrator starts the DCP executor and subscribes to events from it. The orchestrator raises Aspire lifecycle events and publishes resource notifications. It handles managing parent/child notifications.
  • Rename ApplicationExecutor to DcpExecutor.
  • Add IDcpExecutor. Allows ApplicationOrchestrator to be tested independently.
  • Add DcpExecutorEvents. Use by DCP executor to publish events and the orchestrator to subscribe. Copies what DistributedApplicationEventing does but much simplified.
  • Add ResourceSnapshotPublisher. Moves building resource snapshots from DCP resources out into a seperate file.
  • Add DcpHost. This splits the logic related to starting DCP process into its own file.
  • Refactor DcpHostService into OrchestratorHostService. The orchestrator host service starts the DCP process using DcpHost then starts the orchestrator.
  • Improved StartResourceAsync to call the OnResourceStarting event, which then triggers Aspire lifecycle events for the resource (BeforeResourceStartedEvent, waiting for health checks, etc)
  • Improved StartResourceAsync to set a resource to FailedToStart state if there is an exeception.

TODO:

  • Add tests for StartResourceAsync improvements

Fixes #7011

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@JamesNK JamesNK added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Jan 22, 2025
@JamesNK JamesNK requested review from davidfowl and eerhardt January 22, 2025 13:18
@JamesNK JamesNK requested a review from mitchdenny as a code owner January 22, 2025 13:18
@davidfowl
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@JamesNK
Copy link
Member Author

JamesNK commented Jan 23, 2025

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).


namespace Aspire.Hosting.Dcp;

internal record ResourceStatus(string? State, DateTime? StartupTimestamp, DateTime? FinishedTimestamp);
Copy link
Member

Choose a reason for hiding this comment

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

Why didn't you use an interface here? Do we have multiple subscribers?

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 are never multiple subscribers for these events. Just ApplicationOrchestrator uses this to listen to changes from DCP.

Are you asking about why not an interface for DcpExecutorEvents? There is only one implementation. The type could disappear and it becomes part of DcpExecutor/IDcpExecutor, but having it separated feels more usable in tests.

Copy link
Member

@davidfowl davidfowl Jan 23, 2025

Choose a reason for hiding this comment

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

I’m asking why isn’t the dcp executor just calling interface methods to raise the events

Copy link
Member

@davidfowl davidfowl left a comment

Choose a reason for hiding this comment

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

Had an offline discussion with @JamesNK , this enables better testing and is incremental.

@JamesNK JamesNK requested a review from radical as a code owner January 24, 2025 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BeforeResourceStartedEvent is not re-fired when application is restarted
2 participants