пофикшено падение при получении префиксов

This commit is contained in:
kirillius 2025-12-18 14:13:14 +03:00
parent 1bcf317c8f
commit 218e21220f
2 changed files with 72 additions and 67 deletions

View File

@ -13,6 +13,7 @@ import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
@ -33,7 +34,9 @@ public class HEInfoProvider implements ASInfoProvider {
@SneakyThrows
public List<IPv4Subnet> getPrefixes(int as) {
try (var client = HttpClient.newHttpClient()) {
var request = HttpRequest.newBuilder().uri(URI.create("https://bgp.he.net/super-lg/report/api/v1/prefixes/originated/" + as)).header("Accept", "application/json").GET().build();
var request = HttpRequest.newBuilder()
.uri(URI.create("https://bgp.he.net/super-lg/report/api/v1/prefixes/originated/" + as))
.header("Accept", "application/json").timeout(Duration.ofMinutes(2)).GET().build();
var response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
if (response.statusCode() == 200) {
try (var inputStream = response.body()) {

View File

@ -92,6 +92,7 @@ public class NetworkingService extends AppService {
SystemLogger.message("Updating network manager", CTX);
updateProcess.set(executor.submit(() -> {
try {
SystemLogger.message("Update is started", CTX);
var config = context.getConfig();
var filteredResources = config.getFilteredResources();
@ -167,10 +168,12 @@ public class NetworkingService extends AppService {
} catch (Exception e) {
SystemLogger.error("Unable to invoke update event", CTX, e);
}
} catch (Exception e) {
SystemLogger.error("Something went wrong on update", CTX, e);
}
}));
}
/**
* Fetches prefixes for the given autonomous systems and stores them in the cache.
*/
@ -188,12 +191,11 @@ public class NetworkingService extends AppService {
var iPv4Subnets = future.get();
prefixCache.put(as, iPv4Subnets);
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
SystemLogger.error("Error happened while fetching AS" + as + " prefixes. Trying to use cached prefixes...", CTX, e);
}
});
}
/**
* Removes event subscriptions and shuts down the executor.
*/