@@ -87,7 +87,8 @@ type Application struct {
87
87
user security.UserGroup // owner of the application
88
88
allocatedResource * resources.Resource // total allocated resources
89
89
90
- usedResource * resources.UsedResource // keep track of resource usage of the application
90
+ usedResource * resources.TrackedResource // keep track of resource usage of the application
91
+ preemptedResource * resources.TrackedResource // keep track of preempted resource usage of the application
91
92
92
93
maxAllocatedResource * resources.Resource // max allocated resources
93
94
allocatedPlaceholder * resources.Resource // total allocated placeholder resources
@@ -117,15 +118,16 @@ type Application struct {
117
118
}
118
119
119
120
type ApplicationSummary struct {
120
- ApplicationID string
121
- SubmissionTime time.Time
122
- StartTime time.Time
123
- FinishTime time.Time
124
- User string
125
- Queue string
126
- State string
127
- RmID string
128
- ResourceUsage * resources.UsedResource
121
+ ApplicationID string
122
+ SubmissionTime time.Time
123
+ StartTime time.Time
124
+ FinishTime time.Time
125
+ User string
126
+ Queue string
127
+ State string
128
+ RmID string
129
+ ResourceUsage * resources.TrackedResource
130
+ PreemptedResource * resources.TrackedResource
129
131
}
130
132
131
133
func (as * ApplicationSummary ) DoLogging () {
@@ -138,24 +140,28 @@ func (as *ApplicationSummary) DoLogging() {
138
140
zap .String ("queue" , as .Queue ),
139
141
zap .String ("state" , as .State ),
140
142
zap .String ("rmID" , as .RmID ),
141
- zap .Any ("resourceUsage" , as .ResourceUsage .UsedResourceMap ))
143
+ zap .Any ("resourceUsage" , as .ResourceUsage .TrackedResourceMap ),
144
+ zap .Any ("preemptedResource" , as .PreemptedResource .TrackedResourceMap ),
145
+ )
142
146
}
143
147
144
148
func (sa * Application ) GetApplicationSummary (rmID string ) * ApplicationSummary {
145
- state := sa .stateMachine .Current ()
146
- ru := sa .usedResource .Clone ()
147
149
sa .RLock ()
148
150
defer sa .RUnlock ()
151
+ state := sa .stateMachine .Current ()
152
+ ru := sa .usedResource .Clone ()
153
+ pu := sa .preemptedResource .Clone ()
149
154
appSummary := & ApplicationSummary {
150
- ApplicationID : sa .ApplicationID ,
151
- SubmissionTime : sa .SubmissionTime ,
152
- StartTime : sa .startTime ,
153
- FinishTime : sa .finishedTime ,
154
- User : sa .user .User ,
155
- Queue : sa .queuePath ,
156
- State : state ,
157
- RmID : rmID ,
158
- ResourceUsage : ru ,
155
+ ApplicationID : sa .ApplicationID ,
156
+ SubmissionTime : sa .SubmissionTime ,
157
+ StartTime : sa .startTime ,
158
+ FinishTime : sa .finishedTime ,
159
+ User : sa .user .User ,
160
+ Queue : sa .queuePath ,
161
+ State : state ,
162
+ RmID : rmID ,
163
+ ResourceUsage : ru ,
164
+ PreemptedResource : pu ,
159
165
}
160
166
return appSummary
161
167
}
@@ -169,7 +175,8 @@ func NewApplication(siApp *si.AddApplicationRequest, ugi security.UserGroup, eve
169
175
tags : siApp .Tags ,
170
176
pending : resources .NewResource (),
171
177
allocatedResource : resources .NewResource (),
172
- usedResource : resources .NewUsedResource (),
178
+ usedResource : resources .NewTrackedResource (),
179
+ preemptedResource : resources .NewTrackedResource (),
173
180
maxAllocatedResource : resources .NewResource (),
174
181
allocatedPlaceholder : resources .NewResource (),
175
182
requests : make (map [string ]* AllocationAsk ),
@@ -1673,10 +1680,26 @@ func (sa *Application) decUserResourceUsage(resource *resources.Resource, remove
1673
1680
ugm .GetUserManager ().DecreaseTrackedResource (sa .queuePath , sa .ApplicationID , resource , sa .user , removeApp )
1674
1681
}
1675
1682
1683
+ // Track used and preempted resources
1684
+ func (sa * Application ) trackCompletedResource (info * Allocation ) {
1685
+ if info .IsPreempted () {
1686
+ sa .updatePreemptedResource (info )
1687
+ } else {
1688
+ sa .updateUsedResource (info )
1689
+ }
1690
+ }
1691
+
1676
1692
// When the resource allocated with this allocation is to be removed,
1677
1693
// have the usedResource to aggregate the resource used by this allocation
1678
1694
func (sa * Application ) updateUsedResource (info * Allocation ) {
1679
- sa .usedResource .AggregateUsedResource (info .GetInstanceType (),
1695
+ sa .usedResource .AggregateTrackedResource (info .GetInstanceType (),
1696
+ info .GetAllocatedResource (), info .GetBindTime ())
1697
+ }
1698
+
1699
+ // When the resource allocated with this allocation is to be preempted,
1700
+ // have the preemptedResource to aggregate the resource used by this allocation
1701
+ func (sa * Application ) updatePreemptedResource (info * Allocation ) {
1702
+ sa .preemptedResource .AggregateTrackedResource (info .GetInstanceType (),
1680
1703
info .GetAllocatedResource (), info .GetBindTime ())
1681
1704
}
1682
1705
@@ -1772,8 +1795,8 @@ func (sa *Application) removeAllocationInternal(uuid string, releaseType si.Term
1772
1795
} else {
1773
1796
sa .allocatedResource = resources .Sub (sa .allocatedResource , alloc .GetAllocatedResource ())
1774
1797
1775
- // Aggregate the resources used by this alloc to the application's user resource tracker
1776
- sa .updateUsedResource (alloc )
1798
+ // Aggregate the resources used by this alloc to the application's resource tracker
1799
+ sa .trackCompletedResource (alloc )
1777
1800
1778
1801
// When the resource trackers are zero we should not expect anything to come in later.
1779
1802
if sa .hasZeroAllocations () {
@@ -1825,7 +1848,7 @@ func (sa *Application) RemoveAllAllocations() []*Allocation {
1825
1848
for _ , alloc := range sa .allocations {
1826
1849
allocationsToRelease = append (allocationsToRelease , alloc )
1827
1850
// Aggregate the resources used by this alloc to the application's user resource tracker
1828
- sa .updateUsedResource (alloc )
1851
+ sa .trackCompletedResource (alloc )
1829
1852
sa .appEvents .sendRemoveAllocationEvent (alloc , si .TerminationType_STOPPED_BY_RM )
1830
1853
}
1831
1854
@@ -2008,8 +2031,15 @@ func (sa *Application) cleanupAsks() {
2008
2031
sa .sortedRequests = nil
2009
2032
}
2010
2033
2011
- func (sa * Application ) CleanupUsedResource () {
2034
+ func (sa * Application ) cleanupTrackedResource () {
2012
2035
sa .usedResource = nil
2036
+ sa .preemptedResource = nil
2037
+ }
2038
+
2039
+ func (sa * Application ) CleanupTrackedResource () {
2040
+ sa .Lock ()
2041
+ defer sa .Unlock ()
2042
+ sa .cleanupTrackedResource ()
2013
2043
}
2014
2044
2015
2045
func (sa * Application ) LogAppSummary (rmID string ) {
0 commit comments