Search in sources :

Example 6 with DatasetRegistry

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

the class ResultExcelProcessor method getExcelResult.

public <E extends ManagedExecution<?> & SingleTableResult> Response getExcelResult(Subject subject, E exec, DatasetId datasetId, boolean pretty) {
    ConqueryMDC.setLocation(subject.getName());
    final Namespace namespace = datasetRegistry.get(datasetId);
    Dataset dataset = namespace.getDataset();
    subject.authorize(dataset, Ability.READ);
    subject.authorize(dataset, Ability.DOWNLOAD);
    subject.authorize(exec, Ability.READ);
    IdPrinter idPrinter = config.getFrontend().getQueryUpload().getIdPrinter(subject, exec, namespace);
    final Locale locale = I18n.LOCALE.get();
    PrintSettings settings = new PrintSettings(pretty, locale, datasetRegistry, config, idPrinter::createId);
    ExcelRenderer excelRenderer = new ExcelRenderer(config.getExcel(), settings);
    StreamingOutput out = output -> excelRenderer.renderToStream(config.getFrontend().getQueryUpload().getIdResultInfos(), (ManagedExecution<?> & SingleTableResult) exec, output);
    return makeResponseWithFileName(out, exec.getLabelWithoutAutoLabelSuffix(), "xlsx", MEDIA_TYPE, ResultUtil.ContentDispositionOption.ATTACHMENT);
}
Also used : IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) Locale(java.util.Locale) ResultUtil(com.bakdata.conquery.io.result.ResultUtil) ConqueryMDC(com.bakdata.conquery.util.io.ConqueryMDC) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) ResultUtil.makeResponseWithFileName(com.bakdata.conquery.io.result.ResultUtil.makeResponseWithFileName) Subject(com.bakdata.conquery.models.auth.entities.Subject) RequiredArgsConstructor(lombok.RequiredArgsConstructor) StreamingOutput(javax.ws.rs.core.StreamingOutput) SingleTableResult(com.bakdata.conquery.models.query.SingleTableResult) ArrayList(java.util.ArrayList) Dataset(com.bakdata.conquery.models.datasets.Dataset) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) Response(javax.ws.rs.core.Response) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) Ability(com.bakdata.conquery.models.auth.permissions.Ability) Locale(java.util.Locale) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) I18n(com.bakdata.conquery.models.i18n.I18n) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) Namespace(com.bakdata.conquery.models.worker.Namespace) Dataset(com.bakdata.conquery.models.datasets.Dataset) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) StreamingOutput(javax.ws.rs.core.StreamingOutput) SingleTableResult(com.bakdata.conquery.models.query.SingleTableResult) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) Namespace(com.bakdata.conquery.models.worker.Namespace)

Example 7 with DatasetRegistry

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

the class CopyUserTest method testUserCopy.

@Test
void testUserCopy() {
    final DatasetRegistry registry = new DatasetRegistry(0);
    MetaStorage storage = new NonPersistentStoreFactory().createMetaStorage();
    registry.setMetaStorage(storage);
    // Create test role
    Role role = new Role("role", "role", storage);
    storage.addRole(role);
    role.addPermission(DatasetPermission.onInstance(Ability.READ, new DatasetId("dataset0")));
    // Create test group
    Group group = new Group("group", "group", storage);
    storage.addGroup(group);
    group.addPermission(DatasetPermission.onInstance(Ability.READ, new DatasetId("dataset1")));
    // Create original user with role and group mapping
    User originUser = new User("user", "user", storage);
    storage.addUser(originUser);
    originUser.addRole(role);
    group.addMember(originUser);
    // Do copy
    User copy = AuthorizationController.flatCopyUser(originUser, "copytest", storage);
    // Check that it is not the same user
    assertThat(copy).usingRecursiveComparison().isNotEqualTo(originUser);
    // Check that the copy does not have any mappings
    assertThat(group.containsMember(copy)).isFalse();
    assertThat(copy.getRoles()).isEmpty();
    // Check that the flat map worked
    assertThat(copy.getPermissions()).containsExactlyInAnyOrderElementsOf(originUser.getEffectivePermissions());
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) Group(com.bakdata.conquery.models.auth.entities.Group) User(com.bakdata.conquery.models.auth.entities.User) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) Test(org.junit.jupiter.api.Test)

Example 8 with DatasetRegistry

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

the class AdminResource method getQueries.

