Search in sources :

Example 1 with ExecuteQueryControllerServiceRequestBuilder

use of com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder in project kylo by Teradata.

the class DBCPConnectionPoolService method generatePreviewQueryForDatasource.

/**
 * Generates a preview query on a table that is appropriate for the type of specified data source.
 *
 * @param datasource the JDBC datasource
 * @param schema the schema determining the SQL dialect, or null/empty for the default dialect
 * @param tableName the name of the table
 * @param limit the result size
 * @return the query string
 * @throws IllegalArgumentException if the datasource is invalid
 */
@Nonnull
public String generatePreviewQueryForDatasource(@Nonnull final JdbcDatasource datasource, @Nonnull final String schema, @Nonnull final String tableName, final int limit) {
    final Optional<ControllerServiceDTO> controllerService = Optional.ofNullable(datasource.getControllerServiceId()).map(id -> getControllerService(id, null));
    if (controllerService.isPresent()) {
        final DatabaseType dbType = DatabaseType.fromJdbcConnectionString(datasource.getDatabaseConnectionUrl());
        final ExecuteQueryControllerServiceRequest serviceProperties = new ExecuteQueryControllerServiceRequestBuilder(controllerService.get()).previewQuery(dbType, schema, tableName, limit).build();
        return serviceProperties.getQuery();
    } else {
        log.error("Cannot execute query for datasource: {}", datasource);
        throw new IllegalArgumentException("Missing controller service for datasource: " + datasource);
    }
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) DatabaseType(com.thinkbiganalytics.jdbc.util.DatabaseType) ExecuteQueryControllerServiceRequestBuilder(com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder) Nonnull(javax.annotation.Nonnull)

Example 2 with ExecuteQueryControllerServiceRequestBuilder

use of com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder in project kylo by Teradata.

the class DBCPConnectionPoolService method executeQueryForDatasource.

/**
 * Executes the specified SELECT query in the context of the specified data source.
 *
 * @param datasource the JDBC datasource
 * @param query      the query to execute
 * @return the query results
 * @throws DataAccessException      if the query cannot be executed
 * @throws IllegalArgumentException if the datasource is invalid
 */
@Nonnull
public QueryResult executeQueryForDatasource(@Nonnull final JdbcDatasource datasource, @Nonnull final String query) {
    final Optional<ControllerServiceDTO> controllerService = Optional.ofNullable(datasource.getControllerServiceId()).map(id -> getControllerService(id, null));
    if (controllerService.isPresent()) {
        final ExecuteQueryControllerServiceRequestBuilder builder = new ExecuteQueryControllerServiceRequestBuilder(controllerService.get());
        final ExecuteQueryControllerServiceRequest serviceProperties = builder.password(datasource.getPassword()).query(query).useEnvironmentProperties(false).build();
        final PoolingDataSourceService.DataSourceProperties dataSourceProperties = getDataSourceProperties(serviceProperties);
        return executeQueryForControllerService(dataSourceProperties, serviceProperties);
    } else {
        log.error("Cannot execute query for datasource: {}", datasource);
        throw new IllegalArgumentException("Missing controller service for datasource: " + datasource);
    }
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) PoolingDataSourceService(com.thinkbiganalytics.db.PoolingDataSourceService) ExecuteQueryControllerServiceRequestBuilder(com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder) Nonnull(javax.annotation.Nonnull)

Example 3 with ExecuteQueryControllerServiceRequestBuilder

use of com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder in project kylo by Teradata.

the class DBCPConnectionPoolService method executePreviewQueryForControllerService.

/**
 * Executes preview query on a table, in the context of the specified controller service, based
 * on the supplied schema (if provided) and limit.
 *
 * @param serviceId   a NiFi controller service id
 * @param serviceName a NiFi controller service name
 * @param tableName the name of the table
 * @param schema the schema determining the SQL dialect, or null/empty for the default dialect
 * @param limit the result size
 * @return the query results
 * @throws DataAccessException      if the query cannot be executed
 * @throws IllegalArgumentException if the controller service cannot be found, the schema/tableName is empty, or the limit is less than zero
 */
public QueryResult executePreviewQueryForControllerService(final String serviceId, final String serviceName, @Nonnull final String schema, @Nonnull final String tableName, final int limit) {
    Validate.notEmpty(schema, "No schema provided");
    Validate.notEmpty(tableName, "No table name provided");
    Validate.isTrue(limit >= 0, "The query result size must be greater than or equal to 0");
    final ControllerServiceDTO controllerService = getControllerService(serviceId, serviceName);
    if (controllerService != null) {
        final ExecuteQueryControllerServiceRequest serviceProperties = new ExecuteQueryControllerServiceRequestBuilder(controllerService).build();
        final PoolingDataSourceService.DataSourceProperties dataSourceProperties = getDataSourceProperties(serviceProperties);
        final DatabaseType dbType = DatabaseType.fromJdbcConnectionString(dataSourceProperties.getUrl());
        final ExecuteQueryControllerServiceRequest previewRequest = new ExecuteQueryControllerServiceRequestBuilder(controllerService).using(serviceProperties).previewQuery(dbType, schema, tableName, limit).build();
        return executeQueryForControllerService(dataSourceProperties, previewRequest);
    } else {
        log.error("Cannot execute query for controller service. Unable to obtain controller service: {}, {}", serviceId, serviceName);
        throw new IllegalArgumentException("Not a valid controller service: " + serviceId + ", " + serviceName);
    }
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) PoolingDataSourceService(com.thinkbiganalytics.db.PoolingDataSourceService) DatabaseType(com.thinkbiganalytics.jdbc.util.DatabaseType) ExecuteQueryControllerServiceRequestBuilder(com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder)

