Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle web application exception to redirect request #9228

Merged
merged 3 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,9 @@ protected void internalDeleteNamespaceBundle(String bundleRange, boolean authori
throw new RestException(e);
}

NamespaceBundle bundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange,
authoritative, true);
try {
NamespaceBundle bundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange,
authoritative, true);
List<String> topics = pulsar().getNamespaceService().getListOfPersistentTopics(namespaceName).join();
for (String topic : topics) {
NamespaceBundle topicBundle = pulsar().getNamespaceService()
Expand Down Expand Up @@ -613,10 +613,9 @@ protected void internalDeleteNamespaceBundleForcefully(String bundleRange, boole
throw new RestException(e);
}

NamespaceBundle bundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange,
authoritative, true);

try {
NamespaceBundle bundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange,
authoritative, true);
// directly remove from owned namespace map and ephemeral node from ZK
pulsar().getNamespaceService().removeOwnedServiceUnit(bundle);
} catch (WebApplicationException wae) {
Expand Down Expand Up @@ -1368,8 +1367,15 @@ public void internalUnloadNamespaceBundle(AsyncResponse asyncResponse, String bu
asyncResponse.resume(Response.noContent().build());
return;
}
NamespaceBundle nsBundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange,
NamespaceBundle nsBundle;

try {
nsBundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange,
authoritative, true);
} catch (WebApplicationException wae) {
asyncResponse.resume(wae);
return;
}

pulsar().getNamespaceService().unloadNamespaceBundle(nsBundle)
.thenRun(() -> {
Expand Down Expand Up @@ -1409,8 +1415,6 @@ protected void internalSplitNamespaceBundle(String bundleRange,
}

validatePoliciesReadOnlyAccess();
NamespaceBundle nsBundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange,
authoritative, true);

List<String> supportedNamespaceBundleSplitAlgorithms =
pulsar().getConfig().getSupportedNamespaceBundleSplitAlgorithms();
Expand All @@ -1422,9 +1426,13 @@ protected void internalSplitNamespaceBundle(String bundleRange,
}

try {
NamespaceBundle nsBundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles, bundleRange,
authoritative, true);
pulsar().getNamespaceService().splitAndOwnBundle(nsBundle, unload,
getNamespaceBundleSplitAlgorithmByName(splitAlgorithmName)).get();
getNamespaceBundleSplitAlgorithmByName(splitAlgorithmName)).get();
log.info("[{}] Successfully split namespace bundle {}", clientAppId(), nsBundle.toString());
} catch (WebApplicationException wae) {
throw wae;
} catch (ExecutionException e) {
if (e.getCause() instanceof IllegalArgumentException) {
log.error("[{}] Failed to split namespace bundle {}/{} due to {}", clientAppId(), namespaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ public List<String> getListFromBundle(@PathParam("property") String property, @P
NamespaceName fqnn = NamespaceName.get(property, cluster, namespace);
try {
if (!isBundleOwnedByAnyBroker(fqnn, policies.bundles, bundleRange)
.get(pulsar().getConfig().getZooKeeperOperationTimeoutSeconds(), TimeUnit.SECONDS)) {
.get(pulsar().getConfig().getZooKeeperOperationTimeoutSeconds(), TimeUnit.SECONDS)) {
log.info("[{}] Namespace bundle is not owned by any broker {}/{}/{}/{}", clientAppId(), property,
cluster, namespace, bundleRange);
cluster, namespace, bundleRange);
return null;
}
NamespaceBundle nsBundle = validateNamespaceBundleOwnership(fqnn, policies.bundles, bundleRange,
true, true);
true, true);
final List<String> topicList = Lists.newArrayList();
pulsar().getBrokerService().forEachTopic(topic -> {
TopicName topicName = TopicName.get(topic.getName());
Expand All @@ -281,6 +281,8 @@ public List<String> getListFromBundle(@PathParam("property") String property, @P
}
});
return topicList;
} catch (WebApplicationException wae) {
throw wae;
} catch (Exception e) {
log.error("[{}] Failed to unload namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange, e);
throw new RestException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,14 @@ public void getListFromBundle(
bundleRange);
asyncResponse.resume(Response.noContent().build());
} else {
NamespaceBundle nsBundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles,
NamespaceBundle nsBundle;
try {
nsBundle = validateNamespaceBundleOwnership(namespaceName, policies.bundles,
bundleRange, true, true);
} catch (WebApplicationException wae) {
asyncResponse.resume(wae);
return;
}
try {
final List<String> topicList = Lists.newArrayList();
pulsar().getBrokerService().forEachTopic(topic -> {
Expand Down