use of com.ecwid.consul.v1.kv.model.GetValue in project motan by weibocom.
the class ConsulCommandService method getAllCommands.
/**
* 获取所有指令
*
* @return
*/
@Override
public List<JSONObject> getAllCommands() {
List<JSONObject> commands = new ArrayList<JSONObject>();
Response<List<GetValue>> response = consulClient.getKVValues(ConsulConstants.CONSUL_MOTAN_COMMAND);
List<GetValue> values = response.getValue();
if (values != null) {
for (GetValue value : values) {
JSONObject node = new JSONObject();
if (value.getValue() == null) {
continue;
}
String group = value.getKey().substring(ConsulConstants.CONSUL_MOTAN_COMMAND.length());
String command = new String(Base64.decodeBase64(value.getValue()));
node.put("group", group);
node.put("command", RpcCommandUtil.stringToCommand(command));
commands.add(node);
}
}
return commands;
}
use of com.ecwid.consul.v1.kv.model.GetValue in project spring-cloud-consul by spring-cloud.
the class FilteringAgentClient method getAliveAgents.
public List<Member> getAliveAgents() {
List<Member> members = client.getAgentMembers().getValue();
List<Member> liveMembers = new ArrayList<>(members.size());
for (Member peer : members) {
if (peer.getStatus() == ALIVE_STATUS) {
liveMembers.add(peer);
}
}
return liveMembers;
}
use of com.ecwid.consul.v1.kv.model.GetValue in project spring-cloud-consul by spring-cloud.
the class ServiceCheckServerListFilter method getFilteredListOfServers.
@Override
public List<Server> getFilteredListOfServers(List<Server> servers) {
List<Server> okServers = new ArrayList<>(servers.size());
for (Server server : servers) {
String appName = server.getMetaInfo().getAppName();
String instanceId = server.getMetaInfo().getInstanceId();
// TODO: cache getHealthChecks? this is hit often
List<Check> serviceChecks = client.getHealthChecksForService(appName, QueryParams.DEFAULT).getValue();
boolean serviceOk = true;
for (Check check : serviceChecks) {
if (check.getServiceId().equals(instanceId) && check.getStatus() != Check.CheckStatus.PASSING) {
serviceOk = false;
// just need one to fail
break;
}
}
if (serviceOk) {
okServers.add(server);
}
}
return okServers;
}
use of com.ecwid.consul.v1.kv.model.GetValue in project spring-cloud-consul by spring-cloud.
the class ConsulPropertySource method parsePropertiesInKeyValueFormat.
/**
* Parses the properties in key value style i.e., values are expected to be either a
* sub key or a constant
*
* @param values
*/
protected void parsePropertiesInKeyValueFormat(List<GetValue> values) {
if (values == null) {
return;
}
for (GetValue getValue : values) {
String key = getValue.getKey();
if (!StringUtils.endsWithIgnoreCase(key, "/")) {
key = key.replace(context, "").replace('/', '.');
String value = getValue.getDecodedValue();
properties.put(key, value);
}
}
}
use of com.ecwid.consul.v1.kv.model.GetValue in project spring-cloud-consul by spring-cloud.
the class ConsulPropertySourceLocator method locate.
@Override
@Retryable(interceptor = "consulRetryInterceptor")
public PropertySource<?> locate(Environment environment) {
if (environment instanceof ConfigurableEnvironment) {
ConfigurableEnvironment env = (ConfigurableEnvironment) environment;
String appName = properties.getName();
if (appName == null) {
appName = env.getProperty("spring.application.name");
}
List<String> profiles = Arrays.asList(env.getActiveProfiles());
String prefix = this.properties.getPrefix();
List<String> suffixes = new ArrayList<>();
if (this.properties.getFormat() != FILES) {
suffixes.add("/");
} else {
suffixes.add(".yml");
suffixes.add(".yaml");
suffixes.add(".properties");
}
String defaultContext = getContext(prefix, this.properties.getDefaultContext());
for (String suffix : suffixes) {
this.contexts.add(defaultContext + suffix);
}
for (String suffix : suffixes) {
addProfiles(this.contexts, defaultContext, profiles, suffix);
}
String baseContext = getContext(prefix, appName);
for (String suffix : suffixes) {
this.contexts.add(baseContext + suffix);
}
for (String suffix : suffixes) {
addProfiles(this.contexts, baseContext, profiles, suffix);
}
Collections.reverse(this.contexts);
CompositePropertySource composite = new CompositePropertySource("consul");
for (String propertySourceContext : this.contexts) {
try {
ConsulPropertySource propertySource = null;
if (this.properties.getFormat() == FILES) {
Response<GetValue> response = this.consul.getKVValue(propertySourceContext, this.properties.getAclToken());
addIndex(propertySourceContext, response.getConsulIndex());
if (response.getValue() != null) {
ConsulFilesPropertySource filesPropertySource = new ConsulFilesPropertySource(propertySourceContext, this.consul, this.properties);
filesPropertySource.init(response.getValue());
propertySource = filesPropertySource;
}
} else {
propertySource = create(propertySourceContext, contextIndex);
}
if (propertySource != null) {
composite.addPropertySource(propertySource);
}
} catch (Exception e) {
if (this.properties.isFailFast()) {
log.error("Fail fast is set and there was an error reading configuration from consul.");
ReflectionUtils.rethrowRuntimeException(e);
} else {
log.warn("Unable to load consul config from " + propertySourceContext, e);
}
}
}
return composite;
}
return null;
}
Aggregations