Search in sources :

Example 1 with ExportDataProcessor

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;
}
Also used : ExportDataProcessor(org.voltdb.export.ExportDataProcessor) PropertyType(org.voltdb.compiler.deploymentfile.PropertyType) Properties(java.util.Properties) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) JSONException(org.json_voltpatches.JSONException) SAXException(org.xml.sax.SAXException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) MalformedURLException(java.net.MalformedURLException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Properties (java.util.Properties)1 JAXBException (javax.xml.bind.JAXBException)1 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)1 JSONException (org.json_voltpatches.JSONException)1 PropertyType (org.voltdb.compiler.deploymentfile.PropertyType)1 ExportDataProcessor (org.voltdb.export.ExportDataProcessor)1 SAXException (org.xml.sax.SAXException)1