Search in sources :

Example 1 with DirectConnector

use of io.cdap.cdap.etl.api.connector.DirectConnector in project cdap by caskdata.

the class ConnectionUtils method getSampleResponse.

/**
 * Return {@link SampleResponse} for the connector
 *
 * @throws IOException
 */
public static SampleResponse getSampleResponse(Connector connector, ConnectorContext connectorContext, SampleRequest sampleRequest, ConnectorDetail detail, ServicePluginConfigurer pluginConfigurer) throws IOException {
    if (connector instanceof DirectConnector) {
        DirectConnector directConnector = (DirectConnector) connector;
        List<StructuredRecord> sample = directConnector.sample(connectorContext, sampleRequest);
        return new SampleResponse(detail, sample.isEmpty() ? null : sample.get(0).getSchema(), sample);
    }
    if (connector instanceof BatchConnector) {
        LimitingConnector limitingConnector = new LimitingConnector((BatchConnector) connector, pluginConfigurer);
        List<StructuredRecord> sample = limitingConnector.sample(connectorContext, sampleRequest);
        return new SampleResponse(detail, sample.isEmpty() ? null : sample.get(0).getSchema(), sample);
    }
    throw new ConnectionBadRequestException("Connector is not supported. " + "The supported connector should be DirectConnector or BatchConnector.");
}
Also used : ConnectionBadRequestException(io.cdap.cdap.etl.proto.connection.ConnectionBadRequestException) BatchConnector(io.cdap.cdap.etl.api.batch.BatchConnector) DirectConnector(io.cdap.cdap.etl.api.connector.DirectConnector) SampleResponse(io.cdap.cdap.etl.proto.connection.SampleResponse) LimitingConnector(io.cdap.cdap.datapipeline.connection.LimitingConnector) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord)

Example 2 with DirectConnector

use of io.cdap.cdap.etl.api.connector.DirectConnector in project cdap by cdapio.

the class ConnectionUtils method getSampleResponse.

/**
 * Return {@link SampleResponse} for the connector
 *
 * @throws IOException
 */
public static SampleResponse getSampleResponse(Connector connector, ConnectorContext connectorContext, SampleRequest sampleRequest, ConnectorDetail detail, ServicePluginConfigurer pluginConfigurer) throws IOException {
    if (connector instanceof DirectConnector) {
        DirectConnector directConnector = (DirectConnector) connector;
        List<StructuredRecord> sample = directConnector.sample(connectorContext, sampleRequest);
        return new SampleResponse(detail, sample.isEmpty() ? null : sample.get(0).getSchema(), sample);
    }
    if (connector instanceof BatchConnector) {
        LimitingConnector limitingConnector = new LimitingConnector((BatchConnector) connector, pluginConfigurer);
        List<StructuredRecord> sample = limitingConnector.sample(connectorContext, sampleRequest);
        return new SampleResponse(detail, sample.isEmpty() ? null : sample.get(0).getSchema(), sample);
    }
    throw new ConnectionBadRequestException("Connector is not supported. " + "The supported connector should be DirectConnector or BatchConnector.");
}
Also used : ConnectionBadRequestException(io.cdap.cdap.etl.proto.connection.ConnectionBadRequestException) BatchConnector(io.cdap.cdap.etl.api.batch.BatchConnector) DirectConnector(io.cdap.cdap.etl.api.connector.DirectConnector) SampleResponse(io.cdap.cdap.etl.proto.connection.SampleResponse) LimitingConnector(io.cdap.cdap.datapipeline.connection.LimitingConnector) StructuredRecord(io.cdap.cdap.api.data.format.StructuredRecord)

Aggregations

StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)2 LimitingConnector (io.cdap.cdap.datapipeline.connection.LimitingConnector)2 BatchConnector (io.cdap.cdap.etl.api.batch.BatchConnector)2 DirectConnector (io.cdap.cdap.etl.api.connector.DirectConnector)2 ConnectionBadRequestException (io.cdap.cdap.etl.proto.connection.ConnectionBadRequestException)2 SampleResponse (io.cdap.cdap.etl.proto.connection.SampleResponse)2