Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run ECS launch in goroutine, and add local cluster paymodel #61

Merged
merged 22 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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