Search in sources :

Example 66 with FlinkException

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

the class Task method deliverOperatorEvent.

/**
 * Dispatches an operator event to the invokable task.
 *
 * <p>If the event delivery did not succeed, this method throws an exception. Callers can use
 * that exception for error reporting, but need not react with failing this task (this method
 * takes care of that).
 *
 * @throws FlinkException This method throws exceptions indicating the reason why delivery did
 *     not succeed.
 */
public void deliverOperatorEvent(OperatorID operator, SerializedValue<OperatorEvent> evt) throws FlinkException {
    final TaskInvokable invokable = this.invokable;
    final ExecutionState currentState = this.executionState;
    if (invokable == null || (currentState != ExecutionState.RUNNING && currentState != ExecutionState.INITIALIZING)) {
        throw new TaskNotRunningException("Task is not running, but in state " + currentState);
    }
    if (invokable instanceof CoordinatedTask) {
        try {
            ((CoordinatedTask) invokable).dispatchOperatorEvent(operator, evt);
        } catch (Throwable t) {
            ExceptionUtils.rethrowIfFatalErrorOrOOM(t);
            if (getExecutionState() == ExecutionState.RUNNING || getExecutionState() == ExecutionState.INITIALIZING) {
                FlinkException e = new FlinkException("Error while handling operator event", t);
                failExternally(e);
                throw e;
            }
        }
    }
}
Also used : ExecutionState(org.apache.flink.runtime.execution.ExecutionState) TaskNotRunningException(org.apache.flink.runtime.operators.coordination.TaskNotRunningException) CoordinatedTask(org.apache.flink.runtime.jobgraph.tasks.CoordinatedTask) TaskInvokable(org.apache.flink.runtime.jobgraph.tasks.TaskInvokable) FlinkException(org.apache.flink.util.FlinkException)

Example 67 with FlinkException

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

the class FailureHandlingResultSnapshotTest method testGlobalFailureHandlingResultSnapshotCreation.

@Test
public void testGlobalFailureHandlingResultSnapshotCreation() {
    final Throwable rootCause = new FlinkException("Expected exception: root cause");
    final long timestamp = System.currentTimeMillis();
    final ExecutionVertex failedExecutionVertex0 = extractExecutionVertex(0);
    final Throwable failure0 = new RuntimeException("Expected exception: failure #0");
    final ExecutionVertex failedExecutionVertex1 = extractExecutionVertex(1);
    final Throwable failure1 = new IllegalStateException("Expected exception: failure #1");
    triggerFailure(failedExecutionVertex0, failure0);
    triggerFailure(failedExecutionVertex1, failure1);
    final FailureHandlingResult failureHandlingResult = FailureHandlingResult.restartable(null, rootCause, timestamp, StreamSupport.stream(executionGraph.getAllExecutionVertices().spliterator(), false).map(ExecutionVertex::getID).collect(Collectors.toSet()), 0L, true);
    final FailureHandlingResultSnapshot testInstance = FailureHandlingResultSnapshot.create(failureHandlingResult, this::getLatestExecution);
    assertThat(testInstance.getRootCause(), is(rootCause));
    assertThat(testInstance.getTimestamp(), is(timestamp));
    assertThat(testInstance.getRootCauseExecution().isPresent(), is(false));
    assertThat(testInstance.getConcurrentlyFailedExecution(), IsIterableContainingInAnyOrder.containsInAnyOrder(failedExecutionVertex0.getCurrentExecutionAttempt(), failedExecutionVertex1.getCurrentExecutionAttempt()));
}
Also used : FailureHandlingResult(org.apache.flink.runtime.executiongraph.failover.flip1.FailureHandlingResult) SerializedThrowable(org.apache.flink.util.SerializedThrowable) FlinkException(org.apache.flink.util.FlinkException) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) Test(org.junit.Test)

Example 68 with FlinkException

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

the class YarnClusterDescriptor method killCluster.

@Override
public void killCluster(ApplicationId applicationId) throws FlinkException {
    try {
        yarnClient.killApplication(applicationId);
        try (final FileSystem fs = FileSystem.get(yarnConfiguration)) {
            final Path applicationDir = YarnApplicationFileUploader.getApplicationDirPath(getStagingDir(fs), applicationId);
            Utils.deleteApplicationFiles(applicationDir.toUri().toString());
        }
    } catch (YarnException | IOException e) {
        throw new FlinkException("Could not kill the Yarn Flink cluster with id " + applicationId + '.', e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) FlinkException(org.apache.flink.util.FlinkException)

Example 69 with FlinkException

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

the class YarnLocalResourceDescriptor method fromString.

static YarnLocalResourceDescriptor fromString(String desc) throws Exception {
    Matcher m = LOCAL_RESOURCE_DESC_FORMAT.matcher(desc);
    boolean mat = m.find();
    if (mat) {
        return new YarnLocalResourceDescriptor(m.group(1), new Path(m.group(2)), Long.parseLong(m.group(3)), Long.parseLong(m.group(4)), LocalResourceVisibility.valueOf(m.group(5)), LocalResourceType.valueOf(m.group(6)));
    } else {
        throw new FlinkException("Error to parse YarnLocalResourceDescriptor from " + desc);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Matcher(java.util.regex.Matcher) FlinkException(org.apache.flink.util.FlinkException)

Example 70 with FlinkException

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

the class FlinkYarnSessionCli method run.

public int run(String[] args) throws CliArgsException, FlinkException {
    // 
    // Command Line Options
    // 
    final CommandLine cmd = parseCommandLineOptions(args, true);
    if (cmd.hasOption(help.getOpt())) {
        printUsage();
        return 0;
    }
    final Configuration effectiveConfiguration = new Configuration(configuration);
    final Configuration commandLineConfiguration = toConfiguration(cmd);
    effectiveConfiguration.addAll(commandLineConfiguration);
    LOG.debug("Effective configuration: {}", effectiveConfiguration);
    final ClusterClientFactory<ApplicationId> yarnClusterClientFactory = clusterClientServiceLoader.getClusterClientFactory(effectiveConfiguration);
    effectiveConfiguration.set(DeploymentOptions.TARGET, YarnDeploymentTarget.SESSION.getName());
    final YarnClusterDescriptor yarnClusterDescriptor = (YarnClusterDescriptor) yarnClusterClientFactory.createClusterDescriptor(effectiveConfiguration);
    try {
        // Query cluster for metrics
        if (cmd.hasOption(query.getOpt())) {
            final String description = yarnClusterDescriptor.getClusterDescription();
            System.out.println(description);
            return 0;
        } else {
            final ClusterClientProvider<ApplicationId> clusterClientProvider;
            final ApplicationId yarnApplicationId;
            if (cmd.hasOption(applicationId.getOpt())) {
                yarnApplicationId = ConverterUtils.toApplicationId(cmd.getOptionValue(applicationId.getOpt()));
                clusterClientProvider = yarnClusterDescriptor.retrieve(yarnApplicationId);
            } else {
                final ClusterSpecification clusterSpecification = yarnClusterClientFactory.getClusterSpecification(effectiveConfiguration);
                clusterClientProvider = yarnClusterDescriptor.deploySessionCluster(clusterSpecification);
                ClusterClient<ApplicationId> clusterClient = clusterClientProvider.getClusterClient();
                // ------------------ ClusterClient deployed, handle connection details
                yarnApplicationId = clusterClient.getClusterId();
                try {
                    System.out.println("JobManager Web Interface: " + clusterClient.getWebInterfaceURL());
                    writeYarnPropertiesFile(yarnApplicationId, dynamicPropertiesEncoded);
                } catch (Exception e) {
                    try {
                        clusterClient.close();
                    } catch (Exception ex) {
                        LOG.info("Could not properly shutdown cluster client.", ex);
                    }
                    try {
                        yarnClusterDescriptor.killCluster(yarnApplicationId);
                    } catch (FlinkException fe) {
                        LOG.info("Could not properly terminate the Flink cluster.", fe);
                    }
                    throw new FlinkException("Could not write the Yarn connection information.", e);
                }
            }
            if (!effectiveConfiguration.getBoolean(DeploymentOptions.ATTACHED)) {
                YarnClusterDescriptor.logDetachedClusterInformation(yarnApplicationId, LOG);
            } else {
                ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
                final YarnApplicationStatusMonitor yarnApplicationStatusMonitor = new YarnApplicationStatusMonitor(yarnClusterDescriptor.getYarnClient(), yarnApplicationId, new ScheduledExecutorServiceAdapter(scheduledExecutorService));
                Thread shutdownHook = ShutdownHookUtil.addShutdownHook(() -> shutdownCluster(clusterClientProvider.getClusterClient(), scheduledExecutorService, yarnApplicationStatusMonitor), getClass().getSimpleName(), LOG);
                try {
                    runInteractiveCli(yarnApplicationStatusMonitor, acceptInteractiveInput);
                } finally {
                    shutdownCluster(clusterClientProvider.getClusterClient(), scheduledExecutorService, yarnApplicationStatusMonitor);
                    if (shutdownHook != null) {
                        // we do not need the hook anymore as we have just tried to shutdown the
                        // cluster.
                        ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);
                    }
                    tryRetrieveAndLogApplicationReport(yarnClusterDescriptor.getYarnClient(), yarnApplicationId);
                }
            }
        }
    } finally {
        try {
            yarnClusterDescriptor.close();
        } catch (Exception e) {
            LOG.info("Could not properly close the yarn cluster descriptor.", e);
        }
    }
    return 0;
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SecurityConfiguration(org.apache.flink.runtime.security.SecurityConfiguration) Configuration(org.apache.flink.configuration.Configuration) GlobalConfiguration(org.apache.flink.configuration.GlobalConfiguration) ClusterSpecification(org.apache.flink.client.deployment.ClusterSpecification) FlinkException(org.apache.flink.util.FlinkException) CliArgsException(org.apache.flink.client.cli.CliArgsException) ConfigurationException(org.apache.flink.util.ConfigurationException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) FlinkException(org.apache.flink.util.FlinkException) CommandLine(org.apache.commons.cli.CommandLine) ScheduledExecutorServiceAdapter(org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) YarnClusterDescriptor(org.apache.flink.yarn.YarnClusterDescriptor)

Aggregations

FlinkException (org.apache.flink.util.FlinkException)197 Test (org.junit.Test)91 CompletableFuture (java.util.concurrent.CompletableFuture)59 IOException (java.io.IOException)38 ExecutionException (java.util.concurrent.ExecutionException)26 ArrayList (java.util.ArrayList)25 JobID (org.apache.flink.api.common.JobID)24 Collection (java.util.Collection)22 CompletionException (java.util.concurrent.CompletionException)22 Configuration (org.apache.flink.configuration.Configuration)21 TimeoutException (java.util.concurrent.TimeoutException)19 FutureUtils (org.apache.flink.util.concurrent.FutureUtils)19 Time (org.apache.flink.api.common.time.Time)16 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)16 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)16 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)15 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)14 Collections (java.util.Collections)13 List (java.util.List)13 ExecutorService (java.util.concurrent.ExecutorService)13