Exemplo n.º 1
0
def transfer_start(request):
    """
    Starts a transfer to another AgoraD loading dock, parameters are url encoded

    :param token: API token for this loading dock
    :param table_names: A list of table names to transfer
    :param destination: The IP or host to transfer to
    :param session_id: ID of session from the MarketPlace
    :param database_name: Name of database to transfer
    """

    ## do a quick check to make sure it is actually a POST request
    if request.method != 'POST':
        return Response(status=status.HTTP_400_BAD_REQUEST)

    params = request.POST.dict()
    #### CALCULATE BLOCKS ####

    error = blocks.create_blocks(params['database_name'])
    if error:
        return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)

    session = Session.objects.create(
        session_id=params['session_id']
    )

    #TODO verify token
    #TODO request table names

    #### SEND THE SCHEMA ####

    url = params['destination'] + '/highway/intercept/schema/'
    data = schema2json(params['database_name'], params['table_names'])
    response = urllib2.urlopen(url, data)
    if response.get_code() != status.HTTP_200_OK:
        return Response(status=response.get_code())

    #### START BLOCK TRANSFER ####

    block_count = Block.objects.all().count()
    block_url = params['destination'] + '/highway/intercept/block/'

    for x in range(block_count):
        block = Block.objects.all()[x]
        session.current_block = block
        session.save()

        data = dict()
        data['block_id'] = block.pk
        data['session_id'] = params['session_id']
        data['block_data'] = json.loads(blocks.json_from_block(block))

        #TODO fill out data param with JSON
        response = urllib2.urlopen(block_url, json.dumps(data))
        if response.get_code() != status.HTTP_200_OK:
            return Response(status=response.get_code())
Exemplo n.º 2
0
def transfer_schema(request):
    """
    Use this to request only a schema. Must have an active session id.

    :param session_id: ID of session from marketplace
    :param database_name: Name of database to get schema from
    :param table_names: An array of table names to pull schema for
    """
    #TODO lookup session

    params = request.QUERY_PARAMS.dict()

    try:
        data = schema2json(params['database_name'], params['table_names'])
        return Response(data=data, status=status.HTTP_200_OK)
    except:
        return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)