diff --git a/backend/src/main/java/com/bakdata/conquery/Conquery.java b/backend/src/main/java/com/bakdata/conquery/Conquery.java index 6051d23a9c..4fbbdecfd9 100644 --- a/backend/src/main/java/com/bakdata/conquery/Conquery.java +++ b/backend/src/main/java/com/bakdata/conquery/Conquery.java @@ -3,7 +3,12 @@ import jakarta.validation.Validator; import ch.qos.logback.classic.Level; -import com.bakdata.conquery.commands.*; +import com.bakdata.conquery.commands.DistributedStandaloneCommand; +import com.bakdata.conquery.commands.ManagerNode; +import com.bakdata.conquery.commands.MigrateCommand; +import com.bakdata.conquery.commands.PreprocessorCommand; +import com.bakdata.conquery.commands.RecodeStoreCommand; +import com.bakdata.conquery.commands.ShardCommand; import com.bakdata.conquery.io.jackson.Jackson; import com.bakdata.conquery.io.jackson.MutableInjectableValues; import com.bakdata.conquery.metrics.prometheus.PrometheusBundle; @@ -21,7 +26,6 @@ import io.dropwizard.core.setup.Environment; import lombok.Getter; import lombok.RequiredArgsConstructor; -import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.text.StringSubstitutor; import org.glassfish.jersey.internal.inject.AbstractBinder; @@ -32,13 +36,15 @@ public class Conquery extends Application { private final String name; - @Setter - private ManagerNode managerNode; public Conquery() { this("Conquery"); } + public static void main(String... args) throws Exception { + new Conquery().run(args); + } + @Override public void initialize(Bootstrap bootstrap) { final ObjectMapper confMapper = bootstrap.getObjectMapper(); @@ -49,7 +55,7 @@ public void initialize(Bootstrap bootstrap) { bootstrap.addCommand(new ShardCommand()); bootstrap.addCommand(new PreprocessorCommand()); - bootstrap.addCommand(new DistributedStandaloneCommand(this)); + bootstrap.addCommand(new DistributedStandaloneCommand()); bootstrap.addCommand(new RecodeStoreCommand()); bootstrap.addCommand(new MigrateCommand()); @@ -92,17 +98,10 @@ protected Level bootstrapLogLevel() { public void run(ConqueryConfig configuration, Environment environment) throws Exception { ManagerProvider provider = configuration.getSqlConnectorConfig().isEnabled() ? new LocalManagerProvider() : new ClusterManagerProvider(); - run(provider.provideManager(configuration, environment)); - } + Manager manager = provider.provideManager(configuration, environment); - public void run(Manager manager) throws InterruptedException { - if (managerNode == null) { - managerNode = new ManagerNode(); - } - managerNode.run(manager); - } + ManagerNode managerNode = new ManagerNode(); - public static void main(String... args) throws Exception { - new Conquery().run(args); + managerNode.run(manager); } } diff --git a/backend/src/main/java/com/bakdata/conquery/commands/DistributedStandaloneCommand.java b/backend/src/main/java/com/bakdata/conquery/commands/DistributedStandaloneCommand.java index 311c72cf5f..97b67aa1f1 100644 --- a/backend/src/main/java/com/bakdata/conquery/commands/DistributedStandaloneCommand.java +++ b/backend/src/main/java/com/bakdata/conquery/commands/DistributedStandaloneCommand.java @@ -4,14 +4,13 @@ import java.util.List; import java.util.Vector; -import com.bakdata.conquery.Conquery; import com.bakdata.conquery.mode.cluster.ClusterManager; import com.bakdata.conquery.mode.cluster.ClusterManagerProvider; import com.bakdata.conquery.models.config.ConqueryConfig; import com.bakdata.conquery.models.config.XodusStoreFactory; +import com.bakdata.conquery.util.commands.NoOpConquery; import com.bakdata.conquery.util.io.ConqueryMDC; import io.dropwizard.core.cli.ServerCommand; -import io.dropwizard.core.setup.Bootstrap; import io.dropwizard.core.setup.Environment; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -21,56 +20,30 @@ @Getter public class DistributedStandaloneCommand extends ServerCommand implements StandaloneCommand { - private final Conquery conquery; - private ClusterManager manager; private final ManagerNode managerNode = new ManagerNode(); private final List shardNodes = new Vector<>(); + private ClusterManager manager; - // TODO clean up the command structure, so we can use the Environment from EnvironmentCommand - private Environment environment; - - public DistributedStandaloneCommand(Conquery conquery) { - super(conquery, "standalone", "starts a server and a client at the same time."); - this.conquery = conquery; + public DistributedStandaloneCommand() { + super(new NoOpConquery(), "standalone", "starts a manager node and shard node(s) at the same time in a single JVM."); } - // this must be overridden so that @Override - public void run(Bootstrap bootstrap, Namespace namespace, ConqueryConfig configuration) throws Exception { - environment = new Environment( - bootstrap.getApplication().getName(), - bootstrap.getObjectMapper(), - bootstrap.getValidatorFactory(), - bootstrap.getMetricRegistry(), - bootstrap.getClassLoader(), - bootstrap.getHealthCheckRegistry(), - configuration - ); - configuration.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry()); - configuration.getServerFactory().configure(environment); - - bootstrap.run(configuration, environment); - startStandalone(environment, namespace, configuration); - } + protected void run(Environment environment, Namespace namespace, ConqueryConfig configuration) throws Exception { - public void startStandalone(Environment environment, Namespace namespace, ConqueryConfig config) throws Exception { - // start ManagerNode - ConqueryMDC.setLocation("ManagerNode"); - log.debug("Starting ManagerNode"); - ConqueryConfig managerConfig = config; + ConqueryConfig managerConfig = configuration; - if (config.getStorage() instanceof XodusStoreFactory) { - final Path managerDir = ((XodusStoreFactory) config.getStorage()).getDirectory().resolve("manager"); - managerConfig = config.withStorage(((XodusStoreFactory) config.getStorage()).withDirectory(managerDir)); + if (configuration.getStorage() instanceof XodusStoreFactory) { + final Path managerDir = ((XodusStoreFactory) configuration.getStorage()).getDirectory().resolve("manager"); + managerConfig = configuration.withStorage(((XodusStoreFactory) configuration.getStorage()).withDirectory(managerDir)); } manager = new ClusterManagerProvider().provideManager(managerConfig, environment); - conquery.setManagerNode(managerNode); - conquery.run(manager); + managerNode.run(manager); - for (int id = 0; id < config.getStandalone().getNumberOfShardNodes(); id++) { + for (int id = 0; id < configuration.getStandalone().getNumberOfShardNodes(); id++) { ShardNode sc = new ShardNode(ShardNode.DEFAULT_NAME + id); @@ -78,11 +51,11 @@ public void startStandalone(Environment environment, Namespace namespace, Conque ConqueryMDC.setLocation(sc.getName()); - ConqueryConfig clone = config; + ConqueryConfig clone = configuration; - if (config.getStorage() instanceof XodusStoreFactory) { - final Path managerDir = ((XodusStoreFactory) config.getStorage()).getDirectory().resolve("shard-node" + id); - clone = config.withStorage(((XodusStoreFactory) config.getStorage()).withDirectory(managerDir)); + if (configuration.getStorage() instanceof XodusStoreFactory) { + final Path managerDir = ((XodusStoreFactory) configuration.getStorage()).getDirectory().resolve("shard-node" + id); + clone = configuration.withStorage(((XodusStoreFactory) configuration.getStorage()).withDirectory(managerDir)); } sc.run(clone, environment); @@ -93,6 +66,6 @@ public void startStandalone(Environment environment, Namespace namespace, Conque ConqueryMDC.setLocation("ManagerNode"); log.debug("Starting REST Server"); ConqueryMDC.setLocation(null); - super.run(environment, namespace, config); + super.run(environment, namespace, configuration); } } diff --git a/backend/src/main/java/com/bakdata/conquery/commands/StandaloneCommand.java b/backend/src/main/java/com/bakdata/conquery/commands/StandaloneCommand.java index abf7ec7fe3..7545564291 100644 --- a/backend/src/main/java/com/bakdata/conquery/commands/StandaloneCommand.java +++ b/backend/src/main/java/com/bakdata/conquery/commands/StandaloneCommand.java @@ -2,25 +2,15 @@ import java.util.List; -import com.bakdata.conquery.Conquery; import com.bakdata.conquery.mode.Manager; -import com.bakdata.conquery.models.config.ConqueryConfig; -import io.dropwizard.core.setup.Bootstrap; import io.dropwizard.core.setup.Environment; -import net.sourceforge.argparse4j.inf.Namespace; public interface StandaloneCommand { - void startStandalone(Environment environment, Namespace namespace, ConqueryConfig config) throws Exception; - Manager getManager(); List getShardNodes(); - void run(Bootstrap bootstrap, Namespace namespace, ConqueryConfig configuration) throws Exception; - - Conquery getConquery(); - ManagerNode getManagerNode(); Environment getEnvironment(); diff --git a/backend/src/test/java/com/bakdata/conquery/integration/sql/SqlStandaloneCommand.java b/backend/src/test/java/com/bakdata/conquery/integration/sql/SqlStandaloneCommand.java index 6504e804a2..5b21e5491b 100644 --- a/backend/src/test/java/com/bakdata/conquery/integration/sql/SqlStandaloneCommand.java +++ b/backend/src/test/java/com/bakdata/conquery/integration/sql/SqlStandaloneCommand.java @@ -3,7 +3,6 @@ import java.util.Collections; import java.util.List; -import com.bakdata.conquery.Conquery; import com.bakdata.conquery.commands.ManagerNode; import com.bakdata.conquery.commands.ShardNode; import com.bakdata.conquery.commands.StandaloneCommand; @@ -12,9 +11,9 @@ import com.bakdata.conquery.mode.local.LocalManagerProvider; import com.bakdata.conquery.models.config.ConqueryConfig; import com.bakdata.conquery.models.worker.LocalNamespace; +import com.bakdata.conquery.util.commands.NoOpConquery; import com.bakdata.conquery.util.io.ConqueryMDC; import io.dropwizard.core.cli.ServerCommand; -import io.dropwizard.core.setup.Bootstrap; import io.dropwizard.core.setup.Environment; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -24,27 +23,11 @@ @Getter public class SqlStandaloneCommand extends ServerCommand implements StandaloneCommand { - private final Conquery conquery; - private ManagerNode managerNode = new ManagerNode(); + private final ManagerNode managerNode = new ManagerNode(); private DelegateManager manager; - private Environment environment; - public SqlStandaloneCommand(Conquery conquery) { - super(conquery, "standalone", "starts a sql server and a client at the same time."); - this.conquery = conquery; - } - - @Override - public void startStandalone(Environment environment, Namespace namespace, ConqueryConfig config) throws Exception { - ConqueryMDC.setLocation("ManagerNode"); - log.debug("Starting ManagerNode"); - this.manager = new LocalManagerProvider(new TestSqlDialectFactory()).provideManager(config, environment); - this.conquery.setManagerNode(managerNode); - this.conquery.run(manager); - // starts the Jersey Server - log.debug("Starting REST Server"); - ConqueryMDC.setLocation(null); - super.run(environment, namespace, config); + public SqlStandaloneCommand() { + super(new NoOpConquery(), "standalone", "starts a sql server and a client at the same time."); } @Override @@ -53,23 +36,14 @@ public List getShardNodes() { } @Override - public void run(Bootstrap bootstrap, Namespace namespace, ConqueryConfig configuration) throws Exception { - environment = new Environment( - bootstrap.getApplication().getName(), - bootstrap.getObjectMapper(), - bootstrap.getValidatorFactory(), - bootstrap.getMetricRegistry(), - bootstrap.getClassLoader(), - bootstrap.getHealthCheckRegistry(), - configuration - ); - configuration.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry()); - configuration.getServerFactory().configure(environment); - - bootstrap.run(configuration, environment); - startStandalone(environment, namespace, configuration); + protected void run(Environment environment, Namespace namespace, ConqueryConfig configuration) throws Exception { + ConqueryMDC.setLocation("ManagerNode"); + log.debug("Starting ManagerNode"); + this.manager = new LocalManagerProvider(new TestSqlDialectFactory()).provideManager(configuration, environment); + managerNode.run(manager); + // starts the Jersey Server + log.debug("Starting REST Server"); + ConqueryMDC.setLocation(null); + super.run(environment, namespace, configuration); } - - - } diff --git a/backend/src/test/java/com/bakdata/conquery/util/support/TestConquery.java b/backend/src/test/java/com/bakdata/conquery/util/support/TestConquery.java index 90b6f61be1..5780c6348c 100644 --- a/backend/src/test/java/com/bakdata/conquery/util/support/TestConquery.java +++ b/backend/src/test/java/com/bakdata/conquery/util/support/TestConquery.java @@ -16,7 +16,6 @@ import jakarta.ws.rs.client.Client; import jakarta.ws.rs.core.UriBuilder; -import com.bakdata.conquery.Conquery; import com.bakdata.conquery.commands.DistributedStandaloneCommand; import com.bakdata.conquery.commands.ShardNode; import com.bakdata.conquery.commands.StandaloneCommand; @@ -230,10 +229,10 @@ public void beforeAll() throws Exception { // define server dropwizard = new DropwizardTestSupport<>(TestBootstrappingConquery.class, config, app -> { if (config.getSqlConnectorConfig().isEnabled()) { - standaloneCommand = new SqlStandaloneCommand((Conquery) app); + standaloneCommand = new SqlStandaloneCommand(); } else { - standaloneCommand = new DistributedStandaloneCommand((Conquery) app); + standaloneCommand = new DistributedStandaloneCommand(); } return (Command) standaloneCommand; });