You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by la...@apache.org on 2022/12/22 05:18:52 UTC

[incubator-pegasus] branch master updated: feat: expose parameter success_if_exist for interface create_app (#1148)

This is an automated email from the ASF dual-hosted git repository.

laiyingchun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new cb99a6b70 feat: expose parameter success_if_exist for interface create_app (#1148)
cb99a6b70 is described below

commit cb99a6b7099aed192452dbe027ae4f3545181456
Author: liguohao <48...@users.noreply.github.com>
AuthorDate: Thu Dec 22 13:18:46 2022 +0800

    feat: expose parameter success_if_exist for interface create_app (#1148)
---
 go-client/admin/client.go                                |  9 +++++++--
 .../org/apache/pegasus/client/PegasusAdminClient.java    | 16 ++++++++++++++--
 .../pegasus/client/PegasusAdminClientInterface.java      | 10 ++++++++++
 src/client/replication_ddl_client.cpp                    |  5 +++--
 src/client/replication_ddl_client.h                      |  3 ++-
 src/shell/commands/table_management.cpp                  | 10 ++++++++--
 src/shell/main.cpp                                       |  2 +-
 7 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/go-client/admin/client.go b/go-client/admin/client.go
index 5d3c044ee..d5848560f 100644
--- a/go-client/admin/client.go
+++ b/go-client/admin/client.go
@@ -33,7 +33,7 @@ import (
 // Client provides the administration API to a specific cluster.
 // Remember only the superusers configured to the cluster have the admin priviledges.
 type Client interface {
-	CreateTable(ctx context.Context, tableName string, partitionCount int) error
+	CreateTable(ctx context.Context, tableName string, partitionCount int, successIfExist_optional ...bool) error
 
 	DropTable(ctx context.Context, tableName string) error
 
@@ -89,12 +89,17 @@ func (c *rpcBasedClient) waitTableReady(ctx context.Context, tableName string, p
 	return nil
 }
 
-func (c *rpcBasedClient) CreateTable(ctx context.Context, tableName string, partitionCount int) error {
+func (c *rpcBasedClient) CreateTable(ctx context.Context, tableName string, partitionCount int, successIfExist_optional ...bool) error {
+	successIfExist := true
+	if len(successIfExist_optional) > 0 {
+		successIfExist = successIfExist_optional[0]
+	}
 	_, err := c.metaManager.CreateApp(ctx, &admin.ConfigurationCreateAppRequest{
 		AppName: tableName,
 		Options: &admin.CreateAppOptions{
 			PartitionCount: int32(partitionCount),
 			ReplicaCount:   3,
+			SuccessIfExist: successIfExist,
 			AppType:        "pegasus",
 			Envs:           make(map[string]string),
 			IsStateful:     true,
diff --git a/java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClient.java b/java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClient.java
index 2f869d21d..dc1636cf4 100644
--- a/java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClient.java
+++ b/java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClient.java
@@ -69,7 +69,8 @@ public class PegasusAdminClient extends PegasusAbstractClient
       int partitionCount,
       int replicaCount,
       Map<String, String> envs,
-      long timeoutMs)
+      long timeoutMs,
+      boolean successIfExist)
       throws PException {
     if (partitionCount < 1) {
       throw new PException(
@@ -111,7 +112,7 @@ public class PegasusAdminClient extends PegasusAbstractClient
     create_app_options options = new create_app_options();
     options.setPartition_count(partitionCount);
     options.setReplica_count(replicaCount);
-    options.setSuccess_if_exist(true);
+    options.setSuccess_if_exist(successIfExist);
     options.setApp_type(APP_TYPE);
     options.setEnvs(envs);
     options.setIs_stateful(true);
@@ -158,6 +159,17 @@ public class PegasusAdminClient extends PegasusAbstractClient
     }
   }
 
+  @Override
+  public void createApp(
+      String appName,
+      int partitionCount,
+      int replicaCount,
+      Map<String, String> envs,
+      long timeoutMs)
+      throws PException {
+    this.createApp(appName, partitionCount, replicaCount, envs, timeoutMs, true);
+  }
+
   @Override
   public boolean isAppHealthy(String appName, int replicaCount) throws PException {
     if (replicaCount < 1) {
diff --git a/java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClientInterface.java b/java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClientInterface.java
index ac76af1d0..bfa1e5bf1 100644
--- a/java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClientInterface.java
+++ b/java-client/src/main/java/org/apache/pegasus/client/PegasusAdminClientInterface.java
@@ -34,10 +34,20 @@ public interface PegasusAdminClientInterface extends Closeable {
    * @param envs Environment variables of pegasus app, you can see the supported envs in the website
    *     : https://pegasus.apache.org/administration/table-env
    * @param timeoutMs The timeout of the interface, milli-seconds
+   * @param successIfExist whether return success if app exist
    * @throws PException if rpc to the pegasus server cause timeout or other error happens in the
    *     server side, or the newly created app is not fully healthy when the 'timeoutMs' has
    *     elapsed, the interface will throw exception
    */
+  public void createApp(
+      String appName,
+      int partitionCount,
+      int replicaCount,
+      Map<String, String> envs,
+      long timeoutMs,
+      boolean successIfExist)
+      throws PException;
+
   public void createApp(
       String appName,
       int partitionCount,
diff --git a/src/client/replication_ddl_client.cpp b/src/client/replication_ddl_client.cpp
index 02fb7175f..63d187ee2 100644
--- a/src/client/replication_ddl_client.cpp
+++ b/src/client/replication_ddl_client.cpp
@@ -134,7 +134,8 @@ dsn::error_code replication_ddl_client::create_app(const std::string &app_name,
                                                    int partition_count,
                                                    int replica_count,
                                                    const std::map<std::string, std::string> &envs,
-                                                   bool is_stateless)
+                                                   bool is_stateless,
+                                                   bool success_if_exist)
 {
     if (partition_count < 1) {
         std::cout << "create app " << app_name << " failed: partition_count should >= 1"
@@ -167,7 +168,7 @@ dsn::error_code replication_ddl_client::create_app(const std::string &app_name,
     req->app_name = app_name;
     req->options.partition_count = partition_count;
     req->options.replica_count = replica_count;
-    req->options.success_if_exist = true;
+    req->options.success_if_exist = success_if_exist;
     req->options.app_type = app_type;
     req->options.envs = envs;
     req->options.is_stateful = !is_stateless;
diff --git a/src/client/replication_ddl_client.h b/src/client/replication_ddl_client.h
index f3350f5fe..9aa1d32b3 100644
--- a/src/client/replication_ddl_client.h
+++ b/src/client/replication_ddl_client.h
@@ -65,7 +65,8 @@ public:
                                int partition_count,
                                int replica_count,
                                const std::map<std::string, std::string> &envs,
-                               bool is_stateless);
+                               bool is_stateless,
+                               bool success_if_exist = true);
 
     // reserve_seconds == 0 means use default value in configuration 'hold_seconds_for_dropped_app'
     dsn::error_code drop_app(const std::string &app_name, int reserve_seconds);
diff --git a/src/shell/commands/table_management.cpp b/src/shell/commands/table_management.cpp
index b9a6871e8..3ccfa4927 100644
--- a/src/shell/commands/table_management.cpp
+++ b/src/shell/commands/table_management.cpp
@@ -631,6 +631,7 @@ bool create_app(command_executor *e, shell_context *sc, arguments args)
 {
     static struct option long_options[] = {{"partition_count", required_argument, 0, 'p'},
                                            {"replica_count", required_argument, 0, 'r'},
+                                           {"fail_if_exist", no_argument, 0, 'f'},
                                            {"envs", required_argument, 0, 'e'},
                                            {0, 0, 0, 0}};
 
@@ -638,6 +639,7 @@ bool create_app(command_executor *e, shell_context *sc, arguments args)
         return false;
 
     std::string app_name = args.argv[1];
+    bool success_if_exist = true;
 
     int pc = 4, rc = 3;
     std::map<std::string, std::string> envs;
@@ -645,7 +647,7 @@ bool create_app(command_executor *e, shell_context *sc, arguments args)
     while (true) {
         int option_index = 0;
         int c;
-        c = getopt_long(args.argc, args.argv, "p:r:e:", long_options, &option_index);
+        c = getopt_long(args.argc, args.argv, "p:r:fe:", long_options, &option_index);
         if (c == -1)
             break;
         switch (c) {
@@ -661,6 +663,9 @@ bool create_app(command_executor *e, shell_context *sc, arguments args)
                 return false;
             }
             break;
+        case 'f':
+            success_if_exist = false;
+            break;
         case 'e':
             if (!::dsn::utils::parse_kv_map(optarg, envs, ',', '=')) {
                 fprintf(stderr, "invalid envs: %s\n", optarg);
@@ -672,7 +677,8 @@ bool create_app(command_executor *e, shell_context *sc, arguments args)
         }
     }
 
-    ::dsn::error_code err = sc->ddl_client->create_app(app_name, "pegasus", pc, rc, envs, false);
+    ::dsn::error_code err =
+        sc->ddl_client->create_app(app_name, "pegasus", pc, rc, envs, false, success_if_exist);
     if (err == ::dsn::ERR_OK)
         std::cout << "create app \"" << pegasus::utils::c_escape_string(app_name) << "\" succeed"
                   << std::endl;
diff --git a/src/shell/main.cpp b/src/shell/main.cpp
index 766f5d863..d877ecee4 100644
--- a/src/shell/main.cpp
+++ b/src/shell/main.cpp
@@ -81,7 +81,7 @@ static command_executor commands[] = {
     {
         "create",
         "create an app",
-        "<app_name> [-p|--partition_count num] [-r|--replica_count num] "
+        "<app_name> [-p|--partition_count num] [-r|--replica_count num] [-f|--fail_if_exist] "
         "[-e|--envs k1=v1,k2=v2...]",
         create_app,
     },


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org