Search in sources :

Example 41 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class XaFacadeImpl method endAndPrepare.

@Override
public void endAndPrepare(Xid xid) {
    execute(Command.fromRunnable("end", xid, () -> xaResource.end(xid, XAResource.TMSUCCESS)));
    int prepResult = execute(new Command<>("prepare", of(xid), () -> xaResource.prepare(xid)));
    if (prepResult == XAResource.XA_RDONLY) {
        throw new EmptyXaTransactionException(xid);
    } else if (prepResult != XAResource.XA_OK) {
        throw new FlinkRuntimeException(formatErrorMessage("prepare", of(xid), empty(), "response: " + prepResult));
    }
}
Also used : FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException)

Example 42 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class DriverBaseITCase method getSystemOutput.

/**
 * Capture the command-line standard output from the driver execution.
 *
 * @param args driver command-line arguments
 * @return standard output from driver execution
 * @throws Exception on error
 */
private String getSystemOutput(String[] args) throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    // Configure object reuse mode
    switch(mode) {
        case CLUSTER:
        case COLLECTION:
            args = ArrayUtils.add(args, "--__disable_object_reuse");
            break;
        case CLUSTER_OBJECT_REUSE:
            // object reuse is enabled by default when executing drivers
            break;
        default:
            throw new FlinkRuntimeException("Unknown execution mode " + mode);
    }
    // Redirect stdout
    PrintStream stdout = System.out;
    System.setOut(new PrintStream(output));
    Runner.main(args);
    // Restore stdout
    System.setOut(stdout);
    return output.toString();
}
Also used : PrintStream(java.io.PrintStream) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 43 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class DefaultDispatcherGatewayServiceFactory method create.

@Override
public AbstractDispatcherLeaderProcess.DispatcherGatewayService create(DispatcherId fencingToken, Collection<JobGraph> recoveredJobs, Collection<JobResult> recoveredDirtyJobResults, JobGraphWriter jobGraphWriter, JobResultStore jobResultStore) {
    final Dispatcher dispatcher;
    try {
        dispatcher = dispatcherFactory.createDispatcher(rpcService, fencingToken, recoveredJobs, recoveredDirtyJobResults, (dispatcherGateway, scheduledExecutor, errorHandler) -> new NoOpDispatcherBootstrap(), PartialDispatcherServicesWithJobPersistenceComponents.from(partialDispatcherServices, jobGraphWriter, jobResultStore));
    } catch (Exception e) {
        throw new FlinkRuntimeException("Could not create the Dispatcher rpc endpoint.", e);
    }
    dispatcher.start();
    return DefaultDispatcherGatewayService.from(dispatcher);
}
Also used : DispatcherId(org.apache.flink.runtime.dispatcher.DispatcherId) Dispatcher(org.apache.flink.runtime.dispatcher.Dispatcher) PartialDispatcherServices(org.apache.flink.runtime.dispatcher.PartialDispatcherServices) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) PartialDispatcherServicesWithJobPersistenceComponents(org.apache.flink.runtime.dispatcher.PartialDispatcherServicesWithJobPersistenceComponents) Collection(java.util.Collection) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobResult(org.apache.flink.runtime.jobmaster.JobResult) RpcService(org.apache.flink.runtime.rpc.RpcService) NoOpDispatcherBootstrap(org.apache.flink.runtime.dispatcher.NoOpDispatcherBootstrap) DispatcherFactory(org.apache.flink.runtime.dispatcher.DispatcherFactory) JobResultStore(org.apache.flink.runtime.highavailability.JobResultStore) JobGraphWriter(org.apache.flink.runtime.jobmanager.JobGraphWriter) NoOpDispatcherBootstrap(org.apache.flink.runtime.dispatcher.NoOpDispatcherBootstrap) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Dispatcher(org.apache.flink.runtime.dispatcher.Dispatcher) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException)

Example 44 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class SubtaskGatewayImpl method sendEvent.

@Override
public CompletableFuture<Acknowledge> sendEvent(OperatorEvent evt) {
    if (!isReady()) {
        throw new FlinkRuntimeException("SubtaskGateway is not ready, task not yet running.");
    }
    final SerializedValue<OperatorEvent> serializedEvent;
    try {
        serializedEvent = new SerializedValue<>(evt);
    } catch (IOException e) {
        // unchecked so that it can bubble up
        throw new FlinkRuntimeException("Cannot serialize operator event", e);
    }
    final Callable<CompletableFuture<Acknowledge>> sendAction = subtaskAccess.createEventSendAction(serializedEvent);
    final CompletableFuture<Acknowledge> sendResult = new CompletableFuture<>();
    final CompletableFuture<Acknowledge> result = sendResult.whenCompleteAsync((success, failure) -> {
        if (failure != null && subtaskAccess.isStillRunning()) {
            String msg = String.format(EVENT_LOSS_ERROR_MESSAGE, evt, subtaskAccess.subtaskName());
            Runnables.assertNoException(() -> subtaskAccess.triggerTaskFailover(new FlinkException(msg, failure)));
        }
    }, sendingExecutor);
    sendingExecutor.execute(() -> {
        sender.sendEvent(sendAction, sendResult);
        incompleteFuturesTracker.trackFutureWhileIncomplete(result);
    });
    return result;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) IOException(java.io.IOException) FlinkException(org.apache.flink.util.FlinkException)

Example 45 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class JobMasterServiceLeadershipRunnerTest method testJobMasterServiceProcessCreationFailureIsForwardedToResultFuture.

@Test
public void testJobMasterServiceProcessCreationFailureIsForwardedToResultFuture() throws Exception {
    final FlinkRuntimeException testException = new FlinkRuntimeException("Test exception");
    final JobMasterServiceLeadershipRunner jobManagerRunner = newJobMasterServiceLeadershipRunnerBuilder().setJobMasterServiceProcessFactory(TestingJobMasterServiceProcessFactory.newBuilder().setJobMasterServiceProcessFunction(ignored -> {
        throw testException;
    }).build()).build();
    jobManagerRunner.start();
    leaderElectionService.isLeader(UUID.randomUUID());
    assertThat(jobManagerRunner.getResultFuture(), FlinkMatchers.futureWillCompleteExceptionally(cause -> ExceptionUtils.findThrowable(cause, testException::equals).isPresent(), Duration.ofMillis(5L), "Result future should be completed exceptionally."));
}
Also used : Arrays(java.util.Arrays) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) TimeoutException(java.util.concurrent.TimeoutException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) Assert.assertThat(org.junit.Assert.assertThat) TestingFatalErrorHandler(org.apache.flink.runtime.util.TestingFatalErrorHandler) After(org.junit.After) Duration(java.time.Duration) TestLogger(org.apache.flink.util.TestLogger) TestingJobMasterGatewayBuilder(org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGatewayBuilder) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) FlinkMatchers.containsCause(org.apache.flink.core.testutils.FlinkMatchers.containsCause) UUID(java.util.UUID) Preconditions(org.apache.flink.util.Preconditions) Acknowledge(org.apache.flink.runtime.messages.Acknowledge) TestingJobMasterServiceProcessFactory(org.apache.flink.runtime.jobmaster.factories.TestingJobMasterServiceProcessFactory) TestingJobResultStore(org.apache.flink.runtime.testutils.TestingJobResultStore) Matchers.is(org.hamcrest.Matchers.is) JobResultStore(org.apache.flink.runtime.highavailability.JobResultStore) Queue(java.util.Queue) Time(org.apache.flink.api.common.time.Time) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) FlinkException(org.apache.flink.util.FlinkException) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) BeforeClass(org.junit.BeforeClass) FlinkMatchers(org.apache.flink.core.testutils.FlinkMatchers) EmbeddedJobResultStore(org.apache.flink.runtime.highavailability.nonha.embedded.EmbeddedJobResultStore) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) JobStatus(org.apache.flink.api.common.JobStatus) LibraryCacheManager(org.apache.flink.runtime.execution.librarycache.LibraryCacheManager) TestingClassLoaderLease(org.apache.flink.runtime.execution.librarycache.TestingClassLoaderLease) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) Nonnull(javax.annotation.Nonnull) Before(org.junit.Before) ArchivedExecutionGraph(org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph) FlinkMatchers.willNotComplete(org.apache.flink.core.testutils.FlinkMatchers.willNotComplete) TestingLeaderElectionService(org.apache.flink.runtime.leaderelection.TestingLeaderElectionService) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) JobMasterServiceProcessFactory(org.apache.flink.runtime.jobmaster.factories.JobMasterServiceProcessFactory) ApplicationStatus(org.apache.flink.runtime.clusterframework.ApplicationStatus) FlinkMatchers.containsMessage(org.apache.flink.core.testutils.FlinkMatchers.containsMessage) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ExecutionGraphInfo(org.apache.flink.runtime.scheduler.ExecutionGraphInfo) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) JobResultEntry(org.apache.flink.runtime.highavailability.JobResultEntry) JobID(org.apache.flink.api.common.JobID) ArrayDeque(java.util.ArrayDeque) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) NoOpInvokable(org.apache.flink.runtime.testtasks.NoOpInvokable) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Test(org.junit.Test)

Aggregations

FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)78 IOException (java.io.IOException)28 Test (org.junit.Test)13 JobID (org.apache.flink.api.common.JobID)10 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 ExecutionException (java.util.concurrent.ExecutionException)7 Nonnull (javax.annotation.Nonnull)7 Configuration (org.apache.flink.configuration.Configuration)6 Collectors (java.util.stream.Collectors)5 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)5 JobResultStore (org.apache.flink.runtime.highavailability.JobResultStore)4 RocksDBException (org.rocksdb.RocksDBException)4 List (java.util.List)3 Map (java.util.Map)3 CheckpointMetrics (org.apache.flink.runtime.checkpoint.CheckpointMetrics)3 TaskStateSnapshot (org.apache.flink.runtime.checkpoint.TaskStateSnapshot)3 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)3 JobResult (org.apache.flink.runtime.jobmaster.JobResult)3