use of org.apache.flink.client.program.ClusterClient in project flink by apache.
the class JMXJobManagerMetricTest method testJobManagerJMXMetricAccess.
/**
* Tests that metrics registered on the JobManager are actually accessible via JMX.
*/
@Test
void testJobManagerJMXMetricAccess(@InjectClusterClient ClusterClient<?> client) throws Exception {
Deadline deadline = Deadline.now().plus(Duration.ofMinutes(2));
try {
JobVertex sourceJobVertex = new JobVertex("Source");
sourceJobVertex.setInvokableClass(BlockingInvokable.class);
sourceJobVertex.setParallelism(1);
final JobCheckpointingSettings jobCheckpointingSettings = new JobCheckpointingSettings(new CheckpointCoordinatorConfiguration(500, 500, 50, 5, CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION, true, false, 0, 0), null);
final JobGraph jobGraph = JobGraphBuilder.newStreamingJobGraphBuilder().setJobName("TestingJob").addJobVertex(sourceJobVertex).setJobCheckpointingSettings(jobCheckpointingSettings).build();
client.submitJob(jobGraph).get();
FutureUtils.retrySuccessfulWithDelay(() -> client.getJobStatus(jobGraph.getJobID()), Time.milliseconds(10), deadline, status -> status == JobStatus.RUNNING, TestingUtils.defaultScheduledExecutor()).get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS);
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> nameSet = mBeanServer.queryNames(new ObjectName("org.apache.flink.jobmanager.job.lastCheckpointSize:job_name=TestingJob,*"), null);
assertThat(nameSet).hasSize(1);
assertThat(mBeanServer.getAttribute(nameSet.iterator().next(), "Value")).isEqualTo(-1L);
BlockingInvokable.unblock();
} finally {
BlockingInvokable.unblock();
}
}
use of org.apache.flink.client.program.ClusterClient in project flink by apache.
the class SavepointITCase method testStopWithFailingSourceInOnePipeline.
/**
* FLINK-21030
*
* <p>Tests the handling of a failure that happened while stopping an embarrassingly parallel
* job with a Savepoint. The test expects that the stopping action fails and all executions are
* in state {@code RUNNING} afterwards.
*
* @param failingSource the failing {@link SourceFunction} used in one of the two pipelines.
* @param expectedMaximumNumberOfRestarts the maximum number of restarts allowed by the restart
* strategy.
* @param exceptionAssertion asserts the client-call exception to verify that the right error
* was handled.
* @see SavepointITCase#failingPipelineLatch The latch used to trigger the successful start of
* the later on failing pipeline.
* @see SavepointITCase#succeedingPipelineLatch The latch that triggers the successful start of
* the succeeding pipeline.
* @throws Exception if an error occurred while running the test.
*/
private static void testStopWithFailingSourceInOnePipeline(InfiniteTestSource failingSource, File savepointDir, int expectedMaximumNumberOfRestarts, BiFunction<JobID, ExecutionException, Boolean> exceptionAssertion) throws Exception {
MiniClusterWithClientResource cluster = new MiniClusterWithClientResource(new MiniClusterResourceConfiguration.Builder().build());
failingPipelineLatch = new OneShotLatch();
succeedingPipelineLatch = new OneShotLatch();
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1);
env.getConfig().setRestartStrategy(RestartStrategies.fixedDelayRestart(expectedMaximumNumberOfRestarts, 0));
env.addSource(failingSource).name("Failing Source").map(value -> {
failingPipelineLatch.trigger();
return value;
}).addSink(new DiscardingSink<>());
env.addSource(new InfiniteTestSource()).name("Succeeding Source").map(value -> {
succeedingPipelineLatch.trigger();
return value;
}).addSink(new DiscardingSink<>());
final JobGraph jobGraph = env.getStreamGraph().getJobGraph();
cluster.before();
try {
ClusterClient<?> client = cluster.getClusterClient();
JobID jobID = client.submitJob(jobGraph).get();
// we need to wait for both pipelines to be in state RUNNING because that's the only
// state which allows creating a savepoint
failingPipelineLatch.await();
succeedingPipelineLatch.await();
waitForAllTaskRunning(cluster.getMiniCluster(), jobID, false);
try {
client.stopWithSavepoint(jobGraph.getJobID(), false, savepointDir.getAbsolutePath(), SavepointFormatType.CANONICAL).get();
fail("The future should fail exceptionally.");
} catch (ExecutionException e) {
assertThrowable(e, ex -> exceptionAssertion.apply(jobGraph.getJobID(), e));
}
waitUntilAllTasksAreRunning(cluster.getRestClusterClient(), jobGraph.getJobID());
} finally {
cluster.after();
}
}
Aggregations