Search in sources :

Example 6 with BundlesData

use of org.apache.pulsar.common.policies.data.BundlesData 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());
    }
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) Field(java.lang.reflect.Field) OwnershipCache(org.apache.pulsar.broker.namespace.OwnershipCache) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) RestException(org.apache.pulsar.broker.web.RestException) URL(java.net.URL) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 7 with BundlesData

use of org.apache.pulsar.common.policies.data.BundlesData in project incubator-pulsar by apache.

the class NamespacesTest method testGetBundles.

@Test
public void testGetBundles() throws Exception {
    BundlesData bundle = new BundlesData(Lists.newArrayList("0x00000000", "0x80000000", "0xffffffff"));
    createBundledTestNamespaces(this.testProperty, this.testLocalCluster, "test-bundled-namespace-1", bundle);
    BundlesData responseData = namespaces.getBundlesData(testProperty, this.testLocalCluster, "test-bundled-namespace-1");
    assertEquals(responseData, bundle);
}
Also used : BundlesData(org.apache.pulsar.common.policies.data.BundlesData) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 8 with BundlesData

use of org.apache.pulsar.common.policies.data.BundlesData 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");
    }
}
Also used : NamespaceBundle(org.apache.pulsar.common.naming.NamespaceBundle) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) Field(java.lang.reflect.Field) OwnershipCache(org.apache.pulsar.broker.namespace.OwnershipCache) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) RestException(org.apache.pulsar.broker.web.RestException) PersistentTopics(org.apache.pulsar.broker.admin.v1.PersistentTopics) URL(java.net.URL) TopicName(org.apache.pulsar.common.naming.TopicName) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 9 with BundlesData

use of org.apache.pulsar.common.policies.data.BundlesData in project incubator-pulsar by apache.

the class DiscoveryServiceWebTest method testRiderectUrlWithServerStarted.

@Test
public void testRiderectUrlWithServerStarted() throws Exception {
    // 1. start server
    int port = nextFreePort();
    ServiceConfig config = new ServiceConfig();
    config.setWebServicePort(port);
    ServerManager server = new ServerManager(config);
    DiscoveryZooKeeperClientFactoryImpl.zk = mockZookKeeper;
    Map<String, String> params = new TreeMap<>();
    params.put("zookeeperServers", "dummy-value");
    params.put("zookeeperClientFactoryClass", DiscoveryZooKeeperClientFactoryImpl.class.getName());
    server.addServlet("/", DiscoveryServiceServlet.class, params);
    server.start();
    // 2. create znode for each broker
    List<String> brokers = Lists.newArrayList("broker-1", "broker-2", "broker-3");
    brokers.stream().forEach(b -> {
        try {
            final String broker = b + ":15000";
            LoadReport report = new LoadReport("http://" + broker, null, null, null);
            String reportData = ObjectMapperFactory.getThreadLocal().writeValueAsString(report);
            ZkUtils.createFullPathOptimistic(mockZookKeeper, LOADBALANCE_BROKERS_ROOT + "/" + broker, reportData.getBytes(ZookeeperClientFactoryImpl.ENCODING_SCHEME), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        } catch (KeeperException.NodeExistsException ne) {
        // Ok
        } catch (KeeperException | InterruptedException e) {
            e.printStackTrace();
            fail("failed while creating broker znodes");
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            fail("failed while creating broker znodes");
        }
    });
    String serviceUrl = server.getServiceUri().toString();
    String requestUrl = serviceUrl + "admin/namespaces/p1/c1/n1";
    /**
     * 3. verify : every time when vip receives a request: it redirects to above brokers sequentially and client
     * must get unknown host exception with above brokers in a sequential manner.
     */
    assertEquals(brokers, validateRequest(brokers, HttpMethod.PUT, requestUrl, new BundlesData(1)), "redirection failed");
    assertEquals(brokers, validateRequest(brokers, HttpMethod.GET, requestUrl, null), "redirection failed");
    assertEquals(brokers, validateRequest(brokers, HttpMethod.POST, requestUrl, new BundlesData(1)), "redirection failed");
    server.stop();
}
Also used : ServerManager(org.apache.pulsar.discovery.service.server.ServerManager) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) TreeMap(java.util.TreeMap) ServiceConfig(org.apache.pulsar.discovery.service.server.ServiceConfig) LoadReport(org.apache.pulsar.policies.data.loadbalancer.LoadReport) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) KeeperException(org.apache.zookeeper.KeeperException) Test(org.testng.annotations.Test)

Example 10 with BundlesData

use of org.apache.pulsar.common.policies.data.BundlesData in project incubator-pulsar by apache.

the class PoliciesDataTest method bundlesData.

@Test
void bundlesData() throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper jsonMapper = ObjectMapperFactory.create();
    String newJsonPolicy = "{\"auth_policies\":{\"namespace_auth\":{},\"destination_auth\":{}},\"replication_clusters\":[],\"bundles\":{\"boundaries\":[\"0x00000000\",\"0xffffffff\"]},\"backlog_quota_map\":{},\"persistence\":null,\"latency_stats_sample_rate\":{}}";
    List<String> bundleSet = Lists.newArrayList();
    bundleSet.add("0x00000000");
    bundleSet.add("0xffffffff");
    String newBundlesDataString = "{\"boundaries\":[\"0x00000000\",\"0xffffffff\"]}";
    BundlesData data = jsonMapper.readValue(newBundlesDataString.getBytes(), BundlesData.class);
    assertEquals(data.getBoundaries(), bundleSet);
    Policies policies = jsonMapper.readValue(newJsonPolicy.getBytes(), Policies.class);
    Policies expected = new Policies();
    expected.bundles = data;
    assertEquals(policies, expected);
}
Also used : Policies(org.apache.pulsar.common.policies.data.Policies) BundlesData(org.apache.pulsar.common.policies.data.BundlesData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Aggregations

BundlesData (org.apache.pulsar.common.policies.data.BundlesData)18 Test (org.testng.annotations.Test)14 RestException (org.apache.pulsar.broker.web.RestException)12 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)10 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)8 URL (java.net.URL)7 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)7 Field (java.lang.reflect.Field)5 OwnershipCache (org.apache.pulsar.broker.namespace.OwnershipCache)5 NamespaceBundles (org.apache.pulsar.common.naming.NamespaceBundles)4 LocalPolicies (org.apache.pulsar.common.policies.data.LocalPolicies)3 Policies (org.apache.pulsar.common.policies.data.Policies)3 KeeperException (org.apache.zookeeper.KeeperException)3 MalformedURLException (java.net.MalformedURLException)2 TreeMap (java.util.TreeMap)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)2 PropertyAdmin (org.apache.pulsar.common.policies.data.PropertyAdmin)2 NamespaceIsolationPolicies (org.apache.pulsar.common.policies.impl.NamespaceIsolationPolicies)2 ServerManager (org.apache.pulsar.discovery.service.server.ServerManager)2