use of org.apache.pulsar.client.admin.PulsarAdmin in project incubator-pulsar by apache.
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.setAdvertisedAddress("localhost");
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");
}
}
use of org.apache.pulsar.client.admin.PulsarAdmin in project incubator-pulsar by apache.
the class MockedPulsarServiceBaseTest method init.
protected final void init() throws Exception {
mockZookKeeper = createMockZooKeeper();
mockBookKeeper = createMockBookKeeper(mockZookKeeper);
sameThreadOrderedSafeExecutor = new SameThreadOrderedSafeExecutor();
startBroker();
brokerUrl = new URL("http://" + pulsar.getAdvertisedAddress() + ":" + BROKER_WEBSERVICE_PORT);
brokerUrlTls = new URL("https://" + pulsar.getAdvertisedAddress() + ":" + BROKER_WEBSERVICE_PORT_TLS);
admin = spy(new PulsarAdmin(brokerUrl, (Authentication) null));
}
use of org.apache.pulsar.client.admin.PulsarAdmin in project flink by apache.
the class PulsarEmbeddedRuntime method startPulsarService.
private void startPulsarService() throws Exception {
ServiceConfiguration config;
try (FileInputStream inputStream = new FileInputStream(CONFIG_FILE_PATH)) {
config = PulsarConfigurationLoader.create(inputStream, ServiceConfiguration.class);
} catch (IOException e) {
throw new IllegalStateException(e);
}
// Use runtime dynamic ports for broker.
config.setAdvertisedAddress("127.0.0.1");
config.setClusterName("standalone");
// Use random port.
config.setBrokerServicePort(Optional.of(0));
config.setWebServicePort(Optional.of(0));
// Select available port for bookkeeper and zookeeper.
int zkPort = getZkPort();
String zkConnect = "127.0.0.1" + ":" + zkPort;
config.setZookeeperServers(zkConnect);
config.setConfigurationStoreServers(zkConnect);
config.setRunningStandalone(true);
this.pulsarService = new PulsarService(config);
// Start Pulsar Broker.
pulsarService.start();
// Create sample data environment.
String webServiceUrl = getWebServiceUrl();
String brokerUrl = getBrokerUrl();
try (PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(webServiceUrl).build()) {
ClusterData clusterData = ClusterData.builder().serviceUrl(webServiceUrl).brokerServiceUrl(brokerUrl).build();
String cluster = config.getClusterName();
createSampleNameSpace(admin, clusterData, cluster);
// Create default namespace
createNameSpace(admin, cluster, TopicName.PUBLIC_TENANT, TopicName.PUBLIC_TENANT + "/" + TopicName.DEFAULT_NAMESPACE);
// Create Pulsar system namespace
createNameSpace(admin, cluster, SYSTEM_NAMESPACE.getTenant(), SYSTEM_NAMESPACE.toString());
// Enable transaction
if (config.isTransactionCoordinatorEnabled() && !admin.namespaces().getTopics(SYSTEM_NAMESPACE.toString()).contains(TRANSACTION_COORDINATOR_ASSIGN.getPartition(0).toString())) {
admin.topics().createPartitionedTopic(TRANSACTION_COORDINATOR_ASSIGN.toString(), 1);
}
}
}
use of org.apache.pulsar.client.admin.PulsarAdmin in project flink by apache.
the class PulsarSourceReaderFactory method create.
@SuppressWarnings("java:S2095")
public static <OUT> SourceReader<OUT, PulsarPartitionSplit> create(SourceReaderContext readerContext, PulsarDeserializationSchema<OUT> deserializationSchema, SourceConfiguration sourceConfiguration) {
PulsarClient pulsarClient = createClient(sourceConfiguration);
PulsarAdmin pulsarAdmin = createAdmin(sourceConfiguration);
// Create a message queue with the predefined source option.
int queueCapacity = sourceConfiguration.getMessageQueueCapacity();
FutureCompletingBlockingQueue<RecordsWithSplitIds<PulsarMessage<OUT>>> elementsQueue = new FutureCompletingBlockingQueue<>(queueCapacity);
// Create different pulsar source reader by subscription type.
SubscriptionType subscriptionType = sourceConfiguration.getSubscriptionType();
if (subscriptionType == SubscriptionType.Failover || subscriptionType == SubscriptionType.Exclusive) {
// Create a ordered split reader supplier.
Supplier<PulsarOrderedPartitionSplitReader<OUT>> splitReaderSupplier = () -> new PulsarOrderedPartitionSplitReader<>(pulsarClient, pulsarAdmin, sourceConfiguration, deserializationSchema);
return new PulsarOrderedSourceReader<>(elementsQueue, splitReaderSupplier, readerContext, sourceConfiguration, pulsarClient, pulsarAdmin);
} else if (subscriptionType == SubscriptionType.Shared || subscriptionType == SubscriptionType.Key_Shared) {
TransactionCoordinatorClient coordinatorClient = ((PulsarClientImpl) pulsarClient).getTcClient();
if (coordinatorClient == null && !sourceConfiguration.isEnableAutoAcknowledgeMessage()) {
throw new IllegalStateException("Transaction is required but didn't enabled");
}
Supplier<PulsarUnorderedPartitionSplitReader<OUT>> splitReaderSupplier = () -> new PulsarUnorderedPartitionSplitReader<>(pulsarClient, pulsarAdmin, sourceConfiguration, deserializationSchema, coordinatorClient);
return new PulsarUnorderedSourceReader<>(elementsQueue, splitReaderSupplier, readerContext, sourceConfiguration, pulsarClient, pulsarAdmin, coordinatorClient);
} else {
throw new UnsupportedOperationException("This subscription type is not " + subscriptionType + " supported currently.");
}
}
Aggregations