Search in sources :

Example 36 with FlinkException

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

the class CliFrontend method cancel.

/**
 * Executes the CANCEL action.
 *
 * @param args Command line arguments for the cancel action.
 */
protected void cancel(String[] args) throws Exception {
    LOG.info("Running 'cancel' command.");
    final Options commandOptions = CliFrontendParser.getCancelCommandOptions();
    final CommandLine commandLine = getCommandLine(commandOptions, args, false);
    CancelOptions cancelOptions = new CancelOptions(commandLine);
    // evaluate help flag
    if (cancelOptions.isPrintHelp()) {
        CliFrontendParser.printHelpForCancel(customCommandLines);
        return;
    }
    final CustomCommandLine activeCommandLine = validateAndGetActiveCommandLine(commandLine);
    final String[] cleanedArgs = cancelOptions.getArgs();
    if (cancelOptions.isWithSavepoint()) {
        logAndSysout("DEPRECATION WARNING: Cancelling a job with savepoint is deprecated. Use \"stop\" instead.");
        final JobID jobId;
        final String targetDirectory;
        if (cleanedArgs.length > 0) {
            jobId = parseJobId(cleanedArgs[0]);
            targetDirectory = cancelOptions.getSavepointTargetDirectory();
        } else {
            jobId = parseJobId(cancelOptions.getSavepointTargetDirectory());
            targetDirectory = null;
        }
        final SavepointFormatType formatType = cancelOptions.getFormatType();
        if (targetDirectory == null) {
            logAndSysout("Cancelling job " + jobId + " with " + formatType + " savepoint to default savepoint directory.");
        } else {
            logAndSysout("Cancelling job " + jobId + " with " + formatType + " savepoint to " + targetDirectory + '.');
        }
        runClusterAction(activeCommandLine, commandLine, clusterClient -> {
            final String savepointPath;
            try {
                savepointPath = clusterClient.cancelWithSavepoint(jobId, targetDirectory, formatType).get(clientTimeout.toMillis(), TimeUnit.MILLISECONDS);
            } catch (Exception e) {
                throw new FlinkException("Could not cancel job " + jobId + '.', e);
            }
            logAndSysout("Cancelled job " + jobId + ". Savepoint stored in " + savepointPath + '.');
        });
    } else {
        final JobID jobId;
        if (cleanedArgs.length > 0) {
            jobId = parseJobId(cleanedArgs[0]);
        } else {
            throw new CliArgsException("Missing JobID. Specify a JobID to cancel a job.");
        }
        logAndSysout("Cancelling job " + jobId + '.');
        runClusterAction(activeCommandLine, commandLine, clusterClient -> {
            try {
                clusterClient.cancel(jobId).get(clientTimeout.toMillis(), TimeUnit.MILLISECONDS);
            } catch (Exception e) {
                throw new FlinkException("Could not cancel job " + jobId + '.', e);
            }
        });
        logAndSysout("Cancelled job " + jobId + '.');
    }
}
Also used : JobManagerOptions(org.apache.flink.configuration.JobManagerOptions) Options(org.apache.commons.cli.Options) RestOptions(org.apache.flink.configuration.RestOptions) CoreOptions(org.apache.flink.configuration.CoreOptions) CommandLine(org.apache.commons.cli.CommandLine) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) JobID(org.apache.flink.api.common.JobID) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ProgramMissingJobException(org.apache.flink.client.program.ProgramMissingJobException) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) ProgramParametrizationException(org.apache.flink.client.program.ProgramParametrizationException) FileNotFoundException(java.io.FileNotFoundException) FlinkException(org.apache.flink.util.FlinkException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) FlinkException(org.apache.flink.util.FlinkException)

Example 37 with FlinkException

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

the class CliFrontend method runClusterAction.

/**
 * Retrieves the {@link ClusterClient} from the given {@link CustomCommandLine} and runs the
 * given {@link ClusterAction} against it.
 *
 * @param activeCommandLine to create the {@link ClusterDescriptor} from
 * @param commandLine containing the parsed command line options
 * @param clusterAction the cluster action to run against the retrieved {@link ClusterClient}.
 * @param <ClusterID> type of the cluster id
 * @throws FlinkException if something goes wrong
 */
private <ClusterID> void runClusterAction(CustomCommandLine activeCommandLine, CommandLine commandLine, ClusterAction<ClusterID> clusterAction) throws FlinkException {
    final Configuration effectiveConfiguration = getEffectiveConfiguration(activeCommandLine, commandLine);
    LOG.debug("Effective configuration after Flink conf, and custom commandline: {}", effectiveConfiguration);
    final ClusterClientFactory<ClusterID> clusterClientFactory = clusterClientServiceLoader.getClusterClientFactory(effectiveConfiguration);
    final ClusterID clusterId = clusterClientFactory.getClusterId(effectiveConfiguration);
    if (clusterId == null) {
        throw new FlinkException("No cluster id was specified. Please specify a cluster to which you would like to connect.");
    }
    try (final ClusterDescriptor<ClusterID> clusterDescriptor = clusterClientFactory.createClusterDescriptor(effectiveConfiguration)) {
        try (final ClusterClient<ClusterID> clusterClient = clusterDescriptor.retrieve(clusterId).getClusterClient()) {
            clusterAction.runAction(clusterClient);
        }
    }
}
Also used : ApplicationConfiguration(org.apache.flink.client.deployment.application.ApplicationConfiguration) SecurityConfiguration(org.apache.flink.runtime.security.SecurityConfiguration) Configuration(org.apache.flink.configuration.Configuration) GlobalConfiguration(org.apache.flink.configuration.GlobalConfiguration) FlinkException(org.apache.flink.util.FlinkException)

