Skip to content

Commit 709d41b

Browse files
committed
Add zookeeper-with-patched-admin
1 parent 178634c commit 709d41b

27 files changed

Lines changed: 2570 additions & 6 deletions

File tree

conf/zookeeper.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dataDir=data/zookeeper
3131
clientPort=2181
3232

3333
# the port at which the admin will listen
34-
admin.enableServer=false
34+
admin.enableServer=true
3535
admin.serverPort=9990
3636

3737
# the maximum number of client connections.

distribution/server/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@
133133
<groupId>${project.groupId}</groupId>
134134
<artifactId>pulsar-testclient</artifactId>
135135
<version>${project.version}</version>
136+
<exclusions>
137+
<exclusion>
138+
<groupId>org.apache.zookeeper</groupId>
139+
<artifactId>zookeeper</artifactId>
140+
</exclusion>
141+
</exclusions>
136142
</dependency>
137143

138144
<dependency>

distribution/server/src/assemble/LICENSE.bin.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,6 @@ The Apache Software License, Version 2.0
514514
- io.vertx-vertx-web-4.5.22.jar
515515
- io.vertx-vertx-web-common-4.5.22.jar
516516
* Apache ZooKeeper
517-
- org.apache.zookeeper-zookeeper-3.9.4.jar
518517
- org.apache.zookeeper-zookeeper-jute-3.9.4.jar
519518
* Snappy Java
520519
- org.xerial.snappy-snappy-java-1.1.10.5.jar

jetty-upgrade/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@
3434
<modules>
3535
<module>bookkeeper-prometheus-metrics-provider</module>
3636
<module>zookeeper-prometheus-metrics</module>
37+
<module>zookeeper-with-patched-admin</module>
3738
</modules>
3839
</project>

