-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add broker interceptor for Intercepting all Pulsar command and REST API requests #7143
Merged
codelipenghui
merged 18 commits into
apache:master
from
codelipenghui:server_interceptors
Jun 9, 2020
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c83dd46
Add interceptor definition
codelipenghui d0f7bf1
Merge branch 'server_interceptors' of /Users/lipenghui/Github/incubat…
codelipenghui f0513eb
Add broker event listener
codelipenghui cdc292d
Fix merge issue.
codelipenghui 35d3ebd
Revert un-related changes.
codelipenghui cc88318
Revert un-related changes.
codelipenghui 45c201d
Fix nar extract directory
codelipenghui 3f72bef
Listen all commands.
codelipenghui bdea8b8
Cleanup
codelipenghui d55d6fc
Fix check style.
codelipenghui 3dbf1b9
Merge remote-tracking branch 'apache/master' into server_interceptors
codelipenghui 4f5b87b
Add WebService request listener.
codelipenghui 89440cb
Merge remote-tracking branch 'apache/master' into server_interceptors
codelipenghui afae533
Merge remote-tracking branch 'apache/master' into server_interceptors
codelipenghui b9a75e0
Rename to broker interceptor.
codelipenghui d0e776b
remove unused configurations.
codelipenghui 72e0d38
Fix unit test
codelipenghui 5d0177b
Add get method for auth related methods.
codelipenghui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
pulsar-broker/src/main/java/org/apache/pulsar/broker/events/BrokerEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* 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.broker.events; | ||
|
||
import com.google.common.annotations.Beta; | ||
import org.apache.pulsar.broker.ServiceConfiguration; | ||
import org.apache.pulsar.broker.service.ServerCnx; | ||
import org.apache.pulsar.common.api.proto.PulsarApi.BaseCommand; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
/** | ||
* A plugin interface that allows you to listen (and possibly mutate) the | ||
* client requests to the Pulsar brokers. | ||
* | ||
* <p>Exceptions thrown by BrokerEventListener methods will be caught, logged, but | ||
* not propagated further. | ||
* | ||
* <p>BrokerEventListener callbacks may be called from multiple threads. Interceptor | ||
* implementation must ensure thread-safety, if needed. | ||
*/ | ||
@Beta | ||
public interface BrokerEventListener extends AutoCloseable { | ||
|
||
/** | ||
* Called by the broker while new command incoming. | ||
*/ | ||
void onPulsarCommand(BaseCommand command, ServerCnx cnx); | ||
|
||
/** | ||
* Called by the web service while new request incoming. | ||
*/ | ||
void onWebServiceRequest(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException; | ||
|
||
/** | ||
* Initialize the broker event listener. | ||
* | ||
* @throws Exception when fail to initialize the broker event listener. | ||
*/ | ||
void initialize(ServiceConfiguration conf) throws Exception; | ||
|
||
BrokerEventListener DISABLED = new BrokerEventListenerDisabled(); | ||
|
||
/** | ||
* Broker event listener disabled implementation. | ||
*/ | ||
class BrokerEventListenerDisabled implements BrokerEventListener { | ||
|
||
@Override | ||
public void onPulsarCommand(BaseCommand command, ServerCnx cnx) { | ||
//No-op | ||
} | ||
|
||
@Override | ||
public void onWebServiceRequest(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
chain.doFilter(request, response); | ||
} | ||
|
||
@Override | ||
public void initialize(ServiceConfiguration conf) throws Exception { | ||
//No-op | ||
} | ||
|
||
@Override | ||
public void close() { | ||
//No-op | ||
} | ||
} | ||
|
||
/** | ||
* Close this broker event listener. | ||
*/ | ||
@Override | ||
void close(); | ||
} |
45 changes: 45 additions & 0 deletions
45
...r-broker/src/main/java/org/apache/pulsar/broker/events/BrokerEventListenerDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* 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.broker.events; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* Metadata information about a broker event listener. | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
public class BrokerEventListenerDefinition { | ||
|
||
/** | ||
* The name of the broker event listener. | ||
*/ | ||
private String name; | ||
|
||
/** | ||
* The description of the broker event listener to be used for user help. | ||
*/ | ||
private String description; | ||
|
||
/** | ||
* The class name for the broker event listener. | ||
*/ | ||
private String listenerClass; | ||
} |
34 changes: 34 additions & 0 deletions
34
...-broker/src/main/java/org/apache/pulsar/broker/events/BrokerEventListenerDefinitions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* 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.broker.events; | ||
|
||
import lombok.Data; | ||
import lombok.experimental.Accessors; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
/** | ||
* The collection of broker event listener. | ||
*/ | ||
@Data | ||
@Accessors(fluent = true) | ||
public class BrokerEventListenerDefinitions { | ||
|
||
private final Map<String, BrokerEventListenerMetadata> listeners = new TreeMap<>(); | ||
} |
42 changes: 42 additions & 0 deletions
42
pulsar-broker/src/main/java/org/apache/pulsar/broker/events/BrokerEventListenerMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* 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.broker.events; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* The metadata of broker event listener | ||
*/ | ||
@Data | ||
@NoArgsConstructor | ||
public class BrokerEventListenerMetadata { | ||
|
||
/** | ||
* The definition of the broker event listener. | ||
*/ | ||
private BrokerEventListenerDefinition definition; | ||
|
||
/** | ||
* The path to the handler package. | ||
*/ | ||
private Path archivePath; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall looks good to me. I see there are two sets of settings here, one is for
listeners
and the other one is forinterceptors
? I think we should just rename the listener interfaces to Interceptors. So it is consistent with client-side interceptor.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.