Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datanode preflight dns check #20492

Merged
merged 12 commits into from
Oct 28, 2024
5 changes: 5 additions & 0 deletions changelog/unreleased/issue-20503.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type="c"
message="Datanode preflight check that verifies if hostname is bound to an IP"

issues=["20503"]
pulls=["20492"]
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.MapBinder;
import org.graylog.datanode.bootstrap.preflight.DatanodeDirectoriesLockfileCheck;
import org.graylog.datanode.bootstrap.preflight.DatanodeDnsPreflightCheck;
import org.graylog.datanode.bootstrap.preflight.DatanodeKeystoreCheck;
import org.graylog.datanode.bootstrap.preflight.OpenSearchPreconditionsCheck;
import org.graylog.datanode.bootstrap.preflight.OpensearchBinPreflightCheck;
Expand All @@ -41,6 +42,7 @@ protected void configure() {
bind(CertificateExchange.class).to(CertificateExchangeImpl.class);

addPreflightCheck(OpensearchConfigSync.class);
addPreflightCheck(DatanodeDnsPreflightCheck.class);
addPreflightCheck(OpensearchBinPreflightCheck.class);
addPreflightCheck(DatanodeDirectoriesLockfileCheck.class);
addPreflightCheck(OpenSearchPreconditionsCheck.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
package org.graylog.datanode.bootstrap.preflight;

import jakarta.inject.Inject;
import org.graylog.datanode.Configuration;
import org.graylog2.bootstrap.preflight.PreflightCheck;
import org.graylog2.bootstrap.preflight.PreflightCheckException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.stream.Stream;

public class DatanodeDnsPreflightCheck implements PreflightCheck {

private static final Logger LOG = LoggerFactory.getLogger(DatanodeDnsPreflightCheck.class);

private final String configuredHostname;

@Inject
public DatanodeDnsPreflightCheck(Configuration datanodeConfiguration) {
configuredHostname = datanodeConfiguration.getHostname();
}

@Override
public void runCheck() throws PreflightCheckException {
try {
final InetAddress[] addresses = InetAddress.getAllByName(configuredHostname);
final List<String> ips = Stream.of(addresses).map(InetAddress::getHostAddress).toList();
LOG.debug("Datanode host " + configuredHostname + " is available on " + ips + " addresses");
todvora marked this conversation as resolved.
Show resolved Hide resolved
} catch (UnknownHostException e) {
throw new PreflightCheckException("Configured hostname " + configuredHostname + " is not bound to any address! Please configure your DNS so the hostname points to this machine");
}
}
}
Loading