Java Code Examples for org.apache.pulsar.client.admin.PulsarAdmin#close()

The following examples show how to use org.apache.pulsar.client.admin.PulsarAdmin#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: V1_AdminApiTest2.java    From pulsar with Apache License 2.0 6 votes vote down vote up
/**
 * It verifies that pulsar with different load-manager generates different load-report and returned by admin-api
 *
 * @throws Exception
 */
@Test
public void testLoadReportApi() throws Exception {

    this.conf.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
    MockedPulsarService mockPulsarSetup1 = new MockedPulsarService(this.conf);
    mockPulsarSetup1.setup();
    PulsarService simpleLoadManager = mockPulsarSetup1.getPulsar();
    PulsarAdmin simpleLoadManagerAdmin = mockPulsarSetup1.getAdmin();
    assertNotNull(simpleLoadManagerAdmin.brokerStats().getLoadReport());

    this.conf.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    MockedPulsarService mockPulsarSetup2 = new MockedPulsarService(this.conf);
    mockPulsarSetup2.setup();
    PulsarService modularLoadManager = mockPulsarSetup2.getPulsar();
    PulsarAdmin modularLoadManagerAdmin = mockPulsarSetup2.getAdmin();
    assertNotNull(modularLoadManagerAdmin.brokerStats().getLoadReport());

    simpleLoadManagerAdmin.close();
    simpleLoadManager.close();
    modularLoadManagerAdmin.close();
    modularLoadManager.close();
    mockPulsarSetup1.cleanup();
    mockPulsarSetup2.cleanup();
}
 
Example 2
Source File: AdminApiTest2.java    From pulsar with Apache License 2.0 6 votes vote down vote up
/**
 * It verifies that pulsar with different load-manager generates different load-report and returned by admin-api
 *
 * @throws Exception
 */
@Test
public void testLoadReportApi() throws Exception {

    this.conf.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
    MockedPulsarService mockPulsarSetup1 = new MockedPulsarService(this.conf);
    mockPulsarSetup1.setup();
    PulsarService simpleLoadManager = mockPulsarSetup1.getPulsar();
    PulsarAdmin simpleLoadManagerAdmin = mockPulsarSetup1.getAdmin();
    assertNotNull(simpleLoadManagerAdmin.brokerStats().getLoadReport());

    this.conf.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    MockedPulsarService mockPulsarSetup2 = new MockedPulsarService(this.conf);
    mockPulsarSetup2.setup();
    PulsarService modularLoadManager = mockPulsarSetup2.getPulsar();
    PulsarAdmin modularLoadManagerAdmin = mockPulsarSetup2.getAdmin();
    assertNotNull(modularLoadManagerAdmin.brokerStats().getLoadReport());

    simpleLoadManagerAdmin.close();
    simpleLoadManager.close();
    modularLoadManagerAdmin.close();
    modularLoadManager.close();
    mockPulsarSetup1.cleanup();
    mockPulsarSetup2.cleanup();
}
 
Example 3
Source File: FlinkPulsarITest.java    From pulsar-flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartFromExternalSubscription() throws Exception {
    String topic = newTopic();
    List<MessageId> mids = sendTypedMessages(topic, SchemaType.INT32, Arrays.asList(
            //  0,   1,   2, 3, 4, 5,  6,  7,  8
            -20, -21, -22, 1, 2, 3, 10, 11, 12), Optional.empty());

    String subName = "sub-1";

    PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(adminUrl).build();

    admin.topics().createSubscription(TopicName.get(topic).toString(), subName, mids.get(3));

    Map<String, Set<Integer>> expectedData = new HashMap<>();
    expectedData.put(topic, new HashSet<>(Arrays.asList(2, 3, 10, 11, 12)));

    StreamExecutionEnvironment see = StreamExecutionEnvironment.getExecutionEnvironment();
    see.getConfig().disableSysoutLogging();
    see.setParallelism(1);

    Properties sourceProps = sourceProperties();
    sourceProps.setProperty(TOPIC_SINGLE_OPTION_KEY, topic);
    DataStream stream = see.addSource(
            new FlinkPulsarRowSource(serviceUrl, adminUrl, sourceProps).setStartFromSubscription(subName));
    stream.flatMap(new CheckAllMessageExist(expectedData, 5)).setParallelism(1);

    TestUtils.tryExecute(see, "start from specific");

    assertTrue(Sets.newHashSet(admin.topics().getSubscriptions(topic)).contains(subName));

    admin.close();
}
 
