Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/SOLR-18248-list-tasks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Migrated ListTasks API & TaskStatus API from homegrown @EndPoint to JAX-RS
type: added
authors:
- name: Jalaz Kumar
links:
- name: SOLR-18248
url: https://issues.apache.org/jira/browse/SOLR-18248
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.solr.client.api.endpoint;

import static org.apache.solr.client.api.util.Constants.INDEX_PATH_PREFIX;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import org.apache.solr.client.api.model.ListActiveTaskResponse;
import org.apache.solr.client.api.model.TaskStatusResponse;
import org.apache.solr.client.api.util.StoreApiParameters;

@Path(INDEX_PATH_PREFIX + "/tasks/list")
public interface ListActiveTasksApi {

// Handles: .../tasks/list (Lists all)
@GET
@StoreApiParameters
@Operation(
summary = "Lists all the currently running tasks",
tags = {"tasks"})
ListActiveTaskResponse listAllActiveTasks() throws Exception;

// Handles: .../tasks/list/slow-task-id (Lists specific)
@GET
@Path("/{taskUUID}")
@StoreApiParameters
@Operation(
summary = "Status of a specific taskUUID passed as pathParam",
tags = {"tasks"})
TaskStatusResponse getTaskStatus(@PathParam("taskUUID") String taskUUID) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.solr.client.api.model;

import com.fasterxml.jackson.annotation.JsonProperty;

public class ActiveTaskDetails {

public ActiveTaskDetails() {}

public ActiveTaskDetails(String taskUUID, String taskQuery) {
this.taskUUID = taskUUID;
this.taskQuery = taskQuery;
}

@JsonProperty public String taskUUID;
@JsonProperty public String taskQuery;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.solr.client.api.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;

public class ListActiveTaskResponse extends SolrJerseyResponse {
@JsonProperty public List<ActiveTaskDetails> taskList;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.solr.client.api.model;

import com.fasterxml.jackson.annotation.JsonProperty;

public class TaskStatusResponse extends SolrJerseyResponse {
@JsonProperty public boolean taskStatus;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.solr.handler.admin.api;

import static org.apache.solr.security.PermissionNameProvider.Name.READ_PERM;

import jakarta.inject.Inject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.solr.api.JerseyResource;
import org.apache.solr.client.api.endpoint.ListActiveTasksApi;
import org.apache.solr.client.api.model.ActiveTaskDetails;
import org.apache.solr.client.api.model.ListActiveTaskResponse;
import org.apache.solr.client.api.model.TaskStatusResponse;
import org.apache.solr.jersey.PermissionName;
import org.apache.solr.request.SolrQueryRequest;

public class ListActiveTasks extends JerseyResource implements ListActiveTasksApi {

private final SolrQueryRequest solrQueryRequest;

@Inject
public ListActiveTasks(SolrQueryRequest solrQueryRequest) {
this.solrQueryRequest = solrQueryRequest;
}

@Override
@PermissionName(READ_PERM)
public ListActiveTaskResponse listAllActiveTasks() throws Exception {
final ListActiveTaskResponse response = instantiateJerseyResponse(ListActiveTaskResponse.class);

response.taskList = extractActiveTaskLists();

return response;
}

@Override
@PermissionName(READ_PERM)
public TaskStatusResponse getTaskStatus(String taskUUID) throws Exception {
final TaskStatusResponse response = instantiateJerseyResponse(TaskStatusResponse.class);

response.taskStatus =
solrQueryRequest.getCore().getCancellableQueryTracker().isQueryIdActive(taskUUID);

return response;
}

private List<ActiveTaskDetails> extractActiveTaskLists() {
Iterator<Map.Entry<String, String>> iterator =
solrQueryRequest.getCore().getCancellableQueryTracker().getActiveQueriesGenerated();

List<ActiveTaskDetails> activeTaskDetails = new ArrayList<>();
while (iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next();
activeTaskDetails.add(new ActiveTaskDetails(entry.getKey(), entry.getValue()));
}

return activeTaskDetails;
}
}

This file was deleted.

This file was deleted.

Loading