Beispiel #1
0
    def __init__(self, provider_def):
        """
        Initialize object

        :param provider_def: provider definition
        :returns: `woudc_api.plugins.metrics.MetricsProcessor`
        """

        BaseProcessor.__init__(self, provider_def, PROCESS_SETTINGS)

        url_tokens = os.environ.get('WOUDC_API_ES_URL').split('/')

        LOGGER.debug('Setting Elasticsearch properties')
        self.index = 'woudc_data_registry.data_record'
        host = url_tokens[2]

        LOGGER.debug('Host: {}'.format(host))
        LOGGER.debug('Index name: {}'.format(self.index))

        LOGGER.debug('Connecting to Elasticsearch')
        self.es = Elasticsearch(host)

        if not self.es.ping():
            msg = 'Cannot connect to Elasticsearch'
            LOGGER.error(msg)
            raise ProcessorExecuteError(msg)

        LOGGER.debug('Checking Elasticsearch version')
        version = float(self.es.info()['version']['number'][:3])
        if version < 7:
            msg = 'Elasticsearch version below 7 not supported ({})' \
                  .format(version)
            LOGGER.error(msg)
            raise ProcessorExecuteError(msg)
Beispiel #2
0
        def execute(self, data):
            layer = data['layer']
            date_end = data['date_end']
            date_begin = data['date_begin']
            x = data['x']
            y = data['y']
            time_step = data['time_step']
            format_ = data['format']

            if format_.lower() != 'geojson' and format_.lower() != 'png':
                msg = 'Invalid format'
                LOGGER.error(msg)
                raise ValueError(msg)

            try:
                output = get_rpda_info(layer, date_end, date_begin, x, y,
                                       time_step, format_)

            except ValueError as error:
                msg = 'Process execution error: {}'.format(error)
                LOGGER.error(msg)
                raise ProcessorExecuteError(msg)

            if format_.lower() == 'png':
                if output is not None:
                    return output.getvalue()
                else:
                    return BytesIO().getvalue()
            else:
                return output
        def execute(self, data):
            mimetype = 'application/json'

            layer = data.get('layer')
            x = float(data.get('x'))
            y = float(data.get('y'))
            format_ = data.get('format')

            try:
                output = raster_drill(layer, x, y, format_)
            except ValueError as err:
                msg = 'Process execution error: {}'.format(err)
                LOGGER.error(msg)
                raise ProcessorExecuteError(msg)

            if format_ == 'GeoJSON':
                dict_ = output
            elif format_ == 'CSV':
                mimetype = 'text/csv'
                dict_ = output.getvalue()
            else:
                msg = 'Invalid format'
                LOGGER.error(msg)
                raise ValueError(msg)

            return mimetype, dict_
Beispiel #4
0
    def execute(self, data):

        name = data.get('name', None)

        if name is None:
            raise ProcessorExecuteError('Cannot process without a name')

        value = 'Hello {}! {}'.format(name, data.get('message', '')).strip()

        outputs = [{'id': 'echo', 'value': value}]

        return outputs
Beispiel #5
0
    def execute(self, data):

        mimetype = 'application/json'
        name = data.get('name', None)

        if name is None:
            raise ProcessorExecuteError('Cannot process without a name')

        value = 'Hello {}! {}'.format(name, data.get('message', '')).strip()

        outputs = {'id': 'echo', 'value': value}

        return mimetype, outputs
Beispiel #6
0
        def execute(self, data):
            layers = data['layers']
            fh = datetime.strptime(data['forecast-hour'], DATE_FORMAT)
            mr = datetime.strptime(data['model-run'], DATE_FORMAT)
            bbox = data['bbox']
            format_ = data['format'].lower()

            try:
                output = generate_vigilance(layers.split(','), fh, mr,
                                            bbox.split(','), format_)
                if output is not None:
                    if format_ == "geopng":
                        return output
                    else:
                        return output.getvalue()
                else:
                    return BytesIO().getvalue()
            except ValueError as err:
                msg = 'Process execution error: {}'.format(err)
                LOGGER.error(msg)
                raise ProcessorExecuteError(msg)
Beispiel #7
0
        def execute(self, data):
            layer = data['layer']
            x = float(data['x'])
            y = float(data['y'])
            format_ = data['format']

            try:
                output = raster_drill(layer, x, y, format_)
            except ValueError as err:
                msg = 'Process execution error: {}'.format(err)
                LOGGER.error(msg)
                raise ProcessorExecuteError(msg)

            if format_ == 'GeoJSON':
                dict_ = output
            elif format_ == 'CSV':
                dict_ = output.getvalue()
            else:
                msg = 'Invalid format'
                LOGGER.error(msg)
                raise ValueError(msg)

            return dict_