Search in sources :

Example 1 with RecordMetadata

use of com.datastax.oss.dsbulk.connectors.api.RecordMetadata in project dsbulk by datastax.

the class PrometheusEndToEndSimulacronIT method newConnectorDelegate.

@NonNull
private Connector newConnectorDelegate() {
    return new Connector() {

        @Override
        public int readConcurrency() {
            return 1;
        }

        @Override
        public boolean supports(@NonNull ConnectorFeature feature) {
            return feature == CommonConnectorFeature.INDEXED_RECORDS;
        }

        @NonNull
        @Override
        public Publisher<Publisher<Record>> read() {
            AtomicInteger counter = new AtomicInteger();
            AtomicBoolean running = new AtomicBoolean(true);
            return Flux.just(Flux.generate(sink -> {
                int i = counter.getAndAdd(1);
                if (i == 0) {
                    startTimer(running);
                }
                if (running.get()) {
                    Record record = RecordUtils.indexedCSV("pk", "pk" + 1, "cc", "cc" + 1, "v", "v" + 1);
                    sink.next(record);
                } else {
                    sink.complete();
                }
            }));
        }

        @NonNull
        @Override
        public RecordMetadata getRecordMetadata() {
            return (fieldType, cqlType) -> GenericType.STRING;
        }

        @NonNull
        @Override
        public Function<Publisher<Record>, Publisher<Record>> write() {
            throw new UnsupportedOperationException();
        }

        @Override
        public int writeConcurrency() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : SimulacronUtils(com.datastax.oss.dsbulk.tests.simulacron.SimulacronUtils) BoundCluster(com.datastax.oss.simulacron.server.BoundCluster) Connector(com.datastax.oss.dsbulk.connectors.api.Connector) DockerImageName(org.testcontainers.utility.DockerImageName) URL(java.net.URL) MockConnector(com.datastax.oss.dsbulk.runner.tests.MockConnector) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GenericType(com.datastax.oss.driver.api.core.type.reflect.GenericType) Timer(java.util.Timer) Function(java.util.function.Function) Network(org.testcontainers.containers.Network) RecordUtils(com.datastax.oss.dsbulk.runner.tests.RecordUtils) RecordMetadata(com.datastax.oss.dsbulk.connectors.api.RecordMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) Keyspace(com.datastax.oss.dsbulk.tests.simulacron.SimulacronUtils.Keyspace) NonNull(edu.umd.cs.findbugs.annotations.NonNull) EndToEndUtils.assertStatus(com.datastax.oss.dsbulk.runner.tests.EndToEndUtils.assertStatus) Resources(com.datastax.oss.driver.shaded.guava.common.io.Resources) GenericContainer(org.testcontainers.containers.GenericContainer) Tag(org.junit.jupiter.api.Tag) TimerTask(java.util.TimerTask) Record(com.datastax.oss.dsbulk.connectors.api.Record) LogInterceptor(com.datastax.oss.dsbulk.tests.logging.LogInterceptor) Container(org.testcontainers.junit.jupiter.Container) Session(com.datastax.oss.driver.api.core.session.Session) CommonConnectorFeature(com.datastax.oss.dsbulk.connectors.api.CommonConnectorFeature) WorkflowUtils(com.datastax.oss.dsbulk.workflow.api.utils.WorkflowUtils) Table(com.datastax.oss.dsbulk.tests.simulacron.SimulacronUtils.Table) TestAssertions.assertThat(com.datastax.oss.dsbulk.tests.assertions.TestAssertions.assertThat) Publisher(org.reactivestreams.Publisher) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) IOException(java.io.IOException) ConnectorFeature(com.datastax.oss.dsbulk.connectors.api.ConnectorFeature) DataStaxBulkLoader(com.datastax.oss.dsbulk.runner.DataStaxBulkLoader) LogCapture(com.datastax.oss.dsbulk.tests.logging.LogCapture) StandardCharsets(java.nio.charset.StandardCharsets) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) STATUS_OK(com.datastax.oss.dsbulk.runner.ExitStatus.STATUS_OK) Flux(reactor.core.publisher.Flux) ExitStatus(com.datastax.oss.dsbulk.runner.ExitStatus) MountableFile(org.testcontainers.utility.MountableFile) Column(com.datastax.oss.dsbulk.tests.simulacron.SimulacronUtils.Column) TEXT(com.datastax.oss.driver.api.core.type.DataTypes.TEXT) Connector(com.datastax.oss.dsbulk.connectors.api.Connector) MockConnector(com.datastax.oss.dsbulk.runner.tests.MockConnector) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Record(com.datastax.oss.dsbulk.connectors.api.Record) Publisher(org.reactivestreams.Publisher) CommonConnectorFeature(com.datastax.oss.dsbulk.connectors.api.CommonConnectorFeature) ConnectorFeature(com.datastax.oss.dsbulk.connectors.api.ConnectorFeature) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 2 with RecordMetadata

