use of org.apache.flink.runtime.execution.Environment in project flink by apache.
the class AccumulatingAlignedProcessingTimeWindowOperatorTest method createMockTask.
// ------------------------------------------------------------------------
private static StreamTask<?, ?> createMockTask() {
Configuration configuration = new Configuration();
configuration.setString(CoreOptions.STATE_BACKEND, "jobmanager");
StreamTask<?, ?> task = mock(StreamTask.class);
when(task.getAccumulatorMap()).thenReturn(new HashMap<String, Accumulator<?, ?>>());
when(task.getName()).thenReturn("Test task name");
when(task.getExecutionConfig()).thenReturn(new ExecutionConfig());
final TaskManagerRuntimeInfo mockTaskManagerRuntimeInfo = mock(TaskManagerRuntimeInfo.class);
when(mockTaskManagerRuntimeInfo.getConfiguration()).thenReturn(configuration);
final Environment env = mock(Environment.class);
when(env.getTaskInfo()).thenReturn(new TaskInfo("Test task name", 1, 0, 1, 0));
when(env.getUserClassLoader()).thenReturn(AggregatingAlignedProcessingTimeWindowOperatorTest.class.getClassLoader());
when(env.getMetricGroup()).thenReturn(new UnregisteredTaskMetricsGroup());
when(env.getTaskManagerInfo()).thenReturn(new TestingTaskManagerRuntimeInfo());
when(task.getEnvironment()).thenReturn(env);
return task;
}
use of org.apache.flink.runtime.execution.Environment in project flink by apache.
the class StreamOperatorContextBuilder method build.
StreamOperatorStateContext build(Logger logger) throws IOException {
final Environment environment = new SavepointEnvironment.Builder(ctx, maxParallelism).setConfiguration(configuration).setSubtaskIndex(split.getSplitNumber()).setPrioritizedOperatorSubtaskState(split.getPrioritizedOperatorSubtaskState()).build();
StateBackend stateBackend;
try {
stateBackend = StateBackendLoader.fromApplicationOrConfigOrDefault(applicationStateBackend, TernaryBoolean.FALSE, configuration, ctx.getUserCodeClassLoader(), logger);
} catch (DynamicCodeLoadingException e) {
throw new IOException("Failed to load state backend", e);
}
StreamTaskStateInitializer initializer = new StreamTaskStateInitializerImpl(environment, stateBackend);
try {
return initializer.streamOperatorStateContext(operatorState.getOperatorID(), operatorState.getOperatorID().toString(), new NeverFireProcessingTimeService(), keyContext, keySerializer, registry, ctx.getMetricGroup(), 1.0, false);
} catch (Exception e) {
throw new IOException("Failed to restore state backend", e);
}
}
use of org.apache.flink.runtime.execution.Environment in project flink by apache.
the class DataSourceTask method createRuntimeContext.
public DistributedRuntimeUDFContext createRuntimeContext() {
Environment env = getEnvironment();
String sourceName = getEnvironment().getTaskInfo().getTaskName().split("->")[0].trim();
sourceName = sourceName.startsWith("CHAIN") ? sourceName.substring(6) : sourceName;
return new DistributedRuntimeUDFContext(env.getTaskInfo(), env.getUserCodeClassLoader(), getExecutionConfig(), env.getDistributedCacheEntries(), env.getAccumulatorRegistry().getUserMap(), getEnvironment().getMetricGroup().getOrAddOperator(sourceName), env.getExternalResourceInfoProvider(), env.getJobID());
}
use of org.apache.flink.runtime.execution.Environment in project flink by apache.
the class TaskExecutorPartitionLifecycleTest method internalTestPartitionRelease.
private void internalTestPartitionRelease(TaskExecutorPartitionTracker partitionTracker, ShuffleEnvironment<?, ?> shuffleEnvironment, CompletableFuture<ResultPartitionID> startTrackingFuture, TestAction testAction) throws Exception {
final ResultPartitionDeploymentDescriptor taskResultPartitionDescriptor = PartitionTestUtils.createPartitionDeploymentDescriptor(ResultPartitionType.BLOCKING);
final ExecutionAttemptID eid1 = taskResultPartitionDescriptor.getShuffleDescriptor().getResultPartitionID().getProducerId();
final TaskDeploymentDescriptor taskDeploymentDescriptor = TaskExecutorSubmissionTest.createTaskDeploymentDescriptor(jobId, "job", eid1, new SerializedValue<>(new ExecutionConfig()), "Sender", 1, 0, 1, 0, new Configuration(), new Configuration(), TestingInvokable.class.getName(), Collections.singletonList(taskResultPartitionDescriptor), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
final TaskSlotTable<Task> taskSlotTable = createTaskSlotTable();
final TaskExecutorLocalStateStoresManager localStateStoresManager = new TaskExecutorLocalStateStoresManager(false, Reference.owned(new File[] { tmp.newFolder() }), Executors.directExecutor());
final TaskManagerServices taskManagerServices = new TaskManagerServicesBuilder().setTaskSlotTable(taskSlotTable).setTaskStateManager(localStateStoresManager).setShuffleEnvironment(shuffleEnvironment).build();
final CompletableFuture<Void> taskFinishedFuture = new CompletableFuture<>();
final OneShotLatch slotOfferedLatch = new OneShotLatch();
final TestingJobMasterGateway jobMasterGateway = new TestingJobMasterGatewayBuilder().setRegisterTaskManagerFunction((ignoredJobId, ignoredTaskManagerRegistrationInformation) -> CompletableFuture.completedFuture(new JMTMRegistrationSuccess(ResourceID.generate()))).setOfferSlotsFunction((resourceID, slotOffers) -> {
slotOfferedLatch.trigger();
return CompletableFuture.completedFuture(slotOffers);
}).setUpdateTaskExecutionStateFunction(taskExecutionState -> {
if (taskExecutionState.getExecutionState() == ExecutionState.FINISHED) {
taskFinishedFuture.complete(null);
}
return CompletableFuture.completedFuture(Acknowledge.get());
}).build();
final TestingTaskExecutor taskExecutor = createTestingTaskExecutor(taskManagerServices, partitionTracker);
final CompletableFuture<SlotReport> initialSlotReportFuture = new CompletableFuture<>();
final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway();
testingResourceManagerGateway.setSendSlotReportFunction(resourceIDInstanceIDSlotReportTuple3 -> {
initialSlotReportFuture.complete(resourceIDInstanceIDSlotReportTuple3.f2);
return CompletableFuture.completedFuture(Acknowledge.get());
});
testingResourceManagerGateway.setRegisterTaskExecutorFunction(input -> CompletableFuture.completedFuture(new TaskExecutorRegistrationSuccess(new InstanceID(), testingResourceManagerGateway.getOwnResourceId(), new ClusterInformation("blobServerHost", 55555))));
try {
taskExecutor.start();
taskExecutor.waitUntilStarted();
final TaskExecutorGateway taskExecutorGateway = taskExecutor.getSelfGateway(TaskExecutorGateway.class);
final String jobMasterAddress = "jm";
rpc.registerGateway(jobMasterAddress, jobMasterGateway);
rpc.registerGateway(testingResourceManagerGateway.getAddress(), testingResourceManagerGateway);
// inform the task manager about the job leader
taskManagerServices.getJobLeaderService().addJob(jobId, jobMasterAddress);
jobManagerLeaderRetriever.notifyListener(jobMasterAddress, UUID.randomUUID());
resourceManagerLeaderRetriever.notifyListener(testingResourceManagerGateway.getAddress(), testingResourceManagerGateway.getFencingToken().toUUID());
final Optional<SlotStatus> slotStatusOptional = StreamSupport.stream(initialSlotReportFuture.get().spliterator(), false).findAny();
assertTrue(slotStatusOptional.isPresent());
final SlotStatus slotStatus = slotStatusOptional.get();
while (true) {
try {
taskExecutorGateway.requestSlot(slotStatus.getSlotID(), jobId, taskDeploymentDescriptor.getAllocationId(), ResourceProfile.ZERO, jobMasterAddress, testingResourceManagerGateway.getFencingToken(), timeout).get();
break;
} catch (Exception e) {
// the proper establishment of the RM connection is tracked
// asynchronously, so we have to poll here until it went through
// until then, slot requests will fail with an exception
Thread.sleep(50);
}
}
TestingInvokable.sync = new BlockerSync();
// Wait till the slot has been successfully offered before submitting the task.
// This ensures TM has been successfully registered to JM.
slotOfferedLatch.await();
taskExecutorGateway.submitTask(taskDeploymentDescriptor, jobMasterGateway.getFencingToken(), timeout).get();
TestingInvokable.sync.awaitBlocker();
// the task is still running => the partition is in in-progress and should be tracked
assertThat(startTrackingFuture.get(), equalTo(taskResultPartitionDescriptor.getShuffleDescriptor().getResultPartitionID()));
TestingInvokable.sync.releaseBlocker();
taskFinishedFuture.get(timeout.getSize(), timeout.getUnit());
testAction.accept(jobId, taskResultPartitionDescriptor, taskExecutor, taskExecutorGateway);
} finally {
RpcUtils.terminateRpcEndpoint(taskExecutor, timeout);
}
// the shutdown of the backing shuffle environment releases all partitions
// the book-keeping is not aware of this
assertTrue(shuffleEnvironment.getPartitionsOccupyingLocalResources().isEmpty());
}
use of org.apache.flink.runtime.execution.Environment in project flink by apache.
the class LatencyTrackingStateTestBase method createKeyedBackend.
protected AbstractKeyedStateBackend<K> createKeyedBackend(TypeSerializer<K> keySerializer) throws Exception {
Environment env = new DummyEnvironment();
KeyGroupRange keyGroupRange = new KeyGroupRange(0, 127);
int numberOfKeyGroups = keyGroupRange.getNumberOfKeyGroups();
Configuration configuration = new Configuration();
configuration.setBoolean(StateBackendOptions.LATENCY_TRACK_ENABLED, true);
configuration.setInteger(StateBackendOptions.LATENCY_TRACK_SAMPLE_INTERVAL, SAMPLE_INTERVAL);
// use a very large value to not let metrics data overridden.
int historySize = 1000_000;
configuration.setInteger(StateBackendOptions.LATENCY_TRACK_HISTORY_SIZE, historySize);
HashMapStateBackend stateBackend = new HashMapStateBackend().configure(configuration, Thread.currentThread().getContextClassLoader());
return stateBackend.createKeyedStateBackend(env, new JobID(), "test_op", keySerializer, numberOfKeyGroups, keyGroupRange, env.getTaskKvStateRegistry(), TtlTimeProvider.DEFAULT, new UnregisteredMetricsGroup(), Collections.emptyList(), new CloseableRegistry());
}
Aggregations