Skip to content

Commit

Permalink
[fix][admin] Fix deprecated check (#22653)
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan Liu <nodeces@gmail.com>
  • Loading branch information
nodece committed May 8, 2024
1 parent 3114199 commit 188355b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
Expand Down Expand Up @@ -197,16 +198,16 @@ private void mergeArgs() {
}
}

@Override
public void runCmd() throws Exception {
@VisibleForTesting
List<String> getLocalRunArgs() throws Exception {
// merge deprecated args with new args
mergeArgs();
List<String> localRunArgs = new LinkedList<>();
localRunArgs.add(System.getenv("PULSAR_HOME") + "/bin/function-localrunner");
localRunArgs.add("--sinkConfig");
localRunArgs.add(new Gson().toJson(sinkConfig));
for (Field field : this.getClass().getDeclaredFields()) {
if (field.getName().startsWith("DEPRECATED")) {
if (field.getName().toUpperCase().startsWith("DEPRECATED")) {
continue;
}
if (field.getName().contains("$")) {
Expand All @@ -218,7 +219,12 @@ public void runCmd() throws Exception {
localRunArgs.add(value.toString());
}
}
ProcessBuilder processBuilder = new ProcessBuilder(localRunArgs).inheritIO();
return localRunArgs;
}

@Override
public void runCmd() throws Exception {
ProcessBuilder processBuilder = new ProcessBuilder(getLocalRunArgs()).inheritIO();
Process process = processBuilder.start();
process.waitFor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
Expand Down Expand Up @@ -198,17 +199,16 @@ private void mergeArgs() {
}
}

@Override
public void runCmd() throws Exception {
@VisibleForTesting
List<String> getLocalRunArgs() throws Exception {
// merge deprecated args with new args
mergeArgs();

List<String> localRunArgs = new LinkedList<>();
localRunArgs.add(System.getenv("PULSAR_HOME") + "/bin/function-localrunner");
localRunArgs.add("--sourceConfig");
localRunArgs.add(new Gson().toJson(sourceConfig));
for (Field field : this.getClass().getDeclaredFields()) {
if (field.getName().startsWith("DEPRECATED")) {
if (field.getName().toUpperCase().startsWith("DEPRECATED")) {
continue;
}
if (field.getName().contains("$")) {
Expand All @@ -220,7 +220,12 @@ public void runCmd() throws Exception {
localRunArgs.add(value.toString());
}
}
ProcessBuilder processBuilder = new ProcessBuilder(localRunArgs).inheritIO();
return localRunArgs;
}

@Override
public void runCmd() throws Exception {
ProcessBuilder processBuilder = new ProcessBuilder(getLocalRunArgs()).inheritIO();
Process process = processBuilder.start();
process.waitFor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertFalse;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import java.io.Closeable;
Expand All @@ -37,6 +38,7 @@
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.admin.cli.CmdSinks.LocalSinkRunner;
import org.apache.pulsar.admin.cli.utils.CmdUtils;
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.Sinks;
Expand Down Expand Up @@ -808,4 +810,14 @@ public void testParseConfigs() throws Exception {
Assert.assertEquals(config.get("float_string"), "1000.0");
Assert.assertEquals(config.get("created_at"), "Mon Jul 02 00:33:15 +0000 2018");
}

@Test
public void testExcludeDeprecatedOptions() throws Exception {
SinkConfig testSinkConfig = getSinkConfig();
LocalSinkRunner localSinkRunner = spy(new CmdSinks(() -> pulsarAdmin)).getLocalSinkRunner();
localSinkRunner.sinkConfig = testSinkConfig;
localSinkRunner.deprecatedBrokerServiceUrl = "pulsar://localhost:6650";
List<String> localRunArgs = localSinkRunner.getLocalRunArgs();
assertFalse(String.join(",", localRunArgs).contains("--deprecated"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.pulsar.admin.cli.CmdSources.LocalSourceRunner;
import org.apache.pulsar.admin.cli.utils.CmdUtils;
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.Sources;
Expand Down Expand Up @@ -680,4 +683,14 @@ public void testParseConfigs() throws Exception {
Assert.assertEquals(config.get("float_string"), "1000.0");
Assert.assertEquals(config.get("created_at"), "Mon Jul 02 00:33:15 +0000 2018");
}

@Test
public void testExcludeDeprecatedOptions() throws Exception {
SourceConfig testSinkConfig = getSourceConfig();
LocalSourceRunner localSourceRunner = spy(new CmdSources(() -> pulsarAdmin)).getLocalSourceRunner();
localSourceRunner.sourceConfig = testSinkConfig;
localSourceRunner.deprecatedBrokerServiceUrl = "pulsar://localhost:6650";
List<String> localRunArgs = localSourceRunner.getLocalRunArgs();
assertFalse(String.join(",", localRunArgs).contains("--deprecated"));
}
}

0 comments on commit 188355b

Please sign in to comment.