use of org.hyperledger.besu.nat.core.exception.NatInitializationException in project besu by hyperledger.
the class UpnpNatManager method doStart.
/**
* Start the manager. Must not be in started state.
*
* @throws IllegalStateException if already started.
*/
@Override
public synchronized void doStart() throws NatInitializationException {
LOG.info("Starting UPnP Service");
try {
upnpService.startup();
upnpService.getRegistry().addListener(registryListener);
initiateExternalIpQuery();
} catch (Exception e) {
throw new NatInitializationException("Failed start UPnP nat service.", e);
}
}
use of org.hyperledger.besu.nat.core.exception.NatInitializationException in project besu by hyperledger.
the class DockerNatManagerTest method assertThatExternalIPIsEqualToDefaultHostIfIpDetectorCannotRetrieveIP.
@Test
public void assertThatExternalIPIsEqualToDefaultHostIfIpDetectorCannotRetrieveIP() throws ExecutionException, InterruptedException {
final NatManager natManager = new DockerNatManager(hostBasedIpDetector, advertisedHost, p2pPort, rpcHttpPort);
when(hostBasedIpDetector.detectAdvertisedIp()).thenReturn(Optional.empty());
try {
natManager.start();
} catch (NatInitializationException e) {
Assertions.fail(e.getMessage());
}
assertThat(natManager.queryExternalIPAddress().get()).isEqualTo(advertisedHost);
}
use of org.hyperledger.besu.nat.core.exception.NatInitializationException in project besu by hyperledger.
the class KubernetesNatManager method doStart.
@Override
protected void doStart() throws NatInitializationException {
LOG.info("Starting kubernetes NAT manager.");
try {
KubeConfig.registerAuthenticator(new GCPAuthenticator());
LOG.debug("Trying to update information using Kubernetes client SDK.");
final ApiClient client = ClientBuilder.cluster().build();
// set the global default api-client to the in-cluster one from above
Configuration.setDefaultApiClient(client);
// the CoreV1Api loads default api-client from global configuration.
final CoreV1Api api = new CoreV1Api();
// invokes the CoreV1Api client
final V1Service service = api.listServiceForAllNamespaces(null, null, null, null, null, null, null, null, null, null).getItems().stream().filter(v1Service -> v1Service.getMetadata().getName().contains(besuServiceNameFilter)).findFirst().orElseThrow(() -> new NatInitializationException("Service not found"));
updateUsingBesuService(service);
} catch (Exception e) {
throw new NatInitializationException(e.getMessage(), e);
}
}
use of org.hyperledger.besu.nat.core.exception.NatInitializationException in project besu by hyperledger.
the class DockerNatManager method doStart.
@Override
protected void doStart() throws NatInitializationException {
LOG.info("Starting docker NAT manager.");
try {
ipDetector.detectAdvertisedIp().ifPresent(ipFound -> internalAdvertisedHost = ipFound);
buildForwardedPorts();
} catch (Exception e) {
throw new NatInitializationException("Unable to retrieve IP from docker");
}
}
use of org.hyperledger.besu.nat.core.exception.NatInitializationException in project besu by hyperledger.
the class KubernetesNatManager method updateUsingBesuService.
@VisibleForTesting
void updateUsingBesuService(final V1Service service) throws RuntimeException {
try {
LOG.info("Found Besu service: {}", service.getMetadata().getName());
internalAdvertisedHost = getIpDetector(service).detectAdvertisedIp().orElseThrow(() -> new NatInitializationException("Unable to retrieve IP from service"));
LOG.info("Setting host IP to: {}.", internalAdvertisedHost);
final String internalHost = queryLocalIPAddress().get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
service.getSpec().getPorts().forEach(v1ServicePort -> {
try {
final NatServiceType natServiceType = NatServiceType.fromString(v1ServicePort.getName());
forwardedPorts.add(new NatPortMapping(natServiceType, natServiceType.equals(NatServiceType.DISCOVERY) ? NetworkProtocol.UDP : NetworkProtocol.TCP, internalHost, internalAdvertisedHost, v1ServicePort.getPort(), v1ServicePort.getTargetPort().getIntValue()));
} catch (IllegalStateException e) {
LOG.warn("Ignored unknown Besu port: {}", e.getMessage());
}
});
} catch (Exception e) {
throw new RuntimeException("Failed update information using pod metadata : " + e.getMessage(), e);
}
}
Aggregations