Esempio n. 1
0
  @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;
  }
Esempio n. 2
0
  @RequireSystemAccess
  @GET
  @Path("rebuild/{jobId}")
  @JSONP
  @Produces({MediaType.APPLICATION_JSON, "application/javascript"})
  public ApiResponse rebuildIndexesGet(
      @PathParam("jobId") String jobId,
      @QueryParam("callback") @DefaultValue("callback") String callback)
      throws Exception {
    logger.info("Getting status for index jobs");

    Preconditions.checkNotNull(jobId, "query param jobId must not be null");

    ReIndexService.ReIndexStatus status = getReIndexService().getStatus(jobId);

    final ApiResponse response = createApiResponse();

    response.setAction("rebuild indexes");
    response.setProperty("jobId", status.getJobId());
    response.setProperty("status", status.getStatus());
    response.setProperty("lastUpdatedEpoch", status.getLastUpdated());
    response.setProperty("numberQueued", status.getNumberProcessed());
    response.setSuccess();

    return response;
  }
Esempio n. 3
0
  /** Execute the request and return the response. */
  private ApiResponse executeAndCreateResponse(
      final ReIndexRequestBuilder request, final String callback) {

    final ReIndexService.ReIndexStatus status = getReIndexService().rebuildIndex(request);

    final ApiResponse response = createApiResponse();

    response.setAction("rebuild indexes");
    response.setProperty("jobId", status.getJobId());
    response.setProperty("status", status.getStatus());
    response.setProperty("lastUpdatedEpoch", status.getLastUpdated());
    response.setProperty("numberQueued", status.getNumberProcessed());
    response.setSuccess();

    return response;
  }