hotfix: router os progress counter and gateway match
This commit is contained in:
parent
991007a39b
commit
3683dde410
|
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Component that synchronises FRR routing instances with the aggregated subnet list.
|
||||
|
|
@ -45,7 +46,7 @@ public final class ROS extends AbstractComponent<ROS.ROSConfig> {
|
|||
connection.login(entry.username, entry.password);
|
||||
SystemLogger.message("Fetching existing subnets...", CTX);
|
||||
var existingSubnets = new HashMap<String, IPv4Subnet>();
|
||||
var result = connection.execute("/ip/route/print where routing-table=" + entry.VRF);
|
||||
var result = connection.execute("/ip/route/print where gateway=" + entry.gateway + " and routing-table=" + entry.VRF);
|
||||
result.forEach(row -> {
|
||||
if (row.containsKey("static") && row.get("static").equals("true")) {
|
||||
existingSubnets.put(row.get(".id"), new IPv4Subnet(row.get("dst-address")));
|
||||
|
|
@ -57,26 +58,41 @@ public final class ROS extends AbstractComponent<ROS.ROSConfig> {
|
|||
var subnetsToRemove = existingSubnets.keySet().stream().filter(id -> !subnets.contains(existingSubnets.get(id))).toList();
|
||||
if (!subnetsToRemove.isEmpty()) {
|
||||
SystemLogger.message(subnetsToRemove.size() + " subnets should be removed", CTX);
|
||||
var counter = new AtomicInteger(0);
|
||||
subnetsToRemove.forEach(id -> {
|
||||
try {
|
||||
connection.execute("/ip/route/remove .id=" + id);
|
||||
counter.incrementAndGet();
|
||||
|
||||
if (counter.get() % 100 == 0) {
|
||||
SystemLogger.message(counter.get() + " subnets has been removed", CTX);
|
||||
}
|
||||
} catch (MikrotikApiException e) {
|
||||
throw new RuntimeException("Failed to remove subnet " + id, e);
|
||||
}
|
||||
});
|
||||
|
||||
SystemLogger.message("All subnets has been removed", CTX);
|
||||
|
||||
}
|
||||
|
||||
//добавляем новые подсети
|
||||
var subnetsToAdd = subnets.stream().filter(subnet -> !existingSubnets.containsValue(subnet)).toList();
|
||||
if (!subnetsToAdd.isEmpty()) {
|
||||
SystemLogger.message(subnetsToAdd.size() + " subnets should be added", CTX);
|
||||
var counter = new AtomicInteger(0);
|
||||
subnetsToAdd.forEach(subnet -> {
|
||||
try {
|
||||
connection.execute("/ip/route/add dst-address=" + subnet + " gateway=" + entry.gateway + " routing-table=" + entry.VRF);
|
||||
counter.incrementAndGet();
|
||||
if(counter.get() % 100 == 0){
|
||||
SystemLogger.message(counter.get() + " subnets has been added", CTX);
|
||||
}
|
||||
} catch (MikrotikApiException e) {
|
||||
throw new RuntimeException("Failed to remove subnet " + subnet, e);
|
||||
}
|
||||
});
|
||||
SystemLogger.message("All subnets has been added", CTX);
|
||||
}
|
||||
|
||||
SystemLogger.message("ROS update is complete", CTX);
|
||||
|
|
|
|||
Loading…
Reference in New Issue