use of com.datastax.oss.dsbulk.connectors.api.RecordMetadata in project dsbulk by datastax.

the class UnloadWorkflow method init.

@Override
public void init() throws Exception {
    settingsManager.init("UNLOAD", false, SchemaGenerationStrategy.READ_AND_MAP);
    executionId = settingsManager.getExecutionId();
    LogSettings logSettings = settingsManager.getLogSettings();
    DriverSettings driverSettings = settingsManager.getDriverSettings();
    ConnectorSettings connectorSettings = settingsManager.getConnectorSettings();
    SchemaSettings schemaSettings = settingsManager.getSchemaSettings();
    ExecutorSettings executorSettings = settingsManager.getExecutorSettings();
    CodecSettings codecSettings = settingsManager.getCodecSettings();
    MonitoringSettings monitoringSettings = settingsManager.getMonitoringSettings();
    EngineSettings engineSettings = settingsManager.getEngineSettings();
    engineSettings.init();
    // First verify that dry-run is off; that's unsupported for unload.
    if (engineSettings.isDryRun()) {
        throw new IllegalArgumentException("Dry-run is not supported for unload");
    }
    // No logs should be produced until the following statement returns
    logSettings.init();
    connectorSettings.init(false);
    connector = connectorSettings.getConnector();
    connector.init();
    driverSettings.init(false);
    logSettings.logEffectiveSettings(settingsManager.getEffectiveBulkLoaderConfig(), driverSettings.getDriverConfig());
    codecSettings.init();
    monitoringSettings.init();
    executorSettings.init();
    ConvertingCodecFactory codecFactory = codecSettings.createCodecFactory(schemaSettings.isAllowExtraFields(), schemaSettings.isAllowMissingFields());
    session = driverSettings.newSession(executionId, codecFactory.getCodecRegistry(), monitoringSettings.getRegistry());
    ClusterInformationUtils.printDebugInfoAboutCluster(session);
    schemaSettings.init(session, codecFactory, connector.supports(CommonConnectorFeature.INDEXED_RECORDS), connector.supports(CommonConnectorFeature.MAPPED_RECORDS));
    logManager = logSettings.newLogManager(session, false);
    logManager.init();
    metricsManager = monitoringSettings.newMetricsManager(false, false, logManager.getOperationDirectory(), logSettings.getVerbosity(), session.getContext().getProtocolVersion(), session.getContext().getCodecRegistry(), schemaSettings.getRowType());
    metricsManager.init();
    RecordMetadata recordMetadata = connector.getRecordMetadata();
    readResultMapper = schemaSettings.createReadResultMapper(session, recordMetadata, codecFactory, logSettings.isSources());
    readStatements = schemaSettings.createReadStatements(session);
    executor = executorSettings.newReadExecutor(session, metricsManager.getExecutionListener(), schemaSettings.isSearchQuery());
    closed.set(false);
    writer = connector.write();
    totalItemsMonitor = metricsManager.newTotalItemsMonitor();
    failedRecordsMonitor = metricsManager.newFailedItemsMonitor();
    failedReadResultsMonitor = metricsManager.newFailedItemsMonitor();
    failedRecordsHandler = logManager.newFailedRecordsHandler();
    totalItemsCounter = logManager.newTotalItemsCounter();
    failedReadsHandler = logManager.newFailedReadsHandler();
    queryWarningsHandler = logManager.newQueryWarningsHandler();
    unmappableRecordsHandler = logManager.newUnmappableRecordsHandler();
    terminationHandler = logManager.newTerminationHandler();
    numCores = Runtime.getRuntime().availableProcessors();
    if (connector.writeConcurrency() < 1) {
        throw new IllegalArgumentException("Invalid write concurrency: " + connector.writeConcurrency());
    }
    writeConcurrency = connector.writeConcurrency();
    LOGGER.debug("Using write concurrency: {}", writeConcurrency);
    readConcurrency = Math.min(readStatements.size(), // a good readConcurrency is then numCores.
    engineSettings.getMaxConcurrentQueries().orElse(numCores));
    LOGGER.debug("Using read concurrency: {} (user-supplied: {})", readConcurrency, engineSettings.getMaxConcurrentQueries().isPresent());
    schedulers = new HashSet<>();
}
Also used : ExecutorSettings(com.datastax.oss.dsbulk.workflow.commons.settings.ExecutorSettings) ConvertingCodecFactory(com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory) RecordMetadata(com.datastax.oss.dsbulk.connectors.api.RecordMetadata) DriverSettings(com.datastax.oss.dsbulk.workflow.commons.settings.DriverSettings) EngineSettings(com.datastax.oss.dsbulk.workflow.commons.settings.EngineSettings) LogSettings(com.datastax.oss.dsbulk.workflow.commons.settings.LogSettings) MonitoringSettings(com.datastax.oss.dsbulk.workflow.commons.settings.MonitoringSettings) ConnectorSettings(com.datastax.oss.dsbulk.workflow.commons.settings.ConnectorSettings) SchemaSettings(com.datastax.oss.dsbulk.workflow.commons.settings.SchemaSettings) CodecSettings(com.datastax.oss.dsbulk.workflow.commons.settings.CodecSettings)

