RootEntry.hpp 7.69 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
21
22
#pragma once

#include "objectstore/cta.pb.h"

23
#include "Backend.hpp"
24
#include "ObjectOps.hpp"
25
26
#include "CreationLog.hpp"
#include "UserIdentity.hpp"
27
#include "common/MountControl.hpp"
28
#include <list>
29

30
31
namespace cta { namespace objectstore {

32
class Agent;
33
class GenericObject;
34
  
35
class RootEntry: public ObjectOps<serializers::RootEntry, serializers::RootEntry_t> {
36
public:
37
  // Constructor
38
  RootEntry(Backend & os);
39
  RootEntry(GenericObject & go);
40
  
41
  CTA_GENERATE_EXCEPTION_CLASS(NotAllocated);
Eric Cano's avatar
Eric Cano committed
42
  CTA_GENERATE_EXCEPTION_CLASS(NotEmpty);
43
  
44
45
46
  // In memory initialiser
  void initialize();
  
Eric Cano's avatar
Eric Cano committed
47
48
49
50
51
52
  // Emptyness checker
  bool isEmpty();
  
  // Safe remover
  void removeIfEmpty();
  
53
  // Manipulations of AdminHosts ===============================================
54
  void addAdminHost(const std::string & hostname, const CreationLog & log);
55
  CTA_GENERATE_EXCEPTION_CLASS(NoSuchAdminHost);
56
57
58
59
60
61
62
63
  void removeAdminHost(const std::string & hostname);
  bool isAdminHost(const std::string & hostname);
  class AdminHostDump {
  public:
    std::string hostname;
    CreationLog log;
  };
  std::list<AdminHostDump> dumpAdminHosts();
64
  
65
  CTA_GENERATE_EXCEPTION_CLASS(DuplicateEntry);
66
  
67
  // Manipulations of Admin Users ==============================================
68
  void addAdminUser(const UserIdentity & user, const CreationLog & log);
69
  CTA_GENERATE_EXCEPTION_CLASS(NoSuchAdminUser);
70
71
72
73
74
75
76
77
78
  void removeAdminUser(const UserIdentity & user);
  bool isAdminUser(const UserIdentity & user);
  class AdminUserDump {
  public:
    UserIdentity user;
    CreationLog log;
  };
  std::list<AdminUserDump> dumpAdminUsers();
  
79
  // Manipulations of Storage Classes and archive routes =======================
80
81
82
  CTA_GENERATE_EXCEPTION_CLASS(MissingEntry);
  CTA_GENERATE_EXCEPTION_CLASS(IncompleteEntry);
  CTA_GENERATE_EXCEPTION_CLASS(NoSuchStorageClass);
83
  CTA_GENERATE_EXCEPTION_CLASS(StorageClassHasActiveRoutes);
84
85
86
87
88
  CTA_GENERATE_EXCEPTION_CLASS(InvalidCopyNumber);
  CTA_GENERATE_EXCEPTION_CLASS(CopyNumberOutOfRange);
private:
  // Totally arbitrary (but ridiculously high) copy number
  static const uint16_t maxCopyCount=100;
89
  void checkStorageClassCopyCount(uint16_t copyCount);
90
91
92
public:
  void addStorageClass(const std::string storageClass, uint16_t copyCount, 
    const CreationLog & log);
93
  void removeStorageClass(const std::string storageClass);
94
95
96
  void setStorageClassCopyCount(const std::string & storageClass,
    uint16_t copyCount, const CreationLog & cl);
  uint16_t getStorageClassCopyCount(const std::string & storageClass);
97
  CTA_GENERATE_EXCEPTION_CLASS(ArchiveRouteAlreadyExists);
98
  CTA_GENERATE_EXCEPTION_CLASS(TapePoolUsedInOtherRoute);
99
  void addArchiveRoute(const std::string & storageClass, uint16_t copyNb, 
100
    const std::string & tapePool, const CreationLog & cl);
101
102
  CTA_GENERATE_EXCEPTION_CLASS(NoSuchArchiveRoute);
  void removeArchiveRoute(const std::string & storageClass, uint16_t copyNb);
103

104
  /** Ordered vector of archive routes */
105
  std::vector<std::string> getArchiveRoutes (const std::string storageClass);
106
107
  class StorageClassDump {
  public:
108
    class ArchiveRouteDump {
109
110
111
112
113
114
115
    public:
      uint16_t copyNumber;
      std::string tapePool;
      CreationLog log;
    };
    std::string storageClass;
    uint16_t copyCount;
116
    std::list<ArchiveRouteDump> routes;
117
    CreationLog log;
118
119
  };
  std::list<StorageClassDump> dumpStorageClasses();
120
  StorageClassDump dumpStorageClass(const std::string & name);
121
  
122
  // Manipulations of libraries ================================================
123
  void addLibrary(const std::string & library, const CreationLog & log);
124
  CTA_GENERATE_EXCEPTION_CLASS(NoSuchLibrary);
125
126
  void removeLibrary(const std::string & library);
  bool libraryExists(const std::string & library);
127
128
129
130
131
132
  class LibraryDump {
  public:
    std::string library;
    CreationLog log;
  };
  std::list<LibraryDump> dumpLibraries();
133
  
134
  // TapePool Manipulations =====================================================
135
136
  CTA_GENERATE_EXCEPTION_CLASS(TapePoolNotEmpty);
  CTA_GENERATE_EXCEPTION_CLASS(WrongTapePool);
137
  /** This function implicitly creates the tape pool structure and updates 
138
   * the pointer to it. It needs to implicitly commit the object to the store. */
139
  std::string addOrGetTapePoolAndCommit(const std::string & tapePool,
140
141
    uint32_t nbPartialTapes, uint16_t maxRetriesPerMount, uint16_t maxTotalRetries,
    Agent & agent, const CreationLog & log);
142
143
  /** This function implicitly deletes the tape pool structure. 
   * Fails if it not empty*/
144
145
  CTA_GENERATE_EXCEPTION_CLASS(NoSuchTapePool);
  CTA_GENERATE_EXCEPTION_CLASS(TapePoolUsedInRoute);
Eric Cano's avatar
Eric Cano committed
146
  void removeTapePoolAndCommit(const std::string & tapePool);
147
  std::string getTapePoolAddress(const std::string & tapePool);
148
149
150
151
  class TapePoolDump {
  public:
    std::string tapePool;
    std::string address;
152
    uint32_t nbPartialTapes;
153
    MountCriteriaByDirection mountCriteriaByDirection;
154
155
    CreationLog log;
  };
156
  std::list<TapePoolDump> dumpTapePools();
157
  
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
  // TapePoolQueue Manipulations =====================================================
  CTA_GENERATE_EXCEPTION_CLASS(TapePoolQueueNotEmpty);
  CTA_GENERATE_EXCEPTION_CLASS(WrongTapePoolQueue);
  /** This function implicitly creates the tape pool structure and updates 
   * the pointer to it. It needs to implicitly commit the object to the store. */
  std::string addOrGetTapePoolQueueAndCommit(const std::string & tapePool, Agent & agent);
  /** This function implicitly deletes the tape pool structure. 
   * Fails if it not empty*/
  CTA_GENERATE_EXCEPTION_CLASS(NoSuchTapePoolQueue);
  void removeTapePoolQueueAndCommit(const std::string & tapePool);
  std::string getTapePoolQueueAddress(const std::string & tapePool);
  class TapePoolQueueDump {
  public:
    std::string tapePool;
    std::string address;
  };
  std::list<TapePoolQueueDump> dumpTapePoolQueues();
  
176
  // Drive register manipulations ==============================================
Eric Cano's avatar
Eric Cano committed
177
178
179
180
  CTA_GENERATE_EXCEPTION_CLASS(DriveRegisterNotEmpty);
  std::string getDriveRegisterAddress();  
  std::string addOrGetDriveRegisterPointerAndCommit(Agent & agent, const CreationLog & log);
  void removeDriveRegisterAndCommit();
181
  
182
  // Agent register manipulations ==============================================
183
184
  CTA_GENERATE_EXCEPTION_CLASS(AgentRegisterNotEmpty);
  std::string getAgentRegisterAddress();
185
186
  /** We do pass the agent here even if there is no agent register yet, as it
   * is used to generate the object name. We have the dedicated agent intent
187
188
189
190
   * log for tracking objects being created. We already use an agent here for
   * object name generation, but not yet tracking. */
  std::string addOrGetAgentRegisterPointerAndCommit(Agent & agent,
    const CreationLog & log);
Eric Cano's avatar
Eric Cano committed
191
  void removeAgentRegisterAndCommit();
192

193
194
195
196
197
  // Agent register manipulations ==============================================
  std::string getSchedulerGlobalLock();
  std::string addOrGetSchedulerGlobalLockAndCommit(Agent & agent, const CreationLog & log);
  void removeSchedulerGlobalLockAndCommit();
  
198
private:
199
  void addIntendedAgentRegistry(const std::string & address);
200
  
201
public:
202
  // Dump the root entry
203
  std::string dump ();
204
205
};

206
207
}}

208