forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[package management service] check service status before run commands (…
…apache#12847) ### Motivation `pulsar-admin` runs packages management services commands, but if the broker is not enabled the service, it will throw NPE. The root cause is https://github.com/apache/pulsar/blob/master/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PackagesBase.java#L45-L47, the `PackagesManagement` might be null if the service is not enabled. ### Modifications Check `isEnablePackagesManagement` before each internal request.
- Loading branch information
Showing
5 changed files
with
121 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/v3/PackagesApiNotEnabledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.broker.admin.v3; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.fail; | ||
import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest; | ||
import org.apache.pulsar.client.admin.PulsarAdminException; | ||
import org.apache.pulsar.packages.management.core.common.PackageMetadata; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
@Test(groups = "broker") | ||
public class PackagesApiNotEnabledTest extends MockedPulsarServiceBaseTest { | ||
|
||
@BeforeMethod | ||
@Override | ||
protected void setup() throws Exception { | ||
// not enable Package Management Service | ||
conf.setEnablePackagesManagement(false); | ||
super.internalSetup(); | ||
} | ||
|
||
@AfterMethod(alwaysRun = true) | ||
@Override | ||
protected void cleanup() throws Exception { | ||
super.internalCleanup(); | ||
} | ||
|
||
@Test(timeOut = 60000) | ||
public void testPackagesOperationsWithoutPackagesServiceEnabled() { | ||
// download package api should return 503 Service Unavailable exception | ||
String unknownPackageName = "function://public/default/unknown@v1"; | ||
try { | ||
admin.packages().download(unknownPackageName, "/test/unknown"); | ||
fail("should throw 503 error"); | ||
} catch (PulsarAdminException e) { | ||
assertEquals(503, e.getStatusCode()); | ||
} | ||
|
||
// get metadata api should return 503 Service Unavailable exception | ||
try { | ||
admin.packages().getMetadata(unknownPackageName); | ||
fail("should throw 503 error"); | ||
} catch (PulsarAdminException e) { | ||
assertEquals(503, e.getStatusCode()); | ||
} | ||
|
||
// update metadata api should return 503 Service Unavailable exception | ||
try { | ||
admin.packages().updateMetadata(unknownPackageName, | ||
PackageMetadata.builder().description("unknown").build()); | ||
fail("should throw 503 error"); | ||
} catch (PulsarAdminException e) { | ||
assertEquals(503, e.getStatusCode()); | ||
} | ||
|
||
// list all the packages api should return 503 Service Unavailable exception | ||
try { | ||
admin.packages().listPackages("function", "unknown/unknown"); | ||
fail("should throw 503 error"); | ||
} catch (PulsarAdminException e) { | ||
assertEquals(503, e.getStatusCode()); | ||
} | ||
|
||
// list all the versions api should return 503 Service Unavailable exception | ||
try { | ||
admin.packages().listPackageVersions(unknownPackageName); | ||
fail("should throw 503 error"); | ||
} catch (PulsarAdminException e) { | ||
assertEquals(503, e.getStatusCode()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters