Search in sources :

Example 6 with ApiTask

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();
}
Also used : ApiTask(org.opengrok.web.api.ApiTask) Path(jakarta.ws.rs.Path) DELETE(jakarta.ws.rs.DELETE)

Example 7 with ApiTask

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;
    }));
}
Also used : Project(org.opengrok.indexer.configuration.Project) Repository(org.opengrok.indexer.history.Repository) RepositoryFactory.getRepository(org.opengrok.indexer.history.RepositoryFactory.getRepository) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) NotFoundException(jakarta.ws.rs.NotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) ApiTask(org.opengrok.web.api.ApiTask) Path(jakarta.ws.rs.Path) Consumes(jakarta.ws.rs.Consumes) PUT(jakarta.ws.rs.PUT)

Example 8 with ApiTask

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));
}
Also used : ApiTask(org.opengrok.web.api.ApiTask) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes)

Example 9 with ApiTask

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());
}
Also used : Response(jakarta.ws.rs.core.Response) ApiTaskManager(org.opengrok.web.api.ApiTaskManager) ApiTask(org.opengrok.web.api.ApiTask) Test(org.junit.jupiter.api.Test)

Aggregations

ApiTask (org.opengrok.web.api.ApiTask)9 Path (jakarta.ws.rs.Path)4 DELETE (jakarta.ws.rs.DELETE)3 Response (jakarta.ws.rs.core.Response)3 Test (org.junit.jupiter.api.Test)3 ApiTaskManager (org.opengrok.web.api.ApiTaskManager)3 Consumes (jakarta.ws.rs.Consumes)2 Project (org.opengrok.indexer.configuration.Project)2 NotFoundException (jakarta.ws.rs.NotFoundException)1 POST (jakarta.ws.rs.POST)1 PUT (jakarta.ws.rs.PUT)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Repository (org.opengrok.indexer.history.Repository)1 RepositoryFactory.getRepository (org.opengrok.indexer.history.RepositoryFactory.getRepository)1 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)1