use of org.opengrok.web.api.ApiTask in project OpenGrok by OpenGrok.
the class StatusController method delete.
@DELETE
@Path("/{uuid}")
public Response delete(@PathParam("uuid") String uuid) {
ApiTask apiTask = ApiTaskManager.getInstance().getApiTask(uuid);
if (apiTask == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
if (!apiTask.isDone()) {
LOGGER.log(Level.WARNING, "API task {0} not yet done", apiTask);
return Response.status(Response.Status.BAD_REQUEST).build();
}
ApiTaskManager.getInstance().deleteApiTask(uuid);
return Response.ok().build();
}
use of org.opengrok.web.api.ApiTask in project OpenGrok by OpenGrok.
the class ProjectsController method markIndexed.
@PUT
@Path("/{project}/indexed")
@Consumes(MediaType.TEXT_PLAIN)
public Response markIndexed(@Context HttpServletRequest request, @PathParam("project") String projectNameParam) {
// Avoid classification as a taint bug.
final String projectName = Laundromat.launderInput(projectNameParam);
Project project = env.getProjects().get(projectName);
if (project == null) {
LOGGER.log(Level.WARNING, "cannot find project {0} to mark as indexed", projectName);
throw new NotFoundException(String.format("project '%s' does not exist", projectName));
}
project.setIndexed(true);
return ApiTaskManager.getInstance().submitApiTask(PROJECTS_PATH, new ApiTask(request.getRequestURI(), () -> {
// Refresh current version of the project's repositories.
List<RepositoryInfo> riList = env.getProjectRepositoriesMap().get(project);
if (riList != null) {
for (RepositoryInfo ri : riList) {
Repository repo = getRepository(ri, CommandTimeoutType.RESTFUL);
if (repo != null && repo.getCurrentVersion() != null && repo.getCurrentVersion().length() > 0) {
// getRepository() always creates fresh instance
// of the Repository object so there is no need
// to call setCurrentVersion() on it.
ri.setCurrentVersion(repo.determineCurrentVersion());
}
}
}
CompletableFuture.runAsync(() -> suggester.rebuild(projectName));
// In case this project has just been incrementally indexed,
// its IndexSearcher needs a poke.
env.maybeRefreshIndexSearchers(Collections.singleton(projectName));
env.refreshDateForLastIndexRun();
return null;
}));
}
use of org.opengrok.web.api.ApiTask in project OpenGrok by OpenGrok.
the class ProjectsController method addProject.
@POST
@Consumes(MediaType.TEXT_PLAIN)
public Response addProject(@Context HttpServletRequest request, String projectNameParam) {
// Avoid classification as a taint bug.
final String projectName = Laundromat.launderInput(projectNameParam);
LOGGER.log(Level.INFO, "adding project {0}", projectName);
return ApiTaskManager.getInstance().submitApiTask(PROJECTS_PATH, new ApiTask(request.getRequestURI(), () -> {
addProjectWorkHorse(projectName);
return null;
}, Response.Status.CREATED));
}
use of org.opengrok.web.api.ApiTask in project OpenGrok by OpenGrok.
the class StatusControllerTest method testDeleteNotCompleted.
@Test
void testDeleteNotCompleted() {
int sleepTime = 3000;
ApiTask apiTask = new ApiTask("foo", () -> {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
});
String uuidString = apiTask.getUuid().toString();
ApiTaskManager apiTaskManager = ApiTaskManager.getInstance();
String poolName = "deleteNotCompleted";
apiTaskManager.addPool(poolName, 1);
apiTaskManager.submitApiTask(poolName, apiTask);
Response response = target(StatusController.PATH).path(uuidString).request().delete();
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
Aggregations