use of org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache in project flink by apache.
the class JobConfigHandlerTest method handleRequest_executionConfigWithSecretValues_excludesSecretValuesFromResponse.
@Test
public void handleRequest_executionConfigWithSecretValues_excludesSecretValuesFromResponse() throws HandlerRequestException {
final JobConfigHandler jobConfigHandler = new JobConfigHandler(() -> null, TestingUtils.TIMEOUT, Collections.emptyMap(), JobConfigHeaders.getInstance(), new DefaultExecutionGraphCache(TestingUtils.TIMEOUT, TestingUtils.TIMEOUT), TestingUtils.defaultExecutor());
final Map<String, String> globalJobParameters = new HashMap<>();
globalJobParameters.put("foobar", "barfoo");
globalJobParameters.put("bar.secret.foo", "my secret");
globalJobParameters.put("password.to.my.safe", "12345");
final ArchivedExecutionConfig archivedExecutionConfig = new ArchivedExecutionConfigBuilder().setGlobalJobParameters(globalJobParameters).build();
final AccessExecutionGraph archivedExecutionGraph = new ArchivedExecutionGraphBuilder().setArchivedExecutionConfig(archivedExecutionConfig).build();
final HandlerRequest<EmptyRequestBody> handlerRequest = createRequest(archivedExecutionGraph.getJobID());
final JobConfigInfo jobConfigInfoResponse = jobConfigHandler.handleRequest(handlerRequest, archivedExecutionGraph);
final Map<String, String> filteredGlobalJobParameters = filterSecretValues(globalJobParameters);
assertThat(jobConfigInfoResponse.getExecutionConfigInfo().getGlobalJobParameters(), is(equalTo(filteredGlobalJobParameters)));
}
use of org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache in project flink by apache.
the class SubtaskCurrentAttemptDetailsHandlerTest method testHandleRequest.
@Test
public void testHandleRequest() throws Exception {
// Prepare the execution graph.
final JobID jobID = new JobID();
final JobVertexID jobVertexID = new JobVertexID();
// The testing subtask.
final long deployingTs = System.currentTimeMillis() - 1024;
final long finishedTs = System.currentTimeMillis();
final long bytesIn = 1L;
final long bytesOut = 10L;
final long recordsIn = 20L;
final long recordsOut = 30L;
final IOMetrics ioMetrics = new IOMetrics(bytesIn, bytesOut, recordsIn, recordsOut);
final long[] timestamps = new long[ExecutionState.values().length];
timestamps[ExecutionState.DEPLOYING.ordinal()] = deployingTs;
final ExecutionState expectedState = ExecutionState.FINISHED;
timestamps[expectedState.ordinal()] = finishedTs;
final LocalTaskManagerLocation assignedResourceLocation = new LocalTaskManagerLocation();
final AllocationID allocationID = new AllocationID();
final int subtaskIndex = 1;
final int attempt = 2;
final ArchivedExecution execution = new ArchivedExecution(new StringifiedAccumulatorResult[0], ioMetrics, new ExecutionAttemptID(), attempt, expectedState, null, assignedResourceLocation, allocationID, subtaskIndex, timestamps);
final ArchivedExecutionVertex executionVertex = new ArchivedExecutionVertex(subtaskIndex, "Test archived execution vertex", execution, new EvictingBoundedList<>(0));
// Instance the handler.
final RestHandlerConfiguration restHandlerConfiguration = RestHandlerConfiguration.fromConfiguration(new Configuration());
final MetricFetcher metricFetcher = new MetricFetcherImpl<>(() -> null, address -> null, TestingUtils.defaultExecutor(), Time.milliseconds(1000L), MetricOptions.METRIC_FETCHER_UPDATE_INTERVAL.defaultValue());
final SubtaskCurrentAttemptDetailsHandler handler = new SubtaskCurrentAttemptDetailsHandler(() -> null, Time.milliseconds(100), Collections.emptyMap(), SubtaskCurrentAttemptDetailsHeaders.getInstance(), new DefaultExecutionGraphCache(restHandlerConfiguration.getTimeout(), Time.milliseconds(restHandlerConfiguration.getRefreshInterval())), TestingUtils.defaultExecutor(), metricFetcher);
final HashMap<String, String> receivedPathParameters = new HashMap<>(2);
receivedPathParameters.put(JobIDPathParameter.KEY, jobID.toString());
receivedPathParameters.put(JobVertexIdPathParameter.KEY, jobVertexID.toString());
final HandlerRequest<EmptyRequestBody> request = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), new SubtaskMessageParameters(), receivedPathParameters, Collections.emptyMap(), Collections.emptyList());
// Handle request.
final SubtaskExecutionAttemptDetailsInfo detailsInfo = handler.handleRequest(request, executionVertex);
// Verify
final IOMetricsInfo ioMetricsInfo = new IOMetricsInfo(bytesIn, true, bytesOut, true, recordsIn, true, recordsOut, true);
final SubtaskExecutionAttemptDetailsInfo expectedDetailsInfo = new SubtaskExecutionAttemptDetailsInfo(subtaskIndex, expectedState, attempt, assignedResourceLocation.getHostname(), deployingTs, finishedTs, finishedTs - deployingTs, ioMetricsInfo, assignedResourceLocation.getResourceID().getResourceIdString());
assertEquals(expectedDetailsInfo, detailsInfo);
}
use of org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache in project flink by apache.
the class SubtaskExecutionAttemptAccumulatorsHandlerTest method testHandleRequest.
@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 DefaultExecutionGraphCache(restHandlerConfiguration.getTimeout(), Time.milliseconds(restHandlerConfiguration.getRefreshInterval())), TestingUtils.defaultExecutor());
// Instance a empty request.
final HandlerRequest<EmptyRequestBody> request = HandlerRequest.create(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);
}
use of org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache in project flink by apache.
the class SubtaskExecutionAttemptDetailsHandlerTest method testHandleRequest.
@Test
public void testHandleRequest() throws Exception {
final JobID jobID = new JobID();
final JobVertexID jobVertexId = new JobVertexID();
// The testing subtask.
final int subtaskIndex = 1;
final ExecutionState expectedState = ExecutionState.FINISHED;
final int attempt = 0;
final StringifiedAccumulatorResult[] emptyAccumulators = new StringifiedAccumulatorResult[0];
final long bytesIn = 1L;
final long bytesOut = 10L;
final long recordsIn = 20L;
final long recordsOut = 30L;
final IOMetrics ioMetrics = new IOMetrics(bytesIn, bytesOut, recordsIn, recordsOut);
final ArchivedExecutionJobVertex archivedExecutionJobVertex = new ArchivedExecutionJobVertex(new ArchivedExecutionVertex[] { // the first subtask won't be queried
null, new ArchivedExecutionVertex(subtaskIndex, "test task", new ArchivedExecution(emptyAccumulators, ioMetrics, new ExecutionAttemptID(), attempt, expectedState, null, null, null, subtaskIndex, new long[ExecutionState.values().length]), new EvictingBoundedList<>(0)) }, jobVertexId, "test", 1, 1, ResourceProfile.UNKNOWN, emptyAccumulators);
// Change some fields so we can make it different from other sub tasks.
final MetricFetcher metricFetcher = new MetricFetcherImpl<>(() -> null, address -> null, TestingUtils.defaultExecutor(), Time.milliseconds(1000L), MetricOptions.METRIC_FETCHER_UPDATE_INTERVAL.defaultValue());
// Instance the handler.
final RestHandlerConfiguration restHandlerConfiguration = RestHandlerConfiguration.fromConfiguration(new Configuration());
final SubtaskExecutionAttemptDetailsHandler handler = new SubtaskExecutionAttemptDetailsHandler(() -> null, Time.milliseconds(100L), Collections.emptyMap(), SubtaskExecutionAttemptDetailsHeaders.getInstance(), new DefaultExecutionGraphCache(restHandlerConfiguration.getTimeout(), Time.milliseconds(restHandlerConfiguration.getRefreshInterval())), TestingUtils.defaultExecutor(), metricFetcher);
final HashMap<String, String> receivedPathParameters = new HashMap<>(4);
receivedPathParameters.put(JobIDPathParameter.KEY, jobID.toString());
receivedPathParameters.put(JobVertexIdPathParameter.KEY, jobVertexId.toString());
receivedPathParameters.put(SubtaskIndexPathParameter.KEY, Integer.toString(subtaskIndex));
receivedPathParameters.put(SubtaskAttemptPathParameter.KEY, Integer.toString(attempt));
final HandlerRequest<EmptyRequestBody> request = HandlerRequest.resolveParametersAndCreate(EmptyRequestBody.getInstance(), new SubtaskAttemptMessageParameters(), receivedPathParameters, Collections.emptyMap(), Collections.emptyList());
// Handle request.
final SubtaskExecutionAttemptDetailsInfo detailsInfo = handler.handleRequest(request, archivedExecutionJobVertex);
// Verify
final IOMetricsInfo ioMetricsInfo = new IOMetricsInfo(bytesIn, true, bytesOut, true, recordsIn, true, recordsOut, true);
final SubtaskExecutionAttemptDetailsInfo expectedDetailsInfo = new SubtaskExecutionAttemptDetailsInfo(subtaskIndex, expectedState, attempt, "(unassigned)", -1L, 0L, -1L, ioMetricsInfo, "(unassigned)");
assertEquals(expectedDetailsInfo, detailsInfo);
}
Aggregations