Search in sources :

Example 1 with AsyncExecutorService

use of com.yahoo.elide.async.service.AsyncExecutorService 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 AsyncExecutorService

use of com.yahoo.elide.async.service.AsyncExecutorService in project elide by yahoo.

the class GraphQLTableExportOperationTest method setupMocks.

@BeforeEach
public void setupMocks(@TempDir Path tempDir) {
    dataStore = new HashMapDataStore(DefaultClassScanner.getInstance(), new HashSet<>(Arrays.asList(TableExport.class.getPackage(), ArtifactGroup.class.getPackage())));
    Map<String, Class<? extends Check>> map = new HashMap<>();
    map.put(AsyncAPIInlineChecks.AsyncAPIOwner.PRINCIPAL_IS_OWNER, AsyncAPIInlineChecks.AsyncAPIOwner.class);
    map.put(AsyncAPIInlineChecks.AsyncAPIAdmin.PRINCIPAL_IS_ADMIN, AsyncAPIInlineChecks.AsyncAPIAdmin.class);
    map.put(AsyncAPIInlineChecks.AsyncAPIStatusValue.VALUE_IS_CANCELLED, AsyncAPIInlineChecks.AsyncAPIStatusValue.class);
    map.put(AsyncAPIInlineChecks.AsyncAPIStatusQueuedValue.VALUE_IS_QUEUED, AsyncAPIInlineChecks.AsyncAPIStatusQueuedValue.class);
    elide = new Elide(new ElideSettingsBuilder(dataStore).withEntityDictionary(EntityDictionary.builder().checks(map).build()).withAuditLogger(new Slf4jLogger()).withExportApiPath("/export").build());
    elide.doScans();
    user = mock(User.class);
    requestScope = mock(RequestScope.class);
    asyncExecutorService = mock(AsyncExecutorService.class);
    engine = new FileResultStorageEngine(tempDir.toString(), false);
    when(asyncExecutorService.getElide()).thenReturn(elide);
    when(requestScope.getApiVersion()).thenReturn(NO_VERSION);
    when(requestScope.getUser()).thenReturn(user);
    when(requestScope.getElideSettings()).thenReturn(elide.getElideSettings());
    when(requestScope.getBaseUrlEndPoint()).thenReturn("https://elide.io");
}
Also used : FileResultStorageEngine(com.yahoo.elide.async.service.storageengine.FileResultStorageEngine) User(com.yahoo.elide.core.security.User) HashMap(java.util.HashMap) Slf4jLogger(com.yahoo.elide.core.audit.Slf4jLogger) Check(com.yahoo.elide.core.security.checks.Check) AsyncAPIInlineChecks(com.yahoo.elide.async.models.security.AsyncAPIInlineChecks) RequestScope(com.yahoo.elide.core.RequestScope) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) AsyncExecutorService(com.yahoo.elide.async.service.AsyncExecutorService) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) Elide(com.yahoo.elide.Elide) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with AsyncExecutorService

use of com.yahoo.elide.async.service.AsyncExecutorService in project elide by yahoo.

the class JsonAPITableExportOperationTest method setupMocks.

@BeforeEach
public void setupMocks(@TempDir Path tempDir) {
    dataStore = new HashMapDataStore(DefaultClassScanner.getInstance(), new HashSet<>(Arrays.asList(TableExport.class.getPackage(), ArtifactGroup.class.getPackage())));
    Map<String, Class<? extends Check>> map = new HashMap<>();
    map.put(AsyncAPIInlineChecks.AsyncAPIOwner.PRINCIPAL_IS_OWNER, AsyncAPIInlineChecks.AsyncAPIOwner.class);
    map.put(AsyncAPIInlineChecks.AsyncAPIAdmin.PRINCIPAL_IS_ADMIN, AsyncAPIInlineChecks.AsyncAPIAdmin.class);
    map.put(AsyncAPIInlineChecks.AsyncAPIStatusValue.VALUE_IS_CANCELLED, AsyncAPIInlineChecks.AsyncAPIStatusValue.class);
    map.put(AsyncAPIInlineChecks.AsyncAPIStatusQueuedValue.VALUE_IS_QUEUED, AsyncAPIInlineChecks.AsyncAPIStatusQueuedValue.class);
    elide = new Elide(new ElideSettingsBuilder(dataStore).withEntityDictionary(EntityDictionary.builder().checks(map).build()).withAuditLogger(new Slf4jLogger()).withExportApiPath("/export").build());
    elide.doScans();
    user = mock(User.class);
    requestScope = mock(RequestScope.class);
    asyncExecutorService = mock(AsyncExecutorService.class);
    engine = new FileResultStorageEngine(tempDir.toString(), true);
    when(asyncExecutorService.getElide()).thenReturn(elide);
    when(requestScope.getApiVersion()).thenReturn(NO_VERSION);
    when(requestScope.getUser()).thenReturn(user);
    when(requestScope.getElideSettings()).thenReturn(elide.getElideSettings());
    when(requestScope.getBaseUrlEndPoint()).thenReturn("https://elide.io");
}
Also used : FileResultStorageEngine(com.yahoo.elide.async.service.storageengine.FileResultStorageEngine) User(com.yahoo.elide.core.security.User) HashMap(java.util.HashMap) Slf4jLogger(com.yahoo.elide.core.audit.Slf4jLogger) Check(com.yahoo.elide.core.security.checks.Check) AsyncAPIInlineChecks(com.yahoo.elide.async.models.security.AsyncAPIInlineChecks) RequestScope(com.yahoo.elide.core.RequestScope) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) AsyncExecutorService(com.yahoo.elide.async.service.AsyncExecutorService) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) Elide(com.yahoo.elide.Elide) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

AsyncExecutorService (com.yahoo.elide.async.service.AsyncExecutorService)3 HashMap (java.util.HashMap)3 Elide (com.yahoo.elide.Elide)2 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)2 AsyncAPIInlineChecks (com.yahoo.elide.async.models.security.AsyncAPIInlineChecks)2 FileResultStorageEngine (com.yahoo.elide.async.service.storageengine.FileResultStorageEngine)2 RequestScope (com.yahoo.elide.core.RequestScope)2 Slf4jLogger (com.yahoo.elide.core.audit.Slf4jLogger)2 HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)2 User (com.yahoo.elide.core.security.User)2 Check (com.yahoo.elide.core.security.checks.Check)2 HashSet (java.util.HashSet)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 CSVExportFormatter (com.yahoo.elide.async.export.formatter.CSVExportFormatter)1 JSONExportFormatter (com.yahoo.elide.async.export.formatter.JSONExportFormatter)1 TableExportFormatter (com.yahoo.elide.async.export.formatter.TableExportFormatter)1 AsyncQueryHook (com.yahoo.elide.async.hooks.AsyncQueryHook)1 TableExportHook (com.yahoo.elide.async.hooks.TableExportHook)1 ResultType (com.yahoo.elide.async.models.ResultType)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1