Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

untangle commands, use overrides from framework #3616

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions backend/src/main/java/com/bakdata/conquery/Conquery.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -32,13 +36,15 @@
public class Conquery extends Application<ConqueryConfig> {

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<ConqueryConfig> bootstrap) {
final ObjectMapper confMapper = bootstrap.getObjectMapper();
Expand All @@ -49,7 +55,7 @@ public void initialize(Bootstrap<ConqueryConfig> 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());

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,68 +20,42 @@
@Getter
public class DistributedStandaloneCommand extends ServerCommand<ConqueryConfig> implements StandaloneCommand {

private final Conquery conquery;
private ClusterManager manager;
private final ManagerNode managerNode = new ManagerNode();
private final List<ShardNode> 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<ConqueryConfig> 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);

shardNodes.add(sc);

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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShardNode> getShardNodes();

void run(Bootstrap<ConqueryConfig> bootstrap, Namespace namespace, ConqueryConfig configuration) throws Exception;

Conquery getConquery();

ManagerNode getManagerNode();

Environment getEnvironment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -24,27 +23,11 @@
@Getter
public class SqlStandaloneCommand extends ServerCommand<ConqueryConfig> implements StandaloneCommand {

private final Conquery conquery;
private ManagerNode managerNode = new ManagerNode();
private final ManagerNode managerNode = new ManagerNode();
private DelegateManager<LocalNamespace> 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
Expand All @@ -53,23 +36,14 @@ public List<ShardNode> getShardNodes() {
}

@Override
public void run(Bootstrap<ConqueryConfig> 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);
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
});
Expand Down
Loading