Search in sources :

Example 1 with ResultType

use of com.yahoo.elide.async.models.ResultType in project elide by yahoo.

the class ElideAsyncConfiguration method buildAsyncExecutorService.

/**
 * Configure the AsyncExecutorService used for submitting async query requests.
 * @param elide elideObject.
 * @param settings Elide settings.
 * @param asyncQueryDao AsyncDao object.
 * @return a AsyncExecutorService.
 */
@Bean
@ConditionalOnMissingBean
public AsyncExecutorService buildAsyncExecutorService(RefreshableElide elide, ElideConfigProperties settings, AsyncAPIDAO asyncQueryDao, @Autowired(required = false) ResultStorageEngine resultStorageEngine) {
    AsyncProperties asyncProperties = settings.getAsync();
    ExecutorService executor = Executors.newFixedThreadPool(asyncProperties.getThreadPoolSize());
    ExecutorService updater = Executors.newFixedThreadPool(asyncProperties.getThreadPoolSize());
    AsyncExecutorService asyncExecutorService = new AsyncExecutorService(elide.getElide(), executor, updater, asyncQueryDao);
    // Binding AsyncQuery LifeCycleHook
    AsyncQueryHook asyncQueryHook = new AsyncQueryHook(asyncExecutorService, asyncProperties.getMaxAsyncAfterSeconds());
    EntityDictionary dictionary = elide.getElide().getElideSettings().getDictionary();
    dictionary.bindTrigger(AsyncQuery.class, CREATE, PREFLUSH, asyncQueryHook, false);
    dictionary.bindTrigger(AsyncQuery.class, CREATE, POSTCOMMIT, asyncQueryHook, false);
    dictionary.bindTrigger(AsyncQuery.class, CREATE, PRESECURITY, asyncQueryHook, false);
    boolean exportEnabled = ElideAutoConfiguration.isExportEnabled(asyncProperties);
    if (exportEnabled) {
        // Initialize the Formatters.
        boolean skipCSVHeader = asyncProperties.getExport() != null && asyncProperties.getExport().isSkipCSVHeader();
        Map<ResultType, TableExportFormatter> supportedFormatters = new HashMap<>();
        supportedFormatters.put(ResultType.CSV, new CSVExportFormatter(elide.getElide(), skipCSVHeader));
        supportedFormatters.put(ResultType.JSON, new JSONExportFormatter(elide.getElide()));
        // Binding TableExport LifeCycleHook
        TableExportHook tableExportHook = getTableExportHook(asyncExecutorService, settings, supportedFormatters, resultStorageEngine);
        dictionary.bindTrigger(TableExport.class, CREATE, PREFLUSH, tableExportHook, false);
        dictionary.bindTrigger(TableExport.class, CREATE, POSTCOMMIT, tableExportHook, false);
        dictionary.bindTrigger(TableExport.class, CREATE, PRESECURITY, tableExportHook, false);
    }
    return asyncExecutorService;
}
Also used : TableExportHook(com.yahoo.elide.async.hooks.TableExportHook) HashMap(java.util.HashMap) AsyncQueryHook(com.yahoo.elide.async.hooks.AsyncQueryHook) JSONExportFormatter(com.yahoo.elide.async.export.formatter.JSONExportFormatter) ResultType(com.yahoo.elide.async.models.ResultType) CSVExportFormatter(com.yahoo.elide.async.export.formatter.CSVExportFormatter) AsyncExecutorService(com.yahoo.elide.async.service.AsyncExecutorService) ExecutorService(java.util.concurrent.ExecutorService) AsyncExecutorService(com.yahoo.elide.async.service.AsyncExecutorService) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) TableExportFormatter(com.yahoo.elide.async.export.formatter.TableExportFormatter) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with ResultType

use of com.yahoo.elide.async.models.ResultType in project elide by yahoo.

the class TableExportHook method getOperation.

@Override
public Callable<AsyncAPIResult> getOperation(AsyncAPI export, RequestScope requestScope) {
    Callable<AsyncAPIResult> operation = null;
    TableExport exportObj = (TableExport) export;
    ResultType resultType = exportObj.getResultType();
    QueryType queryType = exportObj.getQueryType();
    com.yahoo.elide.core.RequestScope scope = (com.yahoo.elide.core.RequestScope) requestScope;
    TableExportFormatter formatter = supportedFormatters.get(resultType);
    if (formatter == null) {
        throw new InvalidOperationException("Formatter unavailable for " + resultType);
    }
    if (queryType.equals(QueryType.GRAPHQL_V1_0)) {
        operation = new GraphQLTableExportOperation(formatter, getAsyncExecutorService(), export, scope, engine);
    } else if (queryType.equals(QueryType.JSONAPI_V1_0)) {
        operation = new JSONAPITableExportOperation(formatter, getAsyncExecutorService(), export, scope, engine);
    } else {
        throw new InvalidOperationException(queryType + "is not supported");
    }
    return operation;
}
Also used : JSONAPITableExportOperation(com.yahoo.elide.async.operation.JSONAPITableExportOperation) ResultType(com.yahoo.elide.async.models.ResultType) RequestScope(com.yahoo.elide.core.security.RequestScope) TableExport(com.yahoo.elide.async.models.TableExport) InvalidOperationException(com.yahoo.elide.core.exceptions.InvalidOperationException) GraphQLTableExportOperation(com.yahoo.elide.async.operation.GraphQLTableExportOperation) AsyncAPIResult(com.yahoo.elide.async.models.AsyncAPIResult) QueryType(com.yahoo.elide.async.models.QueryType) TableExportFormatter(com.yahoo.elide.async.export.formatter.TableExportFormatter)

Aggregations

TableExportFormatter (com.yahoo.elide.async.export.formatter.TableExportFormatter)2 ResultType (com.yahoo.elide.async.models.ResultType)2 CSVExportFormatter (com.yahoo.elide.async.export.formatter.CSVExportFormatter)1 JSONExportFormatter (com.yahoo.elide.async.export.formatter.JSONExportFormatter)1 AsyncQueryHook (com.yahoo.elide.async.hooks.AsyncQueryHook)1 TableExportHook (com.yahoo.elide.async.hooks.TableExportHook)1 AsyncAPIResult (com.yahoo.elide.async.models.AsyncAPIResult)1 QueryType (com.yahoo.elide.async.models.QueryType)1 TableExport (com.yahoo.elide.async.models.TableExport)1 GraphQLTableExportOperation (com.yahoo.elide.async.operation.GraphQLTableExportOperation)1 JSONAPITableExportOperation (com.yahoo.elide.async.operation.JSONAPITableExportOperation)1 AsyncExecutorService (com.yahoo.elide.async.service.AsyncExecutorService)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 InvalidOperationException (com.yahoo.elide.core.exceptions.InvalidOperationException)1 RequestScope (com.yahoo.elide.core.security.RequestScope)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1