Java Code Examples for org.apache.flink.runtime.rest.messages.EmptyRequestBody#getInstance()

The following examples show how to use org.apache.flink.runtime.rest.messages.EmptyRequestBody#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobVertexBackPressureHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testAbsentBackPressure() throws Exception {
	final Map<String, String> pathParameters = new HashMap<>();
	pathParameters.put(JobIDPathParameter.KEY, TEST_JOB_ID_BACK_PRESSURE_STATS_ABSENT.toString());
	pathParameters.put(JobVertexIdPathParameter.KEY, new JobVertexID().toString());

	final HandlerRequest<EmptyRequestBody, JobVertexMessageParameters> request =
		new HandlerRequest<>(
			EmptyRequestBody.getInstance(),
			new JobVertexMessageParameters(), pathParameters, Collections.emptyMap());

	final CompletableFuture<JobVertexBackPressureInfo> jobVertexBackPressureInfoCompletableFuture =
		jobVertexBackPressureHandler.handleRequest(request, restfulGateway);
	final JobVertexBackPressureInfo jobVertexBackPressureInfo = jobVertexBackPressureInfoCompletableFuture.get();

	assertThat(jobVertexBackPressureInfo.getStatus(), equalTo(VertexBackPressureStatus.DEPRECATED));
}
 
Example 2
Source File: AggregatingMetricsHandlerTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testListMetrics() throws Exception {
	HandlerRequest<EmptyRequestBody, P> request = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		handler.getMessageHeaders().getUnresolvedMessageParameters(),
		pathParameters,
		Collections.emptyMap()
	);

	AggregatedMetricsResponseBody response = handler.handleRequest(request, MOCK_DISPATCHER_GATEWAY)
		.get();

	List<String> availableMetrics = response.getMetrics().stream()
		.map(AggregatedMetric::getId)
		.sorted()
		.collect(Collectors.toList());

	assertEquals(2, availableMetrics.size());
	assertEquals("abc.metric1", availableMetrics.get(0));
	assertEquals("abc.metric2", availableMetrics.get(1));
}
 
Example 3
Source File: AggregatingMetricsHandlerTestBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSumAggregation() throws Exception {
	Map<String, List<String>> queryParams = new HashMap<>(4);
	queryParams.put("get", Collections.singletonList("abc.metric1"));
	queryParams.put("agg", Collections.singletonList("sum"));

	HandlerRequest<EmptyRequestBody, P> request = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		handler.getMessageHeaders().getUnresolvedMessageParameters(),
		pathParameters,
		queryParams
	);

	AggregatedMetricsResponseBody response = handler.handleRequest(request, MOCK_DISPATCHER_GATEWAY)
		.get();

	Collection<AggregatedMetric> aggregatedMetrics = response.getMetrics();

	assertEquals(1, aggregatedMetrics.size());
	AggregatedMetric aggregatedMetric = aggregatedMetrics.iterator().next();

	assertEquals("abc.metric1", aggregatedMetric.getId());
	assertEquals(4.0, aggregatedMetric.getSum(), 0.1);
	assertNull(aggregatedMetric.getMin());
	assertNull(aggregatedMetric.getMax());
	assertNull(aggregatedMetric.getAvg());
}
 
Example 4
Source File: AbstractAsynchronousOperationHandlersTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static HandlerRequest<EmptyRequestBody, TriggerMessageParameters> statusOperationRequest(TriggerId triggerId) throws HandlerRequestException {
	return new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		new TriggerMessageParameters(),
		Collections.singletonMap(TriggerIdPathParameter.KEY, triggerId.toString()),
		Collections.emptyMap());
}
 
Example 5
Source File: AggregatingMetricsHandlerTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMinAggregation() throws Exception {
	Map<String, List<String>> queryParams = new HashMap<>(4);
	queryParams.put("get", Collections.singletonList("abc.metric1"));
	queryParams.put("agg", Collections.singletonList("min"));

	HandlerRequest<EmptyRequestBody, P> request = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		handler.getMessageHeaders().getUnresolvedMessageParameters(),
		pathParameters,
		queryParams
	);

	AggregatedMetricsResponseBody response = handler.handleRequest(request, MOCK_DISPATCHER_GATEWAY)
		.get();

	Collection<AggregatedMetric> aggregatedMetrics = response.getMetrics();

	assertEquals(1, aggregatedMetrics.size());
	AggregatedMetric aggregatedMetric = aggregatedMetrics.iterator().next();

	assertEquals("abc.metric1", aggregatedMetric.getId());
	assertEquals(1.0, aggregatedMetric.getMin(), 0.1);
	assertNull(aggregatedMetric.getMax());
	assertNull(aggregatedMetric.getSum());
	assertNull(aggregatedMetric.getAvg());
}
 
