当前位置: 首页>>代码示例>>Python>>正文


Python Session.query方法代码示例

本文整理汇总了Python中fts3rest.lib.base.Session.query方法的典型用法代码示例。如果您正苦于以下问题:Python Session.query方法的具体用法?Python Session.query怎么用?Python Session.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fts3rest.lib.base.Session的用法示例。


在下文中一共展示了Session.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cancel_terminal

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
    def test_cancel_terminal(self):
        """
        Cancel a job with files in terminal state
        """
        job_id = self._submit()

        job = Session.query(Job).get(job_id)
        job.job_state = 'FINISHED'
        for f in job.files:
            f.file_state = 'FINISHED'
        Session.merge(job)
        Session.commit()

        answer = self.app.delete(url="/jobs/%s" % job_id,
                                 status=200)
        job = json.loads(answer.body)

        self.assertEqual(job['job_id'], job_id)
        self.assertEqual(job['job_state'], 'FINISHED')
        self.assertNotEqual(job['reason'], 'Job canceled by the user')

        # Is it in the database?
        job = Session.query(Job).get(job_id)
        self.assertEqual(job.job_state, 'FINISHED')
        for f in job.files:
            self.assertEqual(f.file_state, 'FINISHED')
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:28,代码来源:test_job_cancel.py

示例2: get_my_apps

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
    def get_my_apps(self):
        """
        Returns the list of registered apps
        """
        user = pylons.request.environ['fts3.User.Credentials']
        my_apps = Session.query(OAuth2Application).filter(OAuth2Application.owner == user.user_dn).all()

        authorized_apps = Session.query(
            OAuth2Application.client_id, OAuth2Application.name, OAuth2Application.website,
            OAuth2Application.description, OAuth2Token.refresh_token, OAuth2Token.scope, OAuth2Token.expires
        ).filter((OAuth2Token.dlg_id == user.delegation_id) & (OAuth2Token.client_id == OAuth2Application.client_id))

        response = {'apps': my_apps, 'authorized': authorized_apps}
        if _accept_html(pylons.request.accept):
            pylons.response.headers['Content-Type'] = 'text/html; charset=UTF-8'
            response['user'] = user
            response['site'] = pylons.config['fts3.SiteName']
            return render('/apps.html', extra_vars=response)
        else:
            pylons.response.headers['Content-Type'] = 'application/json'
            # Better serialization for authorized apps
            authorized = list()
            for auth in authorized_apps:
                authorized.append({
                    'name': auth.name,
                    'website': auth.website,
                    'description': auth.description,
                    'scope': auth.scope,
                    'expires': auth.expires
                })
            response['authorized'] = authorized
            return to_json(response)
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:34,代码来源:oauth2.py

示例3: update_app

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
    def update_app(self, client_id):
        """
        Update an application
        """
        user = pylons.request.environ['fts3.User.Credentials']
        app = Session.query(OAuth2Application).get(client_id)
        if not app:
            raise HTTPNotFound('Application not found')
        if app.owner != user.user_dn:
            raise HTTPForbidden()
        if pylons.request.headers['Content-Type'].startswith('application/json'):
            fields = json.loads(pylons.request.body)
        else:
            fields = pylons.request.POST

        try:
            if 'delete' not in fields:
                app.description = fields.get('description', '')
                app.website = fields.get('website', '')
                app.redirect_to = fields.get('redirect_to', '')
                Session.merge(app)
                Session.commit()
                redirect(url_for(controller='oauth2', action='get_app'), code=HTTPSeeOther.code)
            else:
                Session.delete(app)
                Session.query(OAuth2Token).filter(OAuth2Token.client_id == client_id).delete()
                Session.query(OAuth2Code).filter(OAuth2Code.client_id == client_id).delete()
                Session.commit()
                redirect(url_for(controller='oauth2', action='get_my_apps'), code=HTTPSeeOther.code)
        except:
            Session.rollback()
            raise
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:34,代码来源:oauth2.py

