Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hubspot.singularity;

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

public class SingularityScheduledTasksInfo {
Expand All @@ -9,12 +11,13 @@ public class SingularityScheduledTasksInfo {
private final List<SingularityPendingTaskId> lateTasks;
private final List<SingularityPendingTaskId> onDemandLateTasks;

@JsonCreator
public SingularityScheduledTasksInfo(
List<SingularityPendingTaskId> lateTasks,
List<SingularityPendingTaskId> onDemandLateTasks,
int numFutureTasks,
long maxTaskLag,
long timestamp
@JsonProperty("lateTasks") List<SingularityPendingTaskId> lateTasks,
@JsonProperty("onDemandLateTasks") List<SingularityPendingTaskId> onDemandLateTasks,
@JsonProperty("numFutureTasks") int numFutureTasks,
@JsonProperty("maxTaskLag") long maxTaskLag,
@JsonProperty("timestamp") long timestamp
) {
this.lateTasks = lateTasks;
this.onDemandLateTasks = onDemandLateTasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.hubspot.singularity.SingularityRequestWithState;
import com.hubspot.singularity.SingularityS3Log;
import com.hubspot.singularity.SingularitySandbox;
import com.hubspot.singularity.SingularityScheduledTasksInfo;
import com.hubspot.singularity.SingularityShellCommand;
import com.hubspot.singularity.SingularitySlave;
import com.hubspot.singularity.SingularityState;
Expand Down Expand Up @@ -118,6 +119,7 @@ public class SingularityClient {
AUTH_FORMAT + "/groups/auth-check";

private static final String STATE_FORMAT = "%s/state";
private static final String SCHEDULED_TASKS_INFO_FORMAT = "%s/scheduled-tasks-info";
private static final String TASK_RECONCILIATION_FORMAT =
STATE_FORMAT + "/task-reconciliation";

Expand Down Expand Up @@ -829,6 +831,28 @@ private HttpResponse executeRequest(
// GLOBAL
//

public SingularityScheduledTasksInfo getScheduledTasksInfo() {
final Function<String, String> uri = host ->
String.format(SCHEDULED_TASKS_INFO_FORMAT, getApiBase(host));

LOG.info("Fetching scheduled tasks info from {}", uri);

final long start = System.currentTimeMillis();

HttpResponse response = executeRequest(
uri,
Method.GET,
Optional.empty(),
Collections.emptyMap()
);

checkResponse("singularity scheduled tasks info", response);

LOG.info("Got scheduled tasks info in {}ms", System.currentTimeMillis() - start);

return response.getAs(SingularityScheduledTasksInfo.class);
}

public SingularityState getState(
Optional<Boolean> skipCache,
Optional<Boolean> includeRequestIds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public SingularityState generateState(boolean includeRequestIds) {
);
}

private SingularityScheduledTasksInfo getScheduledTasksInfo() {
public SingularityScheduledTasksInfo getScheduledTasksInfo() {
long now = System.currentTimeMillis();
List<SingularityPendingTaskId> allPendingTaskIds = taskManager.getPendingTaskIds();
List<SingularityPendingTaskId> lateTasks = allPendingTaskIds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hubspot.singularity.resources;

import com.google.inject.Inject;
import com.hubspot.singularity.SingularityScheduledTasksInfo;
import com.hubspot.singularity.SingularityState;
import com.hubspot.singularity.SingularityTaskReconciliationStatistics;
import com.hubspot.singularity.config.ApiPaths;
Expand All @@ -12,12 +13,14 @@
import io.swagger.v3.oas.annotations.tags.Tags;
import java.util.List;
import java.util.Optional;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

@Consumes(MediaType.APPLICATION_JSON)
@Path(ApiPaths.STATE_RESOURCE_PATH)
@Produces({ MediaType.APPLICATION_JSON })
@Schema(title = "Provides information about the current state of Singularity")
Expand All @@ -30,6 +33,13 @@ public StateResource(StateManager stateManager) {
this.stateManager = stateManager;
}

@GET
@Path("/scheduled-tasks-info")
@Operation(summary = "Retrieve the scheduled tasks info.")
public SingularityScheduledTasksInfo getScheduledTasksInfo() {
return stateManager.getScheduledTasksInfo();
}

@GET
@Operation(summary = "Retrieve information about the current state of Singularity.")
public SingularityState getState(
Expand Down