| 1 |
# Bacula(R) - The Network Backup Solution |
| 2 |
# |
| 3 |
# Copyright (C) 2000-2022 Kern Sibbald |
| 4 |
# |
| 5 |
# The original author of Bacula is Kern Sibbald, with contributions |
| 6 |
# from many others, a complete list can be found in the file AUTHORS. |
| 7 |
# |
| 8 |
# You may use this file and others of this release according to the |
| 9 |
# license defined in the LICENSE file, which includes the Affero General |
| 10 |
# Public License, v3.0 ("AGPLv3") and some additional permissions and |
| 11 |
# terms pursuant to its AGPLv3 Section 7. |
| 12 |
# |
| 13 |
# This notice must be preserved when any source code is |
| 14 |
# conveyed and/or propagated. |
| 15 |
# |
| 16 |
# Bacula(R) is a registered trademark of Kern Sibbald. |
| 17 |
import sys |
| 18 |
from baculak8s.io.default_io import DefaultIO |
| 19 |
from baculak8s.io.log import Log |
| 20 |
from baculak8s.io.packet_definitions import TERMINATION_PACKET |
| 21 |
from baculak8s.services.service import Service |
| 22 |
|
| 23 |
END_JOB_START_PACKET = "END" |
| 24 |
INVALID_END_JOB_START_PACKET = "Invalid End Job Start Packet" |
| 25 |
INVALID_TERMINATION_PACKET = "Invalid Termination Packet." \ |
| 26 |
" This indicates a possible error " \ |
| 27 |
"with the reading of the input sent" \ |
| 28 |
"to the Backend." |
| 29 |
|
| 30 |
|
| 31 |
class JobEndService(Service): |
| 32 |
""" |
| 33 |
Service that contains the business logic |
| 34 |
related to ending the Backend Job |
| 35 |
""" |
| 36 |
|
| 37 |
def __init__(self, job_info, plugin): |
| 38 |
# The job_info parameter will probably be used in the future |
| 39 |
self.plugin = plugin |
| 40 |
self.job_info = job_info |
| 41 |
self.io = DefaultIO() |
| 42 |
|
| 43 |
def execute(self, params=None): |
| 44 |
if self.job_info.get("query", None) is not None: |
| 45 |
return |
| 46 |
self.__read_start() |
| 47 |
self.plugin.disconnect() |
| 48 |
self.__read_termination() |
| 49 |
|
| 50 |
def __read_start(self): |
| 51 |
_, packet = self.io.read_packet() |
| 52 |
if packet != END_JOB_START_PACKET: |
| 53 |
self.io.send_abort(INVALID_END_JOB_START_PACKET) |
| 54 |
self.__abort() |
| 55 |
return |
| 56 |
self.io.send_eod() |
| 57 |
|
| 58 |
def __read_termination(self): |
| 59 |
packet_header = self.io.read_line() |
| 60 |
|
| 61 |
if packet_header != TERMINATION_PACKET: |
| 62 |
self.__abort() |
| 63 |
|
| 64 |
Log.save_received_termination(packet_header) |
| 65 |
|
| 66 |
def __abort(self): |
| 67 |
self.plugin.disconnect() |
| 68 |
sys.exit(0) |