RootEntry.hpp 6.65 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
27
#include "CreationLog.hpp"
#include "UserIdentity.hpp"
#include <list>
28

29
30
namespace cta { namespace objectstore {

31
32
class Agent;
  
33
class RootEntry: public ObjectOps<serializers::RootEntry> {
34
public:
35
36
  // construtor
  RootEntry(Backend & os);
37
38
39
  
  class NotAllocatedEx: public cta::exception::Exception {
  public:
40
    NotAllocatedEx(const std::string & w): cta::exception::Exception(w) {}
41
42
  };
  
43
44
45
  // In memory initialiser
  void initialize();
  
46
  // Manipulations of AdminHosts ===============================================
47
48
49
50
51
52
53
54
55
  void addAdminHost(const std::string & hostname, const CreationLog & log);
  void removeAdminHost(const std::string & hostname);
  bool isAdminHost(const std::string & hostname);
  class AdminHostDump {
  public:
    std::string hostname;
    CreationLog log;
  };
  std::list<AdminHostDump> dumpAdminHosts();
56
  
57
  CTA_GENERATE_EXCEPTION_CLASS(DuplicateEntry);
58
  
59
  // Manipulations of Admin Users ==============================================
60
61
62
63
64
65
66
67
68
69
  void addAdminUser(const UserIdentity & user, const CreationLog & log);
  void removeAdminUser(const UserIdentity & user);
  bool isAdminUser(const UserIdentity & user);
  class AdminUserDump {
  public:
    UserIdentity user;
    CreationLog log;
  };
  std::list<AdminUserDump> dumpAdminUsers();
  
70
71
72
73
74
75
76
77
78
  // Manipulations of Storage Classes and archival routes ======================
  CTA_GENERATE_EXCEPTION_CLASS(MissingEntry);
  CTA_GENERATE_EXCEPTION_CLASS(IncompleteEntry);
  CTA_GENERATE_EXCEPTION_CLASS(NoSuchStorageClass);
  CTA_GENERATE_EXCEPTION_CLASS(InvalidCopyNumber);
  CTA_GENERATE_EXCEPTION_CLASS(CopyNumberOutOfRange);
private:
  // Totally arbitrary (but ridiculously high) copy number
  static const uint16_t maxCopyCount=100;
79
  void checkStorageClassCopyCount(uint16_t copyCount);
80
81
82
public:
  void addStorageClass(const std::string storageClass, uint16_t copyCount, 
    const CreationLog & log);
83
  void removeStorageClass(const std::string storageClass);
84
85
86
  void setStorageClassCopyCount(const std::string & storageClass,
    uint16_t copyCount, const CreationLog & cl);
  uint16_t getStorageClassCopyCount(const std::string & storageClass);
87
88
89
  void setArchiveRoute(const std::string & storageClass, uint16_t copyNb, 
    const std::string & tapePool, const CreationLog & cl);

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  /** Ordered vector of archive routes */
  std::vector<std::string> getArchiveRoutes (const std::string storageClass);
  class StorageClassDump {
  public:
    class ArchiveRouteDump {
    public:
      uint16_t copyNumber;
      std::string tapePool;
      CreationLog log;
    };
    std::string storageClass;
    uint16_t copyCount;
    std::list<ArchiveRouteDump> routes;
  };
  std::list<StorageClassDump> dumpStorageClasses();
  
106
  // Manipulations of libraries ================================================
107
  void addLibrary(const std::string & library, const CreationLog & log);
108
109
110
111
  void removeLibrary(const std::string & library);
  bool libraryExists(const std::string & library);
  std::list<std::string> dumpLibraries();
  
112
  // TapePoolManipulations =====================================================
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  /** This function implicitly creates the tape pool structure and updates 
   * the pointer to it */
  void addTapePool(const std::string & tapePool, const CreationLog & log, Agent & agent);
  /** This function implicitly deletes the tape pool structure. 
   * Fails if it not empty*/
  void removeTapePool(const std::string & tapePool, Agent & agent);
  std::string getTapePoolPointer(const std::string & tapePool);
  class TapePoolDump {
  public:
    std::string tapePool;
    std::string address;
    CreationLog log;
  };
  std::list<TapePoolDump> dumpTapePool();
  
128
  // Drive register manipulations ==============================================
129
130
131
132
  std::string getDriveRegisterPointer();  
  std::string addOrGetDriveRegisterPointer(const CreationLog & log, Agent & agent);
  std::string removeDriveRegister();
  
133
  // Agent register manipulations ==============================================
134
135
136
137
138
139
  std::string getAgentRegisterPointer();
  /** 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
   * log for tracking objects being created. */
  std::string addOrGetAgentRegisterPointer(Agent & agent, const CreationLog & log);
  std::string removeAgentRegister();
140
141
142


private:
143
  void addIntendedAgentRegistry(const std::string & address);
144
  
145
  void deleteIntendedAgentRegistry();
146
  
147
  void setAgentRegistry(const std::string & address, const CreationLog & cl);
148
  
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//public:  
//  // Get the name of the JobPool (or exception if not available)
//  std::string getJobPool();
//  
//  // Get the name of a (possibly freshly created) job pool
//  std::string allocateOrGetJobPool(Agent & agent);
//  
//private:
//  void addIntendedJobPool(const std::string & name);
//  
//  void deleteFromIntendedJobPool(const std::string & name);
//  
//  void setJobPool(const std::string & name);

//public:  
//  // Get the name of the AdminUsersList (or exception if not available)
//  std::string getAdminUsersList();
//  
//  // Get the name of a (possibly freshly created) AdminUsersList
//  std::string allocateOrGetAdminUsersList(Agent & agent);
//  
//private:
//  void addIntendedAdminUsersList(const std::string & name);
//  
//  void deleteFromIntendedAdminUsersList(const std::string & name);
//  
//  void setAdminUsersList(const std::string & name);
  
//public:
//  // Get the name of the StorageClassList (or exception if not available)
//  std::string getStorageClassList();
//  
//  // Get the name of a (possibly freshly created) StorageClassList
//  std::string allocateOrGetStorageClassList(Agent & agent);
//  
//private:
//  void addIntendedStorageClassList(const std::string & name);
//  
//  void deleteFromIntendedStorageClassList(const std::string & name);
//  
//  void setStorageClassList(const std::string & name);
190
191
  
  
192
public:
193
  // Dump the root entry
194
  std::string dump ();
195
196
};

197
198
}}

199