Skip to content

Commit

Permalink
[fix apache#8089] expose PulsarAdmin client through Function Context (a…
Browse files Browse the repository at this point in the history
…pache#9246)

Fixes apache#8089

### Motivation

apache#8089 addressed that making pulsar admin client api calls is conflict with Jersey library. This PR expose `PulsarAdmin` client through `Function Context`, so the function implementers can use PulsarAdmin to do whatever they want to do.

### Modifications

- add `getPulsarAdmin()` and `getPulsarAdmin(String clusterName)` in function `Context` 
- add implementation of above interface in `ContextImpl`
- add passing `pulsarWebServiceUrl` to function runtimes
- add passing `pulsarWebServiceUrl` to `LocalRunner` / `JavaInstanceStarter`
- add `"--web-service-url"` parameter to `LocalRunner` admin command
- add unit tests
- add example function
- add `exposeAdminClientEnabled` in `functions_worker.yml`
  • Loading branch information
freeznet authored Feb 2, 2021
1 parent 562b2e7 commit 0469dfe
Show file tree
Hide file tree
Showing 70 changed files with 880 additions and 87 deletions.
2 changes: 2 additions & 0 deletions conf/functions_worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ assignmentWriteMaxRetries: 60
instanceLivenessCheckFreqMs: 30000
# Frequency how often worker performs compaction on function-topics
topicCompactionFrequencySec: 1800
# should the function context have pulsar admin client exposed? Default is disabled.
exposeAdminClientEnabled: false


###############################
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,7 @@ flexible messaging model and an intuitive client API.</description>
<module>pulsar-client</module>
<module>pulsar-client-shaded</module>
<module>pulsar-client-1x-base</module>
<module>pulsar-client-admin-api</module>
<module>pulsar-client-admin</module>
<module>pulsar-client-admin-shaded</module>
<module>pulsar-client-tools</module>
Expand Down Expand Up @@ -1717,6 +1718,7 @@ flexible messaging model and an intuitive client API.</description>
<module>pulsar-broker</module>
<module>pulsar-client-api</module>
<module>pulsar-client</module>
<module>pulsar-client-admin-api</module>
<module>pulsar-client-admin</module>
<module>pulsar-client-tools</module>
<module>pulsar-client-tools-test</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.apache.pulsar.broker.loadbalance.impl.SimpleResourceUnit;
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.admin.internal.NamespacesImpl;
import org.apache.pulsar.client.admin.internal.PulsarAdminImpl;
import org.apache.pulsar.common.naming.NamespaceName;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.policies.data.AutoFailoverPolicyData;
Expand Down Expand Up @@ -635,7 +636,7 @@ public void testNamespaceBundleAutoSplit() throws Exception {

// fake Namespaces Admin
NamespacesImpl namespaceAdmin = mock(NamespacesImpl.class);
setObjectField(PulsarAdmin.class, pulsarServices[0].getAdminClient(), "namespaces", namespaceAdmin);
setObjectField(PulsarAdminImpl.class, pulsarServices[0].getAdminClient(), "namespaces", namespaceAdmin);

// create load report
// namespace 01~09 need to be split
Expand Down
1 change: 1 addition & 0 deletions pulsar-client-admin-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
73 changes: 73 additions & 0 deletions pulsar-client-admin-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar</artifactId>
<version>2.8.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>pulsar-client-admin-api</artifactId>
<name>Pulsar Client Admin :: API</name>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>pulsar-common</artifactId>
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>pulsar-client-original</artifactId>
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>pulsar-package-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>checkstyle</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.client.admin;

import java.io.Closeable;
import org.apache.pulsar.client.admin.utils.DefaultImplementation;
import org.apache.pulsar.client.impl.conf.ClientConfigurationData;
import org.apache.pulsar.common.classification.InterfaceAudience;
import org.apache.pulsar.common.classification.InterfaceStability;

@InterfaceAudience.Public
@InterfaceStability.Stable
public interface PulsarAdmin extends Closeable {

/**
* Get a new builder instance that can used to configure and build a {@link PulsarAdmin} instance.
*
* @return the {@link PulsarAdminBuilder}
*
*/
static PulsarAdminBuilder builder() {
return DefaultImplementation.newAdminClientBuilder();
}

/**
* @return the clusters management object
*/
Clusters clusters();

/**
* @return the brokers management object
*/
Brokers brokers();

/**
* @return the tenants management object
*/
Tenants tenants();

/**
*
* @deprecated since 2.0. See {@link #tenants()}
*/
@Deprecated
Properties properties();

/**
* @return the namespaces management object
*/
Namespaces namespaces();

/**
* @return the topics management object
*/
Topics topics();

/**
* @return the bookies management object
*/
Bookies bookies();

/**
* @return the persistentTopics management object
* @deprecated Since 2.0. See {@link #topics()}
*/
@Deprecated
NonPersistentTopics nonPersistentTopics();

/**
* @return the resource quota management object
*/
ResourceQuotas resourceQuotas();

/**
* @return does a looks up for the broker serving the topic
*/
Lookup lookups();

/**
*
* @return the functions management object
*/
Functions functions();

/**
* @return the sources management object
* @deprecated in favor of {@link #sources()}
*/
@Deprecated
Source source();

/**
* @return the sources management object
*/
Sources sources();

/**
* @return the sinks management object
* @deprecated in favor of {@link #sinks}
*/
@Deprecated
Sink sink();

/**
* @return the sinks management object
*/
Sinks sinks();

/**
* @return the Worker stats
*/
Worker worker();

/**
* @return the broker statics
*/
BrokerStats brokerStats();

/**
* @return the proxy statics
*/
ProxyStats proxyStats();

/**
* @return the service HTTP URL that is being used
*/
String getServiceUrl();

/**
* @return the client Configuration Data that is being used
*/
ClientConfigurationData getClientConfigData();

/**
* @return the schemas
*/
Schemas schemas();

/**
* @return the packages management object
*/
Packages packages();

/**
* Close the PulsarAdminClient and release all the resources.
*
*/
@Override
void close();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.client.admin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.client.admin.utils;

import lombok.experimental.UtilityClass;
import org.apache.pulsar.client.admin.PulsarAdminBuilder;

/**
* Helper class for class instantiations and it also contains methods to work with schemas.
*/
@SuppressWarnings("unchecked")
@UtilityClass
public class DefaultImplementation {
private static final Class<PulsarAdminBuilder> ADMIN_CLIENT_BUILDER_IMPL = ReflectionUtils.newClassInstance(
"org.apache.pulsar.client.admin.internal.PulsarAdminBuilderImpl");

public static PulsarAdminBuilder newAdminClientBuilder() {
return ReflectionUtils.catchExceptions(() -> ADMIN_CLIENT_BUILDER_IMPL.newInstance());
}
}
Loading

0 comments on commit 0469dfe

Please sign in to comment.