Example #1
0
    def fetch_profiles(self):
        rpc = GenericClient(module='UserProfile',
                            url=self.user_profile_url,
                            timeout=self.upstream_timeout,
                            token=None)
        users = rpc.call_func('filter_users', {'filter': ''})

        usernames = [user['username'] for user in users]

        profiles = []

        batches, rem = divmod(len(usernames), 1000)

        for batch_number in range(0, batches + 1):
            if batch_number == batches:
                start = batch_number * 1000
                stop = start + rem
            else:
                start = batch_number * 1000
                stop = (batch_number + 1) * 1000

            username_group = usernames[start:stop]
            result = rpc.call_func('get_user_profile', username_group)

            profiles.extend(result)

        return profiles
 def get_client_groups(self):
     url = self.config['catalog-url']
     rpc = GenericClient(url=url, module="Catalog", token=self.token)
     # Note that an empty params is sent - this is due to the definition of this
     # catalog method -- it is specified with an empty struct as the param!
     result = rpc.call_func('get_client_groups', {})
     return result
 def test_mock_call_status(self):
     client = GenericClient(module='Test',
                            url='http://localhost:5001',
                            token='FAKE',
                            timeout=CALL_TIMEOUT)
     result = client.call_func('status')
     self.assertIn('state', result)
     self.assertEqual(result['state'], 'ok')
    def _lookup_url(self, timeout):
        service_wizard = GenericClient(module='ServiceWizard',
                                       url=self.service_wizard_url,
                                       token=self.token,
                                       timeout=timeout)

        params = {'module_name': self.module_name, 'version': self.service_ver}
        result = service_wizard.call_func('get_service_status', params)
        return result['url']
Example #5
0
 def __init__(self, url, token, timeout):
     self.url = url
     self.token = token
     self.timeout = timeout
     self.module = 'execution_engine2'
     self.rpc = GenericClient(url=self.url,
                              module=self.module,
                              timeout=self.timeout,
                              token=self.token)
    def test_mock_call_timeout(self):
        TIMEOUT = 1
        client = GenericClient(module='Test',
                               url='http://localhost:5001',
                               token='FAKE',
                               timeout=TIMEOUT)
        with self.assertRaises(ServiceError) as context_manager:
            client.call_func('sleep_for', {'sleep': 2})

        service_error = context_manager.exception
        self.assertEqual(service_error.code, 100)
    def load_for_tag(self, tag):
        rpc = GenericClient(module='NarrativeMethodStore',
                            url=self.narrative_method_store_url,
                            timeout=self.upstream_timeout,
                            token=None)
        result = rpc.call_func('list_methods', {'tag': tag})

        to_add = []
        for app in result:
            to_add.append((app['id'], app))
        self.add_many(to_add, tag)
    def call_func(self, method, params=None, timeout=None):
        timeout = timeout or self.timeout

        # If not cached or cache entry is expired, re-fetch the url from
        # the service wizard.
        service_url = self._get_url(timeout)

        client = GenericClient(module=self.module_name,
                               url=service_url,
                               token=self.token,
                               timeout=timeout)

        return client.call_func(method, params)
Example #9
0
    def get_workspaces(self, workspace_ids):
        url = self.config['workspace-url']
        rpc = GenericClient(url=url,
                            module="Workspace",
                            token=self.token,
                            timeout=self.timeout)

        workspace_infos = []
        for workspace_id in workspace_ids:
            try:
                [
                    id, name, owner, moddate, max_objid, user_permission,
                    globalread, lockstat, metadata
                ] = rpc.call_func('get_workspace_info', {'id': workspace_id})

                if metadata.get('narrative', None) is None:
                    is_narrative = False
                else:
                    is_narrative = True

                info = {
                    'id': workspace_id,
                    'is_accessible': True,
                    'name': name,
                    'is_deleted': False
                }
                if (is_narrative):
                    if metadata.get('is_temporary', None) == 'true':
                        is_temporary = True
                    else:
                        is_temporary = False
                    info['narrative'] = {
                        'title': metadata.get('narrative_nice_name', None),
                        'is_temporary': is_temporary
                    }

                workspace_infos.append(info)
            except Exception:
                workspace_infos.append({
                    'id': workspace_id,
                    'is_accessible': False
                })

        return workspace_infos
 def test_basic_constructor(self):
     GenericClient(module='Foo',
                   url='https://example.kbase.us',
                   token='FAKE',
                   timeout=CALL_TIMEOUT)
     self.assertEqual(True, True)
 def test_constructor_missing_timeout(self):
     with self.assertRaisesRegexp(ValueError, 'timeout'):
         GenericClient(module='Foo',
                       url='https://example.kbase.us',
                       token='FAKE')
 def test_constructor_missing_url(self):
     with self.assertRaisesRegexp(ValueError, 'url'):
         GenericClient(module='Foo', token='FAKE', timeout=CALL_TIMEOUT)
 def test_constructor_missing_module(self):
     with self.assertRaisesRegexp(ValueError, 'module'):
         GenericClient(url='https://example.kbase.us',
                       token='FAKE',
                       timeout=CALL_TIMEOUT)
