Search in sources :

Example 6 with ConqueryConfig

use of com.bakdata.conquery.models.config.ConqueryConfig in project conquery by bakdata.

the class StandaloneSupport method preprocessTmp.

public void preprocessTmp(File tmpDir, List<File> descriptions) throws Exception {
    final Environment env = testConquery.getDropwizard().getEnvironment();
    final net.sourceforge.argparse4j.inf.Namespace namespace = new net.sourceforge.argparse4j.inf.Namespace(Map.of("in", tmpDir, "out", tmpDir, "desc", descriptions));
    // We use this to change the visibility of the run method, hence it cannot be instantiated.
    new PreprocessorCommand(MoreExecutors.newDirectExecutorService()) {

        @Override
        public void run(Environment environment, net.sourceforge.argparse4j.inf.Namespace namespace, ConqueryConfig config) throws Exception {
            super.run(environment, namespace, config);
        }
    }.run(env, namespace, config);
}
Also used : ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) Environment(io.dropwizard.setup.Environment) PreprocessorCommand(com.bakdata.conquery.commands.PreprocessorCommand) Namespace(com.bakdata.conquery.models.worker.Namespace) IOException(java.io.IOException)

Example 7 with ConqueryConfig

use of com.bakdata.conquery.models.config.ConqueryConfig in project conquery by bakdata.

the class StandaloneCommand method startStandalone.

protected void startStandalone(Environment environment, Namespace namespace, ConqueryConfig config) throws Exception {
    // start ManagerNode
    ConqueryMDC.setLocation("ManagerNode");
    log.debug("Starting ManagerNode");
    ConqueryConfig managerConfig = config;
    if (config.getStorage() instanceof XodusStoreFactory) {
        final Path managerDir = ((XodusStoreFactory) config.getStorage()).getDirectory().resolve("manager");
        managerConfig = config.withStorage(((XodusStoreFactory) config.getStorage()).withDirectory(managerDir));
    }
    conquery.setManager(manager);
    conquery.run(managerConfig, environment);
    // create thread pool to start multiple ShardNodes at the same time
    ExecutorService starterPool = Executors.newFixedThreadPool(config.getStandalone().getNumberOfShardNodes(), new ThreadFactoryBuilder().setNameFormat("ShardNode Storage Loader %d").setUncaughtExceptionHandler((t, e) -> {
        ConqueryMDC.setLocation(t.getName());
        log.error(t.getName() + " failed to init storage of ShardNode", e);
    }).build());
    List<Future<ShardNode>> tasks = new ArrayList<>();
    for (int i = 0; i < config.getStandalone().getNumberOfShardNodes(); i++) {
        final int id = i;
        tasks.add(starterPool.submit(() -> {
            ShardNode sc = new ShardNode(ShardNode.DEFAULT_NAME + id);
            shardNodes.add(sc);
            ConqueryMDC.setLocation(sc.getName());
            ConqueryConfig clone = config;
            if (config.getStorage() instanceof XodusStoreFactory) {
                final Path managerDir = ((XodusStoreFactory) config.getStorage()).getDirectory().resolve("shard-node" + id);
                clone = config.withStorage(((XodusStoreFactory) config.getStorage()).withDirectory(managerDir));
            }
            sc.run(environment, namespace, clone);
            return sc;
        }));
    }
    ConqueryMDC.setLocation("ManagerNode");
    log.debug("Waiting for ShardNodes to start");
    starterPool.shutdown();
    starterPool.awaitTermination(1, TimeUnit.HOURS);
    // catch exceptions on tasks
    boolean failed = false;
    for (Future<ShardNode> f : tasks) {
        try {
            f.get();
        } catch (ExecutionException e) {
            log.error("during ShardNodes creation", e);
            failed = true;
        }
    }
    if (failed) {
        System.exit(-1);
    }
    // starts the Jersey Server
    log.debug("Starting REST Server");
    ConqueryMDC.setLocation(null);
    super.run(environment, namespace, config);
}
Also used : Path(java.nio.file.Path) XodusStoreFactory(com.bakdata.conquery.models.config.XodusStoreFactory) ArrayList(java.util.ArrayList) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with ConqueryConfig

