Skip to content
Draft
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-refactor-list-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Refactor Tasks API to use Nested Interfaces
type: updated
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,52 @@
/*
* 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")
public interface TasksApi {

@Path("")
interface List {
@GET
@StoreApiParameters
@Operation(
summary = "Lists all the active tasks.",
tags = {"tasks"})
ListActiveTaskResponse listAllActiveTasks() throws Exception;
}

@Path("{taskID}")
interface Status {
@GET
@StoreApiParameters
@Operation(
summary = "Status of a specific task.",
tags = {"tasks"})
TaskStatusResponse getTaskStatus(@PathParam("taskID") String taskID) 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 taskID, String taskQuery) {
this.taskID = taskID;
this.taskQuery = taskQuery;
}

@JsonProperty public String taskID;
@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,40 @@
/*
* 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 {

public enum TaskStatus {
ACTIVE("active"),
INACTIVE("inactive");

private final String value;

TaskStatus(String value) {
this.value = value;
}

public String getValue() {
return this.value;
}
}

@JsonProperty public TaskStatus taskStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@
* specify the acceptable generation lag follower should be with respect to its leader using the
* <code>maxGenerationLag=&lt;max_generation_lag&gt;</code> request parameter. If <code>
* maxGenerationLag</code> is not provided then health check would simply return OK.
*
* <p>All health-check logic lives in the v2 {@link NodeHealth}; this handler is a thin v1 bridge
* that extracts request parameters and delegates.
*/
public class HealthCheckHandler extends RequestHandlerBase {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.client.api.model.TaskStatusResponse.TaskStatus;
import static org.apache.solr.security.PermissionNameProvider.Name.READ_PERM;

import jakarta.inject.Inject;
import org.apache.solr.api.JerseyResource;
import org.apache.solr.client.api.endpoint.TasksApi;
import org.apache.solr.client.api.model.TaskStatusResponse;
import org.apache.solr.jersey.PermissionName;
import org.apache.solr.request.SolrQueryRequest;

public class GetTaskStatus extends JerseyResource implements TasksApi.Status {

private final SolrQueryRequest solrQueryRequest;

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

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

boolean isTaskActive =
solrQueryRequest.getCore().getCancellableQueryTracker().isQueryIdActive(taskID);

response.taskStatus = (isTaskActive) ? TaskStatus.ACTIVE : TaskStatus.INACTIVE;

return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.TasksApi;
import org.apache.solr.client.api.model.ActiveTaskDetails;
import org.apache.solr.client.api.model.ListActiveTaskResponse;
import org.apache.solr.jersey.PermissionName;
import org.apache.solr.request.SolrQueryRequest;

public class ListActiveTasks extends JerseyResource implements TasksApi.List {

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;
}

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.

Loading
Loading