use of org.opengrok.web.api.ApiTask in project OpenGrok by OpenGrok.
the class ProjectsController method deleteProject.
@DELETE
@Path("/{project}")
public Response deleteProject(@Context HttpServletRequest request, @PathParam("project") String projectNameParam) {
// Avoid classification as a taint bug.
final String projectName = Laundromat.launderInput(projectNameParam);
Project project = disableProject(projectName);
LOGGER.log(Level.INFO, "deleting configuration for project {0}", projectName);
return ApiTaskManager.getInstance().submitApiTask(PROJECTS_PATH, new ApiTask(request.getRequestURI(), () -> {
deleteProjectWorkHorse(projectName, project);
return null;
}, Response.Status.NO_CONTENT));
}
use of org.opengrok.web.api.ApiTask in project OpenGrok by OpenGrok.
the class ProjectsController method deleteProjectData.
@DELETE
@Path("/{project}/data")
public Response deleteProjectData(@Context HttpServletRequest request, @PathParam("project") String projectNameParam) {
// Avoid classification as a taint bug.
final String projectName = Laundromat.launderInput(projectNameParam);
disableProject(projectName);
return ApiTaskManager.getInstance().submitApiTask(PROJECTS_PATH, new ApiTask(request.getRequestURI(), () -> {
deleteProjectDataWorkHorse(projectName, false);
return null;
}, Response.Status.NO_CONTENT));
}
use of org.opengrok.web.api.ApiTask in project OpenGrok by OpenGrok.
the class ApiUtils method waitForTask.
/**
* Busy-waits the status of asynchronous API call, mimicking
* {@link org.opengrok.indexer.web.ApiUtils#waitForAsyncApi(Response)},
* however side-steps status API check by going to the {@link ApiTaskManager} directly in order to avoid
* going through the {@link StatusController} as it might not be deployed in the unit tests.
* The method will return right away if the status of the response object parameter is not
* {@code Response.Status.ACCEPTED}.
* @param response API Response object
* @return the response object
*/
protected static Response waitForTask(Response response) {
if (response.getStatus() != Response.Status.ACCEPTED.getStatusCode()) {
return response;
}
String location = response.getHeaderString(HttpHeaders.LOCATION);
String locationUri = URI.create(location).getPath();
final String apiPrefix = "api/v1/status/";
assertTrue(locationUri.contains(apiPrefix));
int idx = locationUri.indexOf(apiPrefix);
assertTrue(idx > 0);
String uuid = locationUri.substring(idx + apiPrefix.length());
ApiTask apiTask = ApiTaskManager.getInstance().getApiTask(uuid);
assertNotNull(apiTask);
await().atMost(16, TimeUnit.SECONDS).until(apiTask::isDone);
if (!apiTask.isDone()) {
return response;
} else {
return apiTask.getResponse();
}
}
use of org.opengrok.web.api.ApiTask in project OpenGrok by OpenGrok.
the class StatusControllerTest method testGet.
@Test
void testGet() throws InterruptedException {
int sleepTime = 3000;
ApiTask apiTask = new ApiTask("foo", () -> {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}, Response.Status.CREATED);
String uuidString = apiTask.getUuid().toString();
ApiTaskManager apiTaskManager = ApiTaskManager.getInstance();
String poolName = "foo";
apiTaskManager.addPool(poolName, 1);
apiTaskManager.submitApiTask(poolName, apiTask);
Response response = target(StatusController.PATH).path(uuidString).request().get();
assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
Thread.sleep(sleepTime);
response = target(StatusController.PATH).path(uuidString).request().get();
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
}
use of org.opengrok.web.api.ApiTask in project OpenGrok by OpenGrok.
the class StatusControllerTest method testDelete.
@Test
void testDelete() throws InterruptedException {
ApiTask apiTask = new ApiTask("foo", this::doNothing);
String uuidString = apiTask.getUuid().toString();
ApiTaskManager apiTaskManager = ApiTaskManager.getInstance();
String poolName = "deleteCompleted";
apiTaskManager.addPool(poolName, 1);
apiTaskManager.submitApiTask(poolName, apiTask);
Thread.sleep(1000);
Response response = target(StatusController.PATH).path(uuidString).request().delete();
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
Aggregations