apache-ignite

Форк
0
111 строк · 4.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 the base class to build Ignite aware application written on java.
18
"""
19
import re
20

21
from ducktape.errors import TimeoutError
22

23
from ignitetest.services.ignite_execution_exception import IgniteExecutionException
24
from ignitetest.services.utils.ignite_aware import IgniteAwareService
25

26

27
class IgniteApplicationService(IgniteAwareService):
28
    """
29
    The base class to build Ignite aware application written on java.
30
    """
31

32
    SERVICE_JAVA_CLASS_NAME = "org.apache.ignite.internal.ducktest.utils.IgniteAwareApplicationService"
33
    APP_INIT_EVT_MSG = "IGNITE_APPLICATION_INITIALIZED"
34
    APP_FINISH_EVT_MSG = "IGNITE_APPLICATION_FINISHED"
35
    APP_BROKEN_EVT_MSG = "IGNITE_APPLICATION_BROKEN"
36

37
    def __init__(self, context, config, java_class_name, num_nodes=1, params="", startup_timeout_sec=60,
38
                 shutdown_timeout_sec=60, modules=None, main_java_class=SERVICE_JAVA_CLASS_NAME, jvm_opts=None,
39
                 merge_with_default=True):
40
        super().__init__(context, config, num_nodes, startup_timeout_sec, shutdown_timeout_sec, main_java_class,
41
                         modules, jvm_opts=jvm_opts, merge_with_default=merge_with_default)
42

43
        self.java_class_name = java_class_name
44
        self.params = params
45

46
    def await_started(self):
47
        super().await_started()
48

49
        self.__check_status(self.APP_INIT_EVT_MSG, timeout=self.startup_timeout_sec)
50

51
    def await_stopped(self):
52
        super().await_stopped()
53

54
        self.__check_status(self.APP_FINISH_EVT_MSG)
55

56
    def __check_status(self, desired, timeout=1):
57
        self.await_event("%s\\|%s" % (desired, self.APP_BROKEN_EVT_MSG), timeout, from_the_beginning=True)
58

59
        try:
60
            self.await_event(self.APP_BROKEN_EVT_MSG, 1, from_the_beginning=True)
61
            raise IgniteExecutionException("Java application execution failed. %s" % self.extract_result("ERROR"))
62
        except TimeoutError:
63
            pass
64

65
        try:
66
            self.await_event(desired, 1, from_the_beginning=True)
67
        except Exception:
68
            raise Exception("Java application execution failed.") from None
69

70
    def get_init_time(self, selector=min):
71
        """
72
        Gets the time of application init event.
73
        :param selector: Selector function, default is min.
74
        :return: Application initialization time.
75
        """
76
        return self.get_event_time(self.APP_INIT_EVT_MSG, selector=selector)
77

78
    def get_finish_time(self, selector=max):
79
        """
80
        Gets the time of application finish event.
81
        :param selector: Selector function, default is max.
82
        :return: Application finish time.
83
        """
84
        return self.get_event_time(self.APP_FINISH_EVT_MSG, selector=selector)
85

86
    def extract_result(self, name):
87
        """
88
        :param name: Result parameter's name.
89
        :return: Extracted result of application run.
90
        """
91
        results = self.extract_results(name)
92

93
        assert len(results) == len(self.nodes), f"Expected exactly {len(self.nodes)} occurence," \
94
                                                f" but found {len(results)}."
95

96
        return results[0] if results else ""
97

98
    def extract_results(self, name):
99
        """
100
        :param name: Results parameter's name.
101
        :return: Extracted results of application run.
102
        """
103
        res = []
104

105
        for node in self.nodes:
106
            output = node.account.ssh_capture(
107
                "grep '%s' %s" % (name + "->", node.log_file), allow_fail=False)
108
            for line in output:
109
                res.append(re.search("%s(.*)%s" % (name + "->", "<-"), line).group(1))
110

111
        return res
112

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

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

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

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