|
|
|
@ -52,22 +52,25 @@ public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh
|
|
|
|
|
|
|
|
|
|
private static final String KEY = "key";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getProperties() throws Exception {
|
|
|
|
|
Map<String, String> etcd = bootstrapConfigProperties.getEtcd();
|
|
|
|
|
Charset charset = StringUtil.isBlank(etcd.get(CHARSET)) ? StandardCharsets.UTF_8 : Charset.forName(etcd.get(CHARSET));
|
|
|
|
|
initClient(etcd, charset);
|
|
|
|
|
|
|
|
|
|
String key = etcd.get(KEY);
|
|
|
|
|
GetResponse getResponse = client.getKVClient().get(ByteSequence.from(key, charset)).get();
|
|
|
|
|
KeyValue keyValue = getResponse.getKvs().get(0);
|
|
|
|
|
return Objects.isNull(keyValue) ? null : keyValue.getValue().toString(charset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterPropertiesSet() throws Exception {
|
|
|
|
|
Map<String, String> etcd = bootstrapConfigProperties.getEtcd();
|
|
|
|
|
String user = etcd.get(USER);
|
|
|
|
|
String password = etcd.get(PASSWORD);
|
|
|
|
|
String endpoints = etcd.get(ENDPOINTS);
|
|
|
|
|
String authority = etcd.get(AUTHORITY);
|
|
|
|
|
String key = etcd.get(KEY);
|
|
|
|
|
Charset charset = StringUtil.isBlank(etcd.get(CHARSET)) ? StandardCharsets.UTF_8 : Charset.forName(etcd.get(CHARSET));
|
|
|
|
|
ClientBuilder clientBuilder = Client.builder().endpoints(endpoints.split(","));
|
|
|
|
|
// todo
|
|
|
|
|
if (Objects.isNull(client)) {
|
|
|
|
|
client = StringUtil.isAllNotEmpty(user, password) ? clientBuilder.user(ByteSequence.from(user, charset))
|
|
|
|
|
.password(ByteSequence.from(password, charset)).authority(authority)
|
|
|
|
|
.build() : clientBuilder.build();
|
|
|
|
|
}
|
|
|
|
|
initClient(etcd, charset);
|
|
|
|
|
|
|
|
|
|
// todo Currently only supports json
|
|
|
|
|
GetResponse getResponse = client.getKVClient().get(ByteSequence.from(key, charset)).get();
|
|
|
|
|
KeyValue keyValue = getResponse.getKvs().get(0);
|
|
|
|
@ -100,4 +103,25 @@ public class EtcdRefresherHandler extends AbstractConfigThreadPoolDynamicRefresh
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* if client is null, init it
|
|
|
|
|
*
|
|
|
|
|
* @param etcd etcd configuration item
|
|
|
|
|
* @param charset charset
|
|
|
|
|
*/
|
|
|
|
|
private void initClient(Map<String, String> etcd, Charset charset) {
|
|
|
|
|
// todo
|
|
|
|
|
if (Objects.isNull(client)) {
|
|
|
|
|
String user = etcd.get(USER);
|
|
|
|
|
String password = etcd.get(PASSWORD);
|
|
|
|
|
String authority = etcd.get(AUTHORITY);
|
|
|
|
|
String endpoints = etcd.get(ENDPOINTS);
|
|
|
|
|
ClientBuilder clientBuilder = Client.builder().endpoints(endpoints.split(","));
|
|
|
|
|
client = StringUtil.isAllNotEmpty(user, password) ? clientBuilder.user(ByteSequence.from(user, charset))
|
|
|
|
|
.password(ByteSequence.from(password, charset)).authority(authority)
|
|
|
|
|
.build() : clientBuilder.build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|