Example usage for org.apache.hadoop.yarn.api.records ContainerStatus newInstance

List of usage examples for org.apache.hadoop.yarn.api.records ContainerStatus newInstance

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.records ContainerStatus newInstance.

Prototype

@Private
    @Unstable
    public static ContainerStatus newInstance(ContainerId containerId, ContainerState containerState,
            String diagnostics, int exitStatus) 

Source Link

Usage

From source file:de.huberlin.wbi.hiway.scheduler.TestScheduler.java

License:Apache License

private static void run(Scheduler scheduler, List<String> nodeNames, List<String> taskNames, int[][] runtimes) {

    Queue<NodeId> availableNodes = new LinkedList<>();
    for (String nodeName : nodeNames) {
        NodeId node = NodeId.newInstance(nodeName, 0);
        availableNodes.add(node);//w ww . jav a 2  s.  c o m
    }

    Map<Container, TaskInstance> runningTasks = new HashMap<>();
    Map<Container, Long> finishTimes = new HashMap<>();

    int runningId = 0;
    long clock = 0;
    while (!scheduler.nothingToSchedule() || !runningTasks.isEmpty()) {
        if (!scheduler.nothingToSchedule() && !availableNodes.isEmpty()) {
            NodeId nodeId = availableNodes.remove();
            ContainerId containerId = ContainerId.newContainerId(null, runningId++);
            Container container = Container.newInstance(containerId, nodeId, "", null, null, null);
            TaskInstance task = scheduler.getNextTask(container);
            runningTasks.put(container, task);
            long runtime = (runtimes == null) ? 1
                    : runtimes[nodeNames.indexOf(nodeId.getHost())][taskNames.indexOf(task.getTaskName())];

            finishTimes.put(container, clock + runtime);
        }

        for (Container container : finishTimes.keySet()) {
            if (clock == finishTimes.get(container)) {
                NodeId nodeId = container.getNodeId();
                ContainerStatus containerStatus = ContainerStatus.newInstance(container.getId(), null, "", 0);
                TaskInstance task = runningTasks.get(container);
                task.setCompleted();
                long runtime = (runtimes == null) ? 1
                        : runtimes[nodeNames.indexOf(nodeId.getHost())][taskNames.indexOf(task.getTaskName())];
                scheduler.taskCompleted(task, containerStatus, runtime);
                runningTasks.remove(container);
                availableNodes.add(nodeId);
            }
        }

        clock++;
    }
}