-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HostSettings specifies storage_roots by hostname for sharding
- Loading branch information
Showing
15 changed files
with
86 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Lets us consolidate shared_configs for almost identical machines | ||
class HostSettings | ||
# @return [Config::Options] key/value pairs of name: file_path | ||
def self.storage_roots | ||
Settings.storage_root_map[storage_root_lookup_name] | ||
end | ||
|
||
# @return [String] hostname depending on environment | ||
def self.storage_root_lookup_name | ||
Rails.env.production? ? parsed_hostname : 'default' | ||
end | ||
|
||
# @return [String] modified hostname | ||
def self.parsed_hostname | ||
Socket.gethostname.underscore.remove('.stanford.edu') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
moab: | ||
# this is a list of named storage roots. the names are used to seed the endpoints table. | ||
storage_roots: | ||
# name: '/location/on/disk' # e.g. | ||
storage_root_map: | ||
default: | ||
fixture_sr1: 'spec/fixtures/storage_root01' | ||
fixture_sr2: 'spec/fixtures/storage_root02' | ||
fixture_sr3: 'spec/fixtures/checksum_root01' | ||
preservation_catalog_prod: | ||
fixture_sr1: 'spec/fixtures/storage_root01' | ||
fixture_sr2: 'spec/fixtures/storage_root02' | ||
fixture_sr3: 'spec/fixtures/checksum_root01' | ||
preservation_catalog_prod_a: | ||
fixture_sr1: 'spec/fixtures/storage_root01' | ||
fixture_sr2: 'spec/fixtures/storage_root02' | ||
workflow_services_url: 'https://sul-lyberservices-test.stanford.edu/workflow/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
moab: | ||
# this is a list of named storage roots. the names are used to seed the endpoints table. | ||
storage_roots: | ||
# name: '/location/on/disk' # e.g. | ||
storage_root_map: | ||
default: | ||
fixture_sr1: 'spec/fixtures/storage_root01' | ||
fixture_sr2: 'spec/fixtures/storage_root02' | ||
fixture_sr3: 'spec/fixtures/checksum_root01' | ||
fixture_empty: 'spec/fixtures/empty' | ||
preservation_catalog_prod: | ||
fixture_sr1: 'spec/fixtures/storage_root01' | ||
fixture_sr2: 'spec/fixtures/storage_root02' | ||
fixture_sr3: 'spec/fixtures/checksum_root01' | ||
preservation_catalog_prod_a: | ||
fixture_sr1: 'spec/fixtures/storage_root01' | ||
fixture_sr2: 'spec/fixtures/storage_root02' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe HostSettings do | ||
describe '.storage_roots' do | ||
it 'gets the correct values' do | ||
expect(described_class).to receive(:storage_root_lookup_name).and_call_original | ||
expect(described_class.storage_roots.to_h).to eq(fixture_sr1: 'spec/fixtures/storage_root01', | ||
fixture_sr2: 'spec/fixtures/storage_root02', | ||
fixture_sr3: 'spec/fixtures/checksum_root01', | ||
fixture_empty: 'spec/fixtures/empty') | ||
end | ||
end | ||
|
||
describe '.storage_root_lookup_name' do | ||
it "returns 'default' when not in production" do | ||
expect(described_class.storage_root_lookup_name).to eq('default') | ||
end | ||
it 'returns parsed hostname when in production' do | ||
expect(Rails.env).to receive(:production?).and_return(true) | ||
expect(described_class).to receive(:parsed_hostname).and_return('preservation_catalog_prod_a') | ||
expect(described_class.storage_root_lookup_name).to eq('preservation_catalog_prod_a') | ||
end | ||
end | ||
|
||
describe '.parsed_hostname' do | ||
it 'makes hyphens into underscores and trims the domain down' do | ||
expect(Socket).to receive(:gethostname).and_return('preservation-catalog-prod-a.stanford.edu') | ||
expect(described_class.parsed_hostname).to eq('preservation_catalog_prod_a') | ||
end | ||
end | ||
end |