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

[SCB-788] public key black/white add feature: choose server by version #846

Merged
merged 2 commits into from
Aug 7, 2018

Conversation

weichao666
Copy link
Contributor

@weichao666 weichao666 commented Jul 30, 2018

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SCB-XXX] Fixes bug in ApproximateQuantiles, where you replace SCB-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

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)) {
Copy link
Contributor

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?

Copy link
Contributor Author

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)) {
Copy link
Contributor

@liubao68 liubao68 Jul 30, 2018

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.

Copy link
Contributor Author

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

@coveralls
Copy link

coveralls commented Aug 2, 2018

Coverage Status

Coverage decreased (-0.03%) to 85.048% when pulling 68f691a on weichao666:blacksupportversion into ebff3ee on apache:master.

Field field;
String fieldValue = null;
try {
field = service.getDeclaredField(fieldName);
Copy link
Contributor

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.

Copy link
Contributor Author

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()) {
Copy link
Contributor

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

Copy link
Contributor Author

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))
Copy link
Contributor

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.

Copy link
Contributor Author

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";
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@liubao68 liubao68 merged commit 7abb7b1 into apache:master Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants