From 53e883d2c432123da171275d049d8bca67e10b1f Mon Sep 17 00:00:00 2001 From: Alex Ormenisan Date: Thu, 21 Sep 2023 17:35:21 +0300 Subject: [PATCH] [HWORKS-547][APPEND] allow AGENT user to trigger reindex (#1561) --- .../io/hops/hopsworks/api/admin/SystemAdminService.java | 2 ++ .../commands/featurestore/search/SearchFSReindexer.java | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hopsworks-api/src/main/java/io/hops/hopsworks/api/admin/SystemAdminService.java b/hopsworks-api/src/main/java/io/hops/hopsworks/api/admin/SystemAdminService.java index e383f3daa7..bc1504e671 100644 --- a/hopsworks-api/src/main/java/io/hops/hopsworks/api/admin/SystemAdminService.java +++ b/hopsworks-api/src/main/java/io/hops/hopsworks/api/admin/SystemAdminService.java @@ -232,6 +232,7 @@ public Response getElasticAdminToken(@Context SecurityContext sc) throws OpenSea @GET @Path("/search/featurestore/status") @Produces(MediaType.APPLICATION_JSON) + @JWTRequired(acceptedTokens={Audience.API}, allowedUserRoles={"HOPS_ADMIN", "AGENT"}) public Response statusSearchFeatureStore(@Context SecurityContext sc, @Context HttpServletRequest req) { SearchFSCommandStatus status = searchFSReindexer.status(); return Response.ok().entity(status).build(); @@ -239,6 +240,7 @@ public Response statusSearchFeatureStore(@Context SecurityContext sc, @Context H @POST @Path("/search/featurestore/reindex") + @JWTRequired(acceptedTokens={Audience.API}, allowedUserRoles={"HOPS_ADMIN", "AGENT"}) public Response reindexSearchFeatureStoreIndex(@Context SecurityContext sc, @Context HttpServletRequest req) throws OpenSearchException, FeaturestoreException, CommandException { searchFSReindexer.reindex(); diff --git a/hopsworks-common/src/main/java/io/hops/hopsworks/common/commands/featurestore/search/SearchFSReindexer.java b/hopsworks-common/src/main/java/io/hops/hopsworks/common/commands/featurestore/search/SearchFSReindexer.java index 75a7b7ebd7..fd61fe4cf9 100644 --- a/hopsworks-common/src/main/java/io/hops/hopsworks/common/commands/featurestore/search/SearchFSReindexer.java +++ b/hopsworks-common/src/main/java/io/hops/hopsworks/common/commands/featurestore/search/SearchFSReindexer.java @@ -74,7 +74,14 @@ public void reindex() throws OpenSearchException, FeaturestoreException, Command throw new CommandException(RESTCodes.CommandErrorCode.INVALID_SQL_QUERY, Level.INFO, msg); } LOGGER.info("reindexing featurestore search"); - searchClient.mngIndexDelete(Settings.FEATURESTORE_INDEX); + try { + searchClient.mngIndexDelete(Settings.FEATURESTORE_INDEX); + } catch(OpenSearchException e) { + if(e.getErrorCode().equals(RESTCodes.OpenSearchErrorCode.OPENSEARCH_INDEX_NOT_FOUND)) { + //index doesn't exist, nothing to delete + return; + } + } for (Featurestore featureStore : featurestoreFacade.findAll()) { reindex(featureStore); }