Exemplo n.º 1
0
def stop(request, session_id):
    """
    Inform the proxy to stop a session based on session_id.
    """
    if request.method != "POST":
        return HttpResponse(status=405)
    r = redis_wrapper.init_redis()
    response_key = str(ObjectId())
    redis_wrapper.publish_to_proxy(
        json.dumps({
            "operation": "stop_session",
            "param": session_id,
            "key": response_key,
        }))
    for i in range(0, 50):
        response = r.get(response_key)
        if response is not None:
            try:
                response = json.loads(response)
            except ValueError:
                return HttpResponse(status=500)
            if ('code' in response) and (response['code'] == 200):
                return JsonResponse({"proxyResponse": response}, status=200)
            else:
                return HttpResponse(status=500)
        else:
            time.sleep(.1)  # sleep 100ms
    return HttpResponse(status=408, content='The proxy did not respond')
Exemplo n.º 2
0
def stop(request):
    """
    Stop the proxy.
    """
    if request.method != "GET":
        return HttpResponse(status=405)

    from api.models import redis_wrapper
    r = redis_wrapper.init_redis()
    response_key = str(ObjectId())
    redis_wrapper.publish_to_proxy(json.dumps({
        "operation": "stop",
        "param": None,
        "key": response_key,
    }))
    for i in range(0, 50):
        response = r.get(response_key)
        if response is not None:
            try:
                response = json.loads(response)
            except ValueError:
                return HttpResponse(status=500)
            if ('code' in response) and (response['code'] == 200):
                return JsonResponse({"proxyResponse": response}, status=200)
            else:
                return HttpResponse(status=500)
        else:
            time.sleep(.1)  # sleep 100ms
    return HttpResponse(status=408)
Exemplo n.º 3
0
def stop(request, session_id):
    """
    Inform the proxy to stop a session based on session_id.
    """
    if request.method != "POST":
        return HttpResponse(status=405)
    r = redis_wrapper.init_redis()
    response_key = str(ObjectId())
    redis_wrapper.publish_to_proxy(json.dumps({
        "operation": "stop_session",
        "param": session_id,
        "key": response_key,
    }))
    for i in range(0, 50):
        response = r.get(response_key)
        if response is not None:
            try:
                response = json.loads(response)
            except ValueError:
                return HttpResponse(status=500)
            if ('code' in response) and (response['code'] == 200):
                return JsonResponse({"proxyResponse": response}, status=200)
            else:
                return HttpResponse(status=500)
        else:
            time.sleep(.1)  # sleep 100ms
    return HttpResponse(status=408, content='The proxy did not respond')
Exemplo n.º 4
0
def stop(request):
    """
    Stop the proxy.
    """
    if request.method != "GET":
        return HttpResponse(status=405)

    from api.models import redis_wrapper
    r = redis_wrapper.init_redis()
    response_key = str(ObjectId())
    redis_wrapper.publish_to_proxy(
        json.dumps({
            "operation": "stop",
            "param": None,
            "key": response_key,
        }))
    for i in range(0, 50):
        response = r.get(response_key)
        if response is not None:
            try:
                response = json.loads(response)
            except ValueError:
                return HttpResponse(status=500)
            if ('code' in response) and (response['code'] == 200):
                return JsonResponse({"proxyResponse": response}, status=200)
            else:
                return HttpResponse(status=500)
        else:
            time.sleep(.1)  # sleep 100ms
    return HttpResponse(status=408)
Exemplo n.º 5
0
def stop(request, recording_id):
    """
    Stop a recording, and wait N seconds for the proxy to acknowledge."
    """
    from api.models import redis_wrapper

    r = redis_wrapper.init_redis()
    response_key = str(ObjectId())
    redis_wrapper.publish_to_proxy(
        json.dumps({"operation": "stop_recording", "param": recording_id, "key": response_key})
    )
    logger.info("recording '%s' stopped by '%s'" % (recording_id, request.user["username"]))
    for i in range(0, 50):
        response = r.get(response_key)
        if response is not None:
            return JsonResponse({"proxyResponse": response})
        else:
            time.sleep(0.1)  # sleep 100ms
    return JsonResponse({"proxyResponse": None}, status=503)
