Esempio n. 1
0
 def test_list_all_clusters(self, redshift_clusters):
     assert len(list_all_clusters(redshift_clusters)['clusters']) == \
         len(SAMPLE_CLUSTER_ITEMS)
Esempio n. 2
0
def clusters(request):
    """
    clusters handles GET and POST requests from the clusters endpoint

    **GET /v1/clusters/**

    Example: ``/v1/clusters/``

    *Example Response* ::

        [
            {
                'redshift_id': 'cluster-1',
                'port': 5439,
                'host': 'cluster-1.account.region.redshift.amazonaws.com',
                'db_schema': 'public',
                'groups': ['search_infra', 'biz']
            },
            {
                'redshift_id': 'cluster-1-user',
                'port': 5439,
                'host': 'cluster-1-user.account.region.redshift.amazonaws.com',
                'db_schema': 'public',
                'groups': ['search_infra', 'log_infra']
            },
            {
                'redshift_id': 'cluster-2',
                'port': 5439,
                'host': cluster-2.account.region.redshift.amazonaws.com,
                'db_schema': 'public',
                'groups': ['mobile', 'log_infra']
            },
        ]


    ============ ===========
    Status Code  Description
    ============ ===========
    **200**      Success
    **500**      unknown exception
    ============ ===========

    * **Encoding type:** *application/json*

    **POST /v1/clusters/**


    Example: ``/v1/clusters``

    **Query Parameters:**

    * **request.body** -- the json string of cluster details

    *Example request.body* ::

        "{
            'redshift_id': 'cluster-2',
            'port': 5439,
            'host': 'cluster-2.account.region.redshift.amazonaws.com'
        }"

    ============ ===========
    Status Code  Description
    ============ ===========
    **200**      Success
    **404**      invalid cluster parameters
    **500**      unknown exception
    ============ ===========

    * **Encoding type:** *application/json*
    """

    try:
        if request.method == "POST":
            return 200, post_cluster(
                TableConnection.get_connection('RedshiftClusters'),
                request.body)
        elif request.method == "GET":
            return 200, list_all_clusters(
                TableConnection.get_connection('RedshiftClusters'))
    except PrimaryKeyError as e:
        return 400, {'error': 'bad hash_key or missing required arguments'}
    except ValueError as e:
        if "ConditionalCheckFailedException" in repr(e):
            return 404, {
                'error': "ConditionalCheckFailed; possible duplicate cluster"
            }
        return 404, {'error': repr(e)}
    except Exception as unknown_exception:
        return 500, {'error': repr(unknown_exception)}
Esempio n. 3
0
 def test_list_all_clusters(self, redshift_clusters):
     assert len(list_all_clusters(redshift_clusters)['clusters']) == \
         len(SAMPLE_CLUSTER_ITEMS)