Java Code Examples for org.apache.flink.streaming.api.operators.StreamingRuntimeContext#getTaskNameWithSubtasks()

The following examples show how to use org.apache.flink.streaming.api.operators.StreamingRuntimeContext#getTaskNameWithSubtasks() . 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: FlinkKafkaConsumer09.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractFetcher<T, ?> createFetcher(
		SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> assignedPartitionsWithInitialOffsets,
		SerializedValue<AssignerWithPeriodicWatermarks<T>> watermarksPeriodic,
		SerializedValue<AssignerWithPunctuatedWatermarks<T>> watermarksPunctuated,
		StreamingRuntimeContext runtimeContext,
		OffsetCommitMode offsetCommitMode,
		MetricGroup consumerMetricGroup,
		boolean useMetrics) throws Exception {

	// make sure that auto commit is disabled when our offset commit mode is ON_CHECKPOINTS;
	// this overwrites whatever setting the user configured in the properties
	adjustAutoCommitConfig(properties, offsetCommitMode);

	// If a rateLimiter is set, then call rateLimiter.open() with the runtime context.
	if (rateLimiter != null) {
		rateLimiter.open(runtimeContext);
	}

	return new Kafka09Fetcher<>(
			sourceContext,
			assignedPartitionsWithInitialOffsets,
			watermarksPeriodic,
			watermarksPunctuated,
			runtimeContext.getProcessingTimeService(),
			runtimeContext.getExecutionConfig().getAutoWatermarkInterval(),
			runtimeContext.getUserCodeClassLoader(),
			runtimeContext.getTaskNameWithSubtasks(),
			deserializer,
			properties,
			pollTimeout,
			runtimeContext.getMetricGroup(),
			consumerMetricGroup,
			useMetrics,
			rateLimiter);
}
 
Example 2
Source File: FlinkKafkaConsumer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractFetcher<T, ?> createFetcher(
	SourceContext<T> sourceContext,
	Map<KafkaTopicPartition, Long> assignedPartitionsWithInitialOffsets,
	SerializedValue<AssignerWithPeriodicWatermarks<T>> watermarksPeriodic,
	SerializedValue<AssignerWithPunctuatedWatermarks<T>> watermarksPunctuated,
	StreamingRuntimeContext runtimeContext,
	OffsetCommitMode offsetCommitMode,
	MetricGroup consumerMetricGroup,
	boolean useMetrics) throws Exception {

	// make sure that auto commit is disabled when our offset commit mode is ON_CHECKPOINTS;
	// this overwrites whatever setting the user configured in the properties
	adjustAutoCommitConfig(properties, offsetCommitMode);

	return new KafkaFetcher<>(
		sourceContext,
		assignedPartitionsWithInitialOffsets,
		watermarksPeriodic,
		watermarksPunctuated,
		runtimeContext.getProcessingTimeService(),
		runtimeContext.getExecutionConfig().getAutoWatermarkInterval(),
		runtimeContext.getUserCodeClassLoader(),
		runtimeContext.getTaskNameWithSubtasks(),
		deserializer,
		properties,
		pollTimeout,
		runtimeContext.getMetricGroup(),
		consumerMetricGroup,
		useMetrics);
}
 
Example 3
Source File: FlinkKafkaConsumer010.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractFetcher<T, ?> createFetcher(
		SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> assignedPartitionsWithInitialOffsets,
		SerializedValue<AssignerWithPeriodicWatermarks<T>> watermarksPeriodic,
		SerializedValue<AssignerWithPunctuatedWatermarks<T>> watermarksPunctuated,
		StreamingRuntimeContext runtimeContext,
		OffsetCommitMode offsetCommitMode,
		MetricGroup consumerMetricGroup,
		boolean useMetrics) throws Exception {

	// make sure that auto commit is disabled when our offset commit mode is ON_CHECKPOINTS;
	// this overwrites whatever setting the user configured in the properties
	adjustAutoCommitConfig(properties, offsetCommitMode);

	FlinkConnectorRateLimiter rateLimiter = super.getRateLimiter();
	// If a rateLimiter is set, then call rateLimiter.open() with the runtime context.
	if (rateLimiter != null) {
		rateLimiter.open(runtimeContext);
	}

	return new Kafka010Fetcher<>(
			sourceContext,
			assignedPartitionsWithInitialOffsets,
			watermarksPeriodic,
			watermarksPunctuated,
			runtimeContext.getProcessingTimeService(),
			runtimeContext.getExecutionConfig().getAutoWatermarkInterval(),
			runtimeContext.getUserCodeClassLoader(),
			runtimeContext.getTaskNameWithSubtasks(),
			deserializer,
			properties,
			pollTimeout,
			runtimeContext.getMetricGroup(),
			consumerMetricGroup,
			useMetrics,
			rateLimiter);
}
 
