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

Group variables into a common class #6179

Merged
merged 4 commits into from
Feb 23, 2021
Merged
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 @@ -26,6 +26,7 @@
import org.apache.dubbo.config.context.ConfigManager;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.ServiceMetadata;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -52,6 +53,21 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {

private static final long serialVersionUID = -1559314110797223229L;

/**
* The interface name of the exported service
*/
protected String interfaceName;
/**
* The remote service version the customer/provider side will reference
*/
protected String version;

/**
* The remote service group the customer/provider side will reference
*/
protected String group;

protected ServiceMetadata serviceMetadata;
/**
* Local impl class name for the service interface
*/
Expand Down Expand Up @@ -683,4 +699,46 @@ public void setAuth(Boolean auth) {
public SslConfig getSslConfig() {
return ApplicationModel.getConfigManager().getSsl().orElse(null);
}

public void initServiceMetadata(AbstractInterfaceConfig interfaceConfig) {
serviceMetadata.setVersion(getVersion(interfaceConfig));
serviceMetadata.setGroup(getGroup(interfaceConfig));
serviceMetadata.setDefaultGroup(getGroup(interfaceConfig));
serviceMetadata.setServiceInterfaceName(getInterface());
}

public String getGroup(AbstractInterfaceConfig interfaceConfig) {
return StringUtils.isEmpty(this.group) ? (interfaceConfig != null ? interfaceConfig.getGroup() : this.group) : this.group;
}

public String getVersion(AbstractInterfaceConfig interfaceConfig) {
return StringUtils.isEmpty(this.version) ? (interfaceConfig != null ? interfaceConfig.getVersion() : this.version) : this.version;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public String getGroup() {
return group;
}

public void setGroup(String group) {
this.group = group;
}

public String getInterface() {
return interfaceName;
}

public void setInterface(String interfaceName) {
this.interfaceName = interfaceName;
// if (StringUtils.isEmpty(id)) {
// id = interfaceName;
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,7 @@ public abstract class AbstractReferenceConfig extends AbstractInterfaceConfig {
//TODO solve merge problem
protected Boolean stubevent;//= Constants.DEFAULT_STUB_EVENT;

/**
* The remote service version the customer side will reference
*/
protected String version;

/**
* The remote service group the customer side will reference
*/
protected String group;

/**
* declares which app or service this interface belongs to
Expand Down Expand Up @@ -212,21 +204,7 @@ public void setSticky(Boolean sticky) {
this.sticky = sticky;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public String getGroup() {
return group;
}

public void setGroup(String group) {
this.group = group;
}

@Parameter(key = "provided-by")
public String getProvidedBy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public abstract class ReferenceConfigBase<T> extends AbstractReferenceConfig {

private static final long serialVersionUID = -5864351140409987595L;

/**
* The interface name of the reference service
*/
protected String interfaceName;

/**
* The interface class of the reference service
*/
Expand All @@ -72,7 +67,6 @@ public abstract class ReferenceConfigBase<T> extends AbstractReferenceConfig {
*/
protected String protocol;

protected ServiceMetadata serviceMetadata;

public ReferenceConfigBase() {
serviceMetadata = new ServiceMetadata();
Expand Down Expand Up @@ -160,18 +154,6 @@ public void setInterfaceClass(Class<?> interfaceClass) {
setInterface(interfaceClass);
}

public String getInterface() {
return interfaceName;
}

public void setInterface(String interfaceName) {
this.interfaceName = interfaceName;
// FIXME, add id strategy in ConfigManager
// if (StringUtils.isEmpty(id)) {
// id = interfaceName;
// }
}

public void setInterface(Class<?> interfaceClass) {
if (interfaceClass != null && !interfaceClass.isInterface()) {
throw new IllegalStateException("The interface class " + interfaceClass + " is not a interface!");
Expand Down Expand Up @@ -272,16 +254,6 @@ public String getUniqueServiceName() {
return URL.buildKey(interfaceName, getGroup(), getVersion());
}

@Override
public String getVersion() {
return StringUtils.isEmpty(this.version) ? (consumer != null ? consumer.getVersion() : this.version) : this.version;
}

@Override
public String getGroup() {
return StringUtils.isEmpty(this.group) ? (consumer != null ? consumer.getGroup() : this.group) : this.group;
}

public abstract T get();

public abstract void destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ public abstract class ServiceConfigBase<T> extends AbstractServiceConfig {

private static final long serialVersionUID = 3033787999037024738L;

/**
* The interface name of the exported service
*/
protected String interfaceName;


/**
* The interface class of the exported service
Expand Down Expand Up @@ -78,7 +75,7 @@ public abstract class ServiceConfigBase<T> extends AbstractServiceConfig {
*/
protected volatile String generic;

protected ServiceMetadata serviceMetadata;


public ServiceConfigBase() {
serviceMetadata = new ServiceMetadata();
Expand Down Expand Up @@ -292,9 +289,7 @@ public void setInterfaceClass(Class<?> interfaceClass) {
setInterface(interfaceClass);
}

public String getInterface() {
return interfaceName;
}


public void setInterface(Class<?> interfaceClass) {
if (interfaceClass != null && !interfaceClass.isInterface()) {
Expand All @@ -304,14 +299,6 @@ public void setInterface(Class<?> interfaceClass) {
setInterface(interfaceClass == null ? null : interfaceClass.getName());
}

public void setInterface(String interfaceName) {
this.interfaceName = interfaceName;
// FIXME, add id strategy in ConfigManager
// if (StringUtils.isEmpty(id)) {
// id = interfaceName;
// }
}

public T getRef() {
return ref;
}
Expand Down Expand Up @@ -403,15 +390,7 @@ public String getUniqueServiceName() {
return URL.buildKey(interfaceName, getGroup(), getVersion());
}

@Override
public String getGroup() {
return StringUtils.isEmpty(this.group) ? (provider != null ? provider.getGroup() : this.group) : this.group;
}

@Override
Copy link
Contributor

Choose a reason for hiding this comment

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

public String getVersion() {
return StringUtils.isEmpty(this.version) ? (provider != null ? provider.getVersion() : this.version) : this.version;
}

private void computeValidProtocolIds() {
if (StringUtils.isEmpty(getProtocolIds())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,8 @@ public void checkAndUpdateSubConfigs() {
checkInterfaceAndMethods(interfaceClass, getMethods());
}

//init serivceMetadata
serviceMetadata.setVersion(getVersion());
serviceMetadata.setGroup(getGroup());
serviceMetadata.setDefaultGroup(getGroup());
initServiceMetadata(consumer);
serviceMetadata.setServiceType(getActualInterface());
serviceMetadata.setServiceInterfaceName(interfaceName);
// TODO, uncomment this line once service key is unified
serviceMetadata.setServiceKey(URL.buildKey(interfaceName, group, version));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,8 @@ public synchronized void export() {

checkAndUpdateSubConfigs();

//init serviceMetadata
serviceMetadata.setVersion(getVersion());
serviceMetadata.setGroup(getGroup());
serviceMetadata.setDefaultGroup(getGroup());
initServiceMetadata(provider);
serviceMetadata.setServiceType(getInterfaceClass());
serviceMetadata.setServiceInterfaceName(getInterface());
serviceMetadata.setTarget(getRef());

if (shouldDelay()) {
Expand Down