Example 6
Source File: JobVertexBackPressureHandlerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetBackPressure() throws Exception {
	final Map<String, String> pathParameters = new HashMap<>();
	pathParameters.put(JobIDPathParameter.KEY, TEST_JOB_ID_BACK_PRESSURE_STATS_AVAILABLE.toString());
	pathParameters.put(JobVertexIdPathParameter.KEY, new JobVertexID().toString());

	final HandlerRequest<EmptyRequestBody, JobVertexMessageParameters> request =
		new HandlerRequest<>(
			EmptyRequestBody.getInstance(),
			new JobVertexMessageParameters(), pathParameters, Collections.emptyMap());

	final CompletableFuture<JobVertexBackPressureInfo> jobVertexBackPressureInfoCompletableFuture =
		jobVertexBackPressureHandler.handleRequest(request, restfulGateway);
	final JobVertexBackPressureInfo jobVertexBackPressureInfo = jobVertexBackPressureInfoCompletableFuture.get();

	assertThat(jobVertexBackPressureInfo.getStatus(), equalTo(VertexBackPressureStatus.OK));
	assertThat(jobVertexBackPressureInfo.getBackpressureLevel(), equalTo(HIGH));

	assertThat(jobVertexBackPressureInfo.getSubtasks()
		.stream()
		.map(JobVertexBackPressureInfo.SubtaskBackPressureInfo::getRatio)
		.collect(Collectors.toList()), contains(1.0, 0.5, 0.1));

	assertThat(jobVertexBackPressureInfo.getSubtasks()
		.stream()
		.map(JobVertexBackPressureInfo.SubtaskBackPressureInfo::getBackpressureLevel)
		.collect(Collectors.toList()), contains(HIGH, LOW, OK));

	assertThat(jobVertexBackPressureInfo.getSubtasks()
		.stream()
		.map(JobVertexBackPressureInfo.SubtaskBackPressureInfo::getSubtask)
		.collect(Collectors.toList()), contains(0, 1, 2));
}
 
Example 7
Source File: AggregatingMetricsHandlerTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleAggregation() throws Exception {
	Map<String, List<String>> queryParams = new HashMap<>(4);
	queryParams.put("get", Collections.singletonList("abc.metric1"));
	queryParams.put("agg", Arrays.asList("min", "max", "avg"));

	HandlerRequest<EmptyRequestBody, P> request = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		handler.getMessageHeaders().getUnresolvedMessageParameters(),
		pathParameters,
		queryParams
	);

	AggregatedMetricsResponseBody response = handler.handleRequest(request, MOCK_DISPATCHER_GATEWAY)
		.get();

	Collection<AggregatedMetric> aggregatedMetrics = response.getMetrics();

	assertEquals(1, aggregatedMetrics.size());
	AggregatedMetric aggregatedMetric = aggregatedMetrics.iterator().next();

	assertEquals("abc.metric1", aggregatedMetric.getId());
	assertEquals(1.0, aggregatedMetric.getMin(), 0.1);
	assertEquals(3.0, aggregatedMetric.getMax(), 0.1);
	assertEquals(2.0, aggregatedMetric.getAvg(), 0.1);
	assertNull(aggregatedMetric.getSum());
}
 
Example 8
Source File: AggregatingMetricsHandlerTestBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleAggregation() throws Exception {
	Map<String, List<String>> queryParams = new HashMap<>(4);
	queryParams.put("get", Collections.singletonList("abc.metric1"));
	queryParams.put("agg", Arrays.asList("min", "max", "avg"));

	HandlerRequest<EmptyRequestBody, P> request = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		handler.getMessageHeaders().getUnresolvedMessageParameters(),
		pathParameters,
		queryParams
	);

	AggregatedMetricsResponseBody response = handler.handleRequest(request, MOCK_DISPATCHER_GATEWAY)
		.get();

	Collection<AggregatedMetric> aggregatedMetrics = response.getMetrics();

	assertEquals(1, aggregatedMetrics.size());
	AggregatedMetric aggregatedMetric = aggregatedMetrics.iterator().next();

	assertEquals("abc.metric1", aggregatedMetric.getId());
	assertEquals(1.0, aggregatedMetric.getMin(), 0.1);
	assertEquals(3.0, aggregatedMetric.getMax(), 0.1);
	assertEquals(2.0, aggregatedMetric.getAvg(), 0.1);
	assertNull(aggregatedMetric.getSum());
}
 
