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;
}
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());
}
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());
}
}
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);
}
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;
}
Aggregations