@GET
@Path("/queries")
public FullExecutionStatus[] getQueries(@Auth Subject currentUser, @QueryParam("limit") OptionalLong limit, @QueryParam("since") Optional<String> since) {
    final MetaStorage storage = processor.getStorage();
    final DatasetRegistry datasetRegistry = processor.getDatasetRegistry();
    return storage.getAllExecutions().stream().map(t -> {
        try {
            return t.buildStatusFull(storage, currentUser, datasetRegistry, processor.getConfig());
        } catch (ConqueryError e) {
            // Initialization of execution probably failed, so we construct a status based on the overview status
            final FullExecutionStatus fullExecutionStatus = new FullExecutionStatus();
            t.setStatusBase(currentUser, fullExecutionStatus);
            fullExecutionStatus.setStatus(ExecutionState.FAILED);
            fullExecutionStatus.setError(e);
            return fullExecutionStatus;
        }
    }).filter(t -> t.getCreatedAt().toLocalDate().isEqual(since.map(LocalDate::parse).orElse(LocalDate.now()))).limit(limit.orElse(100)).toArray(FullExecutionStatus[]::new);
}
Also used : PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ExecutionState(com.bakdata.conquery.models.execution.ExecutionState) JobManagerStatus(com.bakdata.conquery.models.jobs.JobManagerStatus) Path(javax.ws.rs.Path) Subject(com.bakdata.conquery.models.auth.entities.Subject) JOB_ID(com.bakdata.conquery.resources.ResourceConstants.JOB_ID) Auth(io.dropwizard.auth.Auth) NewCookie(javax.ws.rs.core.NewCookie) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Inject(javax.inject.Inject) OptionalLong(java.util.OptionalLong) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) UriBuilder(javax.ws.rs.core.UriBuilder) AdminUIResource(com.bakdata.conquery.resources.admin.ui.AdminUIResource) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) ImmutableMap(com.google.common.collect.ImmutableMap) AuthenticationConfig(com.bakdata.conquery.models.config.auth.AuthenticationConfig) UUID(java.util.UUID) ConqueryError(com.bakdata.conquery.models.error.ConqueryError) ExtraMimeTypes(com.bakdata.conquery.io.jersey.ExtraMimeTypes) Objects(java.util.Objects) CancelJobMessage(com.bakdata.conquery.models.messages.network.specific.CancelJobMessage) Response(javax.ws.rs.core.Response) LocalDate(java.time.LocalDate) FullExecutionStatus(com.bakdata.conquery.apiv1.FullExecutionStatus) ShardNodeInformation(com.bakdata.conquery.models.worker.ShardNodeInformation) Optional(java.util.Optional) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) ConqueryError(com.bakdata.conquery.models.error.ConqueryError) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) FullExecutionStatus(com.bakdata.conquery.apiv1.FullExecutionStatus) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 9 with DatasetRegistry

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

the class ManagerNode method run.

public void run(ConqueryConfig config, Environment environment) throws InterruptedException {
    this.environment = environment;
    validator = environment.getValidator();
    client = new JerseyClientBuilder(environment).using(config.getJerseyClient()).build(getName());
    // Instantiate DatasetRegistry and MetaStorage so they are ready for injection into the object mapper (API + Storage)
    // The validator is already injected at this point see Conquery.java
    datasetRegistry = new DatasetRegistry(config.getCluster().getEntityBucketSize());
    storage = new MetaStorage(datasetRegistry);
    datasetRegistry.injectInto(environment.getObjectMapper());
    storage.injectInto(environment.getObjectMapper());
    jobManager = new JobManager("ManagerNode", config.isFailOnError());
    formScanner = new FormScanner();
    this.config = config;
    config.initialize(this);
    // Initialization of internationalization
    I18n.init();
    RESTServer.configure(config, environment.jersey().getResourceConfig());
    maintenanceService = environment.lifecycle().scheduledExecutorService("Maintenance Service").build();
    environment.lifecycle().manage(this);
    loadNamespaces();
    loadMetaStorage();
    authController = new AuthorizationController(storage, config.getAuthorizationRealms());
    environment.lifecycle().manage(authController);
    unprotectedAuthAdmin = AuthServlet.generalSetup(environment.metrics(), config, environment.admin(), environment.getObjectMapper());
    unprotectedAuthApi = AuthServlet.generalSetup(environment.metrics(), config, environment.servlets(), environment.getObjectMapper());
    // Create AdminServlet first to make it available to the realms
    admin = new AdminServlet(this);
    authController.externalInit(this, config.getAuthenticationRealms());
    // Register default components for the admin interface
    admin.register(this);
    log.info("Registering ResourcesProvider");
    for (Class<? extends ResourcesProvider> resourceProvider : CPSTypeIdResolver.listImplementations(ResourcesProvider.class)) {
        try {
            ResourcesProvider provider = resourceProvider.getConstructor().newInstance();
            provider.registerResources(this);
            providers.add(provider);
        } catch (Exception e) {
            log.error("Failed to register Resource {}", resourceProvider, e);
        }
    }
    try {
        formScanner.execute(null, null);
    } catch (Exception e) {
        Throwables.throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
    environment.admin().addTask(formScanner);
    environment.admin().addTask(new QueryCleanupTask(storage, Duration.of(config.getQueries().getOldQueriesTime().getQuantity(), config.getQueries().getOldQueriesTime().getUnit().toChronoUnit())));
    environment.admin().addTask(new PermissionCleanupTask(storage));
    environment.admin().addTask(new ClearFilterSourceSearch());
    environment.admin().addTask(new ReportConsistencyTask(datasetRegistry));
    ShutdownTask shutdown = new ShutdownTask();
    environment.admin().addTask(shutdown);
    environment.lifecycle().addServerLifecycleListener(shutdown);
}
Also used : FormScanner(com.bakdata.conquery.models.forms.frontendconfiguration.FormScanner) ResourcesProvider(com.bakdata.conquery.resources.ResourcesProvider) JobManager(com.bakdata.conquery.models.jobs.JobManager) PermissionCleanupTask(com.bakdata.conquery.tasks.PermissionCleanupTask) ClearFilterSourceSearch(com.bakdata.conquery.tasks.ClearFilterSourceSearch) ReportConsistencyTask(com.bakdata.conquery.tasks.ReportConsistencyTask) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) QueryCleanupTask(com.bakdata.conquery.tasks.QueryCleanupTask) AuthorizationController(com.bakdata.conquery.models.auth.AuthorizationController) AdminServlet(com.bakdata.conquery.resources.admin.AdminServlet) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) ShutdownTask(com.bakdata.conquery.resources.admin.ShutdownTask) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry)