Example 4
Source File: FlinkKafkaConsumer09.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractFetcher<T, ?> createFetcher(
		SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> assignedPartitionsWithInitialOffsets,
		SerializedValue<AssignerWithPeriodicWatermarks<T>> watermarksPeriodic,
		SerializedValue<AssignerWithPunctuatedWatermarks<T>> watermarksPunctuated,
		StreamingRuntimeContext runtimeContext,
		OffsetCommitMode offsetCommitMode,
		MetricGroup consumerMetricGroup,
		boolean useMetrics) throws Exception {

	// make sure that auto commit is disabled when our offset commit mode is ON_CHECKPOINTS;
	// this overwrites whatever setting the user configured in the properties
	adjustAutoCommitConfig(properties, offsetCommitMode);

	// If a rateLimiter is set, then call rateLimiter.open() with the runtime context.
	if (rateLimiter != null) {
		rateLimiter.open(runtimeContext);
	}

	return new Kafka09Fetcher<>(
			sourceContext,
			assignedPartitionsWithInitialOffsets,
			watermarksPeriodic,
			watermarksPunctuated,
			runtimeContext.getProcessingTimeService(),
			runtimeContext.getExecutionConfig().getAutoWatermarkInterval(),
			runtimeContext.getUserCodeClassLoader(),
			runtimeContext.getTaskNameWithSubtasks(),
			deserializer,
			properties,
			pollTimeout,
			runtimeContext.getMetricGroup(),
			consumerMetricGroup,
			useMetrics,
			rateLimiter);
}
 
Example 5
Source File: FlinkKafkaConsumer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractFetcher<T, ?> createFetcher(
	SourceContext<T> sourceContext,
	Map<KafkaTopicPartition, Long> assignedPartitionsWithInitialOffsets,
	SerializedValue<AssignerWithPeriodicWatermarks<T>> watermarksPeriodic,
	SerializedValue<AssignerWithPunctuatedWatermarks<T>> watermarksPunctuated,
	StreamingRuntimeContext runtimeContext,
	OffsetCommitMode offsetCommitMode,
	MetricGroup consumerMetricGroup,
	boolean useMetrics) throws Exception {

	// make sure that auto commit is disabled when our offset commit mode is ON_CHECKPOINTS;
	// this overwrites whatever setting the user configured in the properties
	adjustAutoCommitConfig(properties, offsetCommitMode);

	return new KafkaFetcher<>(
		sourceContext,
		assignedPartitionsWithInitialOffsets,
		watermarksPeriodic,
		watermarksPunctuated,
		runtimeContext.getProcessingTimeService(),
		runtimeContext.getExecutionConfig().getAutoWatermarkInterval(),
		runtimeContext.getUserCodeClassLoader(),
		runtimeContext.getTaskNameWithSubtasks(),
		deserializer,
		properties,
		pollTimeout,
		runtimeContext.getMetricGroup(),
		consumerMetricGroup,
		useMetrics);
}
 
Example 6
Source File: FlinkKafkaConsumer010.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractFetcher<T, ?> createFetcher(
		SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> assignedPartitionsWithInitialOffsets,
		SerializedValue<AssignerWithPeriodicWatermarks<T>> watermarksPeriodic,
		SerializedValue<AssignerWithPunctuatedWatermarks<T>> watermarksPunctuated,
		StreamingRuntimeContext runtimeContext,
		OffsetCommitMode offsetCommitMode,
		MetricGroup consumerMetricGroup,
		boolean useMetrics) throws Exception {

	// make sure that auto commit is disabled when our offset commit mode is ON_CHECKPOINTS;
	// this overwrites whatever setting the user configured in the properties
	adjustAutoCommitConfig(properties, offsetCommitMode);

	FlinkConnectorRateLimiter rateLimiter = super.getRateLimiter();
	// If a rateLimiter is set, then call rateLimiter.open() with the runtime context.
	if (rateLimiter != null) {
		rateLimiter.open(runtimeContext);
	}

	return new Kafka010Fetcher<>(
			sourceContext,
			assignedPartitionsWithInitialOffsets,
			watermarksPeriodic,
			watermarksPunctuated,
			runtimeContext.getProcessingTimeService(),
			runtimeContext.getExecutionConfig().getAutoWatermarkInterval(),
			runtimeContext.getUserCodeClassLoader(),
			runtimeContext.getTaskNameWithSubtasks(),
			deserializer,
			properties,
			pollTimeout,
			runtimeContext.getMetricGroup(),
			consumerMetricGroup,
			useMetrics,
			rateLimiter);
}
 
