Skip to content

Commit

Permalink
Gather info about the wiki size xwikisas#7 (xwikisas#28)
Browse files Browse the repository at this point in the history
Gather info about the wiki size xwikisas#7
* Created base structure for wiki size data gathering
* Created SQL queries and needed support functions for gathering info about the wiki size
* Added comments
* Added translations
* Created UI template
* Added function for rendering the template
* Added tests
* merged WikiSizeProvider class with PingProvider class to UsageDataProvider
* removed ping initialization and ping field and intorduced it as a variable inside the functions to increase thread safety
  • Loading branch information
ChiuchiuSorin authored Jan 30, 2024
1 parent 5d57078 commit 9390191
Show file tree
Hide file tree
Showing 31 changed files with 1,057 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@
*/
package com.xwiki.admintools;

import java.util.Map;
import java.util.regex.Pattern;

import org.xwiki.component.annotation.Role;

import java.util.regex.Pattern;

/**
* Exposes methods for accessing server specific information, like configurations, logs or other XWiki and server
* files.
*
* @version $Id$
*/
@Role
public interface ServerIdentifier
public interface ServerInfo
{
/**
* Verify if a specific server is used. If a server path is provided in the XWiki configurations, it verifies if the
Expand Down Expand Up @@ -68,13 +67,6 @@ public interface ServerIdentifier
*/
void updatePossiblePaths();

/**
* Access a JSON containing the server metadata.
*
* @return the server metadata.
*/
Map<String, String> getServerMetadata();

/**
* Get path to server.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package com.xwiki.admintools;

import org.xwiki.stability.Unstable;

/**
* Stores info about the size of a wiki.
*
* @version $Id$
* @since 1.0
*/
@Unstable
public class WikiSizeResult
{
private String name;

private Long userCount;

private String attachmentsSize;

private Long attachmentsCount;

private Long documentsCount;

/**
* Null constructor to initialize a {@link WikiSizeResult} object.
*/
public WikiSizeResult()
{
}

/**
* Get the name of the wiki.
*
* @return the name of the wiki.
*/
public String getName()
{
return name;
}

/**
* Set the name of the wiki.
*
* @param name representing the name of the wiki.
*/
public void setName(String name)
{
this.name = name;
}

/**
* Get the number of users registered in the wiki.
*
* @return {@link Long} representing the number of users in the wiki.
*/
public Long getUserCount()
{
return userCount;
}

/**
* Set the number of users registered in the wiki.
*
* @param userCount the number of users in the wiki.
*/
public void setUserCount(Long userCount)
{
this.userCount = userCount;
}

/**
* Get the total size of the attachments in the wiki.
*
* @return formatted {@link String} with the size of the attachments in the wiki and corresponding size unit.
*/
public String getAttachmentsSize()
{
return attachmentsSize;
}

/**
* Set the total size of the attachments in the wiki.
*
* @param attachmentsSize the size of the attachments in the wiki and corresponding size unit.
*/
public void setAttachmentsSize(String attachmentsSize)
{
this.attachmentsSize = attachmentsSize;
}

/**
* Get the total number of the attachments in wiki.
*
* @return the total number of the attachments in wiki.
*/
public Long getAttachmentsCount()
{
return attachmentsCount;
}

/**
* Set the total number of the attachments in wiki.
*
* @param attachmentsCount the total number of the attachments in wiki.
*/
public void setAttachmentsCount(Long attachmentsCount)
{
this.attachmentsCount = attachmentsCount;
}

/**
* Get the total number of documents in wiki.
*
* @return the total number of documents in wiki.
*/
public Long getDocumentsCount()
{
return documentsCount;
}

/**
* Set the total number of documents in wiki.
*
* @param documentsCount the total number of documents in wiki.
*/
public void setDocumentsCount(Long documentsCount)
{
this.documentsCount = documentsCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
import com.xwiki.admintools.DataProvider;
import com.xwiki.admintools.internal.data.identifiers.CurrentServer;
import com.xwiki.admintools.internal.files.ImportantFilesManager;
import com.xwiki.admintools.internal.wikiUsage.InstanceUsage;

/**
* Manages the data providers.
* Manages the data that needs to be used by the Admin Tools application.
*
* @version $Id$
*/
Expand All @@ -58,6 +59,9 @@ public class AdminToolsManager
@Inject
private ImportantFilesManager importantFilesManager;

@Inject
private InstanceUsage instanceUsage;

@Inject
@Named("context")
private ComponentManager contextComponentManager;
Expand Down Expand Up @@ -119,4 +123,14 @@ public String getFilesSection()
{
return this.importantFilesManager.renderTemplate();
}

/**
* Get the rendered template for viewing info about the size of the XWiki instance.
*
* @return a {@link String} representation of the rendered template.
*/
public String getInstanceSizeTemplate()
{
return instanceUsage.renderTemplate();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@
import javax.inject.Singleton;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.xwiki.activeinstalls2.internal.data.DatabasePing;
import org.xwiki.component.annotation.Component;

import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xwiki.admintools.ServerIdentifier;
import com.xwiki.admintools.ServerInfo;
import com.xwiki.admintools.internal.wikiUsage.UsageDataProvider;
import com.xwiki.admintools.internal.data.identifiers.CurrentServer;
import com.xwiki.admintools.internal.PingProvider;

/**
* Extension of {@link AbstractDataProvider} for retrieving configuration data.
Expand All @@ -61,7 +60,7 @@ public class ConfigurationDataProvider extends AbstractDataProvider
private CurrentServer currentServer;

@Inject
private PingProvider pingProvider;
private UsageDataProvider usageDataProvider;

@Override
public String getIdentifier()
Expand Down Expand Up @@ -89,13 +88,13 @@ public Map<String, String> getDataAsJSON() throws Exception
{
try {
Map<String, String> systemInfo = new HashMap<>();
Map<String, String> dbMetadata = this.identifyDB();
Map<String, String> dbMetadata = this.usageDataProvider.getDatabaseMetadata();
systemInfo.put("databaseName", dbMetadata.get(METADATA_NAME));
systemInfo.put("databaseVersion", dbMetadata.get(METADATA_VERSION));
systemInfo.put("xwikiCfgPath", getCurrentServer().getXwikiCfgFolderPath());
systemInfo.put("tomcatConfPath", this.getCurrentServer().getServerCfgPath());
systemInfo.put("javaVersion", this.getJavaVersion());
Map<String, String> serverMetadata = this.getCurrentServer().getServerMetadata();
Map<String, String> serverMetadata = this.usageDataProvider.getServerMetadata();
systemInfo.put("usedServerName", serverMetadata.get(METADATA_NAME));
systemInfo.put("usedServerVersion", serverMetadata.get(METADATA_VERSION));
systemInfo.put("xwikiVersion", getXWikiVersion());
Expand All @@ -116,20 +115,6 @@ private String getJavaVersion()
return System.getProperty("java.version");
}

/**
* Identify the used database for XWiki by accessing the {@link DatabasePing}.
*
* @return database metadata or {@code null} in case of an error or if the used DB is not supported.
*/
private Map<String, String> identifyDB()
{
DatabasePing databasePing = pingProvider.getDatabasePing();
if (databasePing == null) {
return new HashMap<>();
}
return Map.of(METADATA_NAME, databasePing.getName(), METADATA_VERSION, databasePing.getVersion());
}

/**
* Get info about the OS that XWiki is running on.
*
Expand All @@ -145,13 +130,13 @@ private Map<String, String> getOSInfo()
return result;
}

private ServerIdentifier getCurrentServer()
private ServerInfo getCurrentServer()
{
ServerIdentifier serverIdentifier = currentServer.getCurrentServer();
if (serverIdentifier == null) {
ServerInfo serverInfo = currentServer.getCurrentServer();
if (serverInfo == null) {
throw new NullPointerException("Failed to retrieve the current used server, check your configurations.");
}
return serverIdentifier;
return serverInfo;
}

private String getXWikiVersion()
Expand Down
Loading

0 comments on commit 9390191

Please sign in to comment.