Example 9
Source File: AggregatingMetricsHandlerTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSumAggregation() throws Exception {
	Map<String, List<String>> queryParams = new HashMap<>(4);
	queryParams.put("get", Collections.singletonList("abc.metric1"));
	queryParams.put("agg", Collections.singletonList("sum"));

	HandlerRequest<EmptyRequestBody, P> request = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		handler.getMessageHeaders().getUnresolvedMessageParameters(),
		pathParameters,
		queryParams
	);

	AggregatedMetricsResponseBody response = handler.handleRequest(request, MOCK_DISPATCHER_GATEWAY)
		.get();

	Collection<AggregatedMetric> aggregatedMetrics = response.getMetrics();

	assertEquals(1, aggregatedMetrics.size());
	AggregatedMetric aggregatedMetric = aggregatedMetrics.iterator().next();

	assertEquals("abc.metric1", aggregatedMetric.getId());
	assertEquals(4.0, aggregatedMetric.getSum(), 0.1);
	assertNull(aggregatedMetric.getMin());
	assertNull(aggregatedMetric.getMax());
	assertNull(aggregatedMetric.getAvg());
}
 
Example 10
Source File: JarDeleteHandlerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static HandlerRequest<EmptyRequestBody, JarDeleteMessageParameters> createRequest(
		final String jarFileName) throws HandlerRequestException {
	return new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		new JarDeleteMessageParameters(),
		Collections.singletonMap(JarIdPathParameter.KEY, jarFileName),
		Collections.emptyMap());
}
 
Example 11
Source File: JobExecutionResultHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = TestingRestfulGateway.newBuilder().build();

	jobExecutionResultHandler = new JobExecutionResultHandler(
		() -> CompletableFuture.completedFuture(testingRestfulGateway),
		Time.seconds(10),
		Collections.emptyMap());

	testRequest = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		new JobMessageParameters(),
		Collections.singletonMap("jobid", TEST_JOB_ID.toString()),
		Collections.emptyMap());
}
 
Example 12
Source File: AbstractAsynchronousOperationHandlersTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static HandlerRequest<EmptyRequestBody, TriggerMessageParameters> statusOperationRequest(TriggerId triggerId) throws HandlerRequestException {
	return new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		new TriggerMessageParameters(),
		Collections.singletonMap(TriggerIdPathParameter.KEY, triggerId.toString()),
		Collections.emptyMap());
}
 
Example 13
Source File: JobExecutionResultHandlerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	final TestingRestfulGateway testingRestfulGateway = TestingRestfulGateway.newBuilder().build();

	jobExecutionResultHandler = new JobExecutionResultHandler(
		() -> CompletableFuture.completedFuture(testingRestfulGateway),
		Time.seconds(10),
		Collections.emptyMap());

	testRequest = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		new JobMessageParameters(),
		Collections.singletonMap("jobid", TEST_JOB_ID.toString()),
		Collections.emptyMap());
}
 
Example 14
Source File: JobVertexBackPressureHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetBackPressure() throws Exception {
	final Map<String, String> pathParameters = new HashMap<>();
	pathParameters.put(JobIDPathParameter.KEY, TEST_JOB_ID_BACK_PRESSURE_STATS_AVAILABLE.toString());
	pathParameters.put(JobVertexIdPathParameter.KEY, new JobVertexID().toString());

	final HandlerRequest<EmptyRequestBody, JobVertexMessageParameters> request =
		new HandlerRequest<>(
			EmptyRequestBody.getInstance(),
			new JobVertexMessageParameters(), pathParameters, Collections.emptyMap());

	final CompletableFuture<JobVertexBackPressureInfo> jobVertexBackPressureInfoCompletableFuture =
		jobVertexBackPressureHandler.handleRequest(request, restfulGateway);
	final JobVertexBackPressureInfo jobVertexBackPressureInfo = jobVertexBackPressureInfoCompletableFuture.get();

	assertThat(jobVertexBackPressureInfo.getStatus(), equalTo(VertexBackPressureStatus.OK));
	assertThat(jobVertexBackPressureInfo.getBackpressureLevel(), equalTo(HIGH));

	assertThat(jobVertexBackPressureInfo.getSubtasks()
		.stream()
		.map(JobVertexBackPressureInfo.SubtaskBackPressureInfo::getRatio)
		.collect(Collectors.toList()), contains(1.0, 0.5, 0.1));

	assertThat(jobVertexBackPressureInfo.getSubtasks()
		.stream()
		.map(JobVertexBackPressureInfo.SubtaskBackPressureInfo::getBackpressureLevel)
		.collect(Collectors.toList()), contains(HIGH, LOW, OK));

	assertThat(jobVertexBackPressureInfo.getSubtasks()
		.stream()
		.map(JobVertexBackPressureInfo.SubtaskBackPressureInfo::getSubtask)
		.collect(Collectors.toList()), contains(0, 1, 2));
}
 