Example 7
Source File: FlinkKafkaShuffleConsumer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractFetcher<T, ?> createFetcher(
		SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> assignedPartitionsWithInitialOffsets,
		SerializedValue<WatermarkStrategy<T>> watermarkStrategy,
		StreamingRuntimeContext runtimeContext,
		OffsetCommitMode offsetCommitMode,
		MetricGroup consumerMetricGroup,
		boolean useMetrics) throws Exception {
	// make sure that auto commit is disabled when our offset commit mode is ON_CHECKPOINTS;
	// this overwrites whatever setting the user configured in the properties
	adjustAutoCommitConfig(properties, offsetCommitMode);

	return new KafkaShuffleFetcher<>(
		sourceContext,
		assignedPartitionsWithInitialOffsets,
		watermarkStrategy,
		runtimeContext.getProcessingTimeService(),
		runtimeContext.getExecutionConfig().getAutoWatermarkInterval(),
		runtimeContext.getUserCodeClassLoader(),
		runtimeContext.getTaskNameWithSubtasks(),
		deserializer,
		properties,
		pollTimeout,
		runtimeContext.getMetricGroup(),
		consumerMetricGroup,
		useMetrics,
		typeSerializer,
		producerParallelism);
}
 
Example 8
Source File: FlinkKafkaConsumer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractFetcher<T, ?> createFetcher(
	SourceContext<T> sourceContext,
	Map<KafkaTopicPartition, Long> assignedPartitionsWithInitialOffsets,
	SerializedValue<WatermarkStrategy<T>> watermarkStrategy,
	StreamingRuntimeContext runtimeContext,
	OffsetCommitMode offsetCommitMode,
	MetricGroup consumerMetricGroup,
	boolean useMetrics) throws Exception {

	// make sure that auto commit is disabled when our offset commit mode is ON_CHECKPOINTS;
	// this overwrites whatever setting the user configured in the properties
	adjustAutoCommitConfig(properties, offsetCommitMode);

	return new KafkaFetcher<>(
		sourceContext,
		assignedPartitionsWithInitialOffsets,
		watermarkStrategy,
		runtimeContext.getProcessingTimeService(),
		runtimeContext.getExecutionConfig().getAutoWatermarkInterval(),
		runtimeContext.getUserCodeClassLoader(),
		runtimeContext.getTaskNameWithSubtasks(),
		deserializer,
		properties,
		pollTimeout,
		runtimeContext.getMetricGroup(),
		consumerMetricGroup,
		useMetrics);
}
 
Example 9
Source File: FlinkKafkaConsumer010.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected AbstractFetcher<T, ?> createFetcher(
		SourceContext<T> sourceContext,
		Map<KafkaTopicPartition, Long> assignedPartitionsWithInitialOffsets,
		SerializedValue<WatermarkStrategy<T>> watermarkStrategy,
		StreamingRuntimeContext runtimeContext,
		OffsetCommitMode offsetCommitMode,
		MetricGroup consumerMetricGroup,
		boolean useMetrics) throws Exception {

	// make sure that auto commit is disabled when our offset commit mode is ON_CHECKPOINTS;
	// this overwrites whatever setting the user configured in the properties
	adjustAutoCommitConfig(properties, offsetCommitMode);

	// If a rateLimiter is set, then call rateLimiter.open() with the runtime context.
	if (rateLimiter != null) {
		rateLimiter.open(runtimeContext);
	}

	return new Kafka010Fetcher<>(
			sourceContext,
			assignedPartitionsWithInitialOffsets,
			watermarkStrategy,
			runtimeContext.getProcessingTimeService(),
			runtimeContext.getExecutionConfig().getAutoWatermarkInterval(),
			runtimeContext.getUserCodeClassLoader(),
			runtimeContext.getTaskNameWithSubtasks(),
			deserializer,
			properties,
			pollTimeout,
			runtimeContext.getMetricGroup(),
			consumerMetricGroup,
			useMetrics,
			rateLimiter);
}
 
