LogicFileWrapper.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.cpp: implementation of the LogicFileWrapper class.
  14. //
  15. //////////////////////////////////////////////////////////////////////
  16. #include "LogicFileWrapper.hpp"
  17. #include "dautils.hpp"
  18. #include "exception_util.hpp"
  19. //////////////////////////////////////////////////////////////////////
  20. // Construction/Destruction
  21. //////////////////////////////////////////////////////////////////////
  22. #define REMOVE_FILE_SDS_CONNECT_TIMEOUT (1000*15) // 15 seconds
  23. LogicFileWrapper::LogicFileWrapper()
  24. {
  25. }
  26. LogicFileWrapper::~LogicFileWrapper()
  27. {
  28. }
  29. void LogicFileWrapper::FindClusterName(const char* logicalName, StringBuffer& returnCluster, IUserDescriptor* udesc)
  30. {
  31. try {
  32. Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(logicalName, udesc, false, false, false, nullptr, defaultPrivilegedUser) ;
  33. if(!df)
  34. throw MakeStringException(-1,"Could not find logical file");
  35. df->getClusterName(0,returnCluster); // ** TBD other cluster
  36. }
  37. catch(IException* e){
  38. StringBuffer msg;
  39. e->errorMessage(msg);
  40. IWARNLOG("%s", msg.str());
  41. e->Release();
  42. }
  43. catch(...){
  44. IWARNLOG("Unknown Exception thrown within LogicFileWrapper::FindClusterName");
  45. }
  46. }
  47. bool LogicFileWrapper::doDeleteFile(const char* logicalName,const char *cluster, StringBuffer& returnStr, IUserDescriptor* udesc)
  48. {
  49. CDfsLogicalFileName lfn;
  50. lfn.set(logicalName);
  51. StringBuffer cname;
  52. lfn.getCluster(cname);
  53. if (0 == cname.length()) // if has no cluster, use supplied cluster
  54. lfn.setCluster(cluster);
  55. lfn.get(cname.clear(), false, true); // get file@cluster form;
  56. try
  57. {
  58. IDistributedFileDirectory &fdir = queryDistributedFileDirectory();
  59. {
  60. Owned<IDistributedFile> df = fdir.lookup(cname.str(), udesc, true, false, false, nullptr, defaultPrivilegedUser) ;
  61. if(!df)
  62. {
  63. returnStr.appendf("<Message><Value>File %s not found</Value></Message>", cname.str());
  64. return false;
  65. }
  66. }
  67. fdir.removeEntry(cname.str(), udesc, NULL, REMOVE_FILE_SDS_CONNECT_TIMEOUT, true);
  68. returnStr.appendf("<Message><Value>Deleted File %s</Value></Message>", cname.str());
  69. return true;
  70. }
  71. catch (IException *e)
  72. {
  73. StringBuffer errorMsg;
  74. e->errorMessage(returnStr);
  75. e->Release();
  76. PROGLOG("%s", errorMsg.str());
  77. returnStr.appendf("<Message><Value>Failed to delete File %s, error: %s</Value></Message>", cname.str(), errorMsg.str());
  78. }
  79. return false;
  80. }
  81. IDistributedFile* lookupLogicalName(IEspContext& context, const char* logicalName, bool writeattr, bool hold,
  82. bool lockSuperOwner, IDistributedFileTransaction* transaction, bool privilegedUser, unsigned timeout)
  83. {
  84. StringBuffer userID;
  85. context.getUserID(userID);
  86. Owned<IUserDescriptor> userDesc;
  87. if (!userID.isEmpty())
  88. {
  89. userDesc.setown(createUserDescriptor());
  90. userDesc->set(userID, context.queryPassword(), context.querySignature());
  91. }
  92. Owned<IDistributedFile> df = queryDistributedFileDirectory().lookup(logicalName, userDesc, writeattr,
  93. hold, lockSuperOwner, transaction, privilegedUser, timeout);
  94. return df.getClear();
  95. }
  96. void getNodeGroupFromLFN(IEspContext& context, const char* lfn, StringBuffer& nodeGroup)
  97. {
  98. Owned<IDistributedFile> df = lookupLogicalName(context, lfn, false, false, false, nullptr, defaultPrivilegedUser);
  99. if (!df)
  100. throw makeStringExceptionV(ECLWATCH_FILE_NOT_EXIST, "Failed to find file: %s", lfn);
  101. df->getClusterGroupName(0, nodeGroup);
  102. }