Skip to content

Commit

Permalink
Merge pull request juju#19002 from jack-w-shaw/JUJU-7548_wire_up_appl…
Browse files Browse the repository at this point in the history
…ication_display_status

juju#19002

Make use of the new GetApplicationDisplayStatus service method to calculate the application display status, backed by DQLite.

You may be wondering why this is included in the task to wire up *unit* statuses. This is because our facade handlers would also query the unit statuses and use those to derive the application status if it is unset.

However, this logic has now been encapsulated into the domain, so we can drop all of this.

As a result, we can also drop a lot of code out of core/status, and (*Application).UnitStatuses from the state package.

Also, as a flyby, restore apiserver/facades/agent/uniter/status_test.go tests. ApplicationStatus, the method being tested, no longer depends on Mongo state, so we can remove the factory methods and move over to mocked services entirely.

## QA steps


```
juju bootstrap lxd lxd
juju add-model m
juju deploy ubuntu
```
& watch the unit and application status, ensuring that the application becomes active when the unit does
  • Loading branch information
jujubot authored Feb 24, 2025
2 parents 810c718 + 8132b53 commit 0b1b248
Show file tree
Hide file tree
Showing 15 changed files with 297 additions and 483 deletions.
58 changes: 0 additions & 58 deletions apiserver/common/status.go

This file was deleted.

78 changes: 78 additions & 0 deletions apiserver/facades/agent/uniter/legacy_service_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apiserver/facades/agent/uniter/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func newUniterAPIWithServices(
lxdProfileAPI: NewExternalLXDProfileAPIv2(st, machineService, context.WatcherRegistry(), authorizer, accessUnit, logger, modelInfoService, applicationService),
// TODO(fwereade): so *every* unit should be allowed to get/set its
// own status *and* its application's? This is not a pleasing arrangement.
StatusAPI: NewStatusAPI(m, applicationService, accessUnitOrApplication, leadershipChecker, aClock),
StatusAPI: NewStatusAPI(st, applicationService, accessUnitOrApplication, leadershipChecker, aClock),

m: m,
st: st,
Expand Down
19 changes: 15 additions & 4 deletions apiserver/facades/agent/uniter/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,21 @@ type ApplicationService interface {

// GetApplicationIDByUnitName returns the application ID for the named unit.
//
// Returns [github.com/juju/juju/domain/application.UnitNotFound] if the
// unit is not found.
// Returns [applicationerrors.UnitNotFound] if the unit is not found.
GetApplicationIDByUnitName(ctx context.Context, unitName coreunit.Name) (coreapplication.ID, error)

// GetApplicationIDByName returns an application ID by application name.
//
// Returns [github.com/juju/juju/domain/application.ApplicationNotFound] if
// the application is not found.
// Returns [applicationerrors.ApplicationNotFound] if the application is not found.
GetApplicationIDByName(ctx context.Context, name string) (coreapplication.ID, error)

// GetApplicationDisplayStatus returns the display status of the specified application.
// The display status is equal to the application status if it is set, otherwise it is
// derived from the unit display statuses.
// If no application is found, an error satisfying [applicationerrors.ApplicationNotFound]
// is returned.
GetApplicationDisplayStatus(ctx context.Context, appID coreapplication.ID) (*corestatus.StatusInfo, error)

// GetUnitWorkloadStatus returns the workload status of the specified unit, returning an
// error satisfying [applicationerrors.UnitNotFound] if the unit doesn't exist.
GetUnitWorkloadStatus(context.Context, coreunit.Name) (*corestatus.StatusInfo, error)
Expand All @@ -105,6 +110,12 @@ type ApplicationService interface {
// application.
GetCharmModifiedVersion(ctx context.Context, id coreapplication.ID) (int, error)

// GetUnitWorkloadStatusesForApplication returns the workload statuses of all
// units in the specified application, indexed by unit name, returning an error
// satisfying [applicationerrors.ApplicationNotFound] if the application doesn't
// exist.
GetUnitWorkloadStatusesForApplication(ctx context.Context, appID coreapplication.ID) (map[coreunit.Name]corestatus.StatusInfo, error)

// GetAvailableCharmArchiveSHA256 returns the SHA256 hash of the charm archive
// for the given charm name, source and revision. If the charm is not available,
// [applicationerrors.CharmNotResolved] is returned.
Expand Down
78 changes: 78 additions & 0 deletions apiserver/facades/agent/uniter/service_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0b1b248

Please sign in to comment.