Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge develop into main #423

Merged
merged 11 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM tomcat:jdk17-temurin-focal
FROM tomcat:10-jdk17-temurin-jammy
RUN groupadd -r mcr -g 501 && \
useradd -d /home/mcr -u 501 -m -s /bin/bash -g mcr mcr
WORKDIR /usr/local/tomcat/
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ ubo-cli/target/bin/ubo.sh create configuration directory
create database ubo;
grant all privileges on ubo.* to ubo@localhost identified by 'ubo';
```
- setup your database and JDBC configuration in persistence.xml and **REMOVE** the following lines
- setup your database and JDBC configuration in persistence.xml, update mappings with:
```
<mapping-file>META-INF/mycore-iview2-mappings.xml</mapping-file>
<mapping-file>META-INF/mycore-viewer-mappings.xml</mapping-file>
<mapping-file>META-INF/mycore-ifs-mappings.xml</mapping-file>
ubo-cli/target/bin/ubo.sh reload mappings in jpa configuration file
```
```
vi ~/.mycore/ubo/resources/META-INF/persistence.xml
Expand All @@ -34,7 +32,7 @@ vi ~/.mycore/ubo/resources/META-INF/persistence.xml
- copy jdbc driver to ~/.mycore/ubo/lib, eg. for h2
```
cd ~/.mycore/ubo/lib
wget https://repo1.maven.org/maven2/com/h2database/h2/1.4.200/h2-1.4.200.jar
wget https://repo1.maven.org/maven2/com/h2database/h2/2.2.224/h2-2.2.224.jar
cd -
```
## Solr
Expand Down
105 changes: 79 additions & 26 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,56 @@ function downloadDriver {
fi
}

function migrateC3P0toHikari {
# check if c3p0 is used (if any c3p0-* file present)
if ls "${MCR_CONFIG_DIR}lib/c3p0-"*.jar 1> /dev/null 2>&1; then
echo "Migrate from c3p0 to HikariCP"
# delete old c3p0 drivers
rm "${MCR_CONFIG_DIR}lib/c3p0-"*.jar
rm "${MCR_CONFIG_DIR}lib/mchange-commons-java-"*.jar
rm "${MCR_CONFIG_DIR}lib/hibernate-c3p0-"*.jar

# delete old database drivers
rm "${MCR_CONFIG_DIR}lib/postgresql-42.2.9.jar"
rm "${MCR_CONFIG_DIR}lib/mariadb-java-client-2.5.4.jar"
rm "${MCR_CONFIG_DIR}lib/h2-1.4.200.jar"
rm "${MCR_CONFIG_DIR}lib/mysql-connector-java-8.0.19.jar"

# delete old configuration and add new configuration
if grep -q "hibernate.c3p0" "${PERSISTENCE_XML}"; then
sed -ri "s/.*hibernate.c3p0.*//" "${PERSISTENCE_XML}"
sed -ri "s/(<property name=\"hibernate.connection.provider_class\" value=\")(.*)(\" \/>)/\1org.hibernate.hikaricp.internal.HikariCPConnectionProvider\3/" "${PERSISTENCE_XML}"
sed -ri "s/(<\/properties>)/<property name=\"hibernate.hikari.maximumPoolSize\" value=\"30\" \/>\n<property name=\"hibernate.hikari.minimumIdle\" value=\"2\" \/>\n<property name=\"hibernate.hikari.idleTimeout\" value=\"30000\" \/>\n<property name=\"hibernate.hikari.maxLifetime\" value=\"1800000\" \/>\n<property name=\"hibernate.hikari.leakDetectionThreshold\" value=\"9000\" \/>\n<property name=\"hibernate.hikari.registerMbeans\" value=\"true\" \/>\n\1/" "${PERSISTENCE_XML}"
fi

/opt/ubo/ubo-cli/target/bin/ubo.sh reload mappings in jpa configuration file
else
echo "No c3p0 driver found. Skip migration."
fi
}

