|
22 | 22 | import static org.apache.commons.lang3.StringUtils.isBlank;
|
23 | 23 | import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
24 | 24 | import static org.apache.pulsar.broker.resourcegroup.ResourceUsageTransportManager.DISABLE_RESOURCE_USAGE_TRANSPORT_MANAGER;
|
| 25 | +import static org.apache.pulsar.common.naming.NamespaceName.SYSTEM_NAMESPACE; |
25 | 26 | import static org.apache.pulsar.common.naming.SystemTopicNames.isTransactionInternalName;
|
26 | 27 | import com.google.common.annotations.VisibleForTesting;
|
| 28 | +import com.google.common.collect.Sets; |
27 | 29 | import io.netty.channel.ChannelInitializer;
|
28 | 30 | import io.netty.channel.EventLoopGroup;
|
29 | 31 | import io.netty.channel.socket.SocketChannel;
|
|
87 | 89 | import org.apache.pulsar.broker.loadbalance.LoadReportUpdaterTask;
|
88 | 90 | import org.apache.pulsar.broker.loadbalance.LoadResourceQuotaUpdaterTask;
|
89 | 91 | import org.apache.pulsar.broker.loadbalance.LoadSheddingTask;
|
| 92 | +import org.apache.pulsar.broker.loadbalance.extensions.ExtensibleLoadManagerWrapper; |
90 | 93 | import org.apache.pulsar.broker.lookup.v1.TopicLookup;
|
91 | 94 | import org.apache.pulsar.broker.namespace.NamespaceService;
|
92 | 95 | import org.apache.pulsar.broker.protocol.ProtocolHandlers;
|
93 | 96 | import org.apache.pulsar.broker.resourcegroup.ResourceGroupService;
|
94 | 97 | import org.apache.pulsar.broker.resourcegroup.ResourceUsageTopicTransportManager;
|
95 | 98 | import org.apache.pulsar.broker.resourcegroup.ResourceUsageTransportManager;
|
96 | 99 | import org.apache.pulsar.broker.resources.ClusterResources;
|
| 100 | +import org.apache.pulsar.broker.resources.NamespaceResources; |
97 | 101 | import org.apache.pulsar.broker.resources.PulsarResources;
|
| 102 | +import org.apache.pulsar.broker.resources.TenantResources; |
98 | 103 | import org.apache.pulsar.broker.rest.Topics;
|
99 | 104 | import org.apache.pulsar.broker.service.BrokerService;
|
100 | 105 | import org.apache.pulsar.broker.service.PulsarMetadataEventSynchronizer;
|
|
137 | 142 | import org.apache.pulsar.common.naming.NamespaceBundle;
|
138 | 143 | import org.apache.pulsar.common.naming.NamespaceName;
|
139 | 144 | import org.apache.pulsar.common.naming.TopicName;
|
| 145 | +import org.apache.pulsar.common.policies.data.ClusterData; |
140 | 146 | import org.apache.pulsar.common.policies.data.ClusterDataImpl;
|
141 | 147 | import org.apache.pulsar.common.policies.data.OffloadPoliciesImpl;
|
| 148 | +import org.apache.pulsar.common.policies.data.Policies; |
| 149 | +import org.apache.pulsar.common.policies.data.TenantInfo; |
142 | 150 | import org.apache.pulsar.common.protocol.schema.SchemaStorage;
|
143 | 151 | import org.apache.pulsar.common.util.FutureUtil;
|
144 | 152 | import org.apache.pulsar.common.util.GracefulExecutorServicesShutdown;
|
@@ -794,6 +802,12 @@ public void start() throws PulsarServerException {
|
794 | 802 | }
|
795 | 803 | brokerService.start();
|
796 | 804 |
|
| 805 | + if (this.loadManager.get() instanceof ExtensibleLoadManagerWrapper) { |
| 806 | + // Init system namespace for extensible load manager |
| 807 | + this.createNamespaceIfNotExists(this.getConfiguration().getClusterName(), |
| 808 | + SYSTEM_NAMESPACE.getTenant(), SYSTEM_NAMESPACE); |
| 809 | + } |
| 810 | + |
797 | 811 | // Load additional servlets
|
798 | 812 | this.brokerAdditionalServlets = AdditionalServlets.load(config);
|
799 | 813 |
|
@@ -825,6 +839,11 @@ public void start() throws PulsarServerException {
|
825 | 839 | this.webSocketService.setLocalCluster(clusterData);
|
826 | 840 | }
|
827 | 841 |
|
| 842 | + // By starting the Load manager service, the broker will also become visible |
| 843 | + // to the rest of the broker by creating the registration z-node. This needs |
| 844 | + // to be done only when the broker is fully operative. |
| 845 | + this.startLoadManagementService(); |
| 846 | + |
828 | 847 | // Initialize namespace service, after service url assigned. Should init zk and refresh self owner info.
|
829 | 848 | this.nsService.initialize();
|
830 | 849 |
|
@@ -866,11 +885,6 @@ public void start() throws PulsarServerException {
|
866 | 885 |
|
867 | 886 | this.metricsGenerator = new MetricsGenerator(this);
|
868 | 887 |
|
869 |
| - // By starting the Load manager service, the broker will also become visible |
870 |
| - // to the rest of the broker by creating the registration z-node. This needs |
871 |
| - // to be done only when the broker is fully operative. |
872 |
| - this.startLoadManagementService(); |
873 |
| - |
874 | 888 | // Initialize the message protocol handlers.
|
875 | 889 | // start the protocol handlers only after the broker is ready,
|
876 | 890 | // so that the protocol handlers can access broker service properly.
|
@@ -925,6 +939,36 @@ public void start() throws PulsarServerException {
|
925 | 939 | }
|
926 | 940 | }
|
927 | 941 |
|
| 942 | + protected void createNamespaceIfNotExists(String cluster, String publicTenant, NamespaceName ns) throws Exception { |
| 943 | + ClusterResources cr = this.getPulsarResources().getClusterResources(); |
| 944 | + TenantResources tr = this.getPulsarResources().getTenantResources(); |
| 945 | + NamespaceResources nsr = this.getPulsarResources().getNamespaceResources(); |
| 946 | + |
| 947 | + if (!cr.clusterExists(cluster)) { |
| 948 | + cr.createCluster(cluster, |
| 949 | + ClusterData.builder() |
| 950 | + .serviceUrl(this.getWebServiceAddress()) |
| 951 | + .serviceUrlTls(this.getWebServiceAddressTls()) |
| 952 | + .brokerServiceUrl(this.getBrokerServiceUrl()) |
| 953 | + .brokerServiceUrlTls(this.getBrokerServiceUrlTls()) |
| 954 | + .build()); |
| 955 | + } |
| 956 | + |
| 957 | + if (!tr.tenantExists(publicTenant)) { |
| 958 | + tr.createTenant(publicTenant, |
| 959 | + TenantInfo.builder() |
| 960 | + .adminRoles(Sets.newHashSet(config.getSuperUserRoles())) |
| 961 | + .allowedClusters(Sets.newHashSet(cluster)) |
| 962 | + .build()); |
| 963 | + } |
| 964 | + |
| 965 | + if (!nsr.namespaceExists(ns)) { |
| 966 | + Policies nsp = new Policies(); |
| 967 | + nsp.replication_clusters = Collections.singleton(config.getClusterName()); |
| 968 | + nsr.createPolicies(ns, nsp); |
| 969 | + } |
| 970 | + } |
| 971 | + |
928 | 972 | private synchronized void createMetricsServlet() {
|
929 | 973 | this.metricsServlet = new PulsarPrometheusMetricsServlet(
|
930 | 974 | this, config.isExposeTopicLevelMetricsInPrometheus(),
|
@@ -1085,6 +1129,9 @@ protected void closeLocalMetadataStore() throws Exception {
|
1085 | 1129 | }
|
1086 | 1130 |
|
1087 | 1131 | protected void startLeaderElectionService() {
|
| 1132 | + if (this.loadManager.get() instanceof ExtensibleLoadManagerWrapper) { |
| 1133 | + return; |
| 1134 | + } |
1088 | 1135 | this.leaderElectionService = new LeaderElectionService(coordinationService, getSafeWebServiceAddress(),
|
1089 | 1136 | state -> {
|
1090 | 1137 | if (state == LeaderElectionState.Leading) {
|
|
0 commit comments