Search in sources :

Example 1 with DatasetRegistry

use of com.bakdata.conquery.models.worker.DatasetRegistry in project conquery by bakdata.

the class FormTest method executeTest.

@Override
public void executeTest(StandaloneSupport support) throws Exception {
    DatasetRegistry namespaces = support.getNamespace().getNamespaces();
    assertThat(support.getValidator().validate(form)).describedAs("Form Validation Errors").isEmpty();
    ManagedExecution<?> managedForm = support.getNamespace().getExecutionManager().runQuery(namespaces, form, support.getTestUser(), support.getDataset(), support.getConfig());
    managedForm.awaitDone(10, TimeUnit.MINUTES);
    if (managedForm.getState() != ExecutionState.DONE) {
        if (managedForm.getState() == ExecutionState.FAILED) {
            fail(getLabel() + " Query failed");
        } else {
            fail(getLabel() + " not finished after 10 min");
        }
    }
    log.info("{} QUERIES EXECUTED", getLabel());
    checkResults(support, (ManagedForm) managedForm, support.getTestUser());
}
Also used : DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry)

Example 2 with DatasetRegistry

use of com.bakdata.conquery.models.worker.DatasetRegistry in project conquery by bakdata.

the class FormConfigTest method setupTestClass.

@BeforeAll
public void setupTestClass() throws Exception {
    datasetId = dataset.getId();
    datasetId1 = dataset1.getId();
    // Mock DatasetRegistry for translation
    namespacesMock = Mockito.mock(DatasetRegistry.class);
    doAnswer(invocation -> {
        throw new UnsupportedOperationException("Not yet implemented");
    }).when(namespacesMock).getOptional(any());
    doAnswer(invocation -> {
        final DatasetId id = invocation.getArgument(0);
        Namespace namespaceMock = Mockito.mock(Namespace.class);
        if (id.equals(datasetId)) {
            when(namespaceMock.getDataset()).thenReturn(dataset);
        } else if (id.equals(datasetId1)) {
            when(namespaceMock.getDataset()).thenReturn(dataset1);
        } else {
            throw new IllegalStateException("Unkown dataset id.");
        }
        return namespaceMock;
    }).when(namespacesMock).get(any(DatasetId.class));
    when(namespacesMock.getAllDatasets()).thenReturn(List.of(dataset, dataset1));
    when(namespacesMock.injectIntoNew(any(ObjectMapper.class))).thenCallRealMethod();
    when(namespacesMock.inject(any(MutableInjectableValues.class))).thenCallRealMethod();
    storage = new NonPersistentStoreFactory().createMetaStorage();
    ((MutableInjectableValues) FormConfigProcessor.getMAPPER().getInjectableValues()).add(IdResolveContext.class, namespacesMock);
    processor = new FormConfigProcessor(validator, storage, namespacesMock);
    controller = new AuthorizationController(storage, new DevelopmentAuthorizationConfig());
    controller.start();
}
Also used : AuthorizationController(com.bakdata.conquery.models.auth.AuthorizationController) DevelopmentAuthorizationConfig(com.bakdata.conquery.models.config.auth.DevelopmentAuthorizationConfig) FormConfigProcessor(com.bakdata.conquery.models.forms.frontendconfiguration.FormConfigProcessor) MutableInjectableValues(com.bakdata.conquery.io.jackson.MutableInjectableValues) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) Namespace(com.bakdata.conquery.models.worker.Namespace) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with DatasetRegistry

use of com.bakdata.conquery.models.worker.DatasetRegistry in project conquery by bakdata.

the class QueryProcessor method postQuery.

/**
 * Creates a query for all datasets, then submits it for execution on the
 * intended dataset.
 */
