This is an automated email from the ASF dual-hosted git repository.
chia7712 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git
The following commit(s) were added to refs/heads/master by this push:
new d7dc86f6 [YUNIKORN-2326] refactor `getAppsByState`,
`getRejectedAppsByState`, and `getCompletedAppsByState` (#804)
d7dc86f6 is described below
commit d7dc86f602aefaa439fe14548cf45b2806b02e90
Author: Priyansh Choudhary <[email protected]>
AuthorDate: Tue Feb 20 01:08:39 2024 +0800
[YUNIKORN-2326] refactor `getAppsByState`, `getRejectedAppsByState`, and
`getCompletedAppsByState` (#804)
Closes: #804
Signed-off-by: Chia-Ping Tsai <[email protected]>
---
pkg/scheduler/partition.go | 34 +++++++++++-----------------------
1 file changed, 11 insertions(+), 23 deletions(-)
diff --git a/pkg/scheduler/partition.go b/pkg/scheduler/partition.go
index 5300faf3..ab05972b 100644
--- a/pkg/scheduler/partition.go
+++ b/pkg/scheduler/partition.go
@@ -1070,13 +1070,11 @@ func (pc *PartitionContext) GetRejectedApplications()
[]*objects.Application {
return appList
}
-// getAppsByState returns a slice of applicationIDs for the current
applications filtered by state
-// Completed and Rejected applications are tracked in a separate map and will
never be included.
-func (pc *PartitionContext) getAppsByState(state string) []string {
+func (pc *PartitionContext) getAppsState(appMap
map[string]*objects.Application, state string) []string {
pc.RLock()
defer pc.RUnlock()
- var apps []string
- for appID, app := range pc.applications {
+ apps := []string{}
+ for appID, app := range appMap {
if app.CurrentState() == state {
apps = append(apps, appID)
}
@@ -1084,30 +1082,20 @@ func (pc *PartitionContext) getAppsByState(state
string) []string {
return apps
}
+// getAppsByState returns a slice of applicationIDs for the current
applications filtered by state
+// Completed and Rejected applications are tracked in a separate map and will
never be included.
+func (pc *PartitionContext) getAppsByState(state string) []string {
+ return pc.getAppsState(pc.applications, state)
+}
+
// getRejectedAppsByState returns a slice of applicationIDs for the rejected
applications filtered by state.
func (pc *PartitionContext) getRejectedAppsByState(state string) []string {
- pc.RLock()
- defer pc.RUnlock()
- var apps []string
- for appID, app := range pc.rejectedApplications {
- if app.CurrentState() == state {
- apps = append(apps, appID)
- }
- }
- return apps
+ return pc.getAppsState(pc.rejectedApplications, state)
}
// getCompletedAppsByState returns a slice of applicationIDs for the completed
applicationIDs filtered by state.
func (pc *PartitionContext) getCompletedAppsByState(state string) []string {
- pc.RLock()
- defer pc.RUnlock()
- var apps []string
- for appID, app := range pc.completedApplications {
- if app.CurrentState() == state {
- apps = append(apps, appID)
- }
- }
- return apps
+ return pc.getAppsState(pc.completedApplications, state)
}
// cleanupExpiredApps cleans up applications in the Expired state from the
three tracking maps
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]