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