匹配回收,bug修复
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.nanri.aiimage.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
@Component
|
||||
public class InstanceMetadata {
|
||||
|
||||
private final String instanceId;
|
||||
private final String hostname;
|
||||
|
||||
public InstanceMetadata(@Value("${aiimage.instance-id:}") String configuredInstanceId) {
|
||||
this.hostname = resolveHostname();
|
||||
this.instanceId = configuredInstanceId == null || configuredInstanceId.isBlank()
|
||||
? this.hostname
|
||||
: configuredInstanceId.trim();
|
||||
}
|
||||
|
||||
public String getInstanceId() {
|
||||
return instanceId;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
private static String resolveHostname() {
|
||||
try {
|
||||
return InetAddress.getLocalHost().getHostName();
|
||||
} catch (Exception ignored) {
|
||||
String envHostname = System.getenv("HOSTNAME");
|
||||
return (envHostname == null || envHostname.isBlank()) ? "unknown-host" : envHostname;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user