Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAMZA-2465: Task inputs information lost when enabled RegExTopicGenerator or specified 'task.inputs' explicitly in non-legacy application #1286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import joptsimple.internal.Strings;
import org.apache.commons.lang3.StringUtils;
import org.apache.samza.SamzaException;
import org.apache.samza.config.ApplicationConfig;
Expand Down Expand Up @@ -167,7 +168,23 @@ JobConfig generateJobConfig(JobNode jobNode, String executionPlanJson) {

LOG.info("Job {} has generated configs {}", jobNode.getJobNameAndId(), generatedConfig);

return new JobConfig(mergeConfig(originalConfig, generatedConfig));
// Merge generated task.inputs and original task.inputs together as new task.inputs
Map<String, String> newConfigs = mergeInputs(originalConfig, inputs);

return new JobConfig(mergeConfig(newConfigs, generatedConfig));
}

private Map<String, String> mergeInputs(Config originalConfig, Set<String> inputs) {
Map<String, String> mergedConfigs = new HashMap<>(originalConfig);
if (inputs.isEmpty()) {
return mergedConfigs;
}
String originalInputs = originalConfig.get(TaskConfig.INPUT_STREAMS);
if (!Strings.isNullOrEmpty(originalInputs)) {
inputs.add(originalInputs);
}
mergedConfigs.put(TaskConfig.INPUT_STREAMS, Joiner.on(',').join(inputs));
return mergedConfigs;
}

private Map<String, TableDescriptor> getReachableTables(Collection<OperatorSpec> reachableOperators, JobNode jobNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ String getJobNameAndId() {
}

void configureJobNode(ApplicationDescriptorImpl mockStreamAppDesc) {
configureJobNode(mockStreamAppDesc, mockConfig);
}

void configureJobNode(ApplicationDescriptorImpl mockStreamAppDesc, Config mockConfig) {
JobGraph jobGraph = new ExecutionPlanner(mockConfig, mock(StreamManager.class))
.createJobGraph(mockStreamAppDesc);
mockJobNode = spy(jobGraph.getJobNodes().get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import joptsimple.internal.Strings;
import org.apache.samza.SamzaException;
import org.apache.samza.application.descriptors.StreamApplicationDescriptorImpl;
import org.apache.samza.application.descriptors.TaskApplicationDescriptorImpl;
Expand Down Expand Up @@ -121,6 +122,23 @@ public void testGenerateJobConfigWithTaskApplication() {
validateStreamConfigures(jobConfig, deserializedSerdes);
}

@Test
public void testGenerateJobConfigWithTaskApplicationWhenSpecifiedTaskInputsInConfig() {
Map<String, String> configs = new HashMap<>(mockConfig);
// specify task.inputs in config explicitly
configs.put(TaskConfig.INPUT_STREAMS, "kafka.topic1,kafka.topic2");
MapConfig originConfig = new MapConfig(configs);
TaskApplicationDescriptorImpl taskAppDesc = new TaskApplicationDescriptorImpl(getTaskApplication(), originConfig);
configureJobNode(taskAppDesc, originConfig);
// create the JobGraphConfigureGenerator and generate the jobConfig for the jobNode
JobNodeConfigurationGenerator configureGenerator = new JobNodeConfigurationGenerator();
JobConfig jobConfig = configureGenerator.generateJobConfig(mockJobNode, "testJobGraphJson");

// Verify the results
Config expectedJobConfig = getExpectedJobConfig(originConfig, mockJobNode.getInEdges());
validateJobConfig(expectedJobConfig, jobConfig);
}

@Test
public void testGenerateJobConfigWithLegacyTaskApplication() {
TaskApplicationDescriptorImpl taskAppDesc = new TaskApplicationDescriptorImpl(getLegacyTaskApplication(), mockConfig);
Expand Down Expand Up @@ -274,6 +292,10 @@ private Config getExpectedJobConfig(Config originConfig, Map<String, StreamEdge>
inputs.add(inputEdge.getName());
}
}
String originalInputs = originConfig.get(TaskConfig.INPUT_STREAMS);
if (!Strings.isNullOrEmpty(originalInputs)) {
inputs.add(originalInputs);
}
if (!inputs.isEmpty()) {
configMap.put(TaskConfig.INPUT_STREAMS, Joiner.on(',').join(inputs));
}
Expand Down