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

101
  /** Ordered vector of archive routes */
102
  std::vector<std::string> getArchivalRoutes (const std::string storageClass);
103
104
  class StorageClassDump {
  public:
105
    class ArchivalRouteDump {
106
107
108
109
110
111
112
    public:
      uint16_t copyNumber;
      std::string tapePool;
      CreationLog log;
    };
    std::string storageClass;
    uint16_t copyCount;
113
    std::list<ArchivalRouteDump> routes;
114
    CreationLog log;
115
116
  };
  std::list<StorageClassDump> dumpStorageClasses();
117
  StorageClassDump dumpStorageClass(const std::string & name);
118
  
119
  // Manipulations of libraries ================================================
120
  void addLibrary(const std::string & library, const CreationLog & log);
121
  CTA_GENERATE_EXCEPTION_CLASS(NoSuchLibrary);
122
123
  void removeLibrary(const std::string & library);
  bool libraryExists(const std::string & library);
124
125
126
127
128
129
  class LibraryDump {
  public:
    std::string library;
    CreationLog log;
  };
  std::list<LibraryDump> dumpLibraries();
130
  
131
  // TapePoolManipulations =====================================================
132
133
  CTA_GENERATE_EXCEPTION_CLASS(TapePoolNotEmpty);
  CTA_GENERATE_EXCEPTION_CLASS(WrongTapePool);
134
  /** This function implicitly creates the tape pool structure and updates 
135
   * the pointer to it. It needs to implicitly commit the object to the store. */
136
137
  std::string addOrGetTapePoolAndCommit(const std::string & tapePool,
    uint32_t nbPartialTapes, Agent & agent,
Eric Cano's avatar
Eric Cano committed
138
    const CreationLog & log);
139
140
  /** This function implicitly deletes the tape pool structure. 
   * Fails if it not empty*/
141
142
  CTA_GENERATE_EXCEPTION_CLASS(NoSuchTapePool);
  CTA_GENERATE_EXCEPTION_CLASS(TapePoolUsedInRoute);
Eric Cano's avatar
Eric Cano committed
143
  void removeTapePoolAndCommit(const std::string & tapePool);
144
  std::string getTapePoolAddress(const std::string & tapePool);
145
146
147
148
  class TapePoolDump {
  public:
    std::string tapePool;
    std::string address;
149
    uint32_t nbPartialTapes;
150
151
    CreationLog log;
  };
152
  std::list<TapePoolDump> dumpTapePools();
153
  
154
  // Drive register manipulations ==============================================
Eric Cano's avatar
Eric Cano committed
155
156
157
158
  CTA_GENERATE_EXCEPTION_CLASS(DriveRegisterNotEmpty);
  std::string getDriveRegisterAddress();  
  std::string addOrGetDriveRegisterPointerAndCommit(Agent & agent, const CreationLog & log);
  void removeDriveRegisterAndCommit();
159
  
160
  // Agent register manipulations ==============================================
161
162
  CTA_GENERATE_EXCEPTION_CLASS(AgentRegisterNotEmpty);
  std::string getAgentRegisterAddress();
163
164
  /** 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
165
166
167
168
   * 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
169
  void removeAgentRegisterAndCommit();
170
171

private:
172
  void addIntendedAgentRegistry(const std::string & address);
173
  
174
public:
175
  // Dump the root entry
176
  std::string dump ();
177
178
};

179
180
}}

181