Search in sources :

Example 1 with VirtualMachineCurrentState

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);
}
Also used : VirtualMachineCurrentState(com.netflix.fenzo.VirtualMachineCurrentState) TaskRequest(com.netflix.fenzo.TaskRequest) LaunchTaskRequest(io.mantisrx.server.master.scheduler.LaunchTaskRequest) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) WorkerId(io.mantisrx.server.core.domain.WorkerId)

Example 2 with VirtualMachineCurrentState

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;
}
Also used : ArrayList(java.util.ArrayList) VirtualMachineCurrentState(com.netflix.fenzo.VirtualMachineCurrentState) TaskRequest(com.netflix.fenzo.TaskRequest) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) WorkerId(io.mantisrx.server.core.domain.WorkerId) Protos(org.apache.mesos.Protos) WorkerOnDisabledVM(io.mantisrx.server.master.scheduler.WorkerOnDisabledVM)

Example 3 with VirtualMachineCurrentState

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;
}
Also used : Protos(org.apache.mesos.Protos) IMantisStorageProvider(io.mantisrx.server.master.persistence.IMantisStorageProvider) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) DateTimeExt(io.mantisrx.common.util.DateTimeExt) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) BaseService(io.mantisrx.server.core.BaseService) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) TaskRequest(com.netflix.fenzo.TaskRequest) AgentClustersAutoScaler(io.mantisrx.server.master.AgentClustersAutoScaler) LifecycleEventsProto(io.mantisrx.master.events.LifecycleEventsProto) VirtualMachineCurrentState(com.netflix.fenzo.VirtualMachineCurrentState) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) WorkerOnDisabledVM(io.mantisrx.server.master.scheduler.WorkerOnDisabledVM) Metrics(io.mantisrx.common.metrics.Metrics) AutoScaleRule(com.netflix.fenzo.AutoScaleRule) Counter(io.mantisrx.common.metrics.Counter) Logger(org.slf4j.Logger) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) Preconditions(com.netflix.spectator.impl.Preconditions) JsonProperty(io.mantisrx.shaded.com.fasterxml.jackson.annotation.JsonProperty) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) WorkerId(io.mantisrx.server.core.domain.WorkerId) List(java.util.List) JobMessageRouter(io.mantisrx.server.master.scheduler.JobMessageRouter) JsonCreator(io.mantisrx.shaded.com.fasterxml.jackson.annotation.JsonCreator) Optional(java.util.Optional) Collections(java.util.Collections) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) ArrayList(java.util.ArrayList) VirtualMachineCurrentState(com.netflix.fenzo.VirtualMachineCurrentState) TaskRequest(com.netflix.fenzo.TaskRequest) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) WorkerId(io.mantisrx.server.core.domain.WorkerId) Protos(org.apache.mesos.Protos)

Example 4 with VirtualMachineCurrentState

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;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) VirtualMachineCurrentState(com.netflix.fenzo.VirtualMachineCurrentState) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

VirtualMachineCurrentState (com.netflix.fenzo.VirtualMachineCurrentState)4 TaskRequest (com.netflix.fenzo.TaskRequest)3 VirtualMachineLease (com.netflix.fenzo.VirtualMachineLease)3 WorkerId (io.mantisrx.server.core.domain.WorkerId)3 ArrayList (java.util.ArrayList)3 WorkerOnDisabledVM (io.mantisrx.server.master.scheduler.WorkerOnDisabledVM)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 Protos (org.apache.mesos.Protos)2 AutoScaleRule (com.netflix.fenzo.AutoScaleRule)1 Preconditions (com.netflix.spectator.impl.Preconditions)1 Counter (io.mantisrx.common.metrics.Counter)1 Metrics (io.mantisrx.common.metrics.Metrics)1 DateTimeExt (io.mantisrx.common.util.DateTimeExt)1 LifecycleEventPublisher (io.mantisrx.master.events.LifecycleEventPublisher)1 LifecycleEventsProto (io.mantisrx.master.events.LifecycleEventsProto)1 BaseService (io.mantisrx.server.core.BaseService)1 AgentClustersAutoScaler (io.mantisrx.server.master.AgentClustersAutoScaler)1