function migrateJavaxPropertiesToJakarta() {
if grep -q "javax.persistence" "${PERSISTENCE_XML}"; then
echo "Migrate properties in persistence.xml from javax to jakarta"
sed -ri "s/(<property name=\")javax.persistence(.*\" value=\".*\" \/>)/\1jakarta.persistence\2/" "${PERSISTENCE_XML}"
fi
if grep -q "xmlns.jcp.org" "${PERSISTENCE_XML}"; then
echo "Migrate xmlns in persistence.xml from jcp.org to jakarta.ee"
sed -ri "s/xmlns=\".+persistence\"/xmlns=\"https:\/\/jakarta.ee\/xml\/ns\/persistence\"/" "${PERSISTENCE_XML}"
echo "Migrate schemaLocation in persistence.xml from jcp.org to jakarta.ee"
sed -ri "s/(xsi:schemaLocation=\").*jcp.org.*(\")/\1https:\/\/jakarta.ee\/xml\/ns\/persistence https:\/\/jakarta.ee\/xml\/ns\/persistence\/persistence_3_0.xsd\2/" "${PERSISTENCE_XML}"
fi
if grep -q "version=\"2" "${PERSISTENCE_XML}"; then
echo "Migrate version in persistence.xml from 2.* to 3.0"
sed -ri "s/version=\"2.*\"/version=\"3.0\"/" "${PERSISTENCE_XML}"
fi
}

function setDockerValues() {
echo "Set Docker Values to Config!"

migrateJavaxPropertiesToJakarta

if [ -n "${SOLR_URL}" ]; then
sed -ri "s/#?(MCR\.Solr\.ServerURL=).+/\1${SOLR_URL_ESCAPED}/" "${MYCORE_PROPERTIES}";
fi
Expand All @@ -70,23 +118,33 @@ function setDockerValues() {
fi

if [ -n "${JDBC_NAME}" ]; then
sed -ri "s/(name=\"javax.persistence.jdbc.user\" value=\").*(\")/\1${JDBC_NAME_ESCAPED}\2/" "${PERSISTENCE_XML}"
sed -ri "s/(name=\"jakarta.persistence.jdbc.user\" value=\").*(\")/\1${JDBC_NAME_ESCAPED}\2/" "${PERSISTENCE_XML}"
fi

if [ -n "${JDBC_PASSWORD}" ]; then
sed -ri "s/(name=\"javax.persistence.jdbc.password\" value=\").*(\")/\1${JDBC_PASSWORD_ESCAPED}\2/" "${PERSISTENCE_XML}"
sed -ri "s/(name=\"jakarta.persistence.jdbc.password\" value=\").*(\")/\1${JDBC_PASSWORD_ESCAPED}\2/" "${PERSISTENCE_XML}"
fi

if [ -n "${JDBC_DRIVER}" ]; then
sed -ri "s/(name=\"javax.persistence.jdbc.driver\" value=\").*(\")/\1${JDBC_DRIVER_ESCAPED}\2/" "${PERSISTENCE_XML}"
sed -ri "s/(name=\"jakarta.persistence.jdbc.driver\" value=\").*(\")/\1${JDBC_DRIVER_ESCAPED}\2/" "${PERSISTENCE_XML}"
fi

if [ -n "${JDBC_URL}" ]; then
sed -ri "s/(name=\"javax.persistence.jdbc.url\" value=\").*(\")/\1${JDBC_URL_ESCAPED}\2/" "${PERSISTENCE_XML}"
sed -ri "s/(name=\"jakarta.persistence.jdbc.url\" value=\").*(\")/\1${JDBC_URL_ESCAPED}\2/" "${PERSISTENCE_XML}"
fi

if [ -n "${SOLR_CLASSIFICATION_CORE}" ]; then
sed -ri "s/(name=\"hibernate.default_schema\" value=\").*(\")/\1${HIBERNATE_SCHEMA_ESCAPED}\2/" "${PERSISTENCE_XML}"
if [ -n "${JDBC_SCHEMA}" ]; then
if grep -q "hibernate.default_schema" "${PERSISTENCE_XML}"; then
sed -ri "s/(name=\"hibernate.default_schema\" value=\").*(\")/\1${JDBC_SCHEMA_ESCAPED}\2/" "${PERSISTENCE_XML}"
else
sed -ri "s/(<\/properties>)/<property name=\"hibernate.default_schema\" value=\"${JDBC_SCHEMA_ESCAPED}\" \/>\n\1/" "${PERSISTENCE_XML}"
fi

if grep -q "hibernate.hbm2ddl.create_namespaces" "${PERSISTENCE_XML}"; then
sed -ri "s/(name=\"hibernate.hbm2ddl.create_namespaces\" value=\").*(\")/\1true\2/" "${PERSISTENCE_XML}"
else
sed -ri "s/(<\/properties>)/<property name=\"hibernate.hbm2ddl.create_namespaces\" value=\"true\" \/>\n\1/" "${PERSISTENCE_XML}"
fi
fi

sed -ri "s/(name=\"hibernate.hbm2ddl.auto\" value=\").*(\")/\1update\2/" "${PERSISTENCE_XML}"
Expand All @@ -97,43 +155,38 @@ function setDockerValues() {
echo "MCR.datadir=${MCR_DATA_DIR}">>"${MYCORE_PROPERTIES}"
fi

if grep -q "MCR.Solr.NestedDocuments=" "${MYCORE_PROPERTIES}" ; then
sed -ri "s/#?(MCR\.Solr\.NestedDocuments=).+/\1true/" "${MYCORE_PROPERTIES}"
else
echo "MCR.Solr.NestedDocuments=true">>"${MYCORE_PROPERTIES}";
fi

if grep -q "MCR.Save.FileSystem=" "${MYCORE_PROPERTIES}" ; then
sed -ri "s/#?(MCR\.Save\.FileSystem=).+/\1${MCR_SAVE_DIR_ESCAPED}/" "${MYCORE_PROPERTIES}"
else
echo "MCR.Save.FileSystem=${MCR_SAVE_DIR}">>"${MYCORE_PROPERTIES}"
fi

migrateC3P0toHikari

case $JDBC_DRIVER in
org.postgresql.Driver) downloadDriver "https://jdbc.postgresql.org/download/postgresql-42.2.9.jar";;
org.mariadb.jdbc.Driver) downloadDriver "https://repo.maven.apache.org/maven2/org/mariadb/jdbc/mariadb-java-client/2.5.4/mariadb-java-client-2.5.4.jar";;
org.hsqldb.jdbcDriver) downloadDriver "https://repo.maven.apache.org/maven2/org/hsqldb/hsqldb/2.5.0/hsqldb-2.5.0.jar";;
org.h2.Driver) downloadDriver "https://repo.maven.apache.org/maven2/com/h2database/h2/1.4.200/h2-1.4.200.jar";;
com.mysql.jdbc.Driver) downloadDriver "https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/8.0.19/mysql-connector-java-8.0.19.jar";;
org.postgresql.Driver) downloadDriver "https://jdbc.postgresql.org/download/postgresql-42.7.0.jar";;
org.mariadb.jdbc.Driver) downloadDriver "https://repo.maven.apache.org/maven2/org/mariadb/jdbc/mariadb-java-client/3.3.0/mariadb-java-client-3.3.0.jar";;
org.h2.Driver) downloadDriver "https://repo1.maven.org/maven2/com/h2database/h2/2.2.224/h2-2.2.224.jar";;
com.mysql.jdbc.Driver) downloadDriver "https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/8.2.0/mysql-connector-j-8.2.0.jar";;
esac

