Skip to content

Commit

Permalink
[pulsar-admin] Add remove-subscription-types-enabled command for name…
Browse files Browse the repository at this point in the history
…space (apache#12392)

### Motivation
CLI `bin/pulsar-admin` supports `set-subscription-types-enabled` and `get-subscription-types-enabled` command, but lacks corresponding `remove-subscription-types-enabled` commands,  the purpose of this PR is to add this command.
  • Loading branch information
yuruguo authored and eolivelli committed Nov 29, 2021
1 parent 1839193 commit 452f954
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.pulsar.broker.admin.v2;

import static org.apache.pulsar.common.policies.data.PoliciesUtil.getBundles;
import com.google.common.collect.Sets;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
Expand Down Expand Up @@ -1674,6 +1675,18 @@ public void setSubscriptionTypesEnabled(
internalSetSubscriptionTypesEnabled(subscriptionTypesEnabled);
}

@DELETE
@Path("/{tenant}/{namespace}/subscriptionTypesEnabled")
@ApiOperation(value = " Remove subscription types enabled on a namespace.")
@ApiResponses(value = {
@ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Tenant or Namespace does not exist"),
@ApiResponse(code = 409, message = "Concurrent modification")})
public void removeSubscriptionTypesEnabled(@PathParam("tenant") String tenant,
@PathParam("namespace") String namespace) {
validateNamespaceName(tenant, namespace);
internalSetSubscriptionTypesEnabled(Sets.newHashSet());
}

@GET
@Path("/{tenant}/{namespace}/schemaValidationEnforced")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1698,8 +1698,8 @@ public void testSubscriptionTypesEnabled() throws PulsarAdminException, PulsarCl
}

// clear all namespace subType enabled, add failover to broker.conf and sub with shared will fail
subscriptionTypes.clear();
admin.namespaces().setSubscriptionTypesEnabled(namespace, subscriptionTypes);
admin.namespaces().removeSubscriptionTypesEnabled(namespace);
assertEquals(admin.namespaces().getSubscriptionTypesEnabled(namespace), Sets.newHashSet());
consumerBuilder.subscriptionType(SubscriptionType.Shared);
HashSet<String> subscriptions = new HashSet<>();
subscriptions.add("Failover");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,31 @@ CompletableFuture<Void> setSubscriptionTypesEnabledAsync(String namespace,
*/
CompletableFuture<Set<SubscriptionType>> getSubscriptionTypesEnabledAsync(String namespace);

/**
* Removes the subscriptionTypesEnabled policy for a given namespace.
*
* @param namespace
* Namespace name
*
* @throws NotAuthorizedException
* Don't have admin permission
* @throws NotFoundException
* Namespace does not exist
* @throws PulsarAdminException
* Unexpected error
* @return
*/
void removeSubscriptionTypesEnabled(String namespace) throws PulsarAdminException;

/**
* Removes the subscriptionTypesEnabled policy for a given namespace.
*
* @param namespace
* Namespace name
* @return
*/
CompletableFuture<Void> removeSubscriptionTypesEnabledAsync(String namespace);

/**
* Removes the autoSubscriptionCreation policy for a given namespace.
* <p/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,27 @@ public void failed(Throwable throwable) {
return future;
}

@Override
public void removeSubscriptionTypesEnabled(String namespace) throws PulsarAdminException {
try {
removeSubscriptionTypesEnabledAsync(namespace).get(this.readTimeoutMs, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
throw (PulsarAdminException) e.getCause();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new PulsarAdminException(e);
} catch (TimeoutException e) {
throw new PulsarAdminException.TimeoutException(e);
}
}

@Override
public CompletableFuture<Void> removeSubscriptionTypesEnabledAsync(String namespace) {
NamespaceName ns = NamespaceName.get(namespace);
WebTarget path = namespacePath(ns, "subscriptionTypesEnabled");
return asyncDeleteRequest(path);
}

@Override
public void removeAutoSubscriptionCreation(String namespace) throws PulsarAdminException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ public void namespaces() throws Exception {
namespaces.run(split("get-subscription-types-enabled myprop/clust/ns1"));
verify(mockNamespaces).getSubscriptionTypesEnabled("myprop/clust/ns1");

namespaces.run(split("remove-subscription-types-enabled myprop/clust/ns1"));
verify(mockNamespaces).removeSubscriptionTypesEnabled("myprop/clust/ns1");

namespaces.run(split("get-schema-validation-enforce myprop/clust/ns1 -ap"));
verify(mockNamespaces).getSchemaValidationEnforced("myprop/clust/ns1", true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,18 @@ void run() throws PulsarAdminException {
}
}

@Parameters(commandDescription = "Remove subscription types enabled for a namespace")
private class RemoveSubscriptionTypesEnabled extends CliCommand {
@Parameter(description = "tenant/namespace", required = true)
private java.util.List<String> params;

@Override
void run() throws PulsarAdminException {
String namespace = validateNamespace(params);
getAdmin().namespaces().removeSubscriptionTypesEnabled(namespace);
}
}

@Parameters(commandDescription = "Set Message TTL for a namespace")
private class SetMessageTTL extends CliCommand {
@Parameter(description = "tenant/namespace", required = true)
Expand Down Expand Up @@ -2451,6 +2463,7 @@ public CmdNamespaces(Supplier<PulsarAdmin> admin) {

jcommander.addCommand("set-subscription-types-enabled", new SetSubscriptionTypesEnabled());
jcommander.addCommand("get-subscription-types-enabled", new GetSubscriptionTypesEnabled());
jcommander.addCommand("remove-subscription-types-enabled", new RemoveSubscriptionTypesEnabled());

jcommander.addCommand("get-backlog-quotas", new GetBacklogQuotaMap());
jcommander.addCommand("set-backlog-quota", new SetBacklogQuota());
Expand Down

0 comments on commit 452f954

Please sign in to comment.