NIFI-2485 Added log messages and default values to standalone tool.

NIFI-2485 - Updating standalone success message (+2 squashed commits)
Squashed commits:
[68638bc] NIFI-2485 - Logging successful host processing in standalone
[9b41e0f] NIFI-2485 - Updating standalone defaults, adding logging

This closes #790.

Signed-off-by: Andy LoPresto <alopresto@apache.org>
This commit is contained in:
Bryan Rosander 2016-08-04 11:37:32 -04:00 committed by Andy LoPresto
parent 0e0166cec5
commit d223423de9
No known key found for this signature in database
GPG Key ID: 3C6EF65B2F7DEF69
4 changed files with 29 additions and 20 deletions

View File

@ -35,9 +35,9 @@ public class NifiPropertiesTlsClientConfigWriter implements ConfigurationWriter<
private final OutputStreamFactory outputStreamFactory;
private final File file;
private final String hostname;
private final String httpsPort;
private final int httpsPort;
public NifiPropertiesTlsClientConfigWriter(NiFiPropertiesWriterFactory niFiPropertiesWriterFactory, OutputStreamFactory outputStreamFactory, File file, String hostname, String httpsPort) {
public NifiPropertiesTlsClientConfigWriter(NiFiPropertiesWriterFactory niFiPropertiesWriterFactory, OutputStreamFactory outputStreamFactory, File file, String hostname, int httpsPort) {
this.niFiPropertiesWriterFactory = niFiPropertiesWriterFactory;
this.outputStreamFactory = outputStreamFactory;
this.file = file;
@ -63,14 +63,12 @@ public class NifiPropertiesTlsClientConfigWriter implements ConfigurationWriter<
niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_TRUSTSTORE, parentPath.relativize(Paths.get(tlsClientConfig.getTrustStore())).toString());
niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_TRUSTSTORE_TYPE, tlsClientConfig.getTrustStoreType());
niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD, tlsClientConfig.getTrustStorePassword());
if (!StringUtils.isEmpty(httpsPort)) {
if (!StringUtils.isEmpty(hostname)) {
niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTPS_HOST, hostname);
}
niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTPS_PORT, httpsPort);
niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTPS_PORT, Integer.toString(httpsPort));
niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTP_HOST, "");
niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTP_PORT, "");
niFiPropertiesWriter.setPropertyValue(NiFiProperties.SITE_TO_SITE_SECURE, "true");
}
}
}

View File

@ -58,7 +58,7 @@ public class TlsToolkitStandalone {
}
public void createNifiKeystoresAndTrustStores(File baseDir, TlsConfig tlsConfig, NiFiPropertiesWriterFactory niFiPropertiesWriterFactory, List<String> hostnames, List<String> keyStorePasswords,
List<String> keyPasswords, List<String> trustStorePasswords, String httpsPort) throws GeneralSecurityException, IOException {
List<String> keyPasswords, List<String> trustStorePasswords, int httpsPort) throws GeneralSecurityException, IOException {
String signingAlgorithm = tlsConfig.getSigningAlgorithm();
int days = tlsConfig.getDays();
String keyPairAlgorithm = tlsConfig.getKeyPairAlgorithm();
@ -127,10 +127,13 @@ public class TlsToolkitStandalone {
tlsClientManager.addClientConfigurationWriter(new NifiPropertiesTlsClientConfigWriter(niFiPropertiesWriterFactory, outputStreamFactory, new File(hostDir, "nifi.properties"),
hostname, httpsPort));
tlsClientManager.write(outputStreamFactory);
if (logger.isInfoEnabled()) {
logger.info("Successfully generated TLS configuration for " + hostname + ":" + httpsPort + " in " + hostDir);
}
}
if (logger.isInfoEnabled()) {
logger.info("Successfully generated TLS configuration");
logger.info("Successfully generated TLS configuration for all hosts");
}
}
}

View File

