// Path: src/main/java/crate/elasticsearch/action/import_/ImportContext.java
// public class ImportContext {
// 
//     private String nodePath;
//     private boolean compression;
//     private String directory;
//     private Pattern file_pattern;
//     private boolean mappings = false;
//     private boolean settings = false;
// 
//     public ImportContext(String nodePath) {
//         this.nodePath = nodePath;
//     }
// 
//     public boolean compression() {
//         return compression;
//     }
// 
//     public void compression(boolean compression) {
//         this.compression = compression;
//     }
// 
//     public String directory() {
//         return directory;
//     }
// 
//     public void directory(String directory) {
//         File file = new File(directory);
//         if (!file.isAbsolute() && nodePath != null) {
//             file = new File(nodePath, directory);
//             directory = file.getAbsolutePath();
//         }
//         this.directory = directory;
//     }
// 
//     public Pattern file_pattern() {
//         return file_pattern;
//     }
// 
//     public void file_pattern(Pattern file_pattern) {
//         this.file_pattern = file_pattern;
//     }
// 
//     public boolean mappings() {
//         return mappings;
//     }
// 
//     public void mappings(boolean mappings) {
//         this.mappings = mappings;
//     }
// 
//     public boolean settings() {
//         return settings;
//     }
// 
//     public void settings(boolean settings) {
//         this.settings = settings;
//     }
// }
// 
// Path: src/main/java/crate/elasticsearch/action/import_/NodeImportRequest.java
// public class NodeImportRequest  extends NodeOperationRequest {
// 
//     public static final int DEFAULT_BULK_SIZE = 10000;
// 
//     private BytesReference source;
//     private String index;
//     private String type;
// 
//     NodeImportRequest() {
//     }
// 
//     public NodeImportRequest(String nodeId, ImportRequest request) {
//         super(request, nodeId);
//         this.source = request.source();
//         this.index = request.index();
//         this.type = request.type();
//     }
// 
//     @Override
//     public void readFrom(StreamInput in) throws IOException {
//         super.readFrom(in);
//         source = in.readBytesReference();
//         index = in.readOptionalString();
//         type = in.readOptionalString();
//     }
// 
//     @Override
//     public void writeTo(StreamOutput out) throws IOException {
//         super.writeTo(out);
//         out.writeBytesReference(source);
//         out.writeOptionalString(index);
//         out.writeOptionalString(type);
//     }
// 
//     public BytesReference source() {
//         return source;
//     }
// 
//     public String index() {
//         return index;
//     }
// 
//     public String type() {
//         return type;
//     }
// 
//     public int bulkSize() {
//         return DEFAULT_BULK_SIZE;
//     }
// }


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ElasticSearchParseException;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.bulk.BulkProcessor;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexRequest.OpType;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.ImmutableSettings.Builder;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.mapper.internal.IdFieldMapper;
import org.elasticsearch.index.mapper.internal.IndexFieldMapper;
import org.elasticsearch.index.mapper.internal.RoutingFieldMapper;
import org.elasticsearch.index.mapper.internal.SourceFieldMapper;
import org.elasticsearch.index.mapper.internal.TTLFieldMapper;
import org.elasticsearch.index.mapper.internal.TimestampFieldMapper;
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
import org.elasticsearch.indices.IndexAlreadyExistsException;
import org.elasticsearch.indices.IndexMissingException;
import crate.elasticsearch.action.import_.ImportContext;
import crate.elasticsearch.action.import_.NodeImportRequest;
package crate.elasticsearch.import_;




public class Importer {

    private Client client;
    private final Injector injector;

    private final ByteSizeValue bulkByteSize = new ByteSizeValue(5, ByteSizeUnit.MB);
    private final TimeValue flushInterval = TimeValue.timeValueSeconds(5);
    private final int concurrentRequests = 4;