jetty-upgrade/zookeeper-prometheus-metrics/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<groupId>org.apache.zookeeper</groupId>
3838
<artifactId>zookeeper</artifactId>
3939
<version>${zookeeper.version}</version>
40+
<scope>provided</scope>
4041
</dependency>
4142
<dependency>
4243
<groupId>io.prometheus</groupId>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
21+
-->
22+
<project xmlns="http://maven.apache.org/POM/4.0.0"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
25+
<modelVersion>4.0.0</modelVersion>
26+
<parent>
27+
<groupId>org.apache.pulsar</groupId>
28+
<artifactId>jetty-upgrade</artifactId>
29+
<version>4.2.0-SNAPSHOT</version>
30+
</parent>
31+
32+
<artifactId>zookeeper-with-patched-admin</artifactId>
33+
<name>Apache Pulsar :: patched Apache ZooKeeper with Admin API using Jetty 12.1.x</name>
34+
<description>Apache ZooKeeper with patched admin servlet using Jetty 12.1.x API</description>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>org.apache.zookeeper</groupId>
39+
<artifactId>zookeeper</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.eclipse.jetty</groupId>
43+
<artifactId>jetty-server</artifactId>
44+
<scope>provided</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.eclipse.jetty.ee8</groupId>
48+
<artifactId>jetty-ee8-servlet</artifactId>
49+
<scope>provided</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.github.spotbugs</groupId>
53+
<artifactId>spotbugs-annotations</artifactId>
54+
<scope>provided</scope>
55+
<optional>true</optional>
56+
</dependency>
57+
<dependency>
58+
<groupId>com.fasterxml.jackson.core</groupId>
59+
<artifactId>jackson-databind</artifactId>
60+
<scope>provided</scope>
61+
</dependency>
62+
</dependencies>
63+
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.apache.maven.plugins</groupId>
68+
<artifactId>maven-shade-plugin</artifactId>
69+
<executions>
70+
<execution>
71+
<phase>${shadePluginPhase}</phase>
72+
<goals>
73+
<goal>shade</goal>
74+
</goals>
75+
<configuration>
76+
<createDependencyReducedPom>true</createDependencyReducedPom>
77+
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
78+
<artifactSet>
79+
<includes>
80+
<include>org.apache.zookeeper:zookeeper</include>
81+
</includes>
82+
</artifactSet>
83+
<filters>
84+
<filter>
85+
<artifact>org.apache.zookeeper:zookeeper</artifact>
86+
<includes>
87+
<include>**</include>
88+
</includes>
89+
<excludes>
90+
<exclude>org/apache/zookeeper/server/admin/**</exclude>
91+
</excludes>
92+
</filter>
93+
</filters>
94+
</configuration>
95+
</execution>
96+
</executions>
97+
</plugin>
98+
</plugins>
99+
</build>
100+
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.zookeeper.server.admin;
20+
21+
import org.apache.yetus.audience.InterfaceAudience;
22+
import org.apache.zookeeper.server.ZooKeeperServer;
23+
24+
/**
25+
* Interface for an embedded admin server that runs Commands. There is only one
26+
* functional implementation, JettyAdminServer. DummyAdminServer, which does
27+
* nothing, is used when we do not wish to run a server.
28+
*/
29+
@InterfaceAudience.Public
30+
public interface AdminServer {
31+
32+
void start() throws AdminServerException;
33+
34+
void shutdown() throws AdminServerException;
35+
36+
void setZooKeeperServer(ZooKeeperServer zkServer);
37+
38+
@InterfaceAudience.Public
39+
class AdminServerException extends Exception {
40+
41+
private static final long serialVersionUID = 1L;
42+
43+
public AdminServerException(String message, Throwable cause) {
44+
super(message, cause);
45+
}
46+
47+
public AdminServerException(Throwable cause) {
48+
super(cause);
49+
}
50+
51+
}
52+
53+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.zookeeper.server.admin;
20+
21+
import java.lang.reflect.InvocationTargetException;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
25+
/**
26+
* Factory class for creating an AdminServer.
27+
*/
28+
public class AdminServerFactory {
29+
30+
private static final Logger LOG = LoggerFactory.getLogger(AdminServerFactory.class);
31+
32+
/**
33+
* This method encapsulates the logic for whether we should use a
34+
* JettyAdminServer (i.e., the AdminServer is enabled) or a DummyAdminServer
35+
* (i.e., the AdminServer is disabled). It uses reflection when attempting
36+
* to create a JettyAdminServer, rather than referencing the class directly,
37+
* so that it's ok to omit Jetty from the classpath if a user doesn't wish
38+
* to pull in Jetty with ZooKeeper.
39+
*/
40+
public static AdminServer createAdminServer() {
41+
if (!"false".equals(System.getProperty("zookeeper.admin.enableServer"))) {
42+
try {
43+
Class<?> jettyAdminServerC = Class.forName("org.apache.zookeeper.server.admin.JettyAdminServer");
44+
Object adminServer = jettyAdminServerC.getConstructor().newInstance();
45+
return (AdminServer) adminServer;
46+
47+
} catch (ClassNotFoundException e) {
48+
LOG.warn("Unable to start JettyAdminServer", e);
49+
} catch (InstantiationException e) {
50+
LOG.warn("Unable to start JettyAdminServer", e);
51+
} catch (IllegalAccessException e) {
52+
LOG.warn("Unable to start JettyAdminServer", e);
53+
} catch (InvocationTargetException e) {
54+
LOG.warn("Unable to start JettyAdminServer", e);
55+
} catch (NoSuchMethodException e) {
56+
LOG.warn("Unable to start JettyAdminServer", e);
57+
} catch (NoClassDefFoundError e) {
58+
LOG.warn("Unable to load jetty, not starting JettyAdminServer", e);
59+
}
60+
}
61+
return new DummyAdminServer();
62+
}
63+
64+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.zookeeper.server.admin;
20+
21+
import org.apache.zookeeper.ZooDefs;
22+
23+
/**
24+
* Class representing auth data for performing ACL check on admin server commands.
25+
*
26+
* For example, SnapshotCommand requires {@link ZooDefs.Perms.ALL} permission on
27+
* the root node.
28+
*
29+
*/
30+
public class AuthRequest {
31+
private final int permission;
32+
private final String path;
33+
34+
/**
35+
* @param permission the required permission for auth check
36+
* @param path the ZNode path for auth check
37+
*/
38+
public AuthRequest(final int permission, final String path) {
39+
this.permission = permission;
40+
this.path = path;
41+
}
42+
43+
/**
44+
* @return permission
45+
*/
46+
public int getPermission() {
47+
return permission;
48+
}
49+
50+
/**
51+
* @return ZNode path
52+
*/
53+
public String getPath() {
54+
return path;
55+
}
56+
57+
@Override
58+
public String toString() {
59+
return "AuthRequest{"
60+
+ "permission=" + permission
61+
+ ", path='" + path + '\''
62+
+ '}';
63+
}
64+
}

0 commit comments

Comments
 (0)