Skip to content

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

Merged
JamesNK merged 1 commit intomainfrom
jamesnk/appexe-refactor
Jan 24, 2025
Merged

Start to split AppExecutor, call events on restart of resources#7206
JamesNK merged 1 commit intomainfrom
jamesnk/appexe-refactor

Conversation

@JamesNK
Copy link
Copy Markdown
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
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@JamesNK
Copy link
Copy Markdown
Member Author

JamesNK commented Jan 23, 2025

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).


namespace Aspire.Hosting.Dcp;

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

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
Copy Markdown
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
Copy Markdown
Contributor

@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
Copy Markdown
Contributor

@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 force-pushed the jamesnk/appexe-refactor branch from 01fc6e7 to 5cd3d7a Compare January 24, 2025 03:57
@JamesNK JamesNK merged commit 5633dc4 into main Jan 24, 2025
@JamesNK JamesNK deleted the jamesnk/appexe-refactor branch January 24, 2025 05:20
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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