예제 #1
0
def handlerouteRoot():
    """Root route"""
    setup_adaguc()
    response = Response(
        response="Welcome to adaguc-server! Please go to /wms or /autowms.",
        mimetype='text/plain',
        status=200,
    )
    return response
예제 #2
0
def handleRouteHealthCheck():
    """handleRouteHealthCheck"""
    setup_adaguc(False)
    response = Response(
        response="OK",
        mimetype='text/plain',
        status=200,
    )
    return response
예제 #3
0
def handleWMS(text):
    logger.info(text)
    adagucInstance = setup_adaguc()
    url = request.query_string
    logger.info(request.query_string)
    adagucenv = {}
    """ Set required environment variables """
    baseUrl = request.base_url.replace(request.path, "")
    adagucenv['ADAGUC_ONLINERESOURCE'] = os.getenv('EXTERNALADDRESS',
                                                   baseUrl) + "/adagucopendap?"
    adagucenv['ADAGUC_DB'] = os.getenv(
        'ADAGUC_DB',
        "user=adaguc password=adaguc host=localhost dbname=adaguc")

    logger.info('Setting request_uri to %s' % request.base_url)
    adagucenv['REQUEST_URI'] = request.path
    adagucenv['SCRIPT_NAME'] = ""

    status, data, headers = adagucInstance.runADAGUCServer(
        url, env=adagucenv, showLogOnError=False)
    """ Obtain logfile """
    logfile = adagucInstance.getLogFile()
    adagucInstance.removeLogFile()

    logger.info(logfile)

    response = Response(response=data.getvalue(), status=200)

    # Append the headers from adaguc-server to the headers from flask.
    for header in headers:
        key = header.split(":")[0]
        value = header.split(":")[1]
        response.headers[key] = value
    return response
예제 #4
0
def handleWMS():
    start = time.perf_counter()
    adagucInstance = setup_adaguc()
    url = request.query_string

    logger.info(request.query_string)
    stage1 = time.perf_counter()

    adagucenv = {}
    """ Set required environment variables """
    baseUrl = request.base_url.replace(request.path, "")
    adagucenv['ADAGUC_ONLINERESOURCE'] = os.getenv('EXTERNALADDRESS',
                                                   baseUrl) + "/adaguc-server?"
    adagucenv['ADAGUC_DB'] = os.getenv(
        'ADAGUC_DB',
        "user=adaguc password=adaguc host=localhost dbname=adaguc")
    """ Run adaguc-server """
    status, data, headers = adagucInstance.runADAGUCServer(
        url, env=adagucenv, showLogOnError=False)
    """ Obtain logfile """
    logfile = adagucInstance.getLogFile()
    adagucInstance.removeLogFile()

    stage2 = time.perf_counter()
    logger.info("[PERF] Adaguc executation took: %f" % (stage2 - stage1))

    if len(logfile) > 0:
        logger.info(logfile)

    responseCode = 200
    if status != 0:
        logger.info("Adaguc status code was %d" % status)
        responseCode = 500
    response = Response(response=data.getvalue(), status=responseCode)

    stage3 = time.perf_counter()

    # Append the headers from adaguc-server to the headers from flask.
    for header in headers:
        key = header.split(":")[0]
        value = header.split(":")[1]
        response.headers[key] = value
    stage4 = time.perf_counter()

    return response
예제 #5
0
def handleAutoWMS():
    adagucInstance = setup_adaguc()
    logger.info(request.query_string)
    adagucDataSetDir = adagucInstance.ADAGUC_DATASET_DIR
    adagucDataDir = adagucInstance.ADAGUC_DATA_DIR
    adagucAutoWMSDir = adagucInstance.ADAGUC_AUTOWMS_DIR
    baseUrl = request.base_url.replace(request.path, "")
    adagucOnlineResource = os.getenv('EXTERNALADDRESS', baseUrl)
    print('Online resource = [%s]' % adagucOnlineResource)
    urlParamRequest = request.args.get('request')
    urlParamPath = request.args.get('path')
    if urlParamRequest is None or urlParamPath is None:
        response = Response(
            response="Mandatory parameters [request] and or [path] are missing",
            status=400,
        )
        return response
    if urlParamRequest != "getfiles":
        response = Response(
            response="Only request=getfiles is supported",
            status=400,
        )
        return response
    print(urlParamPath)

    if urlParamPath == "":
        return handleBaseRoute()

    if urlParamPath.startswith("/adaguc::datasets"):
        return handleDatasetsRoute(adagucDataSetDir, adagucOnlineResource)

    if urlParamPath.startswith("/adaguc::data"):
        return handleDataRoute(adagucDataDir, urlParamPath, adagucOnlineResource)

    if urlParamPath.startswith("/adaguc::autowms"):
        return handleAutoWMSDIRRoute(adagucAutoWMSDir, urlParamPath, adagucOnlineResource)

    response = Response(
        response="Path parameter not understood..",
        mimetype='application/json',
        status=400,
    )
    return response
예제 #6
0
파일: main.py 프로젝트: KNMI/adaguc-server
def testadaguc():
    """Test adaguc is setup correctly"""
    logger.info("Checking adaguc-server.")
    adaguc_instance = setup_adaguc()
    url = "SERVICE=WMS&REQUEST=GETCAPABILITIES"
    adagucenv = {}

    #  Set required environment variables
    baseurl = "---"
    adagucenv['ADAGUC_ONLINERESOURCE'] = os.getenv(
        'EXTERNALADDRESS', baseurl) + "/adaguc-server?"
    adagucenv['ADAGUC_DB'] = os.getenv(
        'ADAGUC_DB', "user=adaguc password=adaguc host=localhost dbname=adaguc")

    # Run adaguc-server
    # pylint: disable=unused-variable
    status, data, headers = adaguc_instance.runADAGUCServer(
        url, env=adagucenv,  showLogOnError=False)
    assert status == 0
    assert headers == ['Content-Type:text/xml']
    logger.info("adaguc-server seems [OK]")