@RequireSystemAccess @POST @Path(RootResource.APPLICATION_ID_PATH) @JSONP @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) public ApiResponse addIndex( @Context UriInfo ui, @PathParam("applicationId") final String applicationIdStr, Map<String, Object> config, @QueryParam("callback") @DefaultValue("callback") String callback) throws Exception { Preconditions.checkNotNull( config, "Payload for config is null, please pass {replicas:int, shards:int} in body"); ApiResponse response = createApiResponse(); if (!config.containsKey("replicas") || !config.containsKey("shards") || !(config.get("replicas") instanceof Integer) || !(config.get("shards") instanceof Integer)) { throw new IllegalArgumentException( "body must contains 'replicas' of type int and 'shards' of type int"); } if (!config.containsKey("indexSuffix")) { throw new IllegalArgumentException("Please add an indexSuffix to your post"); } final UUID appId = UUIDUtils.tryExtractUUID(applicationIdStr); if (appId == null) { throw new IllegalArgumentException("app id was not parsed"); } EntityManager em = emf.getEntityManager(appId); em.addIndex( config.get("indexSuffix").toString(), (int) config.get("shards"), (int) config.get("replicas"), (String) config.get("writeConsistency")); response.setAction("Add index to alias"); return response; }
@RequireSystemAccess @POST @Path("rebuild/" + RootResource.APPLICATION_ID_PATH) @JSONP @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) public ApiResponse rebuildIndexesPut( @PathParam("applicationId") String applicationIdStr, @QueryParam("callback") @DefaultValue("callback") String callback, @QueryParam("delay") @DefaultValue("10") final long delay) throws Exception { logger.info("Rebuilding application {}", applicationIdStr); final UUID appId = UUIDUtils.tryExtractUUID(applicationIdStr); final ReIndexRequestBuilder request = createRequest().withApplicationId(appId); return executeAndCreateResponse(request, callback); }
@RequireSystemAccess @POST @Path("rebuild/" + RootResource.APPLICATION_ID_PATH + "/{collectionName}") @JSONP @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) public ApiResponse rebuildIndexesPost( @PathParam("applicationId") final String applicationIdStr, @PathParam("collectionName") final String collectionName, @QueryParam("reverse") @DefaultValue("false") final Boolean reverse, @QueryParam("callback") @DefaultValue("callback") String callback) throws Exception { logger.info("Rebuilding collection {} in application {}", collectionName, applicationIdStr); final UUID appId = UUIDUtils.tryExtractUUID(applicationIdStr); final ReIndexRequestBuilder request = createRequest().withApplicationId(appId).withCollection(collectionName); return executeAndCreateResponse(request, callback); }