mirror of
https://github.com/LamGC/Oracle-Sentry.git
synced 2025-04-29 22:27:34 +00:00
refactor(oci): 补充日志输出, 方便 Debug.
补充日志输出, 可通过配置 application.yml 的 logging.root 来控制是否打印这些日志以排查错误.
This commit is contained in:
parent
18d8bb1ef2
commit
2f98d1f91d
@ -9,6 +9,8 @@ import com.oracle.bmc.identity.responses.ListCompartmentsResponse;
|
|||||||
import net.lamgc.oracle.sentry.oci.account.OracleAccount;
|
import net.lamgc.oracle.sentry.oci.account.OracleAccount;
|
||||||
import net.lamgc.oracle.sentry.oci.compute.ComputeInstance;
|
import net.lamgc.oracle.sentry.oci.compute.ComputeInstance;
|
||||||
import net.lamgc.oracle.sentry.oci.compute.ssh.SshAuthIdentityProvider;
|
import net.lamgc.oracle.sentry.oci.compute.ssh.SshAuthIdentityProvider;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -25,6 +27,8 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public final class ComputeInstanceManager {
|
public final class ComputeInstanceManager {
|
||||||
|
|
||||||
|
private final static Logger log = LoggerFactory.getLogger(ComputeInstanceManager.class);
|
||||||
|
|
||||||
private final Map<String, ComputeInstance> instanceMap = new ConcurrentHashMap<>();
|
private final Map<String, ComputeInstance> instanceMap = new ConcurrentHashMap<>();
|
||||||
private SshAuthIdentityProvider sshIdentityProvider;
|
private SshAuthIdentityProvider sshIdentityProvider;
|
||||||
|
|
||||||
@ -34,8 +38,10 @@ public final class ComputeInstanceManager {
|
|||||||
* @throws IOException 加载时如有异常将直接抛出.
|
* @throws IOException 加载时如有异常将直接抛出.
|
||||||
*/
|
*/
|
||||||
public void initialSshIdentityProvider(File sshIdentityJson) throws IOException {
|
public void initialSshIdentityProvider(File sshIdentityJson) throws IOException {
|
||||||
|
log.debug("正在初始化 SSH 认证配置提供器...");
|
||||||
sshIdentityProvider = new SshAuthIdentityProvider(this, sshIdentityJson);
|
sshIdentityProvider = new SshAuthIdentityProvider(this, sshIdentityJson);
|
||||||
sshIdentityProvider.loadAuthInfo();
|
sshIdentityProvider.loadAuthInfo();
|
||||||
|
log.debug("SSH 认证配置提供器已初始化完成.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,13 +97,15 @@ public final class ComputeInstanceManager {
|
|||||||
.compartmentId(compartmentId)
|
.compartmentId(compartmentId)
|
||||||
.build());
|
.build());
|
||||||
for (Instance instance : listInstances.getItems()) {
|
for (Instance instance : listInstances.getItems()) {
|
||||||
if (instance.getLifecycleState() == Instance.LifecycleState.Terminated) {
|
if (instance.getLifecycleState() == Instance.LifecycleState.Terminated ||
|
||||||
|
instance.getLifecycleState() == Instance.LifecycleState.Terminating) {
|
||||||
|
log.debug("实例 {} 状态为 {}, 不添加该实例.", instance.getId(), instance.getLifecycleState());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ComputeInstance computeInstance = new ComputeInstance(this, instance.getId(),
|
ComputeInstance computeInstance = new ComputeInstance(this, instance.getId(),
|
||||||
compartmentId, instance.getImageId(), account);
|
compartmentId, instance.getImageId(), account);
|
||||||
|
|
||||||
addComputeInstance(computeInstance);
|
addComputeInstance(computeInstance);
|
||||||
|
log.debug("已为用户 {} 添加计算实例: {}", account.id(), instance.getId());
|
||||||
addCount ++;
|
addCount ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user