LogicFileWrapper.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. // LogicFileWrapper.h: interface for the LogicFileWrapper class.
  14. //
  15. //////////////////////////////////////////////////////////////////////
  16. #ifndef __DFUWrapper_HPP__
  17. #define __DFUWrapper_HPP__
  18. #ifdef SMCLIB_EXPORTS
  19. #define LFWRAPPER_API DECL_EXPORT
  20. #else
  21. #define LFWRAPPER_API DECL_IMPORT
  22. #endif
  23. #include "jiface.hpp"
  24. #include "jstring.hpp"
  25. #include "dadfs.hpp"
  26. #include "daft.hpp"
  27. #include "dalienv.hpp"
  28. #include "jpqueue.hpp"
  29. class LFWRAPPER_API LogicFileWrapper : public CInterface
  30. {
  31. public:
  32. IMPLEMENT_IINTERFACE;
  33. LogicFileWrapper();
  34. virtual ~LogicFileWrapper();
  35. bool doDeleteFile(const char* name, const char *cluster, StringBuffer& returnStr, IUserDescriptor* udesc = NULL);
  36. bool doCompressFile(const char* name,StringBuffer& returnStr, IUserDescriptor* udesc = 0);
  37. void FindClusterName(const char* logicalName,StringBuffer& returnCluster, IUserDescriptor* udesc = 0);
  38. };
  39. struct ErrorReceiver: public CInterface, implements IErrorListener
  40. {
  41. IMPLEMENT_IINTERFACE;
  42. virtual void reportError(const char* err,...) __attribute__((format(printf,2,3)))
  43. {
  44. va_list args;
  45. va_start(args, err);
  46. buf.valist_appendf(err, args);
  47. va_end(args);
  48. }
  49. bool hasErrors()
  50. {
  51. return buf.length()!=0;
  52. }
  53. StringBuffer& getErrors(StringBuffer& err)
  54. {
  55. err.append(buf);
  56. return buf;
  57. }
  58. StringBuffer buf;
  59. };
  60. struct DeleteTask: public CInterface, implements ITask
  61. {
  62. IMPLEMENT_IINTERFACE;
  63. DeleteTask(IDistributedFilePart* _part): part(_part)
  64. {
  65. }
  66. virtual int run()
  67. {
  68. unsigned copies = part->numCopies();
  69. StringBuffer errs;
  70. for (unsigned copy = 0; copy < copies; copy++)
  71. {
  72. try
  73. {
  74. RemoteFilename r;
  75. OwnedIFile file = createIFile(part->getFilename(r, copy));
  76. if (!file->remove())
  77. {
  78. StringBuffer e;
  79. e.appendf("Failed to remove file part %s\n",file->queryFilename());
  80. LOG(MCerror, unknownJob, "%s", e.str());
  81. errs.append(e);
  82. }
  83. }
  84. catch(IException* e)
  85. {
  86. StringBuffer str;
  87. e->errorMessage(str);
  88. OERRLOG("%s",str.str());
  89. e->Release();
  90. }
  91. catch(...)
  92. {
  93. IERRLOG("Unknown Exception thrown while deleting file part\n");
  94. }
  95. }
  96. if(errs.length())
  97. throw MakeStringException(0, "%s", errs.str());
  98. return 0;
  99. }
  100. virtual bool stop()
  101. {
  102. return false;
  103. }
  104. Linked<IDistributedFilePart> part;
  105. };
  106. struct CompressTask: public CInterface, implements ITask
  107. {
  108. IMPLEMENT_IINTERFACE;
  109. CompressTask(IDistributedFilePart* _part): part(_part)
  110. {
  111. }
  112. virtual int run()
  113. {
  114. try
  115. {
  116. queryDistributedFileSystem().compress(part);
  117. }
  118. catch(IException* e)
  119. {
  120. StringBuffer err;
  121. e->errorMessage(err);
  122. LOG(MCerror, unknownJob, "%s", err.str());
  123. e->Release();
  124. }
  125. catch(...)
  126. {
  127. IERRLOG("Unknown Exception thrown\n");
  128. }
  129. return 0;
  130. }
  131. virtual bool stop()
  132. {
  133. return false;
  134. }
  135. Linked<IDistributedFilePart> part;
  136. };
  137. #endif //__DFUWrapper_HPP__