コード例 #1
0
    def get_platforms(self) -> dict:
        platforms_path = Factory().get_config().get('platforms',
                                                    'class_storage')
        platforms = {}

        for filename in os.listdir(platforms_path):
            is_platform = all([
                os.path.isfile(os.path.join(platforms_path, filename)),
                not (filename.startswith('base_') or filename.startswith('_'))
            ])

            if is_platform:
                name = filename.replace('.py', '')
                class_name = StringUtils.snake_to_camel(name)

                platform_module = getattr(
                    importlib.import_module('platforms.' + name,
                                            package='app'), class_name)
                inspection = self._reflect_platform_settings(platform_module)

                platforms[name] = {
                    'display_name': class_name,
                    'settings': inspection
                }

        return platforms
コード例 #2
0
    def request_execution(self, platform_id: str, settings: dict, **kwargs):
        try:
            client = Factory().get_platform(platform_id, settings)
            return self._queue.enqueue(f=client.run,
                                       job_id='::'.join([
                                           datetime.now().isoformat(),
                                           kwargs.get('_id', 'manual'),
                                           platform_id
                                       ])).get_id()

        except AttributeError:
            raise errors.MissingPlatformError
        except TypeError as e:
            raise errors.PlatformInstantiationError(*e.args)
コード例 #3
0
 def get(self):
     """
     GET
     """
     try:
         job = Factory().get_execution_service().get_job_data(
             job_id=request.GET.get('job_id'),
             is_full='full' in request.GET)
         return self._dict_reply(200, job)
     except NameError as e:
         return self._dict_reply(400, e.message)
     except Exception as e:
         return self._dict_reply(
             500, ', '.join([getattr(e, 'message', ''), ', '.join(e.args)]))
コード例 #4
0
    def run(self):
        """
        POST
        """
        try:
            account_settings = request.json
            return self._dict_reply(
                200, {
                    'job_id':
                    Factory().get_execution_service().request_execution(
                        **account_settings)
                })

        except PlatformInstantiationError as e:
            print(e.args)
            return self._dict_reply(
                400, 'Missing parameters in request: ' + ', '.join(e.args))
        except (ModuleNotFoundError, AssertionError):
            return self._dict_reply(400, 'Missing or invalid platform_id')
        except Exception as e:
            print(e.args)
            return self._dict_reply(
                500, 'Execution threw a ' + str(e.__class__) + 'error')
コード例 #5
0
ファイル: redis.py プロジェクト: QuittyMR/etlas-collector
 def __init__(self) -> None:
     super(Redis, self).__init__()
     from appcore.services.factory import Factory
     self._config = dict(Factory().get_config().items('redis'))
     self.DB_NAME = self._config['db']
     self._client = self._connect_to_redis()
コード例 #6
0
 def __init__(self):
     super(ExecutionService, self).__init__()
     self._queue = rq.Queue(
         constants.WORKER_QUEUE,
         connection=Factory().get_storage_client('redis')._client)
コード例 #7
0
ファイル: base_api.py プロジェクト: QuittyMR/etlas-collector
 def _csv_reply(self, data):
     response.content_type = 'text/csv'
     response.add_header('Content-Disposition', 'attachment')
     return Factory().get_storage_service().get_csv(data)
コード例 #8
0
 def __init__(self) -> None:
     super(Mongo, self).__init__()
     from appcore.services.factory import Factory
     self._client = self._connect_to_mongo(
         dict(Factory().get_config().items('mongo')))