/
storm_info_provider.py
128 lines (105 loc) · 4.63 KB
/
storm_info_provider.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import logging
import os
import sys
from info_provider.glue.glue13 import Glue13
from info_provider.glue.glue2 import Glue2
from info_provider.storm_gateway import StormGateway
from info_provider.storm_space_info_builder import SpaceInfoBuilder
from info_provider.storm_storage_service_builder import StorageServiceBuilder
from info_provider.utils.ldap_utils import LDIFExporter
from info_provider.report import Report
class StormInfoProvider:
GET_IMPLEMENTATION_VERSION_CMD = "rpm -q --queryformat='%{VERSION}' storm-backend-server"
def __init__(self, **args):
logging.debug("StormInfoProvider initialization ...")
# set configuration
if not args.get("configuration"):
raise ValueError("No configuration provided")
self._configuration = args["configuration"]
# set gateway
if not args.get("gateway"):
self._gateway = StormGateway(self._configuration.get_backend_rest_endpoint())
else:
self._gateway = args["gateway"]
# set Glue13
if not args.get("glue13"):
self._glue13 = Glue13(self._configuration)
else:
self._glue13 = args["glue13"]
# set Glue2
if not args.get("glue2"):
self._glue2 = Glue2(self._configuration)
else:
self._glue2 = args["glue2"]
def _create_json_report(self, spaceinfo, outputfilepath):
# create report JSON
storage_service = StorageServiceBuilder(self._configuration, spaceinfo).build()
report = Report(storage_service=storage_service)
self._save_string_to_file(outputfilepath, report.to_json())
def configure(self, glue_protocol, exported_json_file_path):
logging.debug("Configure ...")
# load space info
spaceinfo = SpaceInfoBuilder(self._configuration, self._gateway).build()
# configure Glue13 info
if glue_protocol in ['glue13', 'all']:
self._glue13.configure(spaceinfo)
# configure Glue2 info
if glue_protocol in ['glue2', 'all']:
self._glue2.configure(spaceinfo)
# create report json
self._create_json_report(spaceinfo, exported_json_file_path)
return
def get_static_ldif(self, glue_protocol):
logging.debug("Get static LDIF ...")
# load space info
spaceinfo = SpaceInfoBuilder(self._configuration, self._gateway).build()
exporter = LDIFExporter()
# get Glue13 static LDIF info
if glue_protocol in ['glue13']:
exporter.add_nodes(self._glue13.get_static_ldif_nodes(spaceinfo))
# get Glue2 static LDIF info
if glue_protocol in ['glue2']:
exporter.add_nodes(self._glue2.get_static_ldif_nodes(spaceinfo))
exporter.print_nodes(sys.stdout)
return
def get_update_ldif(self, glue_protocol):
logging.debug("Get update LDIF ...")
# check serving state
serving_state = self._configuration.get_serving_state()
if serving_state == "closed":
# Backend is declared not running
logging.debug("StoRM Backend is not running")
# update endpoints serving state
if glue_protocol in ['glue2']:
exporter = LDIFExporter()
exporter.add_nodes(self._glue2.get_update_ldif_endpoints(serving_state))
exporter.print_nodes(sys.stdout)
return
return
# load space info
spaceinfo = SpaceInfoBuilder(self._configuration, self._gateway).build()
exporter = LDIFExporter()
# get Glue13 update LDIF info
if glue_protocol in ['glue13']:
exporter.add_nodes(self._glue13.get_update_ldif_nodes(spaceinfo))
# get Glue2 update LDIF info
if glue_protocol in ['glue2']:
exporter.add_nodes(self._glue2.get_update_ldif_endpoints(serving_state))
exporter.add_nodes(self._glue2.get_update_ldif_spaceinfo(spaceinfo, serving_state))
exporter.print_nodes(sys.stdout)
return
def get_report_json(self, exported_json_file_path):
logging.debug("Get report JSON ...")
# load space info
spaceinfo = SpaceInfoBuilder(self._configuration, self._gateway).build()
# create report JSON
self._create_json_report(spaceinfo, exported_json_file_path)
logging.info("Exported JSON report to %s", exported_json_file_path)
return
def _get_implementation_version(self):
return os.popen(self.GET_IMPLEMENTATION_VERSION_CMD).read()
def _save_string_to_file(self, filepath, content):
f = open(filepath, 'w')
f.write(content)
f.close()
return