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;
}
}
}
}
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()));
}
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);
}
}
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);
}
}
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;
}
Aggregations