-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathbmqstoragetool.m.cpp
273 lines (255 loc) · 9.81 KB
/
bmqstoragetool.m.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
// Copyright 2014-2023 Bloomberg Finance L.P.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//@PURPOSE: Provide the main function for the 'bmqstoragetool' application.
//
//@DESCRIPTION: This component provides the 'main' function and arguments
// parsing scheme for the 'bmqstoragetool' application.
// bmqstoragetool
#include <m_bmqstoragetool_commandprocessorfactory.h>
#include <m_bmqstoragetool_parameters.h>
// BDE
#include <balcl_commandline.h>
#include <bdls_filesystemutil.h>
#include <bsl_iostream.h>
#include <bslma_managedptr.h>
using namespace BloombergLP;
using namespace m_bmqstoragetool;
static bool parseArgs(CommandLineArguments& arguments,
int argc,
const char* argv[],
bslma::Allocator* allocator)
{
bool showHelp = false;
balcl::OptionInfo specTable[] = {
{"r|record-type",
"record type",
"record type to search {<message>|queue-op|journal-op}",
balcl::TypeInfo(&arguments.d_recordType,
CommandLineArguments::isValidRecordType),
balcl::OccurrenceInfo::e_OPTIONAL},
{"csl-record-type",
"csl record type",
"CSL record type to search {<snapshot>|update|commit|ack}",
balcl::TypeInfo(&arguments.d_cslRecordType,
CommandLineArguments::isValidCslRecordType),
balcl::OccurrenceInfo::e_OPTIONAL},
{"journal-path",
"journal path",
"'*'-ended file path pattern, where the tool will try to find "
"journal and data files",
balcl::TypeInfo(&arguments.d_journalPath),
balcl::OccurrenceInfo::e_OPTIONAL},
{"journal-file",
"journal file",
"path to a .bmq_journal file",
balcl::TypeInfo(&arguments.d_journalFile,
CommandLineArguments::isValidFileName),
balcl::OccurrenceInfo::e_OPTIONAL},
{"data-file",
"data file",
"path to a .bmq_data file",
balcl::TypeInfo(&arguments.d_dataFile,
CommandLineArguments::isValidFileName),
balcl::OccurrenceInfo::e_OPTIONAL},
{"csl-file",
"csl file",
"path to a .bmq_csl file",
balcl::TypeInfo(&arguments.d_cslFile,
CommandLineArguments::isValidFileName),
balcl::OccurrenceInfo::e_OPTIONAL},
{"csl-from-begin",
"start from begin",
"force to iterate CSL file from the beginning. By default: iterate "
"from the latest snapshot",
balcl::TypeInfo(&arguments.d_cslFromBegin),
balcl::OccurrenceInfo::e_OPTIONAL},
{"print-mode",
"print mode",
"can be one of the following {human|json-pretty|json-line}",
balcl::TypeInfo(&arguments.d_printMode,
CommandLineArguments::isValidPrintMode),
balcl::OccurrenceInfo("human")},
{"guid",
"guid",
"message guid",
balcl::TypeInfo(&arguments.d_guid),
balcl::OccurrenceInfo::e_OPTIONAL},
{"seqnum",
"seqnum",
"message composite sequence number",
balcl::TypeInfo(&arguments.d_seqNum),
balcl::OccurrenceInfo::e_OPTIONAL},
{"offset",
"offset",
"message offset",
balcl::TypeInfo(&arguments.d_offset),
balcl::OccurrenceInfo::e_OPTIONAL},
{"queue-name",
"queue name",
"message queue name",
balcl::TypeInfo(&arguments.d_queueName),
balcl::OccurrenceInfo::e_OPTIONAL},
{"queue-key",
"queue key",
"message queue key",
balcl::TypeInfo(&arguments.d_queueKey),
balcl::OccurrenceInfo::e_OPTIONAL},
{"timestamp-gt",
"timestamp greater than",
"lower timestamp bound",
balcl::TypeInfo(&arguments.d_timestampGt),
balcl::OccurrenceInfo::e_OPTIONAL},
{"timestamp-lt",
"timestamp less than",
"higher timestamp bound",
balcl::TypeInfo(&arguments.d_timestampLt),
balcl::OccurrenceInfo::e_OPTIONAL},
{"seqnum-gt",
"message composite sequence number greater than",
"lower record sequence number bound, defined in form "
"<leaseId-sequenceNumber>",
balcl::TypeInfo(&arguments.d_seqNumGt),
balcl::OccurrenceInfo::e_OPTIONAL},
{"seqnum-lt",
"message composite sequence number less than",
"higher sequence number bound, defined in form "
"<leaseId-sequenceNumber>",
balcl::TypeInfo(&arguments.d_seqNumLt),
balcl::OccurrenceInfo::e_OPTIONAL},
{"offset-gt",
"message offset greater than",
"lower record offset bound",
balcl::TypeInfo(&arguments.d_offsetGt),
balcl::OccurrenceInfo::e_OPTIONAL},
{"offset-lt",
"message offset less than",
"higher record offset bound",
balcl::TypeInfo(&arguments.d_offsetLt),
balcl::OccurrenceInfo::e_OPTIONAL},
{"outstanding",
"only outstanding",
"show only outstanding (not deleted) messages",
balcl::TypeInfo(&arguments.d_outstanding),
balcl::OccurrenceInfo::e_OPTIONAL},
{"confirmed",
"only confirmed",
"show only messages, confirmed by all the appId's",
balcl::TypeInfo(&arguments.d_confirmed),
balcl::OccurrenceInfo::e_OPTIONAL},
{"partially-confirmed",
"only partially confirmed",
"show only messages, confirmed by some of the appId's",
balcl::TypeInfo(&arguments.d_partiallyConfirmed),
balcl::OccurrenceInfo::e_OPTIONAL},
{"details",
"details",
"specify if you need message details",
balcl::TypeInfo(&arguments.d_details),
balcl::OccurrenceInfo::e_OPTIONAL},
{"dump-payload",
"dump payload",
"specify if you need message payload",
balcl::TypeInfo(&arguments.d_dumpPayload),
balcl::OccurrenceInfo::e_OPTIONAL},
{"dump-limit",
"dump limit",
"limit of payload output",
balcl::TypeInfo(&arguments.d_dumpLimit),
balcl::OccurrenceInfo(1024)},
{"summary",
"summary",
"summary of all matching records",
balcl::TypeInfo(&arguments.d_summary),
balcl::OccurrenceInfo::e_OPTIONAL},
{"min-records-per-queue",
"min records per queue",
"min number of records per queue for detailed info to be displayed",
balcl::TypeInfo(&arguments.d_minRecordsPerQueue),
balcl::OccurrenceInfo(0LL)},
{"summary-queues-limit",
"queues limit",
"limit of queues to display in CSL file summary",
balcl::TypeInfo(&arguments.d_cslSummaryQueuesLimit),
balcl::OccurrenceInfo(50)},
{"h|help",
"help",
"print usage)",
balcl::TypeInfo(&showHelp),
balcl::OccurrenceInfo::e_OPTIONAL}};
balcl::CommandLine commandLine(specTable);
if (commandLine.parse(argc, argv) != 0 || showHelp) {
commandLine.printUsage();
return false; // RETURN
}
bsl::string error;
if (!arguments.validate(&error, allocator)) {
bsl::cerr << "Arguments validation failed:\n" << error;
return false; // RETURN
}
return true;
}
// ====
// main
// ====
int main(int argc, const char* argv[])
{
enum RcEnum {
// Enum for the various RC error categories
rc_SUCCESS = 0,
rc_ARGUMENTS_PARSING_FAILED = -1,
rc_FILE_MANAGER_INIT_FAILED = -2,
rc_COMMAND_PROCESSOR_INIT_FAILED = -3
};
// Init allocator
bslma::Allocator* allocator = bslma::Default::allocator();
// Arguments parsing
CommandLineArguments arguments(allocator);
if (!parseArgs(arguments, argc, argv, allocator)) {
return rc_ARGUMENTS_PARSING_FAILED; // RETURN
}
// Create parameters
Parameters parameters(arguments, allocator);
// Create file manager
bslma::ManagedPtr<FileManager> fileManager;
try {
fileManager.load(new (*allocator)
FileManagerImpl(arguments.d_journalFile,
arguments.d_dataFile,
arguments.d_cslFile,
arguments.d_cslFromBegin,
allocator));
if (!arguments.d_cslFile.empty()) {
fileManager->fillQueueMapFromCslFile(¶meters.d_queueMap);
parameters.validateQueueNames();
}
}
catch (const bsl::exception& e) {
bsl::cerr << e.what();
return rc_FILE_MANAGER_INIT_FAILED; // RETURN
}
// Create command processor
bslma::ManagedPtr<CommandProcessor> processor =
CommandProcessorFactory::createCommandProcessor(¶meters,
fileManager,
bsl::cout,
allocator);
if (!processor) {
bsl::cerr << "Failed to create processor";
return rc_COMMAND_PROCESSOR_INIT_FAILED; // RETURN
}
// Run command processor
processor->process();
return rc_SUCCESS;
}