| 1 |
# -*- coding: UTF-8 -*- |
| 2 |
# Bacula(R) - The Network Backup Solution |
| 3 |
# |
| 4 |
# Copyright (C) 2000-2022 Kern Sibbald |
| 5 |
# |
| 6 |
# The original author of Bacula is Kern Sibbald, with contributions |
| 7 |
# from many others, a complete list can be found in the file AUTHORS. |
| 8 |
# |
| 9 |
# You may use this file and others of this release according to the |
| 10 |
# license defined in the LICENSE file, which includes the Affero General |
| 11 |
# Public License, v3.0 ("AGPLv3") and some additional permissions and |
| 12 |
# terms pursuant to its AGPLv3 Section 7. |
| 13 |
# |
| 14 |
# This notice must be preserved when any source code is |
| 15 |
# conveyed and/or propagated. |
| 16 |
# |
| 17 |
# Bacula(R) is a registered trademark of Kern Sibbald. |
| 18 |
|
| 19 |
import logging |
| 20 |
|
| 21 |
from baculak8s.io.default_io import DefaultIO |
| 22 |
from baculak8s.jobs.job import Job |
| 23 |
from baculak8s.util.respbody import parse_json_descr |
| 24 |
|
| 25 |
QUERY_START = "QueryStart" |
| 26 |
QUERY_ERROR_RESPONSE = "QueryParam returned error response: {}" |
| 27 |
|
| 28 |
|
| 29 |
class QueryJob(Job): |
| 30 |
""" |
| 31 |
Job that contains the business logic |
| 32 |
related to the queryParams mode of the Backend. |
| 33 |
It depends upon a Plugin Class implementation |
| 34 |
that retrieves listing data from the Plugins Data Source |
| 35 |
""" |
| 36 |
|
| 37 |
def __init__(self, plugin, params): |
| 38 |
super().__init__(plugin, DefaultIO(), params) |
| 39 |
|
| 40 |
def execute(self): |
| 41 |
self._start(QUERY_START) |
| 42 |
self.execution_loop() |
| 43 |
self._io.send_eod() |
| 44 |
|
| 45 |
def execution_loop(self): |
| 46 |
self.__query_loop() |
| 47 |
|
| 48 |
def __query_loop(self): |
| 49 |
found_any = False |
| 50 |
query_param_list = self._plugin.query_parameter(self._params["query"]) |
| 51 |
if isinstance(query_param_list, dict) and 'error' in query_param_list: |
| 52 |
logging.warning(query_param_list) |
| 53 |
self._io.send_warning(QUERY_ERROR_RESPONSE.format(parse_json_descr(query_param_list))) |
| 54 |
else: |
| 55 |
for param_data in query_param_list: |
| 56 |
found_any = True |
| 57 |
self._io.send_query_response(param_data) |