Search in sources :

Example 16 with InstallRequest

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;
    }
}
Also used : Version(org.xwiki.extension.version.Version) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionId(org.xwiki.extension.ExtensionId) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) XarException(org.xwiki.xar.XarException)

Example 17 with InstallRequest

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;
}
Also used : JobException(org.xwiki.job.JobException) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionId(org.xwiki.extension.ExtensionId) DiffXarJob(org.xwiki.extension.xar.internal.job.DiffXarJob) Job(org.xwiki.job.Job) RepairXarJob(org.xwiki.extension.xar.internal.job.RepairXarJob) DocumentReference(org.xwiki.model.reference.DocumentReference) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) XarException(org.xwiki.xar.XarException)

Example 18 with InstallRequest

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();
}
Also used : ExtensionPlan(org.xwiki.extension.job.plan.ExtensionPlan) InstallRequest(org.xwiki.extension.job.InstallRequest) Job(org.xwiki.job.Job) UpgradePlanJob(org.xwiki.extension.job.internal.UpgradePlanJob)

Example 19 with InstallRequest

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);
    }
}
Also used : InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionId(org.xwiki.extension.ExtensionId) UninstallRequest(org.xwiki.extension.job.UninstallRequest) Test(org.junit.Test) AbstractTest(org.xwiki.test.ui.AbstractTest) AbstractClusterHttpTest(org.xwiki.test.cluster.framework.AbstractClusterHttpTest)

Example 20 with InstallRequest

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();
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionId(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionId) JobStatus(org.xwiki.rest.model.jaxb.JobStatus) JobRequest(org.xwiki.rest.model.jaxb.JobRequest) PutMethod(org.apache.commons.httpclient.methods.PutMethod) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

InstallRequest (org.xwiki.extension.job.InstallRequest)21 DocumentReference (org.xwiki.model.reference.DocumentReference)8 Test (org.junit.Test)7 Job (org.xwiki.job.Job)7 ExtensionId (org.xwiki.extension.ExtensionId)6 ExtensionJobHistoryRecord (org.xwiki.extension.job.history.ExtensionJobHistoryRecord)4 ReplayRequest (org.xwiki.extension.job.history.ReplayRequest)3 ReplayJob (org.xwiki.extension.job.history.internal.ReplayJob)3 InstallJob (org.xwiki.extension.job.internal.InstallJob)3 WikiReference (org.xwiki.model.reference.WikiReference)3 IOException (java.io.IOException)2 InstallException (org.xwiki.extension.InstallException)2 InstalledExtension (org.xwiki.extension.InstalledExtension)2 UninstallRequest (org.xwiki.extension.job.UninstallRequest)2 ScriptExtensionRewriter (org.xwiki.extension.script.ScriptExtensionRewriter)2 JobException (org.xwiki.job.JobException)2 LogEvent (org.xwiki.logging.event.LogEvent)2 XarException (org.xwiki.xar.XarException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 Predicate (org.apache.commons.collections4.Predicate)1