示例4: test_ban_se_cancel_vo

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
    def test_ban_se_cancel_vo(self):
        """
        Cancel a SE that has files queued, make sure they are canceled (with VO)
        """
        jobs = list()
        jobs.append(insert_job('dteam', 'gsiftp://source', 'gsiftp://destination', 'SUBMITTED'))
        jobs.append(insert_job('atlas', 'gsiftp://source', 'gsiftp://destination', 'SUBMITTED'))
        jobs.append(insert_job('atlas', 'gsiftp://source', 'gsiftp://destination2', 'SUBMITTED'))

        answer = self.app.post(
            url="/ban/se",
            params={'storage': 'gsiftp://source', 'status': 'cancel', 'vo_name': 'dteam'},
            status=200
        )
        canceled_ids = json.loads(answer.body)

        self.assertEqual(1, len(canceled_ids))
        self.assertIn(jobs[0], canceled_ids)

        for job_id in jobs:
            job = Session.query(Job).get(job_id)
            files = Session.query(File).filter(File.job_id == job_id)

            if job_id in canceled_ids:
                self.assertEqual('CANCELED', job.job_state)
            else:
                self.assertEqual('SUBMITTED', job.job_state)
            for f in files:
                if job_id in canceled_ids:
                    self.assertEqual('CANCELED', f.file_state)
                else:
                    self.assertEqual('SUBMITTED', f.file_state)
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:34,代码来源:test_banning.py

示例5: test_ban_se_wait_vo

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
    def test_ban_se_wait_vo(self):
        """
        Ban a SE, but instead of canceling, give jobs some time to finish (with VO)
        """
        jobs = list()
        jobs.append(insert_job('dteam', 'gsiftp://source', 'gsiftp://destination', 'SUBMITTED'))
        jobs.append(insert_job('atlas', 'gsiftp://source', 'gsiftp://destination', 'SUBMITTED'))
        jobs.append(insert_job('atlas', 'gsiftp://source', 'gsiftp://destination2', 'SUBMITTED'))

        answer = self.app.post(
            url="/ban/se",
            params={'storage': 'gsiftp://source', 'status': 'wait', 'vo_name': 'dteam', 'timeout': 33},
            status=200
        )
        waiting_ids = json.loads(answer.body)

        self.assertEqual(1, len(waiting_ids))
        self.assertIn(jobs[0], waiting_ids)

        for job_id in jobs:
            job = Session.query(Job).get(job_id)
            files = Session.query(File).filter(File.job_id == job_id)

            self.assertEqual('SUBMITTED', job.job_state)
            for f in files:
                self.assertEqual('SUBMITTED', f.file_state)
                if job_id in waiting_ids:
                    self.assertEqual(33, f.wait_timeout)
                else:
                    self.assertEqual(None, f.wait_timeout)
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:32,代码来源:test_banning.py

示例6: test_ban_se_cancel

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
    def test_ban_se_cancel(self):
        """
        Ban a SE that has files queued, make sure they are canceled
        """
        jobs = list()
        jobs.append(insert_job('dteam', 'gsiftp://source', 'gsiftp://destination', 'SUBMITTED'))
        jobs.append(insert_job('dteam', 'gsiftp://source', 'gsiftp://destination2', 'ACTIVE'))
        jobs.append(insert_job('dteam', 'gsiftp://source', 'gsiftp://destination2', 'FAILED', duration=10, queued=20))

        answer = self.app.post(url="/ban/se", params={'storage': 'gsiftp://source'}, status=200)
        canceled_ids = json.loads(answer.body)

        self.assertEqual(2, len(canceled_ids))
        self.assertIn(jobs[0], canceled_ids)
        self.assertIn(jobs[1], canceled_ids)
        self.assertNotIn(jobs[2], canceled_ids)

        for job_id in jobs[0:2]:
            job = Session.query(Job).get(job_id)
            files = Session.query(File).filter(File.job_id == job_id)
            self.assertEqual('CANCELED', job.job_state)
            self.assertNotEqual(None, job.job_finished)
            self.assertNotEqual(None, job.finish_time)
            for f in files:
                self.assertEqual('CANCELED', f.file_state)
                self.assertNotEqual(None, f.job_finished)
                self.assertNotEqual(None, f.finish_time)
                self.assertEqual('Storage banned', f.reason)

        job = Session.query(Job).get(jobs[2])
        self.assertEqual(job.job_state, 'FAILED')
        files = Session.query(File).filter(File.job_id == job.job_id)
        for f in files:
            self.assertEqual('FAILED', f.file_state)
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:36,代码来源:test_banning.py