public ManagedExecution<?> postQuery(Dataset dataset, QueryDescription query, Subject subject) {
    log.info("Query posted on Dataset[{}] by User[{{}].", dataset.getId(), subject.getId());
    // This maps works as long as we have query visitors that are not configured in anyway.
    // So adding a visitor twice would replace the previous one but both would have yielded the same result.
    // For the future a better data structure might be desired that also regards similar QueryVisitors of different configuration
    ClassToInstanceMap<QueryVisitor> visitors = MutableClassToInstanceMap.create();
    query.addVisitors(visitors);
    // Initialize checks that need to traverse the query tree
    visitors.putInstance(QueryUtils.OnlyReusingChecker.class, new QueryUtils.OnlyReusingChecker());
    visitors.putInstance(NamespacedIdentifiableCollector.class, new NamespacedIdentifiableCollector());
    final String primaryGroupName = AuthorizationHelper.getPrimaryGroup(subject, storage).map(Group::getName).orElse("none");
    visitors.putInstance(ExecutionMetrics.QueryMetricsReporter.class, new ExecutionMetrics.QueryMetricsReporter(primaryGroupName));
    // Chain all Consumers
    Consumer<Visitable> consumerChain = QueryUtils.getNoOpEntryPoint();
    for (QueryVisitor visitor : visitors.values()) {
        consumerChain = consumerChain.andThen(visitor);
    }
    // Apply consumers to the query tree
    query.visit(consumerChain);
    query.authorize(subject, dataset, visitors);
    // After all authorization checks we can now use the actual subject to invoke the query and do not to bubble down the Userish in methods
    ExecutionMetrics.reportNamespacedIds(visitors.getInstance(NamespacedIdentifiableCollector.class).getIdentifiables(), primaryGroupName);
    ExecutionMetrics.reportQueryClassUsage(query.getClass(), primaryGroupName);
    final Namespace namespace = datasetRegistry.get(dataset.getId());
    final ExecutionManager executionManager = namespace.getExecutionManager();
    // If this is only a re-executing query, try to execute the underlying query instead.
    {
        final Optional<ManagedExecutionId> executionId = visitors.getInstance(QueryUtils.OnlyReusingChecker.class).getOnlyReused();
        final Optional<ManagedExecution<?>> execution = executionId.map(id -> tryReuse(query, id, datasetRegistry, config, executionManager, subject.getUser()));
        if (execution.isPresent()) {
            return execution.get();
        }
    }
    // Execute the query
    return executionManager.runQuery(datasetRegistry, query, subject.getUser(), dataset, config);
}
Also used : ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) URL(java.net.URL) ExternalUpload(com.bakdata.conquery.apiv1.query.ExternalUpload) RequiredArgsConstructor(lombok.RequiredArgsConstructor) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) Map(java.util.Map) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) BadRequestException(javax.ws.rs.BadRequestException) UriBuilder(javax.ws.rs.core.UriBuilder) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) CQAnd(com.bakdata.conquery.apiv1.query.concept.specific.CQAnd) ExecutionMetrics(com.bakdata.conquery.metrics.ExecutionMetrics) Collection(java.util.Collection) SecondaryIdQuery(com.bakdata.conquery.apiv1.query.SecondaryIdQuery) Visitable(com.bakdata.conquery.models.query.Visitable) Set(java.util.Set) User(com.bakdata.conquery.models.auth.entities.User) Collectors(java.util.stream.Collectors) Dataset(com.bakdata.conquery.models.datasets.Dataset) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) ExternalUploadResult(com.bakdata.conquery.apiv1.query.ExternalUploadResult) SecondaryIdDescription(com.bakdata.conquery.models.datasets.SecondaryIdDescription) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) CancelQuery(com.bakdata.conquery.models.messages.namespaces.specific.CancelQuery) Ability(com.bakdata.conquery.models.auth.permissions.Ability) QueryUtils(com.bakdata.conquery.util.QueryUtils) Optional(java.util.Optional) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) Namespace(com.bakdata.conquery.models.worker.Namespace) ExecutionManager(com.bakdata.conquery.models.query.ExecutionManager) ResultRendererProvider(com.bakdata.conquery.io.result.ResultRender.ResultRendererProvider) Getter(lombok.Getter) ExecutionState(com.bakdata.conquery.models.execution.ExecutionState) Subject(com.bakdata.conquery.models.auth.entities.Subject) ClassToInstanceMap(com.google.common.collect.ClassToInstanceMap) HttpServletRequest(javax.servlet.http.HttpServletRequest) ManagedExecutionId(com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId) QueryVisitor(com.bakdata.conquery.models.query.visitor.QueryVisitor) NamespacedIdentifiableCollector(com.bakdata.conquery.util.QueryUtils.NamespacedIdentifiableCollector) Group(com.bakdata.conquery.models.auth.entities.Group) CQExternal(com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal) AuthorizationHelper(com.bakdata.conquery.models.auth.AuthorizationHelper) Consumer(java.util.function.Consumer) MutableClassToInstanceMap(com.google.common.collect.MutableClassToInstanceMap) AuthorizationHelper.buildDatasetAbilityMap(com.bakdata.conquery.models.auth.AuthorizationHelper.buildDatasetAbilityMap) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) CQElement(com.bakdata.conquery.apiv1.query.CQElement) Query(com.bakdata.conquery.apiv1.query.Query) QueryVisitor(com.bakdata.conquery.models.query.visitor.QueryVisitor) ExecutionManager(com.bakdata.conquery.models.query.ExecutionManager) NamespacedIdentifiableCollector(com.bakdata.conquery.util.QueryUtils.NamespacedIdentifiableCollector) Optional(java.util.Optional) Visitable(com.bakdata.conquery.models.query.Visitable) ExecutionMetrics(com.bakdata.conquery.metrics.ExecutionMetrics) Namespace(com.bakdata.conquery.models.worker.Namespace) QueryUtils(com.bakdata.conquery.util.QueryUtils)

