use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class XarExtensionScriptService method diff.
/**
* Computes the differences, in unified format, between the documents of an installed XAR extension and the document
* from the wiki.
*
* @param feature the identifier of a XAR extension (or one of its features)
* @param wiki the wiki where the XAR extension is installed
* @return the {@link Job} object which can be used to monitor the progress while the differences are being
* computed, or {@code null} in case of failure
* @since 7.0RC1
*/
public Job diff(String feature, String wiki) {
setError(null);
String namespace = getWikiNamespace(wiki);
InstallRequest installRequest = new InstallRequest();
installRequest.addExtension(new ExtensionId(feature, (Version) null));
if (namespace != null) {
installRequest.addNamespace(namespace);
}
installRequest.setId(getDiffJobId(feature, namespace));
try {
return this.jobExecutor.execute(DiffXarJob.JOB_TYPE, installRequest);
} catch (Exception e) {
setError(e);
return null;
}
}
use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class XarExtensionScriptService method repairInstalledExtension.
/**
* Make sure the provided XAR extension properly is registered in the installed extensions index.
* <p>
* Start an asynchronous Job.
*
* @param id the extension identifier
* @param version the extension version
* @param wiki the wiki where the extension is installed
* @return the {@link Job} object which can be used to monitor the progress of the installation process, or
* {@code null} in case of failure
*/
public Job repairInstalledExtension(String id, String version, String wiki) {
setError(null);
if (!this.authorization.hasAccess(Right.PROGRAM)) {
setError(new JobException("Need programming right to repair a XAR"));
return null;
}
String namespace = getWikiNamespace(wiki);
InstallRequest installRequest = new InstallRequest();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, id, namespace));
DocumentReference currentUserReference = this.documentAccessBridge.getCurrentUserReference();
if (currentUserReference != null) {
installRequest.setProperty(PROPERTY_USER_REFERENCE, currentUserReference);
// We set the string value because the extension repository doesn't know how to serialize/parse an extension
// property whose value is a DocumentReference, and adding support for it requires considerable refactoring
// because ExtensionPropertySerializers are not components (they are currently hard-coded).
installRequest.setExtensionProperty(PROPERTY_USER_REFERENCE, currentUserReference.toString());
}
installRequest.addExtension(new ExtensionId(id, version));
if (StringUtils.isNotBlank(namespace)) {
installRequest.addNamespace(namespace);
}
Job job = null;
try {
job = this.jobExecutor.execute(RepairXarJob.JOBTYPE, installRequest);
} catch (Exception e) {
setError(e);
}
return job;
}
use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class OutdatedExtensionsDistributionStep method createRepairPlan.
private ExtensionPlan createRepairPlan(ExtensionId invalidExtension, String namespace) throws JobException, InterruptedException {
// Install the default UI
InstallRequest installRequest = new InstallRequest();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, invalidExtension.getId(), namespace));
installRequest.addExtension(invalidExtension);
installRequest.addNamespace(namespace);
// Don't take any risk
installRequest.setUninstallAllowed(false);
// Indicate if it's allowed to do modification on root namespace
installRequest.setRootModificationsAllowed(true);
installRequest.setInteractive(false);
// Set user to use as author (for example) to be superadmin
installRequest.setExtensionProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, XWikiRightService.SUPERADMIN_USER_FULLNAME);
Job job = this.jobExecutor.execute(UpgradePlanJob.JOBTYPE, installRequest);
job.join();
return (ExtensionPlan) job.getStatus();
}
use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class InstalledExtensionIndexTest method testInstallExtensionOnRoot.
@Test
public void testInstallExtensionOnRoot() throws Exception {
// Use superadmin
getUtil().setDefaultCredentials(TestUtils.SUPER_ADMIN_CREDENTIALS);
ExtensionId extensionId = new ExtensionId("maven:jar", "1.0");
// ///////////////////////////////////////////
// Make sure it's not yet installed on node 0 and node 1
getUtil().switchExecutor(0);
assertTrue("The extension is already installed on node0", !getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT));
getUtil().switchExecutor(1);
assertTrue("The extension is already installed on node1", !getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT));
// ///////////////////////////////////////////
// Install extension on node 0
getUtil().switchExecutor(0);
InstallRequest installRequest = new InstallRequest();
installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, extensionId.getId(), null));
installRequest.setInteractive(false);
installRequest.addExtension(extensionId);
executeJob("install", installRequest);
// ///////////////////////////////////////////
// Make sure it has been installed on node 0
assertTrue("The extension was not installed on node0", getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT));
// ///////////////////////////////////////////
// Make sure it has been installed on node 1
getUtil().switchExecutor(1);
long t1 = System.currentTimeMillis();
while (!getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT)) {
if (System.currentTimeMillis() - t1 > 10000L) {
fail("The extension was not installed on node1");
}
Thread.sleep(100);
}
// ///////////////////////////////////////////
// Uninstall extension from node 1
getUtil().switchExecutor(1);
UninstallRequest uninstallRequest = new UninstallRequest();
uninstallRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_PLAN_PREFIX, extensionId.getId(), null));
uninstallRequest.setInteractive(false);
uninstallRequest.addExtension(extensionId);
executeJob("uninstall", uninstallRequest);
// ///////////////////////////////////////////
// Make sure it has been uninstalled from node 1
assertTrue("The extension is still installed on node1", !getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT));
// ///////////////////////////////////////////
// Make sure it has been uninstalled from node 0
getUtil().switchExecutor(1);
t1 = System.currentTimeMillis();
while (getExtensionTestUtils().isInstalled(extensionId, Namespace.ROOT)) {
if (System.currentTimeMillis() - t1 > 10000L) {
fail("The extension is still installed on node0");
}
Thread.sleep(100);
}
}
use of org.xwiki.extension.job.InstallRequest in project xwiki-platform by xwiki.
the class InstallMojo method installExtensions.
private void installExtensions(Marshaller marshaller, Unmarshaller unmarshaller, HttpClient httpClient) throws Exception {
InstallRequest installRequest = new InstallRequest();
// Set a job id to save the job result
installRequest.setId("extension", "provision", UUID.randomUUID().toString());
installRequest.setInteractive(false);
// Set the extension list to install
for (ExtensionId extensionId : this.extensionIds) {
org.xwiki.extension.ExtensionId extId = new org.xwiki.extension.ExtensionId(extensionId.getId(), extensionId.getVersion());
getLog().info(String.format("Installing extension [%s]...", extId));
installRequest.addExtension(extId);
}
// Set the namespaces into which to install the extensions
if (this.namespaces == null || this.namespaces.isEmpty()) {
installRequest.addNamespace("wiki:xwiki");
} else {
for (String namespace : this.namespaces) {
installRequest.addNamespace(namespace);
}
}
// Set any user for installing pages (if defined)
if (this.installUserReference != null) {
installRequest.setProperty("user.reference", new DocumentReference("xwiki", "XWiki", "superadmin"));
}
JobRequest request = getModelFactory().toRestJobRequest(installRequest);
String uri = String.format("%s/jobs?jobType=install&async=false", this.xwikiRESTURL);
PutMethod putMethod = executePutXml(uri, request, marshaller, httpClient);
// Verify results
// Verify that we got a 200 response
int statusCode = putMethod.getStatusCode();
if (statusCode < 200 || statusCode >= 300) {
throw new MojoExecutionException(String.format("Job execution failed. Response status code [%s], reason [%s]", statusCode, putMethod.getResponseBodyAsString()));
}
// Get the job status
JobStatus jobStatus = (JobStatus) unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
if (jobStatus.getErrorMessage() != null && jobStatus.getErrorMessage().length() > 0) {
throw new MojoExecutionException(String.format("Job execution failed. Reason [%s]", jobStatus.getErrorMessage()));
}
// Release connection
putMethod.releaseConnection();
}
Aggregations