Skip to content

Commit 8bc54ce

Browse files
committed
Add a switch for dynamically obtaining environment variables
1 parent 68978e6 commit 8bc54ce

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

joylive-core/joylive-core-framework/src/main/java/com/jd/live/agent/core/bootstrap/env/http/HttpEnvSupplier.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class HttpEnvSupplier extends AbstractEnvSupplier {
4949
private static final String KEY_NACOS_NAMESPACE = "CONFIG_NACOS_NAMESPACE";
5050
private static final String KEY_NACOS_SERVICE = "CONFIG_NACOS_SERVICE";
5151

52+
@Config("env.http.enabled")
53+
private boolean enabled;
54+
5255
@Config("env.http.url")
5356
private String url;
5457

@@ -76,6 +79,10 @@ public class HttpEnvSupplier extends AbstractEnvSupplier {
7679
@Override
7780
public void process(AppEnv env) {
7881
env.setEnvironment(environment);
82+
if (!enabled) {
83+
logger.info("Ignore loading env from http, caused by enabled switch.");
84+
return;
85+
}
7986
if (isEmpty(url)) {
8087
String serviceApi = env.getString(KEY_SERVICE_API_URL);
8188
if (isEmpty(serviceApi)) {

joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/config/RegistryRole.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public enum RegistryRole {
2525

2626
/**
27-
* Primary role with highest priority (order=2).
27+
* Primary role with the highest priority (order=2).
2828
*/
2929
PRIMARY(0),
3030

@@ -34,7 +34,7 @@ public enum RegistryRole {
3434
SYSTEM(1),
3535

3636
/**
37-
* Secondary role with lowest priority (order=0).
37+
* Secondary role with the lowest priority (order=0).
3838
*/
3939
SECONDARY(2);
4040

joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/registry/LiveRegistry.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,11 @@ public CompletionStage<List<ServiceEndpoint>> getEndpoints(String service, Strin
316316
future.complete(v);
317317
} else {
318318
// don't convert service name in system registry
319-
system.getEndpoints(service).whenComplete((e, r) -> {
320-
if (r != null) {
321-
future.completeExceptionally(r);
319+
system.getEndpoints(service).whenComplete((r, e) -> {
320+
if (e != null) {
321+
future.completeExceptionally(e);
322322
} else {
323-
future.complete(e);
323+
future.complete(r);
324324
}
325325
});
326326
}

joylive-package/src/main/assembly/config/bootstrap.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ cipher.iv=${CONFIG_CIPHER_IV}
4747
cipher.ivSize=${CONFIG_CIPHER_IV_SIZE:16}
4848
cipher.iterations=${CONFIG_CIPHER_ITERATIONS:1000}
4949
cipher.properties=${CONFIG_CIPHER_PROPERTIES}
50+
env.http.enabled=${CONFIG_ENV_HTTP_ENABLED:false}
5051
env.http.url=${CONFIG_ENV_HTTP_URL}
5152
env.http.environment=${CONFIG_ENV_HTTP_ENVIRONMENT:false}
5253
env.http.parameters=${CONFIG_ENV_HTTP_PARAMETERS}

0 commit comments

Comments
 (0)