Example 4 with DatasetRegistry

use of com.bakdata.conquery.models.worker.DatasetRegistry in project conquery by bakdata.

the class ApiV1 method registerResources.

@Override
public void registerResources(ManagerNode manager) {
    DatasetRegistry datasets = manager.getDatasetRegistry();
    JerseyEnvironment environment = manager.getEnvironment().jersey();
    environment.setUrlPattern("/api");
    // inject required services
    environment.register(new AbstractBinder() {

        @Override
        protected void configure() {
            bind(manager.getConfig()).to(ConqueryConfig.class);
            bind(manager.getDatasetRegistry()).to(DatasetRegistry.class);
            bind(manager.getStorage()).to(MetaStorage.class);
            bind(new ConceptsProcessor(manager.getDatasetRegistry())).to(ConceptsProcessor.class);
            bind(new MeProcessor(manager.getStorage(), datasets)).to(MeProcessor.class);
            bind(new QueryProcessor(datasets, manager.getStorage(), manager.getConfig())).to(QueryProcessor.class);
            bind(new FormConfigProcessor(manager.getValidator(), manager.getStorage(), datasets)).to(FormConfigProcessor.class);
        }
    });
    environment.register(CORSPreflightRequestFilter.class);
    environment.register(CORSResponseFilter.class);
    environment.register(new ActiveUsersFilter(manager.getStorage(), Duration.ofMinutes(manager.getConfig().getMetricsConfig().getUserActiveDuration().toMinutes())));
    /*
		 * Register the authentication filter which protects all resources registered in this servlet.
		 * We use the same instance of the filter for the api servlet and the admin servlet to have a single
		 * point for authentication.
		 */
    environment.register(manager.getAuthController().getAuthenticationFilter());
    environment.register(QueryResource.class);
    environment.register(IdParamConverter.Provider.INSTANCE);
    environment.register(new ConfigResource(manager.getConfig()));
    environment.register(FormConfigResource.class);
    environment.register(DatasetsResource.class);
    environment.register(ConceptResource.class);
    environment.register(DatasetResource.class);
    environment.register(FilterResource.class);
    environment.register(MeResource.class);
    for (ResultRendererProvider resultProvider : manager.getConfig().getResultProviders()) {
        resultProvider.registerResultResource(environment, manager);
    }
    environment.register(new IdRefPathParamConverterProvider(manager.getDatasetRegistry(), manager.getDatasetRegistry().getMetaRegistry()));
}
Also used : FormConfigProcessor(com.bakdata.conquery.models.forms.frontendconfiguration.FormConfigProcessor) AbstractBinder(org.glassfish.hk2.utilities.binding.AbstractBinder) ActiveUsersFilter(com.bakdata.conquery.metrics.ActiveUsersFilter) FormConfigResource(com.bakdata.conquery.resources.api.FormConfigResource) ConfigResource(com.bakdata.conquery.resources.api.ConfigResource) JerseyEnvironment(io.dropwizard.jersey.setup.JerseyEnvironment) IdRefPathParamConverterProvider(com.bakdata.conquery.io.jackson.IdRefPathParamConverterProvider) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) ResultRendererProvider(com.bakdata.conquery.io.result.ResultRender.ResultRendererProvider) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) ConceptsProcessor(com.bakdata.conquery.resources.api.ConceptsProcessor)

