Search in sources :

Example 16 with PulsarAdmin

use of com.yahoo.pulsar.client.admin.PulsarAdmin in project pulsar by yahoo.

the class PulsarAdminToolTest method persistentTopics.

@Test
void persistentTopics() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    PersistentTopics mockTopics = mock(PersistentTopics.class);
    when(admin.persistentTopics()).thenReturn(mockTopics);
    CmdPersistentTopics topics = new CmdPersistentTopics(admin);
    topics.run(split("delete persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).delete("persistent://myprop/clust/ns1/ds1");
    topics.run(split("list myprop/clust/ns1"));
    verify(mockTopics).getList("myprop/clust/ns1");
    topics.run(split("subscriptions persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getSubscriptions("persistent://myprop/clust/ns1/ds1");
    topics.run(split("unsubscribe persistent://myprop/clust/ns1/ds1 -s sub1"));
    verify(mockTopics).deleteSubscription("persistent://myprop/clust/ns1/ds1", "sub1");
    topics.run(split("stats persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getStats("persistent://myprop/clust/ns1/ds1");
    topics.run(split("stats-internal persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getInternalStats("persistent://myprop/clust/ns1/ds1");
    topics.run(split("partitioned-stats persistent://myprop/clust/ns1/ds1 --per-partition"));
    verify(mockTopics).getPartitionedStats("persistent://myprop/clust/ns1/ds1", true);
    topics.run(split("skip-all persistent://myprop/clust/ns1/ds1 -s sub1"));
    verify(mockTopics).skipAllMessages("persistent://myprop/clust/ns1/ds1", "sub1");
    topics.run(split("skip persistent://myprop/clust/ns1/ds1 -s sub1 -n 100"));
    verify(mockTopics).skipMessages("persistent://myprop/clust/ns1/ds1", "sub1", 100);
    topics.run(split("expire-messages persistent://myprop/clust/ns1/ds1 -s sub1 -t 100"));
    verify(mockTopics).expireMessages("persistent://myprop/clust/ns1/ds1", "sub1", 100);
    topics.run(split("expire-messages-all-subscriptions persistent://myprop/clust/ns1/ds1 -t 100"));
    verify(mockTopics).expireMessagesForAllSubscriptions("persistent://myprop/clust/ns1/ds1", 100);
    topics.run(split("create-partitioned-topic persistent://myprop/clust/ns1/ds1 --partitions 32"));
    verify(mockTopics).createPartitionedTopic("persistent://myprop/clust/ns1/ds1", 32);
    topics.run(split("get-partitioned-topic-metadata persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).getPartitionedTopicMetadata("persistent://myprop/clust/ns1/ds1");
    topics.run(split("delete-partitioned-topic persistent://myprop/clust/ns1/ds1"));
    verify(mockTopics).deletePartitionedTopic("persistent://myprop/clust/ns1/ds1");
    topics.run(split("peek-messages persistent://myprop/clust/ns1/ds1 -s sub1 -n 3"));
    verify(mockTopics).peekMessages("persistent://myprop/clust/ns1/ds1", "sub1", 3);
    // range of +/- 1 second of the expected timestamp
    class TimestampMatcher extends ArgumentMatcher<Long> {

        @Override
        public boolean matches(Object argument) {
            long timestamp = (Long) argument;
            long expectedTimestamp = System.currentTimeMillis() - (1 * 60 * 1000);
            if (timestamp < (expectedTimestamp + 1000) && timestamp > (expectedTimestamp - 1000)) {
                return true;
            }
            return false;
        }
    }
    topics.run(split("reset-cursor persistent://myprop/clust/ns1/ds1 -s sub1 -t 1m"));
    verify(mockTopics).resetCursor(Matchers.eq("persistent://myprop/clust/ns1/ds1"), Matchers.eq("sub1"), Matchers.longThat(new TimestampMatcher()));
}
Also used : PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) ArgumentMatcher(org.mockito.ArgumentMatcher) PersistentTopics(com.yahoo.pulsar.client.admin.PersistentTopics) Test(org.testng.annotations.Test)

Example 17 with PulsarAdmin

use of com.yahoo.pulsar.client.admin.PulsarAdmin in project pulsar by yahoo.

the class NamespaceService method unloadSLANamespace.

public void unloadSLANamespace() throws Exception {
    PulsarAdmin adminClient = null;
    String namespaceName = getSLAMonitorNamespace(host, config);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Trying to unload SLA namespace {}", namespaceName);
    }
    NamespaceBundle nsFullBundle = getFullBundle(new NamespaceName(namespaceName));
    if (!getOwner(nsFullBundle).isPresent()) {
        // No one owns the namespace so no point trying to unload it
        return;
    }
    adminClient = pulsar.getAdminClient();
    adminClient.namespaces().unload(namespaceName);
    LOG.debug("Namespace {} unloaded successfully", namespaceName);
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin)

Example 18 with PulsarAdmin

use of com.yahoo.pulsar.client.admin.PulsarAdmin in project pulsar by yahoo.

the class WebServiceTest method setupEnv.

private void setupEnv(boolean enableFilter, String minApiVersion, boolean allowUnversionedClients, boolean enableTls, boolean enableAuth, boolean allowInsecure) throws Exception {
    Set<String> providers = new HashSet<>();
    providers.add("com.yahoo.pulsar.broker.authentication.AuthenticationProviderTls");
    Set<String> roles = new HashSet<>();
    roles.add("client");
    ServiceConfiguration config = new ServiceConfiguration();
    config.setWebServicePort(BROKER_WEBSERVICE_PORT);
    config.setWebServicePortTls(BROKER_WEBSERVICE_PORT_TLS);
    config.setClientLibraryVersionCheckEnabled(enableFilter);
    config.setAuthenticationEnabled(enableAuth);
    config.setAuthenticationProviders(providers);
    config.setAuthorizationEnabled(false);
    config.setClientLibraryVersionCheckAllowUnversioned(allowUnversionedClients);
    config.setSuperUserRoles(roles);
    config.setTlsEnabled(enableTls);
    config.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH);
    config.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH);
    config.setTlsAllowInsecureConnection(allowInsecure);
    config.setTlsTrustCertsFilePath(allowInsecure ? "" : TLS_CLIENT_CERT_FILE_PATH);
    config.setClusterName("local");
    // TLS certificate expects localhost
    config.setAdvertisedAddress("localhost");
    pulsar = spy(new PulsarService(config));
    doReturn(new MockedZooKeeperClientFactoryImpl()).when(pulsar).getZooKeeperClientFactory();
    pulsar.start();
    try {
        pulsar.getZkClient().delete("/minApiVersion", -1);
    } catch (Exception ex) {
    }
    pulsar.getZkClient().create("/minApiVersion", minApiVersion.getBytes(), null, CreateMode.PERSISTENT);
    String serviceUrl = BROKER_URL_BASE;
    ClientConfiguration clientConfig = new ClientConfiguration();
    if (enableTls && enableAuth) {
        serviceUrl = BROKER_URL_BASE_TLS;
        Map<String, String> authParams = new HashMap<>();
        authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH);
        authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH);
        Authentication auth = new AuthenticationTls();
        auth.configure(authParams);
        clientConfig.setAuthentication(auth);
        clientConfig.setUseTls(true);
        clientConfig.setTlsAllowInsecureConnection(true);
    }
    PulsarAdmin pulsarAdmin = new PulsarAdmin(new URL(serviceUrl), clientConfig);
    try {
        pulsarAdmin.clusters().createCluster(config.getClusterName(), new ClusterData(pulsar.getWebServiceAddress()));
    } catch (ConflictException ce) {
    // This is OK.
    } finally {
        pulsarAdmin.close();
    }
}
Also used : PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) HashMap(java.util.HashMap) ConflictException(com.yahoo.pulsar.client.admin.PulsarAdminException.ConflictException) IOException(java.io.IOException) ConflictException(com.yahoo.pulsar.client.admin.PulsarAdminException.ConflictException) URL(java.net.URL) MockedZooKeeperClientFactoryImpl(com.yahoo.pulsar.zookeeper.MockedZooKeeperClientFactoryImpl) AuthenticationTls(com.yahoo.pulsar.client.impl.auth.AuthenticationTls) ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarService(com.yahoo.pulsar.broker.PulsarService) Authentication(com.yahoo.pulsar.client.api.Authentication) ClientConfiguration(com.yahoo.pulsar.client.api.ClientConfiguration) HashSet(java.util.HashSet)

Example 19 with PulsarAdmin

use of com.yahoo.pulsar.client.admin.PulsarAdmin in project pulsar by yahoo.

the class AuthenticatedProducerConsumerTest method internalSetup.

protected final void internalSetup(Authentication auth) throws Exception {
    com.yahoo.pulsar.client.api.ClientConfiguration clientConf = new com.yahoo.pulsar.client.api.ClientConfiguration();
    clientConf.setStatsInterval(0, TimeUnit.SECONDS);
    clientConf.setTlsTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH);
    clientConf.setTlsAllowInsecureConnection(true);
    clientConf.setAuthentication(auth);
    clientConf.setUseTls(true);
    admin = spy(new PulsarAdmin(brokerUrlTls, clientConf));
    String lookupUrl = new URI("pulsar+ssl://localhost:" + BROKER_PORT_TLS).toString();
    pulsarClient = PulsarClient.create(lookupUrl, clientConf);
}
Also used : PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) URI(java.net.URI)

