MCPcopy Create free account
hub / github.com/baidu/uid-generator / DockerUtils

Class DockerUtils

src/main/java/com/baidu/fsg/uid/utils/DockerUtils.java:27–104  ·  view source on GitHub ↗

DockerUtils @author yutianbao

Source from the content-addressed store, hash-verified

25 * @author yutianbao
26 */
27public abstract class DockerUtils {
28 private static final Logger LOGGER = LoggerFactory.getLogger(DockerUtils.class);
29
30 /** Environment param keys */
31 private static final String ENV_KEY_HOST = "JPAAS_HOST";
32 private static final String ENV_KEY_PORT = "JPAAS_HTTP_PORT";
33 private static final String ENV_KEY_PORT_ORIGINAL = "JPAAS_HOST_PORT_8080";
34
35 /** Docker host & port */
36 private static String DOCKER_HOST = "";
37 private static String DOCKER_PORT = "";
38
39 /** Whether is docker */
40 private static boolean IS_DOCKER;
41
42 static {
43 retrieveFromEnv();
44 }
45
46 /**
47 * Retrieve docker host
48 *
49 * @return empty string if not a docker
50 */
51 public static String getDockerHost() {
52 return DOCKER_HOST;
53 }
54
55 /**
56 * Retrieve docker port
57 *
58 * @return empty string if not a docker
59 */
60 public static String getDockerPort() {
61 return DOCKER_PORT;
62 }
63
64 /**
65 * Whether a docker
66 *
67 * @return
68 */
69 public static boolean isDocker() {
70 return IS_DOCKER;
71 }
72
73 /**
74 * Retrieve host & port from environment
75 */
76 private static void retrieveFromEnv() {
77 // retrieve host & port from environment
78 DOCKER_HOST = System.getenv(ENV_KEY_HOST);
79 DOCKER_PORT = System.getenv(ENV_KEY_PORT);
80
81 // not found from 'JPAAS_HTTP_PORT', then try to find from 'JPAAS_HOST_PORT_8080'
82 if (StringUtils.isBlank(DOCKER_PORT)) {
83 DOCKER_PORT = System.getenv(ENV_KEY_PORT_ORIGINAL);
84 }

Callers

nothing calls this directly

Calls 1

retrieveFromEnvMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…