Java Code Examples for org.apache.flink.runtime.operators.util.TaskConfig#setDriverStrategy()

The following examples show how to use org.apache.flink.runtime.operators.util.TaskConfig#setDriverStrategy() . 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: ChainedOperatorsMetricTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void addChainedOperator() {
	final TaskConfig chainedConfig = new TaskConfig(new Configuration());

	// input
	chainedConfig.addInputToGroup(0);
	chainedConfig.setInputSerializer(serFact, 0);

	// output
	chainedConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
	chainedConfig.setOutputSerializer(serFact);

	// driver
	chainedConfig.setDriverStrategy(DriverStrategy.FLAT_MAP);

	// udf
	chainedConfig.setStubWrapper(new UserCodeClassWrapper<>(DuplicatingFlatMapFunction.class));

	getTaskConfig().addChainedTask(ChainedFlatMapDriver.class, chainedConfig, CHAINED_OPERATOR_NAME);
}
 
Example 2
Source File: ChainedOperatorsMetricTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void addChainedOperator() {
	final TaskConfig chainedConfig = new TaskConfig(new Configuration());

	// input
	chainedConfig.addInputToGroup(0);
	chainedConfig.setInputSerializer(serFact, 0);

	// output
	chainedConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
	chainedConfig.setOutputSerializer(serFact);

	// driver
	chainedConfig.setDriverStrategy(DriverStrategy.FLAT_MAP);

	// udf
	chainedConfig.setStubWrapper(new UserCodeClassWrapper<>(DuplicatingFlatMapFunction.class));

	getTaskConfig().addChainedTask(ChainedFlatMapDriver.class, chainedConfig, CHAINED_OPERATOR_NAME);
}
 
Example 3
Source File: ChainedOperatorsMetricTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void addChainedOperator() {
	final TaskConfig chainedConfig = new TaskConfig(new Configuration());

	// input
	chainedConfig.addInputToGroup(0);
	chainedConfig.setInputSerializer(serFact, 0);

	// output
	chainedConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
	chainedConfig.setOutputSerializer(serFact);

	// driver
	chainedConfig.setDriverStrategy(DriverStrategy.FLAT_MAP);

	// udf
	chainedConfig.setStubWrapper(new UserCodeClassWrapper<>(DuplicatingFlatMapFunction.class));

	getTaskConfig().addChainedTask(ChainedFlatMapDriver.class, chainedConfig, CHAINED_OPERATOR_NAME);
}
 
Example 4
Source File: JobGraphGenerator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private JobVertex createDualInputVertex(DualInputPlanNode node) throws CompilerException {
	final String taskName = node.getNodeName();
	final DriverStrategy ds = node.getDriverStrategy();
	final JobVertex vertex = new JobVertex(taskName);
	final TaskConfig config = new TaskConfig(vertex.getConfiguration());
	vertex.setResources(node.getMinResources(), node.getPreferredResources());
	vertex.setInvokableClass( (this.currentIteration != null && node.isOnDynamicPath()) ? IterationIntermediateTask.class : BatchTask.class);
	
	// set user code
	config.setStubWrapper(node.getProgramOperator().getUserCodeWrapper());
	config.setStubParameters(node.getProgramOperator().getParameters());
	
	// set the driver strategy
	config.setDriver(ds.getDriverClass());
	config.setDriverStrategy(ds);
	if (node.getComparator1() != null) {
		config.setDriverComparator(node.getComparator1(), 0);
	}
	if (node.getComparator2() != null) {
		config.setDriverComparator(node.getComparator2(), 1);
	}
	if (node.getPairComparator() != null) {
		config.setDriverPairComparator(node.getPairComparator());
	}
	
	// assign memory, file-handles, etc.
	assignDriverResources(node, config);
	return vertex;
}
 
Example 5
Source File: JobGraphGenerator.java    From flink with Apache License 2.0 5 votes vote down vote up
private JobVertex createDualInputVertex(DualInputPlanNode node) throws CompilerException {
	final String taskName = node.getNodeName();
	final DriverStrategy ds = node.getDriverStrategy();
	final JobVertex vertex = new JobVertex(taskName);
	final TaskConfig config = new TaskConfig(vertex.getConfiguration());
	vertex.setResources(node.getMinResources(), node.getPreferredResources());
	vertex.setInvokableClass( (this.currentIteration != null && node.isOnDynamicPath()) ? IterationIntermediateTask.class : BatchTask.class);
	
	// set user code
	config.setStubWrapper(node.getProgramOperator().getUserCodeWrapper());
	config.setStubParameters(node.getProgramOperator().getParameters());
	
	// set the driver strategy
	config.setDriver(ds.getDriverClass());
	config.setDriverStrategy(ds);
	if (node.getComparator1() != null) {
		config.setDriverComparator(node.getComparator1(), 0);
	}
	if (node.getComparator2() != null) {
		config.setDriverComparator(node.getComparator2(), 1);
	}
	if (node.getPairComparator() != null) {
		config.setDriverPairComparator(node.getPairComparator());
	}
	
	// assign memory, file-handles, etc.
	assignDriverResources(node, config);
	return vertex;
}
 
Example 6
Source File: JobGraphGenerator.java    From flink with Apache License 2.0 5 votes vote down vote up
private JobVertex createDualInputVertex(DualInputPlanNode node) throws CompilerException {
	final String taskName = node.getNodeName();
	final DriverStrategy ds = node.getDriverStrategy();
	final JobVertex vertex = new JobVertex(taskName);
	final TaskConfig config = new TaskConfig(vertex.getConfiguration());
	vertex.setResources(node.getMinResources(), node.getPreferredResources());
	vertex.setInvokableClass( (this.currentIteration != null && node.isOnDynamicPath()) ? IterationIntermediateTask.class : BatchTask.class);
	
	// set user code
	config.setStubWrapper(node.getProgramOperator().getUserCodeWrapper());
	config.setStubParameters(node.getProgramOperator().getParameters());
	
	// set the driver strategy
	config.setDriver(ds.getDriverClass());
	config.setDriverStrategy(ds);
	if (node.getComparator1() != null) {
		config.setDriverComparator(node.getComparator1(), 0);
	}
	if (node.getComparator2() != null) {
		config.setDriverComparator(node.getComparator2(), 1);
	}
	if (node.getPairComparator() != null) {
		config.setDriverPairComparator(node.getPairComparator());
	}
	
	// assign memory, file-handles, etc.
	assignDriverResources(node, config);
	return vertex;
}
 
Example 7
Source File: ChainedAllReduceDriverTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testMapTask() throws Exception {
	final int keyCnt = 100;
	final int valCnt = 20;

	final double memoryFraction = 1.0;

	// environment
	initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
	mockEnv.getExecutionConfig().enableObjectReuse();
	addInput(new UniformRecordGenerator(keyCnt, valCnt, false), 0);
	addOutput(this.outList);

	// chained reduce config
	{
		final TaskConfig reduceConfig = new TaskConfig(new Configuration());

		// input
		reduceConfig.addInputToGroup(0);
		reduceConfig.setInputSerializer(serFact, 0);

		// output
		reduceConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
		reduceConfig.setOutputSerializer(serFact);

		// driver
		reduceConfig.setDriverStrategy(DriverStrategy.ALL_REDUCE);
		reduceConfig.setDriverComparator(compFact, 0);
		reduceConfig.setDriverComparator(compFact, 1);
		reduceConfig.setRelativeMemoryDriver(memoryFraction);

		// udf
		reduceConfig.setStubWrapper(new UserCodeClassWrapper<>(MockReduceStub.class));

		getTaskConfig().addChainedTask(ChainedAllReduceDriver.class, reduceConfig, "reduce");
	}

	// chained map+reduce
	{
		registerTask(FlatMapDriver.class, MockMapStub.class);
		BatchTask<FlatMapFunction<Record, Record>, Record> testTask = new BatchTask<>(mockEnv);

		testTask.invoke();
	}

	int sumTotal = valCnt * keyCnt * (keyCnt - 1) / 2;

	Assert.assertEquals(1, this.outList.size());
	Assert.assertEquals(sumTotal, this.outList.get(0).getField(0, IntValue.class).getValue());
}
 
Example 8
Source File: ChainedAllReduceDriverTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testMapTask() throws Exception {
	final int keyCnt = 100;
	final int valCnt = 20;

	final double memoryFraction = 1.0;

	// environment
	initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
	mockEnv.getExecutionConfig().enableObjectReuse();
	addInput(new UniformRecordGenerator(keyCnt, valCnt, false), 0);
	addOutput(this.outList);

	// chained reduce config
	{
		final TaskConfig reduceConfig = new TaskConfig(new Configuration());

		// input
		reduceConfig.addInputToGroup(0);
		reduceConfig.setInputSerializer(serFact, 0);

		// output
		reduceConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
		reduceConfig.setOutputSerializer(serFact);

		// driver
		reduceConfig.setDriverStrategy(DriverStrategy.ALL_REDUCE);
		reduceConfig.setDriverComparator(compFact, 0);
		reduceConfig.setDriverComparator(compFact, 1);
		reduceConfig.setRelativeMemoryDriver(memoryFraction);

		// udf
		reduceConfig.setStubWrapper(new UserCodeClassWrapper<>(MockReduceStub.class));

		getTaskConfig().addChainedTask(ChainedAllReduceDriver.class, reduceConfig, "reduce");
	}

	// chained map+reduce
	{
		registerTask(FlatMapDriver.class, MockMapStub.class);
		BatchTask<FlatMapFunction<Record, Record>, Record> testTask = new BatchTask<>(mockEnv);

		testTask.invoke();
	}

	int sumTotal = valCnt * keyCnt * (keyCnt - 1) / 2;

	Assert.assertEquals(1, this.outList.size());
	Assert.assertEquals(sumTotal, this.outList.get(0).getField(0, IntValue.class).getValue());
}
 
Example 9
Source File: ChainedAllReduceDriverTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testMapTask() throws Exception {
	final int keyCnt = 100;
	final int valCnt = 20;

	final double memoryFraction = 1.0;

	// environment
	initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
	mockEnv.getExecutionConfig().enableObjectReuse();
	addInput(new UniformRecordGenerator(keyCnt, valCnt, false), 0);
	addOutput(this.outList);

	// chained reduce config
	{
		final TaskConfig reduceConfig = new TaskConfig(new Configuration());

		// input
		reduceConfig.addInputToGroup(0);
		reduceConfig.setInputSerializer(serFact, 0);

		// output
		reduceConfig.addOutputShipStrategy(ShipStrategyType.FORWARD);
		reduceConfig.setOutputSerializer(serFact);

		// driver
		reduceConfig.setDriverStrategy(DriverStrategy.ALL_REDUCE);
		reduceConfig.setDriverComparator(compFact, 0);
		reduceConfig.setDriverComparator(compFact, 1);
		reduceConfig.setRelativeMemoryDriver(memoryFraction);

		// udf
		reduceConfig.setStubWrapper(new UserCodeClassWrapper<>(MockReduceStub.class));

		getTaskConfig().addChainedTask(ChainedAllReduceDriver.class, reduceConfig, "reduce");
	}

	// chained map+reduce
	{
		registerTask(FlatMapDriver.class, MockMapStub.class);
		BatchTask<FlatMapFunction<Record, Record>, Record> testTask = new BatchTask<>(mockEnv);

		testTask.invoke();
	}

	int sumTotal = valCnt * keyCnt * (keyCnt - 1) / 2;

	Assert.assertEquals(1, this.outList.size());
	Assert.assertEquals(sumTotal, this.outList.get(0).getField(0, IntValue.class).getValue());
}