Example 3 with RecordMetadata

use of com.datastax.oss.dsbulk.connectors.api.RecordMetadata in project dsbulk by datastax.

the class MockConnector method mockWrites.

/**
 * Sets up the mock connector to emulate writes; it will store all received records as if they
 * were written to an external sink. The "written" records will appear in the returned list.
 *
 * @return the list where "written" records will be stored.
 */
public static List<Record> mockWrites() {
    List<Record> records = new ArrayList<>();
    setDelegate(new Connector() {

        @Override
        public void init() {
        }

        @Override
        public void configure(@NonNull Config settings, boolean read, boolean retainRecordSources) {
        }

        @Override
        public int readConcurrency() {
            return -1;
        }

        @Override
        public int writeConcurrency() {
            return 1;
        }

        @Override
        public boolean supports(@NonNull ConnectorFeature feature) {
            return true;
        }

        @NonNull
        @Override
        public RecordMetadata getRecordMetadata() {
            return (field, cql) -> GenericType.STRING;
        }

        @NonNull
        @Override
        public Publisher<Publisher<Record>> read() {
            return Flux::just;
        }

        @NonNull
        @Override
        public Function<Publisher<Record>, Publisher<Record>> write() {
            return upstream -> Flux.from(upstream).doOnNext(records::add);
        }
    });
    return records;
}
Also used : Connector(com.datastax.oss.dsbulk.connectors.api.Connector) Config(com.typesafe.config.Config) ArrayList(java.util.ArrayList) Flux(reactor.core.publisher.Flux) Publisher(org.reactivestreams.Publisher) ConnectorFeature(com.datastax.oss.dsbulk.connectors.api.ConnectorFeature) RecordMetadata(com.datastax.oss.dsbulk.connectors.api.RecordMetadata) Function(java.util.function.Function) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Record(com.datastax.oss.dsbulk.connectors.api.Record)

Example 4 with RecordMetadata