Example 20 with PulsarAdmin

use of com.yahoo.pulsar.client.admin.PulsarAdmin in project pulsar by yahoo.

the class PulsarService method getAdminClient.

public synchronized PulsarAdmin getAdminClient() throws PulsarServerException {
    if (this.adminClient == null) {
        try {
            String adminApiUrl = webAddress(config);
            this.adminClient = new PulsarAdmin(new URL(adminApiUrl), this.getConfiguration().getBrokerClientAuthenticationPlugin(), this.getConfiguration().getBrokerClientAuthenticationParameters());
            LOG.info("Admin api url: " + adminApiUrl);
        } catch (Exception e) {
            throw new PulsarServerException(e);
        }
    }
    return this.adminClient;
}
Also used : PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) URL(java.net.URL) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

PulsarAdmin (com.yahoo.pulsar.client.admin.PulsarAdmin)20 URL (java.net.URL)11 Test (org.testng.annotations.Test)8 Authentication (com.yahoo.pulsar.client.api.Authentication)7 PulsarService (com.yahoo.pulsar.broker.PulsarService)6 ServiceConfiguration (com.yahoo.pulsar.broker.ServiceConfiguration)6 ClusterData (com.yahoo.pulsar.common.policies.data.ClusterData)6 LocalBookkeeperEnsemble (com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble)6 PropertyAdmin (com.yahoo.pulsar.common.policies.data.PropertyAdmin)5 BeforeMethod (org.testng.annotations.BeforeMethod)4 Brokers (com.yahoo.pulsar.client.admin.Brokers)2 PulsarAdminException (com.yahoo.pulsar.client.admin.PulsarAdminException)2 ConflictException (com.yahoo.pulsar.client.admin.PulsarAdminException.ConflictException)2 IOException (java.io.IOException)2 Clusters (com.yahoo.pulsar.client.admin.Clusters)1 Lookup (com.yahoo.pulsar.client.admin.Lookup)1 Namespaces (com.yahoo.pulsar.client.admin.Namespaces)1 PersistentTopics (com.yahoo.pulsar.client.admin.PersistentTopics)1 Properties (com.yahoo.pulsar.client.admin.Properties)1 NotAuthorizedException (com.yahoo.pulsar.client.admin.PulsarAdminException.NotAuthorizedException)1