Example #14
0
class EE2Api(object):
    def __init__(self, url, token, timeout):
        self.url = url
        self.token = token
        self.timeout = timeout
        self.module = 'execution_engine2'
        self.rpc = GenericClient(url=self.url,
                                 module=self.module,
                                 timeout=self.timeout,
                                 token=self.token)

    def list_config(self):
        try:
            return self.rpc.call_func('list_config')
        except ServiceError:
            raise
        except Exception as err:
            raise ServiceError(code=40000,
                               message='Unknown error',
                               data={'original_message': str(err)})

    def ver(self):
        try:
            return self.rpc.call_func('ver')
        except ServiceError:
            raise
        except Exception as err:
            raise ServiceError(code=40000,
                               message='Unknown error',
                               data={'original_message': str(err)})

    def get_job_params(self, params):
        try:
            return self.rpc.call_func('get_job_params', params)
        except ServiceError:
            raise
        except Exception as err:
            raise ServiceError(code=40000,
                               message='Unknown error',
                               data={'original_message': str(err)})

    def status(self):
        try:
            return self.rpc.call_func('status')
        except ServiceError:
            raise
        except Exception as err:
            raise ServiceError(code=40000,
                               message='Unknown error',
                               data={'original_message': str(err)})

    def check_job(self, params):
        try:
            return self.rpc.call_func('check_job', params)
        except ServiceError:
            raise
        except Exception as err:
            raise ServiceError(code=40000,
                               message='Unknown error',
                               data={'original_message': str(err)})

    def check_jobs(self, params):
        try:
            return self.rpc.call_func('check_jobs', params)
        except ServiceError:
            raise
        except Exception as err:
            raise ServiceError(code=1,
                               message='Unknown error',
                               data={'original_message': str(err)})

    def check_workspace_jobs(self, params):
        try:
            return self.rpc.call_func('check_workspace_jobs', params)
        except ServiceError:
            raise
        except Exception as err:
            raise ServiceError(code=1,
                               message='Unknown error',
                               data={'original_message': str(err)})

    def check_job_canceled(self, params):
        try:
            return self.rpc.call_func('check_job_canceled', params)
        except ServiceError:
            raise
        except Exception as err:
            raise ServiceError(code=1,
                               message='Unknown error',
                               data={'original_message': str(err)})

    def get_job_status(self, params):
        try:
            return self.rpc.call_func('get_job_status', params)
        except ServiceError:
            raise
        except Exception as err:
            raise ServiceError(code=1,
                               message='Unknown error',
                               data={'original_message': str(err)})

    def get_client_groups(self):
        try:
            return self.rpc.call_func('get_client_groups')
        except ServiceError:
            raise
        except Exception as err:
            raise ServiceError(code=1,
                               message='Unknown error',
                               data={'original_message': str(err)})

    def get_job_logs(self, params):
        try:
            return self.rpc.call_func('get_job_logs', params)
        except ServiceError:
            raise
        except Exception as err:
            raise ServiceError(code=1,
                               message='Unknown error',
                               data={'original_message': str(err)})

    def get_admin_permission(self):
        try:
            result = self.rpc.call_func('get_admin_permission')
            return result
        except ServiceError:
            raise
        except Exception as ex:
            raise ServiceError(code=40000,
                               message='Unknown error',
                               data={'original_message': str(ex)})

    def is_admin(self):
        try:
            result = self.rpc.call_func('is_admin')
            return result
        except ServiceError:
            raise
        except Exception as ex:
            raise ServiceError(code=40000,
                               message='Unknown error',
                               data={'original_message': str(ex)})

    def check_jobs_date_range_for_user(self, params):
        try:
            return self.rpc.call_func('check_jobs_date_range_for_user', params)
        except ServiceError:
            raise
        except Exception as ex:
            raise ServiceError(code=40000,
                               message='Unknown error',
                               data={'original_message': str(ex)})

    def check_jobs_date_range_for_all(self, params):
        try:
            return self.rpc.call_func('check_jobs_date_range_for_all', params)
        except ServiceError:
            raise
        except Exception as ex:
            raise ServiceError(code=40000,
                               message='Unknown error',
                               data={'original_message': str(ex)})

    def cancel_job(self, params):
        try:
            return self.rpc.call_func('cancel_job', params)
        except ServiceError:
            raise
        except Exception as ex:
            raise ServiceError(code=40000,
                               message='Unknown error',
                               data={'original_message': str(ex)})