    @Inject
    public Importer(Injector injector) {
        this.injector = injector;
    }

// Path: src/main/java/crate/elasticsearch/action/import_/ImportContext.java
// public class ImportContext {
// 
//     private String nodePath;
//     private boolean compression;
//     private String directory;
//     private Pattern file_pattern;
//     private boolean mappings = false;
//     private boolean settings = false;
// 
//     public ImportContext(String nodePath) {
//         this.nodePath = nodePath;
//     }
// 
//     public boolean compression() {
//         return compression;
//     }
// 
//     public void compression(boolean compression) {
//         this.compression = compression;
//     }
// 
//     public String directory() {
//         return directory;
//     }
// 
//     public void directory(String directory) {
//         File file = new File(directory);
//         if (!file.isAbsolute() && nodePath != null) {
//             file = new File(nodePath, directory);
//             directory = file.getAbsolutePath();
//         }
//         this.directory = directory;
//     }
// 
//     public Pattern file_pattern() {
//         return file_pattern;
//     }
// 
//     public void file_pattern(Pattern file_pattern) {
//         this.file_pattern = file_pattern;
//     }
// 
//     public boolean mappings() {
//         return mappings;
//     }
// 
//     public void mappings(boolean mappings) {
//         this.mappings = mappings;
//     }
// 
//     public boolean settings() {
//         return settings;
//     }
// 
//     public void settings(boolean settings) {
//         this.settings = settings;
//     }
// }
// 
// Path: src/main/java/crate/elasticsearch/action/import_/NodeImportRequest.java
// public class NodeImportRequest  extends NodeOperationRequest {
// 
//     public static final int DEFAULT_BULK_SIZE = 10000;
// 
//     private BytesReference source;
//     private String index;
//     private String type;
// 
//     NodeImportRequest() {
//     }
// 
//     public NodeImportRequest(String nodeId, ImportRequest request) {
//         super(request, nodeId);
//         this.source = request.source();
//         this.index = request.index();
//         this.type = request.type();
//     }
// 
//     @Override
//     public void readFrom(StreamInput in) throws IOException {
//         super.readFrom(in);
//         source = in.readBytesReference();
//         index = in.readOptionalString();
//         type = in.readOptionalString();
//     }
// 
//     @Override
//     public void writeTo(StreamOutput out) throws IOException {
//         super.writeTo(out);
//         out.writeBytesReference(source);
//         out.writeOptionalString(index);
//         out.writeOptionalString(type);
//     }
// 
//     public BytesReference source() {
//         return source;
//     }
// 
//     public String index() {
//         return index;
//     }
// 
//     public String type() {
//         return type;
//     }
// 
//     public int bulkSize() {
//         return DEFAULT_BULK_SIZE;
//     }
// }


// Path: src/main/java/crate/elasticsearch/import_/Importer.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ElasticSearchParseException;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.bulk.BulkProcessor;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexRequest.OpType;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.ImmutableSettings.Builder;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.mapper.internal.IdFieldMapper;
import org.elasticsearch.index.mapper.internal.IndexFieldMapper;
import org.elasticsearch.index.mapper.internal.RoutingFieldMapper;
import org.elasticsearch.index.mapper.internal.SourceFieldMapper;
import org.elasticsearch.index.mapper.internal.TTLFieldMapper;
import org.elasticsearch.index.mapper.internal.TimestampFieldMapper;
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
import org.elasticsearch.indices.IndexAlreadyExistsException;
import org.elasticsearch.indices.IndexMissingException;
import crate.elasticsearch.action.import_.ImportContext;
import crate.elasticsearch.action.import_.NodeImportRequest;

package crate.elasticsearch.import_;




public class Importer {

    private Client client;
    private final Injector injector;

    private final ByteSizeValue bulkByteSize = new ByteSizeValue(5, ByteSizeUnit.MB);
    private final TimeValue flushInterval = TimeValue.timeValueSeconds(5);
    private final int concurrentRequests = 4;

    @Inject
    public Importer(Injector injector) {
        this.injector = injector;
    }

    public Result execute(ImportContext context, NodeImportRequest request) {