Skip to content

Commit

Permalink
Provide the ability to upload patches xwikisas#78
Browse files Browse the repository at this point in the history
* created upload job request and status
* renamed HealthCheckResult to CustomJobResult and HealthCheckResultLevel to CustomJobResultLevel
* created a new rest endpoint for package upload with the role of instantiating a job with the given reference and time stamp
* added a new endpoint to ServerInfo interface for retrieving the XWiki installation path
* implemented the logic of package archive upload which includes: original file search and backup creation, batch file save (file replacement), batch backup restore in case of an error
* created the ImportPackage page for user interface
* created the hidden PackagesStore for archive storage
* created liveData table for saving a package and starting the upload process
* created liveData table (with PackagesJSON document) for showing the already uploaded packages
* created a template for executing and showing the progress of a package upload
* code refactoring
* added transalations
  • Loading branch information
ChiuchiuSorin committed Oct 10, 2024
1 parent 0ad01fd commit ed7f637
Show file tree
Hide file tree
Showing 44 changed files with 1,979 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public interface ServerInfo
{
/**
* Verify if the path to a specific server is found. If a server path is provided in the XWiki configurations, it
* verifies if the path corresponds to a server. Otherwise, it searches the server location in system properties
* and system environment.
* verifies if the path corresponds to a server. Otherwise, it searches the server location in system properties and
* system environment.
*
* @return {@code true} if the server is used, {@code false} otherwise.
*/
Expand All @@ -62,6 +62,13 @@ public interface ServerInfo
*/
String getXwikiCfgFolderPath();

/**
* Access the path to the XWiki installation folder.
*
* @return the path to the XWiki installation folder.
*/
String getXWikiInstallFolderPath();

/**
* Update the possible paths to the configuration files.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.xwiki.component.annotation.Role;
import org.xwiki.stability.Unstable;

import com.xwiki.admintools.jobs.CustomJobResult;

/**
* Check for issues in the current wiki.
*
Expand All @@ -35,7 +37,7 @@ public interface HealthCheck
/**
* Execute the health check on the wiki instance.
*
* @return a {@link HealthCheckResult} with the relevant info regarding the checked issue.
* @return a {@link CustomJobResult} with the relevant info regarding the checked issue.
*/
HealthCheckResult check();
CustomJobResult check();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
* 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.health;
package com.xwiki.admintools.jobs;

import java.util.List;

import org.xwiki.stability.Unstable;

/**
* Result of a health check. Stores a custom message for the summary of the result, the severity level represented by
* {@link HealthCheckResultLevel}. The result may also contain a {@link List} of additional parameters used if there
* is need to store more information about the result.
* Result of a job. Stores a custom message for the summary of the result, the severity level represented by
* {@link CustomJobResultLevel}. The result may also contain a {@link List} of additional parameters used if there is
* need to store more information about the result.
*
* @version $Id$
* @since 1.0
*/
@Unstable
public class HealthCheckResult
public class CustomJobResult
{
private String message;

private HealthCheckResultLevel level;
private CustomJobResultLevel level;

private List<?> parameters;

Expand All @@ -47,7 +47,7 @@ public class HealthCheckResult
* @param level severity level of a result.
* @param parameters current value of the checked resource.
*/
public HealthCheckResult(String message, HealthCheckResultLevel level, Object... parameters)
public CustomJobResult(String message, CustomJobResultLevel level, Object... parameters)
{
this.message = message;
this.level = level;
Expand Down Expand Up @@ -79,7 +79,7 @@ public List<?> getParameters()
*
* @return the severity level of an error.
*/
public HealthCheckResultLevel getLevel()
public CustomJobResultLevel getLevel()
{
return level;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@
* 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.health;
package com.xwiki.admintools.jobs;

import org.xwiki.stability.Unstable;

/**
* Represents the severity type of {@link HealthCheckResult}, where "INFO" is for informative results, "WARN" for
* Represents the severity level of a job, where "INFO" is for informative results, "WARN" for
* warnings and "ERROR" for critical issues.
*
* @version $Id$
* @since 1.0
*/
@Unstable
public enum HealthCheckResultLevel
public enum CustomJobResultLevel
{
/**
* Used to mark a {@link HealthCheckResult} as an error.
* Used to mark a {@link CustomJobResultLevel} as an error.
*/
ERROR,

/**
* Used to mark a {@link HealthCheckResult} as a warning.
* Used to mark a {@link CustomJobResultLevel} as a warning.
*/
WARN,

/**
* Used to mark a {@link HealthCheckResult} as informative.
* Used to mark a {@link CustomJobResultLevel} as informative.
*/
INFO
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
import org.xwiki.observation.ObservationManager;
import org.xwiki.stability.Unstable;

import com.xwiki.admintools.health.HealthCheckResult;
import com.xwiki.admintools.health.HealthCheckResultLevel;

/**
* The status of the health check job.
*
Expand All @@ -40,7 +37,7 @@
@Unstable
public class HealthCheckJobStatus extends DefaultJobStatus<HealthCheckJobRequest>
{
private final List<HealthCheckResult> healthCheckResults = new LinkedList<>();
private final List<CustomJobResult> customJobResults = new LinkedList<>();

/**
* Create a new health check job status.
Expand All @@ -60,11 +57,11 @@ public HealthCheckJobStatus(String jobType, HealthCheckJobRequest request, Obser
/**
* Get the list issues list from the job.
*
* @return list with {@link HealthCheckResult} containing errors.
* @return list with {@link CustomJobResult} containing errors.
*/
public List<HealthCheckResult> getHealthCheckResults()
public List<CustomJobResult> getJobResults()
{
return healthCheckResults;
return customJobResults;
}

/**
Expand All @@ -73,8 +70,8 @@ public List<HealthCheckResult> getHealthCheckResults()
* @param level represents the searched level of severity.
* @return {@code true} if there is any match for the given level, or {@code false} otherwise.
*/
public boolean hasLevel(HealthCheckResultLevel level)
public boolean hasLevel(CustomJobResultLevel level)
{
return this.healthCheckResults.stream().anyMatch(checkResult -> Objects.equals(level, checkResult.getLevel()));
return this.customJobResults.stream().anyMatch(checkResult -> Objects.equals(level, checkResult.getLevel()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.jobs;

import java.util.List;

import org.xwiki.job.AbstractRequest;
import org.xwiki.stability.Unstable;

/**
* Represents a request to start a package upload job.
*
* @version $Id$
* @since 1.1
*/
@Unstable
public class PackageUploadJobRequest extends AbstractRequest
{
private String fileRef;

/**
* Default constructor.
*/
public PackageUploadJobRequest()
{
setDefaultId();
}

/**
* Creates a specific request for package upload job.
*
* @param fileRef the attachment reference.
* @param jobId the ID of the request.
*/
public PackageUploadJobRequest(String fileRef, List<String> jobId)
{
this.fileRef = fileRef;
setId(jobId);
}

/**
* Get the attachment reference.
*
* @return a {@link String} representing the attachment reference.
*/
public String getFileRef()
{
return this.fileRef;
}

private void setDefaultId()
{
setId(List.of("adminTools", "import"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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.jobs;

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

import org.xwiki.job.DefaultJobStatus;
import org.xwiki.logging.LoggerManager;
import org.xwiki.observation.ObservationManager;
import org.xwiki.stability.Unstable;

/**
* The status of a package upload job.
*
* @version $Id$
* @since 1.1
*/
@Unstable
public class PackageUploadJobStatus extends DefaultJobStatus<PackageUploadJobRequest>
{
private List<CustomJobResult> uploadLogs = new LinkedList<>();

/**
* Create a new import job status.
*
* @param jobType the job type.
* @param request the request provided when the job was started.
* @param observationManager the observation manager.
* @param loggerManager the logger manager.
*/
public PackageUploadJobStatus(String jobType, PackageUploadJobRequest request,
ObservationManager observationManager, LoggerManager loggerManager)
{
super(jobType, request, null, observationManager, loggerManager);
setCancelable(true);
}

/**
* Get the list result list from the job.
*
* @return list with {@link CustomJobResult} containing the results.
*/
public List<CustomJobResult> getJobResults()
{
return uploadLogs;
}

/**
* Add a new log to the job results.
*
* @param statusLog the new log result.
*/
public void addLog(CustomJobResult statusLog)
{
uploadLogs.add(statusLog);
}

/**
* Check if any job result has a specific level of severity.
*
* @param level represents the searched level of severity.
* @return {@code true} if there is any match for the given level, or {@code false} otherwise.
*/
public boolean hasLevel(CustomJobResultLevel level)
{
return this.uploadLogs.stream().anyMatch(checkResult -> Objects.equals(level, checkResult.getLevel()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

import org.xwiki.rest.XWikiRestComponent;
import org.xwiki.rest.XWikiRestException;
import org.xwiki.stability.Unstable;

/**
* Provides the APIs needed by the Admin Tools server in order to download and view configuration files and logs.
Expand Down Expand Up @@ -66,4 +68,19 @@ public interface AdminToolsResource extends XWikiRestComponent
@POST
@Path("/flushCache")
Response flushCache() throws XWikiRestException;

/**
* Start a package upload job based on the attachment reference that was sent.
*
* @param attachReference the reference of the attachment.
* @param startTime the start time of the request.
* @return HTML status code 202 to hint that the upload job has started.
* @throws XWikiRestException if an error occurred while creating the job.
* @since 1.1
*/
@POST
@Path("/import")
@Unstable
Response uploadPackageArchive(@QueryParam("attach") String attachReference,
@QueryParam("startTime") String startTime) throws XWikiRestException;
}
Loading

0 comments on commit ed7f637

Please sign in to comment.