示例7: apiVersion

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
	def apiVersion(self):
		credV   = Session.query(CredentialVersion)[0]
		schemaV = Session.query(SchemaVersion)[0]
		return {'api': _Version(0, 2, 1),
			    'schema': credV,
			    'delegation': schemaV,
			    '_links': {
					'curies': [{'name': 'fts', 'href': 'https://svnweb.cern.ch/trac/fts3'}],
					
					'fts:whoami': {'href': '/whoami', 'title': 'Check user certificate'},
					
					'fts:joblist': {'href': '/jobs{?vo_name,user_dn}', 'title': 'List of active jobs', 'templated': True},
					'fts:job': {
						'href': '/jobs/{id}',
						'title': 'Job information',
						'templated': True,
						'hints': {
							'allow': ['GET', 'DELETE']
						}
					},
					
					
					'fts:configaudit': {'href': '/config/audit', 'title': 'Configuration'},
					
					'fts:submitschema': {'href': '/schema/submit', 'title': 'JSON schema of messages'},
					'fts:jobsubmit': {
						'href': '/jobs',
						'hints': {
							'allow': ['POST'],
							'representations': ['fts:submitschema']
						}
					},
				}
			}
开发者ID:mhellmic,项目名称:fts3,代码行数:36,代码来源:misc.py

示例8: _cancel_jobs

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
def _cancel_jobs(dn):
    """
    Cancel all jobs that belong to dn.
    Returns the list of affected jobs ids.
    """
    jobs = Session.query(Job.job_id).filter(Job.job_state.in_(JobActiveStates)).filter(Job.user_dn == dn)
    job_ids = map(lambda j: j[0], jobs)

    try:
        now = datetime.utcnow()
        for job_id in job_ids:
            Session.query(File).filter(File.job_id == job_id).filter(File.file_state.in_(FileActiveStates))\
                .update({
                    'file_state': 'CANCELED', 'reason': 'User banned',
                    'job_finished': now, 'finish_time': now
                }, synchronize_session=False)
            Session.query(Job).filter(Job.job_id == job_id)\
                .update({
                    'job_state': 'CANCELED', 'reason': 'User banned',
                    'job_finished': now, 'finish_time': now
                }, synchronize_session=False)
        Session.commit()
	Session.expire_all()
        return job_ids
    except Exception:
        Session.rollback()
        raise
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:29,代码来源:banning.py

示例9: test_ban_se_partial_job

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
    def test_ban_se_partial_job(self):
        """
        Ban a SE that has files queued. If a job has other pairs, the job must remain!
        """
        job_id = insert_job(
            'dteam',
            multiple=[('gsiftp://source', 'gsiftp://destination'), ('gsiftp://other', 'gsiftp://destination')]
        )
        answer = self.app.post(url="/ban/se", params={'storage': 'gsiftp://source'}, status=200)
        canceled_ids = json.loads(answer.body)

        self.assertEqual(1, len(canceled_ids))
        self.assertEqual(job_id, canceled_ids[0])

        job = Session.query(Job).get(job_id)
        self.assertEqual('SUBMITTED', job.job_state)
        self.assertEqual(None, job.job_finished)
        self.assertEqual(None, job.finish_time)

        files = Session.query(File).filter(File.job_id == job_id)
        for f in files:
            if f.source_se == 'gsiftp://source':
                self.assertEqual('CANCELED', f.file_state)
                self.assertNotEqual(None, f.finish_time)
            else:
                self.assertEqual('SUBMITTED', f.file_state)
            self.assertEqual(None, f.job_finished)
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:29,代码来源:test_banning.py

示例10: get_files

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
 def get_files(self, job_id):
     """
     Get the files within a job
     """
     owner = Session.query(Job.user_dn, Job.vo_name).filter(Job.job_id == job_id).first()
     if owner is None:
         raise HTTPNotFound('No job with the id "%s" has been found' % job_id)
     if not authorized(TRANSFER, resource_owner=owner[0], resource_vo=owner[1]):
         raise HTTPForbidden('Not enough permissions to check the job "%s"' % job_id)
     files = Session.query(File).filter(File.job_id == job_id).options(noload(File.retries))
     return files.all()
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:13,代码来源:jobs.py

示例11: _get_limits

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
def _get_limits(source, destination):
    source_thr = Session.query(Optimize.throughput)\
        .filter(Optimize.source_se==source).filter(Optimize.throughput != None).all()
    dest_thr = Session.query(Optimize.throughput)\
        .filter(Optimize.dest_se==destination).filter(Optimize.throughput != None).all()

    limits = dict()
    if len(source_thr):
        limits['source'] = source_thr[0][0]
    if len(dest_thr):
        limits['destination'] = dest_thr[0][0]

    return limits
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:15,代码来源:snapshot.py

