author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 22 Jan 2014 10:39:57 +0100 | |
changeset 9454 | a173f9cf9f26 |
parent 9452 | 5308b3fe03c9 |
child 9455 | 62e89e696a3b |
permissions | -rw-r--r-- |
8943
58b3b2d9c965
[repo] kill rebuildinfered feature from Repository.set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8916
diff
changeset
|
1 |
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5376
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""Defines the central class for the CubicWeb RQL server: the repository. |
19 |
||
20 |
The repository is an abstraction allowing execution of rql queries against |
|
21 |
data sources. Most of the work is actually done in helper classes. The |
|
22 |
repository mainly: |
|
23 |
||
24 |
* brings these classes all together to provide a single access |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
25 |
point to a cubicweb instance. |
0 | 26 |
* handles session management |
27 |
* provides method for pyro registration, to call if pyro is enabled |
|
5587
72679e450f6d
[web] dont attempt to update last login time on ldap users, avoiding spurious tb in logs (closes #914464)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
28 |
""" |
0 | 29 |
__docformat__ = "restructuredtext en" |
30 |
||
31 |
import sys |
|
5587
72679e450f6d
[web] dont attempt to update last login time on ldap users, avoiding spurious tb in logs (closes #914464)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
32 |
import threading |
0 | 33 |
import Queue |
7507
4c043afb104a
fix failures introduced by recent refactoring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7503
diff
changeset
|
34 |
from warnings import warn |
6390
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
35 |
from itertools import chain |
4719
aaed3f813ef8
kill dead/useless code as suggested by pylint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4714
diff
changeset
|
36 |
from os.path import join |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
636
diff
changeset
|
37 |
from datetime import datetime |
0 | 38 |
from time import time, localtime, strftime |
9113
af6efc15fc90
[repository] add an ``internal_cnx`` method to replace ``internal_session``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
39 |
from contextlib import contextmanager |
9302
af36f459d2f0
[server] deprecate the old multi-source system
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9272
diff
changeset
|
40 |
from warnings import warn |
0 | 41 |
|
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
42 |
from logilab.common.decorators import cached, clear_cache |
9034
cc3442054e48
[repo] move repo stats to Service (closes #2951067)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9033
diff
changeset
|
43 |
from logilab.common.deprecation import deprecated |
3757 | 44 |
from logilab.common.compat import any |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
45 |
from logilab.common import flatten |
0 | 46 |
|
47 |
from yams import BadSchemaDefinition |
|
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4984
diff
changeset
|
48 |
from yams.schema import role_name |
0 | 49 |
from rql import RQLSyntaxError |
6390
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
50 |
from rql.utils import rqlvar_maker |
0 | 51 |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
52 |
from cubicweb import (CW_SOFTWARE_ROOT, CW_MIGRATION_MAP, QueryError, |
2709
6ee816eb9f25
[hooksmanager] hooks should be reseted after vreg reload
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2708
diff
changeset
|
53 |
UnknownEid, AuthenticationError, ExecutionError, |
3042
d2455badf7fb
[multi-sources] enhance relation'source detection to avoid inconsistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2967
diff
changeset
|
54 |
ETypeNotSupportedBySources, MultiSourcesError, |
0 | 55 |
BadConnectionId, Unauthorized, ValidationError, |
8748
f5027f8d2478
drop typed_eid() in favour of int() (closes #2742462)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8699
diff
changeset
|
56 |
RepositoryError, UniqueTogetherError, onevent) |
2839
6419af16faa0
imports cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
57 |
from cubicweb import cwvreg, schema, server |
7573
c8f8762c986d
[repo, looping task] raise a custom exception when repository is shuting down, avoid looping task to be restarted in such case. Closes #1021276
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7550
diff
changeset
|
58 |
from cubicweb.server import ShuttingDown, utils, hook, pool, querier, sources |
8562
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8539
diff
changeset
|
59 |
from cubicweb.server.session import Session, InternalSession, InternalManager |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
60 |
from cubicweb.server.ssplanner import EditedEntity |
0 | 61 |
|
7780
a1d5365fefc1
[cubification] moved CWPermission handling into a localperms cube. closes #1914011
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7723
diff
changeset
|
62 |
NO_CACHE_RELATIONS = set( [('owned_by', 'object'), |
7373
e5e6ef56cfb5
[repo cache] there are some relations we don't want to cache, they may cause memory leak
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7305
diff
changeset
|
63 |
('created_by', 'object'), |
e5e6ef56cfb5
[repo cache] there are some relations we don't want to cache, they may cause memory leak
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7305
diff
changeset
|
64 |
('cw_source', 'object'), |
e5e6ef56cfb5
[repo cache] there are some relations we don't want to cache, they may cause memory leak
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7305
diff
changeset
|
65 |
]) |
7134
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
66 |
|
8456
c912d82f2166
[repository] drop unused argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8433
diff
changeset
|
67 |
def prefill_entity_caches(entity): |
6467
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
68 |
session = entity._cw |
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
69 |
# prefill entity relation caches |
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
70 |
for rschema in entity.e_schema.subject_relations(): |
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
71 |
rtype = str(rschema) |
7373
e5e6ef56cfb5
[repo cache] there are some relations we don't want to cache, they may cause memory leak
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7305
diff
changeset
|
72 |
if rtype in schema.VIRTUAL_RTYPES or (rtype, 'subject') in NO_CACHE_RELATIONS: |
6467
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
73 |
continue |
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
74 |
if rschema.final: |
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
75 |
entity.cw_attr_cache.setdefault(rtype, None) |
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
76 |
else: |
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
77 |
entity.cw_set_relation_cache(rtype, 'subject', |
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
78 |
session.empty_rset()) |
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
79 |
for rschema in entity.e_schema.object_relations(): |
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
80 |
rtype = str(rschema) |
7373
e5e6ef56cfb5
[repo cache] there are some relations we don't want to cache, they may cause memory leak
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7305
diff
changeset
|
81 |
if rtype in schema.VIRTUAL_RTYPES or (rtype, 'object') in NO_CACHE_RELATIONS: |
6467
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
82 |
continue |
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
83 |
entity.cw_set_relation_cache(rtype, 'object', session.empty_rset()) |
869813c2dd40
[entity, repo] move prefill_entity_cache function back to repository due to usage of del_existing_rel_if_needed function which is also defined there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6466
diff
changeset
|
84 |
|
0 | 85 |
def del_existing_rel_if_needed(session, eidfrom, rtype, eidto): |
86 |
"""delete existing relation when adding a new one if card is 1 or ? |
|
87 |
||
88 |
have to be done once the new relation has been inserted to avoid having |
|
89 |
an entity without a relation for some time |
|
90 |
||
91 |
this kind of behaviour has to be done in the repository so we don't have |
|
92 |
hooks order hazardness |
|
93 |
""" |
|
7503
bc30c2faaadc
[repository] refactor and optimize '?1' relation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7502
diff
changeset
|
94 |
# skip that if integrity explicitly disabled |
bc30c2faaadc
[repository] refactor and optimize '?1' relation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7502
diff
changeset
|
95 |
if not session.is_hook_category_activated('activeintegrity'): |
4687
082e66184f71
[integrity] skip auto-delete for internal sessions (but *not* for super session, see 4642:921737d2e3a8)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4686
diff
changeset
|
96 |
return |
7502
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7501
diff
changeset
|
97 |
rdef = session.rtype_eids_rdef(rtype, eidfrom, eidto) |
e7190f7e850e
[session] deprecates schema_rproperty in favor of more optimized rtype_eids_rdef which return the rdef (so reusable to gather other data)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7501
diff
changeset
|
98 |
card = rdef.cardinality |
0 | 99 |
# one may be tented to check for neweids but this may cause more than one |
100 |
# relation even with '1?' cardinality if thoses relations are added in the |
|
101 |
# same transaction where the entity is being created. This never occurs from |
|
102 |
# the web interface but may occurs during test or dbapi connection (though |
|
103 |
# not expected for this). So: don't do it, we pretend to ensure repository |
|
104 |
# consistency. |
|
4673
6f8b925a29f4
auto-delete relation with single cardinality using execute, not unsafe_execute, so permissions are correctly checked
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4643
diff
changeset
|
105 |
# |
6189 | 106 |
# notes: |
107 |
# * inlined relations will be implicitly deleted for the subject entity |
|
108 |
# * we don't want read permissions to be applied but we want delete |
|
109 |
# permission to be checked |
|
7503
bc30c2faaadc
[repository] refactor and optimize '?1' relation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7502
diff
changeset
|
110 |
if card[0] in '1?': |
8562
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8539
diff
changeset
|
111 |
with session.security_enabled(read=False): |
6189 | 112 |
session.execute('DELETE X %s Y WHERE X eid %%(x)s, ' |
113 |
'NOT Y eid %%(y)s' % rtype, |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
114 |
{'x': eidfrom, 'y': eidto}) |
0 | 115 |
if card[1] in '1?': |
8562
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8539
diff
changeset
|
116 |
with session.security_enabled(read=False): |
5711
ea2538a3c622
[repo] fix typo
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5641
diff
changeset
|
117 |
session.execute('DELETE X %s Y WHERE Y eid %%(y)s, ' |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
118 |
'NOT X eid %%(x)s' % rtype, |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
119 |
{'x': eidfrom, 'y': eidto}) |
1482 | 120 |
|
3694 | 121 |
|
8547
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
122 |
def preprocess_inlined_relations(session, entity): |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
123 |
"""when an entity is added, check if it has some inlined relation which |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
124 |
requires to be extrated for proper call hooks |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
125 |
""" |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
126 |
relations = [] |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
127 |
activeintegrity = session.is_hook_category_activated('activeintegrity') |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
128 |
eschema = entity.e_schema |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
129 |
for attr in entity.cw_edited: |
8547
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
130 |
rschema = eschema.subjrels[attr] |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
131 |
if not rschema.final: # inlined relation |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
132 |
value = entity.cw_edited[attr] |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
133 |
relations.append((attr, value)) |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
134 |
session.update_rel_cache_add(entity.eid, attr, value) |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
135 |
rdef = session.rtype_eids_rdef(attr, entity.eid, value) |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
136 |
if rdef.cardinality[1] in '1?' and activeintegrity: |
8573 | 137 |
with session.security_enabled(read=False): |
8547
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
138 |
session.execute('DELETE X %s Y WHERE Y eid %%(y)s' % attr, |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
139 |
{'x': entity.eid, 'y': value}) |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
140 |
return relations |
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
141 |
|
8320
cd2d332b3063
[repo looping task] move looping task logic in a dedicated object (progress #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8280
diff
changeset
|
142 |
|
8211
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
143 |
class NullEventBus(object): |
8214
ce9556358dbd
[event bus] event has been renamed to publish
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8211
diff
changeset
|
144 |
def publish(self, msg): |
8211
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
145 |
pass |
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
146 |
|
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
147 |
def add_subscription(self, topic, callback): |
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
148 |
pass |
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
149 |
|
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
150 |
def start(self): |
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
151 |
pass |
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
152 |
|
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
153 |
def stop(self): |
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
154 |
pass |
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
155 |
|
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
156 |
|
0 | 157 |
class Repository(object): |
158 |
"""a repository provides access to a set of persistent storages for |
|
159 |
entities and relations |
|
160 |
||
161 |
XXX protect pyro access |
|
162 |
""" |
|
1482 | 163 |
|
8322
cb838b126b07
[repository] move task manager instantiation outside repository.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8321
diff
changeset
|
164 |
def __init__(self, config, tasks_manager=None, vreg=None): |
0 | 165 |
self.config = config |
166 |
if vreg is None: |
|
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8133
diff
changeset
|
167 |
vreg = cwvreg.CWRegistryStore(config) |
0 | 168 |
self.vreg = vreg |
8322
cb838b126b07
[repository] move task manager instantiation outside repository.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8321
diff
changeset
|
169 |
self._tasks_manager = tasks_manager |
8320
cd2d332b3063
[repo looping task] move looping task logic in a dedicated object (progress #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8280
diff
changeset
|
170 |
|
0 | 171 |
self.pyro_registered = False |
7134
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
172 |
self.pyro_uri = None |
9007
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
173 |
# every pyro client is handled in its own thread; map these threads to |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
174 |
# the session we opened for them so we can clean up when they go away |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
175 |
self._pyro_sessions = {} |
8211
543e1579ba0d
[repo] Add a publish/subscribe mechanism for inter-instance communication using zmq
Julien Cristau <julien.cristau@logilab.fr>, Quentin Roquefort <quentin@kpsule.me>
parents:
8190
diff
changeset
|
176 |
self.app_instances_bus = NullEventBus() |
0 | 177 |
self.info('starting repository from %s', self.config.apphome) |
178 |
# dictionary of opened sessions |
|
179 |
self._sessions = {} |
|
8320
cd2d332b3063
[repo looping task] move looping task logic in a dedicated object (progress #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8280
diff
changeset
|
180 |
|
cd2d332b3063
[repo looping task] move looping task logic in a dedicated object (progress #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8280
diff
changeset
|
181 |
|
0 | 182 |
# list of functions to be called at regular interval |
183 |
# list of running threads |
|
184 |
self._running_threads = [] |
|
185 |
# initial schema, should be build or replaced latter |
|
2839
6419af16faa0
imports cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
186 |
self.schema = schema.CubicWebSchema(config.appid) |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3042
diff
changeset
|
187 |
self.vreg.schema = self.schema # until actual schema is loaded... |
5906
d40ced753291
[repository] fix so that when repository is shutting down, internal session in transaction are interrupted
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5813
diff
changeset
|
188 |
# shutdown flag |
d40ced753291
[repository] fix so that when repository is shutting down, internal session in transaction are interrupted
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5813
diff
changeset
|
189 |
self.shutting_down = False |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
190 |
# sources (additional sources info in the system database) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
191 |
self.system_source = self.get_source('native', 'system', |
8672
e8afecc3b576
[repository sources] copy source configuration: source's __init__ modify it while config.sources() return a cached dictionary which shouldn't be modified
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8671
diff
changeset
|
192 |
config.sources()['system'].copy()) |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
193 |
self.sources = [self.system_source] |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
194 |
self.sources_by_uri = {'system': self.system_source} |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
195 |
# querier helper, need to be created after sources initialization |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
196 |
self.querier = querier.QuerierHelper(self, self.schema) |
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
197 |
# cache eid -> (type, physical source, extid, actual source) |
0 | 198 |
self._type_source_cache = {} |
199 |
# cache (extid, source uri) -> eid |
|
200 |
self._extid_cache = {} |
|
8946
fae2f561b0f5
[repo] minor cleanups to bootstrap sequence
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8943
diff
changeset
|
201 |
# open some connection sets |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
202 |
if config.init_cnxset_pool: |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
203 |
self.init_cnxset_pool() |
8946
fae2f561b0f5
[repo] minor cleanups to bootstrap sequence
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8943
diff
changeset
|
204 |
# the hooks manager |
fae2f561b0f5
[repo] minor cleanups to bootstrap sequence
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8943
diff
changeset
|
205 |
self.hm = hook.HooksManager(self.vreg) |
fae2f561b0f5
[repo] minor cleanups to bootstrap sequence
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8943
diff
changeset
|
206 |
# registry hook to fix user class on registry reload |
5079
e646047f80cb
[reload] on registry reloading, we should change class of users of opened session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5073
diff
changeset
|
207 |
@onevent('after-registry-reload', self) |
e646047f80cb
[reload] on registry reloading, we should change class of users of opened session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5073
diff
changeset
|
208 |
def fix_user_classes(self): |
8277
8b173e0a617f
{repository] add documentation explaining ``fix_user_classes`` hook
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8275
diff
changeset
|
209 |
# After registery reload the 'CWUser' class used for CWEtype |
8b173e0a617f
{repository] add documentation explaining ``fix_user_classes`` hook
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8275
diff
changeset
|
210 |
# changed. To any existing user object have a different class than |
8b173e0a617f
{repository] add documentation explaining ``fix_user_classes`` hook
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8275
diff
changeset
|
211 |
# the new loaded one. We are hot fixing this. |
5079
e646047f80cb
[reload] on registry reloading, we should change class of users of opened session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5073
diff
changeset
|
212 |
usercls = self.vreg['etypes'].etype_class('CWUser') |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
213 |
for session in self._sessions.itervalues(): |
5079
e646047f80cb
[reload] on registry reloading, we should change class of users of opened session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5073
diff
changeset
|
214 |
if not isinstance(session.user, InternalManager): |
e646047f80cb
[reload] on registry reloading, we should change class of users of opened session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5073
diff
changeset
|
215 |
session.user.__class__ = usercls |
2959
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2929
diff
changeset
|
216 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
217 |
def init_cnxset_pool(self): |
8946
fae2f561b0f5
[repo] minor cleanups to bootstrap sequence
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8943
diff
changeset
|
218 |
"""should be called bootstrap_repository, as this is what it does""" |
2959
daabb9bc5233
make db-restore command work even with no/corrupted database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2929
diff
changeset
|
219 |
config = self.config |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
220 |
self._cnxsets_pool = Queue.Queue() |
8947
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
221 |
# 0. init a cnxset that will be used to fetch bootstrap information from |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
222 |
# the database |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
223 |
self._cnxsets_pool.put_nowait(pool.ConnectionsSet(self.sources)) |
8947
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
224 |
# 1. set used cubes |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
225 |
if config.creating or not config.read_instance_schema: |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
226 |
config.bootstrap_cubes() |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
227 |
else: |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
228 |
self.set_schema(self.config.load_bootstrap_schema(), resetvreg=False) |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
229 |
config.init_cubes(self.get_cubes()) |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
230 |
# 2. load schema |
5043
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5032
diff
changeset
|
231 |
if config.quick_start: |
8946
fae2f561b0f5
[repo] minor cleanups to bootstrap sequence
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8943
diff
changeset
|
232 |
# quick start: only to get a minimal repository to get cubes |
5084
d8f491cb046c
[repo] we want a hooks manager and hooks initialized event on quick start (we trigger events such as server_backup / server_restore for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5079
diff
changeset
|
233 |
# information (eg dump/restore/...) |
8947
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
234 |
# |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
235 |
# restrict appobject_path to only load hooks and entity classes in |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
236 |
# the registry |
8537
e30d0a7f0087
[config] turn internal configuration methods building appobjects search path into normal method rather than class method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
237 |
config.cube_appobject_path = set(('hooks', 'entities')) |
e30d0a7f0087
[config] turn internal configuration methods building appobjects search path into normal method rather than class method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
238 |
config.cubicweb_appobject_path = set(('hooks', 'entities')) |
8947
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
239 |
# limit connections pool to 1 |
5043
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5032
diff
changeset
|
240 |
config['connections-pool-size'] = 1 |
8947
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
241 |
if config.quick_start or config.creating or not config.read_instance_schema: |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
242 |
# load schema from the file system |
8580
d753d6a6798f
[repository] move modification of appobject_path to repository initialization code so we can restore it later to avoid side effect on the config. Fix regression introduced in d32ab8570e5d
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8573
diff
changeset
|
243 |
if not config.creating: |
d753d6a6798f
[repository] move modification of appobject_path to repository initialization code so we can restore it later to avoid side effect on the config. Fix regression introduced in d32ab8570e5d
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8573
diff
changeset
|
244 |
self.warning("set fs instance'schema") |
9165
7ebf3b1cdb4c
Use the list of cubes from the filesystem when reading the schema from the filesystem
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9132
diff
changeset
|
245 |
self.set_schema(config.load_schema(expand_cubes=True)) |
8592
df16bd045cae
[server] fix repository initialisation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8580
diff
changeset
|
246 |
else: |
df16bd045cae
[server] fix repository initialisation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8580
diff
changeset
|
247 |
# normal start: load the instance schema from the database |
8947
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
248 |
self.info('loading schema from the repository') |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
249 |
self.set_schema(self.deserialize_schema()) |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
250 |
# 3. initialize data sources |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
251 |
if config.creating: |
6128 | 252 |
# call init_creating so that for instance native source can |
253 |
# configurate tsearch according to postgres version |
|
0 | 254 |
for source in self.sources: |
255 |
source.init_creating() |
|
8947
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
256 |
else: |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
257 |
self.init_sources_from_database() |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
258 |
if 'CWProperty' in self.schema: |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
259 |
self.vreg.init_properties(self.properties()) |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
260 |
# 4. close initialization connection set and reopen fresh ones for |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
261 |
# proper initialization |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
262 |
self._get_cnxset().close(True) |
8946
fae2f561b0f5
[repo] minor cleanups to bootstrap sequence
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8943
diff
changeset
|
263 |
self.cnxsets = [] # list of available cnxsets (can't iterate on a Queue) |
0 | 264 |
for i in xrange(config['connections-pool-size']): |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
265 |
self.cnxsets.append(pool.ConnectionsSet(self.sources)) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
266 |
self._cnxsets_pool.put_nowait(self.cnxsets[-1]) |
1482 | 267 |
|
0 | 268 |
# internals ############################################################### |
269 |
||
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
270 |
def init_sources_from_database(self): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
271 |
self.sources_by_eid = {} |
6664
7b6acf314a7a
[repo] don't attempt to read sources from database on quick start. Fix crash after restoring a pre 3.10 database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6629
diff
changeset
|
272 |
if self.config.quick_start \ |
7b6acf314a7a
[repo] don't attempt to read sources from database on quick start. Fix crash after restoring a pre 3.10 database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6629
diff
changeset
|
273 |
or not 'CWSource' in self.schema: # # 3.10 migration |
7550
183a61d1bab9
[3.10] fix typo and error for pre 3.10 migration w/ postgres: we *must* call init_creating else the fti isn't correctly initialized, which may lead to silently rollbacked transaction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7513
diff
changeset
|
274 |
self.system_source.init_creating() |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
275 |
return |
8433
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8393
diff
changeset
|
276 |
with self.internal_session() as session: |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
277 |
# FIXME: sources should be ordered (add_entity priority) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
278 |
for sourceent in session.execute( |
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6953
diff
changeset
|
279 |
'Any S, SN, SA, SC WHERE S is_instance_of CWSource, ' |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
280 |
'S name SN, S type SA, S config SC').entities(): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
281 |
if sourceent.name == 'system': |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
282 |
self.system_source.eid = sourceent.eid |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
283 |
self.sources_by_eid[sourceent.eid] = self.system_source |
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6953
diff
changeset
|
284 |
self.system_source.init(True, sourceent) |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
285 |
continue |
9448
3e7cad3967c5
[multi-sources-removal] Drop the "true" multi-sources planner
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9404
diff
changeset
|
286 |
self.add_source(sourceent) |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
287 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
288 |
def _clear_planning_caches(self): |
9452
5308b3fe03c9
[multi-sources-removal] Drop (dont_)cross relation related code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9451
diff
changeset
|
289 |
for cache in ('source_defs', 'is_multi_sources_relation'): |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
290 |
clear_cache(self, cache) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
291 |
|
9448
3e7cad3967c5
[multi-sources-removal] Drop the "true" multi-sources planner
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9404
diff
changeset
|
292 |
def add_source(self, sourceent): |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
293 |
source = self.get_source(sourceent.type, sourceent.name, |
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6941
diff
changeset
|
294 |
sourceent.host_config, sourceent.eid) |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
295 |
self.sources_by_eid[sourceent.eid] = source |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
296 |
self.sources_by_uri[sourceent.name] = source |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
297 |
if self.config.source_enabled(source): |
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6953
diff
changeset
|
298 |
# call source's init method to complete their initialisation if |
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6953
diff
changeset
|
299 |
# needed (for instance looking for persistent configuration using an |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
300 |
# internal session, which is not possible until connections sets have been |
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6953
diff
changeset
|
301 |
# initialized) |
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6953
diff
changeset
|
302 |
source.init(True, sourceent) |
6724
24bf6f181d0e
[pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
303 |
else: |
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6953
diff
changeset
|
304 |
source.init(False, sourceent) |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
305 |
self._clear_planning_caches() |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
306 |
|
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
307 |
def remove_source(self, uri): |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
308 |
source = self.sources_by_uri.pop(uri) |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
309 |
del self.sources_by_eid[source.eid] |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
310 |
self._clear_planning_caches() |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
311 |
|
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6941
diff
changeset
|
312 |
def get_source(self, type, uri, source_config, eid=None): |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
313 |
# set uri and type in source config so it's available through |
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
314 |
# source_defs() |
0 | 315 |
source_config['uri'] = uri |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
316 |
source_config['type'] = type |
6945
28bf94d062a9
[sources] refactor source creation and options handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6941
diff
changeset
|
317 |
return sources.get_source(type, source_config, self, eid) |
1482 | 318 |
|
8943
58b3b2d9c965
[repo] kill rebuildinfered feature from Repository.set_schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8916
diff
changeset
|
319 |
def set_schema(self, schema, resetvreg=True): |
0 | 320 |
self.info('set schema %s %#x', schema.name, id(schema)) |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3042
diff
changeset
|
321 |
if resetvreg: |
5447
f29dafba250a
[vreg repo] shouldn't call init_registration in on hook registry bootstrap, already done before
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5442
diff
changeset
|
322 |
# trigger full reload of all appobjects |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3042
diff
changeset
|
323 |
self.vreg.set_schema(schema) |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3042
diff
changeset
|
324 |
else: |
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3042
diff
changeset
|
325 |
self.vreg._set_schema(schema) |
0 | 326 |
self.querier.set_schema(schema) |
6126
aca6a2c357fd
[repository] enabled sources refactoring: to avoid error, we should always have all known source in repo.sources_by_uri and only enabled ones in repo.sources, so we still have access to the definition of temporarily disabled sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6061
diff
changeset
|
327 |
# don't use self.sources, we may want to give schema even to disabled |
aca6a2c357fd
[repository] enabled sources refactoring: to avoid error, we should always have all known source in repo.sources_by_uri and only enabled ones in repo.sources, so we still have access to the definition of temporarily disabled sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6061
diff
changeset
|
328 |
# sources |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
329 |
for source in self.sources_by_uri.itervalues(): |
0 | 330 |
source.set_schema(schema) |
331 |
self.schema = schema |
|
332 |
||
8947
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
333 |
def deserialize_schema(self): |
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
334 |
"""load schema from the database""" |
0 | 335 |
from cubicweb.server.schemaserial import deserialize_schema |
2839
6419af16faa0
imports cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
336 |
appschema = schema.CubicWebSchema(self.config.appid) |
0 | 337 |
self.debug('deserializing db schema into %s %#x', appschema.name, id(appschema)) |
8433
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8393
diff
changeset
|
338 |
with self.internal_session() as session: |
0 | 339 |
try: |
340 |
deserialize_schema(appschema, session) |
|
341 |
except BadSchemaDefinition: |
|
342 |
raise |
|
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8694
diff
changeset
|
343 |
except Exception as ex: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1372
diff
changeset
|
344 |
import traceback |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1372
diff
changeset
|
345 |
traceback.print_exc() |
9171
be9596750678
Fix two crashes in db-check (closes #3024964)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9165
diff
changeset
|
346 |
raise (Exception('Is the database initialised ? (cause: %s)' % ex), |
be9596750678
Fix two crashes in db-check (closes #3024964)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9165
diff
changeset
|
347 |
None, sys.exc_info()[-1]) |
8947
3bbd416b09ec
[repo] straightforward bootstrap sequence. Closes #2841188
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8946
diff
changeset
|
348 |
return appschema |
8321
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
349 |
|
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
350 |
def _prepare_startup(self): |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
351 |
"""Prepare "Repository as a server" for startup. |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
352 |
|
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
353 |
* trigger server startup hook, |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
354 |
* register session clean up task. |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
355 |
""" |
5043
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5032
diff
changeset
|
356 |
if not (self.config.creating or self.config.repairing |
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5032
diff
changeset
|
357 |
or self.config.quick_start): |
4958
665eacdd8c50
[repo] call server_startup event in start_looping_task the repo is fully started (registered in pyro for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4951
diff
changeset
|
358 |
# call instance level initialisation hooks |
665eacdd8c50
[repo] call server_startup event in start_looping_task the repo is fully started (registered in pyro for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4951
diff
changeset
|
359 |
self.hm.call_hooks('server_startup', repo=self) |
665eacdd8c50
[repo] call server_startup event in start_looping_task the repo is fully started (registered in pyro for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4951
diff
changeset
|
360 |
# register a task to cleanup expired session |
6012
d56fd78006cd
[session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
361 |
self.cleanup_session_time = self.config['cleanup-session-time'] or 60 * 60 * 24 |
d56fd78006cd
[session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
362 |
assert self.cleanup_session_time > 0 |
d56fd78006cd
[session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
363 |
cleanup_session_interval = min(60*60, self.cleanup_session_time / 3) |
8322
cb838b126b07
[repository] move task manager instantiation outside repository.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8321
diff
changeset
|
364 |
assert self._tasks_manager is not None, "This Repository is not intended to be used as a server" |
8321
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
365 |
self._tasks_manager.add_looping_task(cleanup_session_interval, |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
366 |
self.clean_sessions) |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
367 |
|
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
368 |
def start_looping_tasks(self): |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
369 |
"""Actual "Repository as a server" startup. |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
370 |
|
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
371 |
* trigger server startup hook, |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
372 |
* register session clean up task, |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
373 |
* start all tasks. |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
374 |
|
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
375 |
XXX Other startup related stuffs are done elsewhere. In Repository |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
376 |
XXX __init__ or in external codes (various server managers). |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
377 |
""" |
b5d5a5630649
[repository] split repo initialization from starting looping task (closes #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8320
diff
changeset
|
378 |
self._prepare_startup() |
8322
cb838b126b07
[repository] move task manager instantiation outside repository.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8321
diff
changeset
|
379 |
assert self._tasks_manager is not None, "This Repository is not intended to be used as a server" |
8320
cd2d332b3063
[repo looping task] move looping task logic in a dedicated object (progress #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8280
diff
changeset
|
380 |
self._tasks_manager.start() |
0 | 381 |
|
2708
60d728bdcba5
allow to specify arbitrary argument when recording a looping task func
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2667
diff
changeset
|
382 |
def looping_task(self, interval, func, *args): |
0 | 383 |
"""register a function to be called every `interval` seconds. |
1482 | 384 |
|
0 | 385 |
looping tasks can only be registered during repository initialization, |
386 |
once done this method will fail. |
|
387 |
""" |
|
8322
cb838b126b07
[repository] move task manager instantiation outside repository.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8321
diff
changeset
|
388 |
assert self._tasks_manager is not None, "This Repository is not intended to be used as a server" |
8320
cd2d332b3063
[repo looping task] move looping task logic in a dedicated object (progress #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8280
diff
changeset
|
389 |
self._tasks_manager.add_looping_task(interval, func, *args) |
0 | 390 |
|
391 |
def threaded_task(self, func): |
|
392 |
"""start function in a separated thread""" |
|
8320
cd2d332b3063
[repo looping task] move looping task logic in a dedicated object (progress #2204047)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8280
diff
changeset
|
393 |
utils.RepoThread(func, self._running_threads).start() |
1482 | 394 |
|
0 | 395 |
#@locked |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
396 |
def _get_cnxset(self): |
0 | 397 |
try: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
398 |
return self._cnxsets_pool.get(True, timeout=5) |
0 | 399 |
except Queue.Empty: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
400 |
raise Exception('no connections set available after 5 secs, probably either a ' |
9267
24d9b86dfa54
spelling: rollbacked -> rolled back
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9226
diff
changeset
|
401 |
'bug in code (too many uncommited/rolled back ' |
4706
6035e96b64dd
added stats for munin collecting #615844 - from 027bbff3659f
arthur
parents:
4689
diff
changeset
|
402 |
'connections) or too much load on the server (in ' |
0 | 403 |
'which case you can try to set a bigger ' |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
404 |
'connections pool size)') |
1482 | 405 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
406 |
def _free_cnxset(self, cnxset): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
407 |
self._cnxsets_pool.put_nowait(cnxset) |
0 | 408 |
|
409 |
def pinfo(self): |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
410 |
# XXX: session.cnxset is accessed from a local storage, would be interesting |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
411 |
# to see if there is a cnxset set in any thread specific data) |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
412 |
return '%s: %s (%s)' % (self._cnxsets_pool.qsize(), |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
413 |
','.join(session.user.login for session in self._sessions.itervalues() |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
414 |
if session.cnxset), |
0 | 415 |
threading.currentThread()) |
416 |
def shutdown(self): |
|
417 |
"""called on server stop event to properly close opened sessions and |
|
418 |
connections |
|
419 |
""" |
|
5906
d40ced753291
[repository] fix so that when repository is shutting down, internal session in transaction are interrupted
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5813
diff
changeset
|
420 |
assert not self.shutting_down, 'already shutting down' |
8393
77c7158916c1
[events] add a new before_shutdown event (closes #2345728)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8366
diff
changeset
|
421 |
if not (self.config.creating or self.config.repairing |
77c7158916c1
[events] add a new before_shutdown event (closes #2345728)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8366
diff
changeset
|
422 |
or self.config.quick_start): |
77c7158916c1
[events] add a new before_shutdown event (closes #2345728)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8366
diff
changeset
|
423 |
# then, the system source is still available |
77c7158916c1
[events] add a new before_shutdown event (closes #2345728)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8366
diff
changeset
|
424 |
self.hm.call_hooks('before_server_shutdown', repo=self) |
5906
d40ced753291
[repository] fix so that when repository is shutting down, internal session in transaction are interrupted
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5813
diff
changeset
|
425 |
self.shutting_down = True |
5749
b4393b681f7a
[repo] on repository shutdown, we've to close the new eid creation connection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5747
diff
changeset
|
426 |
self.system_source.shutdown() |
8322
cb838b126b07
[repository] move task manager instantiation outside repository.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8321
diff
changeset
|
427 |
if self._tasks_manager is not None: |
cb838b126b07
[repository] move task manager instantiation outside repository.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8321
diff
changeset
|
428 |
self._tasks_manager.stop() |
8351
02f4f01375e8
[repository] fire 'server_shutdown' hooks before waiting for theads
David Douard <david.douard@logilab.fr>
parents:
8322
diff
changeset
|
429 |
if not (self.config.creating or self.config.repairing |
02f4f01375e8
[repository] fire 'server_shutdown' hooks before waiting for theads
David Douard <david.douard@logilab.fr>
parents:
8322
diff
changeset
|
430 |
or self.config.quick_start): |
02f4f01375e8
[repository] fire 'server_shutdown' hooks before waiting for theads
David Douard <david.douard@logilab.fr>
parents:
8322
diff
changeset
|
431 |
self.hm.call_hooks('server_shutdown', repo=self) |
0 | 432 |
for thread in self._running_threads: |
5376
2c3f14bc2590
[python2.6] don't add a name property on Thread
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5292
diff
changeset
|
433 |
self.info('waiting thread %s...', thread.getName()) |
0 | 434 |
thread.join() |
5376
2c3f14bc2590
[python2.6] don't add a name property on Thread
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5292
diff
changeset
|
435 |
self.info('thread %s finished', thread.getName()) |
0 | 436 |
self.close_sessions() |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
437 |
while not self._cnxsets_pool.empty(): |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
438 |
cnxset = self._cnxsets_pool.get_nowait() |
0 | 439 |
try: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
440 |
cnxset.close(True) |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
441 |
except Exception: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
442 |
self.exception('error while closing %s' % cnxset) |
0 | 443 |
continue |
444 |
if self.pyro_registered: |
|
7134
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
445 |
if self._use_pyrons(): |
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
446 |
pyro_unregister(self.config) |
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
447 |
self.pyro_uri = None |
0 | 448 |
hits, misses = self.querier.cache_hit, self.querier.cache_miss |
449 |
try: |
|
5747
d6ac0cd30fde
[rset] do not filter rsets with __getstate__, ensure whatever flies with pyro has no .req attribute, also set the ._rqlst to None since it will be reconstructed later on demand
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5711
diff
changeset
|
450 |
self.info('rql st cache hit/miss: %s/%s (%s%% hits)', hits, misses, |
0 | 451 |
(hits * 100) / (hits + misses)) |
452 |
hits, misses = self.system_source.cache_hit, self.system_source.cache_miss |
|
453 |
self.info('sql cache hit/miss: %s/%s (%s%% hits)', hits, misses, |
|
454 |
(hits * 100) / (hits + misses)) |
|
455 |
nocache = self.system_source.no_cache |
|
456 |
self.info('sql cache usage: %s/%s (%s%%)', hits+ misses, nocache, |
|
457 |
((hits + misses) * 100) / (hits + misses + nocache)) |
|
458 |
except ZeroDivisionError: |
|
459 |
pass |
|
1482 | 460 |
|
6849
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6822
diff
changeset
|
461 |
def check_auth_info(self, session, login, authinfo): |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6822
diff
changeset
|
462 |
"""validate authentication, raise AuthenticationError on failure, return |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6822
diff
changeset
|
463 |
associated CWUser's eid on success. |
0 | 464 |
""" |
8229
b7bc631816f7
[ldapfeed] make authentication actually working
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8214
diff
changeset
|
465 |
# iter on sources_by_uri then check enabled source since sources doesn't |
b7bc631816f7
[ldapfeed] make authentication actually working
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8214
diff
changeset
|
466 |
# contain copy based sources |
b7bc631816f7
[ldapfeed] make authentication actually working
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8214
diff
changeset
|
467 |
for source in self.sources_by_uri.itervalues(): |
b7bc631816f7
[ldapfeed] make authentication actually working
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8214
diff
changeset
|
468 |
if self.config.source_enabled(source) and source.support_entity('CWUser'): |
0 | 469 |
try: |
6849
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6822
diff
changeset
|
470 |
return source.authenticate(session, login, **authinfo) |
0 | 471 |
except AuthenticationError: |
472 |
continue |
|
473 |
else: |
|
474 |
raise AuthenticationError('authentication failed with all sources') |
|
6849
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6822
diff
changeset
|
475 |
|
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6822
diff
changeset
|
476 |
def authenticate_user(self, session, login, **authinfo): |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6822
diff
changeset
|
477 |
"""validate login / password, raise AuthenticationError on failure |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6822
diff
changeset
|
478 |
return associated CWUser instance on success |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6822
diff
changeset
|
479 |
""" |
5a0c2cfc19bf
[repository auth] cleanup email login by turning it into a proper repo-side authentication plugin
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6822
diff
changeset
|
480 |
eid = self.check_auth_info(session, login, authinfo) |
2268
2f336fd5e040
euser->cwuser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
481 |
cwuser = self._build_user(session, eid) |
0 | 482 |
if self.config.consider_user_state and \ |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5447
diff
changeset
|
483 |
not cwuser.cw_adapt_to('IWorkflowable').state in cwuser.AUTHENTICABLE_STATES: |
0 | 484 |
raise AuthenticationError('user is not in authenticable state') |
2268
2f336fd5e040
euser->cwuser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2267
diff
changeset
|
485 |
return cwuser |
0 | 486 |
|
487 |
def _build_user(self, session, eid): |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1372
diff
changeset
|
488 |
"""return a CWUser entity for user with the given eid""" |
9105
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
489 |
with session.ensure_cnx_set: |
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
490 |
cls = self.vreg['etypes'].etype_class('CWUser') |
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
491 |
st = cls.fetch_rqlst(session.user, ordermethod=None) |
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
492 |
st.add_eid_restriction(st.get_variable('X'), 'x', 'Substitute') |
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
493 |
rset = session.execute(st.as_string(), {'x': eid}) |
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
494 |
assert len(rset) == 1, rset |
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
495 |
cwuser = rset.get_entity(0, 0) |
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
496 |
# pylint: disable=W0104 |
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
497 |
# prefetch / cache cwuser's groups and properties. This is especially |
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
498 |
# useful for internal sessions to avoid security insertions |
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
499 |
cwuser.groups |
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
500 |
cwuser.properties |
55738c9dc26f
[session] explicitly take Connection object in close_cnx
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9093
diff
changeset
|
501 |
return cwuser |
1482 | 502 |
|
0 | 503 |
# public (dbapi) interface ################################################ |
1482 | 504 |
|
9404
3e3e9b37e177
fix version number: we still target cw 3.19
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9402
diff
changeset
|
505 |
@deprecated("[3.19] use _cw.call_service('repo_stats'") |
5587
72679e450f6d
[web] dont attempt to update last login time on ldap users, avoiding spurious tb in logs (closes #914464)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
506 |
def stats(self): # XXX restrict to managers session? |
6256
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
507 |
"""Return a dictionary containing some statistics about the repository |
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
508 |
resources usage. |
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
509 |
|
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
510 |
This is a public method, not requiring a session id. |
9034
cc3442054e48
[repo] move repo stats to Service (closes #2951067)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9033
diff
changeset
|
511 |
|
cc3442054e48
[repo] move repo stats to Service (closes #2951067)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9033
diff
changeset
|
512 |
This method is deprecated in favor of using _cw.call_service('repo_stats') |
6256
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
513 |
""" |
9034
cc3442054e48
[repo] move repo stats to Service (closes #2951067)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9033
diff
changeset
|
514 |
with self.internal_session() as session: |
cc3442054e48
[repo] move repo stats to Service (closes #2951067)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9033
diff
changeset
|
515 |
return session.call_service('repo_stats') |
5587
72679e450f6d
[web] dont attempt to update last login time on ldap users, avoiding spurious tb in logs (closes #914464)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
516 |
|
9404
3e3e9b37e177
fix version number: we still target cw 3.19
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9402
diff
changeset
|
517 |
@deprecated("[3.19] use _cw.call_service('repo_gc_stats'") |
8224
e35d4d4f7eb3
[repository] add a ``gc_stats`` method and 2 more cache size for ``stats`` (closes #2179735)
David Douard <david.douard@logilab.fr>
parents:
8133
diff
changeset
|
518 |
def gc_stats(self, nmax=20): |
e35d4d4f7eb3
[repository] add a ``gc_stats`` method and 2 more cache size for ``stats`` (closes #2179735)
David Douard <david.douard@logilab.fr>
parents:
8133
diff
changeset
|
519 |
"""Return a dictionary containing some statistics about the repository |
e35d4d4f7eb3
[repository] add a ``gc_stats`` method and 2 more cache size for ``stats`` (closes #2179735)
David Douard <david.douard@logilab.fr>
parents:
8133
diff
changeset
|
520 |
memory usage. |
e35d4d4f7eb3
[repository] add a ``gc_stats`` method and 2 more cache size for ``stats`` (closes #2179735)
David Douard <david.douard@logilab.fr>
parents:
8133
diff
changeset
|
521 |
|
e35d4d4f7eb3
[repository] add a ``gc_stats`` method and 2 more cache size for ``stats`` (closes #2179735)
David Douard <david.douard@logilab.fr>
parents:
8133
diff
changeset
|
522 |
This is a public method, not requiring a session id. |
e35d4d4f7eb3
[repository] add a ``gc_stats`` method and 2 more cache size for ``stats`` (closes #2179735)
David Douard <david.douard@logilab.fr>
parents:
8133
diff
changeset
|
523 |
|
e35d4d4f7eb3
[repository] add a ``gc_stats`` method and 2 more cache size for ``stats`` (closes #2179735)
David Douard <david.douard@logilab.fr>
parents:
8133
diff
changeset
|
524 |
nmax is the max number of (most) referenced object returned as |
e35d4d4f7eb3
[repository] add a ``gc_stats`` method and 2 more cache size for ``stats`` (closes #2179735)
David Douard <david.douard@logilab.fr>
parents:
8133
diff
changeset
|
525 |
the 'referenced' result |
e35d4d4f7eb3
[repository] add a ``gc_stats`` method and 2 more cache size for ``stats`` (closes #2179735)
David Douard <david.douard@logilab.fr>
parents:
8133
diff
changeset
|
526 |
""" |
9035
63f3d25bab14
[repo] move repo.gc_stats to Service API (closes #2951068)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9034
diff
changeset
|
527 |
with self.internal_session() as session: |
63f3d25bab14
[repo] move repo.gc_stats to Service API (closes #2951068)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9034
diff
changeset
|
528 |
return session.call_service('repo_gc_stats', nmax=nmax) |
8224
e35d4d4f7eb3
[repository] add a ``gc_stats`` method and 2 more cache size for ``stats`` (closes #2179735)
David Douard <david.douard@logilab.fr>
parents:
8133
diff
changeset
|
529 |
|
0 | 530 |
def get_schema(self): |
6256
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
531 |
"""Return the instance schema. |
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
532 |
|
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
533 |
This is a public method, not requiring a session id. |
0 | 534 |
""" |
7723
badfd5524ab6
[repo] Stop setting hashmode on schema
Julien Cristau <julien.cristau@logilab.fr>
parents:
7716
diff
changeset
|
535 |
return self.schema |
0 | 536 |
|
537 |
def get_cubes(self): |
|
6256
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
538 |
"""Return the list of cubes used by this instance. |
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
539 |
|
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
540 |
This is a public method, not requiring a session id. |
0 | 541 |
""" |
2473
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2268
diff
changeset
|
542 |
versions = self.get_versions(not (self.config.creating |
4689
4eb1f4490538
[test] skipping versions checking during test is enough, no need for monkey patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4687
diff
changeset
|
543 |
or self.config.repairing |
5043
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5032
diff
changeset
|
544 |
or self.config.quick_start |
4689
4eb1f4490538
[test] skipping versions checking during test is enough, no need for monkey patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4687
diff
changeset
|
545 |
or self.config.mode == 'test')) |
0 | 546 |
cubes = list(versions) |
547 |
cubes.remove('cubicweb') |
|
548 |
return cubes |
|
549 |
||
6308
c151c730a1ac
[dbapi] get_option_value now has a foreid argument telling the option should be dereferenced to the entity's actual repository (necessary for apycot/local_cache handling)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6257
diff
changeset
|
550 |
def get_option_value(self, option, foreid=None): |
c151c730a1ac
[dbapi] get_option_value now has a foreid argument telling the option should be dereferenced to the entity's actual repository (necessary for apycot/local_cache handling)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6257
diff
changeset
|
551 |
"""Return the value for `option` in the configuration. If `foreid` is |
c151c730a1ac
[dbapi] get_option_value now has a foreid argument telling the option should be dereferenced to the entity's actual repository (necessary for apycot/local_cache handling)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6257
diff
changeset
|
552 |
specified, the actual repository to which this entity belongs is |
c151c730a1ac
[dbapi] get_option_value now has a foreid argument telling the option should be dereferenced to the entity's actual repository (necessary for apycot/local_cache handling)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6257
diff
changeset
|
553 |
derefenced and the option value retrieved from it. |
6257
7eb5f1aed728
[repo] new method on repo+dbapi.Connection to get a value from repository's configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6256
diff
changeset
|
554 |
|
7eb5f1aed728
[repo] new method on repo+dbapi.Connection to get a value from repository's configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6256
diff
changeset
|
555 |
This is a public method, not requiring a session id. |
7eb5f1aed728
[repo] new method on repo+dbapi.Connection to get a value from repository's configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6256
diff
changeset
|
556 |
""" |
7eb5f1aed728
[repo] new method on repo+dbapi.Connection to get a value from repository's configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6256
diff
changeset
|
557 |
# XXX we may want to check we don't give sensible information |
8074
a7f76e322659
add some notes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8051
diff
changeset
|
558 |
# XXX the only cube using 'foreid', apycot, stop used this, we probably |
a7f76e322659
add some notes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8051
diff
changeset
|
559 |
# want to drop this argument |
6308
c151c730a1ac
[dbapi] get_option_value now has a foreid argument telling the option should be dereferenced to the entity's actual repository (necessary for apycot/local_cache handling)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6257
diff
changeset
|
560 |
if foreid is None: |
c151c730a1ac
[dbapi] get_option_value now has a foreid argument telling the option should be dereferenced to the entity's actual repository (necessary for apycot/local_cache handling)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6257
diff
changeset
|
561 |
return self.config[option] |
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
562 |
_, sourceuri, extid, _ = self.type_and_source_from_eid(foreid) |
6308
c151c730a1ac
[dbapi] get_option_value now has a foreid argument telling the option should be dereferenced to the entity's actual repository (necessary for apycot/local_cache handling)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6257
diff
changeset
|
563 |
if sourceuri == 'system': |
c151c730a1ac
[dbapi] get_option_value now has a foreid argument telling the option should be dereferenced to the entity's actual repository (necessary for apycot/local_cache handling)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6257
diff
changeset
|
564 |
return self.config[option] |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
565 |
cnxset = self._get_cnxset() |
6308
c151c730a1ac
[dbapi] get_option_value now has a foreid argument telling the option should be dereferenced to the entity's actual repository (necessary for apycot/local_cache handling)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6257
diff
changeset
|
566 |
try: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
567 |
cnx = cnxset.connection(sourceuri) |
7064
b8ce2266d026
[repo] fix multi-threads bug with get_option_value: pyro proxy can't be used from a thread to another without caution (closes #1535206)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6889
diff
changeset
|
568 |
# needed to check connection is valid and usable by the current |
b8ce2266d026
[repo] fix multi-threads bug with get_option_value: pyro proxy can't be used from a thread to another without caution (closes #1535206)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6889
diff
changeset
|
569 |
# thread |
b8ce2266d026
[repo] fix multi-threads bug with get_option_value: pyro proxy can't be used from a thread to another without caution (closes #1535206)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6889
diff
changeset
|
570 |
newcnx = self.sources_by_uri[sourceuri].check_connection(cnx) |
b8ce2266d026
[repo] fix multi-threads bug with get_option_value: pyro proxy can't be used from a thread to another without caution (closes #1535206)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6889
diff
changeset
|
571 |
if newcnx is not None: |
b8ce2266d026
[repo] fix multi-threads bug with get_option_value: pyro proxy can't be used from a thread to another without caution (closes #1535206)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6889
diff
changeset
|
572 |
cnx = newcnx |
b8ce2266d026
[repo] fix multi-threads bug with get_option_value: pyro proxy can't be used from a thread to another without caution (closes #1535206)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6889
diff
changeset
|
573 |
return cnx.get_option_value(option, extid) |
6308
c151c730a1ac
[dbapi] get_option_value now has a foreid argument telling the option should be dereferenced to the entity's actual repository (necessary for apycot/local_cache handling)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6257
diff
changeset
|
574 |
finally: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
575 |
self._free_cnxset(cnxset) |
6257
7eb5f1aed728
[repo] new method on repo+dbapi.Connection to get a value from repository's configuration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6256
diff
changeset
|
576 |
|
0 | 577 |
@cached |
578 |
def get_versions(self, checkversions=False): |
|
6256
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
579 |
"""Return the a dictionary containing cubes used by this instance |
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
580 |
as key with their version as value, including cubicweb version. |
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
581 |
|
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
582 |
This is a public method, not requiring a session id. |
0 | 583 |
""" |
584 |
from logilab.common.changelog import Version |
|
585 |
vcconf = {} |
|
8433
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8393
diff
changeset
|
586 |
with self.internal_session() as session: |
0 | 587 |
for pk, version in session.execute( |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1372
diff
changeset
|
588 |
'Any K,V WHERE P is CWProperty, P value V, P pkey K, ' |
0 | 589 |
'P pkey ~="system.version.%"', build_descr=False): |
590 |
cube = pk.split('.')[-1] |
|
591 |
# XXX cubicweb migration |
|
592 |
if cube in CW_MIGRATION_MAP: |
|
593 |
cube = CW_MIGRATION_MAP[cube] |
|
594 |
version = Version(version) |
|
595 |
vcconf[cube] = version |
|
596 |
if checkversions: |
|
597 |
if cube != 'cubicweb': |
|
598 |
fsversion = self.config.cube_version(cube) |
|
599 |
else: |
|
600 |
fsversion = self.config.cubicweb_version() |
|
601 |
if version < fsversion: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
602 |
msg = ('instance has %s version %s but %s ' |
0 | 603 |
'is installed. Run "cubicweb-ctl upgrade".') |
604 |
raise ExecutionError(msg % (cube, version, fsversion)) |
|
605 |
return vcconf |
|
1482 | 606 |
|
0 | 607 |
@cached |
608 |
def source_defs(self): |
|
6256
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
609 |
"""Return the a dictionary containing source uris as value and a |
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
610 |
dictionary describing each source as value. |
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
611 |
|
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
612 |
This is a public method, not requiring a session id. |
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
613 |
""" |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
614 |
sources = {} |
0 | 615 |
# remove sensitive information |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6426
diff
changeset
|
616 |
for uri, source in self.sources_by_uri.iteritems(): |
6722
3341521d857b
[repo source] rename attribute so it's much easier to grasp its role
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6674
diff
changeset
|
617 |
sources[uri] = source.public_config |
0 | 618 |
return sources |
619 |
||
620 |
def properties(self): |
|
6256
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
621 |
"""Return a result set containing system wide properties. |
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
622 |
|
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
623 |
This is a public method, not requiring a session id. |
da77d3f95079
[repo] docstring cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6211
diff
changeset
|
624 |
""" |
8433
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8393
diff
changeset
|
625 |
with self.internal_session() as session: |
5747
d6ac0cd30fde
[rset] do not filter rsets with __getstate__, ensure whatever flies with pyro has no .req attribute, also set the ._rqlst to None since it will be reconstructed later on demand
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5711
diff
changeset
|
626 |
# don't use session.execute, we don't want rset.req set |
d6ac0cd30fde
[rset] do not filter rsets with __getstate__, ensure whatever flies with pyro has no .req attribute, also set the ._rqlst to None since it will be reconstructed later on demand
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5711
diff
changeset
|
627 |
return self.querier.execute(session, 'Any K,V WHERE P is CWProperty,' |
d6ac0cd30fde
[rset] do not filter rsets with __getstate__, ensure whatever flies with pyro has no .req attribute, also set the ._rqlst to None since it will be reconstructed later on demand
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5711
diff
changeset
|
628 |
'P pkey K, P value V, NOT P for_user U', |
d6ac0cd30fde
[rset] do not filter rsets with __getstate__, ensure whatever flies with pyro has no .req attribute, also set the ._rqlst to None since it will be reconstructed later on demand
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5711
diff
changeset
|
629 |
build_descr=False) |
0 | 630 |
|
5032 | 631 |
# XXX protect this method: anonymous should be allowed and registration |
632 |
# plugged |
|
1372
d4264cd876e1
register_user can now also set an email
Florent <florent@secondweb.fr>
parents:
1320
diff
changeset
|
633 |
def register_user(self, login, password, email=None, **kwargs): |
0 | 634 |
"""check a user with the given login exists, if not create it with the |
635 |
given password. This method is designed to be used for anonymous |
|
636 |
registration on public web site. |
|
637 |
""" |
|
8433
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8393
diff
changeset
|
638 |
with self.internal_session() as session: |
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8393
diff
changeset
|
639 |
# for consistency, keep same error as unique check hook (although not required) |
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8393
diff
changeset
|
640 |
errmsg = session._('the value "%s" is already used, use another one') |
5073
a9697325cffa
[repo] don't need rset description on those queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5072
diff
changeset
|
641 |
if (session.execute('CWUser X WHERE X login %(login)s', {'login': login}, |
a9697325cffa
[repo] don't need rset description on those queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5072
diff
changeset
|
642 |
build_descr=False) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1372
diff
changeset
|
643 |
or session.execute('CWUser X WHERE X use_email C, C address %(login)s', |
5073
a9697325cffa
[repo] don't need rset description on those queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5072
diff
changeset
|
644 |
{'login': login}, build_descr=False)): |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4984
diff
changeset
|
645 |
qname = role_name('login', 'subject') |
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4984
diff
changeset
|
646 |
raise ValidationError(None, {qname: errmsg % login}) |
0 | 647 |
# we have to create the user |
5072
072ae171aeb0
[cleanup] style fixes, add nodes, 0.2 cents refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5068
diff
changeset
|
648 |
user = self.vreg['etypes'].etype_class('CWUser')(session) |
0 | 649 |
if isinstance(password, unicode): |
650 |
# password should *always* be utf8 encoded |
|
651 |
password = password.encode('UTF8') |
|
652 |
kwargs['login'] = login |
|
653 |
kwargs['upassword'] = password |
|
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
654 |
self.glob_add_entity(session, EditedEntity(user, **kwargs)) |
0 | 655 |
session.execute('SET X in_group G WHERE X eid %(x)s, G name "users"', |
656 |
{'x': user.eid}) |
|
1372
d4264cd876e1
register_user can now also set an email
Florent <florent@secondweb.fr>
parents:
1320
diff
changeset
|
657 |
if email or '@' in login: |
d4264cd876e1
register_user can now also set an email
Florent <florent@secondweb.fr>
parents:
1320
diff
changeset
|
658 |
d = {'login': login, 'email': email or login} |
5073
a9697325cffa
[repo] don't need rset description on those queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5072
diff
changeset
|
659 |
if session.execute('EmailAddress X WHERE X address %(email)s', d, |
a9697325cffa
[repo] don't need rset description on those queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5072
diff
changeset
|
660 |
build_descr=False): |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4984
diff
changeset
|
661 |
qname = role_name('address', 'subject') |
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4984
diff
changeset
|
662 |
raise ValidationError(None, {qname: errmsg % d['email']}) |
1372
d4264cd876e1
register_user can now also set an email
Florent <florent@secondweb.fr>
parents:
1320
diff
changeset
|
663 |
session.execute('INSERT EmailAddress X: X address %(email)s, ' |
5032 | 664 |
'U primary_email X, U use_email X ' |
5073
a9697325cffa
[repo] don't need rset description on those queries
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5072
diff
changeset
|
665 |
'WHERE U login %(login)s', d, build_descr=False) |
0 | 666 |
session.commit() |
594
76218d42d21f
return success or not on creation of user
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
479
diff
changeset
|
667 |
return True |
1482 | 668 |
|
6390
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
669 |
def find_users(self, fetch_attrs, **query_attrs): |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
670 |
"""yield user attributes for cwusers matching the given query_attrs |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
671 |
(the result set cannot survive this method call) |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
672 |
|
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
673 |
This can be used by low-privileges account (anonymous comes to |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
674 |
mind). |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
675 |
|
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
676 |
`fetch_attrs`: tuple of attributes to be fetched |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
677 |
`query_attrs`: dict of attr/values to restrict the query |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
678 |
""" |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
679 |
assert query_attrs |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
680 |
if not hasattr(self, '_cwuser_attrs'): |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
681 |
cwuser = self.schema['CWUser'] |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
682 |
self._cwuser_attrs = set(str(rschema) |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
683 |
for rschema, _eschema in cwuser.attribute_definitions() |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
684 |
if not rschema.meta) |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
685 |
cwuserattrs = self._cwuser_attrs |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
686 |
for k in chain(fetch_attrs, query_attrs): |
6390
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
687 |
if k not in cwuserattrs: |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
688 |
raise Exception('bad input for find_user') |
8433
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8393
diff
changeset
|
689 |
with self.internal_session() as session: |
6390
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
690 |
varmaker = rqlvar_maker() |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
691 |
vars = [(attr, varmaker.next()) for attr in fetch_attrs] |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
692 |
rql = 'Any %s WHERE X is CWUser, ' % ','.join(var[1] for var in vars) |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
693 |
rql += ','.join('X %s %s' % (var[0], var[1]) for var in vars) + ',' |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
694 |
rset = session.execute(rql + ','.join('X %s %%(%s)s' % (attr, attr) |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8695
diff
changeset
|
695 |
for attr in query_attrs), |
6390
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
696 |
query_attrs) |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
697 |
return rset.rows |
3766853656d7
[repo] add a find_users method for under-privileged accounts
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6368
diff
changeset
|
698 |
|
3647
2941f4a0aab9
refactor repo authentication to allow pluggable authentifier to login with something else than a password
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3629
diff
changeset
|
699 |
def connect(self, login, **kwargs): |
0 | 700 |
"""open a connection for a given user |
701 |
||
702 |
raise `AuthenticationError` if the authentication failed |
|
703 |
raise `ConnectionError` if we can't open a connection |
|
704 |
""" |
|
8538
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8537
diff
changeset
|
705 |
cnxprops = kwargs.pop('cnxprops', None) |
0 | 706 |
# use an internal connection |
8433
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8393
diff
changeset
|
707 |
with self.internal_session() as session: |
ff9d6d269877
[server/session,repo] turn InternalSession, hence repo.internal_session, into a context manager (closes #2393651)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8393
diff
changeset
|
708 |
# try to get a user object |
3647
2941f4a0aab9
refactor repo authentication to allow pluggable authentifier to login with something else than a password
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3629
diff
changeset
|
709 |
user = self.authenticate_user(session, login, **kwargs) |
0 | 710 |
session = Session(user, self, cnxprops) |
9007
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
711 |
if threading.currentThread() in self._pyro_sessions: |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
712 |
# assume no pyro client does one get_repository followed by |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
713 |
# multiple repo.connect |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
714 |
assert self._pyro_sessions[threading.currentThread()] == None |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
715 |
self.debug('record session %s', session) |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
716 |
self._pyro_sessions[threading.currentThread()] = session |
3379
9192ba07890d
use .cw_rset instead of rset on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
717 |
user._cw = user.cw_rset.req = session |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
718 |
user.cw_clear_relation_cache() |
0 | 719 |
self._sessions[session.id] = session |
5638
cea831403e72
log the user name on session opening for easier debugging
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5603
diff
changeset
|
720 |
self.info('opened session %s for user %s', session.id, login) |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2822
diff
changeset
|
721 |
self.hm.call_hooks('session_open', session) |
0 | 722 |
# commit session at this point in case write operation has been done |
723 |
# during `session_open` hooks |
|
724 |
session.commit() |
|
725 |
return session.id |
|
726 |
||
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
727 |
def execute(self, sessionid, rqlstring, args=None, build_descr=True, |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
728 |
txid=None): |
0 | 729 |
"""execute a RQL query |
730 |
||
731 |
* rqlstring should be an unicode string or a plain ascii string |
|
732 |
* args the optional parameters used in the query |
|
733 |
* build_descr is a flag indicating if the description should be |
|
734 |
built on select queries |
|
735 |
""" |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
736 |
session = self._get_session(sessionid, setcnxset=True, txid=txid) |
0 | 737 |
try: |
738 |
try: |
|
5747
d6ac0cd30fde
[rset] do not filter rsets with __getstate__, ensure whatever flies with pyro has no .req attribute, also set the ._rqlst to None since it will be reconstructed later on demand
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5711
diff
changeset
|
739 |
rset = self.querier.execute(session, rqlstring, args, |
0 | 740 |
build_descr) |
5747
d6ac0cd30fde
[rset] do not filter rsets with __getstate__, ensure whatever flies with pyro has no .req attribute, also set the ._rqlst to None since it will be reconstructed later on demand
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5711
diff
changeset
|
741 |
# NOTE: the web front will (re)build it when needed |
d6ac0cd30fde
[rset] do not filter rsets with __getstate__, ensure whatever flies with pyro has no .req attribute, also set the ._rqlst to None since it will be reconstructed later on demand
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5711
diff
changeset
|
742 |
# e.g in facets |
d6ac0cd30fde
[rset] do not filter rsets with __getstate__, ensure whatever flies with pyro has no .req attribute, also set the ._rqlst to None since it will be reconstructed later on demand
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5711
diff
changeset
|
743 |
# Zeroed to avoid useless overhead with pyro |
d6ac0cd30fde
[rset] do not filter rsets with __getstate__, ensure whatever flies with pyro has no .req attribute, also set the ._rqlst to None since it will be reconstructed later on demand
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5711
diff
changeset
|
744 |
rset._rqlst = None |
d6ac0cd30fde
[rset] do not filter rsets with __getstate__, ensure whatever flies with pyro has no .req attribute, also set the ._rqlst to None since it will be reconstructed later on demand
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5711
diff
changeset
|
745 |
return rset |
9184
b982e88e4836
[repo] normalize ValidationError on edited entity (closes #2509729)
David Douard <david.douard@logilab.fr>
parents:
9171
diff
changeset
|
746 |
except (ValidationError, Unauthorized, RQLSyntaxError): |
0 | 747 |
raise |
7616
8837e4733888
[repository] catch Exception instead of everything
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7573
diff
changeset
|
748 |
except Exception: |
0 | 749 |
# FIXME: check error to catch internal errors |
5167
529861a73ec8
log RQL query in case of unexpected failure (priceless when porting to new database)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5115
diff
changeset
|
750 |
self.exception('unexpected error while executing %s with %s', rqlstring, args) |
0 | 751 |
raise |
752 |
finally: |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
753 |
session.free_cnxset() |
1482 | 754 |
|
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
755 |
def describe(self, sessionid, eid, txid=None): |
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
756 |
"""return a tuple `(type, physical source uri, extid, actual source |
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
757 |
uri)` for the entity of the given `eid` |
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
758 |
""" |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
759 |
session = self._get_session(sessionid, setcnxset=True, txid=txid) |
0 | 760 |
try: |
761 |
return self.type_and_source_from_eid(eid, session) |
|
762 |
finally: |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
763 |
session.free_cnxset() |
0 | 764 |
|
765 |
def check_session(self, sessionid): |
|
6012
d56fd78006cd
[session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
766 |
"""raise `BadConnectionId` if the connection is no more valid, else |
d56fd78006cd
[session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
767 |
return its latest activity timestamp. |
d56fd78006cd
[session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
768 |
""" |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
769 |
return self._get_session(sessionid, setcnxset=False).timestamp |
0 | 770 |
|
6013
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6012
diff
changeset
|
771 |
def get_shared_data(self, sessionid, key, default=None, pop=False, txdata=False): |
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6012
diff
changeset
|
772 |
"""return value associated to key in the session's data dictionary or |
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6012
diff
changeset
|
773 |
session's transaction's data if `txdata` is true. |
0 | 774 |
|
8238
087bb529035c
[spelling] fix dictionnary -> dictionary typo
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8224
diff
changeset
|
775 |
If pop is True, value will be removed from the dictionary. |
6013
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6012
diff
changeset
|
776 |
|
8238
087bb529035c
[spelling] fix dictionnary -> dictionary typo
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8224
diff
changeset
|
777 |
If key isn't defined in the dictionary, value specified by the |
6013
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6012
diff
changeset
|
778 |
`default` argument will be returned. |
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6012
diff
changeset
|
779 |
""" |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
780 |
session = self._get_session(sessionid, setcnxset=False) |
6013
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6012
diff
changeset
|
781 |
return session.get_shared_data(key, default, pop, txdata) |
0 | 782 |
|
6013
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6012
diff
changeset
|
783 |
def set_shared_data(self, sessionid, key, value, txdata=False): |
0 | 784 |
"""set value associated to `key` in shared data |
785 |
||
6013
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6012
diff
changeset
|
786 |
if `txdata` is true, the value will be added to the repository session's |
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6012
diff
changeset
|
787 |
transaction's data which are cleared on commit/rollback of the current |
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6012
diff
changeset
|
788 |
transaction. |
0 | 789 |
""" |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
790 |
session = self._get_session(sessionid, setcnxset=False) |
6013
8ca424bc393b
[dbapi] cleanup shared data api: let access to transaction from dbapi, we can write it after all... Also, querydata is better named txdata
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6012
diff
changeset
|
791 |
session.set_shared_data(key, value, txdata) |
0 | 792 |
|
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
793 |
def commit(self, sessionid, txid=None): |
0 | 794 |
"""commit transaction for the session with the given id""" |
795 |
self.debug('begin commit for session %s', sessionid) |
|
796 |
try: |
|
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
797 |
session = self._get_session(sessionid) |
9020
cb87e831c183
rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9008
diff
changeset
|
798 |
session.set_cnx(txid) |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
799 |
return session.commit() |
1482 | 800 |
except (ValidationError, Unauthorized): |
0 | 801 |
raise |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
802 |
except Exception: |
0 | 803 |
self.exception('unexpected error') |
804 |
raise |
|
1482 | 805 |
|
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
806 |
def rollback(self, sessionid, txid=None): |
0 | 807 |
"""commit transaction for the session with the given id""" |
808 |
self.debug('begin rollback for session %s', sessionid) |
|
809 |
try: |
|
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
810 |
session = self._get_session(sessionid) |
9020
cb87e831c183
rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9008
diff
changeset
|
811 |
session.set_cnx(txid) |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
812 |
session.rollback() |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
813 |
except Exception: |
0 | 814 |
self.exception('unexpected error') |
815 |
raise |
|
816 |
||
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
817 |
def close(self, sessionid, txid=None, checkshuttingdown=True): |
0 | 818 |
"""close the session with the given id""" |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
819 |
session = self._get_session(sessionid, setcnxset=True, txid=txid, |
1939
67e7379edd96
#343379: disturbing message on upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1883
diff
changeset
|
820 |
checkshuttingdown=checkshuttingdown) |
9267
24d9b86dfa54
spelling: rollbacked -> rolled back
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9226
diff
changeset
|
821 |
# operation uncommited before close are rolled back before hook is called |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
822 |
session.rollback(free_cnxset=False) |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2822
diff
changeset
|
823 |
self.hm.call_hooks('session_close', session) |
0 | 824 |
# commit session at this point in case write operation has been done |
825 |
# during `session_close` hooks |
|
826 |
session.commit() |
|
827 |
session.close() |
|
9008
e0aa7cf8abf8
repository: make tests pass again
Julien Cristau <julien.cristau@logilab.fr>
parents:
9007
diff
changeset
|
828 |
if threading.currentThread() in self._pyro_sessions: |
e0aa7cf8abf8
repository: make tests pass again
Julien Cristau <julien.cristau@logilab.fr>
parents:
9007
diff
changeset
|
829 |
self._pyro_sessions[threading.currentThread()] = None |
0 | 830 |
del self._sessions[sessionid] |
831 |
self.info('closed session %s for user %s', sessionid, session.user.login) |
|
1482 | 832 |
|
9033
614bf73cc126
[service] drop the asynchronous execution possibility
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9020
diff
changeset
|
833 |
def call_service(self, sessionid, regid, **kwargs): |
8268
c9babe49c1c1
[repository] implement a generic way to call repo-side services; closes #2203418
Florent Cayré <florent.cayre@logilab.fr>
parents:
8239
diff
changeset
|
834 |
""" |
c9babe49c1c1
[repository] implement a generic way to call repo-side services; closes #2203418
Florent Cayré <florent.cayre@logilab.fr>
parents:
8239
diff
changeset
|
835 |
See :class:`cubicweb.dbapi.Connection.call_service` |
c9babe49c1c1
[repository] implement a generic way to call repo-side services; closes #2203418
Florent Cayré <florent.cayre@logilab.fr>
parents:
8239
diff
changeset
|
836 |
and :class:`cubicweb.server.Service` |
c9babe49c1c1
[repository] implement a generic way to call repo-side services; closes #2203418
Florent Cayré <florent.cayre@logilab.fr>
parents:
8239
diff
changeset
|
837 |
""" |
9093
e2f88df79efd
[connection] move call_service on Connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9035
diff
changeset
|
838 |
# XXX lack a txid |
8837
f7f4238ffe3c
[service] extract session retrieval from "task" closure
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8699
diff
changeset
|
839 |
session = self._get_session(sessionid) |
9093
e2f88df79efd
[connection] move call_service on Connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9035
diff
changeset
|
840 |
return session._cnx.call_service(regid, **kwargs) |
8268
c9babe49c1c1
[repository] implement a generic way to call repo-side services; closes #2203418
Florent Cayré <florent.cayre@logilab.fr>
parents:
8239
diff
changeset
|
841 |
|
0 | 842 |
def user_info(self, sessionid, props=None): |
843 |
"""this method should be used by client to: |
|
844 |
* check session id validity |
|
845 |
* update user information on each user's request (i.e. groups and |
|
846 |
custom properties) |
|
847 |
""" |
|
8538
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8537
diff
changeset
|
848 |
user = self._get_session(sessionid, setcnxset=False).user |
0 | 849 |
return user.eid, user.login, user.groups, user.properties |
1482 | 850 |
|
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
851 |
def undoable_transactions(self, sessionid, ueid=None, txid=None, |
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
852 |
**actionfilters): |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
853 |
"""See :class:`cubicweb.dbapi.Connection.undoable_transactions`""" |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
854 |
session = self._get_session(sessionid, setcnxset=True, txid=txid) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
855 |
try: |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
856 |
return self.system_source.undoable_transactions(session, ueid, |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
857 |
**actionfilters) |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
858 |
finally: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
859 |
session.free_cnxset() |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
860 |
|
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
861 |
def transaction_info(self, sessionid, txuuid, txid=None): |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
862 |
"""See :class:`cubicweb.dbapi.Connection.transaction_info`""" |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
863 |
session = self._get_session(sessionid, setcnxset=True, txid=txid) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
864 |
try: |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
865 |
return self.system_source.tx_info(session, txuuid) |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
866 |
finally: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
867 |
session.free_cnxset() |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
868 |
|
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
869 |
def transaction_actions(self, sessionid, txuuid, public=True, txid=None): |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
870 |
"""See :class:`cubicweb.dbapi.Connection.transaction_actions`""" |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
871 |
session = self._get_session(sessionid, setcnxset=True, txid=txid) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
872 |
try: |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
873 |
return self.system_source.tx_actions(session, txuuid, public) |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
874 |
finally: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
875 |
session.free_cnxset() |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
876 |
|
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
877 |
def undo_transaction(self, sessionid, txuuid, txid=None): |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
878 |
"""See :class:`cubicweb.dbapi.Connection.undo_transaction`""" |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
879 |
session = self._get_session(sessionid, setcnxset=True, txid=txid) |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
880 |
try: |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
881 |
return self.system_source.undo_transaction(session, txuuid) |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
882 |
finally: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
883 |
session.free_cnxset() |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
884 |
|
0 | 885 |
# session handling ######################################################## |
1482 | 886 |
|
0 | 887 |
def close_sessions(self): |
888 |
"""close every opened sessions""" |
|
8699
864ffd247d70
[towards py3k] fix bug introduced by 0bb18407c053
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8696
diff
changeset
|
889 |
for sessionid in list(self._sessions): |
0 | 890 |
try: |
1939
67e7379edd96
#343379: disturbing message on upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1883
diff
changeset
|
891 |
self.close(sessionid, checkshuttingdown=False) |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7782
diff
changeset
|
892 |
except Exception: # XXX BaseException? |
0 | 893 |
self.exception('error while closing session %s' % sessionid) |
894 |
||
895 |
def clean_sessions(self): |
|
896 |
"""close sessions not used since an amount of time specified in the |
|
897 |
configuration |
|
898 |
""" |
|
6012
d56fd78006cd
[session] cleanup session-time / cleanup-session-time...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
899 |
mintime = time() - self.cleanup_session_time |
0 | 900 |
self.debug('cleaning session unused since %s', |
901 |
strftime('%T', localtime(mintime))) |
|
902 |
nbclosed = 0 |
|
8890
57ffd0e0643d
[clean_session] revert itervalues usage from 0bb18407c053
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8881
diff
changeset
|
903 |
for session in self._sessions.values(): |
0 | 904 |
if session.timestamp < mintime: |
905 |
self.close(session.id) |
|
906 |
nbclosed += 1 |
|
907 |
return nbclosed |
|
1482 | 908 |
|
9404
3e3e9b37e177
fix version number: we still target cw 3.19
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9402
diff
changeset
|
909 |
@deprecated("[3.19] use internal_cnx now\n" |
9113
af6efc15fc90
[repository] add an ``internal_cnx`` method to replace ``internal_session``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
910 |
"(Beware that integrity hook are now enabled by default)") |
7706
359bc86d2827
[session] safe internal sessions don't deactivate integrity hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7698
diff
changeset
|
911 |
def internal_session(self, cnxprops=None, safe=False): |
359bc86d2827
[session] safe internal sessions don't deactivate integrity hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7698
diff
changeset
|
912 |
"""return a dbapi like connection/cursor using internal user which have |
359bc86d2827
[session] safe internal sessions don't deactivate integrity hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7698
diff
changeset
|
913 |
every rights on the repository. The `safe` argument is a boolean flag |
359bc86d2827
[session] safe internal sessions don't deactivate integrity hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7698
diff
changeset
|
914 |
telling if integrity hooks should be activated or not. |
359bc86d2827
[session] safe internal sessions don't deactivate integrity hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7698
diff
changeset
|
915 |
|
9127
aff75b69db92
[repository] drop safe attribute on ``internal_cnx``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9113
diff
changeset
|
916 |
/!\ the safe argument is False by default. |
aff75b69db92
[repository] drop safe attribute on ``internal_cnx``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9113
diff
changeset
|
917 |
|
7706
359bc86d2827
[session] safe internal sessions don't deactivate integrity hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7698
diff
changeset
|
918 |
*YOU HAVE TO* commit/rollback or close (rollback implicitly) the |
359bc86d2827
[session] safe internal sessions don't deactivate integrity hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7698
diff
changeset
|
919 |
session once the job's done, else you'll leak connections set up to the |
359bc86d2827
[session] safe internal sessions don't deactivate integrity hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7698
diff
changeset
|
920 |
time where no one is available, causing irremediable freeze... |
0 | 921 |
""" |
7706
359bc86d2827
[session] safe internal sessions don't deactivate integrity hooks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7698
diff
changeset
|
922 |
session = InternalSession(self, cnxprops, safe) |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
923 |
session.set_cnxset() |
0 | 924 |
return session |
1482 | 925 |
|
9113
af6efc15fc90
[repository] add an ``internal_cnx`` method to replace ``internal_session``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
926 |
@contextmanager |
9127
aff75b69db92
[repository] drop safe attribute on ``internal_cnx``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9113
diff
changeset
|
927 |
def internal_cnx(self): |
9113
af6efc15fc90
[repository] add an ``internal_cnx`` method to replace ``internal_session``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
928 |
"""return a Connection using internal user which have |
9127
aff75b69db92
[repository] drop safe attribute on ``internal_cnx``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9113
diff
changeset
|
929 |
every rights on the repository. The `safe` argument is dropped. all |
aff75b69db92
[repository] drop safe attribute on ``internal_cnx``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9113
diff
changeset
|
930 |
hook are enabled by default. |
9113
af6efc15fc90
[repository] add an ``internal_cnx`` method to replace ``internal_session``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
931 |
|
9127
aff75b69db92
[repository] drop safe attribute on ``internal_cnx``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9113
diff
changeset
|
932 |
/!\ IN OPPOSITE OF THE OLDER INTERNAL_SESSION, |
aff75b69db92
[repository] drop safe attribute on ``internal_cnx``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9113
diff
changeset
|
933 |
/!\ INTERNAL CONNECTION HAVE ALL HOOKS ENABLED. |
9113
af6efc15fc90
[repository] add an ``internal_cnx`` method to replace ``internal_session``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
934 |
|
af6efc15fc90
[repository] add an ``internal_cnx`` method to replace ``internal_session``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
935 |
This is to be used a context manager. |
af6efc15fc90
[repository] add an ``internal_cnx`` method to replace ``internal_session``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
936 |
""" |
9127
aff75b69db92
[repository] drop safe attribute on ``internal_cnx``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9113
diff
changeset
|
937 |
with InternalSession(self) as session: |
9113
af6efc15fc90
[repository] add an ``internal_cnx`` method to replace ``internal_session``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
938 |
with session.new_cnx() as cnx: |
af6efc15fc90
[repository] add an ``internal_cnx`` method to replace ``internal_session``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
939 |
yield cnx |
af6efc15fc90
[repository] add an ``internal_cnx`` method to replace ``internal_session``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
940 |
|
af6efc15fc90
[repository] add an ``internal_cnx`` method to replace ``internal_session``
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9105
diff
changeset
|
941 |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
942 |
def _get_session(self, sessionid, setcnxset=False, txid=None, |
5813
0b250d72fcfa
[transaction w/ separated web/repo processes] the dbapi should explicitly specify a transaction id to avoid confusion when web server / repository run in separated processes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5808
diff
changeset
|
943 |
checkshuttingdown=True): |
9272
68744f5154c4
[server] fix a number of typos, mostly in docstrings
Julien Cristau <julien.cristau@logilab.fr>
parents:
9267
diff
changeset
|
944 |
"""return the session associated with the given session identifier""" |
5906
d40ced753291
[repository] fix so that when repository is shutting down, internal session in transaction are interrupted
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5813
diff
changeset
|
945 |
if checkshuttingdown and self.shutting_down: |
7573
c8f8762c986d
[repo, looping task] raise a custom exception when repository is shuting down, avoid looping task to be restarted in such case. Closes #1021276
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7550
diff
changeset
|
946 |
raise ShuttingDown('Repository is shutting down') |
0 | 947 |
try: |
948 |
session = self._sessions[sessionid] |
|
949 |
except KeyError: |
|
950 |
raise BadConnectionId('No such session %s' % sessionid) |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
951 |
if setcnxset: |
9020
cb87e831c183
rename server.session.transaction into server.session.connection
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
9008
diff
changeset
|
952 |
session.set_cnx(txid) # must be done before set_cnxset |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
953 |
session.set_cnxset() |
0 | 954 |
return session |
955 |
||
956 |
# data sources handling ################################################### |
|
957 |
# * correspondance between eid and (type, source) |
|
958 |
# * correspondance between eid and local id (i.e. specific to a given source) |
|
1482 | 959 |
|
0 | 960 |
def type_and_source_from_eid(self, eid, session=None): |
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
961 |
"""return a tuple `(type, physical source uri, extid, actual source |
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
962 |
uri)` for the entity of the given `eid` |
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
963 |
""" |
0 | 964 |
try: |
8748
f5027f8d2478
drop typed_eid() in favour of int() (closes #2742462)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8699
diff
changeset
|
965 |
eid = int(eid) |
0 | 966 |
except ValueError: |
967 |
raise UnknownEid(eid) |
|
968 |
try: |
|
969 |
return self._type_source_cache[eid] |
|
970 |
except KeyError: |
|
971 |
if session is None: |
|
972 |
session = self.internal_session() |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
973 |
free_cnxset = True |
0 | 974 |
else: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
975 |
free_cnxset = False |
0 | 976 |
try: |
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
977 |
etype, uri, extid, auri = self.system_source.eid_type_source( |
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
978 |
session, eid) |
0 | 979 |
finally: |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
980 |
if free_cnxset: |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
981 |
session.free_cnxset() |
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
982 |
self._type_source_cache[eid] = (etype, uri, extid, auri) |
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
983 |
if uri != 'system': |
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
984 |
self._extid_cache[(extid, uri)] = eid |
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
985 |
return etype, uri, extid, auri |
0 | 986 |
|
987 |
def clear_caches(self, eids): |
|
988 |
etcache = self._type_source_cache |
|
989 |
extidcache = self._extid_cache |
|
990 |
rqlcache = self.querier._rql_cache |
|
991 |
for eid in eids: |
|
992 |
try: |
|
8748
f5027f8d2478
drop typed_eid() in favour of int() (closes #2742462)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8699
diff
changeset
|
993 |
etype, uri, extid, auri = etcache.pop(int(eid)) # may be a string in some cases |
8133
b0a70092946a
[repo cache] fix cache clearing for an eid: keys are now always a tuple
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8074
diff
changeset
|
994 |
rqlcache.pop( ('%s X WHERE X eid %s' % (etype, eid),), None) |
0 | 995 |
extidcache.pop((extid, uri), None) |
996 |
except KeyError: |
|
997 |
etype = None |
|
8133
b0a70092946a
[repo cache] fix cache clearing for an eid: keys are now always a tuple
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8074
diff
changeset
|
998 |
rqlcache.pop( ('Any X WHERE X eid %s' % eid,), None) |
0 | 999 |
for source in self.sources: |
1000 |
source.clear_eid_cache(eid, etype) |
|
1482 | 1001 |
|
0 | 1002 |
def type_from_eid(self, eid, session=None): |
1003 |
"""return the type of the entity with id <eid>""" |
|
1004 |
return self.type_and_source_from_eid(eid, session)[0] |
|
1482 | 1005 |
|
0 | 1006 |
def source_from_eid(self, eid, session=None): |
1007 |
"""return the source for the given entity's eid""" |
|
1008 |
return self.sources_by_uri[self.type_and_source_from_eid(eid, session)[1]] |
|
1482 | 1009 |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1010 |
def querier_cache_key(self, session, rql, args, eidkeys): |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1011 |
cachekey = [rql] |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1012 |
for key in sorted(eidkeys): |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1013 |
try: |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1014 |
etype = self.type_from_eid(args[key], session) |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1015 |
except KeyError: |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1016 |
raise QueryError('bad cache key %s (no value)' % key) |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1017 |
except TypeError: |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1018 |
raise QueryError('bad cache key %s (value: %r)' % ( |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1019 |
key, args[key])) |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1020 |
cachekey.append(etype) |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1021 |
# ensure eid is correctly typed in args |
8748
f5027f8d2478
drop typed_eid() in favour of int() (closes #2742462)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8699
diff
changeset
|
1022 |
args[key] = int(args[key]) |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1023 |
return tuple(cachekey) |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5115
diff
changeset
|
1024 |
|
0 | 1025 |
def eid2extid(self, source, eid, session=None): |
1026 |
"""get local id from an eid""" |
|
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
1027 |
etype, uri, extid, _ = self.type_and_source_from_eid(eid, session) |
0 | 1028 |
if source.uri != uri: |
1029 |
# eid not from the given source |
|
1030 |
raise UnknownEid(eid) |
|
1031 |
return extid |
|
1032 |
||
1954 | 1033 |
def extid2eid(self, source, extid, etype, session=None, insert=True, |
7708
45be3a9debe6
[datafeed] for datafeed source, we don't want commit in extid2eid but explicitly handled by the source. Also, we should use 'safe' internal session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7706
diff
changeset
|
1034 |
complete=True, commit=True, sourceparams=None): |
7399
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1035 |
"""Return eid from a local id. If the eid is a negative integer, that |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1036 |
means the entity is known but has been copied back to the system source |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1037 |
hence should be ignored. |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1038 |
|
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1039 |
If no record is found, ie the entity is not known yet: |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1040 |
|
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1041 |
1. an eid is attributed |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1042 |
|
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1043 |
2. the source's :meth:`before_entity_insertion` method is called to |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1044 |
build the entity instance |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1045 |
|
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1046 |
3. unless source's :attr:`should_call_hooks` tell otherwise, |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1047 |
'before_add_entity' hooks are called |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1048 |
|
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1049 |
4. record is added into the system source |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1050 |
|
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1051 |
5. the source's :meth:`after_entity_insertion` method is called to |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1052 |
complete building of the entity instance |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1053 |
|
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1054 |
6. unless source's :attr:`should_call_hooks` tell otherwise, |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1055 |
'before_add_entity' hooks are called |
972ed1843bd8
[multi-sources] support for moving an entity from an external source (closes #343818)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
1056 |
""" |
9448
3e7cad3967c5
[multi-sources-removal] Drop the "true" multi-sources planner
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9404
diff
changeset
|
1057 |
uri = 'system' |
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6953
diff
changeset
|
1058 |
cachekey = (extid, uri) |
0 | 1059 |
try: |
1060 |
return self._extid_cache[cachekey] |
|
1061 |
except KeyError: |
|
1062 |
pass |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1063 |
free_cnxset = False |
0 | 1064 |
if session is None: |
1065 |
session = self.internal_session() |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1066 |
free_cnxset = True |
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6953
diff
changeset
|
1067 |
eid = self.system_source.extid2eid(session, uri, extid) |
0 | 1068 |
if eid is not None: |
1069 |
self._extid_cache[cachekey] = eid |
|
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
1070 |
self._type_source_cache[eid] = (etype, uri, extid, source.uri) |
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1071 |
if free_cnxset: |
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1072 |
session.free_cnxset() |
0 | 1073 |
return eid |
1074 |
if not insert: |
|
1075 |
return |
|
1954 | 1076 |
# no link between extid and eid, create one using an internal session |
0 | 1077 |
# since the current session user may not have required permissions to |
1078 |
# do necessary stuff and we don't want to commit user session. |
|
1079 |
# |
|
450
5e14ea0e81c8
a note for later
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
341
diff
changeset
|
1080 |
# Moreover, even if session is already an internal session but is |
0 | 1081 |
# processing a commit, we have to use another one |
1082 |
if not session.is_internal_session: |
|
1083 |
session = self.internal_session() |
|
7398
26695dd703d8
[repository api] definitly kill usage of word 'pool' to refer to connections set used by a session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1084 |
free_cnxset = True |
0 | 1085 |
try: |
1086 |
eid = self.system_source.create_eid(session) |
|
1087 |
self._extid_cache[cachekey] = eid |
|
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
1088 |
self._type_source_cache[eid] = (etype, uri, extid, source.uri) |
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6953
diff
changeset
|
1089 |
entity = source.before_entity_insertion( |
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6953
diff
changeset
|
1090 |
session, extid, etype, eid, sourceparams) |
0 | 1091 |
if source.should_call_hooks: |
7950
99ae8c883ad3
[ms repository] when an exception is raised during extid2eid and no rollback is done, some manual cleanups have to be done (closes #1993420)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7931
diff
changeset
|
1092 |
# get back a copy of operation for later restore if necessary, |
99ae8c883ad3
[ms repository] when an exception is raised during extid2eid and no rollback is done, some manual cleanups have to be done (closes #1993420)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7931
diff
changeset
|
1093 |
# see below |
99ae8c883ad3
[ms repository] when an exception is raised during extid2eid and no rollback is done, some manual cleanups have to be done (closes #1993420)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7931
diff
changeset
|
1094 |
pending_operations = session.pending_operations[:] |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2822
diff
changeset
|
1095 |
self.hm.call_hooks('before_add_entity', session, entity=entity) |
7698
1c7411535c2d
[datafeed / fti] rather control a 'complete' parameter than setting empty attribute values
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7622
diff
changeset
|
1096 |
self.add_info(session, entity, source, extid, complete=complete) |
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6953
diff
changeset
|
1097 |
source.after_entity_insertion(session, extid, entity, sourceparams) |
0 | 1098 |
if source.should_call_hooks: |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2822
diff
changeset
|
1099 |
self.hm.call_hooks('after_add_entity', session, entity=entity) |
7716
c893150b2394
[repo ms] commit/rollback session if it has been created in the method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7708
diff
changeset
|
1100 |
if commit or free_cnxset: |
7708
45be3a9debe6
[datafeed] for datafeed source, we don't want commit in extid2eid but explicitly handled by the source. Also, we should use 'safe' internal session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7706
diff
changeset
|
1101 |
session.commit(free_cnxset) |
0 | 1102 |
return eid |
7708
45be3a9debe6
[datafeed] for datafeed source, we don't want commit in extid2eid but explicitly handled by the source. Also, we should use 'safe' internal session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7706
diff
changeset
|
1103 |
except Exception: |
7716
c893150b2394
[repo ms] commit/rollback session if it has been created in the method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7708
diff
changeset
|
1104 |
if commit or free_cnxset: |
7708
45be3a9debe6
[datafeed] for datafeed source, we don't want commit in extid2eid but explicitly handled by the source. Also, we should use 'safe' internal session
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7706
diff
changeset
|
1105 |
session.rollback(free_cnxset) |
7950
99ae8c883ad3
[ms repository] when an exception is raised during extid2eid and no rollback is done, some manual cleanups have to be done (closes #1993420)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7931
diff
changeset
|
1106 |
else: |
99ae8c883ad3
[ms repository] when an exception is raised during extid2eid and no rollback is done, some manual cleanups have to be done (closes #1993420)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7931
diff
changeset
|
1107 |
# XXX do some cleanup manually so that the transaction has a |
99ae8c883ad3
[ms repository] when an exception is raised during extid2eid and no rollback is done, some manual cleanups have to be done (closes #1993420)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7931
diff
changeset
|
1108 |
# chance to be commited, with simply this entity discarded |
99ae8c883ad3
[ms repository] when an exception is raised during extid2eid and no rollback is done, some manual cleanups have to be done (closes #1993420)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7931
diff
changeset
|
1109 |
self._extid_cache.pop(cachekey, None) |
99ae8c883ad3
[ms repository] when an exception is raised during extid2eid and no rollback is done, some manual cleanups have to be done (closes #1993420)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7931
diff
changeset
|
1110 |
self._type_source_cache.pop(eid, None) |
99ae8c883ad3
[ms repository] when an exception is raised during extid2eid and no rollback is done, some manual cleanups have to be done (closes #1993420)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7931
diff
changeset
|
1111 |
if 'entity' in locals(): |
99ae8c883ad3
[ms repository] when an exception is raised during extid2eid and no rollback is done, some manual cleanups have to be done (closes #1993420)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7931
diff
changeset
|
1112 |
hook.CleanupDeletedEidsCacheOp.get_instance(session).add_data(entity.eid) |
9451
c83a8ecb9bf5
[multi-sources-removal] Simplify repo.delete_info_multi arguments, uri is no more used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9450
diff
changeset
|
1113 |
self.system_source.delete_info_multi(session, [entity]) |
7950
99ae8c883ad3
[ms repository] when an exception is raised during extid2eid and no rollback is done, some manual cleanups have to be done (closes #1993420)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7931
diff
changeset
|
1114 |
if source.should_call_hooks: |
8773
21edcb0a5ed7
[session] rename `_threaddata` to `_tx`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8771
diff
changeset
|
1115 |
session._tx.pending_operations = pending_operations |
0 | 1116 |
raise |
1482 | 1117 |
|
0 | 1118 |
def add_info(self, session, entity, source, extid=None, complete=True): |
1119 |
"""add type and source info for an eid into the system table, |
|
1120 |
and index the entity with the full text index |
|
1121 |
""" |
|
1122 |
# begin by inserting eid/type/source/extid into the entities table |
|
6426
541659c39f6a
[hook/operation] nicer api to achieve same result as set_operation, as described in #1253630
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6390
diff
changeset
|
1123 |
hook.CleanupNewEidsCacheOp.get_instance(session).add_data(entity.eid) |
4806
4f12f59b1a13
[fti] refactor and fix full text indexation handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4756
diff
changeset
|
1124 |
self.system_source.add_info(session, entity, source, extid, complete) |
1482 | 1125 |
|
7884
35d2e2f4e10a
[repo] cleanup [_]delete_info prototype: extid argument isn't used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7823
diff
changeset
|
1126 |
def delete_info(self, session, entity, sourceuri, scleanup=None): |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1127 |
"""called by external source when some entity known by the system source |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1128 |
has been deleted in the external source |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1129 |
""" |
5067
adc2122eed03
[repo] more efficient eid cache operations handling based on set_operation; refactor
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5043
diff
changeset
|
1130 |
# mark eid as being deleted in session info and setup cache update |
adc2122eed03
[repo] more efficient eid cache operations handling based on set_operation; refactor
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5043
diff
changeset
|
1131 |
# operation |
6426
541659c39f6a
[hook/operation] nicer api to achieve same result as set_operation, as described in #1253630
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6390
diff
changeset
|
1132 |
hook.CleanupDeletedEidsCacheOp.get_instance(session).add_data(entity.eid) |
7884
35d2e2f4e10a
[repo] cleanup [_]delete_info prototype: extid argument isn't used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7823
diff
changeset
|
1133 |
self._delete_info(session, entity, sourceuri, scleanup) |
1482 | 1134 |
|
7884
35d2e2f4e10a
[repo] cleanup [_]delete_info prototype: extid argument isn't used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7823
diff
changeset
|
1135 |
def _delete_info(self, session, entity, sourceuri, scleanup=None): |
0 | 1136 |
"""delete system information on deletion of an entity: |
7884
35d2e2f4e10a
[repo] cleanup [_]delete_info prototype: extid argument isn't used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7823
diff
changeset
|
1137 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1138 |
* delete all remaining relations from/to this entity |
9450
af4b93bc38a5
[multi-sources-removal] Drop deleted_entities system table and entities.mtime column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9449
diff
changeset
|
1139 |
* call delete info on the system source |
7884
35d2e2f4e10a
[repo] cleanup [_]delete_info prototype: extid argument isn't used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7823
diff
changeset
|
1140 |
|
35d2e2f4e10a
[repo] cleanup [_]delete_info prototype: extid argument isn't used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7823
diff
changeset
|
1141 |
When scleanup is specified, it's expected to be the source's eid, in |
35d2e2f4e10a
[repo] cleanup [_]delete_info prototype: extid argument isn't used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7823
diff
changeset
|
1142 |
which case we'll specify the target's relation source so that this |
35d2e2f4e10a
[repo] cleanup [_]delete_info prototype: extid argument isn't used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7823
diff
changeset
|
1143 |
source is ignored. E.g. we want to delete relations stored locally, as |
35d2e2f4e10a
[repo] cleanup [_]delete_info prototype: extid argument isn't used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7823
diff
changeset
|
1144 |
the deletion information comes from the external source, it's its |
35d2e2f4e10a
[repo] cleanup [_]delete_info prototype: extid argument isn't used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7823
diff
changeset
|
1145 |
responsability to have cleaned-up its own relations. |
0 | 1146 |
""" |
2641
9c33d98a074e
R [schema hooks] big refactoring / reorganization for clearer code, a few fixes on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2631
diff
changeset
|
1147 |
pendingrtypes = session.transaction_data.get('pendingrtypes', ()) |
7887
42a0b7398d31
[repository] when deleting relations of a deleted external entity, we should skip non-crossable relation (closes #1973680)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7885
diff
changeset
|
1148 |
if scleanup is not None: |
42a0b7398d31
[repository] when deleting relations of a deleted external entity, we should skip non-crossable relation (closes #1973680)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7885
diff
changeset
|
1149 |
source = self.sources_by_eid[scleanup] |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1150 |
# delete remaining relations: if user can delete the entity, he can |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1151 |
# delete all its relations without security checking |
8562
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8539
diff
changeset
|
1152 |
with session.security_enabled(read=False, write=False): |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1153 |
eid = entity.eid |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1154 |
for rschema, _, role in entity.e_schema.relation_definitions(): |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1155 |
rtype = rschema.type |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1156 |
if rtype in schema.VIRTUAL_RTYPES or rtype in pendingrtypes: |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1157 |
continue |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4899
diff
changeset
|
1158 |
if role == 'subject': |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1159 |
# don't skip inlined relation so they are regularly |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1160 |
# deleted and so hooks are correctly called |
5072
072ae171aeb0
[cleanup] style fixes, add nodes, 0.2 cents refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5068
diff
changeset
|
1161 |
rql = 'DELETE X %s Y WHERE X eid %%(x)s' % rtype |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4834
diff
changeset
|
1162 |
else: |
5072
072ae171aeb0
[cleanup] style fixes, add nodes, 0.2 cents refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5068
diff
changeset
|
1163 |
rql = 'DELETE Y %s X WHERE X eid %%(x)s' % rtype |
6941
9ed02daa7dbb
[repo, ms] optimise external source deletion by using source's eid instead of name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
1164 |
if scleanup is not None: |
6626
5c20a005bddc
[pyro source] when cleaning relations of an external entity being cleaned up, only delete local relationsd
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6491
diff
changeset
|
1165 |
# source cleaning: only delete relations stored locally |
6941
9ed02daa7dbb
[repo, ms] optimise external source deletion by using source's eid instead of name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
1166 |
# (here, scleanup |
9ed02daa7dbb
[repo, ms] optimise external source deletion by using source's eid instead of name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
1167 |
rql += ', NOT (Y cw_source S, S eid %(seid)s)' |
6674
fd9c76196bf7
[repository] don't crash when cascading delete a relation, this may let the database in an inconsistent state anyway, so simply log the error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6664
diff
changeset
|
1168 |
try: |
6941
9ed02daa7dbb
[repo, ms] optimise external source deletion by using source's eid instead of name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
1169 |
session.execute(rql, {'x': eid, 'seid': scleanup}, |
6674
fd9c76196bf7
[repository] don't crash when cascading delete a relation, this may let the database in an inconsistent state anyway, so simply log the error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6664
diff
changeset
|
1170 |
build_descr=False) |
7616
8837e4733888
[repository] catch Exception instead of everything
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7573
diff
changeset
|
1171 |
except Exception: |
7885
9454b7ef5ae4
[ms, test] propagate exception in test mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7884
diff
changeset
|
1172 |
if self.config.mode == 'test': |
9454b7ef5ae4
[ms, test] propagate exception in test mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7884
diff
changeset
|
1173 |
raise |
6674
fd9c76196bf7
[repository] don't crash when cascading delete a relation, this may let the database in an inconsistent state anyway, so simply log the error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6664
diff
changeset
|
1174 |
self.exception('error while cascading delete for entity %s ' |
fd9c76196bf7
[repository] don't crash when cascading delete a relation, this may let the database in an inconsistent state anyway, so simply log the error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6664
diff
changeset
|
1175 |
'from %s. RQL: %s', entity, sourceuri, rql) |
9451
c83a8ecb9bf5
[multi-sources-removal] Simplify repo.delete_info_multi arguments, uri is no more used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9450
diff
changeset
|
1176 |
self.system_source.delete_info_multi(session, [entity]) |
0 | 1177 |
|
9451
c83a8ecb9bf5
[multi-sources-removal] Simplify repo.delete_info_multi arguments, uri is no more used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9450
diff
changeset
|
1178 |
def _delete_info_multi(self, session, entities, scleanup=None): |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1179 |
"""same as _delete_info but accepts a list of entities with |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1180 |
the same etype and belinging to the same source. |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1181 |
""" |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1182 |
pendingrtypes = session.transaction_data.get('pendingrtypes', ()) |
7887
42a0b7398d31
[repository] when deleting relations of a deleted external entity, we should skip non-crossable relation (closes #1973680)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7885
diff
changeset
|
1183 |
if scleanup is not None: |
42a0b7398d31
[repository] when deleting relations of a deleted external entity, we should skip non-crossable relation (closes #1973680)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7885
diff
changeset
|
1184 |
source = self.sources_by_eid[scleanup] |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1185 |
# delete remaining relations: if user can delete the entity, he can |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1186 |
# delete all its relations without security checking |
8562
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8539
diff
changeset
|
1187 |
with session.security_enabled(read=False, write=False): |
7895 | 1188 |
in_eids = ','.join([str(_e.eid) for _e in entities]) |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1189 |
for rschema, _, role in entities[0].e_schema.relation_definitions(): |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1190 |
rtype = rschema.type |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1191 |
if rtype in schema.VIRTUAL_RTYPES or rtype in pendingrtypes: |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1192 |
continue |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1193 |
if role == 'subject': |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1194 |
# don't skip inlined relation so they are regularly |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1195 |
# deleted and so hooks are correctly called |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1196 |
rql = 'DELETE X %s Y WHERE X eid IN (%s)' % (rtype, in_eids) |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1197 |
else: |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1198 |
rql = 'DELETE Y %s X WHERE X eid IN (%s)' % (rtype, in_eids) |
6941
9ed02daa7dbb
[repo, ms] optimise external source deletion by using source's eid instead of name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
1199 |
if scleanup is not None: |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1200 |
# source cleaning: only delete relations stored locally |
6941
9ed02daa7dbb
[repo, ms] optimise external source deletion by using source's eid instead of name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
1201 |
rql += ', NOT (Y cw_source S, S eid %(seid)s)' |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1202 |
try: |
6941
9ed02daa7dbb
[repo, ms] optimise external source deletion by using source's eid instead of name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6931
diff
changeset
|
1203 |
session.execute(rql, {'seid': scleanup}, build_descr=False) |
8051
41398fa1a90f
[rql, integrity] let ValidationError and Unauthorized pass during composite deletion (closes #2070042)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7950
diff
changeset
|
1204 |
except ValidationError: |
41398fa1a90f
[rql, integrity] let ValidationError and Unauthorized pass during composite deletion (closes #2070042)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7950
diff
changeset
|
1205 |
raise |
41398fa1a90f
[rql, integrity] let ValidationError and Unauthorized pass during composite deletion (closes #2070042)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7950
diff
changeset
|
1206 |
except Unauthorized: |
9451
c83a8ecb9bf5
[multi-sources-removal] Simplify repo.delete_info_multi arguments, uri is no more used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9450
diff
changeset
|
1207 |
self.exception('Unauthorized exception while cascading delete for entity %s. ' |
c83a8ecb9bf5
[multi-sources-removal] Simplify repo.delete_info_multi arguments, uri is no more used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9450
diff
changeset
|
1208 |
'RQL: %s.\nThis should not happen since security is disabled here.', |
c83a8ecb9bf5
[multi-sources-removal] Simplify repo.delete_info_multi arguments, uri is no more used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9450
diff
changeset
|
1209 |
entities, rql) |
8051
41398fa1a90f
[rql, integrity] let ValidationError and Unauthorized pass during composite deletion (closes #2070042)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7950
diff
changeset
|
1210 |
raise |
7616
8837e4733888
[repository] catch Exception instead of everything
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7573
diff
changeset
|
1211 |
except Exception: |
7885
9454b7ef5ae4
[ms, test] propagate exception in test mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7884
diff
changeset
|
1212 |
if self.config.mode == 'test': |
9454b7ef5ae4
[ms, test] propagate exception in test mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7884
diff
changeset
|
1213 |
raise |
9451
c83a8ecb9bf5
[multi-sources-removal] Simplify repo.delete_info_multi arguments, uri is no more used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9450
diff
changeset
|
1214 |
self.exception('error while cascading delete for entity %s. RQL: %s', |
c83a8ecb9bf5
[multi-sources-removal] Simplify repo.delete_info_multi arguments, uri is no more used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9450
diff
changeset
|
1215 |
entities, rql) |
c83a8ecb9bf5
[multi-sources-removal] Simplify repo.delete_info_multi arguments, uri is no more used
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9450
diff
changeset
|
1216 |
self.system_source.delete_info_multi(session, entities) |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1217 |
|
5068
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1218 |
def init_entity_caches(self, session, entity, source): |
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1219 |
"""add entity to session entities cache and repo's extid cache. |
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1220 |
Return entity's ext id if the source isn't the system source. |
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1221 |
""" |
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1222 |
session.set_entity_cache(entity) |
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1223 |
suri = source.uri |
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1224 |
if suri == 'system': |
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1225 |
extid = None |
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1226 |
else: |
9448
3e7cad3967c5
[multi-sources-removal] Drop the "true" multi-sources planner
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9404
diff
changeset
|
1227 |
suri = 'system' |
5068
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1228 |
extid = source.get_extid(entity) |
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1229 |
self._extid_cache[(str(extid), suri)] = entity.eid |
8900
010a59e12d89
use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8889
diff
changeset
|
1230 |
self._type_source_cache[entity.eid] = (entity.cw_etype, suri, extid, |
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7514
diff
changeset
|
1231 |
source.uri) |
5068
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1232 |
return extid |
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1233 |
|
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1234 |
def glob_add_entity(self, session, edited): |
0 | 1235 |
"""add an entity to the repository |
1482 | 1236 |
|
0 | 1237 |
the entity eid should originaly be None and a unique eid is assigned to |
1238 |
the entity instance |
|
1239 |
""" |
|
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1240 |
entity = edited.entity |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
1241 |
entity._cw_is_saved = False # entity has an eid but is not yet saved |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1242 |
# init edited_attributes before calling before_add_entity hooks |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1243 |
entity.cw_edited = edited |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1244 |
source = self.system_source |
5072
072ae171aeb0
[cleanup] style fixes, add nodes, 0.2 cents refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5068
diff
changeset
|
1245 |
# allocate an eid to the entity before calling hooks |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
1246 |
entity.eid = self.system_source.create_eid(session) |
5068
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1247 |
# set caches asap |
10c3422d7419
[repo] on add entity, set cache as soon as possible + fill type/source cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5067
diff
changeset
|
1248 |
extid = self.init_entity_caches(session, entity, source) |
2600
6cd6c5d11b45
[F repo debugging] log repo event on DBG_REPO debug level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
1249 |
if server.DEBUG & server.DBG_REPO: |
8900
010a59e12d89
use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8889
diff
changeset
|
1250 |
print 'ADD entity', self, entity.cw_etype, entity.eid, edited |
8456
c912d82f2166
[repository] drop unused argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8433
diff
changeset
|
1251 |
prefill_entity_caches(entity) |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1252 |
self.hm.call_hooks('before_add_entity', session, entity=entity) |
8547
f23ac525ddd1
[datafeed] properly call hooks for inlined relations on entity creation. Closes #2481156
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8456
diff
changeset
|
1253 |
relations = preprocess_inlined_relations(session, entity) |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1254 |
edited.set_defaults() |
4843
5f7363416765
fix hooks control method name + other litle cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
1255 |
if session.is_hook_category_activated('integrity'): |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1256 |
edited.check(creation=True) |
6211
e9d125fd1465
nicer error reporting for unique together constraints
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6189
diff
changeset
|
1257 |
try: |
e9d125fd1465
nicer error reporting for unique together constraints
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6189
diff
changeset
|
1258 |
source.add_entity(session, entity) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8694
diff
changeset
|
1259 |
except UniqueTogetherError as exc: |
6465
6401a9d0b5aa
[architecture] introduce adapter to ease transformation of errors before display to the end user. Use it for UniqueTogetherError first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6464
diff
changeset
|
1260 |
userhdlr = session.vreg['adapters'].select( |
6401a9d0b5aa
[architecture] introduce adapter to ease transformation of errors before display to the end user. Use it for UniqueTogetherError first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6464
diff
changeset
|
1261 |
'IUserFriendlyError', session, entity=entity, exc=exc) |
6401a9d0b5aa
[architecture] introduce adapter to ease transformation of errors before display to the end user. Use it for UniqueTogetherError first
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6464
diff
changeset
|
1262 |
userhdlr.raise_user_exception() |
0 | 1263 |
self.add_info(session, entity, source, extid, complete=False) |
6368
f907cc7f2875
[repo] properly mark object as saved once added to its source (code much probably gone during a merge...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6333
diff
changeset
|
1264 |
edited.saved = entity._cw_is_saved = True |
0 | 1265 |
# trigger after_add_entity after after_add_relation |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1266 |
self.hm.call_hooks('after_add_entity', session, entity=entity) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1267 |
# call hooks for inlined relations |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1268 |
for attr, value in relations: |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1269 |
self.hm.call_hooks('before_add_relation', session, |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1270 |
eidfrom=entity.eid, rtype=attr, eidto=value) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1271 |
self.hm.call_hooks('after_add_relation', session, |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1272 |
eidfrom=entity.eid, rtype=attr, eidto=value) |
0 | 1273 |
return entity.eid |
1482 | 1274 |
|
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1275 |
def glob_update_entity(self, session, edited): |
0 | 1276 |
"""replace an entity in the repository |
1277 |
the type and the eid of an entity must not be changed |
|
1278 |
""" |
|
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1279 |
entity = edited.entity |
2600
6cd6c5d11b45
[F repo debugging] log repo event on DBG_REPO debug level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
1280 |
if server.DEBUG & server.DBG_REPO: |
8900
010a59e12d89
use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8889
diff
changeset
|
1281 |
print 'UPDATE entity', entity.cw_etype, entity.eid, \ |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1282 |
entity.cw_attr_cache, edited |
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1283 |
hm = self.hm |
0 | 1284 |
eschema = entity.e_schema |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2641
diff
changeset
|
1285 |
session.set_entity_cache(entity) |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1286 |
orig_edited = getattr(entity, 'cw_edited', None) |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1287 |
entity.cw_edited = edited |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1288 |
source = self.system_source |
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1289 |
try: |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1290 |
only_inline_rels, need_fti_update = True, False |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1291 |
relations = [] |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1292 |
for attr in list(edited): |
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1293 |
if attr == 'eid': |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1294 |
continue |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1295 |
rschema = eschema.subjrels[attr] |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1296 |
if rschema.final: |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1297 |
if getattr(eschema.rdef(attr), 'fulltextindexed', False): |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1298 |
need_fti_update = True |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1299 |
only_inline_rels = False |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1300 |
else: |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1301 |
# inlined relation |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1302 |
previous_value = entity.related(attr) or None |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1303 |
if previous_value is not None: |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1304 |
previous_value = previous_value[0][0] # got a result set |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1305 |
if previous_value == entity.cw_attr_cache[attr]: |
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1306 |
previous_value = None |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1307 |
else: |
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1308 |
hm.call_hooks('before_delete_relation', session, |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1309 |
eidfrom=entity.eid, rtype=attr, |
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1310 |
eidto=previous_value) |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1311 |
relations.append((attr, edited[attr], previous_value)) |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1312 |
# call hooks for inlined relations |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1313 |
for attr, value, _t in relations: |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1314 |
hm.call_hooks('before_add_relation', session, |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1315 |
eidfrom=entity.eid, rtype=attr, eidto=value) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1316 |
if not only_inline_rels: |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1317 |
hm.call_hooks('before_update_entity', session, entity=entity) |
5808
2de32c0c293b
[repo] call entity.check() once before_update hooks has been called, to let them a chance to transform data
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5749
diff
changeset
|
1318 |
if session.is_hook_category_activated('integrity'): |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1319 |
edited.check() |
6211
e9d125fd1465
nicer error reporting for unique together constraints
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6189
diff
changeset
|
1320 |
try: |
e9d125fd1465
nicer error reporting for unique together constraints
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6189
diff
changeset
|
1321 |
source.update_entity(session, entity) |
6225 | 1322 |
edited.saved = True |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8694
diff
changeset
|
1323 |
except UniqueTogetherError as exc: |
9226
653f1d4a1101
[repository] properly use IUserFriendlyError when UniqueTogetherError is raised during entity update. Closes #3096638
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9184
diff
changeset
|
1324 |
userhdlr = session.vreg['adapters'].select( |
653f1d4a1101
[repository] properly use IUserFriendlyError when UniqueTogetherError is raised during entity update. Closes #3096638
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9184
diff
changeset
|
1325 |
'IUserFriendlyError', session, entity=entity, exc=exc) |
653f1d4a1101
[repository] properly use IUserFriendlyError when UniqueTogetherError is raised during entity update. Closes #3096638
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9184
diff
changeset
|
1326 |
userhdlr.raise_user_exception() |
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1327 |
self.system_source.update_info(session, entity, need_fti_update) |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1328 |
if not only_inline_rels: |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1329 |
hm.call_hooks('after_update_entity', session, entity=entity) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1330 |
for attr, value, prevvalue in relations: |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1331 |
# if the relation is already cached, update existant cache |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1332 |
relcache = entity.cw_relation_cached(attr, 'subject') |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1333 |
if prevvalue is not None: |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1334 |
hm.call_hooks('after_delete_relation', session, |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1335 |
eidfrom=entity.eid, rtype=attr, eidto=prevvalue) |
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1336 |
if relcache is not None: |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1337 |
session.update_rel_cache_del(entity.eid, attr, prevvalue) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1338 |
del_existing_rel_if_needed(session, entity.eid, attr, value) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1339 |
if relcache is not None: |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1340 |
session.update_rel_cache_add(entity.eid, attr, value) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1341 |
else: |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1342 |
entity.cw_set_relation_cache(attr, 'subject', |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1343 |
session.eid_rset(value)) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1344 |
hm.call_hooks('after_add_relation', session, |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1345 |
eidfrom=entity.eid, rtype=attr, eidto=value) |
5115
2e43ef618d14
[repository] forbid usage of set_attributes() in before_add_entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5093
diff
changeset
|
1346 |
finally: |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1347 |
if orig_edited is not None: |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6139
diff
changeset
|
1348 |
entity.cw_edited = orig_edited |
0 | 1349 |
|
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1350 |
|
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1351 |
def glob_delete_entities(self, session, eids): |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1352 |
"""delete a list of entities and all related entities from the repository""" |
7501
2983dd24494a
[repository] refactor/cleanup entity deletion methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1353 |
# mark eids as being deleted in session info and setup cache update |
2983dd24494a
[repository] refactor/cleanup entity deletion methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1354 |
# operation (register pending eids before actual deletion to avoid |
2983dd24494a
[repository] refactor/cleanup entity deletion methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1355 |
# multiple call to glob_delete_entities) |
2983dd24494a
[repository] refactor/cleanup entity deletion methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1356 |
op = hook.CleanupDeletedEidsCacheOp.get_instance(session) |
7507
4c043afb104a
fix failures introduced by recent refactoring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7503
diff
changeset
|
1357 |
if not isinstance(eids, (set, frozenset)): |
4c043afb104a
fix failures introduced by recent refactoring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7503
diff
changeset
|
1358 |
warn('[3.13] eids should be given as a set', DeprecationWarning, |
4c043afb104a
fix failures introduced by recent refactoring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7503
diff
changeset
|
1359 |
stacklevel=2) |
4c043afb104a
fix failures introduced by recent refactoring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7503
diff
changeset
|
1360 |
eids = frozenset(eids) |
7501
2983dd24494a
[repository] refactor/cleanup entity deletion methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1361 |
eids = eids - op._container |
2983dd24494a
[repository] refactor/cleanup entity deletion methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1362 |
op._container |= eids |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1363 |
data_by_etype = {} # values are [list of entities] |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1364 |
# |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1365 |
# WARNING: the way this dictionary is populated is heavily optimized |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1366 |
# and does not use setdefault on purpose. Unless a new release |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1367 |
# of the Python interpreter advertises large perf improvements |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1368 |
# in setdefault, this should not be changed without profiling. |
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1369 |
for eid in eids: |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1370 |
etype = self.type_from_eid(eid, session) |
7501
2983dd24494a
[repository] refactor/cleanup entity deletion methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1371 |
# XXX should cache entity's cw_metainformation |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1372 |
entity = session.entity_from_eid(eid, etype) |
7501
2983dd24494a
[repository] refactor/cleanup entity deletion methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1373 |
try: |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1374 |
data_by_etype[etype].append(entity) |
7501
2983dd24494a
[repository] refactor/cleanup entity deletion methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1375 |
except KeyError: |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1376 |
data_by_etype[etype] = [entity] |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1377 |
source = self.system_source |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1378 |
for etype, entities in data_by_etype.iteritems(): |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1379 |
if server.DEBUG & server.DBG_REPO: |
7501
2983dd24494a
[repository] refactor/cleanup entity deletion methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1380 |
print 'DELETE entities', etype, [entity.eid for entity in entities] |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1381 |
self.hm.call_hooks('before_delete_entity', session, entities=entities) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1382 |
self._delete_info_multi(session, entities) |
6889
37668bf302f5
improve massive deletion performance
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6801
diff
changeset
|
1383 |
source.delete_entities(session, entities) |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1384 |
self.hm.call_hooks('after_delete_entity', session, entities=entities) |
7501
2983dd24494a
[repository] refactor/cleanup entity deletion methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7373
diff
changeset
|
1385 |
# don't clear cache here, it is done in a hook on commit |
1482 | 1386 |
|
0 | 1387 |
def glob_add_relation(self, session, subject, rtype, object): |
1388 |
"""add a relation to the repository""" |
|
7237
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7134
diff
changeset
|
1389 |
self.glob_add_relations(session, {rtype: [(subject, object)]}) |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7134
diff
changeset
|
1390 |
|
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7134
diff
changeset
|
1391 |
def glob_add_relations(self, session, relations): |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7134
diff
changeset
|
1392 |
"""add several relations to the repository |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7134
diff
changeset
|
1393 |
|
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7134
diff
changeset
|
1394 |
relations is a dictionary rtype: [(subj_eid, obj_eid), ...] |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7134
diff
changeset
|
1395 |
""" |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1396 |
source = self.system_source |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1397 |
relations_by_rtype = {} |
7513
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1398 |
subjects_by_types = {} |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1399 |
objects_by_types = {} |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1400 |
activintegrity = session.is_hook_category_activated('activeintegrity') |
7237
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7134
diff
changeset
|
1401 |
for rtype, eids_subj_obj in relations.iteritems(): |
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7134
diff
changeset
|
1402 |
if server.DEBUG & server.DBG_REPO: |
8548
eeabc752c32e
[repo] fix debug code in DBG_REPO mode (closes #2469942)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8547
diff
changeset
|
1403 |
for subjeid, objeid in eids_subj_obj: |
7513
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1404 |
print 'ADD relation', subjeid, rtype, objeid |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1405 |
for subjeid, objeid in eids_subj_obj: |
7238
576abb8c4626
fix implementation of repository.glob_add_relations (closes ##1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7237
diff
changeset
|
1406 |
if rtype in relations_by_rtype: |
7513
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1407 |
relations_by_rtype[rtype].append((subjeid, objeid)) |
7237
9f619715665b
[server] improve the speed of setting relations between entities (closes #1625257)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7134
diff
changeset
|
1408 |
else: |
7513
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1409 |
relations_by_rtype[rtype] = [(subjeid, objeid)] |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1410 |
if not activintegrity: |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1411 |
continue |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1412 |
# take care to relation of cardinality '?1', as all eids will |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1413 |
# be inserted later, we've remove duplicated eids since they |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1414 |
# won't be catched by `del_existing_rel_if_needed` |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1415 |
rdef = session.rtype_eids_rdef(rtype, subjeid, objeid) |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1416 |
card = rdef.cardinality |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1417 |
if card[0] in '?1': |
8562
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8539
diff
changeset
|
1418 |
with session.security_enabled(read=False): |
7513
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1419 |
session.execute('DELETE X %s Y WHERE X eid %%(x)s, ' |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1420 |
'NOT Y eid %%(y)s' % rtype, |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1421 |
{'x': subjeid, 'y': objeid}) |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1422 |
subjects = subjects_by_types.setdefault(rdef, {}) |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1423 |
if subjeid in subjects: |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1424 |
del relations_by_rtype[rtype][subjects[subjeid]] |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1425 |
subjects[subjeid] = len(relations_by_rtype[rtype]) - 1 |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1426 |
continue |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1427 |
subjects[subjeid] = len(relations_by_rtype[rtype]) - 1 |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1428 |
if card[1] in '?1': |
8562
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8539
diff
changeset
|
1429 |
with session.security_enabled(read=False): |
7513
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1430 |
session.execute('DELETE X %s Y WHERE Y eid %%(y)s, ' |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1431 |
'NOT X eid %%(x)s' % rtype, |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1432 |
{'x': subjeid, 'y': objeid}) |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1433 |
objects = objects_by_types.setdefault(rdef, {}) |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1434 |
if objeid in objects: |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1435 |
del relations_by_rtype[rtype][objects[objeid]] |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1436 |
objects[objeid] = len(relations_by_rtype[rtype]) |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1437 |
continue |
8f4422391e5a
[repo integrity] test and fix glob add relation where several entities are added at once for a relation of 1? cardinality
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7507
diff
changeset
|
1438 |
objects[objeid] = len(relations_by_rtype[rtype]) |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1439 |
for rtype, source_relations in relations_by_rtype.iteritems(): |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1440 |
self.hm.call_hooks('before_add_relation', session, |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1441 |
rtype=rtype, eids_from_to=source_relations) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1442 |
for rtype, source_relations in relations_by_rtype.iteritems(): |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1443 |
source.add_relations(session, rtype, source_relations) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1444 |
rschema = self.schema.rschema(rtype) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1445 |
for subjeid, objeid in source_relations: |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1446 |
session.update_rel_cache_add(subjeid, rtype, objeid, rschema.symmetric) |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1447 |
for rtype, source_relations in relations_by_rtype.iteritems(): |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1448 |
self.hm.call_hooks('after_add_relation', session, |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1449 |
rtype=rtype, eids_from_to=source_relations) |
0 | 1450 |
|
1451 |
def glob_delete_relation(self, session, subject, rtype, object): |
|
1452 |
"""delete a relation from the repository""" |
|
2600
6cd6c5d11b45
[F repo debugging] log repo event on DBG_REPO debug level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
1453 |
if server.DEBUG & server.DBG_REPO: |
6cd6c5d11b45
[F repo debugging] log repo event on DBG_REPO debug level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2596
diff
changeset
|
1454 |
print 'DELETE relation', subject, rtype, object |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1455 |
source = self.system_source |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1456 |
self.hm.call_hooks('before_delete_relation', session, |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1457 |
eidfrom=subject, rtype=rtype, eidto=object) |
0 | 1458 |
source.delete_relation(session, subject, rtype, object) |
2647
b0a2e779845c
enable server side entity caching, 25% speedup on codenaf insertion. ALL CW TESTS OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2641
diff
changeset
|
1459 |
rschema = self.schema.rschema(rtype) |
4467
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
1460 |
session.update_rel_cache_del(subject, rtype, object, rschema.symmetric) |
9454
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1461 |
self.hm.call_hooks('after_delete_relation', session, |
a173f9cf9f26
[multi-sources-removal] drop source location search on glob_*[entity|relation] methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
1462 |
eidfrom=subject, rtype=rtype, eidto=object) |
0 | 1463 |
|
1464 |
||
1465 |
# pyro handling ########################################################### |
|
1482 | 1466 |
|
6801
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1467 |
@property |
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1468 |
@cached |
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1469 |
def pyro_appid(self): |
6061
7cb29eab1c9d
[pyro] instance id cleanup, ensure config['pyro-instance-id'] is a fully qualified pyro id on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
1470 |
from logilab.common import pyro_ext as pyro |
7cb29eab1c9d
[pyro] instance id cleanup, ensure config['pyro-instance-id'] is a fully qualified pyro id on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
1471 |
config = self.config |
7cb29eab1c9d
[pyro] instance id cleanup, ensure config['pyro-instance-id'] is a fully qualified pyro id on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
1472 |
appid = '%s.%s' % pyro.ns_group_and_id( |
7cb29eab1c9d
[pyro] instance id cleanup, ensure config['pyro-instance-id'] is a fully qualified pyro id on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
1473 |
config['pyro-instance-id'] or config.appid, |
7cb29eab1c9d
[pyro] instance id cleanup, ensure config['pyro-instance-id'] is a fully qualified pyro id on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
1474 |
config['pyro-ns-group']) |
7cb29eab1c9d
[pyro] instance id cleanup, ensure config['pyro-instance-id'] is a fully qualified pyro id on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
1475 |
# ensure config['pyro-instance-id'] is a full qualified pyro name |
7cb29eab1c9d
[pyro] instance id cleanup, ensure config['pyro-instance-id'] is a fully qualified pyro id on the server side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5920
diff
changeset
|
1476 |
config['pyro-instance-id'] = appid |
6801
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1477 |
return appid |
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1478 |
|
7134
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1479 |
def _use_pyrons(self): |
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1480 |
"""return True if the pyro-ns-host is set to something else |
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1481 |
than NO_PYRONS, meaning we want to go through a pyro |
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1482 |
nameserver""" |
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1483 |
return self.config['pyro-ns-host'] != 'NO_PYRONS' |
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1484 |
|
6801
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1485 |
def pyro_register(self, host=''): |
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1486 |
"""register the repository as a pyro object""" |
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1487 |
from logilab.common import pyro_ext as pyro |
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1488 |
daemon = pyro.register_object(self, self.pyro_appid, |
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1489 |
daemonhost=self.config['pyro-host'], |
7134
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1490 |
nshost=self.config['pyro-ns-host'], |
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1491 |
use_pyrons=self._use_pyrons()) |
6801
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1492 |
self.info('repository registered as a pyro object %s', self.pyro_appid) |
7134
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1493 |
self.pyro_uri = pyro.get_object_uri(self.pyro_appid) |
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1494 |
self.info('pyro uri is: %s', self.pyro_uri) |
0 | 1495 |
self.pyro_registered = True |
6801
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1496 |
# register a looping task to regularly ensure we're still registered |
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1497 |
# into the pyro name server |
7134
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1498 |
if self._use_pyrons(): |
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1499 |
self.looping_task(60*10, self._ensure_pyro_ns) |
9007
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
1500 |
pyro_sessions = self._pyro_sessions |
8953
041804bc48e9
[server] add a looping task to free unused cnxsets capture by dead pyro
Julien Cristau <julien.cristau@logilab.fr>
parents:
8890
diff
changeset
|
1501 |
# install hacky function to free cnxset |
9007
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
1502 |
def handleConnection(conn, tcpserver, sessions=pyro_sessions): |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
1503 |
sessions[threading.currentThread()] = None |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
1504 |
return tcpserver.getAdapter().__class__.handleConnection(tcpserver.getAdapter(), conn, tcpserver) |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
1505 |
daemon.getAdapter().handleConnection = handleConnection |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
1506 |
def removeConnection(conn, sessions=pyro_sessions): |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
1507 |
daemon.__class__.removeConnection(daemon, conn) |
9008
e0aa7cf8abf8
repository: make tests pass again
Julien Cristau <julien.cristau@logilab.fr>
parents:
9007
diff
changeset
|
1508 |
session = sessions.pop(threading.currentThread(), None) |
9007
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
1509 |
if session is None: |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
1510 |
# client was not yet connected to the repo |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
1511 |
return |
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
1512 |
if not session.closed: |
9132
b6bcf99504c9
[server/repository] Go through the repo to close pyro sessions
Julien Cristau <julien.cristau@logilab.fr>
parents:
9008
diff
changeset
|
1513 |
self.close(session.id) |
9007
e27337dfec8c
repository: monkey patch pyro connection handling to detect clients going away
Julien Cristau <julien.cristau@logilab.fr>
parents:
8954
diff
changeset
|
1514 |
daemon.removeConnection = removeConnection |
0 | 1515 |
return daemon |
1482 | 1516 |
|
6801
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1517 |
def _ensure_pyro_ns(self): |
7134
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1518 |
if not self._use_pyrons(): |
01544b6d98fa
allow CW to act as a Pyro Server without registering the server to a Pyro Nameserver (closes #1528533)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7085
diff
changeset
|
1519 |
return |
6801
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1520 |
from logilab.common import pyro_ext as pyro |
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1521 |
pyro.ns_reregister(self.pyro_appid, nshost=self.config['pyro-ns-host']) |
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1522 |
self.info('repository re-registered as a pyro object %s', |
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1523 |
self.pyro_appid) |
33952695295b
[repository, pyro] ensure we're still properly registered into pyro name server in a looping task (closes #1336002)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6722
diff
changeset
|
1524 |
|
1228
91ae10ffb611
* refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents:
1217
diff
changeset
|
1525 |
# multi-sources planner helpers ########################################### |
1482 | 1526 |
|
1228
91ae10ffb611
* refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents:
1217
diff
changeset
|
1527 |
@cached |
91ae10ffb611
* refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents:
1217
diff
changeset
|
1528 |
def is_multi_sources_relation(self, rtype): |
9302
af36f459d2f0
[server] deprecate the old multi-source system
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9272
diff
changeset
|
1529 |
warn('[3.18] old multi-source system will go away in the next version', |
af36f459d2f0
[server] deprecate the old multi-source system
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9272
diff
changeset
|
1530 |
DeprecationWarning) |
1228
91ae10ffb611
* refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents:
1217
diff
changeset
|
1531 |
return any(source for source in self.sources |
91ae10ffb611
* refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents:
1217
diff
changeset
|
1532 |
if not source is self.system_source |
91ae10ffb611
* refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents:
1217
diff
changeset
|
1533 |
and source.support_relation(rtype)) |
1482 | 1534 |
|
7083
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7064
diff
changeset
|
1535 |
# these are overridden by set_log_methods below |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7064
diff
changeset
|
1536 |
# only defining here to prevent pylint from complaining |
b8e35cde46e9
help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7064
diff
changeset
|
1537 |
info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
0 | 1538 |
|
8268
c9babe49c1c1
[repository] implement a generic way to call repo-side services; closes #2203418
Florent Cayré <florent.cayre@logilab.fr>
parents:
8239
diff
changeset
|
1539 |
|
0 | 1540 |
def pyro_unregister(config): |
1541 |
"""unregister the repository from the pyro name server""" |
|
2665
0c6281487f90
[pyro] use lgc.pyro_ext, simplify pyro related options
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
1542 |
from logilab.common.pyro_ext import ns_unregister |
3539
f3b14d052798
[pyro] merge pyro-id / pyro-instance-id options, put all pyro options in the same section of the configuration file
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3250
diff
changeset
|
1543 |
appid = config['pyro-instance-id'] or config.appid |
2665
0c6281487f90
[pyro] use lgc.pyro_ext, simplify pyro related options
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
1544 |
ns_unregister(appid, config['pyro-ns-group'], config['pyro-ns-host']) |
0 | 1545 |
|
1546 |
||
1547 |
from logging import getLogger |
|
1548 |
from cubicweb import set_log_methods |
|
1549 |
set_log_methods(Repository, getLogger('cubicweb.repository')) |