Exemplo n.º 6
0
def start(request, session_id):
    """
    Inform the proxy to start a session based on session_id.
    """
    if request.method != "POST":
        return HttpResponse(status=405)
    r = redis_wrapper.init_redis()
    response_key = str(ObjectId())

    dbc = db_model.connect()
    try:
        session = dbc.session.find_one({"_id": ObjectId(session_id)})
    except InvalidId:
        return HttpResponseNotFound()
    if session is None:
        return HttpResponseNotFound()

    session['executions'] += 1
    dbc.session.save(session)

    redis_wrapper.publish_to_proxy(
        json.dumps({
            "operation": "start_session",
            "param": session_id,
            "key": response_key,
        }))
    for i in range(0, 50):
        response = r.get(response_key)
        if response is not None:
            try:
                response = json.loads(response)
            except ValueError:
                return HttpResponse(status=500)
            if ('code' in response) and (response['code'] == 200):
                return JsonResponse({"proxyResponse": response}, status=200)
            else:
                return HttpResponse(status=500)
        else:
            time.sleep(.1)  # sleep 100ms
    return HttpResponse(status=408, content='The proxy did not respond')
Exemplo n.º 7
0
def stop(request, recording_id):
    """
    Stop a recording, and wait N seconds for the proxy to acknowledge."
    """
    from api.models import redis_wrapper
    r = redis_wrapper.init_redis()
    response_key = str(ObjectId())
    redis_wrapper.publish_to_proxy(
        json.dumps({
            "operation": "stop_recording",
            "param": recording_id,
            "key": response_key,
        }))
    logger.info("recording '%s' stopped by '%s'" %
                (recording_id, request.user['username']))
    for i in range(0, 50):
        response = r.get(response_key)
        if response is not None:
            return JsonResponse({"proxyResponse": response})
        else:
            time.sleep(.1)  # sleep 100ms
    return JsonResponse({"proxyResponse": None}, status=503)
Exemplo n.º 8
0
def start(request, session_id):
    """
    Inform the proxy to start a session based on session_id.
    """
    if request.method != "POST":
        return HttpResponse(status=405)
    r = redis_wrapper.init_redis()
    response_key = str(ObjectId())

    dbc = db_model.connect()
    try:
        session = dbc.session.find_one({"_id": ObjectId(session_id)})
    except InvalidId:
        return HttpResponseNotFound()
    if session is None:
        return HttpResponseNotFound()

    session['executions'] += 1
    dbc.session.save(session)

    redis_wrapper.publish_to_proxy(json.dumps({
        "operation": "start_session",
        "param": session_id,
        "key": response_key,
    }))
    for i in range(0, 50):
        response = r.get(response_key)
        if response is not None:
            try:
                response = json.loads(response)
            except ValueError:
                return HttpResponse(status=500)
            if ('code' in response) and (response['code'] == 200):
                return JsonResponse({"proxyResponse": response}, status=200)
            else:
                return HttpResponse(status=500)
        else:
            time.sleep(.1)  # sleep 100ms
    return HttpResponse(status=408, content='The proxy did not respond')
Exemplo n.º 9
0
def status(request):
    """
    Return status of proxy.
    """
    if request.method != "GET":
        return HttpResponse(status=405)

    from api.models import redis_wrapper
    r = redis_wrapper.init_redis()
    response_key = str(ObjectId())
    redis_wrapper.publish_to_proxy(json.dumps({
        "operation": "status",
        "param": None,
        "key": response_key,
    }))
    for i in range(0, 50):
        response = r.get(response_key)
        if response is not None:
            return JsonResponse({"proxyStatus": response})
        else:
            time.sleep(.1)  # sleep 100ms
    return JsonResponse({"proxyStatus": None}, status=503)
Exemplo n.º 10
0
def status(request):
    """
    Return status of proxy.
    """
    if request.method != "GET":
        return HttpResponse(status=405)

    from api.models import redis_wrapper
    r = redis_wrapper.init_redis()
    response_key = str(ObjectId())
    redis_wrapper.publish_to_proxy(
        json.dumps({
            "operation": "status",
            "param": None,
            "key": response_key,
        }))
    for i in range(0, 50):
        response = r.get(response_key)
        if response is not None:
            return JsonResponse({"proxyStatus": response})
        else:
            time.sleep(.1)  # sleep 100ms
    return JsonResponse({"proxyStatus": None}, status=503)