This is an automated email from the ASF dual-hosted git repository.
lhotari 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 3a069ed07ea [fix][client] Fix async method composition in admin
client's NamespacesImpl (#19397)
3a069ed07ea is described below
commit 3a069ed07ea0e03405b72458a585f93bf95b2d77
Author: Lari Hotari <[email protected]>
AuthorDate: Thu Feb 2 22:20:06 2023 +0200
[fix][client] Fix async method composition in admin client's NamespacesImpl
(#19397)
---
.../org/apache/pulsar/broker/admin/impl/NamespacesBase.java | 7 ++++---
.../java/org/apache/pulsar/broker/admin/NamespacesTest.java | 10 +++-------
.../apache/pulsar/client/admin/internal/NamespacesImpl.java | 4 ++--
3 files changed, 9 insertions(+), 12 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 191dbe962ac..9b93752d5e4 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
@@ -645,9 +645,10 @@ public abstract class NamespacesBase extends AdminResource
{
.thenCompose(__ -> validatePoliciesReadOnlyAccessAsync())
.thenApply(__ -> {
checkNotNull(clusterIds, "ClusterIds should not be null");
- if (!namespaceName.isGlobal()) {
- throw new RestException(Status.PRECONDITION_FAILED,
- "Cannot set replication on a non-global
namespace");
+ if (!namespaceName.isGlobal() && !(clusterIds.size() == 1
+ &&
clusterIds.get(0).equals(pulsar().getConfiguration().getClusterName()))) {
+ throw new RestException(Status.PRECONDITION_FAILED,
+ "Cannot set replication on a non-global
namespace");
}
Set<String> replicationClusterSet =
Sets.newHashSet(clusterIds);
if (replicationClusterSet.contains("global")) {
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java
index a0e1cd08db7..5644be406a7 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java
@@ -673,13 +673,9 @@ public class NamespacesTest extends
MockedPulsarServiceBaseTest {
assertEquals(e.getResponse().getStatus(),
Status.PRECONDITION_FAILED.getStatusCode());
}
- try {
- asyncRequests(rsp ->
namespaces.setNamespaceReplicationClusters(rsp, this.testTenant,
this.testLocalCluster,
- this.testLocalNamespaces.get(0).getLocalName(),
List.of("use")));
- fail("should have failed");
- } catch (RestException e) {
- assertEquals(e.getResponse().getStatus(),
Status.PRECONDITION_FAILED.getStatusCode());
- }
+ // setting the replication clusters for a local namespace to the local
cluster should succeed
+ asyncRequests(rsp -> namespaces.setNamespaceReplicationClusters(rsp,
this.testTenant, this.testLocalCluster,
+ this.testLocalNamespaces.get(0).getLocalName(),
List.of(this.testLocalCluster)));
// cleanup
resetBroker();
diff --git
a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/NamespacesImpl.java
b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/NamespacesImpl.java
index fa3155c59d6..59f0ef3b347 100644
---
a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/NamespacesImpl.java
+++
b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/NamespacesImpl.java
@@ -157,9 +157,9 @@ public class NamespacesImpl extends BaseResource implements
Namespaces {
return asyncPutRequest(path, Entity.entity(policies,
MediaType.APPLICATION_JSON));
} else {
// For V1 API, we pass the BundlesData on creation
- return asyncPutRequest(path, Entity.entity("",
MediaType.APPLICATION_JSON)).thenAccept(ignore -> {
+ return asyncPutRequest(path, Entity.entity("",
MediaType.APPLICATION_JSON)).thenCompose(ignore -> {
// For V1, we need to do it in 2 steps
- setNamespaceReplicationClustersAsync(namespace, clusters);
+ return setNamespaceReplicationClustersAsync(namespace,
clusters);
});
}
}