use of com.datastax.oss.dsbulk.connectors.api.RecordMetadata in project dsbulk by datastax.

the class MockConnector method mockCountingWrites.

/**
 * Sets up the mock connector to emulate writes; it will acknowledge records as if they were
 * written to an external sink. The "written" records will be counted and the total number of
 * records "written" will be reflected in the returned AtomicInteger.
 *
 * @return a counter for the number of records "written".
 */
public static AtomicInteger mockCountingWrites() {
    AtomicInteger records = new AtomicInteger();
    setDelegate(new Connector() {

        @Override
        public void init() {
        }

        @Override
        public void configure(@NonNull Config settings, boolean read, boolean retainRecordSources) {
        }

        @Override
        public int readConcurrency() {
            return -1;
        }

        @Override
        public int writeConcurrency() {
            return 1;
        }

        @Override
        public boolean supports(@NonNull ConnectorFeature feature) {
            return true;
        }

        @NonNull
        @Override
        public RecordMetadata getRecordMetadata() {
            return (field, cql) -> GenericType.STRING;
        }

        @NonNull
        @Override
        public Publisher<Publisher<Record>> read() {
            return Flux::just;
        }

        @NonNull
        @Override
        public Function<Publisher<Record>, Publisher<Record>> write() {
            return upstream -> Flux.from(upstream).doOnNext(r -> records.incrementAndGet());
        }
    });
    return records;
}
Also used : Connector(com.datastax.oss.dsbulk.connectors.api.Connector) Functions(com.datastax.oss.driver.shaded.guava.common.base.Functions) Config(com.typesafe.config.Config) Publisher(org.reactivestreams.Publisher) GenericType(com.datastax.oss.driver.api.core.type.reflect.GenericType) ConnectorFeature(com.datastax.oss.dsbulk.connectors.api.ConnectorFeature) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Flux(reactor.core.publisher.Flux) RecordMetadata(com.datastax.oss.dsbulk.connectors.api.RecordMetadata) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Record(com.datastax.oss.dsbulk.connectors.api.Record) Connector(com.datastax.oss.dsbulk.connectors.api.Connector) Config(com.typesafe.config.Config) Flux(reactor.core.publisher.Flux) Publisher(org.reactivestreams.Publisher) ConnectorFeature(com.datastax.oss.dsbulk.connectors.api.ConnectorFeature) RecordMetadata(com.datastax.oss.dsbulk.connectors.api.RecordMetadata) Function(java.util.function.Function) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Record(com.datastax.oss.dsbulk.connectors.api.Record)

Aggregations

RecordMetadata (com.datastax.oss.dsbulk.connectors.api.RecordMetadata)4 Connector (com.datastax.oss.dsbulk.connectors.api.Connector)3 ConnectorFeature (com.datastax.oss.dsbulk.connectors.api.ConnectorFeature)3 Record (com.datastax.oss.dsbulk.connectors.api.Record)3 NonNull (edu.umd.cs.findbugs.annotations.NonNull)3 GenericType (com.datastax.oss.driver.api.core.type.reflect.GenericType)2 Config (com.typesafe.config.Config)2 ArrayList (java.util.ArrayList)2 Function (java.util.function.Function)2 Publisher (org.reactivestreams.Publisher)2 Flux (reactor.core.publisher.Flux)2 Session (com.datastax.oss.driver.api.core.session.Session)1 TEXT (com.datastax.oss.driver.api.core.type.DataTypes.TEXT)1 Functions (com.datastax.oss.driver.shaded.guava.common.base.Functions)1 Resources (com.datastax.oss.driver.shaded.guava.common.io.Resources)1 ConvertingCodecFactory (com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory)1 CommonConnectorFeature (com.datastax.oss.dsbulk.connectors.api.CommonConnectorFeature)1 DataStaxBulkLoader (com.datastax.oss.dsbulk.runner.DataStaxBulkLoader)1 ExitStatus (com.datastax.oss.dsbulk.runner.ExitStatus)1 STATUS_OK (com.datastax.oss.dsbulk.runner.ExitStatus.STATUS_OK)1