Search in sources :

Example 1 with JobRequest

use of org.xwiki.rest.model.jaxb.JobRequest in project xwiki-platform by xwiki.

the class InstalledExtensionIndexTest method executeJob.

private void executeJob(String jobType, Request jobRequest) throws Exception {
    JobRequest request = AbstractTest.componentManager.<ModelFactory>getInstance(ModelFactory.class).toRestJobRequest(jobRequest);
    Map<String, Object[]> queryParameters = new HashMap<>();
    queryParameters.put("jobType", new Object[] { jobType });
    queryParameters.put("async", new Object[] { false });
    TestUtils.assertStatusCodes(getUtil().rest().executePut(JobsResource.class, request, queryParameters), true, TestUtils.STATUS_OK);
}
Also used : JobsResource(org.xwiki.rest.resources.job.JobsResource) JobRequest(org.xwiki.rest.model.jaxb.JobRequest) HashMap(java.util.HashMap) ModelFactory(org.xwiki.rest.internal.ModelFactory)

Example 2 with JobRequest

use of org.xwiki.rest.model.jaxb.JobRequest 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)

Example 3 with JobRequest

use of org.xwiki.rest.model.jaxb.JobRequest in project xwiki-platform by xwiki.

the class ModelFactory method toRestJobRequest.

public JobRequest toRestJobRequest(Request request) throws XWikiRestException {
    JobRequest restJobRequest = this.objectFactory.createJobRequest();
    restJobRequest.setId(toRestJobId(request.getId()));
    restJobRequest.setInteractive(request.isInteractive());
    restJobRequest.setRemote(request.isRemote());
    restJobRequest.setVerbose(request.isVerbose());
    restJobRequest.setStatusSerialized(request.isStatusSerialized());
    restJobRequest.setStatusLogIsolated(request.isStatusLogIsolated());
    for (String key : request.getPropertyNames()) {
        restJobRequest.getProperties().add(toRestMapEntry(key, request.getProperty(key)));
    }
    return restJobRequest;
}
Also used : JobRequest(org.xwiki.rest.model.jaxb.JobRequest)

Aggregations

JobRequest (org.xwiki.rest.model.jaxb.JobRequest)3 HashMap (java.util.HashMap)1 PutMethod (org.apache.commons.httpclient.methods.PutMethod)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 InstallRequest (org.xwiki.extension.job.InstallRequest)1 ExtensionId (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionId)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 ModelFactory (org.xwiki.rest.internal.ModelFactory)1 JobStatus (org.xwiki.rest.model.jaxb.JobStatus)1 JobsResource (org.xwiki.rest.resources.job.JobsResource)1