Search in sources :

Example 1 with MantisJobDurationType

use of io.mantisrx.runtime.MantisJobDurationType in project mantis by Netflix.

the class DurationTypeFitnessCalculator method calculateFitness.

@Override
public double calculateFitness(TaskRequest taskRequest, VirtualMachineCurrentState targetVM, TaskTrackerState taskTrackerState) {
    MantisJobDurationType durationType = ((ScheduleRequest) taskRequest).getDurationType();
    int totalTasks = 0;
    int sameTypeTasks = 0;
    for (TaskRequest request : targetVM.getRunningTasks()) {
        totalTasks++;
        if (((ScheduleRequest) request).getDurationType() == durationType)
            sameTypeTasks++;
    }
    for (TaskAssignmentResult result : targetVM.getTasksCurrentlyAssigned()) {
        totalTasks++;
        if (((ScheduleRequest) result.getRequest()).getDurationType() == durationType)
            sameTypeTasks++;
    }
    if (totalTasks == 0)
        // an arbitrary preferential value to indicate that a fresh new host is not perfect
        return 0.9;
    // fit but a better fit than a host that has tasks of different type
    return (double) sameTypeTasks / (double) totalTasks;
}
Also used : MantisJobDurationType(io.mantisrx.runtime.MantisJobDurationType) ScheduleRequest(io.mantisrx.server.master.scheduler.ScheduleRequest) TaskAssignmentResult(com.netflix.fenzo.TaskAssignmentResult) TaskRequest(com.netflix.fenzo.TaskRequest)

Example 2 with MantisJobDurationType

use of io.mantisrx.runtime.MantisJobDurationType in project mantis by Netflix.

the class WorkerExecutionOperationsNetworkStageTest method convertJobSchedulingInfoToWorkerMapInvalidInputTest.

@Test
public void convertJobSchedulingInfoToWorkerMapInvalidInputTest() {
    String jobName = "convertJobSchedulingInfoToWorkerMapInvalidInputTest";
    String jobId = jobName + "-1";
    MantisJobDurationType durationType = MantisJobDurationType.Perpetual;
    WorkerAssignments workerAssignmentsStage1 = createWorkerAssignments(1, 2);
    WorkerAssignments workerAssignmentsStage2 = createWorkerAssignments(2, 4);
    Map<Integer, WorkerAssignments> workerAssignmentsMap = new HashMap<>();
    workerAssignmentsMap.put(1, workerAssignmentsStage1);
    workerAssignmentsMap.put(2, workerAssignmentsStage2);
    JobSchedulingInfo jobSchedulingInfo = new JobSchedulingInfo(jobId, workerAssignmentsMap);
    WorkerMap workerMap = WorkerExecutionOperationsNetworkStage.convertJobSchedulingInfoToWorkerMap(null, jobId, durationType, jobSchedulingInfo);
    assertTrue(workerMap.isEmpty());
    workerMap = WorkerExecutionOperationsNetworkStage.convertJobSchedulingInfoToWorkerMap(jobName, null, durationType, jobSchedulingInfo);
    assertTrue(workerMap.isEmpty());
    workerMap = WorkerExecutionOperationsNetworkStage.convertJobSchedulingInfoToWorkerMap(jobName, jobId, durationType, null);
    assertTrue(workerMap.isEmpty());
    jobSchedulingInfo = new JobSchedulingInfo(jobId, null);
    workerMap = WorkerExecutionOperationsNetworkStage.convertJobSchedulingInfoToWorkerMap(jobName, jobId, durationType, jobSchedulingInfo);
    assertTrue(workerMap.isEmpty());
    workerAssignmentsMap = new HashMap<>();
    workerAssignmentsMap.put(1, null);
    workerAssignmentsMap.put(2, workerAssignmentsStage2);
    jobSchedulingInfo = new JobSchedulingInfo(jobId, workerAssignmentsMap);
    workerMap = WorkerExecutionOperationsNetworkStage.convertJobSchedulingInfoToWorkerMap(jobName, jobId, durationType, jobSchedulingInfo);
    assertTrue(workerMap.isEmpty());
}
Also used : MantisJobDurationType(io.mantisrx.runtime.MantisJobDurationType) HashMap(java.util.HashMap) WorkerAssignments(io.mantisrx.server.core.WorkerAssignments) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) WorkerMap(io.mantisrx.runtime.WorkerMap) Test(org.junit.Test)

