use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.
the class NamespacesTest method testSplitBundleWithUnDividedRange.
@Test
public void testSplitBundleWithUnDividedRange() throws Exception {
URL localWebServiceUrl = new URL(pulsar.getWebServiceAddress());
String bundledNsLocal = "test-bundled-namespace-1";
BundlesData bundleData = new BundlesData(Lists.newArrayList("0x00000000", "0x08375b1a", "0x08375b1b", "0xffffffff"));
createBundledTestNamespaces(this.testProperty, this.testLocalCluster, bundledNsLocal, bundleData);
final NamespaceName testNs = NamespaceName.get(this.testProperty, this.testLocalCluster, bundledNsLocal);
OwnershipCache MockOwnershipCache = spy(pulsar.getNamespaceService().getOwnershipCache());
doNothing().when(MockOwnershipCache).disableOwnership(any(NamespaceBundle.class));
Field ownership = NamespaceService.class.getDeclaredField("ownershipCache");
ownership.setAccessible(true);
ownership.set(pulsar.getNamespaceService(), MockOwnershipCache);
mockWebUrl(localWebServiceUrl, testNs);
// split bundles
try {
namespaces.splitNamespaceBundle(testProperty, testLocalCluster, bundledNsLocal, "0x08375b1a_0x08375b1b", false, false);
} catch (RestException re) {
assertEquals(re.getResponse().getStatus(), Status.PRECONDITION_FAILED.getStatusCode());
}
}
use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.
the class NamespacesTest method testValidateTopicOwnership.
@Test
public void testValidateTopicOwnership() throws Exception {
try {
URL localWebServiceUrl = new URL(pulsar.getWebServiceAddress());
String bundledNsLocal = "test-bundled-namespace-1";
BundlesData bundleData = new BundlesData(Lists.newArrayList("0x00000000", "0xffffffff"));
createBundledTestNamespaces(this.testProperty, this.testLocalCluster, bundledNsLocal, bundleData);
final NamespaceName testNs = NamespaceName.get(this.testProperty, this.testLocalCluster, bundledNsLocal);
OwnershipCache MockOwnershipCache = spy(pulsar.getNamespaceService().getOwnershipCache());
doNothing().when(MockOwnershipCache).disableOwnership(any(NamespaceBundle.class));
Field ownership = NamespaceService.class.getDeclaredField("ownershipCache");
ownership.setAccessible(true);
ownership.set(pulsar.getNamespaceService(), MockOwnershipCache);
TopicName topicName = TopicName.get(testNs.getPersistentTopicName("my-topic"));
PersistentTopics topics = spy(new PersistentTopics());
topics.setServletContext(new MockServletContext());
topics.setPulsar(pulsar);
doReturn(false).when(topics).isRequestHttps();
doReturn("test").when(topics).clientAppId();
mockWebUrl(localWebServiceUrl, testNs);
doReturn("persistent").when(topics).domain();
try {
topics.validateTopicName(topicName.getProperty(), topicName.getCluster(), topicName.getNamespacePortion(), topicName.getEncodedLocalName());
topics.validateAdminOperationOnTopic(false);
} catch (RestException e) {
fail("validateAdminAccessOnProperty failed");
}
} catch (RestException e) {
fail("validateAdminAccessOnProperty failed");
}
}
use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.
the class NamespaceBundleFactory method onUpdate.
@Override
public void onUpdate(String path, LocalPolicies data, Stat stat) {
final NamespaceName namespace = NamespaceName.get(getNamespaceFromPoliciesPath(path));
try {
LOG.info("Policy updated for namespace {}, refreshing the bundle cache.", namespace);
// invalidate the bundle cache to fetch new bundle data from the policies
bundlesCache.synchronous().invalidate(namespace);
} catch (Exception e) {
LOG.error("Failed to update the policy change for ns {}", namespace, e);
}
}
use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.
the class NamespaceIsolationPoliciesTest method testBrokerAssignment.
@Test
public void testBrokerAssignment() throws Exception {
NamespaceIsolationPolicies policies = this.getDefaultTestPolicies();
NamespaceName ns = NamespaceName.get("pulsar/use/testns-1");
SortedSet<BrokerStatus> primaryCandidates = new TreeSet<>();
BrokerStatus primary = new BrokerStatus("prod1-broker1.messaging.use.example.com", true, 0);
BrokerStatus secondary = new BrokerStatus("prod1-broker4.use.example.com", true, 0);
BrokerStatus shared = new BrokerStatus("use.example.com", true, 0);
SortedSet<BrokerStatus> secondaryCandidates = new TreeSet<>();
SortedSet<BrokerStatus> sharedCandidates = new TreeSet<>();
policies.assignBroker(ns, primary, primaryCandidates, secondaryCandidates, sharedCandidates);
assertEquals(primaryCandidates.size(), 1);
assertEquals(secondaryCandidates.size(), 0);
assertEquals(sharedCandidates.size(), 0);
assertTrue(primaryCandidates.first().equals(primary));
policies.assignBroker(ns, secondary, primaryCandidates, secondaryCandidates, sharedCandidates);
assertEquals(primaryCandidates.size(), 1);
assertEquals(secondaryCandidates.size(), 1);
assertEquals(sharedCandidates.size(), 0);
assertTrue(secondaryCandidates.first().equals(secondary));
policies.assignBroker(NamespaceName.get("pulsar/use1/testns-1"), shared, primaryCandidates, secondaryCandidates, sharedCandidates);
assertEquals(primaryCandidates.size(), 1);
assertEquals(secondaryCandidates.size(), 1);
assertEquals(sharedCandidates.size(), 1);
assertTrue(sharedCandidates.first().equals(shared));
}
use of org.apache.pulsar.common.naming.NamespaceName in project incubator-pulsar by apache.
the class PulsarService method loadNamespaceTopics.
/**
* Load all the topics contained in a namespace
*
* @param bundle
* <code>NamespaceBundle</code> to identify the service unit
* @throws Exception
*/
public void loadNamespaceTopics(NamespaceBundle bundle) {
executor.submit(() -> {
LOG.info("Loading all topics on bundle: {}", bundle);
NamespaceName nsName = bundle.getNamespaceObject();
List<CompletableFuture<Topic>> persistentTopics = Lists.newArrayList();
long topicLoadStart = System.nanoTime();
for (String topic : getNamespaceService().getListOfTopics(nsName)) {
try {
TopicName topicName = TopicName.get(topic);
if (bundle.includes(topicName)) {
CompletableFuture<Topic> future = brokerService.getTopic(topic);
if (future != null) {
persistentTopics.add(future);
}
}
} catch (Throwable t) {
LOG.warn("Failed to preload topic {}", topic, t);
}
}
if (!persistentTopics.isEmpty()) {
FutureUtil.waitForAll(persistentTopics).thenRun(() -> {
double topicLoadTimeSeconds = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - topicLoadStart) / 1000.0;
LOG.info("Loaded {} topics on {} -- time taken: {} seconds", persistentTopics.size(), bundle, topicLoadTimeSeconds);
});
}
return null;
});
}
Aggregations