Skip to content
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

[To dev/1.3] Print current trusted_uri_pattern is error msg #14424

Open
wants to merge 1 commit into
base: dev/1.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,11 @@ public void loadProperties(Properties properties) throws BadNodeUrlException, IO

loadIoTConsensusProps(properties);
loadPipeConsensusProps(properties);

// update query_sample_throughput_bytes_per_sec
loadQuerySampleThroughput(properties);
// update trusted_uri_pattern
loadTrustedUriPattern(properties);
}

private void reloadConsensusProps(Properties properties) throws IOException {
Expand Down Expand Up @@ -2006,48 +2011,9 @@ public synchronized void loadHotModifiedProps(Properties properties)
}

// update query_sample_throughput_bytes_per_sec
String querySamplingRateLimitNumber =
Optional.ofNullable(
properties.getProperty(
"query_sample_throughput_bytes_per_sec",
ConfigurationFileUtils.getConfigurationDefaultValue(
"query_sample_throughput_bytes_per_sec")))
.map(String::trim)
.orElse(
ConfigurationFileUtils.getConfigurationDefaultValue(
"query_sample_throughput_bytes_per_sec"));
if (querySamplingRateLimitNumber != null) {
try {
int rateLimit = Integer.parseInt(querySamplingRateLimitNumber);
commonDescriptor.getConfig().setQuerySamplingRateLimit(rateLimit);
} catch (Exception e) {
LOGGER.warn(
"Failed to parse query_sample_throughput_bytes_per_sec {} to integer",
querySamplingRateLimitNumber);
}
}

loadQuerySampleThroughput(properties);
// update trusted_uri_pattern
String trustedUriPattern =
Optional.ofNullable(
properties.getProperty(
"trusted_uri_pattern",
ConfigurationFileUtils.getConfigurationDefaultValue("trusted_uri_pattern")))
.map(String::trim)
.orElse(ConfigurationFileUtils.getConfigurationDefaultValue("trusted_uri_pattern"));
Pattern pattern;
if (trustedUriPattern != null) {
try {
pattern = Pattern.compile(trustedUriPattern);
} catch (Exception e) {
LOGGER.warn("Failed to parse trusted_uri_pattern {}", trustedUriPattern);
pattern = commonDescriptor.getConfig().getTrustedUriPattern();
}
} else {
pattern = commonDescriptor.getConfig().getTrustedUriPattern();
}
commonDescriptor.getConfig().setTrustedUriPattern(pattern);

loadTrustedUriPattern(properties);
} catch (Exception e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
Expand All @@ -2056,6 +2022,51 @@ public synchronized void loadHotModifiedProps(Properties properties)
}
}

private void loadQuerySampleThroughput(Properties properties) throws IOException {
String querySamplingRateLimitNumber =
Optional.ofNullable(
properties.getProperty(
"query_sample_throughput_bytes_per_sec",
ConfigurationFileUtils.getConfigurationDefaultValue(
"query_sample_throughput_bytes_per_sec")))
.map(String::trim)
.orElse(
ConfigurationFileUtils.getConfigurationDefaultValue(
"query_sample_throughput_bytes_per_sec"));
if (querySamplingRateLimitNumber != null) {
try {
int rateLimit = Integer.parseInt(querySamplingRateLimitNumber);
commonDescriptor.getConfig().setQuerySamplingRateLimit(rateLimit);
} catch (Exception e) {
LOGGER.warn(
"Failed to parse query_sample_throughput_bytes_per_sec {} to integer",
querySamplingRateLimitNumber);
}
}
}

private void loadTrustedUriPattern(Properties properties) throws IOException {
String trustedUriPattern =
Optional.ofNullable(
properties.getProperty(
"trusted_uri_pattern",
ConfigurationFileUtils.getConfigurationDefaultValue("trusted_uri_pattern")))
.map(String::trim)
.orElse(ConfigurationFileUtils.getConfigurationDefaultValue("trusted_uri_pattern"));
Pattern pattern;
if (trustedUriPattern != null) {
try {
pattern = Pattern.compile(trustedUriPattern);
} catch (Exception e) {
LOGGER.warn("Failed to parse trusted_uri_pattern {}", trustedUriPattern);
pattern = commonDescriptor.getConfig().getTrustedUriPattern();
}
} else {
pattern = commonDescriptor.getConfig().getTrustedUriPattern();
}
commonDescriptor.getConfig().setTrustedUriPattern(pattern);
}

public synchronized void loadHotModifiedProps() throws QueryProcessException {
URL url = getPropsUrl(CommonConfig.SYSTEM_CONFIG_NAME);
if (url == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@

import org.apache.tsfile.exception.NotImplementedException;

import static org.apache.iotdb.commons.executable.ExecutableManager.getUnTrustedUriErrorMsg;
import static org.apache.iotdb.commons.executable.ExecutableManager.isUriTrusted;

public class ConfigTaskVisitor extends StatementVisitor<IConfigTask, MPPQueryContext> {
Expand Down Expand Up @@ -327,7 +328,7 @@ && isUriTrusted(createFunctionStatement.getUriString()))) {
return new CreateFunctionTask(createFunctionStatement);
} else {
// user specified uri and that uri is not trusted
throw new SemanticException("Untrusted uri " + createFunctionStatement.getUriString());
throw new SemanticException(getUnTrustedUriErrorMsg(createFunctionStatement.getUriString()));
}
}

Expand All @@ -354,7 +355,7 @@ && isUriTrusted(createTriggerStatement.getUriString()))) {
return new CreateTriggerTask(createTriggerStatement);
} else {
// user specified uri and that uri is not trusted
throw new SemanticException("Untrusted uri " + createTriggerStatement.getUriString());
throw new SemanticException(getUnTrustedUriErrorMsg(createTriggerStatement.getUriString()));
}
}

Expand All @@ -380,7 +381,8 @@ && isUriTrusted(createPipePluginStatement.getUriString())) {
return new CreatePipePluginTask(createPipePluginStatement);
} else {
// user specified uri and that uri is not trusted
throw new SemanticException("Untrusted uri " + createPipePluginStatement.getUriString());
throw new SemanticException(
getUnTrustedUriErrorMsg(createPipePluginStatement.getUriString()));
}
}

Expand Down Expand Up @@ -633,7 +635,7 @@ public IConfigTask visitCreateModel(
return new CreateModelTask(createModelStatement, context);
} else {
// user specified uri and that uri is not trusted
throw new SemanticException("Untrusted uri " + createModelStatement.getUri());
throw new SemanticException(getUnTrustedUriErrorMsg(createModelStatement.getUri()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,10 @@ public String getInstallDir() {
public static boolean isUriTrusted(String uri) {
return CommonDescriptor.getInstance().getConfig().getTrustedUriPattern().matcher(uri).matches();
}

public static String getUnTrustedUriErrorMsg(String uri) {
return String.format(
"Untrusted uri %s, current trusted_uri_pattern is %s",
uri, CommonDescriptor.getInstance().getConfig().getTrustedUriPattern());
}
}
Loading