Search in sources :

Example 16 with TaskManagerLocation

use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.

the class ExecutionVertexLocalityTest method testNoLocalityInputLargeAllToAll.

/**
	 * This test validates that vertices with too many input streams do not have a location
	 * preference any more.
	 */
@Test
public void testNoLocalityInputLargeAllToAll() throws Exception {
    final int parallelism = 100;
    final ExecutionGraph graph = createTestGraph(parallelism, true);
    // set the location for all sources to a distinct location
    for (int i = 0; i < parallelism; i++) {
        ExecutionVertex source = graph.getAllVertices().get(sourceVertexId).getTaskVertices()[i];
        TaskManagerLocation location = new TaskManagerLocation(ResourceID.generate(), InetAddress.getLoopbackAddress(), 10000 + i);
        initializeLocation(source, location);
    }
    // validate that the target vertices have no location preference
    for (int i = 0; i < parallelism; i++) {
        ExecutionVertex target = graph.getAllVertices().get(targetVertexId).getTaskVertices()[i];
        Iterator<TaskManagerLocation> preference = target.getPreferredLocations().iterator();
        assertFalse(preference.hasNext());
    }
}
Also used : TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) Test(org.junit.Test)

Example 17 with TaskManagerLocation

use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.

the class ExecutionVertexLocalityTest method testLocalityBasedOnState.

/**
	 * This test validates that stateful vertices schedule based in the state's location
	 * (which is the prior execution's location).
	 */
@Test
public void testLocalityBasedOnState() throws Exception {
    final int parallelism = 10;
    final TaskManagerLocation[] locations = new TaskManagerLocation[parallelism];
    final ExecutionGraph graph = createTestGraph(parallelism, false);
    // set the location for all sources and targets
    for (int i = 0; i < parallelism; i++) {
        ExecutionVertex source = graph.getAllVertices().get(sourceVertexId).getTaskVertices()[i];
        ExecutionVertex target = graph.getAllVertices().get(targetVertexId).getTaskVertices()[i];
        TaskManagerLocation randomLocation = new TaskManagerLocation(ResourceID.generate(), InetAddress.getLoopbackAddress(), 10000 + i);
        TaskManagerLocation location = new TaskManagerLocation(ResourceID.generate(), InetAddress.getLoopbackAddress(), 20000 + i);
        locations[i] = location;
        initializeLocation(source, randomLocation);
        initializeLocation(target, location);
        setState(source.getCurrentExecutionAttempt(), ExecutionState.CANCELED);
        setState(target.getCurrentExecutionAttempt(), ExecutionState.CANCELED);
    }
    // mimic a restart: all vertices get re-initialized without actually being executed
    for (ExecutionJobVertex ejv : graph.getVerticesTopologically()) {
        ejv.resetForNewExecution();
    }
    // set new location for the sources and some state for the targets
    for (int i = 0; i < parallelism; i++) {
        // source location
        ExecutionVertex source = graph.getAllVertices().get(sourceVertexId).getTaskVertices()[i];
        TaskManagerLocation randomLocation = new TaskManagerLocation(ResourceID.generate(), InetAddress.getLoopbackAddress(), 30000 + i);
        initializeLocation(source, randomLocation);
        // target state
        ExecutionVertex target = graph.getAllVertices().get(targetVertexId).getTaskVertices()[i];
        target.getCurrentExecutionAttempt().setInitialState(mock(TaskStateHandles.class));
    }
    // validate that the target vertices have the state's location as the location preference
    for (int i = 0; i < parallelism; i++) {
        ExecutionVertex target = graph.getAllVertices().get(targetVertexId).getTaskVertices()[i];
        Iterator<TaskManagerLocation> preference = target.getPreferredLocations().iterator();
        assertTrue(preference.hasNext());
        assertEquals(locations[i], preference.next());
        assertFalse(preference.hasNext());
    }
}
Also used : TaskStateHandles(org.apache.flink.runtime.state.TaskStateHandles) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) Test(org.junit.Test)

Example 18 with TaskManagerLocation

use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.

the class AvailableSlotsTest method createAllocatedSlot.

static AllocatedSlot createAllocatedSlot(final ResourceID resourceId) {
    TaskManagerLocation mockTaskManagerLocation = mock(TaskManagerLocation.class);
    when(mockTaskManagerLocation.getResourceID()).thenReturn(resourceId);
    TaskManagerGateway mockTaskManagerGateway = mock(TaskManagerGateway.class);
    return new AllocatedSlot(new AllocationID(), new JobID(), mockTaskManagerLocation, 0, DEFAULT_TESTING_PROFILE, mockTaskManagerGateway);
}
Also used : AllocatedSlot(org.apache.flink.runtime.jobmanager.slots.AllocatedSlot) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) TaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway) JobID(org.apache.flink.api.common.JobID)

