LogicFileWrapper.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 _WIN32
  19. #ifdef SMCLIB_EXPORTS
  20. #define LFWRAPPER_API __declspec(dllexport)
  21. #else
  22. #define LFWRAPPER_API __declspec(dllimport)
  23. #endif
  24. #else
  25. #define LFWRAPPER_API
  26. #endif
  27. #include "jiface.hpp"
  28. #include "jstring.hpp"
  29. #include "dadfs.hpp"
  30. #include "daft.hpp"
  31. #include "dalienv.hpp"
  32. #include "jpqueue.hpp"
  33. class LFWRAPPER_API LogicFileWrapper : public CInterface
  34. {
  35. public:
  36. IMPLEMENT_IINTERFACE;
  37. LogicFileWrapper();
  38. virtual ~LogicFileWrapper();
  39. bool doDeleteFile(const char* name, const char *cluster, StringBuffer& returnStr, IUserDescriptor* udesc = NULL);
  40. bool doCompressFile(const char* name,StringBuffer& returnStr, IUserDescriptor* udesc = 0);
  41. void FindClusterName(const char* logicalName,StringBuffer& returnCluster, IUserDescriptor* udesc = 0);
  42. };
  43. struct ErrorReceiver: public CInterface, implements IErrorListener
  44. {
  45. IMPLEMENT_IINTERFACE;
  46. virtual void reportError(const char* err,...)
  47. {
  48. va_list args;
  49. va_start(args, err);
  50. buf.valist_appendf(err, args);
  51. va_end(args);
  52. }
  53. bool hasErrors()
  54. {
  55. return buf.length()!=0;
  56. }
  57. StringBuffer& getErrors(StringBuffer& err)
  58. {
  59. err.append(buf);
  60. return buf;
  61. }
  62. StringBuffer buf;
  63. };
  64. struct DeleteTask: public CInterface, implements ITask
  65. {
  66. IMPLEMENT_IINTERFACE;
  67. DeleteTask(IDistributedFilePart* _part): part(_part)
  68. {
  69. }
  70. virtual int run()
  71. {
  72. unsigned copies = part->numCopies();
  73. StringBuffer errs;
  74. for (unsigned copy = 0; copy < copies; copy++)
  75. {
  76. try
  77. {
  78. RemoteFilename r;
  79. OwnedIFile file = createIFile(part->getFilename(r, copy));
  80. if (!file->remove())
  81. {
  82. StringBuffer e;
  83. e.appendf("Failed to remove file part %s\n",file->queryFilename());
  84. LOG(MCerror, unknownJob, "%s", e.str());
  85. errs.append(e);
  86. }
  87. }
  88. catch(IException* e)
  89. {
  90. StringBuffer str;
  91. e->errorMessage(str);
  92. PrintLog(str.str());
  93. e->Release();
  94. }
  95. catch(...)
  96. {
  97. PrintLog("Unknown Exception thrown while deleteing file part\n");
  98. }
  99. }
  100. if(errs.length())
  101. throw MakeStringException(0, "%s", errs.str());
  102. return 0;
  103. }
  104. virtual bool stop()
  105. {
  106. return false;
  107. }
  108. Linked<IDistributedFilePart> part;
  109. };
  110. struct CompressTask: public CInterface, implements ITask
  111. {
  112. IMPLEMENT_IINTERFACE;
  113. CompressTask(IDistributedFilePart* _part): part(_part)
  114. {
  115. }
  116. virtual int run()
  117. {
  118. try
  119. {
  120. queryDistributedFileSystem().compress(part);
  121. }
  122. catch(IException* e)
  123. {
  124. StringBuffer err;
  125. e->errorMessage(err);
  126. LOG(MCerror, unknownJob, "%s", err.str());
  127. e->Release();
  128. }
  129. catch(...)
  130. {
  131. PrintLog("Unknown Exception thrown\n");
  132. }
  133. return 0;
  134. }
  135. virtual bool stop()
  136. {
  137. return false;
  138. }
  139. Linked<IDistributedFilePart> part;
  140. };
  141. #endif //__DFUWrapper_HPP__