Example 15
Source File: JarUploadHandlerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static HandlerRequest<EmptyRequestBody, EmptyMessageParameters> createRequest(
		final Path uploadedFile) throws HandlerRequestException, IOException {
	return new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		EmptyMessageParameters.getInstance(),
		Collections.emptyMap(),
		Collections.emptyMap(),
		Collections.singleton(uploadedFile.toFile()));
}
 
Example 16
Source File: JarSubmissionITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static void deleteJar(JarDeleteHandler handler, String jarName, RestfulGateway restfulGateway) throws Exception {
	JarDeleteMessageParameters deleteParameters = JarDeleteHeaders.getInstance().getUnresolvedMessageParameters();
	HandlerRequest<EmptyRequestBody, JarDeleteMessageParameters> deleteRequest = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		deleteParameters,
		Collections.singletonMap(deleteParameters.jarIdPathParameter.getKey(), jarName),
		Collections.emptyMap(),
		Collections.emptyList());
	handler.handleRequest(deleteRequest, restfulGateway)
		.get();
}
 
Example 17
Source File: StopWithSavepointHandlersTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static HandlerRequest<EmptyRequestBody, SavepointStatusMessageParameters> savepointStatusRequest(
		final TriggerId triggerId) throws HandlerRequestException {
	final Map<String, String> pathParameters = new HashMap<>();
	pathParameters.put(JobIDPathParameter.KEY, JOB_ID.toString());
	pathParameters.put(TriggerIdPathParameter.KEY, triggerId.toString());

	return new HandlerRequest<>(
			EmptyRequestBody.getInstance(),
			new SavepointStatusMessageParameters(),
			pathParameters,
			Collections.emptyMap());
}
 
Example 18
Source File: JarSubmissionITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static String uploadJar(JarUploadHandler handler, Path jar, RestfulGateway restfulGateway) throws Exception {
	HandlerRequest<EmptyRequestBody, EmptyMessageParameters> uploadRequest = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		EmptyMessageParameters.getInstance(),
		Collections.emptyMap(),
		Collections.emptyMap(),
		Collections.singletonList(jar.toFile()));
	final JarUploadResponseBody uploadResponse = handler.handleRequest(uploadRequest, restfulGateway)
		.get();
	return uploadResponse.getFilename();
}
 