Example 10
Source File: StickyAllocationAndLocalRecoveryTestJob.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void initializeState(FunctionInitializationContext functionInitializationContext) throws Exception {
	ValueStateDescriptor<String> stateDescriptor =
		new ValueStateDescriptor<>("state", String.class);
	valueState = functionInitializationContext.getKeyedStateStore().getState(stateDescriptor);

	ListStateDescriptor<MapperSchedulingAndFailureInfo> mapperInfoStateDescriptor =
		new ListStateDescriptor<>("mapperState", MapperSchedulingAndFailureInfo.class);
	schedulingAndFailureState =
		functionInitializationContext.getOperatorStateStore().getUnionListState(mapperInfoStateDescriptor);

	StreamingRuntimeContext runtimeContext = (StreamingRuntimeContext) getRuntimeContext();
	String allocationID = runtimeContext.getAllocationIDAsString();

	final int thisJvmPid = getJvmPid();
	final Set<Integer> killedJvmPids = new HashSet<>();

	// here we check if the sticky scheduling worked as expected
	if (functionInitializationContext.isRestored()) {
		Iterable<MapperSchedulingAndFailureInfo> iterable = schedulingAndFailureState.get();
		String taskNameWithSubtasks = runtimeContext.getTaskNameWithSubtasks();

		MapperSchedulingAndFailureInfo infoForThisTask = null;
		List<MapperSchedulingAndFailureInfo> completeInfo = new ArrayList<>();
		if (iterable != null) {
			for (MapperSchedulingAndFailureInfo testInfo : iterable) {

				completeInfo.add(testInfo);

				if (taskNameWithSubtasks.equals(testInfo.taskNameWithSubtask)) {
					infoForThisTask = testInfo;
				}

				if (testInfo.killedJvm) {
					killedJvmPids.add(testInfo.jvmPid);
				}
			}
		}

		Preconditions.checkNotNull(infoForThisTask, "Expected to find info here.");

		if (!isScheduledToCorrectAllocation(infoForThisTask, allocationID, killedJvmPids)) {
			allocationFailureMessage = String.format(
				"Sticky allocation test failed: Subtask %s in attempt %d was rescheduled from allocation %s " +
					"on JVM with PID %d to unexpected allocation %s on JVM with PID %d.\n" +
					"Complete information from before the crash: %s.",
				runtimeContext.getTaskNameWithSubtasks(),
				runtimeContext.getAttemptNumber(),
				infoForThisTask.allocationId,
				infoForThisTask.jvmPid,
				allocationID,
				thisJvmPid,
				completeInfo);
		}
	}

	// We determine which of the subtasks will produce the artificial failure
	boolean failingTask = shouldTaskFailForThisAttempt();

	// We take note of all the meta info that we require to check sticky scheduling in the next re-attempt
	this.currentSchedulingAndFailureInfo = new MapperSchedulingAndFailureInfo(
		failingTask,
		failingTask && killTaskOnFailure,
		thisJvmPid,
		runtimeContext.getTaskNameWithSubtasks(),
		allocationID);

	schedulingAndFailureState.clear();
	schedulingAndFailureState.add(currentSchedulingAndFailureInfo);
}
 
Example 11
Source File: StickyAllocationAndLocalRecoveryTestJob.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void initializeState(FunctionInitializationContext functionInitializationContext) throws Exception {
	ValueStateDescriptor<String> stateDescriptor =
		new ValueStateDescriptor<>("state", String.class);
	valueState = functionInitializationContext.getKeyedStateStore().getState(stateDescriptor);

	ListStateDescriptor<MapperSchedulingAndFailureInfo> mapperInfoStateDescriptor =
		new ListStateDescriptor<>("mapperState", MapperSchedulingAndFailureInfo.class);
	schedulingAndFailureState =
		functionInitializationContext.getOperatorStateStore().getUnionListState(mapperInfoStateDescriptor);

	StreamingRuntimeContext runtimeContext = (StreamingRuntimeContext) getRuntimeContext();
	String allocationID = runtimeContext.getAllocationIDAsString();

	final int thisJvmPid = getJvmPid();
	final Set<Integer> killedJvmPids = new HashSet<>();

	// here we check if the sticky scheduling worked as expected
	if (functionInitializationContext.isRestored()) {
		Iterable<MapperSchedulingAndFailureInfo> iterable = schedulingAndFailureState.get();
		String taskNameWithSubtasks = runtimeContext.getTaskNameWithSubtasks();

		MapperSchedulingAndFailureInfo infoForThisTask = null;
		List<MapperSchedulingAndFailureInfo> completeInfo = new ArrayList<>();
		if (iterable != null) {
			for (MapperSchedulingAndFailureInfo testInfo : iterable) {

				completeInfo.add(testInfo);

				if (taskNameWithSubtasks.equals(testInfo.taskNameWithSubtask)) {
					infoForThisTask = testInfo;
				}

				if (testInfo.killedJvm) {
					killedJvmPids.add(testInfo.jvmPid);
				}
			}
		}

		Preconditions.checkNotNull(infoForThisTask, "Expected to find info here.");

		if (!isScheduledToCorrectAllocation(infoForThisTask, allocationID, killedJvmPids)) {
			allocationFailureMessage = String.format(
				"Sticky allocation test failed: Subtask %s in attempt %d was rescheduled from allocation %s " +
					"on JVM with PID %d to unexpected allocation %s on JVM with PID %d.\n" +
					"Complete information from before the crash: %s.",
				runtimeContext.getTaskNameWithSubtasks(),
				runtimeContext.getAttemptNumber(),
				infoForThisTask.allocationId,
				infoForThisTask.jvmPid,
				allocationID,
				thisJvmPid,
				completeInfo);
		}
	}

	// We determine which of the subtasks will produce the artificial failure
	boolean failingTask = shouldTaskFailForThisAttempt();

	// We take note of all the meta info that we require to check sticky scheduling in the next re-attempt
	this.currentSchedulingAndFailureInfo = new MapperSchedulingAndFailureInfo(
		failingTask,
		failingTask && killTaskOnFailure,
		thisJvmPid,
		runtimeContext.getTaskNameWithSubtasks(),
		allocationID);

	schedulingAndFailureState.clear();
	schedulingAndFailureState.add(currentSchedulingAndFailureInfo);
}
 
