Ejemplo n.º 1
0
def check_solr_schema_version(schema_file=None):
    '''
        Checks if the schema version of the SOLR server is compatible
        with this CKAN version.

        The schema will be retrieved from the SOLR server, using the
        offset defined in SOLR_SCHEMA_FILE_OFFSET
        ('/admin/file/?file=schema.xml'). The schema_file parameter
        allows to override this pointing to different schema file, but
        it should only be used for testing purposes.

        If the CKAN instance is configured to not use SOLR or the SOLR
        server is not available, the function will return False, as the
        version check does not apply. If the SOLR server is available,
        a SearchError exception will be thrown if the version could not
        be extracted or it is not included in the supported versions list.

        :schema_file: Absolute path to an alternative schema file. Should
                      be only used for testing purposes (Default is None)
    '''

    if not is_available():
        # Something is wrong with the SOLR server
        log.warn('Problems were found while connecting to the SOLR server')
        return False

    # Try to get the schema XML file to extract the version
    if not schema_file:
        solr_url, solr_user, solr_password = SolrSettings.get()

        http_auth = None
        if solr_user is not None and solr_password is not None:
            http_auth = solr_user + ':' + solr_password
            http_auth = 'Basic ' + http_auth.encode('base64').strip()

        url = solr_url.strip('/') + SOLR_SCHEMA_FILE_OFFSET

        req = urllib2.Request(url=url)
        if http_auth:
            req.add_header('Authorization', http_auth)

        res = urllib2.urlopen(req)
    else:
        url = 'file://%s' % schema_file
        res = urllib2.urlopen(url)

    tree = xml.dom.minidom.parseString(res.read())

    version = tree.documentElement.getAttribute('version')
    if not len(version):
        raise SearchError('Could not extract version info from the SOLR'
                          ' schema, using file: \n%s' % url)

    if not version in SUPPORTED_SCHEMA_VERSIONS:
        raise SearchError('SOLR schema version not supported: %s. Supported'
                          ' versions are [%s]' %
                          (version, ', '.join(SUPPORTED_SCHEMA_VERSIONS)))
    return True
Ejemplo n.º 2
0
def check_solr_schema_version(schema_file=None):
    '''
        Checks if the schema version of the SOLR server is compatible
        with this CKAN version.

        The schema will be retrieved from the SOLR server, using the
        offset defined in SOLR_SCHEMA_FILE_OFFSET
        ('/admin/file/?file=schema.xml'). The schema_file parameter
        allows to override this pointing to different schema file, but
        it should only be used for testing purposes.

        If the CKAN instance is configured to not use SOLR or the SOLR
        server is not available, the function will return False, as the
        version check does not apply. If the SOLR server is available,
        a SearchError exception will be thrown if the version could not
        be extracted or it is not included in the supported versions list.

        :schema_file: Absolute path to an alternative schema file. Should
                      be only used for testing purposes (Default is None)
    '''

    if not is_available():
        # Something is wrong with the SOLR server
        log.warn('Problems were found while connecting to the SOLR server')
        return False

    # Try to get the schema XML file to extract the version
    if not schema_file:
        solr_url, solr_user, solr_password = SolrSettings.get()

        http_auth = None
        if solr_user is not None and solr_password is not None:
            http_auth = solr_user + ':' + solr_password
            http_auth = 'Basic ' + http_auth.encode('base64').strip()

        url = solr_url.strip('/') + SOLR_SCHEMA_FILE_OFFSET

        req = urllib2.Request(url=url)
        if http_auth:
            req.add_header('Authorization', http_auth)

        res = urllib2.urlopen(req)
    else:
        url = 'file://%s' % schema_file
        res = urllib2.urlopen(url)

    tree = xml.dom.minidom.parseString(res.read())

    version = tree.documentElement.getAttribute('version')
    if not len(version):
        raise SearchError('Could not extract version info from the SOLR'
                          ' schema, using file: \n%s' % url)

    if not version in SUPPORTED_SCHEMA_VERSIONS:
        raise SearchError('SOLR schema version not supported: %s. Supported'
                          ' versions are [%s]'
                          % (version, ', '.join(SUPPORTED_SCHEMA_VERSIONS)))
    return True
Ejemplo n.º 3
0
def _get_schema_from_solr(file_offset):
    solr_url, solr_user, solr_password = SolrSettings.get()

    http_auth = None
    if solr_user is not None and solr_password is not None:
        http_auth = solr_user + ':' + solr_password
        http_auth = 'Basic ' + http_auth.encode('base64').strip()

    url = solr_url.strip('/') + file_offset

    req = urllib2.Request(url=url)
    if http_auth:
        req.add_header('Authorization', http_auth)

    return urllib2.urlopen(req)
Ejemplo n.º 4
0
def _get_schema_from_solr(file_offset):
    solr_url, solr_user, solr_password = SolrSettings.get()

    http_auth = None
    if solr_user is not None and solr_password is not None:
        http_auth = solr_user + ':' + solr_password
        http_auth = 'Basic ' + http_auth.encode('base64').strip()

    url = solr_url.strip('/') + file_offset

    req = urllib2.Request(url=url)
    if http_auth:
        req.add_header('Authorization', http_auth)

    return urllib2.urlopen(req)
Ejemplo n.º 5
0
def _get_schema_from_solr(file_offset):
    solr_url, solr_user, solr_password = SolrSettings.get()

    http_auth = None
    if solr_user is not None and solr_password is not None:
        http_auth = solr_user + ':' + solr_password
        http_auth = 'Basic ' + http_auth.encode('base64').strip()

    url = solr_url.strip('/') + file_offset

    if http_auth:
        response = requests.get(url, headers={'Authorization': http_auth})
    else:
        response = requests.get(url)

    return response