Example 19
Source File: SubtaskExecutionAttemptAccumulatorsHandlerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testHandleRequest() throws Exception {

	// Instance the handler.
	final RestHandlerConfiguration restHandlerConfiguration = RestHandlerConfiguration.fromConfiguration(new Configuration());

	final SubtaskExecutionAttemptAccumulatorsHandler handler = new SubtaskExecutionAttemptAccumulatorsHandler(
		() -> null,
		Time.milliseconds(100L),
		Collections.emptyMap(),
		SubtaskExecutionAttemptAccumulatorsHeaders.getInstance(),
		new ExecutionGraphCache(
			restHandlerConfiguration.getTimeout(),
			Time.milliseconds(restHandlerConfiguration.getRefreshInterval())),
		TestingUtils.defaultExecutor());

	// Instance a empty request.
	final HandlerRequest<EmptyRequestBody, SubtaskAttemptMessageParameters> request = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		new SubtaskAttemptMessageParameters()
	);

	final Map<String, OptionalFailure<Accumulator<?, ?>>> userAccumulators = new HashMap<>(3);
	userAccumulators.put("IntCounter", OptionalFailure.of(new IntCounter(10)));
	userAccumulators.put("LongCounter", OptionalFailure.of(new LongCounter(100L)));
	userAccumulators.put("Failure", OptionalFailure.ofFailure(new FlinkRuntimeException("Test")));

	// Instance the expected result.
	final StringifiedAccumulatorResult[] accumulatorResults =
		StringifiedAccumulatorResult.stringifyAccumulatorResults(userAccumulators);

	final int attemptNum = 1;
	final int subtaskIndex = 2;

	// Instance the tested execution.
	final ArchivedExecution execution = new ArchivedExecution(
		accumulatorResults,
		null,
		new ExecutionAttemptID(),
		attemptNum,
		ExecutionState.FINISHED,
		null,
		null,
		null,
		subtaskIndex,
		new long[ExecutionState.values().length]);

	// Invoke tested method.
	final SubtaskExecutionAttemptAccumulatorsInfo accumulatorsInfo = handler.handleRequest(request, execution);

	final ArrayList<UserAccumulator> userAccumulatorList = new ArrayList<>(userAccumulators.size());
	for (StringifiedAccumulatorResult accumulatorResult : accumulatorResults) {
		userAccumulatorList.add(
			new UserAccumulator(
				accumulatorResult.getName(),
				accumulatorResult.getType(),
				accumulatorResult.getValue()));
	}

	final SubtaskExecutionAttemptAccumulatorsInfo expected = new SubtaskExecutionAttemptAccumulatorsInfo(
		subtaskIndex,
		attemptNum,
		execution.getAttemptId().toString(),
		userAccumulatorList);

	// Verify.
	assertEquals(expected, accumulatorsInfo);
}
 
Example 20
Source File: SubtaskExecutionAttemptAccumulatorsHandlerTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testHandleRequest() throws Exception {

	// Instance the handler.
	final RestHandlerConfiguration restHandlerConfiguration = RestHandlerConfiguration.fromConfiguration(new Configuration());

	final SubtaskExecutionAttemptAccumulatorsHandler handler = new SubtaskExecutionAttemptAccumulatorsHandler(
		() -> null,
		Time.milliseconds(100L),
		Collections.emptyMap(),
		SubtaskExecutionAttemptAccumulatorsHeaders.getInstance(),
		new ExecutionGraphCache(
			restHandlerConfiguration.getTimeout(),
			Time.milliseconds(restHandlerConfiguration.getRefreshInterval())),
		TestingUtils.defaultExecutor());

	// Instance a empty request.
	final HandlerRequest<EmptyRequestBody, SubtaskAttemptMessageParameters> request = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		new SubtaskAttemptMessageParameters()
	);

	final Map<String, OptionalFailure<Accumulator<?, ?>>> userAccumulators = new HashMap<>(3);
	userAccumulators.put("IntCounter", OptionalFailure.of(new IntCounter(10)));
	userAccumulators.put("LongCounter", OptionalFailure.of(new LongCounter(100L)));
	userAccumulators.put("Failure", OptionalFailure.ofFailure(new FlinkRuntimeException("Test")));

	// Instance the expected result.
	final StringifiedAccumulatorResult[] accumulatorResults =
		StringifiedAccumulatorResult.stringifyAccumulatorResults(userAccumulators);

	final int attemptNum = 1;
	final int subtaskIndex = 2;

	// Instance the tested execution.
	final ArchivedExecution execution = new ArchivedExecution(
		accumulatorResults,
		null,
		new ExecutionAttemptID(),
		attemptNum,
		ExecutionState.FINISHED,
		null,
		null,
		null,
		subtaskIndex,
		new long[ExecutionState.values().length]);

	// Invoke tested method.
	final SubtaskExecutionAttemptAccumulatorsInfo accumulatorsInfo = handler.handleRequest(request, execution);

	final ArrayList<UserAccumulator> userAccumulatorList = new ArrayList<>(userAccumulators.size());
	for (StringifiedAccumulatorResult accumulatorResult : accumulatorResults) {
		userAccumulatorList.add(
			new UserAccumulator(
				accumulatorResult.getName(),
				accumulatorResult.getType(),
				accumulatorResult.getValue()));
	}

	final SubtaskExecutionAttemptAccumulatorsInfo expected = new SubtaskExecutionAttemptAccumulatorsInfo(
		subtaskIndex,
		attemptNum,
		execution.getAttemptId().toString(),
		userAccumulatorList);

	// Verify.
	assertEquals(expected, accumulatorsInfo);
}