Search in sources :

Example 1 with InputSplitProviderException

use of org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException in project flink by apache.

the class TaskInputSplitProvider method getNextInputSplit.

@Override
public InputSplit getNextInputSplit(ClassLoader userCodeClassLoader) throws InputSplitProviderException {
    Preconditions.checkNotNull(userCodeClassLoader);
    final Future<Object> response = jobManager.ask(new JobManagerMessages.RequestNextInputSplit(jobID, vertexID, executionID), timeout);
    final Object result;
    try {
        result = Await.result(response, timeout);
    } catch (Exception e) {
        throw new InputSplitProviderException("Did not receive next input split from JobManager.", e);
    }
    if (result instanceof JobManagerMessages.NextInputSplit) {
        final JobManagerMessages.NextInputSplit nextInputSplit = (JobManagerMessages.NextInputSplit) result;
        byte[] serializedData = nextInputSplit.splitData();
        if (serializedData == null) {
            return null;
        } else {
            final Object deserialized;
            try {
                deserialized = InstantiationUtil.deserializeObject(serializedData, userCodeClassLoader);
            } catch (Exception e) {
                throw new InputSplitProviderException("Could not deserialize the serialized input split.", e);
            }
            return (InputSplit) deserialized;
        }
    } else {
        throw new InputSplitProviderException("RequestNextInputSplit requires a response of type " + "NextInputSplit. Instead response is of type " + result.getClass() + '.');
    }
}
Also used : JobManagerMessages(org.apache.flink.runtime.messages.JobManagerMessages) InputSplitProviderException(org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException) InputSplit(org.apache.flink.core.io.InputSplit) InputSplitProviderException(org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException)

Example 2 with InputSplitProviderException

use of org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException in project flink by apache.

the class DataSourceTask method getInputSplits.

private Iterator<InputSplit> getInputSplits() {
    final InputSplitProvider provider = getEnvironment().getInputSplitProvider();
    return new Iterator<InputSplit>() {

        private InputSplit nextSplit;

        private boolean exhausted;

        @Override
        public boolean hasNext() {
            if (exhausted) {
                return false;
            }
            if (nextSplit != null) {
                return true;
            }
            final InputSplit split;
            try {
                split = provider.getNextInputSplit(getUserCodeClassLoader());
            } catch (InputSplitProviderException e) {
                throw new RuntimeException("Could not retrieve next input split.", e);
            }
            if (split != null) {
                this.nextSplit = split;
                return true;
            } else {
                exhausted = true;
                return false;
            }
        }

        @Override
        public InputSplit next() {
            if (this.nextSplit == null && !hasNext()) {
                throw new NoSuchElementException();
            }
            final InputSplit tmp = this.nextSplit;
            this.nextSplit = null;
            return tmp;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : Iterator(java.util.Iterator) InputSplitProviderException(org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException) InputSplitProvider(org.apache.flink.runtime.jobgraph.tasks.InputSplitProvider) InputSplit(org.apache.flink.core.io.InputSplit) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with InputSplitProviderException

use of org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException in project flink by apache.

the class InputFormatSourceFunction method getInputSplits.

private Iterator<InputSplit> getInputSplits() {
    return new Iterator<InputSplit>() {

        private InputSplit nextSplit;

        private boolean exhausted;

        @Override
        public boolean hasNext() {
            if (exhausted) {
                return false;
            }
            if (nextSplit != null) {
                return true;
            }
            final InputSplit split;
            try {
                split = provider.getNextInputSplit(getRuntimeContext().getUserCodeClassLoader());
            } catch (InputSplitProviderException e) {
                throw new RuntimeException("Could not retrieve next input split.", e);
            }
            if (split != null) {
                this.nextSplit = split;
                return true;
            } else {
                exhausted = true;
                return false;
            }
        }

        @Override
        public InputSplit next() {
            if (this.nextSplit == null && !hasNext()) {
                throw new NoSuchElementException();
            }
            final InputSplit tmp = this.nextSplit;
            this.nextSplit = null;
            return tmp;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : Iterator(java.util.Iterator) InputSplitProviderException(org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException) InputSplit(org.apache.flink.core.io.InputSplit) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with InputSplitProviderException

use of org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException in project flink by apache.

the class RpcInputSplitProvider method getNextInputSplit.

@Override
public InputSplit getNextInputSplit(ClassLoader userCodeClassLoader) throws InputSplitProviderException {
    Preconditions.checkNotNull(userCodeClassLoader);
    Future<SerializedInputSplit> futureInputSplit = jobMasterGateway.requestNextInputSplit(jobMasterLeaderId, jobVertexID, executionAttemptID);
    try {
        SerializedInputSplit serializedInputSplit = futureInputSplit.get(timeout.getSize(), timeout.getUnit());
        if (serializedInputSplit.isEmpty()) {
            return null;
        } else {
            return InstantiationUtil.deserializeObject(serializedInputSplit.getInputSplitData(), userCodeClassLoader);
        }
    } catch (Exception e) {
        throw new InputSplitProviderException("Requesting the next input split failed.", e);
    }
}
Also used : SerializedInputSplit(org.apache.flink.runtime.jobmaster.SerializedInputSplit) InputSplitProviderException(org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException) InputSplitProviderException(org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException)

Aggregations

InputSplitProviderException (org.apache.flink.runtime.jobgraph.tasks.InputSplitProviderException)4 InputSplit (org.apache.flink.core.io.InputSplit)3 Iterator (java.util.Iterator)2 NoSuchElementException (java.util.NoSuchElementException)2 InputSplitProvider (org.apache.flink.runtime.jobgraph.tasks.InputSplitProvider)1 SerializedInputSplit (org.apache.flink.runtime.jobmaster.SerializedInputSplit)1 JobManagerMessages (org.apache.flink.runtime.messages.JobManagerMessages)1