Example 4
Source File: AdminApiTlsAuthTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
@Override
public void setup() throws Exception {
    conf.setLoadBalancerEnabled(true);
    conf.setBrokerServicePortTls(Optional.of(0));
    conf.setWebServicePortTls(Optional.of(0));
    conf.setTlsCertificateFilePath(getTLSFile("broker.cert"));
    conf.setTlsKeyFilePath(getTLSFile("broker.key-pk8"));
    conf.setTlsTrustCertsFilePath(getTLSFile("ca.cert"));
    conf.setAuthenticationEnabled(true);
    conf.setAuthenticationProviders(
            ImmutableSet.of("org.apache.pulsar.broker.authentication.AuthenticationProviderTls"));
    conf.setSuperUserRoles(ImmutableSet.of("admin", "superproxy"));
    conf.setProxyRoles(ImmutableSet.of("proxy", "superproxy"));
    conf.setAuthorizationEnabled(true);

    conf.setBrokerClientAuthenticationPlugin("org.apache.pulsar.client.impl.auth.AuthenticationTls");
    conf.setBrokerClientAuthenticationParameters(
            String.format("tlsCertFile:%s,tlsKeyFile:%s", getTLSFile("admin.cert"), getTLSFile("admin.key-pk8")));
    conf.setBrokerClientTrustCertsFilePath(getTLSFile("ca.cert"));
    conf.setBrokerClientTlsEnabled(true);

    super.internalSetup();

    PulsarAdmin admin = buildAdminClient("admin");
    admin.clusters().createCluster("test", new ClusterData(brokerUrl.toString()));
    admin.close();
}
 
Example 5
Source File: WebServiceTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
private void setupEnv(boolean enableFilter, String minApiVersion, boolean allowUnversionedClients,
        boolean enableTls, boolean enableAuth, boolean allowInsecure) throws Exception {
    Set<String> providers = new HashSet<>();
    providers.add("org.apache.pulsar.broker.authentication.AuthenticationProviderTls");

    Set<String> roles = new HashSet<>();
    roles.add("client");

    ServiceConfiguration config = new ServiceConfiguration();
    config.setAdvertisedAddress("localhost");
    config.setBrokerServicePort(Optional.of(0));
    config.setWebServicePort(Optional.of(0));
    if (enableTls) {
        config.setWebServicePortTls(Optional.of(0));
    }
    config.setClientLibraryVersionCheckEnabled(enableFilter);
    config.setAuthenticationEnabled(enableAuth);
    config.setAuthenticationProviders(providers);
    config.setAuthorizationEnabled(false);
    config.setSuperUserRoles(roles);
    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");
    config.setAdvertisedAddress("localhost"); // TLS certificate expects localhost
    config.setZookeeperServers("localhost:2181");
    config.setHttpMaxRequestSize(10 * 1024);
    pulsar = spy(new PulsarService(config));
    doReturn(zkFactory).when(pulsar).getZooKeeperClientFactory();
    doReturn(new MockedBookKeeperClientFactory()).when(pulsar).newBookKeeperClientFactory();
    pulsar.start();

    try {
        pulsar.getZkClient().delete("/minApiVersion", -1);
    } catch (Exception ex) {
    }
    pulsar.getZkClient().create("/minApiVersion", minApiVersion.getBytes(), null, CreateMode.PERSISTENT);

    String BROKER_URL_BASE = "http://localhost:" + pulsar.getListenPortHTTP().get();
    String BROKER_URL_BASE_TLS = "https://localhost:" + pulsar.getListenPortHTTPS().orElse(-1);
    String serviceUrl = BROKER_URL_BASE;

    PulsarAdminBuilder adminBuilder = PulsarAdmin.builder();
    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);

        adminBuilder.authentication(AuthenticationTls.class.getName(), authParams).allowTlsInsecureConnection(true);
    }

    BROKER_LOOKUP_URL = BROKER_URL_BASE
            + "/lookup/v2/destination/persistent/my-property/local/my-namespace/my-topic";
    BROKER_LOOKUP_URL_TLS = BROKER_URL_BASE_TLS
            + "/lookup/v2/destination/persistent/my-property/local/my-namespace/my-topic";

    PulsarAdmin pulsarAdmin = adminBuilder.serviceHttpUrl(serviceUrl).build();

    try {
        pulsarAdmin.clusters().createCluster(config.getClusterName(),
                new ClusterData(pulsar.getSafeWebServiceAddress()));
    } catch (ConflictException ce) {
        // This is OK.
    } finally {
        pulsarAdmin.close();
    }
}