Example 19 with TaskManagerLocation

use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.

the class InstanceManagerTest method testInstanceRegistering.

@Test
public void testInstanceRegistering() {
    try {
        InstanceManager cm = new InstanceManager();
        final int dataPort = 20000;
        HardwareDescription hardwareDescription = HardwareDescription.extractFromSystem(4096);
        InetAddress address = InetAddress.getByName("127.0.0.1");
        // register three instances
        ResourceID resID1 = ResourceID.generate();
        ResourceID resID2 = ResourceID.generate();
        ResourceID resID3 = ResourceID.generate();
        TaskManagerLocation ici1 = new TaskManagerLocation(resID1, address, dataPort);
        TaskManagerLocation ici2 = new TaskManagerLocation(resID2, address, dataPort + 15);
        TaskManagerLocation ici3 = new TaskManagerLocation(resID3, address, dataPort + 30);
        final JavaTestKit probe1 = new JavaTestKit(system);
        final JavaTestKit probe2 = new JavaTestKit(system);
        final JavaTestKit probe3 = new JavaTestKit(system);
        cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe1.getRef(), leaderSessionID)), ici1, hardwareDescription, 1);
        cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe2.getRef(), leaderSessionID)), ici2, hardwareDescription, 2);
        cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe3.getRef(), leaderSessionID)), ici3, hardwareDescription, 5);
        assertEquals(3, cm.getNumberOfRegisteredTaskManagers());
        assertEquals(8, cm.getTotalNumberOfSlots());
        Collection<Instance> instances = cm.getAllRegisteredInstances();
        Set<TaskManagerLocation> taskManagerLocations = new HashSet<TaskManagerLocation>();
        for (Instance instance : instances) {
            taskManagerLocations.add(instance.getTaskManagerLocation());
        }
        assertTrue(taskManagerLocations.contains(ici1));
        assertTrue(taskManagerLocations.contains(ici2));
        assertTrue(taskManagerLocations.contains(ici3));
        cm.shutdown();
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        Assert.fail("Test erroneous: " + e.getMessage());
    }
}
Also used : TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) InetAddress(java.net.InetAddress) JavaTestKit(akka.testkit.JavaTestKit) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with TaskManagerLocation

use of org.apache.flink.runtime.taskmanager.TaskManagerLocation in project flink by apache.

the class InstanceManagerTest method testShutdown.

@Test
public void testShutdown() {
    try {
        InstanceManager cm = new InstanceManager();
        cm.shutdown();
        try {
            ResourceID resID = ResourceID.generate();
            HardwareDescription resources = HardwareDescription.extractFromSystem(4096);
            InetAddress address = InetAddress.getByName("127.0.0.1");
            TaskManagerLocation ici = new TaskManagerLocation(resID, address, 20000);
            JavaTestKit probe = new JavaTestKit(system);
            cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe.getRef(), leaderSessionID)), ici, resources, 1);
            fail("Should raise exception in shutdown state");
        } catch (IllegalStateException e) {
        // expected
        }
        assertFalse(cm.reportHeartBeat(new InstanceID()));
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        Assert.fail("Test erroneous: " + e.getMessage());
    }
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) InetAddress(java.net.InetAddress) JavaTestKit(akka.testkit.JavaTestKit) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) Test(org.junit.Test)

Aggregations

TaskManagerLocation (org.apache.flink.runtime.taskmanager.TaskManagerLocation)59 Test (org.junit.Test)30 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)25 SimpleSlot (org.apache.flink.runtime.instance.SimpleSlot)16 JobID (org.apache.flink.api.common.JobID)14 Instance (org.apache.flink.runtime.instance.Instance)12 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)11 InetAddress (java.net.InetAddress)10 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)10 UUID (java.util.UUID)9 Time (org.apache.flink.api.common.time.Time)9 BroadcastVariableManager (org.apache.flink.runtime.broadcast.BroadcastVariableManager)9 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)9 FileCache (org.apache.flink.runtime.filecache.FileCache)9 HeartbeatServices (org.apache.flink.runtime.heartbeat.HeartbeatServices)9 IOManager (org.apache.flink.runtime.io.disk.iomanager.IOManager)9 NetworkEnvironment (org.apache.flink.runtime.io.network.NetworkEnvironment)9 ActorTaskManagerGateway (org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway)9 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)9 TaskManagerMetricGroup (org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup)9