Class: Moab::StorageRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/moab/storage_repository.rb

Overview

Note:

Copyright © 2012 by The Board of Trustees of the Leland Stanford Junior University. All rights reserved. See LICENSE for details.

A class to represent the SDR repository store

Data Model

  • StorageRepository = represents the digital object repository storage areas

    • StorageServices = supports application layer access to the repository's objects, data, and metadata

    • StorageObject = represents a digital object's repository storage location and ingest/dissemination methods

      • StorageObjectVersion [1..*] = represents a version subdirectory within an object's home directory

        • Bagger [1] = utility for creating bagit packages for ingest or dissemination

Direct Known Subclasses

Stanford::StorageRepository

Instance Method Summary collapse

Instance Method Details

#deposit_branch(object_id) ⇒ String

Note:

Override this method in a subclass

Returns The branch segment of the object deposit path.

Parameters:

  • object_id (String)

    The identifier of the digital object

Returns:

  • (String)

    The branch segment of the object deposit path


66
67
68
# File 'lib/moab/storage_repository.rb', line 66

def deposit_branch(object_id)
  object_id
end

#deposit_trunkString

Returns The trunk segment of the object deposit path.

Returns:

  • (String)

    The trunk segment of the object deposit path


54
55
56
57
58
59
60
61
# File 'lib/moab/storage_repository.rb', line 54

def deposit_trunk
  unless defined?(@deposit_trunk)
    # do not raise error.  this parameter will be ignored if missing
    # raise "Moab::Config.deposit_trunk not found in config file" if Moab::Config.deposit_trunk.nil?
    @deposit_trunk = Moab::Config.deposit_trunk
  end
  @deposit_trunk
end

#find_storage_object(object_id, include_deposit = false) ⇒ StorageObject

Returns The representation of a digitial object's storage directory, which might not exist yet.

Parameters:

  • object_id (String)

    The identifier of the digital object whose version is desired

  • include_deposit (Boolean) (defaults to: false)

    specifies whether to look in deposit areas for objects in process of initial ingest

Returns:

  • (StorageObject)

    The representation of a digitial object's storage directory, which might not exist yet.


101
102
103
104
# File 'lib/moab/storage_repository.rb', line 101

def find_storage_object(object_id, include_deposit = false)
  root = find_storage_root(object_id, include_deposit)
  create_storage_object(object_id, root)
end

#find_storage_root(object_id, include_deposit = false) ⇒ Pathname

Returns The location of the desired object's home directory (default=pairtree).

Parameters:

  • object_id (String)

    The identifier of the digital object whose version is desired

  • include_deposit (Boolean) (defaults to: false)

    specifies whether to look in deposit areas for objects in process of initial ingest

Returns:

  • (Pathname)

    The location of the desired object's home directory (default=pairtree)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/moab/storage_repository.rb', line 73

def find_storage_root(object_id, include_deposit = false)
  # Search for the object's home directory in the storage areas
  branch = storage_branch(object_id)
  storage_roots.each do |root|
    root_trunk = root.join(storage_trunk)
    raise(MoabRuntimeError, "Storage area not found at #{root_trunk}") unless root_trunk.exist?

    root_trunk_branch = root_trunk.join(branch)
    return root if root_trunk_branch.exist?
  end
  # Search for the object's directory in the deposit areas
  if include_deposit && deposit_trunk
    branch = deposit_branch(object_id)
    storage_roots.each do |root|
      root_trunk = root.join(deposit_trunk)
      raise(MoabRuntimeError, "Deposit area not found at #{root_trunk}") unless root_trunk.exist?

      root_trunk_branch = root_trunk.join(branch)
      return root if root_trunk_branch.exist?
    end
  end
  # object not found, will store new objects in the newest (most empty) filesystem
  storage_roots.last
end

#object_size(object_id, include_deposit = false) ⇒ Integer

Returns the size occupied on disk by the storage object, in bytes. this is the entire moab (all versions).

Parameters:

  • object_id (String)

    The identifier of the digital object whose size is desired

  • include_deposit (Boolean) (defaults to: false)

    specifies whether to look in deposit areas for objects in process of initial ingest

Returns:

  • (Integer)

    the size occupied on disk by the storage object, in bytes. this is the entire moab (all versions).


137
138
139
140
141
142
143
144
# File 'lib/moab/storage_repository.rb', line 137

def object_size(object_id, include_deposit = false)
  storage_pathname = find_storage_object(object_id, include_deposit).object_pathname
  size = 0
  Find.find(storage_pathname) do |path|
    size += FileTest.size(path) unless FileTest.directory?(path)
  end
  size
end

#search_storage_objects(object_id, include_deposit = false) ⇒ Array<StorageObject>

Returns Representations of a digitial object's storage directories, or an empty array if none found.

Parameters:

  • object_id (String)

    The identifier of the digital object

  • include_deposit (Boolean) (defaults to: false)

    specifies whether to look in deposit areas for objects in process of initial ingest

Returns:

  • (Array<StorageObject>)

    Representations of a digitial object's storage directories, or an empty array if none found.


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/moab/storage_repository.rb', line 109

def search_storage_objects(object_id, include_deposit = false)
  storage_objects = []
  # Search for the object's home directory in the storage areas
  branch = storage_branch(object_id)
  storage_roots.each do |root|
    root_trunk = root.join(storage_trunk)
    raise(MoabRuntimeError, "Storage area not found at #{root_trunk}") unless root_trunk.exist?

    root_trunk_branch = root_trunk.join(branch)
    storage_objects << create_storage_object(object_id, root) if root_trunk_branch.exist?
  end
  # Search for the object's directory in the deposit areas
  if include_deposit && deposit_trunk
    branch = deposit_branch(object_id)
    storage_roots.each do |root|
      root_trunk = root.join(deposit_trunk)
      raise(MoabRuntimeError, "Deposit area not found at #{root_trunk}") unless root_trunk.exist?

      root_trunk_branch = root_trunk.join(branch)
      storage_objects << create_storage_object(object_id, root) if root_trunk_branch.exist?
    end
  end
  storage_objects
end

#storage_branch(object_id) ⇒ String

Returns The branch segment of the object storage path.

Returns:

  • (String)

    The branch segment of the object storage path


45
46
47
48
49
50
51
# File 'lib/moab/storage_repository.rb', line 45

def storage_branch(object_id)
  #todo This method should be customized, or overridden in a subclass
  # split a object ID into 2-character segments, followed by a copy of the object ID
  # for a more sophisticated pairtree implementation see https://github.com/microservices/pairtree
  path_segments = object_id.scan(/..?/) << object_id
  path_segments.join(File::SEPARATOR).tr(':', '_')
end

#storage_object(object_id, create = false) ⇒ StorageObject

Returns The representation of a digitial object's storage directory, which must exist.

Parameters:

  • object_id (String)

    The identifier of the digital object whose version is desired

  • create (Boolean) (defaults to: false)

    If true, the object home directory should be created if it does not exist

Returns:

  • (StorageObject)

    The representation of a digitial object's storage directory, which must exist.


149
150
151
152
153
154
155
156
157
# File 'lib/moab/storage_repository.rb', line 149

def storage_object(object_id, create = false)
  storage_object = find_storage_object(object_id)
  unless storage_object.object_pathname.exist?
    raise ObjectNotFoundException, "No storage object found for #{object_id}" unless create

    storage_object.object_pathname.mkpath
  end
  storage_object
end

#storage_rootsArray<Pathname>

Returns The list of filesystem root paths in which objects are stored.

Returns:

  • (Array<Pathname>)

    The list of filesystem root paths in which objects are stored


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/moab/storage_repository.rb', line 21

def storage_roots
  unless defined?(@storage_roots)
    raise(MoabRuntimeError, "Moab::Config.storage_roots not found in config file") if Moab::Config.storage_roots.nil?

    @storage_roots = [Moab::Config.storage_roots].flatten.collect { |filesystem| Pathname(filesystem) }
    raise(MoabRuntimeError, "Moab::Config.storage_roots empty") if @storage_roots.empty?

    @storage_roots.each { |root| raise(MoabRuntimeError, "Storage root #{root} not found on system") unless root.exist? }
  end
  @storage_roots
end

#storage_trunkString

Returns The trunk segment of the object storage path.

Returns:

  • (String)

    The trunk segment of the object storage path


34
35
36
37
38
39
40
41
# File 'lib/moab/storage_repository.rb', line 34

def storage_trunk
  unless defined?(@storage_trunk)
    raise(MoabRuntimeError, "Moab::Config.storage_trunk not found in config file") if Moab::Config.storage_trunk.nil?

    @storage_trunk = Moab::Config.storage_trunk
  end
  @storage_trunk
end

#store_new_object_version(druid, bag_pathname)

This method returns an undefined value.

Returns transfer the object to the preservation repository.

Parameters:

  • druid (String)

    The object identifier


162
163
164
# File 'lib/moab/storage_repository.rb', line 162

def store_new_object_version(druid, bag_pathname)
  storage_object(druid, create = true).ingest_bag(bag_pathname)
end