Example 3 with MantisJobDurationType

use of io.mantisrx.runtime.MantisJobDurationType in project mantis by Netflix.

the class WorkerExecutionOperationsNetworkStageTest method convertJobSchedulingInfoToWorkerMapTest.

@Test
public void convertJobSchedulingInfoToWorkerMapTest() {
    String jobName = "convertJobSchedulingInfoToWorkerMapTest";
    String jobId = jobName + "-1";
    MantisJobDurationType durationType = MantisJobDurationType.Perpetual;
    WorkerAssignments workerAssignmentsStage1 = createWorkerAssignments(1, 2);
    WorkerAssignments workerAssignmentsStage2 = createWorkerAssignments(2, 4);
    Map<Integer, WorkerAssignments> workerAssignmentsMap = new HashMap<>();
    workerAssignmentsMap.put(1, workerAssignmentsStage1);
    workerAssignmentsMap.put(2, workerAssignmentsStage2);
    JobSchedulingInfo jobSchedulingInfo = new JobSchedulingInfo(jobId, workerAssignmentsMap);
    WorkerMap workerMap = WorkerExecutionOperationsNetworkStage.convertJobSchedulingInfoToWorkerMap(jobName, jobId, durationType, jobSchedulingInfo);
    List<WorkerInfo> workersForStage1 = workerMap.getWorkersForStage(1);
    assertTrue(workersForStage1 != null);
    assertEquals(2, workersForStage1.size());
    for (int i = 0; i < workersForStage1.size(); i++) {
        WorkerInfo workerInfo = workersForStage1.get(i);
        assertEquals(i, workerInfo.getWorkerIndex());
        assertEquals(i + 1, workerInfo.getWorkerNumber());
        assertEquals(durationType, workerInfo.getDurationType());
        assertEquals(i, workerInfo.getWorkerPorts().getMetricsPort());
        assertEquals(i + 1, workerInfo.getWorkerPorts().getCustomPort());
    }
    List<WorkerInfo> workersForStage2 = workerMap.getWorkersForStage(2);
    assertTrue(workersForStage2 != null);
    assertEquals(4, workersForStage2.size());
    for (int i = 0; i < workersForStage2.size(); i++) {
        WorkerInfo workerInfo = workersForStage2.get(i);
        assertEquals(i, workerInfo.getWorkerIndex());
        assertEquals(i + 1, workerInfo.getWorkerNumber());
        assertEquals(durationType, workerInfo.getDurationType());
        assertEquals(i, workerInfo.getWorkerPorts().getMetricsPort());
        assertEquals(i + 1, workerInfo.getWorkerPorts().getCustomPort());
    }
}
Also used : MantisJobDurationType(io.mantisrx.runtime.MantisJobDurationType) HashMap(java.util.HashMap) WorkerAssignments(io.mantisrx.server.core.WorkerAssignments) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) WorkerInfo(io.mantisrx.runtime.WorkerInfo) WorkerMap(io.mantisrx.runtime.WorkerMap) Test(org.junit.Test)

Example 4 with MantisJobDurationType

use of io.mantisrx.runtime.MantisJobDurationType in project mantis by Netflix.

the class WorkerExecutionOperationsNetworkStage method generateWorkerInfo.

