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

DB admin REST endpoint. DB start/stop. #1499

Open
wants to merge 5 commits into
base: dev
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
1 change: 1 addition & 0 deletions common/src/main/resources/i18n/translations_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ error=Fehler
error_internal=Interner Fehler aufgetreten.
error_not_authorized=Sie sind nicht berechtigt um auf die angefragte Resource zuzugreifen.
error_admin_permission_required=Es werden Administrator Rechte benötigt.
error_local_client_only=Zugriff nur für lokale Clienten erlaubt.
error_illegal_admin_deletion=Man darf keine Admin-Entities löschen.
error_request_parameter_missing=Parameter "{0}" nicht vorhanden.
error_parse_request_json_error=Konnte Request JSON nicht parsen.
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/i18n/translations_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ error=Error
error_internal=Internal error occurred.
error_not_authorized=You are not authorized to access the requested resource.
error_admin_permission_required=Administration permissions are required.
error_local_client_only=Access for the local clients only.
error_request_parameter_missing=Request parameter "{0}" is missing.
error_parse_request_json_error=Could not parse request JSON.
error_name_must_be_set=The name must be set.
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/i18n/translations_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ error=错误
error_internal=发生内部错误。
error_not_authorized=你无权访问所请求的资源。
error_admin_permission_required=需要管理权限。
error_local_client_only=仅限本地客户端访问。
error_request_parameter_missing=请求参数“{0}”缺失。
error_parse_request_json_error=无法解析请求JSON。
error_name_must_be_set=必须设置名称。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public abstract class AbstractBootstrapInitializer implements BootstrapInitializ
public Lazy<IndexHandlerRegistryImpl> indexHandlerRegistry;

@Inject
public Lazy<CoreVerticleLoader> loader;
public Lazy<VerticleLoader> loader;

@Inject
public HighLevelChangelogSystem highlevelChangelogSystem;
Expand Down Expand Up @@ -614,7 +614,6 @@ private void handleLocalData(PostProcessFlags flags, MeshOptions configuration,
}

registerEventHandlers();

}

/**
Expand Down
41 changes: 17 additions & 24 deletions core/src/main/java/com/gentics/mesh/cli/CoreVerticleLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;

import com.gentics.mesh.core.verticle.job.JobWorkerVerticleImpl;
import com.gentics.mesh.etc.config.MeshOptions;
Expand All @@ -24,8 +23,7 @@
/**
* Central loader for core verticles. Needed verticles will be listed and deployed here.
*/
@Singleton
public class CoreVerticleLoader {
public abstract class CoreVerticleLoader implements VerticleLoader {

private static Logger log = LoggerFactory.getLogger(CoreVerticleLoader.class);

Expand All @@ -45,42 +43,41 @@ public class CoreVerticleLoader {
@Inject
public MeshOptions meshOptions;

private final Vertx rxVertx;
private String searchVerticleId;
protected final Vertx rxVertx;
protected String searchVerticleId;

@Inject
public CoreVerticleLoader(Vertx rxVertx) {
this.rxVertx = rxVertx;
}

private JsonObject defaultConfig;

/**
* Load verticles that are configured within the mesh configuration.
*
* @param initialProjects
*/
@Override
public Completable loadVerticles(List<String> initialProjects) {
defaultConfig = new JsonObject();
defaultConfig.put("port", meshOptions.getHttpServerOptions().getPort());
defaultConfig.put("host", meshOptions.getHttpServerOptions().getHost());
defaultConfig.put("initialProjects", initialProjects);

return deployAll();
}

protected Completable deployAll() {
return Completable.mergeArray(
deployRestVerticle(),
deployMonitoringVerticle(),
deployJobWorkerVerticle(),
deploySearchVerticle());
deployRestVerticle(),
deployMonitoringVerticle(),
deployJobWorkerVerticle(),
deploySearchVerticle());
}

private Completable deployRestVerticle() {
protected Completable deployRestVerticle() {
return rxVertx.rxDeployVerticle(restVerticle::get, new DeploymentOptions()
.setConfig(defaultConfig)
.setInstances(meshOptions.getHttpServerOptions().getVerticleAmount()))
.ignoreElement();
}

private Completable deployMonitoringVerticle() {
protected Completable deployMonitoringVerticle() {
if (meshOptions.getMonitoringOptions() != null && meshOptions.getMonitoringOptions().isEnabled()) {
return rxVertx.rxDeployVerticle(monitoringServerVerticle::get, new DeploymentOptions()
.setInstances(1))
Expand All @@ -90,15 +87,15 @@ private Completable deployMonitoringVerticle() {
}
}

private Completable deployJobWorkerVerticle() {
protected Completable deployJobWorkerVerticle() {
// the verticle is not deployed as worker verticle (any more). See comments of AbstractJobVerticle for details
return rxVertx.rxDeployVerticle(jobWorkerVerticle, new DeploymentOptions()
.setInstances(1)
.setWorker(false))
.ignoreElement();
}

private Completable deploySearchVerticle() {
protected Completable deploySearchVerticle() {
// Only deploy search sync verticle if we actually have a configured ES
ElasticSearchOptions searchOptions = meshOptions.getSearchOptions();
if (searchOptions != null && searchOptions.getUrl() != null) {
Expand All @@ -114,11 +111,7 @@ private Completable deploySearchVerticle() {
}
}

/**
* Dedeploy the serarch verticle.
*
* @return
*/
@Override
public Completable redeploySearchVerticle() {
return RxUtil.fromNullable(searchVerticleId)
.flatMapCompletable(rxVertx::rxUndeploy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import com.orientechnologies.orient.core.OConstants;
import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.exception.OSchemaException;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.index.OIndexCursor;
Expand Down Expand Up @@ -194,6 +195,7 @@ public void stop() {

if (txProvider != null) {
txProvider.close();
txProvider = null;
}
}

Expand Down Expand Up @@ -317,6 +319,7 @@ public void closeConnectionPool() {
public void shutdown() {
stopDiskQuotaChecker();
Orient.instance().shutdown();
ODatabaseDocumentTx.closeAll();
}

@Override
Expand Down Expand Up @@ -750,6 +753,15 @@ public boolean isReadOnly(boolean logError) {
}
}

/**
* Check if the database is currently running.
*
* @return
*/
public boolean isRunning() {
return Orient.instance().isActive();
}

/**
* Start the disk quota checker, if configured to do so and not started before
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ public void stop() {
if (server != null) {
log.info("Stopping OrientDB Server");
server.shutdown();
server = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void open(String name) {

@Override
public void close() {
context.close();
}

@Override
Expand Down
28 changes: 28 additions & 0 deletions mdm/api/src/main/java/com/gentics/mesh/cli/VerticleLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.gentics.mesh.cli;

import java.util.List;

import io.reactivex.Completable;

/**
* Serving Verticle loader
*
* @author plyhun
*
*/
public interface VerticleLoader {

/**
* Load verticles that are configured within the mesh configuration.
*
* @param initialProjects
*/
Completable loadVerticles(List<String> initialProjects);

/**
* Redeploy the serarch verticle.
*
* @return
*/
Completable redeploySearchVerticle();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.gentics.mesh.etc.config;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.gentics.mesh.etc.config.env.EnvironmentVariable;
import com.gentics.mesh.etc.config.env.Option;

public class AdministrationOptions implements Option {

public static final String MESH_DB_ADMIN_HTTP_PORT_ENV = "MESH_DB_ADMIN_HTTP_PORT";
public static final String MESH_DB_ADMIN_HTTP_HOST_ENV = "MESH_DB_ADMIN_HTTP_HOST";
public static final String MESH_DB_ADMIN_ENABLED_ENV = "MESH_DB_ADMIN_ENABLED";
public static final String MESH_DB_ADMIN_LOCAL_ONLY_ENV = "MESH_DB_ADMIN_LOCAL_ONLY";

public static final boolean DEFAULT_DB_ADMIN_ENABLED = false;
public static final boolean DEFAULT_DB_ADMIN_LOCAL_ONLY = true;
public static final int DEFAULT_DB_ADMIN_HTTP_PORT = 8082;
public static final String DEFAULT_DB_ADMIN_HTTP_HOST = "127.0.0.1";

@JsonProperty(required = false)
@JsonPropertyDescription("Enable or disable the database administration system. Default is: " + DEFAULT_DB_ADMIN_ENABLED)
@EnvironmentVariable(name = MESH_DB_ADMIN_ENABLED_ENV, description = "Override the configured database administration enabled flag.")
private boolean enabled = DEFAULT_DB_ADMIN_ENABLED;

@JsonProperty(required = false)
@JsonPropertyDescription("Configure the Gentics Mesh database administration HTTP server port. Default is: " + DEFAULT_DB_ADMIN_HTTP_PORT)
@EnvironmentVariable(name = MESH_DB_ADMIN_HTTP_PORT_ENV, description = "Override the configured database administration server http port.")
private int port = DEFAULT_DB_ADMIN_HTTP_PORT;

@JsonProperty(required = false)
@JsonPropertyDescription("Configure the Gentics Mesh database administration HTTP server host to bind to. Default is: " + DEFAULT_DB_ADMIN_HTTP_HOST)
@EnvironmentVariable(name = MESH_DB_ADMIN_HTTP_HOST_ENV, description = "Override the configured database administration http server host which is used to bind to.")
private String host = DEFAULT_DB_ADMIN_HTTP_HOST;

@JsonProperty(required = false)
@JsonPropertyDescription("Whether to allow administration connections from the same ip address. Default is: " + DEFAULT_DB_ADMIN_LOCAL_ONLY)
@EnvironmentVariable(name = MESH_DB_ADMIN_LOCAL_ONLY_ENV, description = "Override the configured database administration local-only flag.")
private boolean localOnly = DEFAULT_DB_ADMIN_LOCAL_ONLY;

public boolean isEnabled() {
return enabled;
}

public AdministrationOptions setEnabled(boolean enabled) {
this.enabled = enabled;
return this;
}

public int getPort() {
return port;
}

public AdministrationOptions setPort(int port) {
this.port = port;
return this;
}

public String getHost() {
return host;
}

public AdministrationOptions setHost(String host) {
this.host = host;
return this;
}

public boolean isLocalOnly() {
return localOnly;
}

public void setLocalOnly(boolean localOnly) {
this.localOnly = localOnly;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public class GraphStorageOptions implements Option {
@JsonPropertyDescription("Options for the disk quota check")
private DiskQuotaOptions diskQuotaOptions = new DiskQuotaOptions();

@JsonProperty("administration")
@JsonPropertyDescription("Options for the database administration")
private AdministrationOptions administrationOptions = new AdministrationOptions();

public String getDirectory() {
return directory;
}
Expand Down Expand Up @@ -261,4 +265,12 @@ public void validate(MeshOptions meshOptions) {
getDiskQuotaOptions().validate(meshOptions);
}

public AdministrationOptions getAdministrationOptions() {
return administrationOptions;
}

public void setAdministrationOptions(AdministrationOptions administrationOptions) {
this.administrationOptions = administrationOptions;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.gentics.mesh.cli;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;

import com.gentics.mesh.dbadmin.DatabaseAdminServerVerticle;
import com.gentics.mesh.etc.config.OrientDBMeshOptions;

import io.reactivex.Completable;
import io.reactivex.CompletableSource;
import io.vertx.core.DeploymentOptions;
import io.vertx.reactivex.core.Vertx;

@Singleton
public class OrientDBCoreVerticleLoader extends CoreVerticleLoader {

@Inject
OrientDBMeshOptions meshOptions;

@Inject
public Provider<DatabaseAdminServerVerticle> dbAdminServerVerticle;

@Inject
public OrientDBCoreVerticleLoader(Vertx rxVertx) {
super(rxVertx);
}

@Override
protected Completable deployAll() {
return Completable.mergeArray(
deployRestVerticle(),
deployMonitoringVerticle(),
deployJobWorkerVerticle(),
deploySearchVerticle(),
deployDatabaseAdminVerticle());
}

protected CompletableSource deployDatabaseAdminVerticle() {
if (meshOptions.getStorageOptions().getAdministrationOptions() != null && meshOptions.getStorageOptions().getAdministrationOptions().isEnabled()) {
return rxVertx.rxDeployVerticle(dbAdminServerVerticle::get, new DeploymentOptions()
.setInstances(1))
.ignoreElement();
} else {
return Completable.complete();
}
}
}
Loading