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.
Support multi-host for pulsar-admin (apache#4018)
*Motivation* Sometimes the user might have many pulsar brokers but doesn't user load balancer or DNS. So we need support multi-host for pulsar-admin. *Modifications* Use `PulsarServiceNameResolver` to resolve it.
- Loading branch information
Showing
7 changed files
with
204 additions
and
45 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
96 changes: 96 additions & 0 deletions
96
...integration/src/test/java/org/apache/pulsar/tests/integration/cli/AdminMultiHostTest.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,96 @@ | ||
/** | ||
* 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.tests.integration.cli; | ||
|
||
import java.util.UUID; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.FutureTask; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import org.apache.pulsar.client.admin.PulsarAdmin; | ||
import org.apache.pulsar.tests.integration.containers.BrokerContainer; | ||
import org.apache.pulsar.tests.integration.topologies.PulsarCluster; | ||
import org.apache.pulsar.tests.integration.topologies.PulsarClusterSpec; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Test for admin service url is multi host. | ||
*/ | ||
public class AdminMultiHostTest { | ||
|
||
private final String clusterName = "MultiHostTest-" + UUID.randomUUID(); | ||
private final PulsarClusterSpec spec = PulsarClusterSpec.builder().clusterName(clusterName).numBrokers(3).build(); | ||
private PulsarCluster pulsarCluster = null; | ||
|
||
@BeforeMethod | ||
public void setupCluster() throws Exception { | ||
pulsarCluster = PulsarCluster.forSpec(spec); | ||
pulsarCluster.start(); | ||
} | ||
|
||
@AfterMethod | ||
public void tearDownCluster() { | ||
if (pulsarCluster != null) { | ||
pulsarCluster.stop(); | ||
pulsarCluster = null; | ||
} | ||
} | ||
|
||
@Test | ||
public void testAdminMultiHost() throws Exception { | ||
String hosts = pulsarCluster.getAllBrokersHttpServiceUrl(); | ||
PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(hosts).build(); | ||
// all brokers alive | ||
Assert.assertEquals(admin.brokers().getActiveBrokers(clusterName).size(), 3); | ||
|
||
// kill one broker admin should be usable | ||
BrokerContainer one = pulsarCluster.getBroker(0); | ||
// admin.brokers(). | ||
one.stop(); | ||
waitBrokerDown(admin, 2, 60); | ||
Assert.assertEquals(admin.brokers().getActiveBrokers(clusterName).size(), 2); | ||
|
||
// kill another broker | ||
BrokerContainer two = pulsarCluster.getBroker(1); | ||
two.stop(); | ||
waitBrokerDown(admin, 1, 60); | ||
Assert.assertEquals(admin.brokers().getActiveBrokers(clusterName).size(), 1); | ||
} | ||
|
||
// Because zookeeper session timeout is 30ms and ticktime is 2ms, so we need wait more than 32ms | ||
private void waitBrokerDown(PulsarAdmin admin, int expectBrokers, int timeout) | ||
throws InterruptedException, ExecutionException, TimeoutException { | ||
FutureTask<Boolean> futureTask = new FutureTask<>(new Callable<Boolean>() { | ||
@Override | ||
public Boolean call() throws Exception { | ||
while (admin.brokers().getActiveBrokers(clusterName).size() != expectBrokers) { | ||
admin.brokers().healthcheck(); | ||
TimeUnit.MILLISECONDS.sleep(1000); | ||
} | ||
return true; | ||
} | ||
}); | ||
new Thread(futureTask).start(); | ||
futureTask.get(timeout, TimeUnit.SECONDS); | ||
} | ||
} |
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