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

aonishuk pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new a55fbba  AMBARI-23187. Add custom actions for: format NN, format ZK 
and bootStrap (aonishuk)
a55fbba is described below

commit a55fbba2fc984ffbfec65c016ad2e6d215435fa9
Author: Andrew Onishuk <aonis...@hortonworks.com>
AuthorDate: Tue Mar 13 14:44:21 2018 +0200

    AMBARI-23187. Add custom actions for: format NN, format ZK and bootStrap 
(aonishuk)
---
 .../controller/StackServiceComponentResponse.java  | 16 ++++++++++++-
 .../StackServiceComponentResourceProvider.java     |  2 +-
 .../server/state/CustomCommandDefinition.java      |  9 ++++++++
 .../common-services/HDFS/2.1.0.2.0/metainfo.xml    | 26 ++++++++++++++++++++++
 .../HDFS/2.1.0.2.0/package/scripts/namenode.py     | 17 +++++++++++++-
 .../HDFS/2.1.0.2.0/package/scripts/zkfc_slave.py   | 17 ++++++++++++++
 6 files changed, 84 insertions(+), 3 deletions(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackServiceComponentResponse.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackServiceComponentResponse.java
index 8797f03..72138fd 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/StackServiceComponentResponse.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/StackServiceComponentResponse.java
@@ -104,6 +104,11 @@ public class StackServiceComponentResponse {
   private List<String> customCommands;
 
   /**
+   * The names of the custom commands defined for the component which are 
hidden=false
+   */
+  private List<String> visibleCustomCommands;
+
+  /**
    * Enabled for auto start or not.
    */
   private boolean recoveryEnabled;
@@ -150,10 +155,15 @@ public class StackServiceComponentResponse {
     List<CustomCommandDefinition> definitions = component.getCustomCommands();
     if (null == definitions || definitions.size() == 0) {
       customCommands = Collections.emptyList();
+      visibleCustomCommands = Collections.emptyList();
     } else {
       customCommands = new ArrayList<>(definitions.size());
+      visibleCustomCommands = new ArrayList<>();
       for (CustomCommandDefinition command : definitions) {
         customCommands.add(command.getName());
+        if(!command.isHidden()) {
+          visibleCustomCommands.add(command.getName());
+        }
       }
     }
   }
@@ -498,11 +508,15 @@ public class StackServiceComponentResponse {
    *
    * @return the commands or an empty list (never {@code null}).
    */
-  @ApiModelProperty(name = "custom_commands")
   public List<String> getCustomCommands() {
     return customCommands;
   }
 
+  @ApiModelProperty(name = "custom_commands")
+  public List<String> getVisibleCustomCommands() {
+    return visibleCustomCommands;
+  }
+
   @ApiModelProperty(name = "has_bulk_commands_definition")
   public boolean hasBulkCommands(){
     return hasBulkCommands;
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackServiceComponentResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackServiceComponentResourceProvider.java
index 933dcb7..37c2efc 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackServiceComponentResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackServiceComponentResourceProvider.java
@@ -217,7 +217,7 @@ public class StackServiceComponentResourceProvider extends
           response.isReassignAlllowed(), requestedIds);
 
       setResourceProperty(resource, CUSTOM_COMMANDS_PROPERTY_ID,
-          response.getCustomCommands(), requestedIds);
+          response.getVisibleCustomCommands(), requestedIds);
 
       setResourceProperty(resource, BULK_COMMANDS_DISPLAY_NAME_PROPERTY_ID,
           response.getBulkCommandsDisplayName(), requestedIds);
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/CustomCommandDefinition.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/state/CustomCommandDefinition.java
index af5c37e..7717143 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/state/CustomCommandDefinition.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/state/CustomCommandDefinition.java
@@ -33,6 +33,7 @@ public class CustomCommandDefinition {
   private String opsDisplayName;
   private CommandScriptDefinition commandScript;
   private boolean background = false;
+  private boolean hidden = false;
 
   public String getName() {
     return name;
@@ -42,6 +43,14 @@ public class CustomCommandDefinition {
     return background;
   }
 
+  public boolean isHidden() {
+    return hidden;
+  }
+
+  public void setHidden(boolean hidden) {
+    this.hidden = hidden;
+  }
+
   public String getOpsDisplayName() {
     return opsDisplayName;
   }
diff --git 
a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/metainfo.xml 
b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/metainfo.xml
index 11a4378..3aac927 100644
--- 
a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/metainfo.xml
+++ 
b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/metainfo.xml
@@ -104,6 +104,22 @@
                 <scriptType>PYTHON</scriptType>
               </commandScript>
             </customCommand>
+            <customCommand>
+              <name>BOOTSTRAP_STANDBY</name>
+              <hidden>true</hidden>
+              <commandScript>
+                <script>scripts/namenode.py</script>
+                <scriptType>PYTHON</scriptType>
+              </commandScript>
+            </customCommand>
+            <customCommand>
+              <name>FORMAT</name>
+              <hidden>true</hidden>
+              <commandScript>
+                <script>scripts/namenode.py</script>
+                <scriptType>PYTHON</scriptType>
+              </commandScript>
+            </customCommand>
           </customCommands>
         </component>
 
@@ -235,6 +251,16 @@
               <primary>true</primary>
             </log>
           </logs>
+          <customCommands>
+            <customCommand>
+              <name>FORMAT</name>
+              <hidden>true</hidden>
+              <commandScript>
+                <script>scripts/zkfc_slave.py</script>
+                <scriptType>PYTHON</scriptType>
+              </commandScript>
+            </customCommand>
+          </customCommands>
         </component>
       </components>
 
diff --git 
a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/namenode.py
 
b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/namenode.py
index e82e73a..da8488c 100644
--- 
a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/namenode.py
+++ 
b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/namenode.py
@@ -47,7 +47,7 @@ from ambari_commons import OSConst
 
 
 import namenode_upgrade
-from hdfs_namenode import namenode, wait_for_safemode_off, refreshProxyUsers
+from hdfs_namenode import namenode, wait_for_safemode_off, refreshProxyUsers, 
format_namenode
 from hdfs import hdfs, reconfig
 import hdfs_rebalance
 from utils import initiate_safe_zkfc_failover, get_hdfs_binary, 
get_dfsadmin_base_command
@@ -94,6 +94,21 @@ class NameNode(Script):
     Logger.info("RELOAD HDFS PROXY USERS")
     refreshProxyUsers()
 
+  def format(self, env):
+    import params
+    env.set_params(params)
+
+    format_namenode()
+
+  def bootstrap_standby(self, env):
+    import params
+    env.set_params(params)
+
+    Execute("hdfs namenode -bootstrapStandby",
+            user=params.hdfs_user,
+            logoutput=True
+    )
+
   def start(self, env, upgrade_type=None):
     import params
     env.set_params(params)
diff --git 
a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/zkfc_slave.py
 
b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/zkfc_slave.py
index 955ff60..aed240a 100644
--- 
a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/zkfc_slave.py
+++ 
b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/zkfc_slave.py
@@ -33,6 +33,9 @@ from 
resource_management.libraries.functions.check_process_status import check_p
 from resource_management.libraries.functions.stack_features import 
check_stack_feature
 from resource_management.libraries.script import Script
 from resource_management.core.resources.zkmigrator import ZkMigrator
+from resource_management.core.resources.system import Execute
+from resource_management.core.exceptions import Fail, ComponentIsNotRunning
+
 
 class ZkfcSlave(Script):
   def install(self, env):
@@ -134,6 +137,19 @@ class ZkfcSlaveDefault(ZkfcSlave):
     env.set_params(params)
     if check_stack_feature(StackFeature.ZKFC_VERSION_ADVERTISED, 
params.version_for_stack_feature_checks):
       stack_select.select_packages(params.version)
+      
+  def format(self, env):
+    import params
+    env.set_params(params)
+
+    try:
+      self.status(env)
+      raise Fail("ZKFC is running. Cannot format it.")
+    except ComponentIsNotRunning:
+      Execute("hdfs zkfc -formatZK",
+              user=params.hdfs_user,
+              logoutput=True
+      )
 
 def initialize_ha_zookeeper(params):
   try:
@@ -155,6 +171,7 @@ def initialize_ha_zookeeper(params):
     Logger.error('HA state initialization in ZooKeeper threw an exception. 
Reason %s' %(str(ex)))
   return False
 
+
 @OsFamilyImpl(os_family=OSConst.WINSRV_FAMILY)
 class ZkfcSlaveWindows(ZkfcSlave):
   def start(self, env):

-- 
To stop receiving notification emails like this one, please contact
aonis...@apache.org.

Reply via email to