Merge pull request 'пофикшено падение при получении префиксов' (#1) from hotfix/asn-fetching into master
Reviewed-on: #1
This commit is contained in:
commit
b94dbb98a4
|
|
@ -13,6 +13,7 @@ import java.net.URI;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
|
@ -33,7 +34,9 @@ public class HEInfoProvider implements ASInfoProvider {
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public List<IPv4Subnet> getPrefixes(int as) {
|
public List<IPv4Subnet> getPrefixes(int as) {
|
||||||
try (var client = HttpClient.newHttpClient()) {
|
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());
|
var response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
|
||||||
if (response.statusCode() == 200) {
|
if (response.statusCode() == 200) {
|
||||||
try (var inputStream = response.body()) {
|
try (var inputStream = response.body()) {
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ public class NetworkingService extends AppService {
|
||||||
SystemLogger.message("Updating network manager", CTX);
|
SystemLogger.message("Updating network manager", CTX);
|
||||||
|
|
||||||
updateProcess.set(executor.submit(() -> {
|
updateProcess.set(executor.submit(() -> {
|
||||||
|
try {
|
||||||
SystemLogger.message("Update is started", CTX);
|
SystemLogger.message("Update is started", CTX);
|
||||||
var config = context.getConfig();
|
var config = context.getConfig();
|
||||||
var filteredResources = config.getFilteredResources();
|
var filteredResources = config.getFilteredResources();
|
||||||
|
|
@ -167,10 +168,12 @@ public class NetworkingService extends AppService {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SystemLogger.error("Unable to invoke update event", CTX, 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.
|
* 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();
|
var iPv4Subnets = future.get();
|
||||||
prefixCache.put(as, iPv4Subnets);
|
prefixCache.put(as, iPv4Subnets);
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} 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.
|
* Removes event subscriptions and shuts down the executor.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue