@@ -2,22 +2,16 @@ package macpool
22
33import (
44 "fmt"
5- "strings"
65
76 maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
8- "github.com/redhat-developer/mapt/pkg/provider/aws/data"
9- macConstants "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/constants"
10- macHost "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/host"
7+ "github.com/redhat-developer/mapt/pkg/provider/aws"
118 macMachine "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/machine"
129 "github.com/redhat-developer/mapt/pkg/provider/aws/modules/serverless"
1310 "github.com/redhat-developer/mapt/pkg/provider/aws/services/tag"
11+ "github.com/redhat-developer/mapt/pkg/util/logging"
1412)
1513
1614func request (ctx * maptContext.ContextArgs , r * RequestMachineArgs ) error {
17- // If remote run through serverless
18- if maptContext .IsRemote () {
19- return requestRemote (ctx , r )
20- }
2115 // First get full info on the pool and the next machine for request
2216 p , err := getPool (r .PoolName , r .Architecture , r .OSVersion )
2317 if err != nil {
@@ -31,16 +25,15 @@ func request(ctx *maptContext.ContextArgs, r *RequestMachineArgs) error {
3125 // Create mapt Context
3226 ctx .ProjectName = * hi .ProjectName
3327 ctx .BackedURL = * hi .BackedURL
34- if err := maptContext .Init (ctx ); err != nil {
28+ if err := maptContext .Init (ctx , aws . Provider () ); err != nil {
3529 return err
3630 }
3731
3832 mr := macMachine.Request {
39- Prefix : * hi .Prefix ,
40- Version : * hi .OSVersion ,
41- Architecture : * hi .Arch ,
42- SetupGHActionsRunner : r .SetupGHActionsRunner ,
43- Timeout : r .Timeout ,
33+ Prefix : * hi .Prefix ,
34+ Version : * hi .OSVersion ,
35+ Architecture : * hi .Arch ,
36+ Timeout : r .Timeout ,
4437 }
4538
4639 // TODO here we would change based on the integration-mode requested
@@ -58,62 +51,46 @@ func request(ctx *maptContext.ContextArgs, r *RequestMachineArgs) error {
5851}
5952
6053func requestRemote (ctx * maptContext.ContextArgs , r * RequestMachineArgs ) error {
61- if err := maptContext .Init (ctx ); err != nil {
54+ if err := maptContext .Init (ctx , aws . Provider () ); err != nil {
6255 return err
6356 }
64- rARNs , err := data .GetResourcesMatchingTags (
65- data .ResourceTypeECS ,
66- requestTags (
67- r .PoolName ,
68- r .Architecture ,
69- r .OSVersion ))
57+ tARN , err := serverlessTaskARN (r .PoolName ,
58+ r .Architecture ,
59+ r .OSVersion ,
60+ requestOperation )
7061 if err != nil {
7162 return err
7263 }
73- if len (rARNs ) > 1 {
74- return fmt .Errorf (
75- "should be only one task spec matching tags. Found %s" ,
76- strings .Join (rARNs , "," ))
77- }
78- // We got the arn value for the task
64+ logging .Debugf ("Got ARN for task spec %s" , * tARN )
7965 return fmt .Errorf ("not implemented yet" )
8066}
8167
8268// Run serverless operation request
8369// check how we will call it from the request?
8470// may add tags and find or add arn to stack?
85- func (r * MacPoolRequestArgs ) createRequestTaskSpec () error {
71+ func requestTaskSpec (r * MacPoolRequestArgs ) error {
72+ name := serverlessName (
73+ r .PoolName ,
74+ r .Architecture ,
75+ r .OSVersion ,
76+ requestOperation )
8677 return serverless .Create (
8778 & serverless.ServerlessArgs {
79+ ContainerName : name ,
8880 Command : requestCommand (
8981 r .PoolName ,
9082 r .Architecture ,
9183 r .OSVersion ),
92- LogGroupName : fmt .Sprintf ("%s-%s-%s-request" ,
93- r .PoolName ,
94- r .Architecture ,
95- r .OSVersion ),
96- Tags : requestTags (
84+ LogGroupName : name ,
85+ Tags : serverlessTags (
9786 r .PoolName ,
9887 r .Architecture ,
99- r .OSVersion )})
88+ r .OSVersion ,
89+ requestOperation )})
10090}
10191
10292func requestCommand (poolName , arch , osVersion string ) string {
10393 cmd := fmt .Sprintf (requestCommandRegex ,
10494 poolName , arch , osVersion )
10595 return cmd
10696}
107-
108- // Return the map of tags wich should identify unique
109- // resquest operation spec for a pool
110- func requestTags (poolName , arch , osVersion string ) (m map [string ]string ) {
111- poolID := macHost.PoolID {
112- PoolName : poolName ,
113- Arch : arch ,
114- OSVersion : osVersion ,
115- }
116- m = poolID .AsTags ()
117- m [macConstants .TagKeyPoolOperationName ] = requestOperation
118- return
119- }
0 commit comments