diff --git a/data/common/common.yaml b/data/common/common.yaml --- a/data/common/common.yaml +++ b/data/common/common.yaml @@ -4249,16 +4249,35 @@ args: hosts: "%{alias('swh::elasticsearch::nodes')}" -swh::deploy::search_journal_client::config_file: "%{lookup('swh::deploy::base_search::config_directory')}/journal_client.yml" -swh::deploy::search_journal_client::config: +swh::deploy::search::journal_client::service_types: + - objects + - indexed + +swh::deploy::search::journal_client::objects::config_file: "%{lookup('swh::deploy::base_search::config_directory')}/journal_client_objects.yml" +swh::deploy::search::journal_client::objects::config: search: cls: elasticsearch - args: - hosts: "%{alias('swh::elasticsearch::nodes')}" + hosts: "%{alias('swh::elasticsearch::nodes')}" journal: brokers: "%{alias('swh::deploy::journal::brokers')}" group_id: swh.search.journal_client - prefix: "%{alias('swh::deploy::journal::prefix')}" + prefix: swh.journal.objects + object_types: + - origin + - origin_visit + - origin_visit_status + +swh::deploy::search::journal_client::indexed::config_file: "%{lookup('swh::deploy::base_search::config_directory')}/journal_client_indexed.yml" +swh::deploy::search::journal_client::indexed::config: + search: + cls: elasticsearch + hosts: "%{alias('swh::elasticsearch::nodes')}" + journal: + brokers: "%{alias('swh::deploy::journal::brokers')}" + group_id: swh.search.journal_client + prefix: swh.journal.indexed + object_types: + - origin_intrinsic_metadata swh::deploy::search::backend::listen::host: 127.0.0.1 swh::deploy::search::backend::listen::port: "%{alias('swh::remote_service::search::port')}" diff --git a/site-modules/profile/manifests/swh/deploy/search/journal_client.pp b/site-modules/profile/manifests/swh/deploy/search/journal_client.pp new file mode 100644 --- /dev/null +++ b/site-modules/profile/manifests/swh/deploy/search/journal_client.pp @@ -0,0 +1,28 @@ +# Deployment of the swh.search.journal_client +class profile::swh::deploy::search::journal_client { + include profile::swh::deploy::journal + + $service_types = lookup('swh::deploy::search::journal_client::service_types') + + $systemd_template_unit_name = 'swh-search-journal-client@.service' + $config_directory = lookup("swh::deploy::base_search::config_directory") + + $user = lookup('swh::deploy::base_search::user') + $group = lookup('swh::deploy::base_search::group') + + # Uses: + # - $config_directory + # - $user + # - $group + systemd::unit_file {$systemd_template_unit_name: + ensure => 'present', + content => template("profile/swh/deploy/journal/${systemd_template_unit_name}.erb"), + } + + $service_types.each | $service_type | { + profile::swh::deploy::search::journal_client_instance {$service_type: + ensure => 'running', + require => Package['python3-swh.search'], + } + } +} diff --git a/site-modules/profile/manifests/swh/deploy/search/journal_client_instance.pp b/site-modules/profile/manifests/swh/deploy/search/journal_client_instance.pp new file mode 100644 --- /dev/null +++ b/site-modules/profile/manifests/swh/deploy/search/journal_client_instance.pp @@ -0,0 +1,53 @@ +# Instance of a worker +define profile::swh::deploy::search::journal_client_instance ( + $ensure = present, + $instance_name = $title, +) +{ + include profile::swh::deploy::base_search + + $service_name = "swh-search-journal-client@${instance_name}" + + $config_path = lookup("swh::deploy::search::journal_client::${instance_name}::config_file") + $config = lookup("swh::deploy::search::journal_client::${instance_name}::config", Hash, 'deep') + + $user = lookup('swh::deploy::base_search::user') + $group = lookup('swh::deploy::base_search::group') + + case $ensure { + 'present', 'running': { + + file {$config_path: + ensure => 'present', + owner => $user, + group => $group, + mode => '0644', + content => inline_template("<%= @config.to_yaml %>\n"), + notify => Service[$service_name], + } + + if $ensure == 'running' { + $service_ensure = 'running' + } else { + $service_ensure = undef + } + + service {$service_name: + ensure => $service_ensure, + enable => true, + require => [ + File[$config_path], + ] + } + } + default: { + # clean up + service {$service_name: + ensure => absent, + } + -> file {$config_path: + ensure => absent, + } + } + } +} diff --git a/site-modules/profile/manifests/swh/deploy/search_journal_client.pp b/site-modules/profile/manifests/swh/deploy/search_journal_client.pp deleted file mode 100644 --- a/site-modules/profile/manifests/swh/deploy/search_journal_client.pp +++ /dev/null @@ -1,32 +0,0 @@ -# Deployment of the swh.search.journal_client -class profile::swh::deploy::search_journal_client { - include ::profile::swh::deploy::base_search - include ::profile::swh::deploy::journal - - $config_path = lookup('swh::deploy::search_journal_client::config_file') - $config = lookup('swh::deploy::search_journal_client::config') - - $service_name = 'swh-search-journal-client' - $unit_name = "${service_name}.service" - $user = lookup('swh::deploy::base_search::user') - $group = lookup('swh::deploy::base_search::group') - - Package['python3-swh.search'] ~> Service[$service_name] - - file {$config_path: - ensure => present, - owner => 'root', - group => 'swhdev', - mode => '0644', - content => inline_template("<%= @config.to_yaml %>\n"), - notify => Service[$service_name], - } - - ::systemd::unit_file {$unit_name: - ensure => present, - content => template("profile/swh/deploy/journal/${unit_name}.erb"), - } ~> service {$service_name: - ensure => running, - enable => true, - } -} diff --git a/site-modules/profile/templates/swh/deploy/journal/swh-search-journal-client.service.erb b/site-modules/profile/templates/swh/deploy/journal/swh-search-journal-client.service.erb deleted file mode 100644 --- a/site-modules/profile/templates/swh/deploy/journal/swh-search-journal-client.service.erb +++ /dev/null @@ -1,18 +0,0 @@ -# Search Journal Client unit file -# Managed by puppet class profile::swh::deploy::search_journal_client -# Changes will be overwritten - -[Unit] -Description=Software Heritage Search Journal Client -After=network.target - -[Service] -User=<%= @user %> -Group=<%= @group %> -Type=simple -ExecStart=/usr/bin/swh search --config-file <%= @config_path %> journal-client objects -Restart=always -RestartSec=10 - -[Install] -WantedBy=multi-user.target diff --git a/site-modules/profile/templates/swh/deploy/journal/swh-search-journal-client@.service.erb b/site-modules/profile/templates/swh/deploy/journal/swh-search-journal-client@.service.erb new file mode 100644 --- /dev/null +++ b/site-modules/profile/templates/swh/deploy/journal/swh-search-journal-client@.service.erb @@ -0,0 +1,18 @@ +# Search Journal Client Template unit file +# Managed by puppet class profile::swh::deploy::search::journal_client +# Changes will be overwritten + +[Unit] +Description=Software Heritage Search Journal Client %i +After=network.target + +[Service] +User=<%= @user %> +Group=<%= @group %> +Type=simple +ExecStart=/usr/bin/swh search --config-file <%= @config_directory %>/journal_client_%i.yml journal-client objects +Restart=always +RestartSec=10 + +[Install] +WantedBy=multi-user.target diff --git a/site-modules/role/manifests/swh_search_with_journal_client.pp b/site-modules/role/manifests/swh_search_with_journal_client.pp --- a/site-modules/role/manifests/swh_search_with_journal_client.pp +++ b/site-modules/role/manifests/swh_search_with_journal_client.pp @@ -1,4 +1,4 @@ class role::swh_search_with_journal_client inherits role::swh_server { - include ::profile::swh::deploy::search - include profile::swh::deploy::search_journal_client + include profile::swh::deploy::search + include profile::swh::deploy::search::journal_client }