Skip to content

Commit

Permalink
Run ECS launch in goroutine, and add local cluster paymodel (#61)
Browse files Browse the repository at this point in the history
* Run ECS launch in goroutine, to prevent timeout issues

* Fix context for launchEcsWorkspace

* Fix status

* Fix transitgateway setup

* Fix routing

* Change order of execution for launch

* Prevent launch if paymodel is not active

* Add 500 error on launch instead of 403

* Log when launch is forbidden

* Add more failure logging

* Add in enhancement for paymodels check.

* Remove comment

* return 404 if no paymodel is found

* Remove error returns from ecsLaunchWorkspace

* Remove error returns from ecsLaunchWorkspace

* Update hatchery/hatchery.go

Co-authored-by: Sai Shanmukha Narumanchi <nss10@outlook.com>

* Making needed changes

* Updating `status` endpoint to work with local launch

* Reverting local changes

* Updating comments

* Fix nil pointer reference

---------

Co-authored-by: Sai Shanmukha Narumanchi <nss10@outlook.com>
  • Loading branch information
jawadqur and nss10 authored Apr 13, 2023
1 parent a0889b6 commit 9bcd8d1
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 136 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@

# End of https://www.toptal.com/developers/gitignore/api/go
.dccache
hatchery_qabrh.json
19 changes: 17 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"exclude": {
"files": "go.sum",
"files": "go.sum|^.secrets.baseline$",
"lines": null
},
"generated_at": "2021-10-13T19:11:36Z",
"generated_at": "2023-04-07T16:22:23Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -61,6 +61,7 @@
"doc/explanation/dockstore.md": [
{
"hashed_secret": "9b5925ea817163740dfb287a9894e8ab3aba2c18",
"is_secret": false,
"is_verified": false,
"line_number": 91,
"type": "Secret Keyword"
Expand All @@ -69,6 +70,7 @@
"doc/howto/configuration.md": [
{
"hashed_secret": "e94cc2a86b04ad4ddc98fcbf91ed236437939d47",
"is_secret": false,
"is_verified": false,
"line_number": 30,
"type": "Secret Keyword"
Expand All @@ -77,6 +79,7 @@
"doc/howto/jupyterNotebook.md": [
{
"hashed_secret": "e94cc2a86b04ad4ddc98fcbf91ed236437939d47",
"is_secret": false,
"is_verified": false,
"line_number": 35,
"type": "Secret Keyword"
Expand All @@ -85,14 +88,25 @@
"doc/howto/noVNCFirefox.md": [
{
"hashed_secret": "0da0e0005ca04acb407af2681d0bede6d9406039",
"is_secret": false,
"is_verified": false,
"line_number": 51,
"type": "Secret Keyword"
}
],
"hatchery/ecs.go": [
{
"hashed_secret": "96e77458817d8486fab4c56c8d4c51b83f85c79d",
"is_secret": false,
"is_verified": false,
"line_number": 391,
"type": "Secret Keyword"
}
],
"testData/dockstore/docker-compose.yml": [
{
"hashed_secret": "770fc9a9befcecb410cd10a29eec487beb70009c",
"is_secret": false,
"is_verified": false,
"line_number": 81,
"type": "Secret Keyword"
Expand All @@ -101,6 +115,7 @@
"testData/testConfig.json": [
{
"hashed_secret": "0da0e0005ca04acb407af2681d0bede6d9406039",
"is_secret": false,
"is_verified": false,
"line_number": 55,
"type": "Secret Keyword"
Expand Down
61 changes: 59 additions & 2 deletions hatchery/alb.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,47 @@ func (creds *CREDS) CreateLoadBalancer(userName string) (*elbv2.CreateLoadBalanc
return loadBalancer, targetGroup.TargetGroups[0].TargetGroupArn, listener, nil
}

func (creds *CREDS) terminateLoadBalancerTargetGroup(userName string) error {
svc := elbv2.New(session.Must(session.NewSession(&aws.Config{
Credentials: creds.creds,
Region: aws.String("us-east-1"),
})))
tgName := truncateString(strings.ReplaceAll(os.Getenv("GEN3_ENDPOINT"), ".", "-")+userToResourceName(userName, "service")+"tg", 32)
Config.Logger.Printf("Deleting target group: %s", tgName)
tgArn, err := svc.DescribeTargetGroups(&elbv2.DescribeTargetGroupsInput{
Names: []*string{aws.String(tgName)},
})
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case elbv2.ErrCodeTargetGroupNotFoundException:
// Target group not found, nothing to do
return nil
}
} else {
Config.Logger.Printf("Error describing target group: %s", err.Error())
return err
}
}
input := &elbv2.DeleteTargetGroupInput{
TargetGroupArn: tgArn.TargetGroups[0].TargetGroupArn,
}

_, err = svc.DeleteTargetGroup(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case elbv2.ErrCodeResourceInUseException:
// Target group in use, nothing to do
return nil
}
} else {
Config.Logger.Printf("Error deleting target group: %s", err.Error())
}
}
return nil
}

func (creds *CREDS) terminateLoadBalancer(userName string) error {
svc := elbv2.New(session.Must(session.NewSession(&aws.Config{
Credentials: creds.creds,
Expand All @@ -229,16 +270,32 @@ func (creds *CREDS) terminateLoadBalancer(userName string) error {
}
result, err := svc.DescribeLoadBalancers(getInput)
if err != nil {
return err
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case elbv2.ErrCodeLoadBalancerNotFoundException:
// Load balancer doesn't exist, we are happy! :)
return nil
}
} else {
return err
}
}
if len(result.LoadBalancers) == 1 {
delInput := &elbv2.DeleteLoadBalancerInput{
LoadBalancerArn: result.LoadBalancers[0].LoadBalancerArn,
}
_, err := svc.DeleteLoadBalancer(delInput)
if err != nil {
return err
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case elbv2.ErrCodeLoadBalancerNotFoundException:
fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error())
}
} else {
return err
}
}
}

return nil
}
2 changes: 2 additions & 0 deletions hatchery/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type PayModel struct {
Name string `json:"workspace_type"`
User string `json:"user_id"`
AWSAccountId string `json:"account_id"`
Status string `json:"request_status"`
Local bool `json:"local"`
Region string `json:"region"`
Ecs bool `json:"ecs"`
Subnet int `json:"subnet"`
Expand Down
Loading

0 comments on commit 9bcd8d1

Please sign in to comment.