You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by hu...@apache.org on 2021/11/15 19:41:32 UTC

[helix] branch master updated: add take/free instance(s) API (#1899)

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

hulee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/master by this push:
     new 54f11af  add take/free instance(s) API (#1899)
54f11af is described below

commit 54f11af0750f4439fb7083e99225057ca7418205
Author: xyuanlu <xy...@gmail.com>
AuthorDate: Mon Nov 15 11:41:23 2021 -0800

    add take/free instance(s) API (#1899)
    
    Create Cluster Maintenance Management service and add API signature and interfaces
---
 .../MaintenanceManagementInstanceInfo.java         |  87 +++++++++++++++
 .../MaintenanceManagementService.java              | 124 +++++++++++++++++++++
 .../api/OperationAbstractClass.java                |  56 ++++++++++
 .../helix/rest/common/datamodel/RestSnapShot.java  |  36 ++++++
 4 files changed, 303 insertions(+)

diff --git a/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementInstanceInfo.java b/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementInstanceInfo.java
new file mode 100644
index 0000000..d50ad0d
--- /dev/null
+++ b/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementInstanceInfo.java
@@ -0,0 +1,87 @@
+package org.apache.helix.rest.clusterMaintenanceService;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class MaintenanceManagementInstanceInfo {
+
+  public enum OperationalStatus {
+    SUCCESS,
+    FAILURE
+  }
+
+  private String operationResult;
+  private OperationalStatus status;
+  private List<String> messages;
+
+  public MaintenanceManagementInstanceInfo(OperationalStatus status) {
+    this.status = status;
+    this.messages = new ArrayList<>();
+  }
+
+  public MaintenanceManagementInstanceInfo(OperationalStatus status, List<String> messages) {
+    this.status = status;
+    this.messages = messages;
+  }
+
+  public MaintenanceManagementInstanceInfo(OperationalStatus status, String newOperationResult) {
+    this.status = status;
+    this.operationResult = newOperationResult;
+    this.messages = new ArrayList<>();
+  }
+
+  public List<String> getMessages() {
+    return messages;
+  }
+
+  public String getOperationResult() {
+    return operationResult;
+  }
+
+  public boolean hasOperationResult() {
+    return !operationResult.isEmpty();
+  }
+
+  public void setOperationResult(String result) {
+    operationResult = result;
+  }
+
+  public void addFailureMessage(List<String> msg) {
+    messages.addAll(msg);
+  }
+
+  public boolean isSuccessful() {
+    return status.equals(OperationalStatus.SUCCESS);
+  }
+
+  public void mergeResultStatus(MaintenanceManagementInstanceInfo info) {
+    messages.addAll(info.getMessages());
+    status = info.isSuccessful() && isSuccessful() ? OperationalStatus.SUCCESS
+        : OperationalStatus.FAILURE;
+    if (info.hasOperationResult()) {
+      operationResult =
+          this.hasOperationResult() ? operationResult + "," + info.getOperationResult()
+              : info.getOperationResult();
+    }
+  }
+}
\ No newline at end of file
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementService.java b/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementService.java
new file mode 100644
index 0000000..0435dc2
--- /dev/null
+++ b/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/MaintenanceManagementService.java
@@ -0,0 +1,124 @@
+package org.apache.helix.rest.clusterMaintenanceService;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+;
+
+public class MaintenanceManagementService {
+
+  /**
+   * Perform health check and maintenance operation check and execution for a instance in
+   * one cluster.
+   * User need to implement OperationAbstractClass for customer operation check & execution.
+   * It will invoke OperationAbstractClass.operationCheckForTakeSingleInstance and
+   * OperationAbstractClass.operationExecForTakeSingleInstance.
+   * The list of check and operation will be executed in the user provided sequence.
+   *
+   * @param clusterId          The cluster id
+   * @param instanceName       The instance name
+   * @param healthChecks       A list of healthChecks to perform
+   * @param healthCheckConfig The input for health Checks
+   * @param operations         A list of operation checks or operations to execute
+   * @param performOperation   If this param is set to false, the function will only do a dry run
+   * @return MaintenanceManagementInstanceInfo
+   * @throws IOException in case of network failure
+   */
+  public MaintenanceManagementInstanceInfo takeInstance(String clusterId, String instanceName,
+      List<String> healthChecks, Map<String, String> healthCheckConfig, List<String> operations,
+      Map<String, String> operationConfig, boolean performOperation) throws IOException {
+    return null;
+  }
+
+  /**
+   * Perform health check and maintenance operation check and execution for a list of instances in
+   * one cluster.
+   * User need to implement OperationAbstractClass for customer operation check & execution.
+   * It will invoke OperationAbstractClass.operationCheckForTakeInstances and
+   * OperationAbstractClass.operationExecForTakeInstances.
+   * The list of check and operation will be executed in the user provided sequence.
+   *
+   * @param clusterId          The cluster id
+   * @param instances          A list of instances
+   * @param healthChecks       A list of healthChecks to perform
+   * @param healthCheckConfig The input for health Checks
+   * @param operations         A list of operation checks or operations to execute
+   * @param performOperation   If this param is set to false, the function will only do a dry run
+   * @return A list of MaintenanceManagementInstanceInfo
+   * @throws IOException in case of network failure
+   */
+  public Map<String, MaintenanceManagementInstanceInfo> takeInstances(String clusterId,
+      List<String> instances, List<String> healthChecks, Map<String, String> healthCheckConfig,
+      List<String> operations, Map<String, String> operationConfig, boolean performOperation)
+      throws IOException {
+    return null;
+  }
+
+  /**
+   * Perform health check and maintenance operation check and execution for a instance in
+   * one cluster.
+   * User need to implement OperationAbstractClass for customer operation check & execution.
+   * It will invoke OperationAbstractClass.operationCheckForFreeSingleInstance and
+   * OperationAbstractClass.operationExecForFreeSingleInstance.
+   * The list of check and operation will be executed in the user provided sequence.
+   *
+   * @param clusterId          The cluster id
+   * @param instanceName       The instance name
+   * @param healthChecks       A list of healthChecks to perform
+   * @param healthCheckConfig The input for health Checks
+   * @param operations         A list of operation checks or operations to execute
+   * @param performOperation   If this param is set to false, the function will only do a dry run
+   * @return MaintenanceManagementInstanceInfo
+   * @throws IOException in case of network failure
+   */
+  public MaintenanceManagementInstanceInfo freeInstance(String clusterId, String instanceName,
+      List<String> healthChecks, Map<String, String> healthCheckConfig, List<String> operations,
+      Map<String, String> operationConfig, boolean performOperation) throws IOException {
+    return null;
+  }
+
+  /**
+   * Perform health check and maintenance operation check and execution for a list of instances in
+   * one cluster.
+   * User need to implement OperationAbstractClass for customer operation check & execution.
+   * It will invoke OperationAbstractClass.operationCheckForFreeInstances and
+   * OperationAbstractClass.operationExecForFreeInstances.
+   * The list of check and operation will be executed in the user provided sequence.
+   *
+   * @param clusterId          The cluster id
+   * @param instances          A list of instances
+   * @param healthChecks       A list of healthChecks to perform
+   * @param healthCheckConfig The input for health Checks
+   * @param operations         A list of operation checks or operations to execute
+   * @param performOperation   If this param is set to false, the function will only do a dry run
+   * @return A list of MaintenanceManagementInstanceInfo
+   * @throws IOException in case of network failure
+   */
+  public Map<String, MaintenanceManagementInstanceInfo> freeInstances(String clusterId,
+      List<String> instances, List<String> healthChecks, Map<String, String> healthCheckConfig,
+      List<String> operations, Map<String, String> operationConfig, boolean performOperation)
+      throws IOException {
+    return null;
+  }
+}
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/api/OperationAbstractClass.java b/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/api/OperationAbstractClass.java
new file mode 100644
index 0000000..e77919b
--- /dev/null
+++ b/helix-rest/src/main/java/org/apache/helix/rest/clusterMaintenanceService/api/OperationAbstractClass.java
@@ -0,0 +1,56 @@
+package org.apache.helix.rest.clusterMaintenanceService.api;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.helix.rest.clusterMaintenanceService.MaintenanceManagementInstanceInfo;
+import org.apache.helix.rest.common.datamodel.RestSnapShot;
+
+
+interface OperationAbstractClass {
+  // operation check
+  MaintenanceManagementInstanceInfo operationCheckForTakeSingleInstance(String instanceName,
+      Map<String, String> operationConfig, RestSnapShot sn);
+
+  MaintenanceManagementInstanceInfo operationCheckForFreeSingleInstance(String instanceName,
+      Map<String, String> operationConfig, RestSnapShot sn);
+
+  Map<String, MaintenanceManagementInstanceInfo> operationCheckForTakeInstances(
+      Collection<String> instances, Map<String, String> operationConfig, RestSnapShot sn);
+
+  Map<String, MaintenanceManagementInstanceInfo> operationCheckForFreeInstances(
+      Collection<String> instances, Map<String, String> operationConfig, RestSnapShot sn);
+
+  // operation execute
+  MaintenanceManagementInstanceInfo operationExecForTakeSingleInstance(String instanceName,
+      Map<String, String> operationConfig, RestSnapShot sn);
+
+  MaintenanceManagementInstanceInfo operationExecForFreeSingleInstance(String instanceName,
+      Map<String, String> operationConfig, RestSnapShot sn);
+
+  Map<String, MaintenanceManagementInstanceInfo> operationExecForTakeInstances(
+      Collection<String> instances, Map<String, String> operationConfig, RestSnapShot sn);
+
+  Map<String, MaintenanceManagementInstanceInfo> operationExecForFreeInstances(
+      Collection<String> instances, Map<String, String> operationConfig, RestSnapShot sn);
+
+}
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/common/datamodel/RestSnapShot.java b/helix-rest/src/main/java/org/apache/helix/rest/common/datamodel/RestSnapShot.java
new file mode 100644
index 0000000..d4b8dbc
--- /dev/null
+++ b/helix-rest/src/main/java/org/apache/helix/rest/common/datamodel/RestSnapShot.java
@@ -0,0 +1,36 @@
+package org.apache.helix.rest.common.datamodel;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* This Snapshot can extend Snapshot from common/core module
+ * once there is more generic snapshot.
+ */
+public class RestSnapShot {
+  /* An Snapshot object should contain all the Helix related info that an implementation of
+   * OperationAbstractClass would need.
+   */
+
+
+  // TODO: Next: Add a KV map and get function for the first version in next change.
+  // TODO: Define a Enum class for all Helix info types like ExternalView, InstanceConfig etc. An
+  // implementation of OperationAbstractClass will need to define what are the types needed.
+
+  // TODO: Future: Support hierarchical Snapshot type for other services besides cluster MaintenanceService.
+}
\ No newline at end of file