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

Support savepoints on AWS S3 #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
54 changes: 54 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@
[[constraint]]
branch = "master"
name = "github.com/hashicorp/go-retryablehttp"

[[constraint]]
name = "github.com/aws/aws-sdk-go"
version = "1.15.87"
66 changes: 66 additions & 0 deletions cmd/cli/operations/retrieve_savepoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,78 @@ package operations

import (
"errors"
"net/url"
"os"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/spf13/afero"
)

var s3Schemes = map[string]bool{
"s3": true,
"s3a": true,
"s3p": true,
}

func (o RealOperator) retrieveLatestSavepoint(dir string) (string, error) {
u, err := url.Parse(dir)

if err == nil && s3Schemes[u.Scheme] {
return o.retrieveLatestSavepointS3(u)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be multiple jobs running in the same flink cluster. Do you assume the savepoint dir param to this function is unique to each job?

}

return o.retrieveLatestSavepointLocal(dir)
}

func (o RealOperator) retrieveLatestSavepointS3(dir *url.URL) (string, error) {
region := os.Getenv("AWS_REGION")
if region == "" {
return "", errors.New("AWS_REGION env var must be specified for S3 savepoint directories")
}

config := &aws.Config{
Region: aws.String(os.Getenv("AWS_REGION")),
Credentials: credentials.NewEnvCredentials(),
}

sess, err := session.NewSession()
if err != nil {
return "", errors.New("creating S3 session: " + err.Error())
}

client := s3.New(sess, config)

input := &s3.ListObjectsV2Input{
Bucket: aws.String(dir.Host),
}
if dir.Path != "" {
input.Prefix = aws.String(strings.TrimLeft(dir.Path, "/"))
}

var newestFile url.URL
var newestTime time.Time
err = client.ListObjectsV2Pages(input, func(output *s3.ListObjectsV2Output, lastPage bool) bool {
for _, object := range output.Contents {
if strings.HasSuffix(*object.Key, "_metadata") && object.LastModified.After(newestTime) {
newestTime = *object.LastModified
newestFile = url.URL{Scheme: dir.Scheme, Host: dir.Host, Path: *object.Key}
}
}
return true
})
if err != nil {
return "", errors.New("listing S3 objects: " + err.Error())
}

return newestFile.String(), nil
}

func (o RealOperator) retrieveLatestSavepointLocal(dir string) (string, error) {
if strings.HasSuffix(dir, "/") {
dir = strings.TrimSuffix(dir, "/")
}
Expand Down
14 changes: 14 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/.github/ISSUE_TEMPLATE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/.godoc_config

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading