RootEntry.hpp 5.68 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
52
53
54
55
56
57
58
59
  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();
60
  
61
  CTA_GENERATE_EXCEPTION_CLASS(DuplicateEntry);
62
  
63
  // Manipulations of Admin Users ==============================================
64
65
66
67
68
69
70
71
72
73
  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();
  
74
75
76
77
78
79
80
81
82
  // 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;
83
  void checkStorageClassCopyCount(uint16_t copyCount);
84
85
86
public:
  void addStorageClass(const std::string storageClass, uint16_t copyCount, 
    const CreationLog & log);
87
  void removeStorageClass(const std::string storageClass);
88
89
90
  void setStorageClassCopyCount(const std::string & storageClass,
    uint16_t copyCount, const CreationLog & cl);
  uint16_t getStorageClassCopyCount(const std::string & storageClass);
91
92
93
  void setArchiveRoute(const std::string & storageClass, uint16_t copyNb, 
    const std::string & tapePool, const CreationLog & cl);

94
95
96
97
98
99
100
101
102
103
104
105
106
  /** 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;
107
    CreationLog log;
108
109
  };
  std::list<StorageClassDump> dumpStorageClasses();
110
  StorageClassDump dumpStorageClass(const std::string & name);
111
  
112
  // Manipulations of libraries ================================================
113
  void addLibrary(const std::string & library, const CreationLog & log);
114
115
116
117
  void removeLibrary(const std::string & library);
  bool libraryExists(const std::string & library);
  std::list<std::string> dumpLibraries();
  
118
  // TapePoolManipulations =====================================================
119
120
  CTA_GENERATE_EXCEPTION_CLASS(TapePoolNotEmpty);
  CTA_GENERATE_EXCEPTION_CLASS(WrongTapePool);
121
  /** This function implicitly creates the tape pool structure and updates 
122
   * the pointer to it. It needs to implicitly commit the object to the store. */
Eric Cano's avatar
Eric Cano committed
123
124
  std::string addOrGetTapePoolAndCommit(const std::string & tapePool, Agent & agent,
    const CreationLog & log);
125
126
  /** This function implicitly deletes the tape pool structure. 
   * Fails if it not empty*/
Eric Cano's avatar
Eric Cano committed
127
  void removeTapePoolAndCommit(const std::string & tapePool);
128
  std::string getTapePoolAddress(const std::string & tapePool);
129
130
131
132
133
134
135
136
  class TapePoolDump {
  public:
    std::string tapePool;
    std::string address;
    CreationLog log;
  };
  std::list<TapePoolDump> dumpTapePool();
  
137
  // Drive register manipulations ==============================================
Eric Cano's avatar
Eric Cano committed
138
139
140
141
  CTA_GENERATE_EXCEPTION_CLASS(DriveRegisterNotEmpty);
  std::string getDriveRegisterAddress();  
  std::string addOrGetDriveRegisterPointerAndCommit(Agent & agent, const CreationLog & log);
  void removeDriveRegisterAndCommit();
142
  
143
  // Agent register manipulations ==============================================
144
145
  CTA_GENERATE_EXCEPTION_CLASS(AgentRegisterNotEmpty);
  std::string getAgentRegisterAddress();
146
147
  /** 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
148
149
150
151
   * 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
152
  void removeAgentRegisterAndCommit();
153
154

private:
155
  void addIntendedAgentRegistry(const std::string & address);
156
  
157
public:
158
  // Dump the root entry
159
  std::string dump ();
160
161
};

162
163
}}

164