Example 10 with DatasetRegistry

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

the class ResultArrowProcessor method getArrowResult.

public static <E extends ManagedExecution<?> & SingleTableResult> Response getArrowResult(Function<OutputStream, Function<VectorSchemaRoot, ArrowWriter>> writerProducer, Subject subject, E exec, Dataset dataset, DatasetRegistry datasetRegistry, boolean pretty, String fileExtension, MediaType mediaType, ConqueryConfig config) {
    final Namespace namespace = datasetRegistry.get(dataset.getId());
    ConqueryMDC.setLocation(subject.getName());
    log.info("Downloading results for {} on dataset {}", exec, dataset);
    subject.authorize(dataset, Ability.READ);
    subject.authorize(dataset, Ability.DOWNLOAD);
    subject.authorize(exec, Ability.READ);
    // Check if subject is permitted to download on all datasets that were referenced by the query
    authorizeDownloadDatasets(subject, exec);
    if (!(exec instanceof ManagedQuery || (exec instanceof ManagedForm && ((ManagedForm) exec).getSubQueries().size() == 1))) {
        return Response.status(HttpStatus.SC_UNPROCESSABLE_ENTITY, "Execution result is not a single Table").build();
    }
    // Get the locale extracted by the LocaleFilter
    IdPrinter idPrinter = config.getFrontend().getQueryUpload().getIdPrinter(subject, exec, namespace);
    final Locale locale = I18n.LOCALE.get();
    PrintSettings settings = new PrintSettings(pretty, locale, datasetRegistry, config, idPrinter::createId);
    // Collect ResultInfos for id columns and result columns
    final List<ResultInfo> resultInfosId = config.getFrontend().getQueryUpload().getIdResultInfos();
    final List<ResultInfo> resultInfosExec = exec.getResultInfos();
    StreamingOutput out = output -> renderToStream(writerProducer.apply(output), settings, config.getArrow().getBatchSize(), resultInfosId, resultInfosExec, exec.streamResults());
    return makeResponseWithFileName(out, exec.getLabelWithoutAutoLabelSuffix(), fileExtension, mediaType, ResultUtil.ContentDispositionOption.ATTACHMENT);
}
Also used : IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) Locale(java.util.Locale) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) ManagedForm(com.bakdata.conquery.models.forms.managed.ManagedForm) Subject(com.bakdata.conquery.models.auth.entities.Subject) AuthorizationHelper.authorizeDownloadDatasets(com.bakdata.conquery.models.auth.AuthorizationHelper.authorizeDownloadDatasets) HttpStatus(org.apache.http.HttpStatus) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) UtilityClass(lombok.experimental.UtilityClass) MediaType(javax.ws.rs.core.MediaType) ManagedExecution(com.bakdata.conquery.models.execution.ManagedExecution) ArrowWriter(org.apache.arrow.vector.ipc.ArrowWriter) Locale(java.util.Locale) ArrowRenderer.renderToStream(com.bakdata.conquery.io.result.arrow.ArrowRenderer.renderToStream) I18n(com.bakdata.conquery.models.i18n.I18n) IdPrinter(com.bakdata.conquery.models.identifiable.mapping.IdPrinter) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) OutputStream(java.io.OutputStream) ResultUtil(com.bakdata.conquery.io.result.ResultUtil) ConqueryMDC(com.bakdata.conquery.util.io.ConqueryMDC) ResultUtil.makeResponseWithFileName(com.bakdata.conquery.io.result.ResultUtil.makeResponseWithFileName) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) StreamingOutput(javax.ws.rs.core.StreamingOutput) SingleTableResult(com.bakdata.conquery.models.query.SingleTableResult) Dataset(com.bakdata.conquery.models.datasets.Dataset) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Response(javax.ws.rs.core.Response) Ability(com.bakdata.conquery.models.auth.permissions.Ability) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) Namespace(com.bakdata.conquery.models.worker.Namespace) ManagedForm(com.bakdata.conquery.models.forms.managed.ManagedForm) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) StreamingOutput(javax.ws.rs.core.StreamingOutput) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) Namespace(com.bakdata.conquery.models.worker.Namespace)

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