Example 38 with FlinkException

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

the class EmbeddedExecutor method submitJob.

private static CompletableFuture<JobID> submitJob(final Configuration configuration, final DispatcherGateway dispatcherGateway, final JobGraph jobGraph, final Time rpcTimeout) {
    checkNotNull(jobGraph);
    LOG.info("Submitting Job with JobId={}.", jobGraph.getJobID());
    return dispatcherGateway.getBlobServerPort(rpcTimeout).thenApply(blobServerPort -> new InetSocketAddress(dispatcherGateway.getHostname(), blobServerPort)).thenCompose(blobServerAddress -> {
        try {
            ClientUtils.extractAndUploadJobGraphFiles(jobGraph, () -> new BlobClient(blobServerAddress, configuration));
        } catch (FlinkException e) {
            throw new CompletionException(e);
        }
        return dispatcherGateway.submitJob(jobGraph, rpcTimeout);
    }).thenApply(ack -> jobGraph.getJobID());
}
Also used : FlinkException(org.apache.flink.util.FlinkException) PipelineExecutorUtils(org.apache.flink.client.deployment.executors.PipelineExecutorUtils) Pipeline(org.apache.flink.api.dag.Pipeline) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) DispatcherGateway(org.apache.flink.runtime.dispatcher.DispatcherGateway) PipelineExecutor(org.apache.flink.core.execution.PipelineExecutor) PipelineOptionsInternal(org.apache.flink.configuration.PipelineOptionsInternal) FunctionUtils(org.apache.flink.util.function.FunctionUtils) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) ClientOptions(org.apache.flink.client.cli.ClientOptions) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Collection(java.util.Collection) Configuration(org.apache.flink.configuration.Configuration) CompletionException(java.util.concurrent.CompletionException) ClientUtils(org.apache.flink.runtime.client.ClientUtils) InetSocketAddress(java.net.InetSocketAddress) JobClient(org.apache.flink.core.execution.JobClient) JobID(org.apache.flink.api.common.JobID) Optional(java.util.Optional) Internal(org.apache.flink.annotation.Internal) BlobClient(org.apache.flink.runtime.blob.BlobClient) Time(org.apache.flink.api.common.time.Time) BlobClient(org.apache.flink.runtime.blob.BlobClient) InetSocketAddress(java.net.InetSocketAddress) CompletionException(java.util.concurrent.CompletionException) FlinkException(org.apache.flink.util.FlinkException)

Example 39 with FlinkException

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

the class CliFrontendSavepointTest method testTriggerSavepointFailure.

@Test
public void testTriggerSavepointFailure() throws Exception {
    replaceStdOutAndStdErr();
    JobID jobId = new JobID();
    String expectedTestException = "expectedTestException";
    Exception testException = new Exception(expectedTestException);
    final ClusterClient<String> clusterClient = createFailingClusterClient(testException);
    try {
        MockedCliFrontend frontend = new MockedCliFrontend(clusterClient);
        String[] parameters = { jobId.toString() };
        try {
            frontend.savepoint(parameters);
            fail("Savepoint should have failed.");
        } catch (FlinkException e) {
            assertTrue(ExceptionUtils.findThrowableWithMessage(e, expectedTestException).isPresent());
        }
    } finally {
        clusterClient.close();
        restoreStdOutAndStdErr();
    }
}
Also used : MockedCliFrontend(org.apache.flink.client.cli.util.MockedCliFrontend) JobID(org.apache.flink.api.common.JobID) FlinkException(org.apache.flink.util.FlinkException) FlinkException(org.apache.flink.util.FlinkException) Test(org.junit.Test)

Example 40 with FlinkException

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

the class DefaultOperatorCoordinatorHandler method deliverOperatorEventToCoordinator.

@Override
public void deliverOperatorEventToCoordinator(final ExecutionAttemptID taskExecutionId, final OperatorID operatorId, final OperatorEvent evt) throws FlinkException {
    // Failure semantics (as per the javadocs of the method):
    // If the task manager sends an event for a non-running task or an non-existing operator
    // coordinator, then respond with an exception to the call. If task and coordinator exist,
    // then we assume that the call from the TaskManager was valid, and any bubbling exception
    // needs to cause a job failure.
    final Execution exec = executionGraph.getRegisteredExecutions().get(taskExecutionId);
    if (exec == null || exec.getState() != ExecutionState.RUNNING && exec.getState() != ExecutionState.INITIALIZING) {
        // on the safe, we notify the TM that the event could not be delivered.
        throw new TaskNotRunningException("Task is not known or in state running on the JobManager.");
    }
    final OperatorCoordinatorHolder coordinator = coordinatorMap.get(operatorId);
    if (coordinator == null) {
        throw new FlinkException("No coordinator registered for operator " + operatorId);
    }
    try {
        coordinator.handleEventFromOperator(exec.getParallelSubtaskIndex(), evt);
    } catch (Throwable t) {
        ExceptionUtils.rethrowIfFatalErrorOrOOM(t);
        globalFailureHandler.handleGlobalFailure(t);
    }
}
Also used : Execution(org.apache.flink.runtime.executiongraph.Execution) TaskNotRunningException(org.apache.flink.runtime.operators.coordination.TaskNotRunningException) OperatorCoordinatorHolder(org.apache.flink.runtime.operators.coordination.OperatorCoordinatorHolder) FlinkException(org.apache.flink.util.FlinkException)

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