Skip to content

Commit

Permalink
#24 统一配置获取方式
Browse files Browse the repository at this point in the history
  • Loading branch information
TannerCai committed Mar 1, 2019
1 parent c9a998b commit 1adea88
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pallas.processor.property 相关参数只支持简单规则配置在./properties/pallas-application.properties 文件中
pallas.processor.property=com.vip.pallas.processor.prop.DefaultPropertyProcessor
pallas.processor.property.key-prefix=""
pallas.processor.property.key-prefix=

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vip.pallas.client.env.LoadEnv;
import com.vip.pallas.client.thread.CleanRestClientTask;
import com.vip.pallas.client.thread.QueryConsoleTask;

Expand Down Expand Up @@ -138,7 +137,7 @@ private static PallasRestClient createPallasRestclient(String clientToken,
while (QueryConsoleTask.getPsListByToken(clientToken) == null && retryCount-- > 0) {
TimeUnit.SECONDS.sleep(1);
log.error("can't get a valid pallas-search list from {} with token: {}, init pallas-client failed.",
LoadEnv.consoleQueryUrl, clientToken);
QueryConsoleTask.consoleQueryUrl, clientToken);
}
PallasRestClient pallasRestClient;
List<HttpHost> psHostList = null;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,41 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.vip.pallas.client.PallasRestClientBuilder;
import com.vip.pallas.client.env.LoadEnv;
import com.vip.pallas.client.util.HttpClient;
import com.vip.pallas.client.util.PallasRestClientProperties;
import com.vip.pallas.utils.IPUtils;

public class QueryConsoleTask implements Runnable {

private static final Logger log = LoggerFactory.getLogger(QueryConsoleTask.class);

private static final String PARAMS = "{\"token\":\"%s\", \"ip\":\"" + IPUtils.localIp4Str() + "\"}";

public static final String QUERY_URL_SUFFIX = "/pallas/ss/query_pslist_and_domain.json";

public static String consoleQueryUrl = addSuffixIfNecessary(PallasRestClientProperties.PALLAS_CONSOLE_QUERY_URL);

public static volatile Map<String, String> esDomainMap = new ConcurrentHashMap<>();

public static volatile Map<String, List<String>> psListMap = new ConcurrentHashMap<>();

private HashSet<String> tokenSet;

public static String addSuffixIfNecessary(String consoleQueryUrl) {
if (!consoleQueryUrl.endsWith(".json")) {
consoleQueryUrl += consoleQueryUrl.endsWith("/") ? StringUtils.substringAfter(QUERY_URL_SUFFIX, "/") : QUERY_URL_SUFFIX;
}
log.warn("console url located to: {}", consoleQueryUrl);
return consoleQueryUrl;
}

public QueryConsoleTask(HashSet<String> tokenSet) {
this.tokenSet = tokenSet;
Expand All @@ -57,7 +70,7 @@ public void run() {
try {
String token = iterator.next();
JSONObject jsonObject = JSON.parseObject(
HttpClient.httpPost(LoadEnv.consoleQueryUrl,
HttpClient.httpPost(consoleQueryUrl,
String.format(PARAMS, token)));
if (jsonObject != null) {
JSONObject data = jsonObject.getJSONObject("data");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright 2019 vip.com.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* </p>
*/

package com.vip.pallas.client.util;

import com.vip.pallas.utils.PallasBasicProperties;

public class PallasRestClientProperties extends PallasBasicProperties {

public static final String NAME_CONSOLE_QUERY_URL = "pallas.console.query.url";
public static final String PALLAS_CONSOLE_QUERY_URL = processor.getString(NAME_CONSOLE_QUERY_URL,
"http://localhost:8080");

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

import com.vip.pallas.client.PallasRestClient;
import com.vip.pallas.client.PallasRestClientBuilder;
import com.vip.pallas.client.env.LoadEnv;
import com.vip.pallas.client.thread.QueryConsoleTask;

public class MockHttpService extends LocalServerTestBase {

Expand Down Expand Up @@ -109,7 +109,7 @@ public void handle(HttpRequest request, HttpResponse response, HttpContext conte
});
target = start();
serverBootstrap.setSocketConfig(SocketConfig.custom().setSoTimeout(61000).build());
LoadEnv.consoleQueryUrl = "http://localhost:" + target.getPort() + "/getPsListAndEsDomain";
QueryConsoleTask.consoleQueryUrl = "http://localhost:" + target.getPort() + "/getPsListAndEsDomain";
String serverUrl = "http://localhost:" + target.getPort();
System.out.println("server listen at: " + serverUrl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.junit.rules.ExpectedException;

import com.vip.pallas.client.PallasRestClient;
import com.vip.pallas.client.env.LoadEnv;
import com.vip.pallas.client.thread.QueryConsoleTask;

public class PallasRestClientTest extends LocalServerTestBase {
Expand All @@ -49,7 +48,7 @@ public class PallasRestClientTest extends LocalServerTestBase {

static {
try {
System.setProperty("VIP_PALLAS_QUERY_INTERVAL_SECONDS", "2");
System.setProperty("PALLAS_QUERY_INTERVAL_SECONDS", "2");
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -99,7 +98,7 @@ public void handle(HttpRequest request, HttpResponse response, HttpContext conte
});
target = start();
serverBootstrap.setSocketConfig(SocketConfig.custom().setSoTimeout(61000).build());
LoadEnv.consoleQueryUrl = "http://localhost:" + target.getPort() + "/getPsListAndEsDomain";
QueryConsoleTask.consoleQueryUrl = "http://localhost:" + target.getPort() + "/getPsListAndEsDomain";
String serverUrl = "http://localhost:" + target.getPort();
System.out.println("server listen at: " + serverUrl);
}
Expand Down

0 comments on commit 1adea88

Please sign in to comment.