Example 12
Source File: StickyAllocationAndLocalRecoveryTestJob.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void initializeState(FunctionInitializationContext functionInitializationContext) throws Exception {
	ValueStateDescriptor<String> stateDescriptor =
		new ValueStateDescriptor<>("state", String.class);
	valueState = functionInitializationContext.getKeyedStateStore().getState(stateDescriptor);

	ListStateDescriptor<MapperSchedulingAndFailureInfo> mapperInfoStateDescriptor =
		new ListStateDescriptor<>("mapperState", MapperSchedulingAndFailureInfo.class);
	schedulingAndFailureState =
		functionInitializationContext.getOperatorStateStore().getUnionListState(mapperInfoStateDescriptor);

	StreamingRuntimeContext runtimeContext = (StreamingRuntimeContext) getRuntimeContext();
	String allocationID = runtimeContext.getAllocationIDAsString();

	final int thisJvmPid = getJvmPid();
	final Set<Integer> killedJvmPids = new HashSet<>();

	// here we check if the sticky scheduling worked as expected
	if (functionInitializationContext.isRestored()) {
		Iterable<MapperSchedulingAndFailureInfo> iterable = schedulingAndFailureState.get();
		String taskNameWithSubtasks = runtimeContext.getTaskNameWithSubtasks();

		MapperSchedulingAndFailureInfo infoForThisTask = null;
		List<MapperSchedulingAndFailureInfo> completeInfo = new ArrayList<>();
		if (iterable != null) {
			for (MapperSchedulingAndFailureInfo testInfo : iterable) {

				completeInfo.add(testInfo);

				if (taskNameWithSubtasks.equals(testInfo.taskNameWithSubtask)) {
					infoForThisTask = testInfo;
				}

				if (testInfo.killedJvm) {
					killedJvmPids.add(testInfo.jvmPid);
				}
			}
		}

		Preconditions.checkNotNull(infoForThisTask, "Expected to find info here.");

		if (!isScheduledToCorrectAllocation(infoForThisTask, allocationID, killedJvmPids)) {
			allocationFailureMessage = String.format(
				"Sticky allocation test failed: Subtask %s in attempt %d was rescheduled from allocation %s " +
					"on JVM with PID %d to unexpected allocation %s on JVM with PID %d.\n" +
					"Complete information from before the crash: %s.",
				runtimeContext.getTaskNameWithSubtasks(),
				runtimeContext.getAttemptNumber(),
				infoForThisTask.allocationId,
				infoForThisTask.jvmPid,
				allocationID,
				thisJvmPid,
				completeInfo);
		}
	}

	// We determine which of the subtasks will produce the artificial failure
	boolean failingTask = shouldTaskFailForThisAttempt();

	// We take note of all the meta info that we require to check sticky scheduling in the next re-attempt
	this.currentSchedulingAndFailureInfo = new MapperSchedulingAndFailureInfo(
		failingTask,
		failingTask && killTaskOnFailure,
		thisJvmPid,
		runtimeContext.getTaskNameWithSubtasks(),
		allocationID);

	schedulingAndFailureState.clear();
	schedulingAndFailureState.add(currentSchedulingAndFailureInfo);
}