##// END OF EJS Templates
core: added option to prefix cache keys for usage in cluster.
marcink -
r3006:9b4df490 default
parent child Browse files
Show More
@@ -1,89 +1,94 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2018 RhodeCode GmbH
3 # Copyright (C) 2010-2018 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import os
21 import os
22 import shlex
22 import shlex
23 import platform
23 import platform
24
24
25 from rhodecode.model import init_model
25 from rhodecode.model import init_model
26
26
27
27
28 def configure_vcs(config):
28 def configure_vcs(config):
29 """
29 """
30 Patch VCS config with some RhodeCode specific stuff
30 Patch VCS config with some RhodeCode specific stuff
31 """
31 """
32 from rhodecode.lib.vcs import conf
32 from rhodecode.lib.vcs import conf
33 import rhodecode.lib.vcs.conf.settings
33 import rhodecode.lib.vcs.conf.settings
34
34
35 conf.settings.BACKENDS = {
35 conf.settings.BACKENDS = {
36 'hg': 'rhodecode.lib.vcs.backends.hg.MercurialRepository',
36 'hg': 'rhodecode.lib.vcs.backends.hg.MercurialRepository',
37 'git': 'rhodecode.lib.vcs.backends.git.GitRepository',
37 'git': 'rhodecode.lib.vcs.backends.git.GitRepository',
38 'svn': 'rhodecode.lib.vcs.backends.svn.SubversionRepository',
38 'svn': 'rhodecode.lib.vcs.backends.svn.SubversionRepository',
39 }
39 }
40
40
41 conf.settings.HOOKS_PROTOCOL = config['vcs.hooks.protocol']
41 conf.settings.HOOKS_PROTOCOL = config['vcs.hooks.protocol']
42 conf.settings.HOOKS_HOST = config['vcs.hooks.host']
42 conf.settings.HOOKS_HOST = config['vcs.hooks.host']
43 conf.settings.HOOKS_DIRECT_CALLS = config['vcs.hooks.direct_calls']
43 conf.settings.HOOKS_DIRECT_CALLS = config['vcs.hooks.direct_calls']
44 conf.settings.GIT_REV_FILTER = shlex.split(config['git_rev_filter'])
44 conf.settings.GIT_REV_FILTER = shlex.split(config['git_rev_filter'])
45 conf.settings.DEFAULT_ENCODINGS = config['default_encoding']
45 conf.settings.DEFAULT_ENCODINGS = config['default_encoding']
46 conf.settings.ALIASES[:] = config['vcs.backends']
46 conf.settings.ALIASES[:] = config['vcs.backends']
47 conf.settings.SVN_COMPATIBLE_VERSION = config['vcs.svn.compatible_version']
47 conf.settings.SVN_COMPATIBLE_VERSION = config['vcs.svn.compatible_version']
48
48
49
49
50 def initialize_database(config):
50 def initialize_database(config):
51 from rhodecode.lib.utils2 import engine_from_config, get_encryption_key
51 from rhodecode.lib.utils2 import engine_from_config, get_encryption_key
52 engine = engine_from_config(config, 'sqlalchemy.db1.')
52 engine = engine_from_config(config, 'sqlalchemy.db1.')
53 init_model(engine, encryption_key=get_encryption_key(config))
53 init_model(engine, encryption_key=get_encryption_key(config))
54
54
55
55
56 def initialize_test_environment(settings, test_env=None):
56 def initialize_test_environment(settings, test_env=None):
57 if test_env is None:
57 if test_env is None:
58 test_env = not int(os.environ.get('RC_NO_TMP_PATH', 0))
58 test_env = not int(os.environ.get('RC_NO_TMP_PATH', 0))
59
59
60 from rhodecode.lib.utils import (
60 from rhodecode.lib.utils import (
61 create_test_directory, create_test_database, create_test_repositories,
61 create_test_directory, create_test_database, create_test_repositories,
62 create_test_index)
62 create_test_index)
63 from rhodecode.tests import TESTS_TMP_PATH
63 from rhodecode.tests import TESTS_TMP_PATH
64 from rhodecode.lib.vcs.backends.hg import largefiles_store
64 from rhodecode.lib.vcs.backends.hg import largefiles_store
65 from rhodecode.lib.vcs.backends.git import lfs_store
65 from rhodecode.lib.vcs.backends.git import lfs_store
66
66
67 # test repos
67 # test repos
68 if test_env:
68 if test_env:
69 create_test_directory(TESTS_TMP_PATH)
69 create_test_directory(TESTS_TMP_PATH)
70 # large object stores
70 # large object stores
71 create_test_directory(largefiles_store(TESTS_TMP_PATH))
71 create_test_directory(largefiles_store(TESTS_TMP_PATH))
72 create_test_directory(lfs_store(TESTS_TMP_PATH))
72 create_test_directory(lfs_store(TESTS_TMP_PATH))
73
73
74 create_test_database(TESTS_TMP_PATH, settings)
74 create_test_database(TESTS_TMP_PATH, settings)
75 create_test_repositories(TESTS_TMP_PATH, settings)
75 create_test_repositories(TESTS_TMP_PATH, settings)
76 create_test_index(TESTS_TMP_PATH, settings)
76 create_test_index(TESTS_TMP_PATH, settings)
77
77
78
78
79 def get_vcs_server_protocol(config):
79 def get_vcs_server_protocol(config):
80 return config['vcs.server.protocol']
80 return config['vcs.server.protocol']
81
81
82
82
83 def set_instance_id(config):
83 def set_instance_id(config):
84 """ Sets a dynamic generated config['instance_id'] if missing or '*' """
84 """
85 Sets a dynamic generated config['instance_id'] if missing or '*'
86 E.g instance_id = *cluster-1 or instance_id = *
87 """
85
88
86 config['instance_id'] = config.get('instance_id') or ''
89 config['instance_id'] = config.get('instance_id') or ''
87 if config['instance_id'] == '*' or not config['instance_id']:
90 instance_id = config['instance_id']
91 if instance_id.startswith('*') or not instance_id:
92 prefix = instance_id.lstrip('*')
88 _platform_id = platform.uname()[1] or 'instance'
93 _platform_id = platform.uname()[1] or 'instance'
89 config['instance_id'] = '%s-%s' % (_platform_id, os.getpid())
94 config['instance_id'] = '%s%s-%s' % (prefix, _platform_id, os.getpid())
General Comments 0
You need to be logged in to leave comments. Login now