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

[ISSUE #3904] feature - operate instance's metadata alonely #3912

Merged
merged 22 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from 11 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 @@ -19,6 +19,8 @@
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.utils.StringUtils;

import java.util.Map;

/**
* NamingUtils.
*
Expand Down Expand Up @@ -54,4 +56,57 @@ public static String getGroupName(final String serviceNameWithGroup) {
}
return serviceNameWithGroup.split(Constants.SERVICE_INFO_SPLITER)[0];
}

/**
* check combineServiceName format. the serviceName can't be blank. some relational logic in {@link
* com.alibaba.nacos.naming.web.DistroFilter#doFilter}, it will handle combineServiceName in some case, you should
* know it.
* <pre>
* serviceName = "@@"; the length = 0; illegal
* serviceName = "group@@"; the length = 1; illegal
* serviceName = "@@serviceName"; the length = 2; legal
* serviceName = "group@@serviceName"; the length = 2; legal
* </pre>
*
* @param combineServiceName such as: groupName@@serviceName
*/
public static void checkServiceNameFormat(String combineServiceName) {
String[] split = combineServiceName.split(Constants.SERVICE_INFO_SPLITER);
if (split.length <= 1) {
throw new IllegalArgumentException(
"Param 'serviceName' is illegal, it should be format as 'groupName@@serviceName'");
}
}

/**
* get target value from param, if not found will throw {@link IllegalArgumentException}.
*
* @param param param
* @param key key
* @return value
*/
public static String required(final Map<String, String> param, final String key) {
chuntaojun marked this conversation as resolved.
Show resolved Hide resolved
String value = param.get(key);
if (StringUtils.isEmpty(value)) {
throw new IllegalArgumentException("Param '" + key + "' is required.");
}
return value;
}

/**
* get target value from param, if not found will return default value.
*
* @param param param
* @param key key
* @param defaultValue default value
* @return value
*/
public static String optional(final Map<String, String> param, final String key, final String defaultValue) {
horizonzy marked this conversation as resolved.
Show resolved Hide resolved
String value = param.get(key);
if (StringUtils.isBlank(value)) {
return defaultValue;
}
return value;
}

}
Loading