Search in sources :

Example 1 with ESEtlService

use of com.alibaba.otter.canal.client.adapter.es7x.etl.ESEtlService in project canal by alibaba.

the class ES7xAdapter method etl.

@Override
public EtlResult etl(String task, List<String> params) {
    EtlResult etlResult = new EtlResult();
    ESSyncConfig config = esSyncConfig.get(task);
    if (config != null) {
        DataSource dataSource = DatasourceConfig.DATA_SOURCES.get(config.getDataSourceKey());
        ESEtlService esEtlService = new ESEtlService(esConnection, config);
        if (dataSource != null) {
            return esEtlService.importData(params);
        } else {
            etlResult.setSucceeded(false);
            etlResult.setErrorMessage("DataSource not found");
            return etlResult;
        }
    } else {
        StringBuilder resultMsg = new StringBuilder();
        boolean resSuccess = true;
        for (ESSyncConfig configTmp : esSyncConfig.values()) {
            // 取所有的destination为task的配置
            if (configTmp.getDestination().equals(task)) {
                ESEtlService esEtlService = new ESEtlService(esConnection, configTmp);
                EtlResult etlRes = esEtlService.importData(params);
                if (!etlRes.getSucceeded()) {
                    resSuccess = false;
                    resultMsg.append(etlRes.getErrorMessage()).append("\n");
                } else {
                    resultMsg.append(etlRes.getResultMessage()).append("\n");
                }
            }
        }
        if (resultMsg.length() > 0) {
            etlResult.setSucceeded(resSuccess);
            if (resSuccess) {
                etlResult.setResultMessage(resultMsg.toString());
            } else {
                etlResult.setErrorMessage(resultMsg.toString());
            }
            return etlResult;
        }
    }
    etlResult.setSucceeded(false);
    etlResult.setErrorMessage("Task not found");
    return etlResult;
}
Also used : ESSyncConfig(com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig) ESEtlService(com.alibaba.otter.canal.client.adapter.es7x.etl.ESEtlService) EtlResult(com.alibaba.otter.canal.client.adapter.support.EtlResult) DataSource(javax.sql.DataSource)

Aggregations

ESSyncConfig (com.alibaba.otter.canal.client.adapter.es.core.config.ESSyncConfig)1 ESEtlService (com.alibaba.otter.canal.client.adapter.es7x.etl.ESEtlService)1 EtlResult (com.alibaba.otter.canal.client.adapter.support.EtlResult)1 DataSource (javax.sql.DataSource)1