mkdir -p "${MCR_CONFIG_DIR}lib"

downloadDriver https://repo1.maven.org/maven2/org/hibernate/hibernate-c3p0/5.3.9.Final/hibernate-c3p0-5.3.9.Final.jar
downloadDriver https://repo1.maven.org/maven2/com/mchange/c3p0/0.9.5.2/c3p0-0.9.5.2.jar
downloadDriver https://repo1.maven.org/maven2/com/mchange/mchange-commons-java/0.2.15/mchange-commons-java-0.2.15.jar


if [ -f "${MCR_CONFIG_DIR}jwt.secret" ]; then
echo "jwt.secret already exists."
else
echo "jwt.secret does not exists, create it.."
openssl rand -out "${MCR_CONFIG_DIR}jwt.secret" 4096
fi;
downloadDriver https://repo1.maven.org/maven2/com/zaxxer/HikariCP/5.1.0/HikariCP-5.1.0.jar
}

function setUpMyCoRe {
/opt/ubo/ubo-cli/target/bin/ubo.sh create configuration directory
setDockerValues
setupLog4jConfig
sed -ri "s/(<\/properties>)/<property name=\"hibernate\.connection\.provider_class\" value=\"org\.hibernate\.connection\.C3P0ConnectionProvider\" \/>\n<property name=\"hibernate\.c3p0\.min_size\" value=\"2\" \/>\n<property name=\"hibernate\.c3p0\.max_size\" value=\"50\" \/>\n<property name=\"hibernate\.c3p0\.acquire_increment\" value=\"2\" \/>\n<property name=\"hibernate\.c3p0\.max_statements\" value=\"30\" \/>\n<property name=\"hibernate\.c3p0\.timeout\" value=\"1800\" \/>\n\1/" "${PERSISTENCE_XML}"
sed -ri "s/<mapping-file>META-INF\/mycore-viewer-mappings.xml<\/mapping-file>//" "${PERSISTENCE_XML}"
sed -ri "s/<mapping-file>META-INF\/mycore-iview2-mappings.xml<\/mapping-file>//" "${PERSISTENCE_XML}"
sed -ri "s/<mapping-file>META-INF\/mycore-ifs-mappings.xml<\/mapping-file>//" "${PERSISTENCE_XML}"
/opt/ubo/ubo-cli/target/bin/ubo.sh reload mappings in jpa configuration file
sed -ri "s/(<\/properties>)/<property name=\"hibernate.hikari.maximumPoolSize\" value=\"30\" \/>\n<property name=\"hibernate.hikari.minimumIdle\" value=\"2\" \/>\n<property name=\"hibernate.hikari.idleTimeout\" value=\"30000\" \/>\n<property name=\"hibernate.hikari.maxLifetime\" value=\"1800000\" \/>\n<property name=\"hibernate.hikari.leakDetectionThreshold\" value=\"9000\" \/>\n<property name=\"hibernate.hikari.registerMbeans\" value=\"true\" \/>\n\1/" "${MCR_CONFIG_DIR}resources/META-INF/persistence.xml"
/opt/ubo/ubo-cli/target/bin/ubo.sh init superuser
/opt/ubo/ubo-cli/target/bin/ubo.sh update all classifications from directory /opt/ubo/ubo-cli/src/main/setup/classifications
/opt/ubo/ubo-cli/target/bin/ubo.sh update permission create-mods for id POOLPRIVILEGE with rulefile /opt/ubo/ubo-cli/src/main/setup/acl/acl-rule-always-allowed.xml described by always allowed
Expand Down
37 changes: 34 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.mycore</groupId>
<artifactId>mycore-parent</artifactId>
<version>49</version>
<version>55</version>
</parent>

<groupId>org.mycore.ubo</groupId>
Expand Down Expand Up @@ -53,13 +53,14 @@
<java.target.version>17</java.target.version>
<jquery.ui.version>1.13.2</jquery.ui.version>
<jquery.version>3.5.1</jquery.version>
<mycore.version>2022.06.3-SNAPSHOT</mycore.version>
<mycore.version>2023.06.3-SNAPSHOT</mycore.version>
<node.version>v16.0.0</node.version>
<pica2mods.version>2.10</pica2mods.version>
<sortpom.sortDeps>scope,groupId,artifactId</sortpom.sortDeps>
<sortpom.sortFile>https://gist.githubusercontent.com/yagee-de/dfd3698c1b49173dbf251f74eb6a9297/raw/406460c088ff3cb6354e4ae6b40535e6f841607d/mycore_sort.xml</sortpom.sortFile>
<sortpom.sortProps>true</sortpom.sortProps>
<timestamp>${maven.build.timestamp}</timestamp>
<tomcat.version>10.1.11</tomcat.version>
<yarn.version>v1.22.10</yarn.version>
</properties>

Expand All @@ -74,6 +75,31 @@
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>com.github.ekryd.sortpom</groupId>
<artifactId>sortpom-maven-plugin</artifactId>
<executions>
<execution>
<id>verify-sort-pom</id>
<goals>
<goal>sort</goal>
</goals>
<phase>verify</phase>
<configuration>
<createBackupFile>false</createBackupFile>
<expandEmptyElements>false</expandEmptyElements>
<spaceBeforeCloseEmptyElement>true</spaceBeforeCloseEmptyElement>
<keepBlankLines>true</keepBlankLines>
<sortDependencies>${sortpom.sortDeps}</sortDependencies>
<sortOrderFile>${sortpom.sortFile}</sortOrderFile>
<sortProperties>${sortpom.sortProps}</sortProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
Expand Down Expand Up @@ -179,7 +205,7 @@
</property>
</activation>
<properties>
<cargo.container>jetty9x</cargo.container>
<cargo.container>jetty12x</cargo.container>
</properties>
<build>
<pluginManagement>
Expand Down Expand Up @@ -281,6 +307,11 @@
<artifactId>bucket4j-core</artifactId>
<version>8.9.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.224</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
Expand Down
Loading
Loading