Skip to content

Commit

Permalink
Merge pull request #388 from guusdk/387_Openfire-4.9.0-compat
Browse files Browse the repository at this point in the history
Fix compatibility issue with Openfire 4.9.0
  • Loading branch information
akrherz authored Sep 6, 2024
2 parents a9247d7 + 87e056f commit 753864b
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ "8", "11" ]
java: [ "11" ]

steps:
# Checkout Repo
Expand Down
6 changes: 4 additions & 2 deletions changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ <h1>
Monitoring Plugin Changelog
</h1>

<p><b>2.5.1</b> -- (tbd)</p>
<p><b>2.6.0</b> -- (tbd)</p>
<ul>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/377'>Issue #383</a>] - Fixes: Database query fails on Oracle</li>
<li>Requires Openfire 4.8.0</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/387'>Issue #387</a>] - Fixes: Compatibility issue with Openfire 4.9.0</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/383'>Issue #383</a>] - Fixes: Database query fails on Oracle</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/377'>Issue #377</a>] - Fixes: Erroneous index confirmation message</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/367'>Issue #367</a>] - Fixes: JRobin's repository uses invalid certificate</li>
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/249'>Issue #249</a>] - Fixes: Erroneous index rebuild progress indicator</li>
Expand Down
5 changes: 2 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
<description>Monitors conversations and statistics of the server.</description>
<author>Ignite Realtime</author>
<version>${project.version}</version>
<date>2024-04-17</date>
<minServerVersion>4.7.0</minServerVersion>
<minJavaVersion>1.8</minJavaVersion>
<date>2024-08-23</date>
<minServerVersion>4.8.0</minServerVersion>
<databaseKey>monitoring</databaseKey>
<databaseVersion>8</databaseVersion>

Expand Down
22 changes: 10 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<artifactId>plugins</artifactId>
<groupId>org.igniterealtime.openfire</groupId>
<version>4.7.0</version>
<version>4.8.0</version>
</parent>
<groupId>org.igniterealtime.openfire.plugins</groupId>
<artifactId>monitoring</artifactId>
<version>2.5.1-SNAPSHOT</version>
<version>2.6.0-SNAPSHOT</version>
<name>Monitoring Plugin</name>
<description>Monitors conversations and statistics of the server.</description>

Expand Down Expand Up @@ -53,9 +53,9 @@
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.jrobin</groupId>
<groupId>com.purej</groupId>
<artifactId>jrobin</artifactId>
<version>1.6.0</version>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>jfree</groupId>
Expand Down Expand Up @@ -103,7 +103,12 @@
<artifactId>jaxb-runtime</artifactId>
<version>2.3.3</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand All @@ -113,13 +118,6 @@
<name>Ignite Realtime Repository</name>
<url>https://igniterealtime.org/archiva/repository/maven/</url>
</repository>

<!-- For jrobin -->
<repository>
<id>opennms-repo</id>
<name>OpenNMS Release Repository</name>
<url>https://maven.mirrors.opennms.org/maven2/</url>
</repository>
</repositories>

<pluginRepositories>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2008 Jive Software, 2024 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reucon.openfire.plugin.archive.impl;

import org.apache.lucene.document.*;
Expand All @@ -17,6 +32,7 @@
import javax.print.Doc;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -53,7 +69,7 @@ public class MessageIndexer extends LuceneIndexer

public MessageIndexer( final TaskEngine taskEngine, final ConversationManager conversationManager )
{
super(taskEngine, new File(JiveGlobals.getHomeDirectory() + File.separator + MonitoringConstants.NAME + File.separator + "msgsearch"), "MESSAGE", SCHEMA_VERSION);
super(taskEngine, JiveGlobals.getHomePath().resolve(Path.of(MonitoringConstants.NAME, "msgsearch")), "MESSAGE", SCHEMA_VERSION);
this.conversationManager = conversationManager;
}

Expand Down
18 changes: 17 additions & 1 deletion src/java/com/reucon/openfire/plugin/archive/impl/MucIndexer.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2008 Jive Software, 2024 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reucon.openfire.plugin.archive.impl;

import org.apache.lucene.document.*;
Expand All @@ -13,6 +28,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -41,7 +57,7 @@ public class MucIndexer extends LuceneIndexer

public MucIndexer( final TaskEngine taskEngine, final ConversationManager conversationManager )
{
super(taskEngine, new File(JiveGlobals.getHomeDirectory() + File.separator + MonitoringConstants.NAME + File.separator + "mucsearch"), "MUCSEARCH", SCHEMA_VERSION);
super(taskEngine, JiveGlobals.getHomePath().resolve(Path.of(MonitoringConstants.NAME, "mucsearch")), "MUCSEARCH", SCHEMA_VERSION);
this.conversationManager = conversationManager;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Jive Software. All rights reserved.
* Copyright (C) 2008 Jive Software, Ignite Realtime Foundation 2024. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -67,7 +68,7 @@ public class ArchiveIndexer extends org.jivesoftware.openfire.index.LuceneIndexe
* @param taskEngine a task engine instance.
*/
public ArchiveIndexer(ConversationManager conversationManager, TaskEngine taskEngine) {
super(taskEngine, new File(JiveGlobals.getHomeDirectory() + File.separator + MonitoringConstants.NAME + File.separator + "search"), "CONVERSATION", SCHEMA_VERSION);
super(taskEngine, JiveGlobals.getHomePath().resolve(Path.of(MonitoringConstants.NAME, "search")), "CONVERSATION", SCHEMA_VERSION);
this.conversationManager = conversationManager;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Jive Software. All rights reserved.
* Copyright (C) 2008 Jive Software, Ignite Realtime Foundation 2024. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@

package org.jivesoftware.openfire.archive;

import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -96,7 +97,7 @@ public void run() {
}
}
};
taskEngine.scheduleAtFixedRate(sendTask, JiveConstants.SECOND * 3, JiveConstants.SECOND * 3);
taskEngine.scheduleAtFixedRate(sendTask, Duration.ofSeconds(3), Duration.ofSeconds(3));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Jive Software. All rights reserved.
* Copyright (C) 2008 Jive Software, Ignite Realtime Foundation 2024. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -255,7 +255,7 @@ public void run() {
}
}
};
taskEngine.scheduleAtFixedRate(cleanupTask, JiveConstants.MINUTE * 5, JiveConstants.MINUTE * 5);
taskEngine.scheduleAtFixedRate(cleanupTask, Duration.ofMinutes(5), Duration.ofMinutes(5));

// Schedule a task to do conversation purging.
maxAgeTask = new TimerTask() {
Expand Down Expand Up @@ -304,7 +304,7 @@ public void run() {
}
}
};
taskEngine.scheduleAtFixedRate(maxAgeTask, JiveConstants.MINUTE, JiveConstants.MINUTE);
taskEngine.scheduleAtFixedRate(maxAgeTask, Duration.ofMinutes(1), Duration.ofMinutes(1));

