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

Enhance metadata report config. #8268

Merged
merged 2 commits into from Jul 12, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -32,6 +32,8 @@
import static org.apache.dubbo.common.constants.CommonConstants.CONFIG_ENABLE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
import static org.apache.dubbo.common.utils.PojoUtils.updatePropertyIfAbsent;
import static org.apache.dubbo.config.Constants.CONFIG_APP_CONFIGFILE_KEY;
import static org.apache.dubbo.config.Constants.ZOOKEEPER_PROTOCOL;

Expand Down Expand Up @@ -147,12 +149,18 @@ public void setAddress(String address) {
if (address != null) {
try {
URL url = URL.valueOf(address);
setUsername(url.getUsername());
setPassword(url.getPassword());
updateIdIfAbsent(url.getProtocol());
updateProtocolIfAbsent(url.getProtocol());
updatePortIfAbsent(url.getPort());
updateParameters(url.getParameters());

// Refactor since 2.7.8
updatePropertyIfAbsent(this::getUsername, this::setUsername, url.getUsername());
updatePropertyIfAbsent(this::getPassword, this::setPassword, url.getPassword());
updatePropertyIfAbsent(this::getProtocol, this::setProtocol, url.getProtocol());
updatePropertyIfAbsent(this::getPort, this::setPort, url.getPort());

Map<String, String> params = url.getParameters();
if (CollectionUtils.isNotEmptyMap(params)) {
params.remove(BACKUP_KEY);
}
updateParameters(params);
} catch (Exception ignored) {
}
}
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.config;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.support.Parameter;

Expand All @@ -25,6 +26,8 @@

import static org.apache.dubbo.common.constants.CommonConstants.DUBBO;
import static org.apache.dubbo.common.constants.CommonConstants.PROPERTIES_CHAR_SEPARATOR;
import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
import static org.apache.dubbo.common.utils.PojoUtils.updatePropertyIfAbsent;
import static org.apache.dubbo.common.utils.StringUtils.isEmpty;

/**
Expand All @@ -41,16 +44,23 @@ public class MetadataReportConfig extends AbstractConfig {
private static final String PREFIX_TAG = StringUtils.camelToSplitName(
MetadataReportConfig.class.getSimpleName().substring(0, MetadataReportConfig.class.getSimpleName().length() - 6), PROPERTIES_CHAR_SEPARATOR);

// Register center address
private String protocol;

// metadata center address
private String address;

// Username to login register center
/**
* Default port for metadata center
*/
private Integer port;

// Username to login metadata center
private String username;

// Password to login register center
// Password to login metadata center
private String password;

// Request timeout in milliseconds for register center
// Request timeout in milliseconds for metadata center
private Integer timeout;

/**
Expand Down Expand Up @@ -118,13 +128,47 @@ public URL toUrl() throws IllegalArgumentException {

}

public String getProtocol() {
return protocol;
}

public void setProtocol(String protocol) {
this.protocol = protocol;
}

@Parameter(excluded = true)
public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
if (address != null) {
try {
URL url = URL.valueOf(address);

// Refactor since 2.7.8
updatePropertyIfAbsent(this::getUsername, this::setUsername, url.getUsername());
updatePropertyIfAbsent(this::getPassword, this::setPassword, url.getPassword());
updatePropertyIfAbsent(this::getProtocol, this::setProtocol, url.getProtocol());
updatePropertyIfAbsent(this::getPort, this::setPort, url.getPort());

Map<String, String> params = url.getParameters();
if (CollectionUtils.isNotEmptyMap(params)) {
params.remove(BACKUP_KEY);
}
updateParameters(params);
} catch (Exception ignored) {
}
}
}

public Integer getPort() {
return port;
}

public void setPort(Integer port) {
this.port = port;
}

public String getUsername() {
Expand Down Expand Up @@ -238,4 +282,15 @@ public String getFile() {
public void setFile(String file) {
this.file = file;
}

public void updateParameters(Map<String, String> parameters) {
if (CollectionUtils.isEmptyMap(parameters)) {
return;
}
if (this.parameters == null) {
this.parameters = parameters;
} else {
this.parameters.putAll(parameters);
}
}
}
Expand Up @@ -223,11 +223,6 @@ public void setAddress(String address) {
updatePropertyIfAbsent(this::getProtocol, this::setProtocol, url.getProtocol());
updatePropertyIfAbsent(this::getPort, this::setPort, url.getPort());

// setUsername(url.getUsername());
// setPassword(url.getPassword());
// updateIdIfAbsent(url.getProtocol());
// updateProtocolIfAbsent(url.getProtocol());
// updatePortIfAbsent(url.getPort());
Map<String, String> params = url.getParameters();
if (CollectionUtils.isNotEmptyMap(params)) {
params.remove(BACKUP_KEY);
Expand Down
Expand Up @@ -634,11 +634,21 @@
<xsd:documentation><![CDATA[ The unique identifier for a bean. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="protocol" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[ The config center protocol. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="address" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ The metadataReport address. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="port" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[ The registry default port. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="username" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ The metadataReport username. ]]></xsd:documentation>
Expand Down