示例12: test_ban_dn

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
    def test_ban_dn(self):
        """
        Just ban a DN and unban it, make sure changes go into the DB
        """
        answer = self.app.post(url='/ban/dn', params={'user_dn': '/DC=cern/CN=someone'}, status=200)
        canceled = json.loads(answer.body)
        self.assertEqual(0, len(canceled))

        banned = Session.query(BannedDN).get('/DC=cern/CN=someone')
        self.assertNotEqual(None, banned)
        self.assertEqual(self.get_user_credentials().user_dn, banned.admin_dn)

        self.app.delete(url="/ban/dn?user_dn=%s" % urllib.quote('/DC=cern/CN=someone'), status=204)
        banned = Session.query(BannedDN).get('/DC=cern/CN=someone')
        self.assertEqual(None, banned)
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:17,代码来源:test_banning.py

示例13: get_file_retries

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
 def get_file_retries(self, job_id, file_id):
     """
     Get the retries for a given file
     """
     owner = Session.query(Job.user_dn, Job.vo_name).filter(Job.job_id == job_id).all()
     if owner is None or len(owner) < 1:
         raise HTTPNotFound('No job with the id "%s" has been found' % job_id)
     if not authorized(TRANSFER,
                       resource_owner=owner[0][0], resource_vo=owner[0][1]):
         raise HTTPForbidden('Not enough permissions to check the job "%s"' % job_id)
     f = Session.query(File.file_id).filter(File.file_id == file_id)
     if not f:
         raise HTTPNotFound('No file with the id "%d" has been found' % file_id)
     retries = Session.query(FileRetryLog).filter(FileRetryLog.file_id == file_id)
     return retries.all()
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:17,代码来源:jobs.py

示例14: credential

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
    def credential(self, dlg_id, start_response):
        """
        Second step of the delegation process: put the generated certificate

        The certificate being PUT will have to pass the following validation:
            - There is a previous certificate request done
            - The certificate subject matches the certificate issuer + '/CN=Proxy'
            - The certificate modulus matches the stored private key modulus
        """
        user = request.environ['fts3.User.Credentials']

        if dlg_id != user.delegation_id:
            raise HTTPForbidden('The requested ID and the credentials ID do not match')

        credential_cache = Session.query(CredentialCache)\
            .get((user.delegation_id, user.user_dn))
        if credential_cache is None:
            raise HTTPBadRequest('No credential cache found')

        x509_proxy_pem = request.body
        log.debug("Received delegated credentials for %s" % dlg_id)
        log.debug(x509_proxy_pem)

        try:
            expiration_time = _validate_proxy(x509_proxy_pem, credential_cache.priv_key)
            x509_full_proxy_pem = _build_full_proxy(x509_proxy_pem, credential_cache.priv_key)
        except ProxyException, e:
            raise HTTPBadRequest('Could not process the proxy: ' + str(e))
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:30,代码来源:delegation.py

示例15: request

# 需要导入模块: from fts3rest.lib.base import Session [as 别名]
# 或者: from fts3rest.lib.base.Session import query [as 别名]
    def request(self, dlg_id, start_response):
        """
        First step of the delegation process: get a certificate request

        The returned certificate request must be signed with the user's original
        credentials.
        """
        user = request.environ['fts3.User.Credentials']

        if dlg_id != user.delegation_id:
            raise HTTPForbidden('The requested ID and the credentials ID do not match')

        credential_cache = Session.query(CredentialCache)\
            .get((user.delegation_id, user.user_dn))

        if credential_cache is None or credential_cache.cert_request is None:
            (x509_request, private_key) = _generate_proxy_request()
            credential_cache = CredentialCache(dlg_id=user.delegation_id, dn=user.user_dn,
                                               cert_request=x509_request.as_pem(),
                                               priv_key=private_key.as_pem(cipher=None),
                                               voms_attrs=' '.join(user.voms_cred))
            try:
                Session.merge(credential_cache)
                Session.commit()
            except Exception:
                Session.rollback()
                raise
            log.debug("Generated new credential request for %s" % dlg_id)
        else:
            log.debug("Using cached request for %s" % dlg_id)

        start_response('200 Ok', [('X-Delegation-ID', credential_cache.dlg_id),
                                  ('Content-Type', 'text/plain')])
        return [credential_cache.cert_request]
开发者ID:andrea-manzi,项目名称:fts3-rest,代码行数:36,代码来源:delegation.py


注:本文中的fts3rest.lib.base.Session.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。