Skip to content

Commit

Permalink
If left unspecified, function tenants and namespaces should have the …
Browse files Browse the repository at this point in the history
…same behavior as topics (apache#1843)

* If left unspecified, function tenants and namespaces should have the same behavior as topics

* Address comments

* Fixed unittest

* Fix Unittest
  • Loading branch information
srkukarni authored and sijie committed May 25, 2018
1 parent e249493 commit 333a75c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void testCreateWithoutTenant() throws Exception {
});

CreateFunction creater = cmd.getCreater();
assertEquals("tenant", creater.getFunctionConfig().getTenant());
assertEquals("public", creater.getFunctionConfig().getTenant());
verify(functions, times(1)).createFunction(any(FunctionDetails.class), anyString());
}

Expand All @@ -228,8 +228,8 @@ public void testCreateWithoutNamespace() throws Exception {
});

CreateFunction creater = cmd.getCreater();
assertEquals("tenant", creater.getFunctionConfig().getTenant());
assertEquals("namespace", creater.getFunctionConfig().getNamespace());
assertEquals("public", creater.getFunctionConfig().getTenant());
assertEquals("default", creater.getFunctionConfig().getNamespace());
verify(functions, times(1)).createFunction(any(FunctionDetails.class), anyString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.isNull;
import static org.apache.bookkeeper.common.concurrent.FutureUtils.result;
import static org.apache.pulsar.common.naming.TopicName.DEFAULT_NAMESPACE;
import static org.apache.pulsar.common.naming.TopicName.PUBLIC_TENANT;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
Expand Down Expand Up @@ -606,21 +608,11 @@ private void inferMissingFunctionName(FunctionConfig functionConfig) {
}

private void inferMissingTenant(FunctionConfig functionConfig) {
try {
String inputTopic = getUniqueInput(functionConfig);
functionConfig.setTenant(TopicName.get(inputTopic).getTenant());
} catch (IllegalArgumentException ex) {
throw new RuntimeException("You need to specify a tenant for the function", ex);
}
functionConfig.setTenant(PUBLIC_TENANT);
}

private void inferMissingNamespace(FunctionConfig functionConfig) {
try {
String inputTopic = getUniqueInput(functionConfig);
functionConfig.setNamespace(TopicName.get(inputTopic).getNamespacePortion());
} catch (IllegalArgumentException ex) {
throw new RuntimeException("You need to specify a namespace for the function");
}
functionConfig.setNamespace(DEFAULT_NAMESPACE);
}

private void inferMissingOutput(FunctionConfig functionConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@

import net.jodah.typetools.TypeResolver;

import static org.apache.pulsar.common.naming.TopicName.DEFAULT_NAMESPACE;
import static org.apache.pulsar.common.naming.TopicName.PUBLIC_TENANT;

@Getter
@Parameters(commandDescription = "Interface for managing Pulsar Sinks (Egress data from Pulsar)")
public class CmdSinks extends CmdBase {
Expand Down Expand Up @@ -182,9 +185,13 @@ void processArguments() throws Exception {

if (null != tenant) {
sinkConfig.setTenant(tenant);
} else if (sinkConfig.getTenant() == null) {
sinkConfig.setTenant(PUBLIC_TENANT);
}
if (null != namespace) {
sinkConfig.setNamespace(namespace);
} else if (sinkConfig.getNamespace() == null) {
sinkConfig.setNamespace(DEFAULT_NAMESPACE);
}
if (null != name) {
sinkConfig.setName(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@

import net.jodah.typetools.TypeResolver;

import static org.apache.pulsar.common.naming.TopicName.DEFAULT_NAMESPACE;
import static org.apache.pulsar.common.naming.TopicName.PUBLIC_TENANT;

@Getter
@Parameters(commandDescription = "Interface for managing Pulsar Source (Ingress data to Pulsar)")
public class CmdSources extends CmdBase {
Expand Down Expand Up @@ -175,9 +178,13 @@ void processArguments() throws Exception {

if (null != tenant) {
sourceConfig.setTenant(tenant);
} else if (sourceConfig.getTenant() == null) {
sourceConfig.setTenant(PUBLIC_TENANT);
}
if (null != namespace) {
sourceConfig.setNamespace(namespace);
} else if (sourceConfig.getNamespace() == null) {
sourceConfig.setNamespace(DEFAULT_NAMESPACE);
}
if (null != name) {
sourceConfig.setName(name);
Expand Down

0 comments on commit 333a75c

Please sign in to comment.