final int activeTasks = taskManager.getNumActiveTasks();
final int scheduledTasks = taskManager.getNumScheduledTasks();
final int cleaningTasks = taskManager.getNumCleanupTasks();
final int lbCleanupTasks = taskManager.getNumLbCleanupTasks();
final SingularityScheduledTasksInfo scheduledTasksInfo = SingularityScheduledTasksInfo.getInfo(taskManager.getPendingTasks(), singularityConfiguration.getDeltaAfterWhichTasksAreLateMillis());
final List<String> overProvisionedRequestIds = new ArrayList<>();
final List<String> possiblyUnderProvisionedRequestIds = new ArrayList<>();
final List<SingularityRequestWithState> requests = requestManager.getRequests();
final Map<String, Long> numInstances = getNumTasks(requests);
int numActiveRequests = 0;
int numPausedRequests = 0;
int cooldownRequests = 0;
int numFinishedRequests = 0;
for (SingularityRequestWithState requestWithState : requests) {
switch (requestWithState.getState()) {
case DEPLOYING_TO_UNPAUSE:
case ACTIVE:
numActiveRequests++;
break;
case FINISHED:
numFinishedRequests++;
break;
case PAUSED:
numPausedRequests++;
break;
case SYSTEM_COOLDOWN:
cooldownRequests++;
break;
case DELETED:
break;
}
if (requestWithState.getState().isRunnable() && !requestWithState.getRequest().isOneOff()) {
final int instances = requestWithState.getRequest().getInstancesSafe();
final Long numActualInstances = numInstances.get(requestWithState.getRequest().getId());
if (numActualInstances == null || numActualInstances.longValue() < instances) {
possiblyUnderProvisionedRequestIds.add(requestWithState.getRequest().getId());
} else if (numActualInstances.longValue() > instances) {
overProvisionedRequestIds.add(requestWithState.getRequest().getId());
}
}
}
final List<String> underProvisionedRequestIds = new ArrayList<>(possiblyUnderProvisionedRequestIds.size());
if (!possiblyUnderProvisionedRequestIds.isEmpty()) {
Map<String, SingularityRequestDeployState> deployStates = deployManager.getRequestDeployStatesByRequestIds(possiblyUnderProvisionedRequestIds);
for (SingularityRequestDeployState deployState : deployStates.values()) {
if (deployState.getActiveDeploy().isPresent() || deployState.getPendingDeploy().isPresent()) {
underProvisionedRequestIds.add(deployState.getRequestId());
}
}
}
final int pendingRequests = requestManager.getSizeOfPendingQueue();
final int cleaningRequests = requestManager.getSizeOfCleanupQueue();
final int activeRacks = rackManager.getNumActive();
final int deadRacks = rackManager.getNumDead();
final int decomissioningRacks = rackManager.getNumDecomissioning();
final int activeSlaves = slaveManager.getNumActive();
final int deadSlaves = slaveManager.getNumDead();
final int decomissioningSlaves = slaveManager.getNumDecomissioning();
final List<SingularityHostState> states = getHostStates();
int numDeploys = 0;
long oldestDeploy = 0;
final long now = System.currentTimeMillis();
for (SingularityPendingDeploy pendingDeploy : deployManager.getPendingDeploys()) {
long delta = now - pendingDeploy.getDeployMarker().getTimestamp();
if (delta > oldestDeploy) {
oldestDeploy = delta;
}
numDeploys++;
}
return new SingularityState(activeTasks, numActiveRequests, cooldownRequests, numPausedRequests, scheduledTasks, pendingRequests, lbCleanupTasks, cleaningRequests, activeSlaves,
deadSlaves, decomissioningSlaves, activeRacks, deadRacks, decomissioningRacks, cleaningTasks, states, oldestDeploy, numDeploys, scheduledTasksInfo.getNumLateTasks(),
scheduledTasksInfo.getNumFutureTasks(), scheduledTasksInfo.getMaxTaskLag(), System.currentTimeMillis(), includeRequestIds ? overProvisionedRequestIds : null,
includeRequestIds ? underProvisionedRequestIds : null, overProvisionedRequestIds.size(), underProvisionedRequestIds.size(), numFinishedRequests);
}