Skip to content

Commit

Permalink
Refactor getting the url to be in a helper method instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry Jiang committed Apr 7, 2015
1 parent bd97789 commit 208a581
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
10 changes: 2 additions & 8 deletions dataduct/etl/etl_actions.py
Expand Up @@ -7,20 +7,14 @@
from ..pipeline import MysqlNode
from ..pipeline import RedshiftNode
from ..pipeline import S3Node
from ..config import Config
from ..utils.exceptions import ETLInputError
from ..utils.hook import hook
from ..utils.helpers import make_pipeline_url

import logging
logger = logging.getLogger(__name__)


config = Config()
REGION = config.etl.get('REGION', None)
URL_TEMPLATE = 'https://console.aws.amazon.com/datapipeline/?%s#ExecutionDetailsPlace:pipelineId={ID}&show=latest' # noqa
URL_TEMPLATE %= 'region=%s' % REGION if REGION is not None else ''


def read_pipeline_definition(file_path):
"""Function reads the yaml pipeline definitions.
Expand Down Expand Up @@ -87,7 +81,7 @@ def activate_pipeline(etl):
etl.activate()
logger.info('Activated pipeline. Id: %s', etl.pipeline.id)
logger.info('Monitor pipeline here: %s',
URL_TEMPLATE.format(ID=etl.pipeline.id))
make_pipeline_url(etl.pipeline.id))


def visualize_pipeline(etl, activities_only=False, filename=None):
Expand Down
21 changes: 21 additions & 0 deletions dataduct/utils/helpers.py
Expand Up @@ -13,6 +13,8 @@
CUSTOM_STEPS_PATH = 'CUSTOM_STEPS_PATH'
HOOKS_BASE_PATH = 'HOOKS_BASE_PATH'

URL_TEMPLATE = 'https://console.aws.amazon.com/datapipeline/?{region}#ExecutionDetailsPlace:pipelineId={ID}&show=latest' # noqa


def atmost_one(*args):
"""Asserts one of the arguments is not None
Expand Down Expand Up @@ -171,3 +173,22 @@ def stringify_credentials(access_key, secret_key, token=None):
if token:
creds += ';token=%s' % token
return creds


def make_pipeline_url(pipeline_id):
"""Creates the DataPipeline url for a particular pipeline
Args:
pipeline_id(str): The id of the pipeline for which to create the url
region(str/None): The Amazon region.
Returns:
A string that links to the pipeline in Amazon DataPipeline's console.
"""
config = Config()
region = config.etl.get('REGION', None)
region_str = 'region=%s' % region if region is not None else ''
return URL_TEMPLATE.format(
region=region_str,
ID=pipeline_id,
)
25 changes: 25 additions & 0 deletions dataduct/utils/tests/test_helpers.py
Expand Up @@ -5,6 +5,7 @@
from unittest import TestCase
from ..helpers import stringify_credentials
from ..helpers import parse_path
from ..helpers import make_pipeline_url
from nose.tools import eq_


Expand Down Expand Up @@ -68,3 +69,27 @@ def test_parse_path_expands_user():
parse_path('test/path', 'TEST_PATH'),
os.path.expanduser('~/transform/test/path'),
)

@staticmethod
def test_make_pipeline_url_no_region_correct():
"""Tests that make_pipeline_url makes a correct url without a region
"""
from dataduct.config import Config
config = Config()
del config.etl['REGION']
eq_(
make_pipeline_url('123'),
'https://console.aws.amazon.com/datapipeline/?#ExecutionDetailsPlace:pipelineId=123&show=latest' # noqa
)

@staticmethod
def test_make_pipeline_url_has_region_correct():
"""Tests that make_pipeline_url makes a correct url with a region
"""
from dataduct.config import Config
config = Config()
config.etl['REGION'] = 'test'
eq_(
make_pipeline_url('123'),
'https://console.aws.amazon.com/datapipeline/?region=test#ExecutionDetailsPlace:pipelineId=123&show=latest' # noqa
)

0 comments on commit 208a581

Please sign in to comment.