-
Notifications
You must be signed in to change notification settings - Fork 803
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
[SCB-788] public key black/white add feature: choose server by version #846
Conversation
if ("serviceName".equals(item.propertyName)) { | ||
if (isPatternMatch(microservice.getServiceName(), item.rule)) { | ||
matched = true; | ||
break; | ||
} | ||
} | ||
if ("version".equals(item.propertyName)) { | ||
if (isVersionMatch(microservice.getVersion(), item.rule)) { |
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.
Why not use isPatternMatch here?
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.
yes,i'll modify it
if ("serviceName".equals(item.propertyName)) { | ||
if (isPatternMatch(microservice.getServiceName(), item.rule)) { | ||
matched = true; | ||
break; | ||
} | ||
} | ||
if ("version".equals(item.propertyName)) { |
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.
Maybe you can write this code using reflection to find all Microservice String getters and match in a general way to avoid many if statements. So that we can support all properties, e.g. serviceName, appId, environment, alias and so on. And when getters not exists, we may search properties of Microservice(properties is a map) for the key.
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, i will deal with this
f9ba502
to
bc322ad
Compare
Field field; | ||
String fieldValue = null; | ||
try { | ||
field = service.getDeclaredField(fieldName); |
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.
Invoke the getter method directly, do not need set accessible to true.
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.
done
break; | ||
// we support to configure properties, e.g. serviceName, appId, environment, alias, version and so on, also support key in properties. | ||
Class<? extends Microservice> service = microservice.getClass(); | ||
for (Method method : service.getDeclaredMethods()) { |
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.
Maybe iterate all fields and find the Read Method is more elegant implementation. See https://stackoverflow.com/questions/28697484/how-to-invoke-a-getter-method-by-its-name
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.
done
String methodName = method.getName(); | ||
if (!methodName.startsWith("get")) | ||
continue; | ||
if (!method.getGenericReturnType().getTypeName().equals(TYPE_STRING_NAME)) |
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.
maybe write two short methods, e.g. matchMicroserviceField & matchMicroserviceProperties to avoid this method too long.
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.
done
@@ -54,6 +57,8 @@ | |||
|
|||
private static final String KEY_RULE_POSTFIX = ".rule"; | |||
|
|||
private static final String TYPE_STRING_NAME = "java.lang.String"; |
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.
String.class.getName maybe is better
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.
done
Follow this checklist to help us incorporate your contribution quickly and easily:
[SCB-XXX] Fixes bug in ApproximateQuantiles
, where you replaceSCB-XXX
with the appropriate JIRA issue.mvn clean install
to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.