apache-ignite
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"""
17This module contains the base class to build Ignite aware application written on java.
18"""
19import re20
21from ducktape.errors import TimeoutError22
23from ignitetest.services.ignite_execution_exception import IgniteExecutionException24from ignitetest.services.utils.ignite_aware import IgniteAwareService25
26
27class IgniteApplicationService(IgniteAwareService):28"""29The base class to build Ignite aware application written on java.
30"""
31
32SERVICE_JAVA_CLASS_NAME = "org.apache.ignite.internal.ducktest.utils.IgniteAwareApplicationService"33APP_INIT_EVT_MSG = "IGNITE_APPLICATION_INITIALIZED"34APP_FINISH_EVT_MSG = "IGNITE_APPLICATION_FINISHED"35APP_BROKEN_EVT_MSG = "IGNITE_APPLICATION_BROKEN"36
37def __init__(self, context, config, java_class_name, num_nodes=1, params="", startup_timeout_sec=60,38shutdown_timeout_sec=60, modules=None, main_java_class=SERVICE_JAVA_CLASS_NAME, jvm_opts=None,39merge_with_default=True):40super().__init__(context, config, num_nodes, startup_timeout_sec, shutdown_timeout_sec, main_java_class,41modules, jvm_opts=jvm_opts, merge_with_default=merge_with_default)42
43self.java_class_name = java_class_name44self.params = params45
46def await_started(self):47super().await_started()48
49self.__check_status(self.APP_INIT_EVT_MSG, timeout=self.startup_timeout_sec)50
51def await_stopped(self):52super().await_stopped()53
54self.__check_status(self.APP_FINISH_EVT_MSG)55
56def __check_status(self, desired, timeout=1):57self.await_event("%s\\|%s" % (desired, self.APP_BROKEN_EVT_MSG), timeout, from_the_beginning=True)58
59try:60self.await_event(self.APP_BROKEN_EVT_MSG, 1, from_the_beginning=True)61raise IgniteExecutionException("Java application execution failed. %s" % self.extract_result("ERROR"))62except TimeoutError:63pass64
65try:66self.await_event(desired, 1, from_the_beginning=True)67except Exception:68raise Exception("Java application execution failed.") from None69
70def get_init_time(self, selector=min):71"""72Gets the time of application init event.
73:param selector: Selector function, default is min.
74:return: Application initialization time.
75"""
76return self.get_event_time(self.APP_INIT_EVT_MSG, selector=selector)77
78def get_finish_time(self, selector=max):79"""80Gets the time of application finish event.
81:param selector: Selector function, default is max.
82:return: Application finish time.
83"""
84return self.get_event_time(self.APP_FINISH_EVT_MSG, selector=selector)85
86def extract_result(self, name):87"""88:param name: Result parameter's name.
89:return: Extracted result of application run.
90"""
91results = self.extract_results(name)92
93assert len(results) == len(self.nodes), f"Expected exactly {len(self.nodes)} occurence," \94f" but found {len(results)}."95
96return results[0] if results else ""97
98def extract_results(self, name):99"""100:param name: Results parameter's name.
101:return: Extracted results of application run.
102"""
103res = []104
105for node in self.nodes:106output = node.account.ssh_capture(107"grep '%s' %s" % (name + "->", node.log_file), allow_fail=False)108for line in output:109res.append(re.search("%s(.*)%s" % (name + "->", "<-"), line).group(1))110
111return res112