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

[fix] Allow setting sourceType in config file #19836

Merged
merged 4 commits into from
Aug 31, 2023
Merged
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 @@ -59,6 +59,7 @@ public class SourceConfig {
private FunctionConfig.ProcessingGuarantees processingGuarantees;
private Resources resources;

private String sourceType;
private String archive;
// Any flags that you want to pass to the runtime.
private String runtimeFlags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ void processArguments() throws Exception {
sinkConfig.setParallelism(parallelism);
}

if (archive != null && sinkType != null) {
if (archive != null && (sinkType != null || sinkConfig.getSinkType() != null)) {
throw new ParameterException("Cannot specify both archive and sink-type");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void processArguments() throws Exception {
sourceConfig.setParallelism(parallelism);
}

if (archive != null && sourceType != null) {
if (archive != null && (sourceType != null || sourceConfig.getSourceType() != null)) {
throw new ParameterException("Cannot specify both archive and source-type");
}

Expand All @@ -447,6 +447,8 @@ void processArguments() throws Exception {

if (sourceType != null) {
sourceConfig.setArchive(validateSourceType(sourceType));
} else if (sourceConfig.getSourceType() != null) {
sourceConfig.setArchive(validateSourceType(sourceConfig.getSourceType()));
}

Resources resources = sourceConfig.getResources();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
*/
package org.apache.pulsar.admin.cli;

import static org.apache.pulsar.common.naming.TopicName.DEFAULT_NAMESPACE;
import static org.apache.pulsar.common.naming.TopicName.PUBLIC_TENANT;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertTrue;

import com.beust.jcommander.ParameterException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
Expand All @@ -35,7 +26,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.util.Map;

import java.util.UUID;
import org.apache.pulsar.admin.cli.utils.CmdUtils;
import org.apache.pulsar.client.admin.PulsarAdmin;
Expand All @@ -51,10 +41,18 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.apache.pulsar.common.naming.TopicName.DEFAULT_NAMESPACE;
import static org.apache.pulsar.common.naming.TopicName.PUBLIC_TENANT;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertTrue;

public class TestCmdSources {

private static final String TENANT = "test-tenant";
private static final String TENANT = "test-tenant";
private static final String NAMESPACE = "test-namespace";
private static final String NAME = "test";
private static final String TOPIC_NAME = "src_topic_1";
Expand Down Expand Up @@ -84,7 +82,6 @@ public class TestCmdSources {

@BeforeMethod
public void setup() throws Exception {

pulsarAdmin = mock(PulsarAdmin.class);
source = mock(Sources.class);
when(pulsarAdmin.sources()).thenReturn(source);
Expand Down Expand Up @@ -414,7 +411,15 @@ public void testBatchSourceConfigMissingDiscoveryTriggererClassName() throws Exc
expectedSourceConfig.setBatchSourceConfig(batchSourceConfig);
testCmdSourceConfigFile(testSourceConfig, expectedSourceConfig);
}


@Test
public void testCmdSourceConfigFileInvalidSourceType() throws Exception {
SourceConfig sourceConfig = getSourceConfig();
sourceConfig.setSourceType("foo");
assertThatThrownBy(() -> testCmdSourceConfigFile(sourceConfig, null))
.hasMessageContaining("Invalid source type 'foo'");
}

public void testCmdSourceConfigFile(SourceConfig testSourceConfig, SourceConfig expectedSourceConfig) throws Exception {

File file = Files.createTempFile("", "").toFile();
Expand Down
Loading