Search in sources :

Example 1 with JobStatus

use of org.xwiki.rest.model.jaxb.JobStatus 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 2 with JobStatus

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

the class ModelFactory method toRestJobStatus.

public JobStatus toRestJobStatus(org.xwiki.job.event.status.JobStatus jobStatus, URI self, boolean request, boolean progress, boolean log, String logFromLevel) throws XWikiRestException {
    JobStatus status = this.objectFactory.createJobStatus();
    status.setId(StringUtils.join(jobStatus.getRequest().getId(), "/"));
    status.setState(jobStatus.getState().name());
    if (jobStatus.getStartDate() != null) {
        Calendar calendarStartDate = Calendar.getInstance();
        calendarStartDate.setTime(jobStatus.getStartDate());
        status.setStartDate(calendarStartDate);
    }
    if (jobStatus.getEndDate() != null) {
        Calendar calendarEndDate = Calendar.getInstance();
        calendarEndDate.setTime(jobStatus.getEndDate());
        status.setEndDate(calendarEndDate);
    }
    if (jobStatus.getError() != null) {
        status.setErrorMessage(ExceptionUtils.getStackTrace(jobStatus.getError()));
    }
    // Request
    if (request) {
        status.setRequest(toRestJobRequest(jobStatus.getRequest()));
    }
    // Progress
    if (progress) {
        status.setProgress(toRestJobProgress(jobStatus.getProgress()));
    }
    // Log
    if (log) {
        status.setLog(toRestJobLog(jobStatus.getLog(), self, null, logFromLevel));
    }
    // Link
    if (self != null) {
        Link link = objectFactory.createLink();
        link.setHref(self.toString());
        link.setRel(Relations.SELF);
        status.getLinks().add(link);
    }
    // Log isolation
    status.setIsolated(jobStatus.isIsolated());
    // Status serialization
    status.setSerialized(jobStatus.isSerialized());
    return status;
}
Also used : JobStatus(org.xwiki.rest.model.jaxb.JobStatus) Calendar(java.util.Calendar) Link(org.xwiki.rest.model.jaxb.Link)

Aggregations

JobStatus (org.xwiki.rest.model.jaxb.JobStatus)2 Calendar (java.util.Calendar)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 JobRequest (org.xwiki.rest.model.jaxb.JobRequest)1 Link (org.xwiki.rest.model.jaxb.Link)1