apache-ignite

Форк
0
263 строки · 7.3 Кб
1
# Licensed to the Apache Software Foundation (ASF) under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#    http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
"""
17
This module contains classes that represent persistent artifacts of tests
18
"""
19

20
import os
21
from abc import abstractmethod, ABCMeta
22

23
from ignitetest.utils.version import DEV_BRANCH
24

25

26
def get_home_dir(install_root, product):
27
    """
28
    Get path to binary release (home) directory.
29
    """
30
    return os.path.join(install_root, product)
31

32

33
def get_shared_root_path(test_globals):
34
    """
35
    Get path to shared root directory.
36
    """
37
    return os.path.join(test_globals.get("persistent_root", "/mnt/service"), "shared")
38

39

40
class PathAware:
41
    """
42
    Basic class for path configs.
43
    """
44
    def init_persistent(self, node):
45
        """
46
        Init persistent directory.
47
        :param node: Service node.
48
        """
49
        node.account.mkdirs(
50
            f"{self.persistent_root} {self.temp_dir} {self.work_dir} {self.log_dir} {self.config_dir} {self.jfr_dir}")
51

52
    def init_logs_attribute(self):
53
        """
54
        Initialize logs attribute for collecting logs by ducktape.
55
        After changing to property based logs, will be removed.
56
        """
57
        setattr(self, 'logs', {
58
            "log": {
59
                "path": self.log_dir,
60
                "collect_default": True
61
            },
62
            "config": {
63
                "path": self.config_dir,
64
                "collect_default": True
65
            },
66
            "shared": {
67
                "path": self.shared_root,
68
                "collect_default": True
69
            },
70
            "jfr": {
71
                "path": self.jfr_dir,
72
                "collect_default": True
73
            }
74
        })
75

76
    @property
77
    @abstractmethod
78
    def config_file(self):
79
        """
80
        :return: path to project configuration file
81
        """
82

83
    @property
84
    @abstractmethod
85
    def log_config_file(self):
86
        """
87
        :return: path to logger configuration file
88
        """
89

90
    @property
91
    def work_dir(self):
92
        """
93
        :return: path to work directory
94
        """
95
        return os.path.join(self.persistent_root, "work")
96

97
    @property
98
    def config_dir(self):
99
        """
100
        :return: path to config directory
101
        """
102
        return os.path.join(self.persistent_root, "config")
103

104
    @property
105
    def jfr_dir(self):
106
        """
107
        :return: path to jfr directory
108
        """
109
        return os.path.join(self.persistent_root, "jfr")
110

111
    @property
112
    def log_dir(self):
113
        """
114
        :return: path to log directory
115
        """
116
        return os.path.join(self.persistent_root, "logs")
117

118
    @property
119
    def shared_root(self):
120
        """
121
        :return: path to directory with shared files - same files on all nodes
122
        """
123
        return get_shared_root_path(self.globals)
124

125
    @property
126
    @abstractmethod
127
    def product(self):
128
        """
129
        :return: Represents product (folder name), typically project/fork name with version.
130
        """
131

132
    @property
133
    @abstractmethod
134
    def globals(self):
135
        """
136
        :return: dictionary of globals variable (usually from test context).
137
        """
138

139
    @property
140
    def home_dir(self):
141
        """
142
        :return: path to binary release (home) directory
143
        """
144
        return get_home_dir(self.install_root, self.product)
145

146
    @property
147
    def temp_dir(self):
148
        """
149
        :return: path to temp directory
150
        """
151
        return os.path.join(self.persistent_root, "tmp")
152

153
    @property
154
    def persistent_root(self):
155
        """
156
        :return: path to persistent root
157
        """
158
        return self.globals.get("persistent_root", "/mnt/service")
159

160
    @property
161
    def install_root(self):
162
        """
163
        :return: path to distributive installation root
164
        """
165
        return self.globals.get("install_root", "/opt")
166

167

168
class IgnitePathAware(PathAware, metaclass=ABCMeta):
169
    """
170
    This class contains Ignite path configs.
171
    """
172
    IGNITE_CONFIG_NAME = "ignite-config.xml"
173

174
    IGNITE_THIN_CLIENT_CONFIG_NAME = "ignite-thin-config.xml"
175

176
    IGNITE_LOG_CONFIG_NAME = "ignite-ducktape-log4j2.xml"
177

178
    @property
179
    def config_file(self):
180
        """
181
        :return: path to config file
182
        """
183
        return os.path.join(self.config_dir, IgnitePathAware.IGNITE_CONFIG_NAME)
184

185
    @property
186
    def thin_client_config_file(self):
187
        """
188
        :return: path to thin client config file
189
        """
190
        return os.path.join(self.config_dir, IgnitePathAware.IGNITE_THIN_CLIENT_CONFIG_NAME)
191

192
    @property
193
    def log_config_file(self):
194
        """
195
        :return: path to log config file
196
        """
197
        return os.path.join(self.config_dir, IgnitePathAware.IGNITE_LOG_CONFIG_NAME)
198

199
    @property
200
    def database_dir(self):
201
        """
202
        :return: path to database directory
203
        """
204
        return os.path.join(self.work_dir, "db")
205

206
    @property
207
    def perf_stat_dir(self):
208
        """
209
        :return: path to performance statistics directory
210
        """
211
        return os.path.join(self.work_dir, "perf_stat")
212

213
    @property
214
    def wal_dir(self):
215
        """
216
        :return: path to wal directory
217
        """
218
        return os.path.join(self.database_dir, "wal")
219

220
    @property
221
    def snapshots_dir(self):
222
        """
223
        :return: path to snapshots directory
224
        """
225
        return os.path.join(self.work_dir, "snapshots")
226

227
    @property
228
    def certificate_dir(self):
229
        """
230
        :return: path to the certificate directory.
231
        """
232
        return os.path.join(get_home_dir(self.install_root, str(DEV_BRANCH)), "modules", "ducktests", "tests", "certs")
233

234
    def script(self, script_name):
235
        """
236
        :param script_name: name of Ignite script
237
        :return: absolute path to the specified script
238
        """
239
        return os.path.join(self.home_dir, "bin", script_name)
240

241
    @staticmethod
242
    def consistent_dir(consistent_id):
243
        """
244
        :param consistent_id: consistent ID
245
        :return: correct file name for consistent ID directory
246
        """
247
        return "".join([c if c.isdigit() or c.isalpha() else '_' for c in consistent_id])
248

249
    def cache_dir(self, consistent_dir, cache_name):
250
        """
251
        :param consistent_dir: consistent ID directory.
252
        :param cache_name: cache name.
253
        :return: absolute path to the cache directory.
254
        """
255
        return os.path.join(self.database_dir, consistent_dir, f'cache-{cache_name}')
256

257
    def index_file(self, consistent_dir, cache_name):
258
        """
259
        :param consistent_dir: consistent ID directory.
260
        :param cache_name: cache name.
261
        :return: absolute path to the index file of cache.
262
        """
263
        return os.path.join(self.cache_dir(consistent_dir, cache_name), 'index.bin')
264

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.