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