Example 5 with DatasetRegistry

use of com.bakdata.conquery.models.worker.DatasetRegistry in project conquery by bakdata.

the class FullExportForm method createSubQueries.

@Override
public Map<String, List<ManagedQuery>> createSubQueries(DatasetRegistry datasets, User user, Dataset submittedDataset) {
    // Forms are sent as an array of standard queries containing AND/OR of CQConcepts, we ignore everything and just convert the CQConcepts into CQUnfiltered for export.
    final List<CQUnfilteredTable> unfilteredTables = tables.stream().flatMap(Visitable::stream).filter(CQConcept.class::isInstance).map(CQConcept.class::cast).flatMap(concept -> concept.getTables().stream()).map(table -> new CQUnfilteredTable(table.getConnector(), table.getDateColumn())).collect(Collectors.toList());
    final TableExportQuery exportQuery = new TableExportQuery(queryGroup.getQuery());
    exportQuery.setDateRange(getDateRange());
    exportQuery.setTables(unfilteredTables);
    final ManagedQuery managedQuery = new ManagedQuery(exportQuery, user, submittedDataset);
    return Map.of(ConqueryConstants.SINGLE_RESULT_TABLE_NAME, List.of(managedQuery));
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Setter(lombok.Setter) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) CQUnfilteredTable(com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable) ManagedForm(com.bakdata.conquery.models.forms.managed.ManagedForm) Getter(lombok.Getter) ManagedInternalForm(com.bakdata.conquery.models.forms.managed.ManagedInternalForm) NotEmpty(javax.validation.constraints.NotEmpty) Valid(javax.validation.Valid) ManagedExecutionId(com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) I18n(com.bakdata.conquery.models.i18n.I18n) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription) ConqueryConstants(com.bakdata.conquery.ConqueryConstants) Nullable(javax.annotation.Nullable) Range(com.bakdata.conquery.models.common.Range) CPSType(com.bakdata.conquery.io.cps.CPSType) Visitable(com.bakdata.conquery.models.query.Visitable) Set(java.util.Set) Form(com.bakdata.conquery.apiv1.forms.Form) NotNull(javax.validation.constraints.NotNull) User(com.bakdata.conquery.models.auth.entities.User) Collectors(java.util.stream.Collectors) ExportFormC10n(com.bakdata.conquery.internationalization.ExportFormC10n) Dataset(com.bakdata.conquery.models.datasets.Dataset) Consumer(java.util.function.Consumer) List(java.util.List) TableExportQuery(com.bakdata.conquery.apiv1.query.TableExportQuery) C10N(c10n.C10N) QueryResolveContext(com.bakdata.conquery.models.query.QueryResolveContext) LocalDate(java.time.LocalDate) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) CQElement(com.bakdata.conquery.apiv1.query.CQElement) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) Collections(java.util.Collections) CQUnfilteredTable(com.bakdata.conquery.apiv1.query.concept.filter.CQUnfilteredTable) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) TableExportQuery(com.bakdata.conquery.apiv1.query.TableExportQuery) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery)

Aggregations

DatasetRegistry (com.bakdata.conquery.models.worker.DatasetRegistry)14 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)6 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)6 Dataset (com.bakdata.conquery.models.datasets.Dataset)6 Namespace (com.bakdata.conquery.models.worker.Namespace)6 Subject (com.bakdata.conquery.models.auth.entities.Subject)5 ManagedExecution (com.bakdata.conquery.models.execution.ManagedExecution)5 List (java.util.List)5 Response (javax.ws.rs.core.Response)5 User (com.bakdata.conquery.models.auth.entities.User)4 Ability (com.bakdata.conquery.models.auth.permissions.Ability)4 I18n (com.bakdata.conquery.models.i18n.I18n)4 DatasetId (com.bakdata.conquery.models.identifiable.ids.specific.DatasetId)4 Group (com.bakdata.conquery.models.auth.entities.Group)3 MediaType (javax.ws.rs.core.MediaType)3 CQElement (com.bakdata.conquery.apiv1.query.CQElement)2 QueryDescription (com.bakdata.conquery.apiv1.query.QueryDescription)2 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)2 ResultRendererProvider (com.bakdata.conquery.io.result.ResultRender.ResultRendererProvider)2 ResultUtil (com.bakdata.conquery.io.result.ResultUtil)2