From 10a919ea0b5e7b5aa4cabeacb39aab9ea6e3b337 Mon Sep 17 00:00:00 2001 From: Seth Shaw Date: Thu, 29 Aug 2019 11:49:18 -0700 Subject: [PATCH] SQL-based Fedora object persistence (Issue 1244) (#8) * support SQL-based persistence * support SQL-based object persistence * use templates instead of default repository.json * add missing quotes * use ansible variables in repository.json instead of tomcat JAVA_OPTS * remove outdated note --- README.md | 39 ++++++++++++------- defaults/main.yml | 14 +++++++ tasks/config.yml | 9 ++++- tasks/db-mysql.yml | 14 +++++++ tasks/db-pgsql.yml | 13 +++++++ tasks/main.yml | 15 +++++++ ...itory.json => file-simple-repository.json} | 4 +- templates/jdbc-mysql-repository.json | 39 +++++++++++++++++++ templates/jdbc-postgresql-repository.json | 39 +++++++++++++++++++ 9 files changed, 168 insertions(+), 18 deletions(-) create mode 100644 tasks/db-mysql.yml create mode 100644 tasks/db-pgsql.yml rename templates/{repository.json => file-simple-repository.json} (84%) create mode 100644 templates/jdbc-mysql-repository.json create mode 100644 templates/jdbc-postgresql-repository.json diff --git a/README.md b/README.md index 233a429..8bf04bd 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,30 @@ Path to put Fedora data directory fcrepo_data_dir: "{{ fcrepo_home_dir }}/fcrepo4-data" ``` +Path to put the Fedora data binaries directory +``` +fcrepo_binary_directory: "{{ fcrepo_data_dir}}/binaries" +``` + +Which Fedora object persistence configuration to use +``` +fcrepo_persistence: file-simple +``` + +If 'file-simple persistence' is used (default), where to keep the modeshape repository file +``` +fcrepo_object_directory: "{{ fcrepo_data_dir}}/objects" +``` + +If either 'jdbc-mysql' or 'jdbc-postgres' are used for object persistence, the database settings +``` +fcrepo_db_name: fcrepo +fcrepo_db_user: fcrepo +fcrepo_db_password: fcrepo +fcrepo_db_host: "127.0.0.1" +fcrepo_db_port: "3306" +``` + Islandora uses the HeaderProvider to pass the users roles into Fedora. To use this you will need to set the below variable. Header name to acquire roles from @@ -80,21 +104,6 @@ fcrepo_allowed_external_content: roles: - { role: islandora.fcrepo } -## Notes - -This role only uses the fcrepo_data_dir to create a directory. To tell Fedora -to use this directory you either need to incorporate the value into the -[repository.json template](templates/repository.json) or add it to the Tomcat -Java Opts. For example, if using -[ansible-role-tomcat8](https://github.com/Islandora-Devops/ansible-role-tomcat8) -adding the following to your inventory: -``` -fcrepo_data_dir: "/data/fcrepo-data" - -tomcat8_java_opts: - - -Dfcrepo.binary.directory={{ fcrepo_data_dir }} -``` - ## License MIT diff --git a/defaults/main.yml b/defaults/main.yml index 99d41ea..972a834 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,11 +1,25 @@ fcrepo_version: 4.7.2 fcrepo_user: "{{ tomcat8_server_user }}" fcrepo_data_dir: /var/lib/tomcat8/fcrepo4-data +fcrepo_binary_directory: "{{ fcrepo_data_dir}}/binaries" fcrepo_war_path: "{{ tomcat8_home }}/webapps/fcrepo.war" fcrepo_home_dir: /opt/fcrepo fcrepo_activemq_template: activemq.xml.j2 fcrepo_config_dir: "{{ fcrepo_home_dir }}/configs" +# For file-simple object persistence. +fcrepo_object_directory: "{{ fcrepo_data_dir}}/objects" + +# For production use either "jdbc-mysql" or "jdbc-postgresql" +fcrepo_persistence: file-simple + +# Used for mysql or postgres object persistence. Please change the password locally! +fcrepo_db_name: fcrepo +fcrepo_db_user: fcrepo +fcrepo_db_password: fcrepo +fcrepo_db_host: "127.0.0.1" +fcrepo_db_port: "3306" + # External content paths can be directories or urls, # and they MUST end in / fcrepo_allowed_external_content: diff --git a/tasks/config.yml b/tasks/config.yml index 64c92f8..9d8ec5e 100644 --- a/tasks/config.yml +++ b/tasks/config.yml @@ -6,10 +6,17 @@ group: "{{ fcrepo_user }}" with_items: - claw.cnd - - repository.json - fcrepo-config.xml notify: restart tomcat8 +- name: Copy templated repository.json + template: + src: "{{ fcrepo_persistence }}-repository.json" + dest: "{{ fcrepo_home_dir }}/configs/repository.json" + owner: "{{ fcrepo_user }}" + group: "{{ fcrepo_user }}" + notify: restart tomcat8 + - name: Copy fedora activemq configuration template: src: "{{ fcrepo_activemq_template }}" diff --git a/tasks/db-mysql.yml b/tasks/db-mysql.yml new file mode 100644 index 0000000..e345038 --- /dev/null +++ b/tasks/db-mysql.yml @@ -0,0 +1,14 @@ +--- + +- name: Create Fedora DB (mysql) + mysql_db: + name: "{{ fcrepo_db_name }}" + state: present + register: fcrepo_db_exists + +- name: Create Fedora DB User (mysql) + mysql_user: + name: "{{ fcrepo_db_user }}" + password: "{{ fcrepo_db_password }}" + state: present + priv: "{{fcrepo_db_name}}.*:ALL" diff --git a/tasks/db-pgsql.yml b/tasks/db-pgsql.yml new file mode 100644 index 0000000..135e71a --- /dev/null +++ b/tasks/db-pgsql.yml @@ -0,0 +1,13 @@ +--- + +- name: Create Fedora DB User (pgsql) + postgresql_user: + name: "{{ fcrepo_db_user }}" + password: "{{ fcrepo_db_password }}" + +- name: Create Fedora DB (pgsql) + postgresql_db: + name: "{{ fcrepo_db_name }}" + state: present + owner: "{{ fcrepo_db_user }}" + register: fcrepo_db_exists diff --git a/tasks/main.yml b/tasks/main.yml index 6bb3a16..b44fd7a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,6 +3,21 @@ - fcrepo - fcrepo-install +- include: db-mysql.yml + when: fcrepo_persistence == 'jdbc-mysql' + tags: + - fedora + - fedora-install + - fedora-db + +- include: db-pgsql.yml + when: fcrepo_persistence == 'jdbc-postgresql' + become: yes + tags: + - fedora + - fedora-install + - fedora-db + - include: config.yml tags: - fcrepo diff --git a/templates/repository.json b/templates/file-simple-repository.json similarity index 84% rename from templates/repository.json rename to templates/file-simple-repository.json index 909021f..e7b0445 100644 --- a/templates/repository.json +++ b/templates/file-simple-repository.json @@ -9,11 +9,11 @@ "storage" : { "persistence": { "type": "file", - "path" : "${fcrepo.object.directory:target/objects}" + "path" : "{{ fcrepo_object_directory }}" }, "binaryStorage" : { "type" : "file", - "directory" : "${fcrepo.binary.directory:target/binaries}", + "directory" : "{{ fcrepo_binary_directory }}", "minimumBinarySizeInBytes" : 4096 } }, diff --git a/templates/jdbc-mysql-repository.json b/templates/jdbc-mysql-repository.json new file mode 100644 index 0000000..72306de --- /dev/null +++ b/templates/jdbc-mysql-repository.json @@ -0,0 +1,39 @@ +{ + "name" : "repo", + "jndiName" : "", + "workspaces" : { + "predefined" : ["default"], + "default" : "default", + "allowCreation" : true, + "cacheSize" : 10000 + }, + "storage" : { + "persistence": { + "type" : "db", + "connectionUrl": "jdbc:mysql://{{ fcrepo_db_host }}:{{ fcrepo_db_port }}/{{ fcrepo_db_name }}?createDatabaseIfNotExist=true", + "driver" : "com.mysql.jdbc.Driver", + "username" : "{{ fcrepo_db_user }}", + "password" : "{{ fcrepo_db_password }}" + }, + "binaryStorage" : { + "type" : "file", + "directory" : "{{ fcrepo_binary_directory }}", + "minimumBinarySizeInBytes" : 4096 + } + }, + "security" : { + "anonymous" : { + "roles" : ["readonly","readwrite","admin"], + "useOnFailedLogin" : false + }, + "providers" : [ + { "classname" : "org.fcrepo.auth.common.BypassSecurityServletAuthenticationProvider" } + ] + }, + "garbageCollection" : { + "threadPool" : "modeshape-gc", + "initialTime" : "00:00", + "intervalInHours" : 24 + }, + "node-types" : ["fedora-node-types.cnd", "file:/opt/fcrepo/configs/claw.cnd"] +} diff --git a/templates/jdbc-postgresql-repository.json b/templates/jdbc-postgresql-repository.json new file mode 100644 index 0000000..d01379c --- /dev/null +++ b/templates/jdbc-postgresql-repository.json @@ -0,0 +1,39 @@ +{ + "name" : "repo", + "jndiName" : "", + "workspaces" : { + "predefined" : ["default"], + "default" : "default", + "allowCreation" : true, + "cacheSize" : 10000 + }, + "storage" : { + "persistence": { + "type" : "db", + "connectionUrl": "jdbc:postgresql://{{ fcrepo_db_host }}:{{ fcrepo_db_port }}/{{ fcrepo_db_name }}", + "driver" : "org.postgresql.Driver", + "username" : "{{ fcrepo_db_user }}", + "password" : "{{ fcrepo_db_password }}" + }, + "binaryStorage" : { + "type" : "file", + "directory" : "{{ fcrepo_binary_directory }}", + "minimumBinarySizeInBytes" : 4096 + } + }, + "security" : { + "anonymous" : { + "roles" : ["readonly","readwrite","admin"], + "useOnFailedLogin" : false + }, + "providers" : [ + { "classname" : "org.fcrepo.auth.common.BypassSecurityServletAuthenticationProvider" } + ] + }, + "garbageCollection" : { + "threadPool" : "modeshape-gc", + "initialTime" : "00:00", + "intervalInHours" : 24 + }, + "node-types" : ["fedora-node-types.cnd", "file:/opt/fcrepo/configs/claw.cnd"] +}