Example 4 with ExecuteQueryControllerServiceRequestBuilder

use of com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder in project kylo by Teradata.

the class DBCPConnectionPoolService method executeQueryForControllerService.

/**
 * Executes the specified SELECT query in the context of the specified controller service.
 *
 * @param serviceId   a NiFi controller service id
 * @param serviceName a NiFi controller service name
 * @param query       the query to execute
 * @return the query results
 * @throws DataAccessException      if the query cannot be executed
 * @throws IllegalArgumentException if the controller service cannot be found
 */
@Nonnull
public QueryResult executeQueryForControllerService(@Nonnull final String serviceId, @Nonnull final String serviceName, @Nonnull final String query) {
    final ControllerServiceDTO controllerService = getControllerService(serviceId, serviceName);
    if (controllerService != null) {
        final ExecuteQueryControllerServiceRequestBuilder builder = new ExecuteQueryControllerServiceRequestBuilder(controllerService);
        final ExecuteQueryControllerServiceRequest serviceProperties = builder.query(query).build();
        final PoolingDataSourceService.DataSourceProperties dataSourceProperties = getDataSourceProperties(serviceProperties);
        return executeQueryForControllerService(dataSourceProperties, serviceProperties);
    } else {
        log.error("Cannot execute query for controller service. Unable to obtain controller service: {}, {}", serviceId, serviceName);
        throw new IllegalArgumentException("Not a valid controller service: " + serviceId + ", " + serviceName);
    }
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) PoolingDataSourceService(com.thinkbiganalytics.db.PoolingDataSourceService) ExecuteQueryControllerServiceRequestBuilder(com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder) Nonnull(javax.annotation.Nonnull)

Example 5 with ExecuteQueryControllerServiceRequestBuilder

use of com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder in project kylo by Teradata.

the class DBCPConnectionPoolService method generatePreviewQueryForControllerService.

/**
 * Generates a preview query on a table, in the context of the specified controller service, based
 * on the supplied schema (if provided) and limit.
 *
 * @param serviceId   a NiFi controller service id
 * @param serviceName a NiFi controller service name
 * @param schema the schema determining the SQL dialect, or null/empty for the default dialect
 * @param tableName the name of the table
 * @param limit the result size
 * @return the query results
 * @throws DataAccessException      if the query cannot be executed
 * @throws IllegalArgumentException if the controller service cannot be found, the tableName is empty, or the limit is less than zero
 */
public String generatePreviewQueryForControllerService(final String serviceId, final String serviceName, @Nonnull final String schema, @Nonnull final String tableName, final int limit) {
    Validate.notEmpty(schema, "No schema provided");
    Validate.notEmpty(tableName, "No table name provided");
    Validate.isTrue(limit >= 0, "The query result size must be greater than or equal to 0");
    final ControllerServiceDTO controllerService = getControllerService(serviceId, serviceName);
    if (controllerService != null) {
        final ExecuteQueryControllerServiceRequest serviceProperties = new ExecuteQueryControllerServiceRequestBuilder(controllerService).build();
        final PoolingDataSourceService.DataSourceProperties dataSourceProperties = getDataSourceProperties(serviceProperties);
        final DatabaseType dbType = DatabaseType.fromJdbcConnectionString(dataSourceProperties.getUrl());
        final ExecuteQueryControllerServiceRequest previewRequest = new ExecuteQueryControllerServiceRequestBuilder(controllerService).using(serviceProperties).previewQuery(dbType, schema, tableName, limit).build();
        return previewRequest.getQuery();
    } else {
        log.error("Cannot execute query for controller service. Unable to obtain controller service: {}, {}", serviceId, serviceName);
        throw new IllegalArgumentException("Not a valid controller service: " + serviceId + ", " + serviceName);
    }
}
Also used : ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) PoolingDataSourceService(com.thinkbiganalytics.db.PoolingDataSourceService) DatabaseType(com.thinkbiganalytics.jdbc.util.DatabaseType) ExecuteQueryControllerServiceRequestBuilder(com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder)

Aggregations

ExecuteQueryControllerServiceRequestBuilder (com.thinkbiganalytics.feedmgr.nifi.controllerservice.ExecuteQueryControllerServiceRequest.ExecuteQueryControllerServiceRequestBuilder)7 ControllerServiceDTO (org.apache.nifi.web.api.dto.ControllerServiceDTO)7 PoolingDataSourceService (com.thinkbiganalytics.db.PoolingDataSourceService)6 DatabaseType (com.thinkbiganalytics.jdbc.util.DatabaseType)5 Nonnull (javax.annotation.Nonnull)5 QueryResult (com.thinkbiganalytics.discovery.schema.QueryResult)1 TableSchema (com.thinkbiganalytics.discovery.schema.TableSchema)1 NifiControllerServiceProperties (com.thinkbiganalytics.feedmgr.nifi.NifiControllerServiceProperties)1 DescribeTableControllerServiceRequestBuilder (com.thinkbiganalytics.feedmgr.nifi.controllerservice.DescribeTableControllerServiceRequest.DescribeTableControllerServiceRequestBuilder)1 DatasourceModelTransform (com.thinkbiganalytics.feedmgr.service.datasource.DatasourceModelTransform)1 KerberosTicketConfiguration (com.thinkbiganalytics.kerberos.KerberosTicketConfiguration)1 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)1 DatasourceProvider (com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider)1 Datasource (com.thinkbiganalytics.metadata.rest.model.data.Datasource)1 JdbcDatasource (com.thinkbiganalytics.metadata.rest.model.data.JdbcDatasource)1 DBSchemaParser (com.thinkbiganalytics.schema.DBSchemaParser)1 QueryRunner (com.thinkbiganalytics.schema.QueryRunner)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1