Pushing Consolidation from an HTTPS Endpoint

This page explains how to make a consolidation endpoint call, and how to push JSON event objects.


Before you begin: Prepare the ingestion of data through an HTTPS endpoint. For more information, see Preparing an Ingestion with an HTTPS Endpoint
See Also
Preparing an Ingestion with an HTTPS Endpoint
Calling an HTTPS Endpoint with a Java Client
Consolidating Data
Pushing JSON Objects from an HTTPS Endpoint
  1. For the consolidation endpoint call, the URL must have the following format:

    http://<localhost>/data-factory/resources/v1/indexunit/<id>/consolidate

    Where <id>: is the id of the index unit in which you want to push data.

    Tip: To get the exact URL, go to the Index Unit > Ingestion. Replace ingest by consolidate at the end of the URL.

  2. Use the CLM agent ID and password for the CLM authentication.

    For more information, see Deploy a CLM Agent.

  3. Make calls to the consolidation endpoint.

    Specify the query in the HTTP request body. This call starts an asynchronous data consolidation process that executes the input data query and ingests events generated by the selected export outputs.

    • The consolidation endpoint takes as input the target storage resource uuid.
    • The data consolidation query execution is single-threaded.
    • The HTTP request returns once the job is validated, and registered in the database. Data Factory Studio then submits it asynchronously.
    • The actual query execution and ingestion happen asynchronously.
    • The response provides a jobId, which uniquely identifies the submitted job. You can use the jobId to retrieve the job's status or cancel the job.
    • If the query uses resources coming from other Data Workspaces, you must declare these Data Workspaces as dependencies of the Data Workspace containing the target index unit.
    • When you delete the target storage, all associated consolidation queries are canceled.

    The consolidation call has the following limitations:

    • The data consolidation query has a 30-minute timeout.
    • A maximum of 5 concurrent workers can perform consolidations in Data Factory Studio.
    • If the worker pool is full and too many consolidation requests are pending, the request is rejected with a 429 (Too Many Requests) response.

    Optionally you can define a consolidationId parameter in the request body. This identifier represents a logical consolidation scope (for example, a specific business process). If another consolidation job is already running with the same consolidationId, it is canceled automatically before the new job is submitted. This mechanism ensures that at most one active job per consolidationId is processed at a given time.

Result:

The following Java code sample shows how you can use the consolidation endpoint API.

// Retrieve the target index unit matching the filter criteria
  IdCard targetIndex = apis.getStorageApi()
    .getFilteredStorages(new ListStorageFilter()
      .workspaceId("dw-global-000000-default")
      .nameFilter("targetIndexUnit"))
    .getCards()
    .stream()
    .findFirst()
    .orElseThrow(() -> new RuntimeException("Target index unit not found"));         
          
// Get data query from a json resource file
  InputStream inputStream = Example.class.getResourceAsStream("/queries/data-query.json");
  JsonNode dataQueryNode = objectMapper.readTree(inputStream);
          
// Register the consolidation job for the target index
  DataConsolidationSubmit jobSubmit = apis.getIndexUnitApi().consolidate(
    targetIndex.getResourceUUID(),
    new DataConsolidationRequest()
      .outputs(List.of("output")) // Specify output options
      .query(new DataQueryWrapper().value(dataQueryNode)) // Query details
      .request(new QueryExecutionRequest()
        .addParametersItem(new ExpressionRequestParameter()
          .expression("*") // Expression to execute
          .dataQueryParameterName("param")))); // Query parameter
          
// Get the job ID from the submission response
  String jobId = jobSubmit.getJobId();
  boolean isRunning = true;
  int backoff = 1000; // Milliseconds to wait between status checks
  int sleep = 0;
          
// Polling loop to check if the job status is not PENDING or RUNNING
   while (isRunning) {
     sleep += backoff;
     Thread.sleep(sleep); // Sleep for the increasing backoff time
          
     // Fetch the current status of the consolidation job
       DataConsolidationStatus status = apis.getIndexUnitApi().getConsolidationStatus(
       targetIndex.getResourceUUID(), jobId);
          
     // Job is still running if the status is PENDING or RUNNING
       isRunning = status.getStatus() == DataConsolidationStatus.StatusEnum.PENDING ||
                   status.getStatus() == DataConsolidationStatus.StatusEnum.RUNNING;
   }
          
// Final status check after the job finishes
  DataConsolidationStatus finalStatus = apis.getIndexUnitApi().getConsolidationStatus(
    targetIndex.getResourceUUID(), jobId);
          
// Handle the job's final status
  switch (finalStatus.getStatus()) {
    case PENDING:
      // Job is still pending, handle accordingly
      log.info("Consolidation job is still pending...");
      break;
    case RUNNING:
      // Job is still running, handle accordingly
      log.info("Consolidation job is still running...");
      break;
    case COMPLETED:
      // Job completed successfully
      DataConsolidationSuccessReport success = finalStatus.getReport().getSuccess();
      log.info("Consolidation successfully ingested {} events", success.getNbEvents());
      break;
    case FAILED:
      // Job failed, handle the failure report
      // Depending on the status code, it can be a good idea to perform a retry of the consolidation. For example, if the status code is 5xx. 
      DataConsolidationFailureReport failure = finalStatus.getReport().getFailure();
      log.error("Consolidation failed with status code {} and message {}", failure.getStatusCode(), failure.getMessage());
      break;
    case CANCELLED:
      // Job was cancelled
      log.warn("Consolidation job was cancelled");
      break;
      default:
      log.error("Unexpected consolidation job status: {}", finalStatus.getStatus());
  }
          
// Wait for the async ingestion process to complete
  sleep = 0;
  boolean isIngesting = true;
          
// Polling loop to check if the ingestion is still pending
  while (isIngesting) {
    sleep += backoff;
    Thread.sleep(sleep); // Sleep for the increasing backoff time
          
// Check the number of pending actions for the index unit
  isIngesting = apis.getIndexUnitApi()
    .getIndexUnitPendingActions(targetIndex.getResourceUUID())
    .getNbActions() > 0; // Continue if there are pending actions
 }
          
  log.info("Ingestion process completed.");