HCE project C++ developers source code library  1.1.1
HCE project developer library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SphinxAdminCommand.hpp
Go to the documentation of this file.
1 
14 #ifndef SPHINX_ADMIN_COMMAND_HPP
15 #define SPHINX_ADMIN_COMMAND_HPP
16 
17 #include <Poco/SharedPtr.h>
18 
19 #include "JsonSerializable.hpp"
21 #include "CustomMessage.hpp"
22 
23 namespace HCE
24 {
25 namespace sphinx
26 {
27 namespace sphinx_admin_command_const
28 {
29  const std::string indexDir = "index";
30  const std::string dataDir = "data";
31 
32  const std::string dataFileExtension = "dat";
33  const std::string sourceFileExtension = "xml";
34  const std::string branchConfigFileExtention = "cfg";
35  const std::string branchPropertyFileExtention = "property";
36  const std::string deletedFileName = "list.deleted";
37 
38  const std::string indexName = "index";
39  const std::string branchName = "branch";
40  const std::string dataContent = "data";
41  const std::string branches = "branches";
42  const std::string documents = "documents";
43  const std::string indexFromName = "index_from";
44  const std::string indexToName = "index_to";
45  const std::string sectionName = "section_name";
46  const std::string parameterName = "parameter_name";
47  const std::string parameterValue = "parameter_value";
48  const std::string allowedSimbols = "*0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-";
49  const std::string procExecErrorMsg = "ERROR:";
50  const std::string procExecFatalMsg = "FATAL:";
51 
52  const std::string sectionOptions = "options";
53  const std::string optionsMaxDocId = sectionOptions+".max_doc_id";
54  const std::string optionsCreatedDate = sectionOptions+".cdate";
55  const std::string optionsMergedDate = sectionOptions+".mdate";
56  const std::string optionsBranches = sectionOptions+".branches";
57  const std::string optionsRanker = sectionOptions+".ranker";
58  const std::string optionsRankerExpression = sectionOptions+".ranker_expression";
59 }
62 //-----------------------------------------------------------------------------
64 {
65 public:
67  virtual ~SphinxAdminCommand(void) {};
68 
69  void setResultData(const std::string& resultData_) {resultData=resultData_;}
70  std::string getResultData(void) const {return resultData;}
71 
72  virtual bool execute(void)=0;
73 protected:
74  bool makeDir(const std::string& path);
75  bool cleanDir(const std::string& path);
76  bool isExistDir(const std::string& path);
77  bool isExistFile(const std::string& file);
78  bool isAllowedString(const std::string& str);
79  bool copyFile(const std::string& srcFile, const std::string& dstFile);
80  bool moveFile(const std::string& srcFile, const std::string& dstFile);
81  bool removeFile(const std::string& file);
82  bool moveIndexFiles(const std::string& indexFileName, const std::string& srcPath, const std::string& dstPath);
83  bool copyIndexFiles(const std::string& indexFileName, const std::string& srcPath, const std::string& dstPath);
84  bool removeIndexFile(const std::string& indexFileName, const std::string& path);
85  bool getFileList(const std::string& path, std::vector<std::string>& vFiles, const std::string& ext);
86  bool getIndexList(const std::string& path, std::vector<std::string>& vIndexes);
87  bool getFreeAllowedPort(unsigned int& res);
88  bool makeTrunkConfig(const std::string& trunkName, const std::string& indexName, const std::string& indexFileName,
89  SphinxConfigOptions& configOptions);
90 
91  bool isExistError(const std::string& shellExecMsg);
92 
93  std::string getPropertyFileName(const std::string& indexPath, const std::string& branchName);
94  std::string getConfigFileName(const std::string& indexPath, const std::string& branchName);
95 
96  void writePropertyOptions(SphinxConfigCreator& configCreator, const SphinxConfigOptions& configOptions);
97 
99  std::string resultData;
100 
102 
104 };
105 //-----------------------------------------------------------------------------
106 //-----------------------------------------------------------------------------
108 {
109 public:
110  Poco::SharedPtr<SphinxAdminCommand> create(SphinxFunctionalObject& fObj, const std::string& commandString);
111 };
112 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
115 {
116 public:
118  virtual ~IndexCreate(void) {};
119 
120  bool serialize(std::string& json);
121  bool unserialize(const std::string& json);
122  virtual bool execute(void);
123 
124  void setIndexName(const std::string& indexName_) {indexName=indexName_;}
125  std::string getIndexName(void) const {return indexName;}
126 protected:
127  std::string indexName;
128 
130 };
131 //-----------------------------------------------------------------------------
132 //-----------------------------------------------------------------------------
133 class IndexCheck : public IndexCreate
134 {
135 public:
137  virtual ~IndexCheck(void) {};
138 
139  bool execute(void);
140 
142 };
143 //-----------------------------------------------------------------------------
144 //-----------------------------------------------------------------------------
146 {
147 public:
149  virtual ~IndexStoreDataFile(void) {};
150 
151  bool serialize(std::string& json);
152  bool unserialize(const std::string& json);
153  bool execute(void);
154 
155  void setIndexName(const std::string& indexName_) {indexName=indexName_;}
156  std::string getIndexName(void) const {return indexName;}
157 
158  void setBranchName(const std::string& branchName_) {branchName=branchName_;}
159  std::string getBranchName(void) const {return branchName;}
160 
161  void setDataContent(const std::string& dataContent_) {dataContent=dataContent_;}
162  std::string getDataContent(void) const {return dataContent;}
163 
164 protected:
165  std::string indexName;
166  std::string branchName;
167  std::string dataContent;
168 
170 };
171 //-----------------------------------------------------------------------------
172 //-----------------------------------------------------------------------------
174 {
175 public:
177  virtual ~IndexStoreSchemaFile(void) {};
178 
179  bool serialize(std::string& json);
180  bool unserialize(const std::string& json);
181  bool execute(void);
182 
183  void setIndexName(const std::string& indexName_) {indexName=indexName_;}
184  std::string getIndexName(void) const {return indexName;}
185 
186  void setSchemaContent(const std::string& schemaContent_) {schemaContent=schemaContent_;}
187  std::string getSchemaContent(void) const {return schemaContent;}
188 
189 protected:
190  std::string indexName;
191  std::string schemaContent;
192 
194 };
195 //-----------------------------------------------------------------------------
197 {
198 protected:
199  bool makeSource(const std::string& schemaFile, const std::string& branchName, const std::string& sourcePath, const std::string& configPath);
200  bool makeIndex(const std::string& sourceFile, const std::string& branchName, const std::string& configPath, unsigned long long maxDocId);
201 public:
203  virtual ~IndexRebuild(void) {};
204 
205  bool serialize(std::string& json);
206  bool unserialize(const std::string& json);
207  bool execute(void);
208 
209  void setIndexName(const std::string& indexName_) {indexName=indexName_;}
210  std::string getIndexName(void) const {return indexName;}
211 
212  void addBranch(const std::string& branch) {branches.push_back(branch);}
213  std::vector<std::string>& getBranches(void) {return branches;}
214 
215 protected:
216  std::string indexName;
217  std::vector<std::string> branches;
218 
220 };
221 //-----------------------------------------------------------------------------
222 //-----------------------------------------------------------------------------
223 class IndexSetDataDir : public SphinxAdminCommand //TODO
224 {
225 public:
227  virtual ~IndexSetDataDir(void) {};
228 
229  bool serialize(std::string& json);
230  bool unserialize(const std::string& json);
231  bool execute(void);
232 
234 };
235 //-----------------------------------------------------------------------------
236 //-----------------------------------------------------------------------------
237 class IndexStart : public IndexCreate
238 {
239 public:
241  virtual ~IndexStart(void) {};
242 
243  bool execute(void);
244 
246 };
247 //-----------------------------------------------------------------------------
248 //-----------------------------------------------------------------------------
249 class IndexStop : public IndexCreate
250 {
251 public:
253  virtual ~IndexStop(void) {};
254 
255  bool execute(void);
256 
258 };
259 //-----------------------------------------------------------------------------
260 //-----------------------------------------------------------------------------
261 class IndexMerge : public IndexRebuild
262 {
263 protected:
264  bool makeMerge(const std::string& branchName,
265  const std::string& configPath,
266  const std::string& trunkName,
267  unsigned long long& maxDocId);
268  bool makeTrunk(const std::string& trunkName,
269  const std::string& configPath,
270  std::vector<std::string>& vIndexes,
271  unsigned long long& maxDocId) throw (Poco::Exception);
272 public:
274  virtual ~IndexMerge(void) {};
275 
276  bool execute(void);
277 
279 };
280 //-----------------------------------------------------------------------------
281 //-----------------------------------------------------------------------------
283 {
284 public:
286  virtual ~IndexMergeTrunk(void) {};
287 
288  bool execute(void);
289 
291 };
292 //-----------------------------------------------------------------------------
293 //-----------------------------------------------------------------------------
295 {
296  bool removeIndexFiles(const std::string& path, std::vector<std::string>& branches, std::vector<std::string>& files) throw (Poco::Exception);
297  bool removeFilesList(const std::string& path, std::vector<std::string>& branches, std::vector<std::string>& files, const std::string& ext) throw (Poco::Exception);
298 public:
300  virtual ~IndexDeleteDataFile(void) {};
301 
302  bool execute(void);
303 
305 };
306 //-----------------------------------------------------------------------------
307 //-----------------------------------------------------------------------------
309 {
310 public:
312  virtual ~IndexDeleteSchemaFile(void) {};
313 
314  bool execute(void);
315 
317 };
318 //-----------------------------------------------------------------------------
319 //-----------------------------------------------------------------------------
321 {
322 public:
324  virtual ~IndexAppendDataFile(void) {};
325 
326  bool execute(void);
327 
329 };
330 //-----------------------------------------------------------------------------
331 //-----------------------------------------------------------------------------
333 {
334 public:
336  virtual ~IndexDeleteDoc(void) {};
337 
338  bool serialize(std::string& json);
339  bool unserialize(const std::string& json);
340  bool execute(void);
341 
342  void addId(unsigned long long id);
343  std::vector <unsigned long long>& getIds(void) {return ids;}
344 private:
345  std::vector <unsigned long long> ids;
346  typedef IndexCreate inherited;
347 };
348 //-----------------------------------------------------------------------------
349 //-----------------------------------------------------------------------------
351 {
352 public:
354  virtual ~IndexDeleteDocNumber(void) {};
355 
356  bool execute(void);
357 
359 };
360 //-----------------------------------------------------------------------------
361 //-----------------------------------------------------------------------------
363 {
364  bool packData(const std::string& file, std::set<std::string>& delList);
365  bool getDocumentCount(const std::string& file, size_t& documentCount);
366 public:
368  virtual ~IndexPackDocData(void) {};
369 
370  bool execute(void);
371 
373 };
374 //-----------------------------------------------------------------------------
375 //-----------------------------------------------------------------------------
376 class IndexRemove : public IndexCreate
377 {
378 public:
380  virtual ~IndexRemove(void) {};
381 
382  bool execute(void);
383 
385 };
386 //-----------------------------------------------------------------------------
387 //-----------------------------------------------------------------------------
389 {
390 public:
392  virtual ~IndexCopy(void) {};
393 
394  bool serialize(std::string& json);
395  bool unserialize(const std::string& json);
396  bool execute(void);
397 
398  void setIndexFromName(const std::string& indexFromName_) {indexFromName=indexFromName_;}
399  std::string getIndexFromName(void) const {return indexFromName;}
400 
401  void setIndexToName(const std::string& indexToName_) {indexToName=indexToName_;}
402  std::string getIndexToName(void) const {return indexToName;}
403 
404 protected:
405  std::string indexFromName;
406  std::string indexToName;
407 
409 };
410 //-----------------------------------------------------------------------------
411 //-----------------------------------------------------------------------------
412 class IndexRename : public IndexCopy
413 {
414 public:
416  virtual ~IndexRename(void) {};
417 
418  bool execute(void);
419 
421 };
422 //-----------------------------------------------------------------------------
423 //-----------------------------------------------------------------------------
425 {
426 public:
428  virtual ~IndexSetConfigVar(void) {};
429 
430  bool serialize(std::string& json);
431  bool unserialize(const std::string& json);
432  bool execute(void);
433 
434  void setIndexName(const std::string& indexName_) {indexName=indexName_;}
435  std::string getIndexName(void) const {return indexName;}
436 
437  void setBranchName(const std::string& branchName_) {branchName=branchName_;}
438  std::string getBranchName(void) const {return branchName;}
439 
440  void setSectionName(const std::string& sectionName_) {sectionName=sectionName_;}
441  std::string getSectionName(void) const {return sectionName;}
442 
443  void setParameterName(const std::string& parameterName_) {parameterName=parameterName_;}
444  std::string getParameterName(void) const {return parameterName;}
445 
446  void setParameterValue(const std::string& parameterValue_) {parameterValue=parameterValue_;}
447  std::string getParameterValue(void) const {return parameterValue;}
448 
449 protected:
450  std::string indexName;
451  std::string branchName;
452  std::string sectionName;
453  std::string parameterName;
454 private:
455  std::string parameterValue;
456 
458 };
459 //-----------------------------------------------------------------------------
460 //-----------------------------------------------------------------------------
462 {
463 public:
465  virtual ~IndexGetConfigVar(void) {};
466 
467  bool serialize(std::string& json);
468  bool unserialize(const std::string& json);
469  bool execute(void);
470 
472 };
473 //-----------------------------------------------------------------------------
474 //-----------------------------------------------------------------------------
476 {
477 public:
479  virtual ~IndexCheckSchema(void) {};
480 
481  bool execute(void);
482 
484 };
485 //-----------------------------------------------------------------------------
486 //-----------------------------------------------------------------------------
488 {
489 public:
491  virtual ~IndexStatusSearchd(void) {};
492 
493  bool execute(void);
494  bool isExistPidFile(void);
495 
497 };
498 //-----------------------------------------------------------------------------
499 //-----------------------------------------------------------------------------
500 class IndexStatus : public IndexCreate
501 {
502 public:
504  virtual ~IndexStatus(void) {};
505 
506  bool execute(void);
507 
509 };
510 //-----------------------------------------------------------------------------
511 //-----------------------------------------------------------------------------
513 {
514 public:
516  virtual ~IndexMaxDocId(void) {};
517 
518  bool execute(void);
519 
521 };
522 //-----------------------------------------------------------------------------
523 //-----------------------------------------------------------------------------
525 {
526 public:
528  virtual ~IndexDataList(void) {};
529 
530  bool execute(void);
531 
533 };
534 //-----------------------------------------------------------------------------
535 //-----------------------------------------------------------------------------
537 {
538 public:
540  virtual ~IndexBranchesList(void) {};
541 
542  bool execute(void);
543 
545 };
546 //-----------------------------------------------------------------------------
547 //-----------------------------------------------------------------------------
549 {
550 public:
552  virtual ~IndexBranchesInfo(void) {};
553 
554  bool execute(void);
555 protected:
556  bool getBranchInfo(const std::string& branchName, const std::string& path, std::string& branchFieldsList);
557 
559 };
560 //-----------------------------------------------------------------------------
561 //-----------------------------------------------------------------------------
563 {
564 public:
566  virtual ~IndexBranchesStatus(void) {};
567 
568  bool execute(void);
569 protected:
570  bool getBranchInfo(const std::string& indexName, const std::string& indexFileName, std::string& information);
571  bool makeBranchConfig(const std::string& indexName, const std::string& indexFileName, std::string& branchConfigFileName);
572 
574 };
575 //-----------------------------------------------------------------------------
576 //-----------------------------------------------------------------------------
577 class IndexConnect : public IndexCreate
578 {
579 public:
581  virtual ~IndexConnect(void) {};
582 
583  bool execute(void);
584 
586 };
587 //-----------------------------------------------------------------------------
588 //-----------------------------------------------------------------------------
590 {
591 public:
593  virtual ~IndexDisconnect(void) {};
594 
595  bool serialize(std::string& json);
596  bool unserialize(const std::string& json);
597  bool execute(void);
598 
600 };
601 //-----------------------------------------------------------------------------
602 //-----------------------------------------------------------------------------
603 } // end namespace sphinx
604 } // end namespace HCE
605 
606 #endif // SPHINX_ADMIN_COMMAND_HPP