private static WorkerInfo generateWorkerInfo(String jobName, String jobId, int stageNumber, int workerIndex, int workerNumber, MantisJobDurationType durationType, String host, WorkerHost workerHost) {
    int sinkPort = Optional.ofNullable(workerHost.getPort()).map(ports -> (ports.size() >= 1 ? ports.get(0) : -1)).orElse(-1);
    WorkerPorts wPorts = new WorkerPorts(workerHost.getMetricsPort(), -1, -1, workerHost.getCustomPort(), sinkPort);
    return generateWorkerInfo(jobName, jobId, stageNumber, workerIndex, workerNumber, durationType, host, wPorts);
}
Also used : Strings(io.mantisrx.shaded.com.google.common.base.Strings) Arrays(java.util.Arrays) MantisJobDurationType(io.mantisrx.runtime.MantisJobDurationType) MantisJobState(io.mantisrx.runtime.MantisJobState) LoggerFactory(org.slf4j.LoggerFactory) StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) JobMasterStageConfig(io.mantisrx.server.worker.jobmaster.JobMasterStageConfig) Lifecycle(io.mantisrx.runtime.lifecycle.Lifecycle) WorkerConsumer(io.mantisrx.runtime.executor.WorkerConsumer) ServiceRegistry(io.mantisrx.server.core.ServiceRegistry) JOB_MASTER_AUTOSCALE_METRIC_SYSTEM_PARAM(io.mantisrx.runtime.parameter.ParameterUtils.JOB_MASTER_AUTOSCALE_METRIC_SYSTEM_PARAM) WorkerPorts(io.mantisrx.common.WorkerPorts) ParameterUtils(io.mantisrx.runtime.parameter.ParameterUtils) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) VirtualMachineTaskStatus(io.mantisrx.server.worker.mesos.VirtualMachineTaskStatus) RxMetrics(io.reactivex.mantis.remote.observable.RxMetrics) Status(io.mantisrx.server.core.Status) StageExecutors(io.mantisrx.runtime.executor.StageExecutors) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) WorkerAssignments(io.mantisrx.server.core.WorkerAssignments) Observer(rx.Observer) Collectors(java.util.stream.Collectors) JobMasterService(io.mantisrx.server.worker.jobmaster.JobMasterService) WorkerConsumerRemoteObservable(io.mantisrx.runtime.executor.WorkerConsumerRemoteObservable) CountDownLatch(java.util.concurrent.CountDownLatch) WorkerId(io.mantisrx.server.core.domain.WorkerId) List(java.util.List) ToDeltaEndpointInjector(io.reactivex.mantis.remote.observable.ToDeltaEndpointInjector) Action0(rx.functions.Action0) BehaviorSubject(rx.subjects.BehaviorSubject) Splitter(io.mantisrx.shaded.com.google.common.base.Splitter) Optional(java.util.Optional) WorkerMap(io.mantisrx.runtime.WorkerMap) PortSelector(io.mantisrx.runtime.executor.PortSelector) WorkerPublisherRemoteObservable(io.mantisrx.runtime.executor.WorkerPublisherRemoteObservable) StageConfig(io.mantisrx.runtime.StageConfig) MantisMasterClientApi(io.mantisrx.server.master.client.MantisMasterClientApi) MetricsRegistry(io.mantisrx.common.metrics.MetricsRegistry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Parameters(io.mantisrx.runtime.parameter.Parameters) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Observable(rx.Observable) Func1(rx.functions.Func1) WorkerMetricsClient(io.mantisrx.server.worker.client.WorkerMetricsClient) LinkedList(java.util.LinkedList) RemoteRxServer(io.reactivex.mantis.remote.observable.RemoteRxServer) AutoScaleMetricsConfig(io.mantisrx.server.worker.jobmaster.AutoScaleMetricsConfig) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Endpoint(io.mantisrx.common.network.Endpoint) TYPE(io.mantisrx.server.core.Status.TYPE) Context(io.mantisrx.runtime.Context) StatusPayloads(io.mantisrx.server.core.StatusPayloads) TimeUnit(java.util.concurrent.TimeUnit) ServiceLocator(io.mantisrx.runtime.lifecycle.ServiceLocator) ExecuteStageRequest(io.mantisrx.server.core.ExecuteStageRequest) Registry(com.netflix.spectator.api.Registry) WorkerConfiguration(io.mantisrx.server.worker.config.WorkerConfiguration) SpectatorRegistryFactory(io.mantisrx.common.metrics.spectator.SpectatorRegistryFactory) WorkerInfo(io.mantisrx.runtime.WorkerInfo) WorkerHost(io.mantisrx.server.core.WorkerHost) WorkerPorts(io.mantisrx.common.WorkerPorts) Endpoint(io.mantisrx.common.network.Endpoint)

Example 5 with MantisJobDurationType

use of io.mantisrx.runtime.MantisJobDurationType in project mantis by Netflix.

the class WorkerExecutionOperationsNetworkStage method convertJobSchedulingInfoToWorkerMap.

/**
 * Converts a JobSchedulingInfo object to a simple WorkerMap to be used from within the context.
 * Static for easier testing.
 *
 * @param jobName
 * @param jobId
 * @param durationType
 * @param js
 *
 * @return
 */
static WorkerMap convertJobSchedulingInfoToWorkerMap(String jobName, String jobId, MantisJobDurationType durationType, JobSchedulingInfo js) {
    Map<Integer, List<WorkerInfo>> stageToWorkerInfoMap = new HashMap<>();
    WorkerMap workerMap = new WorkerMap(stageToWorkerInfoMap);
    if (jobName == null || jobName.isEmpty() || jobId == null || jobId.isEmpty()) {
        logger.warn("Job name/jobId cannot be null in convertJobSchedulingInfoToWorkerMap");
        return workerMap;
    }
    if (js == null || js.getWorkerAssignments() == null) {
        logger.warn("JobSchedulingInfo or workerAssignments cannot be null in convertJobSchedulingInfoToWorkerMap");
        return workerMap;
    }
    try {
        Map<Integer, WorkerAssignments> workerAssignments = js.getWorkerAssignments();
        Iterator<Map.Entry<Integer, WorkerAssignments>> entryIterator = workerAssignments.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry<Integer, WorkerAssignments> next = entryIterator.next();
            int stageNo = next.getKey();
            WorkerAssignments workerAssignmentsForStage = next.getValue();
            Map<Integer, WorkerHost> hosts = workerAssignmentsForStage.getHosts();
            if (hosts != null) {
                List<WorkerInfo> workerInfoList = hosts.values().stream().map((workerHost) -> {
                    return generateWorkerInfo(jobName, jobId, stageNo, workerHost.getWorkerIndex(), workerHost.getWorkerNumber(), durationType, workerHost.getHost(), workerHost);
                }).collect(Collectors.toList());
                stageToWorkerInfoMap.put(stageNo, workerInfoList);
            }
        }
        workerMap = new WorkerMap(stageToWorkerInfoMap);
    } catch (Exception e) {
        logger.warn("Exception converting JobSchedulingInfo " + js + " to worker Map " + e.getMessage());
        return workerMap;
    }
    return workerMap;
}
Also used : Strings(io.mantisrx.shaded.com.google.common.base.Strings) Arrays(java.util.Arrays) MantisJobDurationType(io.mantisrx.runtime.MantisJobDurationType) MantisJobState(io.mantisrx.runtime.MantisJobState) LoggerFactory(org.slf4j.LoggerFactory) StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) JobMasterStageConfig(io.mantisrx.server.worker.jobmaster.JobMasterStageConfig) Lifecycle(io.mantisrx.runtime.lifecycle.Lifecycle) WorkerConsumer(io.mantisrx.runtime.executor.WorkerConsumer) ServiceRegistry(io.mantisrx.server.core.ServiceRegistry) JOB_MASTER_AUTOSCALE_METRIC_SYSTEM_PARAM(io.mantisrx.runtime.parameter.ParameterUtils.JOB_MASTER_AUTOSCALE_METRIC_SYSTEM_PARAM) WorkerPorts(io.mantisrx.common.WorkerPorts) ParameterUtils(io.mantisrx.runtime.parameter.ParameterUtils) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) VirtualMachineTaskStatus(io.mantisrx.server.worker.mesos.VirtualMachineTaskStatus) RxMetrics(io.reactivex.mantis.remote.observable.RxMetrics) Status(io.mantisrx.server.core.Status) StageExecutors(io.mantisrx.runtime.executor.StageExecutors) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) WorkerAssignments(io.mantisrx.server.core.WorkerAssignments) Observer(rx.Observer) Collectors(java.util.stream.Collectors) JobMasterService(io.mantisrx.server.worker.jobmaster.JobMasterService) WorkerConsumerRemoteObservable(io.mantisrx.runtime.executor.WorkerConsumerRemoteObservable) CountDownLatch(java.util.concurrent.CountDownLatch) WorkerId(io.mantisrx.server.core.domain.WorkerId) List(java.util.List) ToDeltaEndpointInjector(io.reactivex.mantis.remote.observable.ToDeltaEndpointInjector) Action0(rx.functions.Action0) BehaviorSubject(rx.subjects.BehaviorSubject) Splitter(io.mantisrx.shaded.com.google.common.base.Splitter) Optional(java.util.Optional) WorkerMap(io.mantisrx.runtime.WorkerMap) PortSelector(io.mantisrx.runtime.executor.PortSelector) WorkerPublisherRemoteObservable(io.mantisrx.runtime.executor.WorkerPublisherRemoteObservable) StageConfig(io.mantisrx.runtime.StageConfig) MantisMasterClientApi(io.mantisrx.server.master.client.MantisMasterClientApi) MetricsRegistry(io.mantisrx.common.metrics.MetricsRegistry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Parameters(io.mantisrx.runtime.parameter.Parameters) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Observable(rx.Observable) Func1(rx.functions.Func1) WorkerMetricsClient(io.mantisrx.server.worker.client.WorkerMetricsClient) LinkedList(java.util.LinkedList) RemoteRxServer(io.reactivex.mantis.remote.observable.RemoteRxServer) AutoScaleMetricsConfig(io.mantisrx.server.worker.jobmaster.AutoScaleMetricsConfig) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Endpoint(io.mantisrx.common.network.Endpoint) TYPE(io.mantisrx.server.core.Status.TYPE) Context(io.mantisrx.runtime.Context) StatusPayloads(io.mantisrx.server.core.StatusPayloads) TimeUnit(java.util.concurrent.TimeUnit) ServiceLocator(io.mantisrx.runtime.lifecycle.ServiceLocator) ExecuteStageRequest(io.mantisrx.server.core.ExecuteStageRequest) Registry(com.netflix.spectator.api.Registry) WorkerConfiguration(io.mantisrx.server.worker.config.WorkerConfiguration) SpectatorRegistryFactory(io.mantisrx.common.metrics.spectator.SpectatorRegistryFactory) WorkerInfo(io.mantisrx.runtime.WorkerInfo) WorkerHost(io.mantisrx.server.core.WorkerHost) WorkerHost(io.mantisrx.server.core.WorkerHost) HashMap(java.util.HashMap) WorkerInfo(io.mantisrx.runtime.WorkerInfo) Endpoint(io.mantisrx.common.network.Endpoint) WorkerAssignments(io.mantisrx.server.core.WorkerAssignments) List(java.util.List) LinkedList(java.util.LinkedList) WorkerMap(io.mantisrx.runtime.WorkerMap) Map(java.util.Map) WorkerMap(io.mantisrx.runtime.WorkerMap) HashMap(java.util.HashMap)

Aggregations

MantisJobDurationType (io.mantisrx.runtime.MantisJobDurationType)5 WorkerMap (io.mantisrx.runtime.WorkerMap)4 JobSchedulingInfo (io.mantisrx.server.core.JobSchedulingInfo)4 WorkerAssignments (io.mantisrx.server.core.WorkerAssignments)4 HashMap (java.util.HashMap)4 WorkerInfo (io.mantisrx.runtime.WorkerInfo)3 Registry (com.netflix.spectator.api.Registry)2 WorkerPorts (io.mantisrx.common.WorkerPorts)2 MetricsRegistry (io.mantisrx.common.metrics.MetricsRegistry)2 SpectatorRegistryFactory (io.mantisrx.common.metrics.spectator.SpectatorRegistryFactory)2 Endpoint (io.mantisrx.common.network.Endpoint)2 Context (io.mantisrx.runtime.Context)2 MantisJobState (io.mantisrx.runtime.MantisJobState)2 StageConfig (io.mantisrx.runtime.StageConfig)2 StageSchedulingInfo (io.mantisrx.runtime.descriptor.StageSchedulingInfo)2 PortSelector (io.mantisrx.runtime.executor.PortSelector)2 StageExecutors (io.mantisrx.runtime.executor.StageExecutors)2 WorkerConsumer (io.mantisrx.runtime.executor.WorkerConsumer)2 WorkerConsumerRemoteObservable (io.mantisrx.runtime.executor.WorkerConsumerRemoteObservable)2 WorkerPublisherRemoteObservable (io.mantisrx.runtime.executor.WorkerPublisherRemoteObservable)2