-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Hibernate Search management endpoint
- to reindex either all or subset of indexed entities
- Loading branch information
1 parent
76348f3
commit 795bba0
Showing
20 changed files
with
954 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...arkus/hibernate/search/orm/elasticsearch/deployment/HibernateSearchManagementEnabled.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.deployment; | ||
|
||
import io.quarkus.hibernate.search.orm.elasticsearch.runtime.HibernateSearchElasticsearchBuildTimeConfig; | ||
import io.quarkus.hibernate.search.orm.elasticsearch.runtime.management.HibernateSearchManagementConfig; | ||
|
||
/** | ||
* Supplier that can be used to only run build steps | ||
* if the Hibernate Search extension and its management is enabled. | ||
*/ | ||
public class HibernateSearchManagementEnabled extends HibernateSearchEnabled { | ||
|
||
private final HibernateSearchManagementConfig config; | ||
|
||
HibernateSearchManagementEnabled(HibernateSearchElasticsearchBuildTimeConfig config, | ||
HibernateSearchManagementConfig managementConfig) { | ||
super(config); | ||
this.config = managementConfig; | ||
} | ||
|
||
@Override | ||
public boolean getAsBoolean() { | ||
return super.getAsBoolean() && config.enabled(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ibernate/search/orm/elasticsearch/runtime/management/HibernateSearchManagementConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.runtime.management; | ||
|
||
import io.quarkus.runtime.annotations.ConfigPhase; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
import io.smallrye.config.ConfigMapping; | ||
import io.smallrye.config.WithDefault; | ||
|
||
@ConfigMapping(prefix = "quarkus.hibernate-search-orm.management") | ||
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) | ||
public interface HibernateSearchManagementConfig { | ||
|
||
/** | ||
* Root path for reindexing endpoints. | ||
* This value will be resolved as a path relative to `${quarkus.management.root-path}`. | ||
* | ||
* @asciidoclet | ||
*/ | ||
@WithDefault("hibernate-search/") | ||
String rootPath(); | ||
|
||
/** | ||
* If management interface is turned on the reindexing endpoints will be published under the management interface. | ||
* This property allows to enable this functionality by setting it to ``true`. | ||
* | ||
* @asciidoclet | ||
*/ | ||
@WithDefault("false") | ||
boolean enabled(); | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...bernate/search/orm/elasticsearch/runtime/management/HibernateSearchManagementHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.quarkus.hibernate.search.orm.elasticsearch.runtime.management; | ||
|
||
import java.util.Locale; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ManagedContext; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.http.HttpHeaders; | ||
import io.vertx.core.http.HttpMethod; | ||
import io.vertx.core.http.HttpServerRequest; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public class HibernateSearchManagementHandler implements Handler<RoutingContext> { | ||
|
||
@Override | ||
public void handle(RoutingContext routingContext) { | ||
ManagedContext requestContext = Arc.container().requestContext(); | ||
if (requestContext.isActive()) { | ||
doHandle(routingContext); | ||
} else { | ||
requestContext.activate(); | ||
try { | ||
doHandle(routingContext); | ||
} finally { | ||
requestContext.terminate(); | ||
} | ||
} | ||
} | ||
|
||
private void doHandle(RoutingContext ctx) { | ||
HttpServerRequest request = ctx.request(); | ||
|
||
if (!HttpMethod.POST.equals(request.method())) { | ||
errorResponse(ctx, 406, "Http method [" + request.method().name() + "] is not supported. Use [POST] instead."); | ||
return; | ||
} | ||
|
||
String contentType = request.getHeader(HttpHeaders.CONTENT_TYPE); | ||
if (contentType != null && !contentType.toLowerCase(Locale.ROOT).startsWith("application/json")) { | ||
errorResponse(ctx, 406, "Content type [" + contentType + " is not supported. Use [application/json] instead."); | ||
return; | ||
} | ||
|
||
new HibernateSearchPostRequestProcessor().process(ctx); | ||
} | ||
|
||
private void errorResponse(RoutingContext ctx, int code, String message) { | ||
ctx.response() | ||
.setStatusCode(code) | ||
.setStatusMessage(message) | ||
.end(); | ||
} | ||
} |
Oops, something went wrong.