use of com.netflix.fenzo.VirtualMachineCurrentState in project mantis by Netflix.
the class SchedulingService method verifyAndReportResUsageMetrics.
private void verifyAndReportResUsageMetrics(List<VirtualMachineCurrentState> vmCurrentStates) {
double totalCPU = 0.0;
double usedCPU = 0.0;
double totalMemory = 0.0;
double usedMemory = 0.0;
double totalNwMbps = 0.0;
double usedNwMbps = 0.0;
for (VirtualMachineCurrentState state : vmCurrentStates) {
final VirtualMachineLease currAvailableResources = state.getCurrAvailableResources();
if (currAvailableResources != null) {
totalCPU += currAvailableResources.cpuCores();
totalMemory += currAvailableResources.memoryMB();
totalNwMbps += currAvailableResources.networkMbps();
}
final Collection<TaskRequest> runningTasks = state.getRunningTasks();
if (runningTasks != null) {
for (TaskRequest t : runningTasks) {
Optional<WorkerId> workerId = WorkerId.fromId(t.getId());
if (!workerId.isPresent() || !workerRegistry.isWorkerValid(workerId.get())) {
taskSchedulingService.removeTask(t.getId(), DEFAULT_Q_ATTRIBUTES, state.getHostname());
} else {
usedCPU += t.getCPUs();
totalCPU += t.getCPUs();
usedMemory += t.getMemory();
totalMemory += t.getMemory();
usedNwMbps += t.getNetworkMbps();
totalNwMbps += t.getNetworkMbps();
}
}
}
}
totalAvailableCPUs.set((long) totalCPU);
totalAllocatedCPUs.set((long) usedCPU);
cpuUtilization.set((long) (usedCPU * 100.0 / totalCPU));
double DRU = usedCPU * 100.0 / totalCPU;
totalAvailableMemory.set((long) totalMemory);
totalAllocatedMemory.set((long) usedMemory);
memoryUtilization.set((long) (usedMemory * 100.0 / totalMemory));
DRU = Math.max(DRU, usedMemory * 100.0 / totalMemory);
totalAvailableNwMbps.set((long) totalNwMbps);
totalAllocatedNwMbps.set((long) usedNwMbps);
networkUtilization.set((long) (usedNwMbps * 100.0 / totalNwMbps));
DRU = Math.max(DRU, usedNwMbps * 100.0 / totalNwMbps);
dominantResUtilization.set((long) DRU);
}
use of com.netflix.fenzo.VirtualMachineCurrentState in project mantis by Netflix.
the class AgentClusterOperationsImpl method manageActiveVMs.
List<String> manageActiveVMs(final List<VirtualMachineCurrentState> currentStates) {
List<String> inactiveVMs = new ArrayList<>();
if (currentStates != null && !currentStates.isEmpty()) {
final List<String> values = getActiveVMsAttributeValues();
if (values == null || values.isEmpty())
// treat no valid active VMs attribute value as all are active
return Collections.EMPTY_LIST;
for (VirtualMachineCurrentState currentState : currentStates) {
final VirtualMachineLease lease = currentState.getCurrAvailableResources();
// logger.info("Lease for VM: " + currentState.getCurrAvailableResources());
if (lease != null) {
final Collection<TaskRequest> runningTasks = currentState.getRunningTasks();
if (runningTasks != null && !runningTasks.isEmpty()) {
final Map<String, Protos.Attribute> attributeMap = lease.getAttributeMap();
if (attributeMap != null && !attributeMap.isEmpty()) {
final Protos.Attribute attribute = attributeMap.get(attrName);
if (attribute != null && attribute.hasText()) {
if (!isIn(attribute.getText().getValue(), values)) {
inactiveVMs.add(lease.hostname());
for (TaskRequest t : runningTasks) {
Optional<WorkerId> workerIdO = WorkerId.fromId(t.getId());
workerIdO.ifPresent(workerId -> jobMessageRouter.routeWorkerEvent(new WorkerOnDisabledVM(workerId)));
}
}
} else
logger.warn("No attribute value for " + attrName + " found on VM " + lease.hostname() + " that has " + runningTasks.size() + " tasks on it");
} else
logger.warn("No attributes found on VM " + lease.hostname() + " that has " + runningTasks.size() + " tasks on it");
}
}
}
}
return inactiveVMs;
}
use of com.netflix.fenzo.VirtualMachineCurrentState in project mantis by Netflix.
the class AgentClusterOperationsImpl method getJobsOnVMStatus.
private List<JobsOnVMStatus> getJobsOnVMStatus() {
List<AgentClusterOperations.JobsOnVMStatus> result = new ArrayList<>();
final List<VirtualMachineCurrentState> vmCurrentStates = scheduler.getCurrentVMState();
if (vmCurrentStates != null && !vmCurrentStates.isEmpty()) {
for (VirtualMachineCurrentState currentState : vmCurrentStates) {
final VirtualMachineLease currAvailableResources = currentState.getCurrAvailableResources();
if (currAvailableResources != null) {
final Protos.Attribute attribute = currAvailableResources.getAttributeMap().get(attrName);
if (attribute != null) {
AgentClusterOperations.JobsOnVMStatus s = new AgentClusterOperations.JobsOnVMStatus(currAvailableResources.hostname(), attribute.getText().getValue());
for (TaskRequest r : currentState.getRunningTasks()) {
final Optional<WorkerId> workerId = WorkerId.fromId(r.getId());
s.addJob(new AgentClusterOperations.JobOnVMInfo(workerId.map(w -> w.getJobId()).orElse("InvalidJobId"), -1, workerId.map(w -> w.getWorkerIndex()).orElse(-1), workerId.map(w -> w.getWorkerNum()).orElse(-1)));
}
result.add(s);
}
}
}
}
return result;
}
use of com.netflix.fenzo.VirtualMachineCurrentState in project mantis by Netflix.
the class AgentClusterOperationsImpl method getAgentInfos.
@Override
public List<AgentInfo> getAgentInfos() {
List<VirtualMachineCurrentState> vmStates = vmStatesMap.get("0");
List<AgentInfo> agentInfos = new ArrayList<>();
if (vmStates != null && !vmStates.isEmpty()) {
for (VirtualMachineCurrentState s : vmStates) {
List<VirtualMachineLease.Range> ranges = s.getCurrAvailableResources().portRanges();
int ports = 0;
if (ranges != null && !ranges.isEmpty())
for (VirtualMachineLease.Range r : ranges) ports += r.getEnd() - r.getBeg();
Map<String, Protos.Attribute> attributeMap = s.getCurrAvailableResources().getAttributeMap();
Map<String, String> attributes = new HashMap<>();
if (attributeMap != null && !attributeMap.isEmpty()) {
for (Map.Entry<String, Protos.Attribute> entry : attributeMap.entrySet()) {
attributes.put(entry.getKey(), entry.getValue().getText().getValue());
}
}
agentInfos.add(new AgentInfo(s.getHostname(), s.getCurrAvailableResources().cpuCores(), s.getCurrAvailableResources().memoryMB(), s.getCurrAvailableResources().diskMB(), ports, s.getCurrAvailableResources().getScalarValues(), attributes, s.getResourceSets().keySet(), getTimeString(s.getDisabledUntil())));
}
}
return agentInfos;
}
Aggregations