Skip to content

Commit

Permalink
Merge pull request #10 from uc-cdis/fix/api
Browse files Browse the repository at this point in the history
Fix/api
  • Loading branch information
giangbui authored Feb 18, 2019
2 parents 1add8d9 + d8b08d6 commit 1c046d7
Show file tree
Hide file tree
Showing 47 changed files with 1,857 additions and 2,943 deletions.
15 changes: 7 additions & 8 deletions Gopkg.lock

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

6 changes: 5 additions & 1 deletion handlers/hash_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"sync"
)

const ChunkSize = 1024 * 1024 * 96
const ChunkSize = 1024 * 1024 * 64

type HashInfo struct {
Crc32c string
Expand Down Expand Up @@ -61,17 +61,21 @@ func CalculateBasicHashes(client *AwsClient, bucket string, key string) (*HashIn
log.Printf("Fail to get object size of %s. Detail %s\n\n", key, err)
return nil, -1, err
}
log.Printf("Size %d", *objectSize)

start := int64(0)
step := int64(ChunkSize)
for {
chunkRange := fmt.Sprintf("bytes: %d-%d", start, minOf(start+step, *objectSize-1))

buff, err := GetChunkDataFromS3(client, bucket, key, chunkRange)
if err != nil {
log.Printf("Can not stream chunk data of %s. Detail %s\n\n", key, err)
return nil, -1, err
}

hashCollection, err = UpdateBasicHashes(hashCollection, buff)

if err != nil {
log.Printf("Can not compute hashes. Detail %s\n\n", err)
}
Expand Down
29 changes: 23 additions & 6 deletions handlers/s3client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package handlers

import (
"fmt"
"io/ioutil"
"os"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"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/aws/aws-sdk-go/service/s3/s3manager"
)

// AWS sesssion wrapper
Expand Down Expand Up @@ -37,18 +37,35 @@ func CreateNewAwsClient() (*AwsClient, error) {

// GetChunkDataFromS3 downloads chunk data from s3
func GetChunkDataFromS3(client *AwsClient, bucket string, key string, byteRange string) ([]byte, error) {
buff := &aws.WriteAtBuffer{}
s3dl := s3manager.NewDownloader(client.session)
_, err := s3dl.Download(buff, &s3.GetObjectInput{

svc := s3.New(client.session)
input := &s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
Range: aws.String(byteRange),
})
}

result, err := svc.GetObject(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case s3.ErrCodeNoSuchKey:
fmt.Println(s3.ErrCodeNoSuchKey, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return nil, err
}
return buff.Bytes(), nil
body, err := ioutil.ReadAll(result.Body)
if err != nil {
fmt.Println(err.Error())
}
return body, nil

}

Expand Down
25 changes: 12 additions & 13 deletions vendor/github.com/aws/aws-sdk-go/aws/awsutil/string_value.go

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

2 changes: 1 addition & 1 deletion vendor/github.com/aws/aws-sdk-go/aws/client/client.go

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.

9 changes: 0 additions & 9 deletions vendor/github.com/aws/aws-sdk-go/aws/context_1_7.go

This file was deleted.

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

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.

20 changes: 20 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/aws/context_background_1_7.go

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

24 changes: 24 additions & 0 deletions vendor/github.com/aws/aws-sdk-go/aws/context_sleep.go

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

4 changes: 2 additions & 2 deletions vendor/github.com/aws/aws-sdk-go/aws/corehandlers/handlers.go

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.

Loading

0 comments on commit 1c046d7

Please sign in to comment.