Пример #1
0
    def layer_to_solr(self, layer):
        """
        Sync a layer in Solr.
        """
        success = True
        message = 'Synced layer id %s to Solr' % layer.id

        layer_dict, message = layer2dict(layer)
        if not layer_dict:
            success = False
        else:
            layer_json = json.dumps(layer_dict)
            try:
                url_solr_update = '%s/solr/hypermap/update/json/docs' % SEARCH_URL
                headers = {"content-type": "application/json"}
                params = {"commitWithin": 1500}
                res = requests.post(url_solr_update,
                                    data=layer_json,
                                    params=params,
                                    headers=headers)
                res = res.json()
                if 'error' in res:
                    success = False
                    message = "Error syncing layer id %s to Solr: %s" % (
                        layer.id, res["error"].get("msg"))
            except Exception, e:
                success = False
                message = "Error syncing layer id %s to Solr: %s" % (
                    layer.id, sys.exc_info()[1])
                LOGGER.error(e, exc_info=True)
Пример #2
0
    def layer_to_solr(self, layer):
        """
        Sync a layer in Solr.
        """
        layer_dict = layer2dict(layer)
        layer_json = json.dumps(layer_dict)
        try:
            url_solr_update = '%s/solr/hypermap/update/json/docs' % SEARCH_URL
            headers = {"content-type": "application/json"}
            params = {"commitWithin": 1500}
            res = requests.post(url_solr_update,
                                data=layer_json,
                                params=params,
                                headers=headers)
            res = res.json()
            if 'error' in res:
                message = res["error"].get("msg")
                LOGGER.debug("ERROR: {0}".format(message))
                return False, message
            else:
                LOGGER.info("Solr record saved for layer with id: %s" %
                            layer.id)

            return True, None
        except Exception, e:
            LOGGER.error("Error saving solr record for layer with id: %s" %
                         layer.id)
            LOGGER.error(e, exc_info=True)
            return False, sys.exc_info()[1]
Пример #3
0
    def layers_to_solr(self, layers):
        """
        Sync n layers in Solr.
        """

        layers_dict_list = []
        layers_success_ids = []
        layers_errors_ids = []

        for layer in layers:
            layer_dict, message = layer2dict(layer)
            if not layer_dict:
                layers_errors_ids.append([layer.id, message])
                LOGGER.error(message)
            else:
                layers_dict_list.append(layer_dict)
                layers_success_ids.append(layer.id)

        layers_json = json.dumps(layers_dict_list)
        try:
            url_solr_update = '%s/solr/hypermap/update/json/docs' % SEARCH_URL
            headers = {"content-type": "application/json"}
            params = {"commitWithin": 1500}
            requests.post(url_solr_update,
                          data=layers_json,
                          params=params,
                          headers=headers)
            LOGGER.info('Solr synced for the given layers')
        except Exception:
            message = "Error saving solr records: %s" % sys.exc_info()[1]
            layers_errors_ids.append([-1, message])
            LOGGER.error(message)
            return False, layers_errors_ids

        return True, layers_errors_ids
Пример #4
0
    def layer_to_solr(self, layer):
        """
        Sync a layer in Solr.
        """
        success = True
        message = 'Synced layer id %s to Solr' % layer.id

        layer_dict, message = layer2dict(layer)
        if not layer_dict:
            success = False
        else:
            layer_json = json.dumps(layer_dict)
            try:
                url_solr_update = '%s/solr/hypermap/update/json/docs' % SEARCH_URL
                headers = {"content-type": "application/json"}
                params = {"commitWithin": 1500}
                res = requests.post(url_solr_update, data=layer_json, params=params,  headers=headers)
                res = res.json()
                if 'error' in res:
                    success = False
                    message = "Error syncing layer id %s to Solr: %s" % (layer.id, res["error"].get("msg"))
            except Exception, e:
                success = False
                message = "Error syncing layer id %s to Solr: %s" % (layer.id, sys.exc_info()[1])
                LOGGER.error(e, exc_info=True)
Пример #5
0
    def layers_to_solr(self, layers):
        """
        Sync n layers in Solr.
        """

        layers_dict_list = []
        layers_success_ids = []
        layers_errors_ids = []

        for layer in layers:
            layer_dict, message = layer2dict(layer)
            if not layer_dict:
                layers_errors_ids.append([layer.id, message])
                LOGGER.error(message)
            else:
                layers_dict_list.append(layer_dict)
                layers_success_ids.append(layer.id)

        layers_json = json.dumps(layers_dict_list)
        try:
            url_solr_update = '%s/solr/hypermap/update/json/docs' % SEARCH_URL
            headers = {"content-type": "application/json"}
            params = {"commitWithin": 1500}
            requests.post(url_solr_update, data=layers_json, params=params, headers=headers)
            LOGGER.info('Solr synced for the given layers')
        except Exception:
            message = "Error saving solr records: %s" % sys.exc_info()[1]
            layers_errors_ids.append([-1, message])
            LOGGER.error(message)
            return False, layers_errors_ids

        return True, layers_errors_ids
Пример #6
0
 def layers_to_solr(self, layers):
     """
     Sync n layers in Solr.
     """
     layers_list = []
     for layer in layers:
         layer_dict = layer2dict(layer)
         layers_list.append(layer_dict)
     layers_json = json.dumps(layers_list)
     try:
         url_solr_update = '%s/solr/hypermap/update/json/docs' % SEARCH_URL
         headers = {"content-type": "application/json"}
         params = {"commitWithin": 1500}
         requests.post(url_solr_update, data=layers_json, params=params, headers=headers)
         LOGGER.info("Solr synced for the given layers.")
         return True, None
     except Exception, e:
         LOGGER.error("Error saving solr records")
         LOGGER.error(e, exc_info=True)
         return False, sys.exc_info()[1]
Пример #7
0
 def layers_to_solr(self, layers):
     """
     Sync n layers in Solr.
     """
     layers_list = []
     for layer in layers:
         layer_dict = layer2dict(layer)
         layers_list.append(layer_dict)
     layers_json = json.dumps(layers_list)
     try:
         url_solr_update = '%s/solr/hypermap/update/json/docs' % SEARCH_URL
         headers = {"content-type": "application/json"}
         params = {"commitWithin": 1500}
         requests.post(url_solr_update, data=layers_json, params=params, headers=headers)
         LOGGER.info("Solr synced for the given layers.")
         return True, None
     except Exception, e:
         LOGGER.error("Error saving solr records")
         LOGGER.error(e, exc_info=True)
         return False, sys.exc_info()[1]
Пример #8
0
    def layer_to_solr(self, layer):
        """
        Sync a layer in Solr.
        """
        layer_dict = layer2dict(layer)
        layer_json = json.dumps(layer_dict)
        try:
            url_solr_update = '%s/solr/hypermap/update/json/docs' % SEARCH_URL
            headers = {"content-type": "application/json"}
            params = {"commitWithin": 1500}
            res = requests.post(url_solr_update, data=layer_json, params=params,  headers=headers)
            res = res.json()
            if 'error' in res:
                message = res["error"].get("msg")
                LOGGER.debug("ERROR: {0}".format(message))
                return False, message
            else:
                LOGGER.info("Solr record saved for layer with id: %s" % layer.id)

            return True, None
        except Exception, e:
            LOGGER.error("Error saving solr record for layer with id: %s" % layer.id)
            LOGGER.error(e, exc_info=True)
            return False, sys.exc_info()[1]