From 017c74c52cff479490fcc3a9893e0c207aa9cb00 Mon Sep 17 00:00:00 2001 From: Serhii Plyhun Date: Tue, 6 Dec 2022 13:57:17 +0100 Subject: [PATCH] SUP-14526: DB indices rebuilding --- .../impl/DatabaseReindexParametersImpl.java | 32 +++++++++++++++ .../core/endpoint/admin/AdminEndpoint.java | 11 +++++ .../parameter/DatabaseReindexParameters.java | 41 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 common/src/main/java/com/gentics/mesh/parameter/impl/DatabaseReindexParametersImpl.java create mode 100644 rest-model/src/main/java/com/gentics/mesh/parameter/DatabaseReindexParameters.java diff --git a/common/src/main/java/com/gentics/mesh/parameter/impl/DatabaseReindexParametersImpl.java b/common/src/main/java/com/gentics/mesh/parameter/impl/DatabaseReindexParametersImpl.java new file mode 100644 index 0000000000..73f8664b4f --- /dev/null +++ b/common/src/main/java/com/gentics/mesh/parameter/impl/DatabaseReindexParametersImpl.java @@ -0,0 +1,32 @@ +package com.gentics.mesh.parameter.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.raml.model.ParamType; +import org.raml.model.parameter.QueryParameter; + +import com.gentics.mesh.parameter.AbstractParameters; +import com.gentics.mesh.parameter.DatabaseReindexParameters; + +public class DatabaseReindexParametersImpl extends AbstractParameters implements DatabaseReindexParameters { + + @Override + public Map getRAMLParameters() { + Map parameters = new HashMap<>(); + + QueryParameter consistencyCheck = new QueryParameter(); + consistencyCheck.setDescription("Specify a comma separated list of database indices, that have to be rebuilt, leaving all other indices untouched."); + consistencyCheck.setExample("e.has_field_container_field,e.has_field_container_branch_type_lang"); + consistencyCheck.setRequired(false); + consistencyCheck.setType(ParamType.STRING); + parameters.put(LIMIT_TO_PARAMETER_KEY, consistencyCheck); + + return parameters; + } + + @Override + public String getName() { + return "Database reindex parameters"; + } +} diff --git a/core/src/main/java/com/gentics/mesh/core/endpoint/admin/AdminEndpoint.java b/core/src/main/java/com/gentics/mesh/core/endpoint/admin/AdminEndpoint.java index a5a1dc5a8d..938763a949 100644 --- a/core/src/main/java/com/gentics/mesh/core/endpoint/admin/AdminEndpoint.java +++ b/core/src/main/java/com/gentics/mesh/core/endpoint/admin/AdminEndpoint.java @@ -33,6 +33,7 @@ import com.gentics.mesh.core.endpoint.admin.plugin.PluginHandler; import com.gentics.mesh.core.verticle.handler.HandlerUtilities; import com.gentics.mesh.parameter.impl.BackupParametersImpl; +import com.gentics.mesh.parameter.impl.DatabaseReindexParametersImpl; import com.gentics.mesh.parameter.impl.JobParametersImpl; import com.gentics.mesh.rest.InternalEndpointRoute; import com.gentics.mesh.router.route.AbstractInternalEndpoint; @@ -107,6 +108,16 @@ public void registerEndPoints() { addShutdownHandler(); addCoordinatorHandler(); addCacheHandler(); + addDatabaseManagementHandler(); + } + + private void addDatabaseManagementHandler() { + InternalEndpointRoute dbReindexEndpoint = createRoute(); + dbReindexEndpoint.path("/db/reindex"); + dbReindexEndpoint.method(POST); + dbReindexEndpoint.description("Recreate database indices, all or mentioned in the query parameter."); + dbReindexEndpoint.produces(APPLICATION_JSON); + dbReindexEndpoint.addQueryParameters(DatabaseReindexParametersImpl.class); } private void addSecurityLogger() { diff --git a/rest-model/src/main/java/com/gentics/mesh/parameter/DatabaseReindexParameters.java b/rest-model/src/main/java/com/gentics/mesh/parameter/DatabaseReindexParameters.java new file mode 100644 index 0000000000..0ee5e11936 --- /dev/null +++ b/rest-model/src/main/java/com/gentics/mesh/parameter/DatabaseReindexParameters.java @@ -0,0 +1,41 @@ +package com.gentics.mesh.parameter; + +import java.util.Arrays; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public interface DatabaseReindexParameters extends ParameterProvider { + + public static final String LIMIT_TO_PARAMETER_KEY = "limitTo"; + + /** + * Set the index names the rebuild should be limited to. + * + * @param flag + * @return Fluent API + */ + default DatabaseReindexParameters setLimitTo(String[] indexNames) { + return setLimitTo(Arrays.stream(indexNames)); + } + + /** + * Set the index names the rebuild should be limited to. + * + * @param flag + * @return Fluent API + */ + default DatabaseReindexParameters setLimitTo(Stream indexNames) { + setParameter(LIMIT_TO_PARAMETER_KEY, indexNames.collect(Collectors.joining(","))); + return this; + } + + /** + * Check if there are indices to limite the rebuild to.. + * + * @return + */ + default String[] isConsistencyCheck() { + String stored = getParameter(LIMIT_TO_PARAMETER_KEY); + return stored == null ? null : stored.split(","); + } +}