ArchiveJob.hpp 3.48 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/archiveNS/TapeFileLocation.hpp"
#include "common/archiveNS/ArchiveFile.hpp"
23
24
#include "common/exception/Exception.hpp"
#include "common/remoteFS/RemotePathAndStatus.hpp"
25
26
#include "scheduler/SchedulerDatabase.hpp"
#include "nameserver/NameServer.hpp"
27
28

#include <stdint.h>
29
30
31
#include <string>

namespace cta {
32
33
34

// Forward declaration
class ArchiveMount;
35
36
37
38

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

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

47
protected:
48
  
49
  /**
50
   * Empty constructor. TODO: to be removed in the future when we put in the reference to the owning mount;
51
   */
52
  //ArchiveJob(): m_mount(*((ArchiveMount*)NULL)), m_ns(*((NameServer*)NULL)){}
53
  
54
  /**
55
56
57
58
59
60
   * 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
61
   */
62
63
64
  ArchiveJob(
  ArchiveMount &mount,
  NameServer & ns,
65
66
  const ArchiveFile &archiveFile,
  const RemotePathAndStatus &remotePathAndStatus,
67
  const NameServerTapeFile &nameServerTapeFile);
Steven Murray's avatar
Steven Murray committed
68
69
70
71
72
73

public:

  /**
   * Destructor.
   */
74
75
76
77
  virtual ~ArchiveJob() throw();
  
  CTA_GENERATE_EXCEPTION_CLASS(BlockIdNotSet);
  CTA_GENERATE_EXCEPTION_CLASS(ChecksumNotSet);
78
  /**
79
   * Indicates that the job was successful and updates the backend store
Steven Murray's avatar
Steven Murray committed
80
   *
81
   */
82
83
  virtual void complete();
  
Steven Murray's avatar
Steven Murray committed
84
  /**
85
86
87
88
89
90
91
92
   * 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
93
   */
94
  virtual void failed(const cta::exception::Exception &ex);
Steven Murray's avatar
Steven Murray committed
95

96
  /**
97
98
   * Indicates that the job should be tried again (typically reaching the end 
   * of the tape).
99
   */
100
  virtual void retry();
101
  
102
103
private:
  std::unique_ptr<cta::SchedulerDatabase::ArchiveJob> m_dbJob;
104
105
106
107
  
  /**
   * The mount that generated this job
   */
108
109
110
111
112
113
114
115
116
  ArchiveMount &m_mount;
  
  /**
   * Reference to the name server
   */
  NameServer &m_ns;
public:
  
  CTA_GENERATE_EXCEPTION_CLASS(NotImplemented);
117
118
119
120
121
122
123
124
125
126
  
  /**
   * The NS archive file information
   */
  ArchiveFile archiveFile;
  
  /**
   * The remote file information
   */
  RemotePathAndStatus remotePathAndStatus; 
127
  
128
  /**
129
   * The file archive result for the NS
130
   */
131
  NameServerTapeFile nameServerTapeFile;
Steven Murray's avatar
Steven Murray committed
132

133
}; // class ArchiveJob
134
135

} // namespace cta