-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
615ec8d
commit c9a998b
Showing
6 changed files
with
104 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
pallas-rest-client/src/main/java/com/vip/pallas/client/env/LoadEnv.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.vip.pallas.client.env; | ||
|
||
import java.util.Iterator; | ||
import java.util.ServiceLoader; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public abstract class LoadEnv { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(LoadEnv.class); | ||
|
||
public static String consoleQueryUrl; | ||
|
||
private static LoadEnv envInstance; | ||
|
||
public static final String CONSOLE_QUERY_URL_ENV_KEY = "VIP_PALLAS_CONSOLE_QUERY_URL"; | ||
|
||
public static final String QUERY_URL_SUFFIX = "/pallas/ss/query_pslist_and_domain.json"; | ||
|
||
static { | ||
initEnvImpl(); | ||
} | ||
|
||
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 static LoadEnv envInstance() { | ||
return envInstance; | ||
} | ||
|
||
private static void initEnvImpl() { | ||
try { | ||
// discover LoadEnv | ||
ServiceLoader<LoadEnv> loader = ServiceLoader.load(LoadEnv.class); | ||
Iterator<LoadEnv> iter = loader.iterator(); | ||
while (iter.hasNext()) { | ||
envInstance = iter.next(); | ||
log.info("LoadEnv implementation found: {}", envInstance.getClass().getName()); | ||
return; | ||
} | ||
// log error, fallback | ||
envInstance = new LoadOpenEnv(); | ||
log.error("LoadEnv implementation not found, fallback to: {}", envInstance.getClass().getName()); | ||
} catch (Throwable e) { | ||
// log error, fallback | ||
envInstance = new LoadOpenEnv(); | ||
log.error("LoadEnv implementation not found, fallback to: {}", envInstance.getClass().getName()); | ||
} | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
pallas-rest-client/src/main/java/com/vip/pallas/client/env/LoadOpenEnv.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.vip.pallas.client.env; | ||
|
||
public class LoadOpenEnv extends LoadEnv { | ||
|
||
static { | ||
consoleQueryUrl = System.getProperty(CONSOLE_QUERY_URL_ENV_KEY, "http://localhost:8080"); | ||
consoleQueryUrl = addSuffixIfNecessary(consoleQueryUrl); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters