@@ -2,22 +2,19 @@ package macpool
22
33import (
44 "fmt"
5+ "os"
56 "strings"
67
78 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"
9+ "github.com/redhat-developer/mapt/pkg/provider/aws"
1110 macMachine "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/machine"
1211 "github.com/redhat-developer/mapt/pkg/provider/aws/modules/serverless"
12+ "github.com/redhat-developer/mapt/pkg/provider/aws/services/ecs"
1313 "github.com/redhat-developer/mapt/pkg/provider/aws/services/tag"
14+ "github.com/redhat-developer/mapt/pkg/util/logging"
1415)
1516
1617func request (ctx * maptContext.ContextArgs , r * RequestMachineArgs ) error {
17- // If remote run through serverless
18- if maptContext .IsRemote () {
19- return requestRemote (ctx , r )
20- }
2118 // First get full info on the pool and the next machine for request
2219 p , err := getPool (r .PoolName , r .Architecture , r .OSVersion )
2320 if err != nil {
@@ -31,16 +28,15 @@ func request(ctx *maptContext.ContextArgs, r *RequestMachineArgs) error {
3128 // Create mapt Context
3229 ctx .ProjectName = * hi .ProjectName
3330 ctx .BackedURL = * hi .BackedURL
34- if err := maptContext .Init (ctx ); err != nil {
31+ if err := maptContext .Init (ctx , aws . Provider () ); err != nil {
3532 return err
3633 }
3734
3835 mr := macMachine.Request {
39- Prefix : * hi .Prefix ,
40- Version : * hi .OSVersion ,
41- Architecture : * hi .Arch ,
42- SetupGHActionsRunner : r .SetupGHActionsRunner ,
43- Timeout : r .Timeout ,
36+ Prefix : * hi .Prefix ,
37+ Version : * hi .OSVersion ,
38+ Architecture : * hi .Arch ,
39+ Timeout : r .Timeout ,
4440 }
4541
4642 // TODO here we would change based on the integration-mode requested
@@ -58,45 +54,47 @@ func request(ctx *maptContext.ContextArgs, r *RequestMachineArgs) error {
5854}
5955
6056func requestRemote (ctx * maptContext.ContextArgs , r * RequestMachineArgs ) error {
61- if err := maptContext .Init (ctx ); err != nil {
57+ if err := maptContext .Init (ctx , aws . Provider () ); err != nil {
6258 return err
6359 }
64- rARNs , err := data .GetResourcesMatchingTags (
65- data .ResourceTypeECS ,
66- requestTags (
67- r .PoolName ,
68- r .Architecture ,
69- r .OSVersion ))
60+ tARN , err := serverlessTaskARN (r .PoolName ,
61+ r .Architecture ,
62+ r .OSVersion ,
63+ requestOperation )
7064 if err != nil {
7165 return err
7266 }
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
79- return fmt .Errorf ("not implemented yet" )
67+ logging .Debugf ("Got ARN for task spec %s" , * tARN )
68+ // How to handle the region...coming from create operation we are always using "us-east-1"
69+ defaultRegion := "us-east-1"
70+ containerName := requestTaskContainerName (r .PoolName , r .Architecture , r .OSVersion )
71+ // just pass the params
72+ cmd := strings .Join (os .Args [1 :], " " )
73+ return ecs .RunTaskWithCommand (& defaultRegion , tARN ,
74+ & serverless .MaptServerlessClusterName , & containerName , & cmd )
8075}
8176
8277// Run serverless operation request
8378// check how we will call it from the request?
8479// may add tags and find or add arn to stack?
85- func (r * MacPoolRequestArgs ) createRequestTaskSpec () error {
80+ func requestTaskSpec (r * MacPoolRequestArgs ) error {
81+ name := requestTaskContainerName (
82+ r .PoolName ,
83+ r .Architecture ,
84+ r .OSVersion )
8685 return serverless .Create (
8786 & serverless.ServerlessArgs {
87+ ContainerName : name ,
8888 Command : requestCommand (
8989 r .PoolName ,
9090 r .Architecture ,
9191 r .OSVersion ),
92- LogGroupName : fmt .Sprintf ("%s-%s-%s-request" ,
93- r .PoolName ,
94- r .Architecture ,
95- r .OSVersion ),
96- Tags : requestTags (
92+ LogGroupName : name ,
93+ Tags : serverlessTags (
9794 r .PoolName ,
9895 r .Architecture ,
99- r .OSVersion )})
96+ r .OSVersion ,
97+ requestOperation )})
10098}
10199
102100func requestCommand (poolName , arch , osVersion string ) string {
@@ -105,15 +103,6 @@ func requestCommand(poolName, arch, osVersion string) string {
105103 return cmd
106104}
107105
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
106+ func requestTaskContainerName (poolName , arch , osVersion string ) string {
107+ return serverlessName (poolName , arch , osVersion , requestOperation )
119108}
0 commit comments