EOSReporter.cpp 3.08 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * The CERN Tape Archive (CTA) project
 * Copyright (C) 2015  CERN
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

19
20
#include <future>

21
22
23
#include "EOSReporter.hpp"
#include "common/exception/XrootCl.hpp"

24
namespace cta { namespace eos {
25

26
27
EOSReporter::EOSReporter(const std::string& hostURL, const std::string& queryValue, std::promise<void>& reporterState):
  m_fs(hostURL), m_query(queryValue), m_reporterState(reporterState) {}
28
29
30
31
32
33


void EOSReporter::reportArchiveFullyComplete() {
  auto qcOpaque = XrdCl::QueryCode::OpaqueFile;
  XrdCl::Buffer arg (m_query.size());
  arg.FromString(m_query);
34
  XrdCl::Buffer * resp = nullptr;
35
  XrdCl::XRootDStatus status=m_fs.Query(qcOpaque, arg, resp, CTA_EOS_QUERY_TIMEOUT);
36
37
  delete (resp);
  cta::exception::XrootCl::throwOnError(status,
38
      "In EOSReporter::reportArchiveFullyComplete(): failed to XrdCl::FileSystem::Query()");
39
} 
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
void EOSReporter::asyncReportArchiveFullyComplete() {
  auto qcOpaque = XrdCl::QueryCode::OpaqueFile;
  XrdCl::Buffer arg (m_query.size());
  arg.FromString(m_query);
  AsyncQueryHandler *handler = new AsyncQueryHandler(m_reporterState);
  XrdCl::XRootDStatus status=m_fs.Query( qcOpaque, arg, handler, CTA_EOS_QUERY_TIMEOUT);
  cta::exception::XrootCl::throwOnError(status,
      "In EOSReporter::asyncReportArchiveFullyComplete(): failed to XrdCl::FileSystem::Query()");
}

//------------------------------------------------------------------------------
//EOSReporter::AsyncQueryHandler::AsyncQueryHandler
//------------------------------------------------------------------------------
EOSReporter::AsyncQueryHandler::AsyncQueryHandler(std::promise<void> &handlerPromise):
  m_handlerPromise(handlerPromise) {}

//------------------------------------------------------------------------------
//EOSReporter::AsyncQueryHandler::HandleResponse
//------------------------------------------------------------------------------
void EOSReporter::AsyncQueryHandler::HandleResponse(XrdCl::XRootDStatus *status,
                                                    XrdCl::AnyObject    *response) {
  try {
    cta::exception::XrootCl::throwOnError(*status,
      "In EOSReporter::AsyncQueryHandler::HandleResponse(): failed to XrdCl::FileSystem::Query()");
  } catch (...) {
    try {
      // store anything thrown in the promise
      m_handlerPromise.set_exception(std::current_exception());
    } catch(...) {
      // set_exception() may throw too
    }
  }

  m_handlerPromise.set_value();
  delete response;
  delete status;
  delete this;
  }
79
}} // namespace cta::disk