apache-ignite

Форк
0
93 строки · 2.9 Кб
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 ignite config classes and utilities.
18
"""
19
import os
20

21
from jinja2 import FileSystemLoader, Environment
22

23
IGNITE_TEMPLATE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")
24
ZK_TEMPLATE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "zk", "templates")
25
DEFAULT_IGNITE_CONF = "ignite.xml.j2"
26
DEFAULT_THIN_CLIENT_CONF = "thin_client_config.xml.j2"
27
DEFAULT_LOG4J2_CONF = "log4j2.xml.j2"
28

29
TEMPLATE_PATHES = [IGNITE_TEMPLATE_PATH, ZK_TEMPLATE_PATH]
30

31

32
class ConfigTemplate:
33
    """
34
    Basic configuration.
35
    """
36
    def __init__(self, path):
37
        env = Environment(loader=FileSystemLoader(searchpath=TEMPLATE_PATHES))
38
        env.filters["snake_to_camel"] = snake_to_camel
39

40
        self.template = env.get_template(path)
41
        self.default_params = {}
42

43
    def render(self, **kwargs):
44
        """
45
        Render configuration.
46
        """
47
        kwargs.update(self.default_params)
48
        unfiltered = self.template.render(**kwargs)
49

50
        return '\n'.join(filter(lambda line: line.strip(), unfiltered.split('\n')))
51

52

53
def snake_to_camel(snake_name):
54
    """
55
    Custom jinja2 filter to convert named from smake to camel format
56
    :param snake_name: name in snake format
57
    :return: name in camel format
58
    """
59
    components = snake_name.split('_')
60
    return components[0] + ''.join(x.title() for x in components[1:])
61

62

63
class IgniteServerConfigTemplate(ConfigTemplate):
64
    """
65
    Ignite server node configuration.
66
    """
67
    def __init__(self, path=DEFAULT_IGNITE_CONF):
68
        super().__init__(path)
69

70

71
class IgniteClientConfigTemplate(ConfigTemplate):
72
    """
73
    Ignite client node configuration.
74
    """
75
    def __init__(self, path=DEFAULT_IGNITE_CONF):
76
        super().__init__(path)
77
        self.default_params.update(client_mode=True)
78

79

80
class IgniteThinClientConfigTemplate(ConfigTemplate):
81
    """
82
    Ignite client node configuration.
83
    """
84
    def __init__(self, path=DEFAULT_THIN_CLIENT_CONF):
85
        super().__init__(path)
86

87

88
class IgniteLoggerConfigTemplate(ConfigTemplate):
89
    """
90
    Ignite logger configuration.
91
    """
92
    def __init__(self):
93
        super().__init__(DEFAULT_LOG4J2_CONF)
94

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

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

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

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