Skip to content

Commit

Permalink
DBAI-29 Canister Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jayamala17 committed Apr 17, 2024
1 parent e49ed96 commit 858d0f5
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 89 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem "aws-sdk-s3", "~> 1.136"
gem "bagit", "~> 0.4.6"
gem "canister"
gem "faraday", "~> 2.9"
gem "faraday-retry", "~> 2.2"
gem "minitar", "~> 0.9"
gem "mysql2", "~> 0.5.6"
gem "rexml", "~> 3.2.6"
gem "semantic_logger", "~> 4.15"
gem "sequel", "~> 5.77"
gem "canister"

gem "sftp",
git: "https://github.com/mlibrary/sftp",
Expand Down
8 changes: 3 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require "minitest/test_task"

Minitest::TestTask.create
Expand All @@ -10,16 +9,15 @@ namespace :db do
task :migrate, [:version] do |t, args|
require "sequel/core"
require_relative "db/database_error"
require "services"
require_relative "services"

Sequel.extension :migration

db_config = Config::ConfigService.database_config_from_env
if !db_config
if !S.db_config
raise DatabaseError, "Migration failed. A database connection is not configured."
end

version = args[:version].to_i if args[:version]
Sequel::Migrator.run(dbconnect, "db/migrations", target: version)
Sequel::Migrator.run(S.dbconnect, "db/migrations", target: version)
end
end
3 changes: 2 additions & 1 deletion example.env
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ ARCHIVEMATICA_DEV_REPOSITORY_NAME=
# REST API
ARCHIVEMATICA_DEV_API_USERNAME=
ARCHIVEMATICA_DEV_API_API_KEY=
ARCHIVEMATICA_DEV_BASE_URL=
ARCHIVEMATICA_DEV_API_BASE_URL=
ARCHIVEMATICA_DEV_API_LOCATION_UUID=
# Remote
ARCHIVEMATICA_DEV_REMOTE_TYPE=file_system
ARCHIVEMATICA_DEV_REMOTE_SETTINGS_FILE_SYSTEM_REMOTE_PATH=
Expand Down
4 changes: 1 addition & 3 deletions lib/aptrust.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require "services"

require_relative "api_backend"
require_relative "bag_status"
require_relative "../services"

module APTrust
module IngestStatus
Expand Down
4 changes: 1 addition & 3 deletions lib/archivematica.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require "services"

require_relative "api_backend"
require_relative "repository_data"
require_relative "../services"

module Archivematica
Package = Struct.new(
Expand Down
3 changes: 1 addition & 2 deletions lib/bag_adapter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require "bagit"
require "services"
require_relative "../services"

module BagAdapter
class BagAdapter
Expand Down
3 changes: 1 addition & 2 deletions lib/bag_courier.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require "minitar"
require "services"

require_relative "bag_adapter"
require_relative "bag_status"
require_relative "remote_client"
require_relative "../services"

module BagCourier
class BagId
Expand Down
4 changes: 1 addition & 3 deletions lib/bag_repository.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require "services"

require_relative "../db/database_schema" if DB
require_relative "../services"

module BagRepository
Bag = Struct.new(
Expand Down
5 changes: 3 additions & 2 deletions lib/bag_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def validate(path)
raise NotImplementedError, "subclass must implement the validate method"
end
end

class InnerBagValidator < BagValidator
def initialize(inner_bag_name)
@inner_bag_name = inner_bag_name
Expand All @@ -20,9 +21,9 @@ def validate(data_path)
validity = @bag.valid?

if !validity
raise BagValidationError, "Inner bag is not valid: #{@bag.errors.full_messages.join(', ')}"
raise BagValidationError, "Inner bag is not valid: #{@bag.errors.full_messages.join(", ")}"
else
return validity
validity
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,4 @@ def self.from_env
create_config(ENV.to_hash)
end
end
end
end
4 changes: 2 additions & 2 deletions lib/remote_client.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require "bundler/setup"

require "aws-sdk-s3"
require "services"
require "sftp"

require_relative "../services"

module RemoteClient
class RemoteClientError < StandardError
end
Expand Down
4 changes: 1 addition & 3 deletions lib/repository_package_repository.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require "services"

require_relative "../db/database_schema" if DB
require_relative "../services"

module RepositoryPackageRepository
RepositoryPackage = Struct.new(
Expand Down
4 changes: 1 addition & 3 deletions lib/status_event_repository.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require "services"

require_relative "bag_status"
require_relative "../services"

require_relative "../db/database_schema" if DB

Expand Down
25 changes: 6 additions & 19 deletions run_dark_blue.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require "optparse"

require "sequel"
require "services"

require_relative "lib/config"
require_relative "services"

SemanticLogger.add_appender(io: $stderr, formatter: :color)
config = Config::ConfigService.from_env
SemanticLogger.default_level = config.settings.log_level
config = S.config

DB = config.database && Sequel.connect(
adapter: "mysql2",
host: config.database.host,
port: config.database.port,
database: config.database.database,
user: config.database.user,
password: config.database.password,
fractional_seconds: true
)
DB = config.database && S.dbconnect

require_relative "lib/archivematica"
require_relative "lib/bag_repository"
Expand All @@ -33,8 +20,8 @@ class DarkBlueError < StandardError
end

class DarkBlueJob
include SemanticLogger::Loggable
include DarkBlueLogger

module ExtraBagInfoData
CONTENT_TYPE_KEY = "Dark-Blue-Content-Type"
LOCATION_UUID_KEY = "Archivematica-Location-UUID"
Expand Down Expand Up @@ -207,4 +194,4 @@ def self.parse(options)
dark_blue_job.redeliver_packages(options.packages)
else
dark_blue_job.process
end
end
32 changes: 11 additions & 21 deletions services.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "canister"
require "semantic_logger"
require "sequel"

require_relative "lib/config"

Services = Canister.new
Expand All @@ -9,20 +10,13 @@

# Config
S.register(:config) do
Config::ConfigService.from_file(ENV.fetch("CONFIG_YML_PATH", File.join(".", "config", "config.yml")))
Config::ConfigService.from_env
end

S.register(:db_config) do
Config::ConfigService.database_config_from_file(ENV.fetch("CONFIG_YML_PATH", File.join(".", "config", "config.yml")))
end

def config
S.config
Config::ConfigService.database_config_from_env
end

def db_config
S.db_config
end

# Logger
module DarkBlueLogger
Expand All @@ -32,13 +26,13 @@ def self.included(klass)
include SemanticLogger::Loggable
SemanticLogger[klass]
S.register(:log_stream) do
$stdout.sync = true
$stdout
$stderr.sync = true
$stderr
end
S.register(:logger) do
if !SemanticLogger::Logger.processor.appenders.console_output?
SemanticLogger.add_appender(io: S.log_stream, formatter: :color)
SemanticLogger.default_level = config.settings.log_level
SemanticLogger.default_level = S.config.settings.log_level
end
end
end
Expand All @@ -49,14 +43,10 @@ def self.included(klass)
# Database Connection
S.register(:dbconnect) do
Sequel.connect(adapter: "mysql2",
host: config.database.host,
port: config.database.port,
database: config.database.database,
user: config.database.user,
password: config.database.password,
host: S.config.database.host,
port: S.config.database.port,
database: S.config.database.database,
user: S.config.database.user,
password: S.config.database.password,
fractional_seconds: true)
end

def dbconnect
S.dbconnect
end
22 changes: 5 additions & 17 deletions verify_aptrust.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require "services"
require "sequel"

require_relative "lib/config"

SemanticLogger.add_appender(io: $stderr, formatter: :color)
config = Config::ConfigService.from_env
SemanticLogger.default_level = config.settings.log_level

DB = config.database && Sequel.connect(
adapter: "mysql2",
host: config.database.host,
port: config.database.port,
database: config.database.database,
user: config.database.user,
password: config.database.password,
fractional_seconds: true
)
require_relative "services"

config = S.config

DB = config.database && S.dbconnect

require_relative "lib/aptrust"
require_relative "lib/bag_repository"
Expand Down

0 comments on commit 858d0f5

Please sign in to comment.