public void createApp()

in java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClient.java [69:162]


  public void createApp(
      String appName,
      int partitionCount,
      int replicaCount,
      Map<String, String> envs,
      long timeoutMs,
      boolean successIfExist)
      throws PException {
    if (partitionCount < 1) {
      throw new PException(
          new IllegalArgumentException("createApp failed: partitionCount should >= 1!"));
    }

    if (replicaCount < 1) {
      throw new PException(
          new IllegalArgumentException("createApp failed: replicaCount should >= 1!"));
    }

    int i = 0;
    for (; i < appName.length(); i++) {
      char c = appName.charAt(i);
      if (!((c >= 'a' && c <= 'z')
          || (c >= 'A' && c <= 'Z')
          || (c >= '0' && c <= '9')
          || c == '_'
          || c == '.'
          || c == ':')) {
        break;
      }
    }

    if (appName.isEmpty() || i < appName.length()) {
      throw new PException(
          new IllegalArgumentException(
              String.format("createApp  failed: invalid appName: %s", appName)));
    }

    if (timeoutMs <= 0) {
      throw new PException(
          new IllegalArgumentException(
              String.format("createApp  failed: invalid timeoutMs: %d", timeoutMs)));
    }

    long startTime = System.currentTimeMillis();

    create_app_options options = new create_app_options();
    options.setPartition_count(partitionCount);
    options.setReplica_count(replicaCount);
    options.setSuccess_if_exist(successIfExist);
    options.setApp_type(APP_TYPE);
    options.setEnvs(envs);
    options.setIs_stateful(true);

    configuration_create_app_request request = new configuration_create_app_request();
    request.setApp_name(appName);
    request.setOptions(options);

    create_app_operator app_operator = new create_app_operator(appName, request);
    error_code.error_types error = this.meta.operate(app_operator, META_RETRY_MIN_COUNT);
    if (error != error_code.error_types.ERR_OK) {
      throw new PException(
          String.format(
              "Create app:%s failed, partitionCount: %d, replicaCount: %s, error:%s.",
              appName, partitionCount, replicaCount, error.toString()));
    }

    long remainDuration = timeoutMs - (System.currentTimeMillis() - startTime);
    if (remainDuration <= 0) {
      remainDuration = 8;
    }

    boolean isHealthy = false;
    while (remainDuration > 0) {
      isHealthy = this.isAppHealthy(appName, replicaCount);
      if (isHealthy) {
        break;
      }

      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        continue;
      }

      remainDuration = timeoutMs - (System.currentTimeMillis() - startTime);
    }

    if (!isHealthy) {
      throw new PException(
          String.format(
              "The newly created app:%s is not fully healthy now, but the interface duration expires 'timeoutMs', partitionCount: %d, replicaCount: %s.",
              appName, partitionCount, replicaCount));
    }
  }