Skip to content

Commit

Permalink
Issue #1912: first round of eliminating OTOBO_SYNC_WITH_S3
Browse files Browse the repository at this point in the history
  • Loading branch information
bschmalhofer committed Sep 5, 2022
1 parent 9b2862e commit e365208
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 37 deletions.
8 changes: 4 additions & 4 deletions Kernel/Config.pm.docker.dist
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Set to I<localhost:5000> for running the test scripts in the otobo_web_1 contain

=item S3 specific settings

These are only enabled when the environmen variable B<OTOBO_SYNC_WITH_S3> is set.
These are always enabled.

=back

Expand Down Expand Up @@ -120,11 +120,11 @@ sub Load {
# setting for running OTOBO under Docker, see the POD #
# ---------------------------------------------------- #

# These settings are used only when the env var OTOBO_SYNC_WITH_S3 ist set
if ( $ENV{OTOBO_SYNC_WITH_S3} ) {
# These settings are for the S3 backend
if ( 1 ) {
$Self->{'Storage::S3::Active'} = 1;
$Self->{'Storage::S3::Region'} = 'eu-central-1';
$Self->{'Storage::S3::Bucket'} = 'otobo-bucket-20220603a';
$Self->{'Storage::S3::Bucket'} = 'otobo-bucket-20220905a';
$Self->{'Storage::S3::HomePrefix'} = 'OTOBO';
$Self->{'Storage::S3::AccessKey'} = 'minio-otobo';
$Self->{'Storage::S3::SecretKey'} = 'minio-otobo'; # more than 8 chars
Expand Down
12 changes: 7 additions & 5 deletions Kernel/Config/Defaults.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use File::stat;

# OTOBO modules
use Kernel::System::ModuleRefresh; # based on Module::Refresh
use if $ENV{OTOBO_SYNC_WITH_S3}, 'Kernel::System::Storage::S3';

our @EXPORT = qw(Translatable); ## no critic qw(Modules::ProhibitAutomaticExportation)

Expand Down Expand Up @@ -2367,18 +2366,21 @@ sub SyncWithS3 {
my ( $Self, %Param ) = @_;

# nothing to do when S3 backend is not enabled
return unless $ENV{OTOBO_SYNC_WITH_S3};
return unless $Self->{'Storage::S3::Active'};

# assign default values
for my $Key (qw(ExtraFileNames)) {
$Param{$Key} //= [];
}

# pass in a unfinished config object for bootstrapping
my $StorageS3Object = Kernel::System::Storage::S3->new(
ConfigObject => $Self
my $StorageS3Object = $Kernel::OM->Create(
'Kernel::System::Storage::S3',
ObjectParams => {
ConfigObject => $Self
},
);
my $FilesPrefix = join '/', 'Kernel', 'Config', 'Files';
my $FilesPrefix = join '/', 'Kernel', 'Config', 'Files';

# only a single process should sync with S3 at one time
CHECK_SYNC:
Expand Down
10 changes: 5 additions & 5 deletions Kernel/System/ACL/DB/ACL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use warnings;
# OTOBO modules
use Kernel::Language qw(Translatable);
use Kernel::System::VariableCheck qw(:all);
use if $ENV{OTOBO_SYNC_WITH_S3}, 'Kernel::System::Storage::S3';

our @ObjectDependencies = (
'Kernel::Config',
Expand All @@ -36,9 +35,10 @@ our @ObjectDependencies = (
'Kernel::System::Encode',
'Kernel::System::Log',
'Kernel::System::Main',
'Kernel::System::Storage::S3',
'Kernel::System::Ticket::FieldRestrictions',
'Kernel::System::User',
'Kernel::System::YAML',
'Kernel::System::Ticket::FieldRestrictions',
);

=head1 NAME
Expand Down Expand Up @@ -970,7 +970,7 @@ END_PM_FILE
my $ZZZFilePath = $Param{Location};
$ZZZFilePath =~ s{^$Home/*}{};

my $StorageS3Object = Kernel::System::Storage::S3->new();
my $StorageS3Object = $Kernel::OM->Get('Kernel::System::Storage::S3');

# only write to S3, no extra copy in the file system
return $StorageS3Object->StoreObject(
Expand Down Expand Up @@ -1185,8 +1185,8 @@ sub _ACLItemOutput {
my ( $Self, %Param ) = @_;

# those params are expected to only contain one line
for my $Key ( qw( CreateBy ChangeBy Comment ) ) {
( $Param{ $Key } ) = $Param{ $Key } =~ /(.+?)$/m;
for my $Key (qw( CreateBy ChangeBy Comment )) {
( $Param{$Key} ) = $Param{$Key} =~ /(.+?)$/m;
}

my $Output = "# Created: $Param{CreateTime} ($Param{CreateBy})\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Kernel::System::Daemon::DaemonModules::SystemConfigurationSyncManager - daemon t
This Daemon module performs two tasks. The first task is to check whether there is a new deployment in the database
that is for some reason not reflected in the config cache F<Kernel/Config/Files/ZZZAAuto.pm>. It performs a new deployment when there
is a discrepancy. When OTOBO_SYNC_WITH_S3 is active then the new ZZZ files are deployed first to the S3 compatible storage.
is a discrepancy. When the S3 backend is active then the new ZZZ files are deployed first to the S3 compatible storage.
This means that potential other nodes don't need to sync the deployment again. But they should restart because the config cache has changed.
The second task is to reload the Daemon in case there is a change in the F<Kernel/Config/Files/*.pm> files. This happens
Expand Down
8 changes: 4 additions & 4 deletions Kernel/System/Loader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use CSS::Minifier qw();
use JavaScript::Minifier qw();

# OTOBO modules
use if $ENV{OTOBO_SYNC_WITH_S3}, 'Kernel::System::Storage::S3';

our @ObjectDependencies = (
'Kernel::Config',
Expand All @@ -38,6 +37,7 @@ our @ObjectDependencies = (
'Kernel::System::Encode',
'Kernel::System::Log',
'Kernel::System::Main',
'Kernel::System::Storage::S3',
);

=head1 NAME
Expand Down Expand Up @@ -197,7 +197,7 @@ sub MinifyFiles {
$LoaderFileExists = -r "$TargetDirectory/$Filename";
}
else {
my $StorageS3Object = Kernel::System::Storage::S3->new();
my $StorageS3Object = $Kernel::OM->Get('Kernel::System::Storage::S3');

# the target directory is below the OTOBO home dir, adapt that to S3
my $FilePath = join '/', $TargetDirectory, $Filename;
Expand Down Expand Up @@ -267,7 +267,7 @@ sub MinifyFiles {
# Daemons and web servers are responsible for syncing the file from S3 to the file system.
if ( $Self->{UseS3Backend} ) {

my $StorageS3Object = Kernel::System::Storage::S3->new();
my $StorageS3Object = $Kernel::OM->Get('Kernel::System::Storage::S3');

# the target directory is below the OTOBO home dir, adapt that to S3
my $FilePath = join '/', $TargetDirectory, $Filename;
Expand Down Expand Up @@ -609,7 +609,7 @@ Returns the success of the the discard operations.
=cut

sub _S3CacheDelete {
my $StorageS3Object = Kernel::System::Storage::S3->new();
my $StorageS3Object = $Kernel::OM->Get('Kernel::System::Storage::S3');

return $StorageS3Object->DiscardObjects(
Prefix => 'var/httpd/htdocs/',
Expand Down
10 changes: 6 additions & 4 deletions Kernel/System/ProcessManagement/DB/Process.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use Kernel::System::ProcessManagement::DB::ActivityDialog;
use Kernel::System::ProcessManagement::DB::Process::State;
use Kernel::System::ProcessManagement::DB::Transition;
use Kernel::System::ProcessManagement::DB::TransitionAction;
use if $ENV{OTOBO_SYNC_WITH_S3}, 'Kernel::System::Storage::S3';
use Kernel::System::VariableCheck qw(:all);

our @ObjectDependencies = (
Expand All @@ -43,6 +42,7 @@ our @ObjectDependencies = (
'Kernel::System::Encode',
'Kernel::System::Log',
'Kernel::System::Main',
'Kernel::System::Storage::S3',
'Kernel::System::YAML',
);

Expand Down Expand Up @@ -87,6 +87,9 @@ sub new {
$Self->{Lower} = 'LOWER';
}

# check whether the S3 backend is used
$Self->{UseS3Backend} = $Kernel::OM->Get('Kernel::Config')->Get('Storage::S3::Active') ? 1 : 0;

return $Self;
}

Expand Down Expand Up @@ -1455,9 +1458,8 @@ EOF
}

# store the Perl module in S3 when S3 is active
if ( $ENV{OTOBO_SYNC_WITH_S3} ) {

my $StorageS3Object = Kernel::System::Storage::S3->new();
if ( $Self->{UseS3Backend} ) {
my $StorageS3Object = $Kernel::OM->Get('Kernel::System::Storage::S3');
my $ZZZFilePath = join '/', 'Kernel', 'Config', 'Files', 'ZZZProcessManagement.pm';

# only write to S3, no extra copy in the file system
Expand Down
6 changes: 5 additions & 1 deletion Kernel/System/Storage/S3.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ use Plack::Util;

# OTOBO modules

our $ObjectManagerDisabled = 1;
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::Encode',
'Kernel::System::Log',
);

=head1 NAME
Expand Down
6 changes: 3 additions & 3 deletions Kernel/System/SysConfig.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use File::Path qw(make_path);
# OTOBO modules
use Kernel::System::VariableCheck qw(:all);
use Kernel::Language qw(Translatable);
use if $ENV{OTOBO_SYNC_WITH_S3}, 'Kernel::System::Storage::S3';

our @ObjectDependencies = (
'Kernel::Config',
Expand All @@ -44,6 +43,7 @@ our @ObjectDependencies = (
'Kernel::System::Main',
'Kernel::System::Package',
'Kernel::System::Storable',
'Kernel::System::Storage::S3',
'Kernel::System::SysConfig::DB',
'Kernel::System::SysConfig::XML',
'Kernel::System::User',
Expand Down Expand Up @@ -3663,7 +3663,7 @@ sub ConfigurationDeploy {
if ( $Self->{UseS3Backend} ) {

# only write to S3, no extra copy in the file system
my $StorageS3Object = Kernel::System::Storage::S3->new();
my $StorageS3Object = $Kernel::OM->Get('Kernel::System::Storage::S3');
my $S3Key = $StorageS3Object->StoreObject(
Key => $TargetPath,
Content => $EffectiveValueStrg,
Expand Down Expand Up @@ -3786,7 +3786,7 @@ sub ConfigurationDeploySync {
if ( $Self->{UseS3Backend} ) {

# only write to S3
my $StorageS3Object = Kernel::System::Storage::S3->new();
my $StorageS3Object = $Kernel::OM->Get('Kernel::System::Storage::S3');
my $ZZZFilePath = join '/', 'Kernel', 'Config', 'Files', 'ZZZAAuto.pm';
my $Success = $StorageS3Object->StoreObject(
Key => $ZZZFilePath,
Expand Down
8 changes: 4 additions & 4 deletions Kernel/System/UnitTest/Helper.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ use Test2::API qw/context run_subtest/;
# OTOBO modules
use Kernel::System::VariableCheck qw(:all);
use Kernel::System::SysConfig;
use if $ENV{OTOBO_SYNC_WITH_S3}, 'Kernel::System::Storage::S3';

our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::DB',
'Kernel::System::Cache',
'Kernel::System::CustomerUser',
'Kernel::System::DB',
'Kernel::System::Group',
'Kernel::System::Log',
'Kernel::System::Main',
'Kernel::System::Storage::S3',
'Kernel::System::User',
'Kernel::System::XML',
);
Expand Down Expand Up @@ -584,7 +584,7 @@ sub CustomCodeActivate {
if ( $Self->{UseS3Backend} ) {

# in the S3 case only write to the S3 compatible storage
my $StorageS3Object = Kernel::System::Storage::S3->new();
my $StorageS3Object = $Kernel::OM->Get('Kernel::System::Storage::S3');

my $Key = "Kernel/Config/Files/$PackageName.pm";
$StorageS3Object->StoreObject(
Expand Down Expand Up @@ -623,7 +623,7 @@ sub CustomFileCleanup {

# also delete in the Backend
if ( $Self->{UseS3Backend} ) {
my $StorageS3Object = Kernel::System::Storage::S3->new();
my $StorageS3Object = $Kernel::OM->Get('Kernel::System::Storage::S3');
$StorageS3Object->DiscardObjects(
Prefix => 'Kernel/Config/Files/',
Delimiter => '',
Expand Down
12 changes: 6 additions & 6 deletions bin/docker/quick_setup.pl
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ =head1 OPTIONS
use Kernel::System::ObjectManager;

sub Main {
my $HelpFlag; # print help
my $DBPassword; # required
my $HTTPPort = 80; # only used for success message
my $ActivateElasticsearch = 0; # must be explicitly enabled
my $AddCustomerUser = 0; # must be explicitly enabled
my $ActivateSyncWithS3 = $ENV{OTOBO_SYNC_WITH_S3}; # activate S3 in the SysConfig, still experimental
my $HelpFlag; # print help
my $DBPassword; # required
my $HTTPPort = 80; # only used for success message
my $ActivateElasticsearch = 0; # must be explicitly enabled
my $AddCustomerUser = 0; # must be explicitly enabled
my $ActivateSyncWithS3 = 0; # activate S3 in the SysConfig, still experimental

Getopt::Long::GetOptions(
'help' => \$HelpFlag,
Expand Down

0 comments on commit e365208

Please sign in to comment.