Skip to content

Commit d7d35ea

Browse files
committed
OK-611 Refaktoroitu lisää virheenkäsittelyä
1 parent 6e0365f commit d7d35ea

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

src/main/java/fi/vm/sade/valinta/kooste/external/resource/HttpClients.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ public RestCasClient getSuoritusrekisteriCasClient(
274274
return new RestCasClient(
275275
new CasConfig.CasConfigBuilder(
276276
username, password, ticketsUrl, service, CSRF_VALUE, CALLER_ID, "")
277+
.setNumberOfRetries(0)
277278
.setJsessionName("JSESSIONID")
278279
.build());
279280
}

src/main/java/fi/vm/sade/valinta/kooste/valintalaskenta/actor/ConcurrencyLimiter.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ public class ConcurrencyLimiter {
2020

2121
private static final Logger LOG = LoggerFactory.getLogger(ConcurrencyLimiter.class);
2222

23-
public static final Duration TIMEOUT = Duration.ofMillis(Long.MIN_VALUE + 1);
24-
public static final Duration ERROR = Duration.ofMillis(Long.MIN_VALUE + 2);
23+
public static final Duration ONGOING = Duration.ofMillis(Long.MIN_VALUE + 1);
24+
public static final Duration TIMEOUT = Duration.ofMillis(Long.MIN_VALUE + 2);
25+
public static final Duration ERROR = Duration.ofMillis(Long.MIN_VALUE + 3);
2526

2627
private int maxPermits;
2728
private final String nimi;
@@ -95,7 +96,9 @@ public String getNimi() {
9596
}
9697

9798
public static String asDurationString(Duration duration) {
98-
if (duration == TIMEOUT) {
99+
if (duration == ONGOING) {
100+
return "ongoing";
101+
} else if (duration == TIMEOUT) {
99102
return "timeout";
100103
} else if (duration == ERROR) {
101104
return "error";
@@ -136,16 +139,19 @@ public <T> CompletableFuture<T> withConcurrencyLimit(
136139
// suoritetaan pyyntö
137140
this.active.incrementAndGet();
138141
try {
142+
invokeDurations.put(this.nimi, ONGOING);
139143
T result = supplier.get().get();
140144
invokeDurations.put(this.nimi, Duration.between(invokeStart, Instant.now()));
141145
future.complete(result);
142146
} catch (ExecutionException e) {
143-
if (e.getCause() instanceof TimeoutException) {
147+
Throwable underlyingCause = getUnderlyingCause(e);
148+
if (underlyingCause instanceof TimeoutException) {
144149
invokeDurations.put(this.nimi, TIMEOUT);
150+
future.completeExceptionally(underlyingCause);
145151
} else {
146152
invokeDurations.put(this.nimi, ERROR);
153+
future.completeExceptionally(e);
147154
}
148-
future.completeExceptionally(e.getCause());
149155
} catch (Exception e) {
150156
invokeDurations.put(this.nimi, ERROR);
151157
future.completeExceptionally(e);
@@ -157,4 +163,11 @@ public <T> CompletableFuture<T> withConcurrencyLimit(
157163

158164
return future;
159165
}
166+
167+
private static Throwable getUnderlyingCause(Throwable t) {
168+
if (t.getCause() != null) {
169+
return getUnderlyingCause(t.getCause());
170+
}
171+
return t;
172+
}
160173
}

src/main/java/fi/vm/sade/valinta/kooste/valintalaskenta/actor/LaskentaResurssiProvider.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,17 +641,25 @@ public CompletableFuture<LaskeDTO> fetchResourcesForOneLaskenta(
641641
.orTimeout(9 * 60 * 1000l, TimeUnit.MILLISECONDS)
642642
.exceptionallyAsync(
643643
ex -> {
644-
if (ex instanceof TimeoutException) {
645-
invokeDurations.put("Total (timeout)", Duration.between(start, Instant.now()));
646-
this.tallennaLokitJaMetriikat(hakukohdeOid, waitDurations, invokeDurations);
647-
}
648-
result.completeExceptionally(ex);
644+
Throwable underlyingCause = getUnderlyingCause(ex);
645+
invokeDurations.put(
646+
"Total" + (underlyingCause instanceof TimeoutException ? " (timeout)" : ""),
647+
Duration.between(start, Instant.now()));
648+
this.tallennaLokitJaMetriikat(hakukohdeOid, waitDurations, invokeDurations);
649+
result.completeExceptionally(underlyingCause);
649650
return null;
650651
},
651652
this.executor);
652653
return result;
653654
}
654655

656+
private static Throwable getUnderlyingCause(Throwable t) {
657+
if (t.getCause() != null) {
658+
return getUnderlyingCause(t.getCause());
659+
}
660+
return t;
661+
}
662+
655663
private <T> CompletableFuture<T> createResurssiFuture(
656664
LaskentaResurssinhakuWrapper.PyynnonTunniste tunniste,
657665
String resurssi,

0 commit comments

Comments
 (0)