use of com.bakdata.conquery.models.config.ConqueryConfig 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)

Example 9 with ConqueryConfig

use of com.bakdata.conquery.models.config.ConqueryConfig in project conquery by bakdata.

the class StringEncodingTest method testHexStreamStringType.

@Test
public void testHexStreamStringType() {
    StringParser parser = new StringParser(new ConqueryConfig());
    Stream.generate(() -> UUID.randomUUID().toString().replace("-", "")).map(String::toUpperCase).mapToInt(v -> {
        try {
            return parser.parse(v);
        } catch (ParsingException e) {
            // We know that StringTypeVarInt is able to parse our strings.
            return 0;
        }
    }).limit(100).forEach(parser::addLine);
    StringTypeEncoded subType = (StringTypeEncoded) parser.findBestType();
    assertThat(subType).isInstanceOf(StringTypeEncoded.class);
    assertThat(subType.getEncoding()).isEqualByComparingTo(StringTypeEncoded.Encoding.Base16UpperCase);
}
Also used : StringParser(com.bakdata.conquery.models.preproc.parser.specific.StringParser) StringTypeEncoded(com.bakdata.conquery.models.events.stores.specific.string.StringTypeEncoded) ParsingException(com.bakdata.conquery.models.exceptions.ParsingException) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 10 with ConqueryConfig

use of com.bakdata.conquery.models.config.ConqueryConfig in project conquery by bakdata.

the class DateRangeParserTest method onlyClosed.

@Test
public void onlyClosed() {
    final DateRangeParser parser = new DateRangeParser(new ConqueryConfig());
    List.of(CDateRange.of(10, 11), CDateRange.exactly(10)).forEach(parser::addLine);
    final ColumnStore actual = parser.decideType();
    assertThat(actual).isInstanceOf(DateRangeTypeDateRange.class);
    assertThat(((IntegerDateStore) ((DateRangeTypeDateRange) actual).getMinStore()).getStore()).isInstanceOfAny(ByteArrayStore.class, RebasingStore.class);
}
Also used : ColumnStore(com.bakdata.conquery.models.events.stores.root.ColumnStore) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) IntegerDateStore(com.bakdata.conquery.models.events.stores.primitive.IntegerDateStore) Test(org.junit.jupiter.api.Test)

Aggregations

ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)18 Test (org.junit.jupiter.api.Test)7 Namespace (com.bakdata.conquery.models.worker.Namespace)3 IOException (java.io.IOException)3 PreprocessorCommand (com.bakdata.conquery.commands.PreprocessorCommand)2 MutableInjectableValues (com.bakdata.conquery.io.jackson.MutableInjectableValues)2 IdPrinter (com.bakdata.conquery.models.identifiable.mapping.IdPrinter)2 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)2 PrintSettings (com.bakdata.conquery.models.query.PrintSettings)2 ResultInfo (com.bakdata.conquery.models.query.resultinfo.ResultInfo)2 DatasetRegistry (com.bakdata.conquery.models.worker.DatasetRegistry)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CollectEntitiesCommand (com.bakdata.conquery.commands.CollectEntitiesCommand)1 MigrateCommand (com.bakdata.conquery.commands.MigrateCommand)1 RecodeStoreCommand (com.bakdata.conquery.commands.RecodeStoreCommand)1 ShardNode (com.bakdata.conquery.commands.ShardNode)1 StandaloneCommand (com.bakdata.conquery.commands.StandaloneCommand)1 JsonIntegrationTest (com.bakdata.conquery.integration.json.JsonIntegrationTest)1 ProgrammaticIntegrationTest (com.bakdata.conquery.integration.tests.ProgrammaticIntegrationTest)1