use of org.apache.flink.runtime.instance.SimpleSlot in project flink by apache.
the class SchedulerSlotSharingTest method testSequentialAllocateAndRelease.
@Test
public void testSequentialAllocateAndRelease() {
try {
final JobVertexID jid1 = new JobVertexID();
final JobVertexID jid2 = new JobVertexID();
final JobVertexID jid3 = new JobVertexID();
final JobVertexID jid4 = new JobVertexID();
final SlotSharingGroup sharingGroup = new SlotSharingGroup(jid1, jid2, jid3, jid4);
final Scheduler scheduler = new Scheduler(TestingUtils.defaultExecutionContext());
scheduler.newInstanceAvailable(getRandomInstance(4));
// allocate something from group 1 and 2 interleaved with schedule for group 3
SimpleSlot slot_1_1 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid1, 0, 4), sharingGroup), false).get();
SimpleSlot slot_1_2 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid1, 1, 4), sharingGroup), false).get();
SimpleSlot slot_2_1 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid2, 0, 4), sharingGroup), false).get();
SimpleSlot slot_2_2 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid2, 1, 4), sharingGroup), false).get();
SimpleSlot slot_3 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid3, 0, 1), sharingGroup), false).get();
SimpleSlot slot_1_3 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid1, 2, 4), sharingGroup), false).get();
SimpleSlot slot_1_4 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid1, 3, 4), sharingGroup), false).get();
SimpleSlot slot_2_3 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid2, 2, 4), sharingGroup), false).get();
SimpleSlot slot_2_4 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid2, 3, 4), sharingGroup), false).get();
// release groups 1 and 2
slot_1_1.releaseSlot();
slot_1_2.releaseSlot();
slot_1_3.releaseSlot();
slot_1_4.releaseSlot();
slot_2_1.releaseSlot();
slot_2_2.releaseSlot();
slot_2_3.releaseSlot();
slot_2_4.releaseSlot();
// allocate group 4
SimpleSlot slot_4_1 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid4, 0, 4), sharingGroup), false).get();
SimpleSlot slot_4_2 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid4, 1, 4), sharingGroup), false).get();
SimpleSlot slot_4_3 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid4, 2, 4), sharingGroup), false).get();
SimpleSlot slot_4_4 = scheduler.allocateSlot(new ScheduledUnit(getTestVertex(jid4, 3, 4), sharingGroup), false).get();
// release groups 3 and 4
slot_3.releaseSlot();
slot_4_1.releaseSlot();
slot_4_2.releaseSlot();
slot_4_3.releaseSlot();
slot_4_4.releaseSlot();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.runtime.instance.SimpleSlot in project flink by apache.
the class Execution method sendUpdatePartitionInfoRpcCall.
/**
* Update the partition infos on the assigned resource.
*
* @param partitionInfos for the remote task
*/
private void sendUpdatePartitionInfoRpcCall(final Iterable<PartitionInfo> partitionInfos) {
final SimpleSlot slot = assignedResource;
if (slot != null) {
final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway();
final TaskManagerLocation taskManagerLocation = slot.getTaskManagerLocation();
Future<Acknowledge> updatePartitionsResultFuture = taskManagerGateway.updatePartitions(attemptId, partitionInfos, timeout);
updatePartitionsResultFuture.exceptionallyAsync(new ApplyFunction<Throwable, Void>() {
@Override
public Void apply(Throwable failure) {
fail(new IllegalStateException("Update task on TaskManager " + taskManagerLocation + " failed due to:", failure));
return null;
}
}, executor);
}
}
use of org.apache.flink.runtime.instance.SimpleSlot in project flink by apache.
the class Execution method notifyCheckpointComplete.
/**
* Notify the task of this execution about a completed checkpoint.
*
* @param checkpointId of the completed checkpoint
* @param timestamp of the completed checkpoint
*/
public void notifyCheckpointComplete(long checkpointId, long timestamp) {
final SimpleSlot slot = assignedResource;
if (slot != null) {
final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway();
taskManagerGateway.notifyCheckpointComplete(attemptId, getVertex().getJobId(), checkpointId, timestamp);
} else {
LOG.debug("The execution has no slot assigned. This indicates that the execution is " + "no longer running.");
}
}
use of org.apache.flink.runtime.instance.SimpleSlot in project flink by apache.
the class Execution method stop.
/**
* Sends stop RPC call.
*/
public void stop() {
final SimpleSlot slot = assignedResource;
if (slot != null) {
final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway();
Future<Acknowledge> stopResultFuture = FutureUtils.retry(new Callable<Future<Acknowledge>>() {
@Override
public Future<Acknowledge> call() throws Exception {
return taskManagerGateway.stopTask(attemptId, timeout);
}
}, NUM_STOP_CALL_TRIES, executor);
stopResultFuture.exceptionally(new ApplyFunction<Throwable, Void>() {
@Override
public Void apply(Throwable failure) {
LOG.info("Stopping task was not successful.", failure);
return null;
}
});
}
}
use of org.apache.flink.runtime.instance.SimpleSlot in project flink by apache.
the class Execution method sendCancelRpcCall.
/**
* This method sends a CancelTask message to the instance of the assigned slot.
*
* The sending is tried up to NUM_CANCEL_CALL_TRIES times.
*/
private void sendCancelRpcCall() {
final SimpleSlot slot = assignedResource;
if (slot != null) {
final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway();
Future<Acknowledge> cancelResultFuture = FutureUtils.retry(new Callable<Future<Acknowledge>>() {
@Override
public Future<Acknowledge> call() throws Exception {
return taskManagerGateway.cancelTask(attemptId, timeout);
}
}, NUM_CANCEL_CALL_TRIES, executor);
cancelResultFuture.exceptionallyAsync(new ApplyFunction<Throwable, Void>() {
@Override
public Void apply(Throwable failure) {
fail(new Exception("Task could not be canceled.", failure));
return null;
}
}, executor);
}
}
Aggregations