后台管理接口修复 后端BUG修复
This commit is contained in:
@@ -1,21 +1,38 @@
|
||||
package com.nanri.aiimage.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class InstanceMetadata {
|
||||
|
||||
private final String instanceId;
|
||||
private final String hostname;
|
||||
private final String source;
|
||||
private final boolean stable;
|
||||
|
||||
public InstanceMetadata(@Value("${aiimage.instance-id:}") String configuredInstanceId) {
|
||||
this.hostname = resolveHostname();
|
||||
this.instanceId = configuredInstanceId == null || configuredInstanceId.isBlank()
|
||||
? this.hostname
|
||||
: configuredInstanceId.trim();
|
||||
String normalizedConfiguredInstanceId = configuredInstanceId == null ? "" : configuredInstanceId.trim();
|
||||
if (!normalizedConfiguredInstanceId.isBlank()) {
|
||||
this.instanceId = normalizedConfiguredInstanceId;
|
||||
this.source = "configured";
|
||||
this.stable = true;
|
||||
log.info("[instance] resolved instanceId={} source={} hostname={} continuityRisk=LOW",
|
||||
this.instanceId, this.source, this.hostname);
|
||||
} else {
|
||||
this.instanceId = this.hostname;
|
||||
this.source = detectFallbackSource(this.hostname);
|
||||
this.stable = false;
|
||||
log.warn("[instance] aiimage.instance-id is not configured, falling back to {}={} as instanceId. "
|
||||
+ "This may change after restart/redeploy and break task owner continuity. "
|
||||
+ "Set AIIMAGE_INSTANCE_ID in 1Panel/Docker env, or set -Daiimage.instance-id=<stable-id> in IDEA/local startup.",
|
||||
this.source, this.hostname);
|
||||
}
|
||||
}
|
||||
|
||||
public String getInstanceId() {
|
||||
@@ -26,6 +43,14 @@ public class InstanceMetadata {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public boolean isStable() {
|
||||
return stable;
|
||||
}
|
||||
|
||||
private static String resolveHostname() {
|
||||
try {
|
||||
return InetAddress.getLocalHost().getHostName();
|
||||
@@ -34,4 +59,12 @@ public class InstanceMetadata {
|
||||
return (envHostname == null || envHostname.isBlank()) ? "unknown-host" : envHostname;
|
||||
}
|
||||
}
|
||||
|
||||
private static String detectFallbackSource(String hostname) {
|
||||
String envHostname = System.getenv("HOSTNAME");
|
||||
if (envHostname != null && !envHostname.isBlank() && envHostname.equalsIgnoreCase(hostname)) {
|
||||
return "env.HOSTNAME";
|
||||
}
|
||||
return "os.hostname";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user