final ExecutionVertex targetVertex = edge.getSource().getProducer();
final ExecutionState executionState = targetVertex.getExecutionState();
// common case - found task running
if (executionState == ExecutionState.RUNNING) {
Instance location = targetVertex.getCurrentAssignedResource().getInstance();
if (location.getInstanceConnectionInfo().equals(caller)) {
// Receiver runs on the same task manager
return ConnectionInfoLookupResponse.createReceiverFoundAndReady(edge.getOutputChannelId());
}
else {
// Receiver runs on a different task manager
final InstanceConnectionInfo ici = location.getInstanceConnectionInfo();
final InetSocketAddress isa = new InetSocketAddress(ici.address(), ici.dataPort());
int connectionIdx = edge.getSource().getIntermediateResult().getConnectionIndex();
return ConnectionInfoLookupResponse.createReceiverFoundAndReady(new RemoteReceiver(isa, connectionIdx));
}
}
else if (executionState == ExecutionState.FINISHED) {
// that should not happen. if there is data pending, the sender cannot yet be done
// we need to fail the whole affair
LOG.error("Receiver " + targetVertex + " set to FINISHED even though data is pending");
fail(new Exception("Channels are not correctly registered"));
return ConnectionInfoLookupResponse.createReceiverNotFound();
}
else if (executionState == ExecutionState.FAILED || executionState == ExecutionState.CANCELED ||
executionState == ExecutionState.CANCELING)
{
return ConnectionInfoLookupResponse.createJobIsAborting();
}
else {
// all other states should not be, because the sender cannot be in CREATED, SCHEDULED, or DEPLOYING
// state when the receiver is already running
LOG.error("Channel lookup (backwards) - sender " + targetVertex + " found in inconsistent state " + executionState);
fail(new Exception("Channels are not correctly registered"));
return ConnectionInfoLookupResponse.createReceiverNotFound();
}
}
// ----- Request was sent from an output channel (sender side), requesting the input channel (receiver side) ------
// ----- This is the case for forward data ------
final ExecutionVertex targetVertex = edge.getTarget();
final ExecutionState executionState = targetVertex.getExecutionState();
if (executionState == ExecutionState.RUNNING) {
// already online
Instance location = targetVertex.getCurrentAssignedResource().getInstance();
if (location.getInstanceConnectionInfo().equals(caller)) {
// Receiver runs on the same task manager
return ConnectionInfoLookupResponse.createReceiverFoundAndReady(edge.getInputChannelId());
}
else {
// Receiver runs on a different task manager
final InstanceConnectionInfo ici = location.getInstanceConnectionInfo();
final InetSocketAddress isa = new InetSocketAddress(ici.address(), ici.dataPort());
final int connectionIdx = edge.getSource().getIntermediateResult().getConnectionIndex();
return ConnectionInfoLookupResponse.createReceiverFoundAndReady(new RemoteReceiver(isa, connectionIdx));
}