@@ -10,12 +10,10 @@ import (
1010 "github.com/redhat-developer/mapt/pkg/provider/aws"
1111 "github.com/redhat-developer/mapt/pkg/provider/aws/modules/iam"
1212 "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac"
13- macConstants "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/constants"
1413 macHost "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/host"
1514 macMachine "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/machine"
1615 macUtil "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/util"
1716 "github.com/redhat-developer/mapt/pkg/provider/aws/modules/serverless"
18- "github.com/redhat-developer/mapt/pkg/provider/aws/services/tag"
1917 "github.com/redhat-developer/mapt/pkg/util"
2018 "github.com/redhat-developer/mapt/pkg/util/logging"
2119)
@@ -58,88 +56,15 @@ func Destroy(ctx *maptContext.ContextArgs) error {
5856// machine non locked which had been running more than 24h.
5957// It should check if capacity allows to remove the machine
6058func HouseKeeper (ctx * maptContext.ContextArgs , r * MacPoolRequestArgs ) error {
61- // Create mapt Context, this is a special case where we need change the context
62- // based on the operation
63- if err := maptContext .Init (ctx , aws .Provider ()); err != nil {
64- return err
65- }
66-
67- // Get full info on the pool
68- p , err := getPool (r .PoolName , r .Architecture , r .OSVersion )
69- if err != nil {
70- return err
71- }
72- // Pool under expected offered capacity
73- if p .currentOfferedCapacity () < r .OfferedCapacity {
74- if p .currentPoolSize () < r .MaxSize {
75- logging .Debug ("house keeper will try to add machines as offered capacity is lower than expected" )
76- maptContext .SetProjectName (r .PoolName )
77- return r .addCapacity (p )
78- }
79- // if number of machines in the pool + to max machines
80- // we do nothing
81- logging .Debug ("house keeper will not do any action as pool size is currently at max size" )
82- return nil
83- }
84- // Pool over expected offered capacity need to destroy machines
85- if p .currentOfferedCapacity () > r .OfferedCapacity {
86- if len (p .destroyableMachines ) > 0 {
87- logging .Debug ("house keeper will try to destroy machines as offered capacity is higher than expected" )
88- // Need to check if any offered can be destroy
89- return r .destroyCapacity (p )
90- }
91- }
92- logging .Debug ("house keeper will not do any action as offered capacity is met by the pool" )
93- // Otherwise nonLockedMachines meet Capacity so we do nothing
94- return nil
59+ return houseKeeper (ctx , r )
9560}
9661
9762func Request (ctx * maptContext.ContextArgs , r * RequestMachineArgs ) error {
9863 // If remote run through serverless
9964 if r .Remote {
10065 return requestRemote (ctx , r )
10166 }
102- // First get full info on the pool and the next machine for request
103- p , err := getPool (r .PoolName , r .Architecture , r .OSVersion )
104- if err != nil {
105- return err
106- }
107- hi , err := p .getNextMachineForRequest ()
108- if err != nil {
109- return err
110- }
111-
112- // Create mapt Context
113- ctx .ProjectName = * hi .ProjectName
114- ctx .BackedURL = * hi .BackedURL
115- if err := maptContext .Init (ctx , aws .Provider ()); err != nil {
116- return err
117- }
118-
119- mr := macMachine.Request {
120- Prefix : * hi .Prefix ,
121- Version : * hi .OSVersion ,
122- Architecture : * hi .Arch ,
123- Timeout : r .Timeout ,
124- }
125-
126- // TODO here we would change based on the integration-mode requested
127- // possible values remote-shh, gh-selfhosted-runner, cirrus-persistent-worker
128- err = mr .ManageRequest (hi )
129- if err != nil {
130- return err
131- }
132-
133- // We update the runID on the dedicated host
134- return tag .Update (maptContext .TagKeyRunID ,
135- maptContext .RunID (),
136- * hi .Region ,
137- * hi .Host .HostId )
138- }
139-
140- func requestRemote (ctx * maptContext.ContextArgs , r * RequestMachineArgs ) error {
141-
142- return fmt .Errorf ("not implemented yet" )
67+ return request (ctx , r )
14368}
14469
14570func Release (ctx * maptContext.ContextArgs , hostID string ) error {
@@ -164,64 +89,6 @@ func (r *MacPoolRequestArgs) addMachinesToPool(n int) error {
16489 return nil
16590}
16691
167- // Run serverless operation for house keeping
168- func (r * MacPoolRequestArgs ) scheduleHouseKeeper () error {
169- return serverless .Create (
170- & serverless.ServerlessArgs {
171- Command : houseKeepingCommand (
172- r .PoolName ,
173- r .Architecture ,
174- r .OSVersion ,
175- r .OfferedCapacity ,
176- r .MaxSize ,
177- r .FixedLocation ),
178- ScheduleType : & serverless .Repeat ,
179- Schedulexpression : houseKeepingInterval ,
180- LogGroupName : fmt .Sprintf ("%s-%s-%s" ,
181- r .PoolName ,
182- r .Architecture ,
183- r .OSVersion )})
184- }
185-
186- // Run serverless operation request
187- // check how we will call it from the request?
188- // may add tags and find or add arn to stack?
189- func (r * MacPoolRequestArgs ) createRequestTaskSpec () error {
190- return serverless .Create (
191- & serverless.ServerlessArgs {
192- Command : requestCommand (
193- r .PoolName ,
194- r .Architecture ,
195- r .OSVersion ),
196- LogGroupName : fmt .Sprintf ("%s-%s-%s-request" ,
197- r .PoolName ,
198- r .Architecture ,
199- r .OSVersion ),
200- Tags : map [string ]string {
201- macConstants .TagKeyArch : r .Architecture ,
202- macConstants .TagKeyOSVersion : r .OSVersion ,
203- macConstants .TagKeyPoolName : r .PoolName ,
204- }})
205- }
206-
207- func houseKeepingCommand (poolName , arch , osVersion string ,
208- offeredCapacity , maxSize int ,
209- fixedLocation bool ) string {
210- cmd := fmt .Sprintf (houseKeepingCommandRegex ,
211- poolName , arch , osVersion ,
212- offeredCapacity , maxSize )
213- if fixedLocation {
214- cmd += houseKeepingFixedLocationParam
215- }
216- return cmd
217- }
218-
219- func requestCommand (poolName , arch , osVersion string ) string {
220- cmd := fmt .Sprintf (requestCommandRegex ,
221- poolName , arch , osVersion )
222- return cmd
223- }
224-
22592// If we need less or equal than the max allowed on the pool we create all of them
22693// if need are more than allowed we can create just the allowed
22794func (r * MacPoolRequestArgs ) addCapacity (p * pool ) error {
0 commit comments