use of org.voltdb.export.ExportDataProcessor in project voltdb by VoltDB.
the class CatalogUtil method checkExportProcessorConfiguration.
private static Properties checkExportProcessorConfiguration(ExportConfigurationType exportConfiguration) {
// on-server export always uses the guest processor
String exportClientClassName = null;
switch(exportConfiguration.getType()) {
case FILE:
exportClientClassName = "org.voltdb.exportclient.ExportToFileClient";
break;
case JDBC:
exportClientClassName = "org.voltdb.exportclient.JDBCExportClient";
break;
case KAFKA:
exportClientClassName = "org.voltdb.exportclient.kafka.KafkaExportClient";
break;
case RABBITMQ:
exportClientClassName = "org.voltdb.exportclient.RabbitMQExportClient";
break;
case HTTP:
exportClientClassName = "org.voltdb.exportclient.HttpExportClient";
break;
case ELASTICSEARCH:
exportClientClassName = "org.voltdb.exportclient.ElasticSearchHttpExportClient";
break;
//Validate that we can load the class.
case CUSTOM:
exportClientClassName = exportConfiguration.getExportconnectorclass();
if (exportConfiguration.isEnabled()) {
try {
CatalogUtil.class.getClassLoader().loadClass(exportClientClassName);
} catch (ClassNotFoundException ex) {
String msg = "Custom Export failed to configure, failed to load" + " export plugin class: " + exportConfiguration.getExportconnectorclass() + " Disabling export.";
hostLog.error(msg);
throw new DeploymentCheckException(msg);
}
}
break;
}
Properties processorProperties = new Properties();
if (exportClientClassName != null && exportClientClassName.trim().length() > 0) {
String dexportClientClassName = System.getProperty(ExportDataProcessor.EXPORT_TO_TYPE, exportClientClassName);
//Override for tests
if (dexportClientClassName != null && dexportClientClassName.trim().length() > 0 && exportConfiguration.getType().equals(ServerExportEnum.CUSTOM)) {
processorProperties.setProperty(ExportDataProcessor.EXPORT_TO_TYPE, dexportClientClassName);
} else {
processorProperties.setProperty(ExportDataProcessor.EXPORT_TO_TYPE, exportClientClassName);
}
}
if (exportConfiguration != null) {
List<PropertyType> configProperties = exportConfiguration.getProperty();
if (configProperties != null && !configProperties.isEmpty()) {
for (PropertyType configProp : configProperties) {
String key = configProp.getName();
String value = configProp.getValue();
if (key.toLowerCase().contains("passw")) {
// Don't trim password
processorProperties.setProperty(key, value);
} else if (key.toLowerCase().contains("delim")) {
// Don't trim \n in delimiters
String trimmedDelimiters = value.replaceAll("^(\r|\f|\t| )+", "").replaceAll("(\r|\f|\t| )+$", "");
processorProperties.setProperty(key, StringEscapeUtils.escapeJava(trimmedDelimiters));
} else {
processorProperties.setProperty(key, value.trim());
}
}
}
}
if (!exportConfiguration.isEnabled()) {
return processorProperties;
}
// Instantiate the Guest Processor
Class<?> processorClazz = null;
try {
processorClazz = Class.forName(ExportManager.PROCESSOR_CLASS);
} catch (ClassNotFoundException e) {
throw new DeploymentCheckException("Export is a PRO version only feature");
}
ExportDataProcessor processor = null;
try {
processor = (ExportDataProcessor) processorClazz.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
hostLog.error("Unable to instantiate export processor", e);
throw new DeploymentCheckException("Unable to instantiate export processor", e);
}
try {
processor.addLogger(hostLog);
processorProperties.put(ExportManager.CONFIG_CHECK_ONLY, "true");
processor.checkProcessorConfig(processorProperties);
processor.shutdown();
} catch (Exception e) {
hostLog.error("Export processor failed its configuration check", e);
throw new DeploymentCheckException("Export processor failed its configuration check: " + e.getMessage(), e);
}
processorProperties.remove(ExportManager.CONFIG_CHECK_ONLY);
return processorProperties;
}
Aggregations