Class: Longleaf::StorageLocationManager

Inherits:
Object
  • Object
show all
Defined in:
lib/longleaf/services/storage_location_manager.rb

Overview

Manager which loads and provides access to StorageLocation objects

Constant Summary collapse

@@storage_type_mappings =

Mapping of storage types to storage location classes

{
  ST::FILESYSTEM_STORAGE_TYPE => Longleaf::FilesystemStorageLocation,
  ST::S3_STORAGE_TYPE => Longleaf::S3StorageLocation
}
@@metadata_type_mappings =
{ ST::FILESYSTEM_STORAGE_TYPE => Longleaf::FilesystemMetadataLocation }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ StorageLocationManager

Returns a new instance of StorageLocationManager.

Parameters:

  • config (Hash)

    has representation of the application configuration

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/longleaf/services/storage_location_manager.rb', line 24

def initialize(config)
  raise ArgumentError.new("Configuration must be provided") if config&.empty?

  @locations = Hash.new
  config[AF::LOCATIONS].each do |name, properties|
    md_loc = (properties)

    @locations[name] = instantiate_storage_location(name, properties, md_loc)
  end
  @locations.freeze
end

Instance Attribute Details

#locationsObject (readonly)

Hash mapping storage location names to Longleaf::StorageLocation objects



15
16
17
# File 'lib/longleaf/services/storage_location_manager.rb', line 15

def locations
  @locations
end

Instance Method Details

#get_location_by_metadata_path(md_path) ⇒ Longleaf::StorageLocation

Get the Longleaf::StorageLocation object which should contain the given metadata path

Returns:

  • (Longleaf::StorageLocation)

    location containing the given metadata path or nil if the path is not contained by a registered location.

Raises:

  • (ArgumentError)


51
52
53
54
55
56
57
58
# File 'lib/longleaf/services/storage_location_manager.rb', line 51

def (md_path)
  raise ArgumentError.new("Metadata path parameter is required") if md_path.nil? || md_path.empty?
  @locations.each do |name, location|
    return location if location..contains?(md_path)
  end

  nil
end

#get_location_by_path(path) ⇒ Longleaf::StorageLocation

Get the Longleaf::StorageLocation object which should contain the given path

Returns:

  • (Longleaf::StorageLocation)

    location containing the given path or nil if the path is not contained by a registered location.

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
# File 'lib/longleaf/services/storage_location_manager.rb', line 39

def get_location_by_path(path)
  raise ArgumentError.new("Path parameter is required") if path.nil? || path.empty?
  @locations.each do |name, location|
    return location if location.contains?(path)
  end

  nil
end

#verify_path_in_location(path, expected_loc = nil) ⇒ StorageLocation

Raises a Longleaf::StorageLocationUnavailableError if the given path is not in a known storage location,

or if it is not within the expected location if provided

Parameters:

  • path (String)

    file path

  • expected_loc (String) (defaults to: nil)

    name of the storage location which path should be contained by

Returns:

  • (StorageLocation)

    the storage location which contains path, if it was within one.

Raises:



66
67
68
69
70
71
72
73
74
# File 'lib/longleaf/services/storage_location_manager.rb', line 66

def verify_path_in_location(path, expected_loc = nil)
  location = get_location_by_path(path)
  if location.nil?
    raise StorageLocationUnavailableError.new("Path #{path} is not from a known storage location.")
  elsif !expected_loc.nil? && expected_loc != location.name
    raise StorageLocationUnavailableError.new("Path #{path} is not contained by storage location #{expected_loc}.")
  end
  location
end