public NodeSelectorReplicationService(Service parent) {
   this.parent = parent;
   super.setHost(parent.getHost());
   super.setSelfLink(
       UriUtils.buildUriPath(parent.getSelfLink(), ServiceHost.SERVICE_URI_SUFFIX_REPLICATION));
   super.setProcessingStage(ProcessingStage.AVAILABLE);
 }
Пример #2
0
  /**
   * This method polls the task status asynchronously until the task completes or fails.
   *
   * @param task Supplies the task object.
   * @param client Supplies the API client object.
   * @param service Supplies the DCP micro-service which is waiting on the task completion.
   * @param queryTaskInterval Supplies the time interval between the task status query.
   * @param callback Supplies the callback to be invoked when the task completes or fails.
   */
  public static void pollTaskAsync(
      final Task task,
      final ApiClient client,
      final Service service,
      final int queryTaskInterval,
      final FutureCallback<Task> callback) {

    switch (task.getState().toUpperCase()) {
      case "QUEUED":
      case "STARTED":
        Runnable runnable =
            new Runnable() {
              @Override
              public void run() {
                try {
                  ServiceUtils.logInfo(
                      service, "Calling GetTask API on with task ID %s", task.getId());

                  client
                      .getTasksApi()
                      .getTaskAsync(
                          task.getId(),
                          new FutureCallback<Task>() {
                            @Override
                            public void onSuccess(Task result) {
                              ServiceUtils.logInfo(
                                  service, "GetTask API call returned task %s", result.toString());
                              try {
                                pollTaskAsync(result, client, service, queryTaskInterval, callback);
                              } catch (Throwable throwable) {
                                callback.onFailure(throwable);
                              }
                            }

                            @Override
                            public void onFailure(Throwable t) {
                              callback.onFailure(t);
                            }
                          });
                } catch (Throwable t) {
                  callback.onFailure(t);
                }
              }
            };

        service.getHost().schedule(runnable, queryTaskInterval, TimeUnit.MILLISECONDS);
        break;
      case "ERROR":
        callback.onFailure(new RuntimeException(ApiUtils.getErrors(task)));
        break;
      case "COMPLETED":
        callback.onSuccess(task);
        break;
      default:
        callback.onFailure(new RuntimeException("Unknown task state: " + task.getState()));
        break;
    }
  }