-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Database restructuring and addition of PendingTransfer model; Test ad…
…ditions and refactoring; Added ci.rake to wrap ci setup steps; Rubocop fixes
- Loading branch information
Showing
44 changed files
with
723 additions
and
334 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,7 @@ AllCops: | |
- 'lib/tasks/**/*' | ||
- 'tmp/**/*' | ||
|
||
|
||
Metrics/MethodLength: | ||
Exclude: | ||
- lib/atc/loaders/checksum_loader.rb |
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,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
# Load DSL and set up stages | ||
require 'capistrano/setup' | ||
|
||
|
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 |
---|---|---|
@@ -1,18 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
# NOTE: This class will be going away. It's only here temporarily during a data migration. | ||
# After we're done with it, there will be a migration that calls `drop_table :checksums`. | ||
class Checksum < ApplicationRecord | ||
belongs_to :checksum_algorithm | ||
belongs_to :transfer_source | ||
belongs_to :source_object | ||
validates :value, presence: true | ||
|
||
class HashOfNothingValidator < ActiveModel::Validator | ||
def validate(record) | ||
return if record.checksum_algorithm.nil? | ||
return unless record.value == record.checksum_algorithm.empty_value | ||
return if record.transfer_source.object_size.zero? | ||
|
||
record.errors.add :value, 'checksum value indicates no content for non-zero length file' | ||
end | ||
end | ||
validates_with HashOfNothingValidator | ||
end |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'digest' | ||
|
||
class PendingTransfer < ApplicationRecord | ||
belongs_to :source_object | ||
belongs_to :storage_provider | ||
belongs_to :transfer_checksum_algorithm, class_name: 'ChecksumAlgorithm' | ||
|
||
# Some db backends don't enforce a limit on binary field length, | ||
# so the limit below is meant to ensure that we don't ever | ||
# accidentally add a larger value. Make sure to update this | ||
# value if the database limit ever changes. | ||
validates :transfer_checksum_value, length: { maximum: 4 } | ||
validates_with TransferChecksumValidator | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'digest' | ||
|
||
class SourceObject < ApplicationRecord | ||
include PathHashes | ||
|
||
belongs_to :repository, optional: true | ||
belongs_to :fixity_checksum_algorithm, class_name: 'ChecksumAlgorithm', optional: true | ||
|
||
validates :path, :path_hash, presence: { strict: true }, on: :create | ||
validates :object_size, presence: true | ||
# Some db backends don't enforce a limit on binary field length, | ||
# so the limit below is meant to ensure that we don't ever | ||
# accidentally add a larger value. Make sure to update this | ||
# value if the database limit ever changes. | ||
validates :fixity_checksum_value, length: { maximum: 64 } | ||
|
||
validates_with PathValidator, on: :update | ||
validates_with PathHashValidator | ||
validates_with FixityChecksumValidator | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'digest' | ||
|
||
class StoredObject < ApplicationRecord | ||
belongs_to :source_object | ||
belongs_to :storage_provider | ||
belongs_to :transfer_checksum_algorithm, class_name: 'ChecksumAlgorithm' | ||
|
||
include PathHashes | ||
|
||
validates :path, :path_hash, presence: { strict: true }, on: :create | ||
validates :source_object, :storage_provider, :transfer_checksum_algorithm, presence: true | ||
validates_with PathValidator, on: :update | ||
validates_with PathHashValidator | ||
# # Some db backends don't enforce a limit on binary field length, | ||
# # so the limit below is meant to ensure that we don't ever | ||
# # accidentally add a larger value. Make sure to update this | ||
# # value if the database limit ever changes. | ||
validates :transfer_checksum_value, length: { maximum: 4 } | ||
validates_with TransferChecksumValidator | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class FixityChecksumValidator < ActiveModel::Validator | ||
def validate(record) | ||
# If record has no fixity_checksum_algorithm, there's nothing to validate | ||
return if record.fixity_checksum_algorithm.nil? | ||
|
||
if record.object_size.zero? | ||
validate_checksum_for_zero_byte_file(record) | ||
else | ||
validate_checksum_for_positive_size_file(record) | ||
end | ||
end | ||
|
||
def validate_checksum_for_zero_byte_file(record) | ||
return if record.fixity_checksum_value == record.fixity_checksum_algorithm.empty_value | ||
|
||
record.errors.add( | ||
:fixity_checksum_value, | ||
'object size is zero bytes, but checksum value does not match zero-byte checksum' | ||
) | ||
end | ||
|
||
def validate_checksum_for_positive_size_file(record) | ||
return if record.fixity_checksum_value != record.fixity_checksum_algorithm.empty_value | ||
|
||
record.errors.add( | ||
:fixity_checksum_value, | ||
'checksum value indicates zero-byte object, but object size is greater than zero bytes' | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class TransferChecksumValidator < ActiveModel::Validator | ||
def validate(record) | ||
# If record has no transfer_checksum_algorithm, there's nothing to validate | ||
return if record.transfer_checksum_algorithm.nil? | ||
|
||
if record.source_object.object_size.zero? | ||
validate_checksum_for_zero_byte_file(record) | ||
else | ||
validate_checksum_for_positive_size_file(record) | ||
end | ||
end | ||
|
||
def validate_checksum_for_zero_byte_file(record) | ||
return if record.transfer_checksum_value == record.transfer_checksum_algorithm.empty_value | ||
|
||
record.errors.add( | ||
:transfer_checksum_value, | ||
'object size is zero bytes, but checksum value does not match zero-byte checksum' | ||
) | ||
end | ||
|
||
def validate_checksum_for_positive_size_file(record) | ||
return if record.transfer_checksum_value != record.transfer_checksum_algorithm.empty_value | ||
|
||
record.errors.add( | ||
:transfer_checksum_value, | ||
'checksum value indicates zero-byte object, but object size is greater than zero bytes' | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
set :remote_user, 'ldpdserv' | ||
set :application, 'atc' | ||
set :repo_name, fetch(:application) | ||
set :repo_url, "[email protected]:cul/atc.git" | ||
set :repo_url, '[email protected]:cul/atc.git' | ||
set :deploy_name, "#{fetch(:application)}_#{fetch(:stage)}" | ||
# used to run rake db:migrate, etc | ||
set :rails_env, fetch(:deploy_name) | ||
|
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,46 @@ | ||
class RestructureModels < ActiveRecord::Migration[7.1] | ||
def change | ||
rename_table :transfer_sources, :source_objects | ||
rename_table :object_transfers, :stored_objects | ||
drop_table :transfer_verifications | ||
|
||
change_table :source_objects do |t| | ||
t.references :fixity_checksum_algorithm, null: true, index: true, foreign_key: { to_table: :checksum_algorithms } | ||
# Need a length of 64 for this column to hold SHA512 checksums, which are 64 bytes (512 bits) | ||
t.binary :fixity_checksum_value, limit: 64, null: true, index: true | ||
end | ||
|
||
change_table :stored_objects do |t| | ||
t.references :transfer_checksum_algorithm, null: true, index: true, foreign_key: { to_table: :checksum_algorithms } | ||
# Need a length of 4 for this column to hold CRC32C checksums, which are 4 bytes (32 bits) | ||
t.binary :transfer_checksum_value, limit: 4, null: true, index: true | ||
t.integer :transfer_checksum_chunk_size, null: true, index: true | ||
t.rename :transfer_source_id, :source_object_id | ||
end | ||
|
||
create_table :pending_transfers do |t| | ||
t.references :transfer_checksum_algorithm, null: false, index: true, foreign_key: { to_table: :checksum_algorithms } | ||
# Need a length of 4 for this column to hold CRC32C checksums, which are 4 bytes (32 bits) | ||
t.binary :transfer_checksum_value, limit: 4, null: false | ||
t.integer :transfer_checksum_chunk_size, null: true | ||
t.references :storage_provider, null: false, index: true | ||
t.references :source_object, null: false, index: true | ||
t.integer :status, null: false, default: 0 # pending / failure (and no need for success, since successful rows get converted into stored_object rows) | ||
t.text :error_message, null: true | ||
t.timestamps | ||
end | ||
|
||
create_table :fixity_verifications do |t| | ||
t.references :source_object, null: false, index: true | ||
t.references :stored_object, null: false, index: true | ||
t.integer :status, null: false, default: 0, index: true # pending / success / failure | ||
t.timestamps | ||
end | ||
|
||
change_table :checksum_algorithms do |t| | ||
t.change :empty_value, :binary | ||
end | ||
|
||
add_index(:pending_transfers, [:source_object_id, :storage_provider_id], unique: true) | ||
end | ||
end |
Oops, something went wrong.