use of com.hubspot.singularity.SingularityState in project Singularity by HubSpot.
the class StateManagerTest method itDoesntFlagPendingRequestsForUnderOrOverProvisioning.
@Test
public void itDoesntFlagPendingRequestsForUnderOrOverProvisioning() {
initRequest();
initFirstDeploy();
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
requestManager.activate(request.toBuilder().setInstances(Optional.of(0)).build(), RequestHistoryType.UPDATED, System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent());
requestManager.addToPendingQueue(new SingularityPendingRequest(request.getId(), firstDeployId, System.currentTimeMillis(), Optional.<String>absent(), PendingType.ONEOFF, Optional.<Boolean>absent(), Optional.<String>absent()));
Assert.assertEquals(0, taskManager.getActiveTaskIds().size());
SingularityState state = stateManager.getState(true, false);
Assert.assertEquals(0, state.getOverProvisionedRequests());
Assert.assertEquals(0, state.getUnderProvisionedRequests());
}
use of com.hubspot.singularity.SingularityState in project Singularity by HubSpot.
the class SingularityClient method getState.
//
// GLOBAL
//
public SingularityState getState(Optional<Boolean> skipCache, Optional<Boolean> includeRequestIds) {
final Function<String, String> uri = (host) -> String.format(STATE_FORMAT, getApiBase(host));
LOG.info("Fetching state from {}", uri);
final long start = System.currentTimeMillis();
Map<String, Boolean> queryParams = new HashMap<>();
if (skipCache.isPresent()) {
queryParams.put("skipCache", skipCache.get());
}
if (includeRequestIds.isPresent()) {
queryParams.put("includeRequestIds", includeRequestIds.get());
}
HttpResponse response = executeRequest(uri, Method.GET, Optional.absent(), queryParams);
checkResponse("state", response);
LOG.info("Got state in {}ms", System.currentTimeMillis() - start);
return response.getAs(SingularityState.class);
}
use of com.hubspot.singularity.SingularityState in project Singularity by HubSpot.
the class StateManager method generateState.
public SingularityState generateState(boolean includeRequestIds) {
final int launchingTasks = taskManager.getNumLaunchingTasks();
final int activeTasks = taskManager.getNumActiveTasks() - launchingTasks;
final int scheduledTasks = taskManager.getNumScheduledTasks();
final int cleaningTasks = taskManager.getNumCleanupTasks();
final int lbCleanupTasks = taskManager.getNumLbCleanupTasks();
final int lbCleanupRequests = requestManager.getNumLbCleanupRequests();
final SingularityScheduledTasksInfo scheduledTasksInfo = SingularityScheduledTasksInfo.getInfo(taskManager.getPendingTasks(), singularityConfiguration.getDeltaAfterWhichTasksAreLateMillis());
final List<String> overProvisionedRequestIds = new ArrayList<>();
final Set<String> possiblyUnderProvisionedRequestIds = new HashSet<>();
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;
}
updatePossiblyUnderProvisionedAndOverProvisionedIds(requestWithState, numInstances, overProvisionedRequestIds, possiblyUnderProvisionedRequestIds);
}
filterForPendingRequests(possiblyUnderProvisionedRequestIds);
final List<String> underProvisionedRequestIds = getUnderProvisionedRequestIds(possiblyUnderProvisionedRequestIds);
final int pendingRequests = requestManager.getSizeOfPendingQueue();
final int cleaningRequests = requestManager.getSizeOfCleanupQueue();
List<SingularityRack> racks = rackManager.getObjects();
int activeRacks = 0;
int deadRacks = 0;
int decommissioningRacks = 0;
int unknownRacks = 0;
for (SingularityRack rack : racks) {
switch(rack.getCurrentState().getState()) {
case ACTIVE:
activeRacks++;
break;
case DEAD:
deadRacks++;
break;
case MISSING_ON_STARTUP:
unknownRacks++;
break;
case DECOMMISSIONED:
case STARTING_DECOMMISSION:
case DECOMMISSIONING:
decommissioningRacks++;
break;
default:
unknownRacks++;
break;
}
}
List<SingularitySlave> slaves = slaveManager.getObjects();
int activeSlaves = 0;
int deadSlaves = 0;
int decommissioningSlaves = 0;
int unknownSlaves = 0;
for (SingularitySlave slave : slaves) {
switch(slave.getCurrentState().getState()) {
case ACTIVE:
activeSlaves++;
break;
case DEAD:
deadSlaves++;
break;
case MISSING_ON_STARTUP:
unknownSlaves++;
break;
case DECOMMISSIONED:
case STARTING_DECOMMISSION:
case DECOMMISSIONING:
decommissioningSlaves++;
break;
default:
unknownSlaves++;
break;
}
}
final List<SingularityHostState> states = getHostStates();
int numDeploys = 0;
long oldestDeploy = 0;
long oldestDeployStep = 0;
List<SingularityDeployMarker> activeDeploys = new ArrayList<>();
final long now = System.currentTimeMillis();
for (SingularityPendingDeploy pendingDeploy : deployManager.getPendingDeploys()) {
activeDeploys.add(pendingDeploy.getDeployMarker());
if (pendingDeploy.getDeployProgress().isPresent() && !pendingDeploy.getDeployProgress().get().isStepComplete()) {
long deployStepDelta = now - pendingDeploy.getDeployProgress().get().getTimestamp();
if (deployStepDelta > oldestDeployStep) {
oldestDeployStep = deployStepDelta;
}
}
long delta = now - pendingDeploy.getDeployMarker().getTimestamp();
if (delta > oldestDeploy) {
oldestDeploy = delta;
}
numDeploys++;
}
final Optional<Boolean> authDatastoreHealthy = authDatastore.isHealthy();
final Optional<Double> minimumPriorityLevel = getMinimumPriorityLevel();
return new SingularityState(activeTasks, launchingTasks, numActiveRequests, cooldownRequests, numPausedRequests, scheduledTasks, pendingRequests, lbCleanupTasks, lbCleanupRequests, cleaningRequests, activeSlaves, deadSlaves, decommissioningSlaves, activeRacks, deadRacks, decommissioningRacks, cleaningTasks, states, oldestDeploy, numDeploys, oldestDeployStep, activeDeploys, scheduledTasksInfo.getNumLateTasks(), scheduledTasksInfo.getNumFutureTasks(), scheduledTasksInfo.getMaxTaskLag(), System.currentTimeMillis(), includeRequestIds ? overProvisionedRequestIds : null, includeRequestIds ? underProvisionedRequestIds : null, overProvisionedRequestIds.size(), underProvisionedRequestIds.size(), numFinishedRequests, unknownRacks, unknownSlaves, authDatastoreHealthy, minimumPriorityLevel, statusUpdateDeltaAvg.get());
}
use of com.hubspot.singularity.SingularityState in project Singularity by HubSpot.
the class StateManager method getState.
public SingularityState getState(boolean skipCache, boolean includeRequestIds) {
Optional<SingularityState> fromZk = Optional.absent();
if (!skipCache) {
fromZk = getData(STATE_PATH, stateTranscoder);
}
if (fromZk.isPresent()) {
final long now = System.currentTimeMillis();
final long delta = now - fromZk.get().getGeneratedAt();
if (delta < singularityConfiguration.getCacheStateForMillis()) {
return fromZk.get();
}
}
final long start = System.currentTimeMillis();
SingularityState newState = generateState(includeRequestIds);
if (!skipCache) {
final byte[] bytes = stateTranscoder.toBytes(newState);
save(STATE_PATH, newState, stateTranscoder);
LOG.info("Generated new state and saved {} bytes in {}", bytes.length, JavaUtils.duration(start));
}
return newState;
}
Aggregations