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();
}
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;
}
Aggregations