-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSystemManagerUI.cpp
156 lines (143 loc) · 3.97 KB
/
SystemManagerUI.cpp
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include"SystemManager/SystemManagerUI.h"
namespace SystemManagerSpace
{
SystemManagerUI::SystemManagerUI(SystemManager &sm) : systemManager(sm)
{
start();
}
SystemManagerUI::~SystemManagerUI()
{}
void SystemManagerUI::printCommand()
{
cout << "SystemManager commands: print-info (p), monitor-resources (m), load-xml (l), clear/kill-database (c), kill-all (k), stop-component (s), exception-list (e), init-service-manager (i), quit (q), help (h)." << endl;
}
void SystemManagerUI::run()
{
printCommand();
while(true)
{
string command;
try
{
istream &ret = getline(cin, command);
if(ret.eof() || ret.bad() || !ret.good())
{
throw string("End of file!");
}
}
catch(...)
{
cout << "SystemManagerUI::run(): WARNING! SystemManager user interface (UI) is off." << endl;
break;
}
if(strncmp(command.c_str(), "monitor-all", 1) == 0)
{
systemManager.cmdMonitorResources();
}
else if(strncmp(command.c_str(), "kill-all", 1) == 0)
{
cout << "Do you really want to kill all components (y/n)? " ;
string confirm;
getline(cin, confirm);
if(strncmp(confirm.c_str(), "yes", 1) == 0)
{
stringstream errorMsg;
systemManager.cmdKillAllComponents(errorMsg);
}
else printCommand();
}
else if(strncmp(command.c_str(), "clear/kill-database", 1) == 0)
{
cout << "Do you really want to clear database and effectively kill all components (y/n)? " ;
string confirm;
getline(cin, confirm);
if(strncmp(confirm.c_str(), "yes", 1) == 0)
{
stringstream errorMsg;
systemManager.cmdKillAllComponents(errorMsg);
systemManager.cmdClearDataBase(errorMsg);
}
else printCommand();
}
else if(strncmp(command.c_str(), "stop-component", 1) == 0)
{
cout << "Name of component you wish to stop (effectively kill): " ;
string componentName;
getline(cin, componentName);
if(componentName.empty())
{
cout << "No components stopped." << endl;
printCommand();
continue;
}
if(!systemManager.cmdKillComponent(componentName))
{
cout << "Component " << componentName << " not found." << endl;
printCommand();
continue;
}
}
else if(strncmp(command.c_str(), "load-xml", 1) == 0)
{
cout << "Configuration file you wish to load (.xml) ";
if(!SystemManagerConfig::systemConfigurationFile.empty())
cout << "(Type 'y' to load " << SystemManagerConfig::systemConfigurationFile << ")";
cout << ": ";
string xmlFile;
getline(cin, xmlFile);
if(xmlFile.empty())
{
printCommand();
continue;
}
if(strcmp(xmlFile.c_str(), "y") == 0)
xmlFile = SystemManagerConfig::systemConfigurationFile;
if(systemManager.cmdStartComponents(std::cout, xmlFile) == 0)
{
cout << "Loaded " << xmlFile << " successfully! " << endl;
cerr << "Please check the status of the components using 'print-info' command!" << endl;
}
else
cout << "Loading of " << xmlFile << " failed!" << endl;
}
else if(strncmp(command.c_str(), "exception-list", 1) == 0)
{
systemManager.exceptionMonitor.PrintAll(cout);
}
else if(strncmp(command.c_str(), "init-service-manager", 1) == 0)
{
cout << "Starting ServiceManager...." << endl;
int ret = systemManager.cmdStartServiceManager(cout);
if(ret == 0)
cout << "Successfully started ServiceManager!" << endl;
else
cout << "Could not start ServiceManager!" << endl;
}
else if(strncmp(command.c_str(), "quit", 1) == 0)
{
cout << "Do you really want to quit (y/n)? " ;
string confirm;
getline(cin, confirm);
if(strncmp(confirm.c_str(), "yes", 1) == 0)
{
cout << "Quitting SystemManager..." << endl;
systemManager.Quit();
break;
}
else printCommand();
}
else if(strncmp(command.c_str(), "print-info", 1) == 0)
{
systemManager.cmdPrintHostInformation(cout);
}
else if(strncmp(command.c_str(), "help", 1) == 0)
{
printCommand();
}
else if(!command.empty())
{
cout << "Command: " << command << " is not supported" << endl;
}
}
}
} // namespace SystemManagerSpace