use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.
the class PulsarStandaloneStarter method start.
void start() throws Exception {
if (config == null) {
System.exit(1);
}
log.debug("--- setup PulsarStandaloneStarter ---");
if (!onlyBroker) {
// Start LocalBookKeeper
bkEnsemble = new LocalBookkeeperEnsemble(numOfBk, zkPort, bkPort, zkDir, bkDir, wipeData, config.getAdvertisedAddress());
bkEnsemble.startStandalone();
}
if (noBroker) {
return;
}
// load aspectj-weaver agent for instrumentation
AgentLoader.loadAgentClass(Agent.class.getName(), null);
// initialize the functions worker
if (!noFunctionsWorker) {
WorkerConfig workerConfig;
if (isBlank(fnWorkerConfigFile)) {
workerConfig = new WorkerConfig();
} else {
workerConfig = WorkerConfig.load(fnWorkerConfigFile);
}
// worker talks to local broker
workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + config.getBrokerServicePort());
workerConfig.setPulsarWebServiceUrl("http://127.0.0.1:" + config.getWebServicePort());
String hostname = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(config.getAdvertisedAddress());
workerConfig.setWorkerHostname(hostname);
workerConfig.setWorkerId("c-" + config.getClusterName() + "-fw-" + hostname + "-" + workerConfig.getWorkerPort());
fnWorkerService = new WorkerService(workerConfig);
}
// Start Broker
broker = new PulsarService(config, Optional.ofNullable(fnWorkerService));
broker.start();
// Create a sample namespace
URL webServiceUrl = new URL(String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePort()));
final String brokerServiceUrl = String.format("pulsar://%s:%d", config.getAdvertisedAddress(), config.getBrokerServicePort());
admin = new PulsarAdmin(webServiceUrl, config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters());
final String property = "sample";
final String cluster = config.getClusterName();
final String globalCluster = "global";
final String namespace = property + "/" + cluster + "/ns1";
try {
ClusterData clusterData = new ClusterData(webServiceUrl.toString(), null, /* serviceUrlTls */
brokerServiceUrl, null);
if (!admin.clusters().getClusters().contains(cluster)) {
admin.clusters().createCluster(cluster, clusterData);
} else {
admin.clusters().updateCluster(cluster, clusterData);
}
// Create marker for "global" cluster
if (!admin.clusters().getClusters().contains(globalCluster)) {
admin.clusters().createCluster(globalCluster, new ClusterData(null, null));
}
if (!admin.properties().getProperties().contains(property)) {
admin.properties().createProperty(property, new PropertyAdmin(Lists.newArrayList(config.getSuperUserRoles()), Sets.newHashSet(cluster)));
}
if (!admin.namespaces().getNamespaces(property).contains(namespace)) {
admin.namespaces().createNamespace(namespace);
}
} catch (PulsarAdminException e) {
log.info(e.getMessage());
}
if (null != fnWorkerService) {
fnWorkerService.start();
}
log.debug("--- setup completed ---");
}
use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.
the class RawReaderTest method setup.
@BeforeMethod
@Override
public void setup() throws Exception {
super.internalSetup();
admin.clusters().createCluster("use", new ClusterData("http://127.0.0.1:" + BROKER_WEBSERVICE_PORT));
admin.properties().createProperty("my-property", new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet("use")));
admin.namespaces().createNamespace("my-property/use/my-ns");
}
use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.
the class PulsarAdminToolTest method clusters.
@Test
void clusters() throws Exception {
PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
Clusters mockClusters = mock(Clusters.class);
when(admin.clusters()).thenReturn(mockClusters);
CmdClusters clusters = new CmdClusters(admin);
clusters.run(split("list"));
verify(mockClusters).getClusters();
clusters.run(split("get use"));
verify(mockClusters).getCluster("use");
clusters.run(split("create use --url http://my-service.url:8080"));
verify(mockClusters).createCluster("use", new ClusterData("http://my-service.url:8080", null));
clusters.run(split("update use --url http://my-service.url:8080"));
verify(mockClusters).updateCluster("use", new ClusterData("http://my-service.url:8080", null));
clusters.run(split("delete use"));
verify(mockClusters).deleteCluster("use");
clusters.run(split("list-failure-domains use"));
verify(mockClusters).getFailureDomains("use");
clusters.run(split("get-failure-domain use --domain-name domain"));
verify(mockClusters).getFailureDomain("use", "domain");
clusters.run(split("create-failure-domain use --domain-name domain --broker-list b1"));
FailureDomain domain = new FailureDomain();
domain.setBrokers(Sets.newHashSet("b1"));
verify(mockClusters).createFailureDomain("use", "domain", domain);
clusters.run(split("update-failure-domain use --domain-name domain --broker-list b1"));
verify(mockClusters).updateFailureDomain("use", "domain", domain);
clusters.run(split("delete-failure-domain use --domain-name domain"));
verify(mockClusters).deleteFailureDomain("use", "domain");
// Re-create CmdClusters to avoid a issue.
// See https://github.com/cbeust/jcommander/issues/271
clusters = new CmdClusters(admin);
clusters.run(split("create my-cluster --url http://my-service.url:8080 --url-secure https://my-service.url:4443"));
verify(mockClusters).createCluster("my-cluster", new ClusterData("http://my-service.url:8080", "https://my-service.url:4443"));
clusters.run(split("update my-cluster --url http://my-service.url:8080 --url-secure https://my-service.url:4443"));
verify(mockClusters).updateCluster("my-cluster", new ClusterData("http://my-service.url:8080", "https://my-service.url:4443"));
clusters.run(split("delete my-cluster"));
verify(mockClusters).deleteCluster("my-cluster");
clusters.run(split("update-peer-clusters my-cluster --peer-clusters c1,c2"));
verify(mockClusters).updatePeerClusterNames("my-cluster", Sets.newLinkedHashSet(Lists.newArrayList("c1", "c2")));
clusters.run(split("get-peer-clusters my-cluster"));
verify(mockClusters).getPeerClusterNames("my-cluster");
}
use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.
the class BrokerService method getReplicationClient.
public PulsarClient getReplicationClient(String cluster) {
PulsarClient client = replicationClients.get(cluster);
if (client != null) {
return client;
}
return replicationClients.computeIfAbsent(cluster, key -> {
try {
String path = PulsarWebResource.path("clusters", cluster);
ClusterData data = this.pulsar.getConfigurationCache().clustersCache().get(path).orElseThrow(() -> new KeeperException.NoNodeException(path));
ClientBuilder clientBuilder = PulsarClient.builder().enableTcpNoDelay(false).connectionsPerBroker(pulsar.getConfiguration().getReplicationConnectionsPerBroker()).statsInterval(0, TimeUnit.SECONDS);
if (pulsar.getConfiguration().isAuthenticationEnabled()) {
clientBuilder.authentication(pulsar.getConfiguration().getBrokerClientAuthenticationPlugin(), pulsar.getConfiguration().getBrokerClientAuthenticationParameters());
}
if (pulsar.getConfiguration().isReplicationTlsEnabled()) {
clientBuilder.serviceUrl(isNotBlank(data.getBrokerServiceUrlTls()) ? data.getBrokerServiceUrlTls() : data.getServiceUrlTls()).enableTls(true).tlsTrustCertsFilePath(pulsar.getConfiguration().getBrokerClientTrustCertsFilePath()).allowTlsInsecureConnection(pulsar.getConfiguration().isTlsAllowInsecureConnection());
} else {
clientBuilder.serviceUrl(isNotBlank(data.getBrokerServiceUrl()) ? data.getBrokerServiceUrl() : data.getServiceUrl());
}
// Share all the IO threads across broker and client connections
ClientConfigurationData conf = ((ClientBuilderImpl) clientBuilder).getClientConfigurationData();
return new PulsarClientImpl(conf, workerGroup);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.
the class ClustersBase method updateCluster.
@POST
@Path("/{cluster}")
@ApiOperation(value = "Update the configuration for a cluster.", notes = "This operation requires Pulsar super-user privileges.")
@ApiResponses(value = { @ApiResponse(code = 204, message = "Cluster has been updated"), @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Cluster doesn't exist") })
public void updateCluster(@PathParam("cluster") String cluster, ClusterData clusterData) {
validateSuperUserAccess();
validatePoliciesReadOnlyAccess();
try {
String clusterPath = path("clusters", cluster);
Stat nodeStat = new Stat();
byte[] content = globalZk().getData(clusterPath, null, nodeStat);
ClusterData currentClusterData = null;
if (content.length > 0) {
currentClusterData = jsonMapper().readValue(content, ClusterData.class);
// only update cluster-url-data and not overwrite other metadata such as peerClusterNames
currentClusterData.update(clusterData);
} else {
currentClusterData = clusterData;
}
// Write back the new updated ClusterData into zookeeper
globalZk().setData(clusterPath, jsonMapper().writeValueAsBytes(currentClusterData), nodeStat.getVersion());
globalZkCache().invalidate(clusterPath);
log.info("[{}] Updated cluster {}", clientAppId(), cluster);
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to update cluster {}: Does not exist", clientAppId(), cluster);
throw new RestException(Status.NOT_FOUND, "Cluster does not exist");
} catch (Exception e) {
log.error("[{}] Failed to update cluster {}", clientAppId(), cluster, e);
throw new RestException(e);
}
}
Aggregations