@ -26,10 +26,13 @@ import org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriterFactory;
import org.apache.nifi.toolkit.tls.util.PasswordUtil;
import org.apache.nifi.toolkit.tls.util.TlsHelper;
import org.apache.nifi.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -46,14 +49,17 @@ public class TlsToolkitStandaloneCommandLine extends BaseCommandLine {
public static final String HOSTNAMES_ARG = "hostnames";
public static final String HTTPS_PORT_ARG = "httpsPort";
public static final String DEFAULT_OUTPUT_DIRECTORY = new File(".").getPath();
public static final String DEFAULT_OUTPUT_DIRECTORY = "../" + Paths.get(".").toAbsolutePath().normalize().getFileName().toString();
public static final int DEFAULT_HTTPS_PORT = 10443;
public static final String DESCRIPTION = "Creates certificates and config files for nifi cluster.";
private final Logger logger = LoggerFactory.getLogger(TlsToolkitStandaloneCommandLine.class);
private final PasswordUtil passwordUtil;
private File baseDir;
private List<String> hostnames;
private String httpsPort;
private int httpsPort;
private NiFiPropertiesWriterFactory niFiPropertiesWriterFactory;
private List<String> keyStorePasswords;
private List<String> keyPasswords;
@ -68,8 +74,8 @@ public class TlsToolkitStandaloneCommandLine extends BaseCommandLine {
this.passwordUtil = passwordUtil;
addOptionWithArg("o", OUTPUT_DIRECTORY_ARG, "The directory to output keystores, truststore, config files.", DEFAULT_OUTPUT_DIRECTORY);
addOptionWithArg("n", HOSTNAMES_ARG, "Comma separated list of hostnames.", TlsConfig.DEFAULT_HOSTNAME);
addOptionWithArg("p", HTTPS_PORT_ARG, "Https port to use.", "");
addOptionWithArg("f", NIFI_PROPERTIES_FILE_ARG, "Base nifi.properties file to update.", "");
addOptionWithArg("p", HTTPS_PORT_ARG, "Https port to use.", DEFAULT_HTTPS_PORT);
addOptionWithArg("f", NIFI_PROPERTIES_FILE_ARG, "Base nifi.properties file to update. (Embedded file identical to the one in a default NiFi install will be used if not specified.)");
addOptionWithArg("S", KEY_STORE_PASSWORD_ARG, "Keystore password to use. Must either be one value or one for each host. (autogenerate if not specified)");
addOptionWithArg("K", KEY_PASSWORD_ARG, "Key password to use. Must either be one value or one for each host. (autogenerate if not specified)");
addOptionWithArg("P", TRUST_STORE_PASSWORD_ARG, "Keystore password to use. Must either be one value or one for each host. (autogenerate if not specified)");
@ -100,7 +106,7 @@ public class TlsToolkitStandaloneCommandLine extends BaseCommandLine {
String outputDirectory = commandLine.getOptionValue(OUTPUT_DIRECTORY_ARG, DEFAULT_OUTPUT_DIRECTORY);
baseDir = new File(outputDirectory);
hostnames = Arrays.stream(commandLine.getOptionValue(HOSTNAMES_ARG, TlsConfig.DEFAULT_HOSTNAME).split(",")).map(String::trim).collect(Collectors.toList());
httpsPort = commandLine.getOptionValue(HTTPS_PORT_ARG, "");
httpsPort = getIntValue(commandLine, HTTPS_PORT_ARG, DEFAULT_HTTPS_PORT);
int numHosts = hostnames.size();
keyStorePasswords = Collections.unmodifiableList(getPasswords(KEY_STORE_PASSWORD_ARG, commandLine, numHosts));
@ -110,8 +116,10 @@ public class TlsToolkitStandaloneCommandLine extends BaseCommandLine {
String nifiPropertiesFile = commandLine.getOptionValue(NIFI_PROPERTIES_FILE_ARG, "");
try {
if (StringUtils.isEmpty(nifiPropertiesFile)) {
logger.info("No " + NIFI_PROPERTIES_FILE_ARG + " specified, using embedded one.");
niFiPropertiesWriterFactory = new NiFiPropertiesWriterFactory();
} else {
logger.info("Using " + nifiPropertiesFile + " as template.");
niFiPropertiesWriterFactory = new NiFiPropertiesWriterFactory(new FileInputStream(nifiPropertiesFile));
}
} catch (IOException e) {
@ -148,7 +156,7 @@ public class TlsToolkitStandaloneCommandLine extends BaseCommandLine {
return hostnames;
}
public String getHttpsPort() {
public int getHttpsPort() {
return httpsPort;
}

View File

@ -149,8 +149,8 @@ public class TlsToolkitStandaloneCommandLineTest {
@Test
public void testHttpsPort() throws CommandLineParseException {
String testPort = "8998";
tlsToolkitStandaloneCommandLine.parse("-p", testPort);
int testPort = 8998;
tlsToolkitStandaloneCommandLine.parse("-p", Integer.toString(testPort));
assertEquals(testPort, tlsToolkitStandaloneCommandLine.getHttpsPort());
}