XRootD
XrdClTPFallBackCopyJob.cc
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2014 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // This file is part of the XRootD software suite.
6 //
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // In applying this licence, CERN does not waive the privileges and immunities
21 // granted to it by virtue of its status as an Intergovernmental Organization
22 // or submit itself to any jurisdiction.
23 //------------------------------------------------------------------------------
24 
29 #include "XrdCl/XrdClConstants.hh"
30 #include "XrdCl/XrdClLog.hh"
31 #include "XrdCl/XrdClDefaultEnv.hh"
32 #include <optional>
33 #include <string>
34 
35 using namespace std::string_literals;
36 
37 namespace XrdCl
38 {
39  namespace
40  {
41  //--------------------------------------------------------------------------
47  //--------------------------------------------------------------------------
48  class PlugInProgressHandler final : public ProgressHandler
49  {
50  public:
51  PlugInProgressHandler( uint32_t job_id,
52  CopyProgressHandler &progress ):
53  progress( progress ),
54  job_id( job_id )
55  {
56  }
57 
58  void HandleProgress( std::size_t processed,
59  std::size_t total ) override
60  {
61  if( total )
62  this->total = total;
63 
64  progress.JobProgress( job_id, processed, this->total );
65  }
66 
67  private:
68  CopyProgressHandler &progress;
69  const uint32_t job_id;
70  std::size_t total = 0;
71  };
72  }
73 
74  //----------------------------------------------------------------------------
75  // Constructor
76  //----------------------------------------------------------------------------
77  TPFallBackCopyJob::TPFallBackCopyJob( uint32_t jobId,
78  PropertyList *jobProperties,
79  PropertyList *jobResults ):
80  CopyJob( jobId, jobProperties, jobResults )
81  {
82  Log *log = DefaultEnv::GetLog();
83  log->Debug( UtilityMsg, "Creating a third party fall back copy job, "
84  "from %s to %s", GetSource().GetObfuscatedURL().c_str(),
85  GetTarget().GetObfuscatedURL().c_str() );
86  }
87 
88  //----------------------------------------------------------------------------
89  // Destructor
90  //----------------------------------------------------------------------------
92 
93  //----------------------------------------------------------------------------
94  // Run the copy job
95  //----------------------------------------------------------------------------
97  {
98  //--------------------------------------------------------------------------
99  // Set up the job
100  //--------------------------------------------------------------------------
101  const bool tpcFallBack = pProperties->Get<std::string>( "thirdParty" ) == "first"s;
102 
104  if( st.IsOK() ) return st; // we are done
105 
106  // try with the plugins
107  if (st.code == errNotSupported)
108  {
109  std::optional<PlugInProgressHandler> progress_handler;
110  if( progress )
111  progress_handler.emplace( pJobId, *progress );
112 
114  progress_handler ? &progress_handler.value() : nullptr);
115  if (st.IsOK())
116  return st;
117  }
118 
119  // check if we can fall back to streaming
120  if( tpcFallBack && ( st.code == errNotSupported || st.code == errNotImplemented || st.code == errOperationExpired ) )
121  {
122  Log *log = DefaultEnv::GetLog();
123  log->Debug( UtilityMsg, "TPC is not supported, falling back to streaming mode." );
124 
125  return ClassicCopyJob(pJobId, pProperties, pResults).Run(progress);
126  }
127 
128  return st;
129  }
130 }
virtual XRootDStatus Run(CopyProgressHandler *progress=0)
PropertyList * pResults
const URL & GetSource() const
Get source.
Definition: XrdClCopyJob.hh:94
const URL & GetTarget() const
Get target.
PropertyList * pProperties
Interface for copy progress notification.
static Log * GetLog()
Get default log.
Handle diagnostics.
Definition: XrdClLog.hh:101
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
Definition: XrdClLog.cc:282
A key-value pair map storing both keys and values as strings.
bool Get(const std::string &name, Item &item) const
virtual ~TPFallBackCopyJob()
Destructor.
virtual XRootDStatus Run(CopyProgressHandler *progress=0)
virtual XRootDStatus Run(CopyProgressHandler *progress=0)
const uint16_t errOperationExpired
Definition: XrdClStatus.hh:90
const uint16_t errNotImplemented
Operation is not implemented.
Definition: XrdClStatus.hh:64
XRootDStatus ThirdPartyCopy(const URL &source, const URL &dest, const PropertyList *properties, ProgressHandler *progress_handler, time_t timeout)
const uint64_t UtilityMsg
const uint16_t errNotSupported
Definition: XrdClStatus.hh:62