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