Additional fail safe.
This commit is contained in:
parent
0d5e680318
commit
b919eb17ac
1 changed files with 18 additions and 2 deletions
|
|
@ -35,6 +35,8 @@ import io.kubernetes.client.util.generic.options.ListOptions;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -197,12 +199,15 @@ public class VmWatcher extends Component {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("PMD.CognitiveComplexity")
|
||||||
private void watchVmDefs(V1APIResource crd, String version) {
|
private void watchVmDefs(V1APIResource crd, String version) {
|
||||||
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
|
@SuppressWarnings({ "PMD.AvoidInstantiatingObjectsInLoops",
|
||||||
|
"PMD.AvoidLiteralsInIfCondition", "PMD.AvoidCatchingThrowable" })
|
||||||
var watcher = new Thread(() -> {
|
var watcher = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
// Watch sometimes terminates without apparent reason.
|
// Watch sometimes terminates without apparent reason.
|
||||||
while (true) {
|
while (true) {
|
||||||
|
Instant started = Instant.now();
|
||||||
var client = Config.defaultClient();
|
var client = Config.defaultClient();
|
||||||
var coa = new CustomObjectsApi(client);
|
var coa = new CustomObjectsApi(client);
|
||||||
var call = coa.listNamespacedCustomObjectCall(VM_OP_GROUP,
|
var call = coa.listNamespacedCustomObjectCall(VM_OP_GROUP,
|
||||||
|
|
@ -215,9 +220,20 @@ public class VmWatcher extends Component {
|
||||||
for (Watch.Response<V1Namespace> item : watch) {
|
for (Watch.Response<V1Namespace> item : watch) {
|
||||||
handleVmDefinitionChange(crd, item);
|
handleVmDefinitionChange(crd, item);
|
||||||
}
|
}
|
||||||
} catch (IllegalStateException e) {
|
} catch (Throwable e) {
|
||||||
logger.log(Level.FINE, e, () -> "Probem watching "
|
logger.log(Level.FINE, e, () -> "Probem watching "
|
||||||
+ "(retrying): " + e.getMessage());
|
+ "(retrying): " + e.getMessage());
|
||||||
|
var runningFor = Duration
|
||||||
|
.between(started, Instant.now()).getSeconds();
|
||||||
|
if (runningFor < 5) {
|
||||||
|
logger.log(Level.FINE, e, () -> "Waiting... ");
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000 - runningFor * 1000);
|
||||||
|
} catch (InterruptedException e1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
logger.log(Level.FINE, e, () -> "Restarting");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException | ApiException e) {
|
} catch (IOException | ApiException e) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue