ArchiveJob.hpp 4.31 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
#pragma once

21
22
#include "common/exception/Exception.hpp"
#include "common/remoteFS/RemotePathAndStatus.hpp"
23
#include "scheduler/SchedulerDatabase.hpp"
24
#include "catalogue/Catalogue.hpp"
25
26

#include <stdint.h>
27
#include <string>
28
#include <future>
29
30

namespace cta {
31
32
33

// Forward declaration
class ArchiveMount;
34
35
36
37

/**
 * Class representing the transfer of a single copy of a remote file to tape.
 */
38
class ArchiveJob {
39
40

  /**
Steven Murray's avatar
Steven Murray committed
41
42
   * The ArchiveMount class is a friend so that it can call the private
   * constructor of ArchiveJob.
43
   */
Steven Murray's avatar
Steven Murray committed
44
45
  friend class ArchiveMount;

46
47
protected:
  /**
48
49
50
51
52
53
   * Constructor.
   * 
   * @param mount the mount that generated this job
   * @param archiveFile informations about the file that we are storing
   * @param remotePathAndStatus location and properties of the remote file
   * @param tapeFileLocation the location within the tape
54
   */
55
56
  ArchiveJob(
  ArchiveMount &mount,
57
  catalogue::Catalogue & catalogue,
58
  const common::dataStructures::ArchiveFile &archiveFile,
59
  const std::string &srcURL,
60
  const common::dataStructures::TapeFile &tapeFile);
Steven Murray's avatar
Steven Murray committed
61
62
63
64
65
66

public:

  /**
   * Destructor.
   */
67
68
69
70
  virtual ~ArchiveJob() throw();
  
  CTA_GENERATE_EXCEPTION_CLASS(BlockIdNotSet);
  CTA_GENERATE_EXCEPTION_CLASS(ChecksumNotSet);
71
  CTA_GENERATE_EXCEPTION_CLASS(ChecksumMismatch);
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  
  /**
   * Indicates that the job was successful and updates the backend store 
   * asynchronously. 
   */
  virtual void asyncSetJobSucceed();
  
  /**
   * Wait if the job was updated in the backend store asynchronously. 
   * @return true if the archive was also sent to client asynchronously.
   */
  virtual bool checkAndAsyncReportComplete();
  
  /**
   * Validate that archiveFile and tapeFile fields are set correctly for archive
   * request.
   * Throw appropriate exception if there is any problem.
   */
  virtual void validate();
  
  /**
   * Update the catalog with the archive request.
   */
  virtual void writeToCatalogue();
  
97
  /**
98
99
100
   * Validate that archiveFile and tapeFile fields are set correctly for archive
   * request.
   * @return The tapeFileWritten event for the catalog update.
101
   */
102
  virtual catalogue::TapeFileWritten validateAndGetTapeFileWritten();
103
  
Steven Murray's avatar
Steven Murray committed
104
  /**
105
106
107
108
109
110
111
112
   * Triggers a scheduler update following the failure of the job.
   * The reason for the failure should have been set beforehand by calling
   * setFailureReason(), but failure to do it is non-fatal (a standard error
   * reason will be used)
   * This 2 step approach allows the reason to be recorded fast in the 
   * tape writing thread, and the slow(er) update of the DB to be executed
   * in a second thread.
   *
Steven Murray's avatar
Steven Murray committed
113
   */
114
  virtual void failed(const cta::exception::Exception &ex, log::LogContext & lc);
115
  
116
117
118
119
120
121
  /**
   * Get the URL used for reporting
   * @return The URL used to report to the disk system.
   */
  virtual std::string reportURL();
  
122
123
private:
  std::unique_ptr<cta::SchedulerDatabase::ArchiveJob> m_dbJob;
124
125
126
127
  
  /**
   * The mount that generated this job
   */
128
  ArchiveMount &m_mount;
129

130
131
132
  /**
   * Reference to the name server
   */
133
  catalogue::Catalogue &m_catalogue;
134
  
135
136
137
138
139
140
141
  /**
   * State for the asynchronous report to the client. 
   */
  std::promise<void> m_reporterState;
      
public:
    
142
  CTA_GENERATE_EXCEPTION_CLASS(NotImplemented);
143
144
145
146
  
  /**
   * The NS archive file information
   */
147
  common::dataStructures::ArchiveFile archiveFile;
148
149
150
151
  
  /**
   * The remote file information
   */
152
  std::string srcURL;
153
  
154
  /**
155
   * The file archive result for the NS
156
   */
157
  common::dataStructures::TapeFile tapeFile;
158
159
160
161
162
  
  /**
   * Wait for the reporterState is set by the reporting thread.
   */
  virtual void waitForReporting();
Steven Murray's avatar
Steven Murray committed
163

164
}; // class ArchiveJob
165
166

} // namespace cta