// Register a statistic.
Statistic conversationStat = new Statistic() {
Expand Down
59 changes: 40 additions & 19 deletions src/java/org/jivesoftware/openfire/index/LuceneIndexer.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2008 Jive Software, 2024 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.openfire.index;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -39,7 +54,7 @@ public abstract class LuceneIndexer
private final int schemaVersion;
protected TaskEngine taskEngine;
protected RebuildFuture rebuildFuture;
private File searchDir;
private Path searchDir;
private XMLProperties indexProperties;
private Directory directory;
private IndexSearcher searcher;
Expand All @@ -55,7 +70,7 @@ public abstract class LuceneIndexer
.setPlugin(MonitoringConstants.PLUGIN_NAME)
.build();

public LuceneIndexer(TaskEngine taskEngine, File searchDir, String logName, int schemaVersion)
public LuceneIndexer(TaskEngine taskEngine, Path searchDir, String logName, int schemaVersion)
{
this.taskEngine = taskEngine;
this.searchDir = searchDir;
Expand All @@ -66,19 +81,20 @@ public LuceneIndexer(TaskEngine taskEngine, File searchDir, String logName, int
public void start()
{
Log.debug("Starting...");
if ( !searchDir.exists() )
if (!Files.exists(searchDir))
{
if ( !searchDir.mkdirs() )
{
Log.warn("Lucene index directory '{}' does not exist, but cannot be created!", searchDir);
try {
Files.createDirectories(searchDir);
} catch (IOException e) {
Log.warn("Lucene index directory '{}' does not exist, but cannot be created!", searchDir, e);
}
}

boolean indexCreated = false;
try
{
indexProperties = loadPropertiesFile(searchDir);
directory = FSDirectory.open(searchDir.toPath());
directory = FSDirectory.open(searchDir);
if ( !DirectoryReader.indexExists(directory) )
{
Log.info("Unable to find a Lucene index in {}. rebuilding.", directory);
Expand All @@ -94,7 +110,7 @@ public void start()
{
// See if the data on disk is of the schema version that we expect to be able to use.
// TODO make this optional through configuration.
final Path schemaVersionFile = searchDir.toPath().resolve("openfire-schema.version");
final Path schemaVersionFile = searchDir.resolve("openfire-schema.version");
final Scanner scanner = new Scanner(schemaVersionFile);
int detectedSchemaVersion = -1;
if (scanner.hasNextInt())
Expand Down Expand Up @@ -169,17 +185,22 @@ public void run()
}
};
final Duration updateInterval = UPDATE_INTERVAL.getValue();
taskEngine.schedule(indexUpdater, Duration.ofMinutes(1).toMillis(), updateInterval.toMillis());
taskEngine.schedule(indexUpdater, Duration.ofMinutes(1), updateInterval);
}

private void removeAndRebuildSearchDir() throws IOException {
directory.close();
FileUtils.deleteDirectory(searchDir);
if ( !searchDir.mkdirs() )
FileUtils.deleteDirectory(searchDir.toFile());
if (!Files.exists(searchDir))
{
Log.warn("Lucene index directory '{}' cannot be recreated!", searchDir);
try {
Files.createDirectories(searchDir);
} catch (IOException e) {
Log.warn("Lucene index directory '{}' cannot be recreated!", searchDir, e);
}
}
directory = FSDirectory.open(searchDir.toPath());

directory = FSDirectory.open(searchDir);
}

protected synchronized Instant getLastModified()
Expand Down Expand Up @@ -244,7 +265,7 @@ public void stop()
*/
public long getIndexSize()
{
File[] files = searchDir.listFiles(( dir, name ) -> {
File[] files = searchDir.toFile().listFiles(( dir, name ) -> {
// Ignore the index properties file since it's not part of the index.
return !name.equals("indexprops.xml");
});
Expand Down Expand Up @@ -331,11 +352,11 @@ public synchronized Future<Integer> rebuildIndex() {

Log.debug("Removing old data from directory: {}", searchDir);
try {
FileUtils.cleanDirectory(searchDir);
Files.write(searchDir.toPath().resolve("openfire-schema.version"), String.valueOf(this.schemaVersion).getBytes());
FileUtils.cleanDirectory(searchDir.toFile());
Files.write(searchDir.resolve("openfire-schema.version"), String.valueOf(this.schemaVersion).getBytes());
indexProperties = loadPropertiesFile(searchDir);
} catch ( IOException e ) {
Log.warn("An exception occurred while trying to clean directory '{}' as part of a rebuild of the Lucene index that's in it.", searchDir);
Log.warn("An exception occurred while trying to clean directory '{}' as part of a rebuild of the Lucene index that's in it.", searchDir, e);
}

final Analyzer analyzer = new StandardAnalyzer();
Expand Down Expand Up @@ -431,9 +452,9 @@ public synchronized IndexSearcher getSearcher() throws IOException
* loaded. If an XML file for the search properties isn't already
* created, it will attempt to make a file with default values.
*/
private XMLProperties loadPropertiesFile( File searchDir ) throws IOException
private XMLProperties loadPropertiesFile( Path searchDir ) throws IOException
{
File indexPropertiesFile = new File(searchDir, "indexprops.xml");
File indexPropertiesFile = new File(searchDir.toFile(), "indexprops.xml");

// Make sure the file actually exists. If it doesn't, a new file
// will be created.
Expand Down
Loading

0 comments on commit 753864b

Please sign in to comment.