Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basicly support dynamic config for extends. (#623)
* support dynamic manager * support layers * support registe and use * add type for consumer * remove type for consumer * dynamic config * Support for getting configuration from the configuration center. (#585) * refactor dynamic config * support for getting configuration from the configuration center * fix build method key bug * fix test case * use common key * support dynamic manager * support layers * support registe and use * add type for consumer * remove type for consumer * dynamic config * Support for getting configuration from the configuration center. (#585) * refactor dynamic config * support for getting configuration from the configuration center * resolve conflict * fix build method key bug * use common key
- Loading branch information
1 parent
2d132a0
commit a97c632
Showing
13 changed files
with
686 additions
and
1 deletion.
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
60 changes: 60 additions & 0 deletions
60
core/api/src/main/java/com/alipay/sofa/rpc/auth/AuthRule.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,60 @@ | ||
/* | ||
* 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 com.alipay.sofa.rpc.auth; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author lepdou | ||
* @version $Id: AuthRule.java, v 0.1 2019年04月11日 下午7:53 lepdou Exp $ | ||
*/ | ||
public class AuthRule { | ||
|
||
private String name; | ||
private int enabled; | ||
|
||
private List<AuthRuleItem> ruleItems; | ||
|
||
public boolean enable() { | ||
return enabled > 0; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public int getEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(int enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public List<AuthRuleItem> getRuleItems() { | ||
return ruleItems; | ||
} | ||
|
||
public void setRuleItems(List<AuthRuleItem> ruleItems) { | ||
this.ruleItems = ruleItems; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
core/api/src/main/java/com/alipay/sofa/rpc/auth/AuthRuleGroup.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,69 @@ | ||
/* | ||
* 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 com.alipay.sofa.rpc.auth; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author lepdou | ||
* @version $Id: AuthRuleGroup.java, v 0.1 2019年04月11日 下午7:53 lepdou Exp $ | ||
*/ | ||
public class AuthRuleGroup { | ||
|
||
private String dataId; | ||
private String type; | ||
private int enabled; | ||
|
||
private List<AuthRule> rules; | ||
|
||
public boolean enable() { | ||
return enabled > 0; | ||
} | ||
|
||
public String getDataId() { | ||
return dataId; | ||
} | ||
|
||
public void setDataId(String dataId) { | ||
this.dataId = dataId; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public int getEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(int enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public List<AuthRule> getRules() { | ||
return rules; | ||
} | ||
|
||
public void setRules(List<AuthRule> rules) { | ||
this.rules = rules; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
core/api/src/main/java/com/alipay/sofa/rpc/auth/AuthRuleItem.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,62 @@ | ||
/* | ||
* 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 com.alipay.sofa.rpc.auth; | ||
|
||
/** | ||
* | ||
* @author lepdou | ||
* @version $Id: AuthRuleItem.java, v 0.1 2019年04月11日 下午7:53 lepdou Exp $ | ||
*/ | ||
public class AuthRuleItem { | ||
|
||
private String type; | ||
private String field; | ||
private String operation; | ||
private String value; | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public String getField() { | ||
return field; | ||
} | ||
|
||
public void setField(String field) { | ||
this.field = field; | ||
} | ||
|
||
public String getOperation() { | ||
return operation; | ||
} | ||
|
||
public void setOperation(String operation) { | ||
this.operation = operation; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
} |
153 changes: 153 additions & 0 deletions
153
core/api/src/main/java/com/alipay/sofa/rpc/dynamic/DynamicConfigKeyHelper.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,153 @@ | ||
/* | ||
* 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 com.alipay.sofa.rpc.dynamic; | ||
|
||
import com.alipay.sofa.rpc.common.utils.StringUtils; | ||
|
||
/** | ||
* | ||
* @author lepdou | ||
* @version $Id: DynamicConfigKeyHelper.java, v 0.1 2019年04月16日 下午12:01 lepdou Exp $ | ||
*/ | ||
public class DynamicConfigKeyHelper { | ||
|
||
private static final String KEY_SEPARATOR = "."; | ||
|
||
public static final String APP_CONSUMER_CONFIG_KEY_PREFIX = "sofa.consumer"; | ||
public static final String APP_PROVIDER_CONFIG_KEY_PREFIX = "sofa.provider"; | ||
public static final String SERVICE_CONSUMER_PROPERTY_KEY_PREFIX = "sofa.consumer.service"; | ||
public static final String SERVICE_PROVIDER_PROPERTY_KEY_PREFIX = "sofa.provider.service"; | ||
public static final String METHOD_CONSUMER_PROPERTY_KEY_PREFIX = "sofa.consumer.method"; | ||
public static final String METHOD_PROVIDER_PROPERTY_KEY_PREFIX = "sofa.provider.method"; | ||
|
||
/** | ||
* The last field of key is actual property key | ||
*/ | ||
public static String extractPropertyKey(String key) { | ||
if (StringUtils.isBlank(key)) { | ||
return ""; | ||
} | ||
return key.substring(key.lastIndexOf(KEY_SEPARATOR) + 1); | ||
} | ||
|
||
/** | ||
* Service property key format : sofa.consumer.service.{serivceName}.{configKey} | ||
* | ||
* For example : sofa.consumer.service.com.alipay.sofa.rpc.test.HelloService.timeout | ||
* service name = com.alipay.sofa.rpc.test.HelloService | ||
* config key = timeout | ||
* | ||
* @param serviceProKey service property key | ||
* @return extracted service name | ||
*/ | ||
public static String extractServiceNameFromServiceProKey(String serviceProKey) { | ||
if (!isServiceProKey(serviceProKey)) { | ||
return ""; | ||
} | ||
|
||
return serviceProKey.substring(SERVICE_CONSUMER_PROPERTY_KEY_PREFIX.length() + 1, | ||
serviceProKey.lastIndexOf(KEY_SEPARATOR)); | ||
} | ||
|
||
/** | ||
* Method property key format : sofa.consumer.method.{serivceName}.{methodName}.{configKey} | ||
* | ||
* Example : sofa.consumer.method.com.alipay.sofa.rpc.test.HelloService.sayHello.timeout | ||
* service name = com.alipay.sofa.rpc.test.HelloService | ||
* method name = sayHello | ||
* config key = timeout | ||
* | ||
* @param methodProKey method property key | ||
* @return extracted service name | ||
*/ | ||
public static String extractServiceNameFromMethodProKey(String methodProKey) { | ||
if (!isMethodProKey(methodProKey)) { | ||
return ""; | ||
} | ||
|
||
String serviceMethod = methodProKey.substring(METHOD_PROVIDER_PROPERTY_KEY_PREFIX.length() + 1, | ||
methodProKey.lastIndexOf(KEY_SEPARATOR)); | ||
|
||
return serviceMethod.substring(0, serviceMethod.lastIndexOf(KEY_SEPARATOR)); | ||
} | ||
|
||
/** | ||
* Method property key format : sofa.consumer.method.{serivceName}.{methodName}.{configKey} | ||
* | ||
* Example : sofa.consumer.method.com.alipay.sofa.rpc.test.HelloService.sayHello.timeout | ||
* service name = com.alipay.sofa.rpc.test.HelloService | ||
* method name = sayHello | ||
* config key = timeout | ||
* | ||
* @param methodProKey method property key | ||
* @return extracted method name | ||
*/ | ||
public static String extractMethodNameFromMethodProKey(String methodProKey) { | ||
if (!isMethodProKey(methodProKey)) { | ||
return ""; | ||
} | ||
|
||
String serviceMethod = methodProKey.substring(METHOD_PROVIDER_PROPERTY_KEY_PREFIX.length() + 1, | ||
methodProKey.lastIndexOf(KEY_SEPARATOR)); | ||
|
||
return serviceMethod.substring(serviceMethod.lastIndexOf(KEY_SEPARATOR) + 1); | ||
} | ||
|
||
/** | ||
* Consumer service property key format : sofa.consumer.service.{serviceName}.{configKey} | ||
*/ | ||
public static String buildConsumerServiceProKey(String serviceName, String proKey) { | ||
return SERVICE_CONSUMER_PROPERTY_KEY_PREFIX + KEY_SEPARATOR + serviceName + KEY_SEPARATOR + proKey; | ||
} | ||
|
||
/** | ||
* Provider service property key format : sofa.provider.service.{serviceName}.{configKey} | ||
*/ | ||
public static String buildProviderServiceProKey(String serviceName, String proKey) { | ||
return SERVICE_PROVIDER_PROPERTY_KEY_PREFIX + KEY_SEPARATOR + serviceName + KEY_SEPARATOR + proKey; | ||
} | ||
|
||
/** | ||
* Consumer method property key format : sofa.consumer.service.{serviceName}.{methodName}.{configKey} | ||
*/ | ||
public static String buildConsumerMethodProKey(String serviceName, String methodName, String proKey) { | ||
return METHOD_CONSUMER_PROPERTY_KEY_PREFIX + KEY_SEPARATOR + serviceName + KEY_SEPARATOR + methodName + | ||
KEY_SEPARATOR + proKey; | ||
} | ||
|
||
/** | ||
* Provider method property key format : sofa.consumer.service.{serviceName}.{methodName}.{configKey} | ||
*/ | ||
public static String buildProviderMethodProKey(String serviceName, String methodName, String proKey) { | ||
return METHOD_PROVIDER_PROPERTY_KEY_PREFIX + KEY_SEPARATOR + serviceName + KEY_SEPARATOR + methodName + | ||
KEY_SEPARATOR + proKey; | ||
} | ||
|
||
public static boolean isServiceProKey(String key) { | ||
return !StringUtils.isBlank(key) && (key.startsWith(SERVICE_CONSUMER_PROPERTY_KEY_PREFIX) || | ||
key.startsWith(SERVICE_PROVIDER_PROPERTY_KEY_PREFIX)); | ||
} | ||
|
||
public static boolean isMethodProKey(String key) { | ||
return !StringUtils.isBlank(key) && (key.startsWith(METHOD_CONSUMER_PROPERTY_KEY_PREFIX) || | ||
key.startsWith(METHOD_PROVIDER_PROPERTY_KEY_PREFIX)); | ||
} | ||
|
||
public static boolean isSofaProKey(String key) { | ||
return isServiceProKey(key) || isMethodProKey(key); | ||
} | ||
} |
Oops, something went wrong.