|
2 | 2 |
|
3 | 3 | import com.uid2.operator.service.ShutdownService; |
4 | 4 | import com.uid2.shared.attest.AttestationResponseCode; |
5 | | -import lombok.extern.java.Log; |
6 | 5 | import org.slf4j.Logger; |
7 | 6 | import org.slf4j.LoggerFactory; |
8 | 7 | import software.amazon.awssdk.utils.Pair; |
|
16 | 15 | public class OperatorShutdownHandler { |
17 | 16 | private static final Logger LOGGER = LoggerFactory.getLogger(OperatorShutdownHandler.class); |
18 | 17 | private static final int SALT_FAILURE_LOG_INTERVAL_MINUTES = 10; |
| 18 | + private static final int KEYSET_KEY_FAILURE_LOG_INTERVAL_MINUTES = 10; |
19 | 19 | private final Duration attestShutdownWaitTime; |
20 | 20 | private final Duration saltShutdownWaitTime; |
| 21 | + private final Duration keysetKeyShutdownWaitTime; |
21 | 22 | private final AtomicReference<Instant> attestFailureStartTime = new AtomicReference<>(null); |
22 | 23 | private final AtomicReference<Instant> saltFailureStartTime = new AtomicReference<>(null); |
| 24 | + private final AtomicReference<Instant> keysetKeyFailureStartTime = new AtomicReference<>(null); |
23 | 25 | private final AtomicReference<Instant> lastSaltFailureLogTime = new AtomicReference<>(null); |
| 26 | + private final AtomicReference<Instant> lastKeysetKeyFailureLogTime = new AtomicReference<>(null); |
24 | 27 | private final Clock clock; |
25 | 28 | private final ShutdownService shutdownService; |
26 | 29 |
|
27 | | - public OperatorShutdownHandler(Duration attestShutdownWaitTime, Duration saltShutdownWaitTime, Clock clock, ShutdownService shutdownService) { |
| 30 | + public OperatorShutdownHandler(Duration attestShutdownWaitTime, Duration saltShutdownWaitTime, Duration keysetKeyShutdownWaitTime, Clock clock, ShutdownService shutdownService) { |
28 | 31 | this.attestShutdownWaitTime = attestShutdownWaitTime; |
29 | 32 | this.saltShutdownWaitTime = saltShutdownWaitTime; |
| 33 | + this.keysetKeyShutdownWaitTime = keysetKeyShutdownWaitTime; |
30 | 34 | this.clock = clock; |
31 | 35 | this.shutdownService = shutdownService; |
32 | 36 | } |
@@ -54,6 +58,29 @@ public void logSaltFailureAtInterval() { |
54 | 58 | } |
55 | 59 | } |
56 | 60 |
|
| 61 | + public void handleKeysetKeyRefreshResponse(Boolean success) { |
| 62 | + if (success) { |
| 63 | + keysetKeyFailureStartTime.set(null); |
| 64 | + } else { |
| 65 | + logKeysetKeyFailureAtInterval(); |
| 66 | + Instant t = keysetKeyFailureStartTime.get(); |
| 67 | + if (t == null) { |
| 68 | + keysetKeyFailureStartTime.set(clock.instant()); |
| 69 | + } else if (Duration.between(t, clock.instant()).compareTo(this.keysetKeyShutdownWaitTime) > 0) { |
| 70 | + LOGGER.error("keyset keys have been failing to sync for too long. shutting down operator"); |
| 71 | + this.shutdownService.Shutdown(1); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + public void logKeysetKeyFailureAtInterval() { |
| 77 | + Instant t = lastKeysetKeyFailureLogTime.get(); |
| 78 | + if (t == null || clock.instant().isAfter(t.plus(KEYSET_KEY_FAILURE_LOG_INTERVAL_MINUTES, ChronoUnit.MINUTES))) { |
| 79 | + LOGGER.error("keyset keys sync failing"); |
| 80 | + lastKeysetKeyFailureLogTime.set(Instant.now()); |
| 81 | + } |
| 82 | + } |
| 83 | + |
57 | 84 | public void handleAttestResponse(Pair<AttestationResponseCode, String> response) { |
58 | 85 | if (response.left() == AttestationResponseCode.AttestationFailure) { |
59 | 86 | LOGGER.error("core attestation failed with AttestationFailure, shutting down operator, core response: {}", response.right()); |
|
0 commit comments