This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 48e4a0b If no clusters are specified, the namespace should by default
use current cluster (#3571)
48e4a0b is described below
commit 48e4a0b52a576dfa8474ed5c6ff467797326f1c7
Author: Matteo Merli <[email protected]>
AuthorDate: Wed Feb 13 17:55:42 2019 -0800
If no clusters are specified, the namespace should by default use current
cluster (#3571)
* If no clusters are specified, the namespace should by default use current
cluster
* Don't apply to v1 local namespaces
* It's better to use the isV2() check instead of isGlobal()
---
.../org/apache/pulsar/broker/admin/impl/NamespacesBase.java | 10 ++++++++--
.../java/org/apache/pulsar/broker/admin/AdminApiTest2.java | 12 ++++++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
index 8a39f1a..cbd512d 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
@@ -30,6 +30,7 @@ import com.google.common.collect.Sets.SetView;
import java.net.URI;
import java.net.URL;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -74,9 +75,9 @@ import org.apache.pulsar.common.policies.data.DispatchRate;
import org.apache.pulsar.common.policies.data.PersistencePolicies;
import org.apache.pulsar.common.policies.data.Policies;
import org.apache.pulsar.common.policies.data.RetentionPolicies;
+import
org.apache.pulsar.common.policies.data.SchemaAutoUpdateCompatibilityStrategy;
import org.apache.pulsar.common.policies.data.SubscribeRate;
import org.apache.pulsar.common.policies.data.SubscriptionAuthMode;
-import
org.apache.pulsar.common.policies.data.SchemaAutoUpdateCompatibilityStrategy;
import org.apache.pulsar.common.util.FutureUtil;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.data.Stat;
@@ -404,7 +405,7 @@ public abstract class NamespacesBase extends AdminResource {
throw new RestException(Status.NOT_IMPLEMENTED, "Authorization is
not enabled");
}
}
-
+
protected Set<String> internalGetNamespaceReplicationClusters() {
if (!namespaceName.isGlobal()) {
throw new RestException(Status.PRECONDITION_FAILED,
@@ -1489,6 +1490,11 @@ public abstract class NamespacesBase extends
AdminResource {
}
private void validatePolicies(NamespaceName ns, Policies policies) {
+ if (ns.isV2() && policies.replication_clusters.isEmpty()) {
+ // Default to local cluster
+ policies.replication_clusters =
Collections.singleton(config().getClusterName());
+ }
+
// Validate cluster names and permissions
policies.replication_clusters.forEach(cluster ->
validateClusterForTenant(ns.getTenant(), cluster));
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java
index 066cb66..5194940 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java
@@ -31,6 +31,7 @@ import com.google.common.collect.Sets;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -903,4 +904,15 @@ public class AdminApiTest2 extends
MockedPulsarServiceBaseTest {
} catch (PulsarAdminException.PreconditionFailedException e) {
}
}
+
+ @Test
+ public void testCreateNamespaceWithNoClusters() throws
PulsarAdminException {
+ String localCluster = pulsar.getConfiguration().getClusterName();
+ String namespace = "prop-xyz/test-ns-with-no-clusters";
+ admin.namespaces().createNamespace(namespace);
+
+ // Global cluster, if there, should be omitted from the results
+
assertEquals(admin.namespaces().getNamespaceReplicationClusters(namespace),
+ Collections.singletonList(localCluster));
+ }
}