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

SUP-14526: DB indices rebuilding #1525

Open
wants to merge 1 commit into
base: hotfix-1.6.x
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
Original file line number Diff line number Diff line change
@@ -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<? extends String, ? extends QueryParameter> getRAMLParameters() {
Map<String, QueryParameter> 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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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(",");
}
}