Skip to content

Dat 171 - Save indices to disk/auto upload to S3 - #122

Open
ProfOak wants to merge 2 commits into
developfrom
dat-171
Open

Dat 171 - Save indices to disk/auto upload to S3#122
ProfOak wants to merge 2 commits into
developfrom
dat-171

Conversation

@ProfOak

@ProfOak ProfOak commented Oct 26, 2016

Copy link
Copy Markdown
Contributor

This PR is kind of large (sorry!)

What's new?

  • New master file ./bin/gdc_datarelease.py that does most of the things
    • Saves archived indices to disk
      • New bash environment variable SAVE_DIR needs to be set before running
      • Only saves the last 5 of each type of archive (active indices/legacy indices)
    • Reads archives from disk (does an integrity check)
    • Uploads indices to Elasticsearch
    • Uploads archives to S3 (does an integrity check)

What's different?

  • Uploading to s3 no longer takes flags, but instead uses environment variables like the Elasticsearch code
    • S3_HOST
    • S3_BUCKET
    • S3_SECRET_KEY
    • S3_ACCESS_KEY
  • Removed dependency on Elasticdump
  • Both graph index builder scripts are combined into gdc_datarelease.py
    • For active don't include any flags
    • For legacy include a --legacy flag

I have not successfully tested these changes in an esbuild environment, but am opening up a pull request for discussion.

Comment thread bin/gdc_datarelease.py
from psqlgraph import PsqlGraphDriver


def shouldnt_delete(node):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you import this from esbuild/gdc_elasticsearch.py?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can move the shouldnt_delete method over there. I can also make it a single underscore "private" method in GDCDtataRelease since it is only used in GDCDataRelease().save_to_elasticsearch()

Comment thread bin/gdc_datarelease.py
if not args.test:
s3_md5 = g.save_to_s3(args, full_path_to_archive)
else:
from moto import mock_s3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Testing/mocking functionality probably shouldn't be tied into the program. This should be done inside tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's fair. I mostly did this to try and avoid changing the tests as much as possible. The only change I had to do was add a flag to the test_build_scripts.py

https://github.com/NCI-GDC/esbuild/blob/dat-171/tests/test_build_scripts.py#L17-L28

Comment thread bin/gdc_datarelease.py
if args.test:
os.environ['SAVE_DIR'] = 'temp_dir'

os.environ['PG_HOST'] = 'localhost'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stylistic comment, but typically we have functionality to pass vars as arguments, too. Something like:

 parser.add_argument('-h', '--host', type=str,
                                      help='host of the postgres server',
                                      default=os.environ.get('PG_HOST', 'localhost'))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I used environment variables to stay uniform in decisions made. That's basically the way all the code for elasticsearch was handled, so I decided to have everything as environment variables. If people want one way over the other I can always change this.

It should be noted that the tungsten file for this is nicer when you can separate the pulling of pillars into separate export lines instead of calling the large line at the bottom with a hand full of command line args.

Comment thread bin/gdc_datarelease.py

# compute md5sum of archive on disk
with open(full_path_to_archive, 'r') as f:
disk_archive_contents = f.read()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You have a large file here, so you could consider streaming it through instead.
See https://docs.python.org/2.7/library/hashlib.html

@ProfOak ProfOak Oct 26, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That was one of my concerns, too. I wasn't sure how large an archived file would be, but I wanted to see how running it in a dev environment would turn out. There's code that uses FileChunkIO so I'll have some reference if we decide to change this.

Comment thread bin/gdc_datarelease.py

log = get_logger("gdc_datarelease")

class GDCDataRelease(object):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this extend GDCElasticsearch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This class saves to disk, uploads to es, and s3. What would be the benefit of inheriting from GDCElasticsearch only?

@ProfOak

ProfOak commented Oct 26, 2016

Copy link
Copy Markdown
Contributor Author

Also I don't remember commiting that pdf, and I don't know that I made any changes to it. Does it get generated when you run the tests or something?

@millerjs

Copy link
Copy Markdown
Contributor

@ProfOak

ProfOak commented Oct 26, 2016

Copy link
Copy Markdown
Contributor Author

Well that's pretty spiffy. Am I safe to keep it since I didn't change the graph at all?

@ProfOak

ProfOak commented Oct 27, 2016

Copy link
Copy Markdown
Contributor Author

@NCI-GDC/ucdevs Please feel free to leave comments

added disk read/write operations
tests for gdc_diskIO.py

generate new archive name whenever call write_archive()

added case for if there's a time when I'll get an empty index

started moving gdces into its own export
fixed derived_files issue so that tests passed
fixed tests for gdc_diskIO.py
fully incorperated upload to s3 functionality

fixed every test to reflect changes
minor style tweaks
add extra comments

added integrity checks and moved ./bin/around

added md5sum check for integrity on s3 storage
removed graph builders -> combined into one script (gdc_datarelease.py)
added extra logging/comments
added new tests
fixed old tests

updated readme, delete unused file
Comment thread esbuild/export/es_upload.py Outdated
file_count = self.es.count(index=new_index, doc_type="file")["count"]
case_count = self.es.count(index=new_index, doc_type="case")["count"]
ann_count = self.es.count(index=new_index, doc_type="annotation")["count"]
file_count = self.es.count(index=new_index, doc_type="file")["count"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is is actually against pep8 recommendations

@ProfOak
ProfOak force-pushed the dat-171 branch 4 times, most recently from 5dba448 to cf0b4da Compare November 21, 2016 15:56
a lot more logging
general cleanup
updated requirements.txt to include latest and greatest
gdc code
@ProfOak ProfOak changed the title Dat 171 (WIP) Dat 171 - Save indices to disk/auto upload to S3 Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants