ArchiveRequest.hpp 5.15 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

/*
 * 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/>.
 */

#pragma once

22
#include "common/dataStructures/DiskFileInfo.hpp"
23
#include "common/dataStructures/EntryLog.hpp"
24
#include "common/dataStructures/MountPolicy.hpp"
25
#include "common/dataStructures/UserIdentity.hpp"
26
#include "common/dataStructures/ArchiveFile.hpp"
27
28
29
30
31
32
33
34
35
#include "ObjectOps.hpp"
#include "objectstore/cta.pb.h"
#include <list>

namespace cta { namespace objectstore {
  
class Backend;
class Agent;
class GenericObject;
36
class EntryLogSerDeser;
37

38
class ArchiveRequest: public ObjectOps<serializers::ArchiveRequest, serializers::ArchiveRequest_t> {
39
40
41
42
43
44
45
public:
  ArchiveRequest(const std::string & address, Backend & os);
  ArchiveRequest(Backend & os);
  ArchiveRequest(GenericObject & go);
  void initialize();
  // Job management ============================================================
  void addJob(uint16_t copyNumber, const std::string & tapepool,
46
    const std::string & archivequeueaddress, uint16_t maxRetiesWithinMount, uint16_t maxTotalRetries);
47
48
49
  void setJobSelected(uint16_t copyNumber, const std::string & owner);
  void setJobPending(uint16_t copyNumber);
  bool setJobSuccessful(uint16_t copyNumber); //< returns true if this is the last job
50
  bool addJobFailure(uint16_t copyNumber, uint64_t sessionId); //< returns true the job is failed
51
  serializers::ArchiveJobStatus getJobStatus(uint16_t copyNumber);
52
53
  bool finishIfNecessary();                   /**< Handling of the consequences of a job status change for the entire request.
                                               * This function returns true if the request got finished. */
54
  // Mark all jobs as pending mount (following their linking to a tape pool)
55
  void setAllJobsLinkingToArchiveQueue();
56
57
58
59
60
  // Mark all the jobs as being deleted, in case of a cancellation
  void setAllJobsFailed();
  CTA_GENERATE_EXCEPTION_CLASS(NoSuchJob);
  // Set a job ownership
  void setJobOwner(uint16_t copyNumber, const std::string & owner);
61
62
63
64
65
  // An asynchronous job ownership updating class.
  class AsyncJobOwnerUpdater {
    friend class ArchiveRequest;
  public:
    void wait();
66
67
68
    const common::dataStructures::ArchiveFile & getArchiveFile();
    const std::string & getSrcURL();
    const std::string & getArchiveReportURL();
69
  private:
70
    std::function<std::string(const std::string &)> m_updaterCallback;
71
    std::unique_ptr<Backend::AsyncUpdater> m_backendUpdater;
72
73
74
    common::dataStructures::ArchiveFile m_archiveFile;
    std::string m_srcURL;
    std::string m_archiveReportURL;
75
76
77
78
  };
  // An job owner updater factory. The owner MUST be previousOwner for the update to be executed.
  CTA_GENERATE_EXCEPTION_CLASS(WrongPreviousOwner);
  AsyncJobOwnerUpdater * asyncUpdateJobOwner(uint16_t copyNumber, const std::string & owner, const std::string &previousOwner);
79
80
81
82
83
84
85
86
87
88
89
90
91

  // An asynchronous job updating class for success.
  class AsyncJobSuccessfulUpdater {
    friend class ArchiveRequest;
  public:
    void wait();
    bool m_isLastJob;
  private:
    std::function<std::string(const std::string &)> m_updaterCallback;
    std::unique_ptr<Backend::AsyncUpdater> m_backendUpdater;
  };
  AsyncJobSuccessfulUpdater * asyncUpdateJobSuccessful(uint16_t copyNumber);

92
93
  // Get a job owner
  std::string getJobOwner(uint16_t copyNumber);
94
95
96
97
  // Request management ========================================================
  void setSuccessful();
  void setFailed();
  // ===========================================================================
98
99
100
  // TODO: ArchiveFile comes with extraneous information. 
  void setArchiveFile(const cta::common::dataStructures::ArchiveFile& archiveFile);
  cta::common::dataStructures::ArchiveFile getArchiveFile();
101
102
103
  
  void setArchiveReportURL(const std::string &URL);
  std::string getArchiveReportURL();
104

105
106
  void setRequester(const cta::common::dataStructures::UserIdentity &requester);
  cta::common::dataStructures::UserIdentity getRequester();
107
108
109
110

  void setSrcURL(const std::string &srcURL);
  std::string getSrcURL();

111
112
  void setEntryLog(const cta::common::dataStructures::EntryLog &creationLog);
  cta::common::dataStructures::EntryLog getEntryLog();
113
  
114
115
116
  void setMountPolicy(const cta::common::dataStructures::MountPolicy &mountPolicy);
  cta::common::dataStructures::MountPolicy getMountPolicy();
  
117
118
119
120
  class JobDump {
  public:
    uint16_t copyNb;
    std::string tapePool;
121
    std::string owner;
122
123
124
  };
  
  std::list<JobDump> dumpJobs();
125
126
  void garbageCollect(const std::string &presumedOwner, AgentReference & agentReference, log::LogContext & lc,
    cta::catalogue::Catalogue & catalogue) override;
127
128
129
130
  std::string  dump();
};

}}