The following example shows how to remove components from multiple hosts.

  1. Stop components on hosts.

    curl -k -u admin:admin -H "X-Requested-By:ambari" 
    -X PUT --data 
    '{
       "RequestInfo":{
          "context":"Stop components on hosts"
       },
       "Body":{
          "HostRoles":{
             "state":"INSTALLED"
          }
       }
    }' "$HTTP_PROTOCOL://$CONSOLE_NODE:$PORT/api/v1/clusters/$CLUSTER/host_components?HostRoles/component_name.in(DATANODE,HBASE_REGIONSERVER)&HostRoles/host_name.in(c7301.ambari.apache.org,c7302.ambari.apache.org)"


    Ambari returns a request status URL to be polled for execution results. You can also review the result from Ambari web UI.

    {
      "href" : "http://c7301.ambari.apache.org:8080/api/v1/clusters/MyCluster/requests/40",
      "Requests" : {
        "id" : 40,
        "status" : "Accepted"
      }
    }
  2. Delete components on hosts once the components are stopped. You will receive an error message from Ambari server if you attempt to delete components that are still running.

    curl -k -u admin:admin -H "X-Requested-By: ambari" -X DELETE 
    "$HTTP_PROTOCOL://$CONSOLE_NODE:$PORT/api/v1/clusters/$CLUSTER/host_components?HostRoles/component_name.in(DATANODE,HBASE_REGIONSERVER)&HostRoles/host_name.in(c7301.ambari.apache.org,c7302.ambari.apache.org)"

     

    1. Result of a successful delete

      {
        "deleteResult" : [
          {
            "deleted" : {
              "key" : "c7301.ambari.apache.org/DATANODE"
            }
          },
          {
            "deleted" : {
              "key" : "c7302.ambari.apache.org/DATANODE"
            }
          },
          {
            "deleted" : {
              "key" : "c7302.ambari.apache.org/HBASE_REGIONSERVER"
            }
          },
          {
            "deleted" : {
              "key" : "c7301.ambari.apache.org/HBASE_REGIONSERVER"
            }
          }
        ]
      }
      
      
    2. Error when trying to delete running components

      {
        "deleteResult" : [
          {
            "error" : {
              "key" : "c7301.ambari.apache.org/DATANODE",
              "code" : 500,
             
       "message" : "org.apache.ambari.server.AmbariException: Host Component 
      cannot be removed, clusterName=MyCluster, serviceName=HDFS, 
      componentName=DATANODE, hostname=c7301.ambari.apache.org, request={ clusterName=MyCluster, serviceName=HDFS, componentName=DATANODE, hostname=c7301.ambari.apache.org,
       publicHostname=null, desiredState=null, state=null, 
      desiredStackId=null, staleConfig=null, adminState=null, 
      maintenanceState=null}"
            }
          },
          {
            "error" : {
              "key" : "c7302.ambari.apache.org/DATANODE",
              "code" : 500,
             
       "message" : "org.apache.ambari.server.AmbariException: Host Component 
      cannot be removed, clusterName=MyCluster, serviceName=HDFS, 
      componentName=DATANODE, hostname=c7302.ambari.apache.org, request={ clusterName=MyCluster, serviceName=HDFS, componentName=DATANODE, hostname=c7302.ambari.apache.org,
       publicHostname=null, desiredState=null, state=null, 
      desiredStackId=null, staleConfig=null, adminState=null, 
      maintenanceState=null}"
            }
          },
          {
            "error" : {
              "key" : "c7302.ambari.apache.org/HBASE_REGIONSERVER",
              "code" : 500,
             
       "message" : "org.apache.ambari.server.AmbariException: Host Component 
      cannot be removed, clusterName=MyCluster, serviceName=HBASE, 
      componentName=HBASE_REGIONSERVER, hostname=c7302.ambari.apache.org, request={ clusterName=MyCluster, serviceName=HBASE, componentName=HBASE_REGIONSERVER, hostname=c7302.ambari.apache.org,
       publicHostname=null, desiredState=null, state=null, 
      desiredStackId=null, staleConfig=null, adminState=null, 
      maintenanceState=null}"
            }
          },
          {
            "error" : {
              "key" : "c7301.ambari.apache.org/HBASE_REGIONSERVER",
              "code" : 500,
             
       "message" : "org.apache.ambari.server.AmbariException: Host Component 
      cannot be removed, clusterName=MyCluster, serviceName=HBASE, 
      componentName=HBASE_REGIONSERVER, hostname=c7301.ambari.apache.org, request={ clusterName=MyCluster, serviceName=HBASE, componentName=HBASE_REGIONSERVER, hostname=c7301.ambari.apache.org,
       publicHostname=null, desiredState=null, state=null, 
      desiredStackId=null, staleConfig=null, adminState=null, 
      maintenanceState=null}"
            }
          }
        ]
      }








  • No labels