Search in sources :

Example 6 with ClusterData

use of com.yahoo.pulsar.common.policies.data.ClusterData in project pulsar by yahoo.

the class AdminApiTest method setup.

@BeforeMethod
@Override
public void setup() throws Exception {
    conf.setLoadBalancerEnabled(true);
    super.internalSetup();
    bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
    // create otherbroker to test redirect on calls that need
    // namespace ownership
    ServiceConfiguration otherconfig = new ServiceConfiguration();
    otherconfig.setBrokerServicePort(SECONDARY_BROKER_PORT);
    otherconfig.setWebServicePort(SECONDARY_BROKER_WEBSERVICE_PORT);
    otherconfig.setLoadBalancerEnabled(false);
    otherconfig.setClusterName("test");
    otherPulsar = startBroker(otherconfig);
    otheradmin = new PulsarAdmin(new URL("http://127.0.0.1" + ":" + SECONDARY_BROKER_WEBSERVICE_PORT), (Authentication) null);
    // Setup namespaces
    admin.clusters().createCluster("use", new ClusterData("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT));
    PropertyAdmin propertyAdmin = new PropertyAdmin(Lists.newArrayList("role1", "role2"), Sets.newHashSet("use"));
    admin.properties().createProperty("prop-xyz", propertyAdmin);
    admin.namespaces().createNamespace("prop-xyz/use/ns1");
}
Also used : ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) PropertyAdmin(com.yahoo.pulsar.common.policies.data.PropertyAdmin) Authentication(com.yahoo.pulsar.client.api.Authentication) NamespaceBundleFactory(com.yahoo.pulsar.common.naming.NamespaceBundleFactory) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with ClusterData

use of com.yahoo.pulsar.common.policies.data.ClusterData in project pulsar by yahoo.

the class AdminApiTest method clusters.

@Test
public void clusters() throws Exception {
    admin.clusters().createCluster("usw", new ClusterData("http://broker.messaging.use.example.com" + ":" + BROKER_WEBSERVICE_PORT));
    assertEquals(admin.clusters().getClusters(), Lists.newArrayList("use", "usw"));
    assertEquals(admin.clusters().getCluster("use"), new ClusterData("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT));
    admin.clusters().updateCluster("usw", new ClusterData("http://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT));
    assertEquals(admin.clusters().getClusters(), Lists.newArrayList("use", "usw"));
    assertEquals(admin.clusters().getCluster("usw"), new ClusterData("http://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT));
    admin.clusters().updateCluster("usw", new ClusterData("http://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT, "https://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT_TLS));
    assertEquals(admin.clusters().getClusters(), Lists.newArrayList("use", "usw"));
    assertEquals(admin.clusters().getCluster("usw"), new ClusterData("http://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT, "https://new-broker.messaging.usw.example.com" + ":" + BROKER_WEBSERVICE_PORT_TLS));
    admin.clusters().deleteCluster("usw");
    Thread.sleep(300);
    assertEquals(admin.clusters().getClusters(), Lists.newArrayList("use"));
    admin.namespaces().deleteNamespace("prop-xyz/use/ns1");
    admin.clusters().deleteCluster("use");
    assertEquals(admin.clusters().getClusters(), Lists.newArrayList());
    // Check name validation
    try {
        admin.clusters().createCluster("bf!", new ClusterData("http://dummy.messaging.example.com"));
        fail("should have failed");
    } catch (PulsarAdminException e) {
        assertTrue(e instanceof PreconditionFailedException);
    }
}
Also used : ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) PreconditionFailedException(com.yahoo.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 8 with ClusterData

use of com.yahoo.pulsar.common.policies.data.ClusterData in project pulsar by yahoo.

the class PulsarWebResource method validateClusterOwnership.

/**
     * Check if the cluster exists and redirect the call to the owning cluster
     *
     * @param cluster
     *            Cluster name
     * @throws Exception
     *             In case the redirect happens
     */
protected void validateClusterOwnership(String cluster) throws WebApplicationException {
    try {
        ClusterData differentClusterData = getClusterDataIfDifferentCluster(pulsar(), cluster, clientAppId()).get();
        if (differentClusterData != null) {
            URL webUrl;
            if (pulsar.getConfiguration().isTlsEnabled() && !differentClusterData.getServiceUrlTls().isEmpty()) {
                webUrl = new URL(differentClusterData.getServiceUrlTls());
            } else {
                webUrl = new URL(differentClusterData.getServiceUrl());
            }
            URI redirect = UriBuilder.fromUri(uri.getRequestUri()).host(webUrl.getHost()).port(webUrl.getPort()).build();
            if (log.isDebugEnabled()) {
                log.debug("[{}] Redirecting the rest call to {}: cluster={}", clientAppId(), redirect, cluster);
            }
            // redirect to the cluster requested
            throw new WebApplicationException(Response.temporaryRedirect(redirect).build());
        }
    } catch (WebApplicationException wae) {
        throw wae;
    } catch (Exception e) {
        if (e.getCause() instanceof WebApplicationException) {
            throw (WebApplicationException) e.getCause();
        }
        throw new RestException(Status.SERVICE_UNAVAILABLE, String.format("Failed to validate Cluster configuration : cluster=%s  emsg=%s", cluster, e.getMessage()));
    }
}
Also used : ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) WebApplicationException(javax.ws.rs.WebApplicationException) URI(java.net.URI) URL(java.net.URL) KeeperException(org.apache.zookeeper.KeeperException) ExecutionException(java.util.concurrent.ExecutionException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 9 with ClusterData

use of com.yahoo.pulsar.common.policies.data.ClusterData in project pulsar by yahoo.

the class HttpDestinationLookupv2Test method setUp.

@SuppressWarnings("unchecked")
@BeforeMethod
public void setUp() throws Exception {
    pulsar = mock(PulsarService.class);
    ns = mock(NamespaceService.class);
    auth = mock(AuthorizationManager.class);
    mockConfigCache = mock(ConfigurationCacheService.class);
    clustersListCache = mock(ZooKeeperChildrenCache.class);
    clustersCache = mock(ZooKeeperDataCache.class);
    policiesCache = mock(ZooKeeperDataCache.class);
    config = spy(new ServiceConfiguration());
    config.setClusterName("use");
    clusters = new TreeSet<String>();
    clusters.add("use");
    clusters.add("usc");
    clusters.add("usw");
    ClusterData useData = new ClusterData("http://broker.messaging.use.example.com:8080");
    ClusterData uscData = new ClusterData("http://broker.messaging.usc.example.com:8080");
    ClusterData uswData = new ClusterData("http://broker.messaging.usw.example.com:8080");
    doReturn(config).when(pulsar).getConfiguration();
    doReturn(mockConfigCache).when(pulsar).getConfigurationCache();
    doReturn(clustersListCache).when(mockConfigCache).clustersListCache();
    doReturn(clustersCache).when(mockConfigCache).clustersCache();
    doReturn(policiesCache).when(mockConfigCache).policiesCache();
    doReturn(Optional.of(useData)).when(clustersCache).get(AdminResource.path("clusters", "use"));
    doReturn(Optional.of(uscData)).when(clustersCache).get(AdminResource.path("clusters", "usc"));
    doReturn(Optional.of(uswData)).when(clustersCache).get(AdminResource.path("clusters", "usw"));
    doReturn(CompletableFuture.completedFuture(Optional.of(useData))).when(clustersCache).getAsync(AdminResource.path("clusters", "use"));
    doReturn(CompletableFuture.completedFuture(Optional.of(uscData))).when(clustersCache).getAsync(AdminResource.path("clusters", "usc"));
    doReturn(CompletableFuture.completedFuture(Optional.of(uswData))).when(clustersCache).getAsync(AdminResource.path("clusters", "usw"));
    doReturn(clusters).when(clustersListCache).get();
    doReturn(ns).when(pulsar).getNamespaceService();
    BrokerService brokerService = mock(BrokerService.class);
    doReturn(brokerService).when(pulsar).getBrokerService();
    doReturn(auth).when(brokerService).getAuthorizationManager();
    doReturn(new Semaphore(1000)).when(brokerService).getLookupRequestSemaphore();
}
Also used : ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) PulsarService(com.yahoo.pulsar.broker.PulsarService) NamespaceService(com.yahoo.pulsar.broker.namespace.NamespaceService) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) ConfigurationCacheService(com.yahoo.pulsar.broker.cache.ConfigurationCacheService) ZooKeeperChildrenCache(com.yahoo.pulsar.zookeeper.ZooKeeperChildrenCache) AuthorizationManager(com.yahoo.pulsar.broker.authorization.AuthorizationManager) ZooKeeperDataCache(com.yahoo.pulsar.zookeeper.ZooKeeperDataCache) Semaphore(java.util.concurrent.Semaphore) BrokerService(com.yahoo.pulsar.broker.service.BrokerService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 10 with ClusterData

use of com.yahoo.pulsar.common.policies.data.ClusterData in project pulsar by yahoo.

the class BacklogQuotaManagerTest method setup.

@BeforeMethod
void setup() throws Exception {
    try {
        // start local bookie and zookeeper
        bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, 5001);
        bkEnsemble.start();
        // start pulsar service
        config = new ServiceConfiguration();
        config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
        config.setWebServicePort(BROKER_WEBSERVICE_PORT);
        config.setClusterName("usc");
        config.setBrokerServicePort(BROKER_SERVICE_PORT);
        config.setAuthorizationEnabled(false);
        config.setAuthenticationEnabled(false);
        config.setBacklogQuotaCheckIntervalInSeconds(TIME_TO_CHECK_BACKLOG_QUOTA);
        config.setManagedLedgerMaxEntriesPerLedger(5);
        config.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
        pulsar = new PulsarService(config);
        pulsar.start();
        adminUrl = new URL("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT);
        admin = new PulsarAdmin(adminUrl, (Authentication) null);
        admin.clusters().createCluster("usc", new ClusterData(adminUrl.toString()));
        admin.properties().createProperty("prop", new PropertyAdmin(Lists.newArrayList("appid1"), Sets.newHashSet("usc")));
        admin.namespaces().createNamespace("prop/usc/ns-quota");
        admin.namespaces().createNamespace("prop/usc/quotahold");
        admin.namespaces().createNamespace("prop/usc/quotaholdasync");
    } catch (Throwable t) {
        LOG.error("Error setting up broker test", t);
        Assert.fail("Broker test setup failed");
    }
}
Also used : ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarService(com.yahoo.pulsar.broker.PulsarService) PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) PropertyAdmin(com.yahoo.pulsar.common.policies.data.PropertyAdmin) Authentication(com.yahoo.pulsar.client.api.Authentication) LocalBookkeeperEnsemble(com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ClusterData (com.yahoo.pulsar.common.policies.data.ClusterData)29 PropertyAdmin (com.yahoo.pulsar.common.policies.data.PropertyAdmin)15 Test (org.testng.annotations.Test)13 PulsarAdminException (com.yahoo.pulsar.client.admin.PulsarAdminException)8 URL (java.net.URL)8 MockedPulsarServiceBaseTest (com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)7 PulsarService (com.yahoo.pulsar.broker.PulsarService)6 ServiceConfiguration (com.yahoo.pulsar.broker.ServiceConfiguration)6 PulsarAdmin (com.yahoo.pulsar.client.admin.PulsarAdmin)6 URI (java.net.URI)5 RestException (com.yahoo.pulsar.broker.web.RestException)4 AuthenticationTls (com.yahoo.pulsar.client.impl.auth.AuthenticationTls)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 KeeperException (org.apache.zookeeper.KeeperException)4 PulsarServerException (com.yahoo.pulsar.broker.PulsarServerException)3 AuthorizationManager (com.yahoo.pulsar.broker.authorization.AuthorizationManager)3 Authentication (com.yahoo.pulsar.client.api.Authentication)3 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)3 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)3