-
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
[improve][broker] Add parameter check for create/update cluster. #19151
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dc45c82
[improve][broker] Add parameter check for cluster data.
mattisonchao 7ca2dee
Fix checkstyle
mattisonchao fe5c8a1
Fix error
mattisonchao 06782d8
Fix conflict
mattisonchao ad173d5
Fix test
mattisonchao a0846d8
Fix failed test
mattisonchao d892a74
Continue fix illgeal usage
mattisonchao 3e63d54
Update pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalan…
mattisonchao 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,12 @@ | |
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
import java.util.LinkedHashSet; | ||
import java.util.Objects; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.pulsar.client.api.ProxyProtocol; | ||
import org.apache.pulsar.common.util.URIPreconditions; | ||
|
||
/** | ||
* The configuration data for a cluster. | ||
|
@@ -398,4 +400,30 @@ public ClusterDataImpl build() { | |
migratedClusterUrl); | ||
} | ||
} | ||
|
||
/** | ||
* Check cluster data properties by rule, if some property is illegal, it will throw | ||
* {@link IllegalArgumentException}. | ||
* | ||
* @throws IllegalArgumentException exist illegal property. | ||
*/ | ||
public void checkPropertiesIfPresent() throws IllegalArgumentException { | ||
URIPreconditions.checkURIIfPresent(getServiceUrl(), | ||
uri -> Objects.equals(uri.getScheme(), "http"), | ||
"Illegal service url, example: http://pulsar.example.com:8080"); | ||
URIPreconditions.checkURIIfPresent(getServiceUrlTls(), | ||
uri -> Objects.equals(uri.getScheme(), "https"), | ||
"Illegal service tls url, example: https://pulsar.example.com:8443"); | ||
URIPreconditions.checkURIIfPresent(getBrokerServiceUrl(), | ||
uri -> Objects.equals(uri.getScheme(), "pulsar"), | ||
"Illegal broker service url, example: pulsar://pulsar.example.com:6650"); | ||
URIPreconditions.checkURIIfPresent(getBrokerServiceUrlTls(), | ||
uri -> Objects.equals(uri.getScheme(), "pulsar+ssl"), | ||
"Illegal broker service tls url, example: pulsar+ssl://pulsar.example.com:6651"); | ||
URIPreconditions.checkURIIfPresent(getProxyServiceUrl(), | ||
uri -> Objects.equals(uri.getScheme(), "pulsar") | ||
|| Objects.equals(uri.getScheme(), "pulsar+ssl"), | ||
"Illegal proxy service url, example: pulsar+ssl://ats-proxy.example.com:4443 " | ||
+ "or pulsar://ats-proxy.example.com:4080"); | ||
} | ||
Comment on lines
+410
to
+428
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we document these requirements? Also, what would happen if a user had already created a cluster in a bad state? |
||
} |
98 changes: 98 additions & 0 deletions
98
pulsar-common/src/main/java/org/apache/pulsar/common/util/URIPreconditions.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,98 @@ | ||
/* | ||
* 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.common.util; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.function.Predicate; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
/** | ||
* Static convenience URI checker. | ||
*/ | ||
@ThreadSafe | ||
public class URIPreconditions { | ||
|
||
/** | ||
* Check whether the given string is a legal URI and passes the user's check. | ||
* | ||
* @param uri URI String | ||
* @param predicate User defined rule | ||
* @throws IllegalArgumentException Illegal URI or failed in the user's rules | ||
*/ | ||
public static void checkURI(@Nonnull String uri, | ||
@Nonnull Predicate<URI> predicate) throws IllegalArgumentException { | ||
checkURI(uri, predicate, null); | ||
} | ||
|
||
/** | ||
* Check whether the given string is a legal URI and passes the user's check. | ||
* | ||
* @param uri URI String | ||
* @param predicate User defined rule | ||
* @throws IllegalArgumentException Illegal URI or failed in the user's rules | ||
*/ | ||
public static void checkURIIfPresent(@Nullable String uri, | ||
@Nonnull Predicate<URI> predicate) throws IllegalArgumentException { | ||
checkURIIfPresent(uri, predicate, null); | ||
} | ||
|
||
/** | ||
* Check whether the given string is a legal URI and passes the user's check. | ||
* | ||
* @param uri URI String | ||
* @param predicate User defined rule | ||
* @param errorMessage Error message | ||
* @throws IllegalArgumentException Illegal URI or failed in the user's rules | ||
*/ | ||
public static void checkURIIfPresent(@Nullable String uri, | ||
@Nonnull Predicate<URI> predicate, | ||
@Nullable String errorMessage) throws IllegalArgumentException { | ||
if (uri == null) { | ||
return; | ||
} | ||
checkURI(uri, predicate, errorMessage); | ||
} | ||
|
||
/** | ||
* Check whether the given string is a legal URI and passes the user's check. | ||
* | ||
* @param uri URI String | ||
* @param predicate User defined rule | ||
* @param errorMessage Error message | ||
* @throws IllegalArgumentException Illegal URI or failed in the user's rules | ||
*/ | ||
public static void checkURI(@Nonnull String uri, | ||
@Nonnull Predicate<URI> predicate, | ||
@Nullable String errorMessage) throws IllegalArgumentException { | ||
requireNonNull(uri, "uri"); | ||
requireNonNull(predicate, "predicate"); | ||
try { | ||
URI u = new URI(uri); | ||
if (!predicate.test(u)) { | ||
throw new IllegalArgumentException(errorMessage == null ? "Illegal syntax: " + uri : errorMessage); | ||
} | ||
} catch (URISyntaxException e) { | ||
throw new IllegalArgumentException(errorMessage == null ? "Illegal syntax: " + uri : errorMessage); | ||
} | ||
} | ||
} |
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.
Is this a breaking change? I haven't reviewed the details.
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.
It's not a breaking change; we just didn't have data validation.