You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2013/03/11 07:24:53 UTC

svn commit: r1455007 - in /incubator/ambari/trunk: ambari-agent/src/main/puppet/modules/configgenerator/manifests/ ambari-agent/src/main/puppet/modules/hdp-hive/manifests/ ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/ ambari-server/src/main...

Author: mahadev
Date: Mon Mar 11 06:24:52 2013
New Revision: 1455007

URL: http://svn.apache.org/r1455007
Log:
AMBARI-1606. Limit access to ooze-site and hive-site xml files to protect DB passwords.

Added:
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScanner.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScannerTest.java
Modified:
    incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/configgenerator/manifests/configfile.pp
    incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/init.pp
    incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/init.pp
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
    incubator/ambari/trunk/ambari-server/src/main/resources/ganglia_properties.json
    incubator/ambari/trunk/ambari-server/src/test/resources/mapreduce_jobtracker_jmx.json

Modified: incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/configgenerator/manifests/configfile.pp
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/configgenerator/manifests/configfile.pp?rev=1455007&r1=1455006&r2=1455007&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/configgenerator/manifests/configfile.pp (original)
+++ incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/configgenerator/manifests/configfile.pp Mon Mar 11 06:24:52 2013
@@ -43,7 +43,7 @@
 # Note: Set correct $modulespath in the configgenerator (or pass it as parameter)
 #
 
-define configgenerator::configfile ($modulespath='/etc/puppet/modules', $filename, $module, $configuration, $owner = "root", $group = "root") {
+define configgenerator::configfile ($modulespath='/etc/puppet/modules', $filename, $module, $configuration, $owner = "root", $group = "root", $mode = undef) {
   $configcontent = inline_template('<!--<%=Time.now.asctime %>-->
   <configuration>
   <% configuration.each do |key,value| -%>
@@ -62,6 +62,7 @@ file {"${modulespath}/${filename}":
   content => $configcontent,
   path => "${modulespath}/${filename}",
   owner => $owner,
-  group => $group
+  group => $group,
+  mode => $mode
 }
 } 

Modified: incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/init.pp
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/init.pp?rev=1455007&r1=1455006&r2=1455007&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/init.pp (original)
+++ incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/hdp-hive/manifests/init.pp Mon Mar 11 06:24:52 2013
@@ -35,7 +35,10 @@ class hdp-hive(
       modulespath => $hdp-hive::params::hive_conf_dir, 
       filename => 'hive-site.xml',
       module => 'hdp-hive',
-      configuration => $configuration['hive-site']
+      configuration => $configuration['hive-site'],
+      owner => $hive_user,
+      group => $hdp::params::user_group,
+      mode => '0660'
     }
   }
 

Modified: incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/init.pp
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/init.pp?rev=1455007&r1=1455006&r2=1455007&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/init.pp (original)
+++ incubator/ambari/trunk/ambari-agent/src/main/puppet/modules/hdp-oozie/manifests/init.pp Mon Mar 11 06:24:52 2013
@@ -28,18 +28,21 @@ class hdp-oozie(
 
 # Configs generation  
 
+  $oozie_user = $hdp-oozie::params::oozie_user
+  $oozie_config_dir = $hdp-oozie::params::conf_dir
+
   if has_key($configuration, 'oozie-site') {
     configgenerator::configfile{'oozie-site':
       modulespath => $hdp-oozie::params::conf_dir, 
       filename => 'oozie-site.xml',
       module => 'hdp-oozie',
-      configuration => $configuration['oozie-site']
+      configuration => $configuration['oozie-site'],
+      owner => $oozie_user,
+      group => $hdp::params::user_group,
+      mode => '0660'
     }
   }
 
-  $oozie_user = $hdp-oozie::params::oozie_user
-  $oozie_config_dir = $hdp-oozie::params::conf_dir
-  
   if ($service_state == 'uninstalled') {
     hdp::package { 'oozie-client' : 
       ensure => 'uninstalled'

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java?rev=1455007&r1=1455006&r2=1455007&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java Mon Mar 11 06:24:52 2013
@@ -42,6 +42,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import org.apache.ambari.server.state.svccomphost.HBaseMasterPortScanner;
 
 
 /**
@@ -64,6 +65,8 @@ public class HeartBeatHandler {
   AmbariMetaInfo ambariMetaInfo;
   @Inject
   ActionMetadata actionMetadata;
+  @Inject
+  HBaseMasterPortScanner scaner;
 
   private Map<String, Long> hostResponseIds = new HashMap<String, Long>();
   private Map<String, HeartBeatResponse> hostResponses = new HashMap<String, HeartBeatResponse>();
@@ -75,10 +78,11 @@ public class HeartBeatHandler {
     this.actionQueue = aq;
     this.actionManager = am;
     this.heartbeatMonitor = new HeartbeatMonitor(fsm, aq, am, 60000);
+    this.heartbeatMonitor.setScaner(scaner);
     injector.injectMembers(this);
   }
 
-  public void start() {
+  public void start() {     
     heartbeatMonitor.start();
   }
 
@@ -127,13 +131,13 @@ public class HeartBeatHandler {
     hostResponses.put(hostname, response);
 
     long now = System.currentTimeMillis();
-
+    HostState hostState = hostObject.getState();
     // If the host is waiting for component status updates, notify it
     if (heartbeat.componentStatus.size() > 0
             && hostObject.getState().equals(HostState.WAITING_FOR_HOST_STATUS_UPDATES)) {
       try {
         LOG.debug("Got component status updates");
-        hostObject.handleEvent(new HostStatusUpdatesReceivedEvent(hostname, now));
+        hostObject.handleEvent(new HostStatusUpdatesReceivedEvent(hostname, now));   
       } catch (InvalidStateTransitionException e) {
         LOG.warn("Failed to notify the host about component status updates", e);
       }
@@ -145,8 +149,9 @@ public class HeartBeatHandler {
             heartbeat.getAgentEnv()));
       } else {
         hostObject.handleEvent(new HostUnhealthyHeartbeatEvent(hostname, now,
-            null));
+            null));       
       }
+      if(hostState != hostObject.getState()) scaner.updateHBaseMaster(hostObject);
     } catch (InvalidStateTransitionException ex) {
       LOG.warn("Asking agent to reregister due to " + ex.getMessage(),  ex);
       hostObject.setState(HostState.INIT);
@@ -185,6 +190,7 @@ public class HeartBeatHandler {
           ServiceComponent svcComp = svc.getServiceComponent(report.getRole());
           ServiceComponentHost scHost = svcComp.getServiceComponentHost(hostname);
           String schName = scHost.getServiceComponentName();
+          State state = scHost.getState();
           if (report.getStatus().equals("COMPLETED")) {
             // Updating stack version, if needed
             if (scHost.getState().equals(State.UPGRADING)) {
@@ -199,6 +205,7 @@ public class HeartBeatHandler {
             scHost.handleEvent(new ServiceComponentHostOpInProgressEvent(schName,
                     hostname, now));
           }
+          if(state != scHost.getState() && schName.equals(Role.HBASE_MASTER.toString())) scaner.updateHBaseMaster(cl);
         } catch (ServiceComponentNotFoundException scnex) {
           LOG.warn("Service component not found ", scnex);
         } catch (InvalidStateTransitionException ex) {
@@ -233,7 +240,8 @@ public class HeartBeatHandler {
                       || prevState.equals(State.STARTED)
                       || prevState.equals(State.STOP_FAILED)) {
                 scHost.setState(liveState);
-                if (!prevState.equals(liveState)) {
+                if (!prevState.equals(liveState) && scHost.getServiceComponentName().equals(Role.HBASE_MASTER.toString())) {
+                    scaner.updateHBaseMaster(scHost);
                   LOG.info("State of service component " + componentName
                           + " of service " + status.getServiceName()
                           + " of cluster " + status.getClusterName()

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java?rev=1455007&r1=1455006&r2=1455007&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java Mon Mar 11 06:24:52 2013
@@ -32,6 +32,7 @@ import org.apache.ambari.server.state.Ho
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.apache.ambari.server.state.host.HostHeartbeatLostEvent;
+import org.apache.ambari.server.state.svccomphost.HBaseMasterPortScanner;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -46,6 +47,11 @@ public class HeartbeatMonitor implements
   private final int threadWakeupInterval; //1 minute
   private volatile boolean shouldRun = true;
   private Thread monitorThread = null;
+  private HBaseMasterPortScanner scaner;
+
+  public void setScaner(HBaseMasterPortScanner scaner) {
+        this.scaner = scaner;
+  }
 
   public HeartbeatMonitor(Clusters fsm, ActionQueue aq, ActionManager am,
       int threadWakeupInterval) {
@@ -110,6 +116,7 @@ public class HeartbeatMonitor implements
         LOG.warn("Hearbeat lost from host "+host);
         //Heartbeat is expired
         hostObj.handleEvent(new HostHeartbeatLostEvent(host));
+        if(hostState != hostObj.getState() && scaner != null) scaner.updateHBaseMaster(hostObj);
         //Purge action queue
         actionQueue.dequeueAll(host);
         //notify action manager

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java?rev=1455007&r1=1455006&r2=1455007&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java Mon Mar 11 06:24:52 2013
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.controller;
 
+import org.apache.ambari.server.state.svccomphost.HBaseMasterPortScanner;
 import com.google.gson.Gson;
 import com.google.inject.Scopes;
 import com.google.inject.assistedinject.FactoryModuleBuilder;
@@ -34,6 +35,7 @@ import org.apache.ambari.server.state.ho
 import org.apache.ambari.server.state.host.HostImpl;
 
 import com.google.inject.AbstractModule;
+import com.google.inject.Singleton;
 import com.google.inject.name.Names;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostImpl;
 import org.springframework.security.crypto.password.PasswordEncoder;
@@ -89,6 +91,8 @@ public class ControllerModule extends Ab
     bindConstant().annotatedWith(Names.named("actionTimeout")).to(300000L);
     bind(AmbariManagementController.class)
         .to(AmbariManagementControllerImpl.class);
+    bind(HBaseMasterPortScanner.class).in(Singleton.class);;
+
   }
 
   private void installFactories() {

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java?rev=1455007&r1=1455006&r2=1455007&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostResponse.java Mon Mar 11 06:24:52 2013
@@ -40,6 +40,9 @@ public class ServiceComponentHostRespons
   private String stackVersion;
 
   private String desiredState;
+  
+  private String ha_status = "NA";
+
 
   public ServiceComponentHostResponse(String clusterName, String serviceName,
                                       String componentName, String hostname,
@@ -171,6 +174,26 @@ public class ServiceComponentHostRespons
     this.clusterName = clusterName;
   }
 
+  /**
+   * 
+   * @return ha_status status of HBaseMaster
+   */
+  public String getHa_status() {
+    return ha_status;
+  }
+
+  
+  /**
+   * 
+   * @param ha_status the state of HBaseMaster
+   */
+  public void setHa_status(String ha_status) {
+    this.ha_status = ha_status;
+  }
+
+  
+  
+  
   @Override
   public boolean equals(Object o) {
     if (this == o) return true;

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java?rev=1455007&r1=1455006&r2=1455007&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java Mon Mar 11 06:24:52 2013
@@ -132,7 +132,7 @@ class HostComponentResourceProvider exte
       setResourceProperty(resource, HOST_COMPONENT_HOST_NAME_PROPERTY_ID, response.getHostname(), requestedIds);
       setResourceProperty(resource, HOST_COMPONENT_STATE_PROPERTY_ID, response.getLiveState(), requestedIds);
       setResourceProperty(resource, HOST_COMPONENT_DESIRED_STATE_PROPERTY_ID, response.getDesiredState(), requestedIds);
-      setResourceProperty(resource, HOST_COMPONENT_HIGH_AVAILABILITY_PROPERTY_ID, "NA", requestedIds);
+      setResourceProperty(resource, HOST_COMPONENT_HIGH_AVAILABILITY_PROPERTY_ID, response.getHa_status(), requestedIds);
       setResourceProperty(resource, HOST_COMPONENT_CONFIGS_PROPERTY_ID,
           response.getConfigs(), requestedIds);
       setResourceProperty(resource, HOST_COMPONENT_DESIRED_CONFIGS_PROPERTY_ID,

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java?rev=1455007&r1=1455006&r2=1455007&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java Mon Mar 11 06:24:52 2013
@@ -85,6 +85,8 @@ public interface ServiceComponentHost {
   public State getState();
 
   public void setState(State state);
+  
+  public void setHAState(String status);
 
   public Map<String, Config> getConfigs() throws AmbariException;
 

Added: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScanner.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScanner.java?rev=1455007&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScanner.java (added)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScanner.java Mon Mar 11 06:24:52 2013
@@ -0,0 +1,205 @@
+/**
+ * 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.
+ */
+package org.apache.ambari.server.state.svccomphost;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.net.ConnectException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.Role;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This class encapsulates the HBaseMaster scanner thread. HBaseMaster scanner
+ * start scan if Host, ServiceComponentHost or Cluster change own state.
+ */
+@Singleton
+public class HBaseMasterPortScanner implements Runnable {
+
+  private static Log LOG = LogFactory.getLog(HBaseMasterPortScanner.class);
+  private Thread schedulerThread = null;
+  private final Object wakeupSyncObject = new Object();
+  private int scanTimeoutMsc = 300;
+  private final int port = 60010;
+  private Set<ServiceComponentHost> componentHostSet;
+  @Inject
+  private Clusters clusters;
+  /**
+   * true if scanner should run ASAP. We need this flag to avoid sleep in
+   * situations, when we receive updateHBaseMaster request during running a
+   * scanner iteration.
+   */
+  private boolean activeAwakeRequest = false;
+
+  public HBaseMasterPortScanner(int scanTimeoutMsc) {
+    this.scanTimeoutMsc = scanTimeoutMsc;
+    this.start();
+  }
+
+  public HBaseMasterPortScanner() {
+     this.start();
+  }
+  
+  private void start() {
+    schedulerThread = new Thread(this, this.getClass().getSimpleName());
+    schedulerThread.start();
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("HBaseMasterPortScaner started");
+    }
+  }
+
+  public void stop() {
+    schedulerThread.interrupt();
+  }
+
+  /**
+   * Should be called from another thread when we want HBase Master scanner to
+   * make a run ASAP (for example, to process desired configs of SCHs). The
+   * method is guaranteed to return quickly.
+   */
+  public void updateHBaseMaster(Cluster cluster) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("HBaseMasterPortScaner start scanning for cluster " + cluster.getClusterName());
+    }
+    synchronized (wakeupSyncObject) {
+      collectServiceComponentHostsForCluster(cluster);
+      activeAwakeRequest = true;
+      wakeupSyncObject.notify();
+    }
+  }
+
+  public void updateHBaseMaster(Host host) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("HBaseMasterPortScaner start scanning for Host " + host.getHostName());
+    }
+    synchronized (wakeupSyncObject) {
+      Set<Cluster> clustersSet;
+      try {
+        clustersSet = clusters.getClustersForHost(host.getHostName());
+      } catch (AmbariException ex) {
+        return;
+      }
+      Iterator<Cluster> iter = clustersSet.iterator();
+      while (iter.hasNext()) {
+        collectServiceComponentHostsForCluster(iter.next());
+      }
+      activeAwakeRequest = true;
+      wakeupSyncObject.notify();
+    }
+  }
+
+  public void updateHBaseMaster(ServiceComponentHost host) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("HBaseMasterPortScaner start scanning for ServiceComponentHost " + host.getServiceComponentName());
+    }
+    synchronized (wakeupSyncObject) {
+      try {
+        collectServiceComponentHostsForCluster(clusters.getCluster(host.getClusterName()));
+      } catch (AmbariException ex) {
+        LOG.warn(ex);
+        return;
+      }
+      activeAwakeRequest = true;
+      wakeupSyncObject.notify();
+    }
+  }
+
+  private void collectServiceComponentHostsForCluster(Cluster cluster) {
+    componentHostSet = new HashSet<ServiceComponentHost>();
+    Map<String, Host> hosts = null;
+    try {
+      hosts = clusters.getHostsForCluster(cluster.getClusterName());
+    } catch (AmbariException ex) {
+      LOG.warn(ex);
+      return;
+    }
+    for (Map.Entry<String, Host> entry : hosts.entrySet()) {
+      if (entry.getValue() != null) {
+        List<ServiceComponentHost> componentHosts = cluster.getServiceComponentHosts(entry.getValue().getHostName());
+        for (ServiceComponentHost componentHost : componentHosts) {
+          if (componentHost != null && componentHost.getServiceComponentName() != null && componentHost.getServiceComponentName().equals(Role.HBASE_MASTER.toString())) {
+            componentHostSet.add(componentHost);
+          }
+        }
+      }
+    }
+
+  }
+
+  @Override
+  public void run() {
+    while (true) {
+      activeAwakeRequest = false;
+      if (componentHostSet != null) {
+        Iterator<ServiceComponentHost> iter = componentHostSet.iterator();
+        while (iter.hasNext()) {
+          ServiceComponentHost componentHost = iter.next();
+          boolean active =
+                  scan(componentHost.getHostName());
+          componentHost.setHAState((active) ? "active" : "passive");
+
+          if (schedulerThread.isInterrupted()) {
+            return;
+          }
+          if (activeAwakeRequest) {
+            break;
+          }
+        }
+      }
+      if (activeAwakeRequest) {
+        activeAwakeRequest = false;
+        continue;
+      }
+      try {
+        synchronized (wakeupSyncObject) {
+          wakeupSyncObject.wait();
+        }
+      } catch (InterruptedException ex) {
+        activeAwakeRequest = true;
+      }
+    }
+  }
+
+  private boolean scan(String hostname) {
+    try {
+      Socket socket = new Socket();
+      socket.connect(new InetSocketAddress(hostname, port), scanTimeoutMsc);
+      socket.close();
+      LOG.info(hostname + ":" + port + " HBASE_MASTER active");
+      return true;
+    } catch (ConnectException e) {
+      LOG.info(hostname + ":" + port + " HBASE_MASTER passive");
+      return false;
+    } catch (Exception ex) {
+      LOG.info(hostname + ":" + port + " HBASE_MASTER passive");
+      LOG.error(ex);
+      return false;
+    }
+  }
+}

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java?rev=1455007&r1=1455006&r2=1455007&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java Mon Mar 11 06:24:52 2013
@@ -107,6 +107,7 @@ public class ServiceComponentHostImpl im
   private long lastOpStartTime;
   private long lastOpEndTime;
   private long lastOpLastUpdateTime;
+  private String ha_status = "passive";
 
   private static final StateMachineFactory
   <ServiceComponentHostImpl, State,
@@ -460,6 +461,17 @@ public class ServiceComponentHostImpl im
   private final StateMachine<State,
       ServiceComponentHostEventType, ServiceComponentHostEvent> stateMachine;
 
+  @Override
+  public void setHAState(String status) {
+    try {
+      writeLock.lock();
+      ha_status = status;
+    }
+    finally {
+      writeLock.unlock();
+    }
+  }
+
   static class ServiceComponentHostOpCompletedTransition
      implements SingleArcTransition<ServiceComponentHostImpl,
          ServiceComponentHostEvent> {
@@ -1110,6 +1122,7 @@ public class ServiceComponentHostImpl im
           getState().toString(),
           getStackVersion().getStackId(),
           getDesiredState().toString());
+      r.setHa_status(ha_status);
       return r;
     }
     finally {

Modified: incubator/ambari/trunk/ambari-server/src/main/resources/ganglia_properties.json
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/resources/ganglia_properties.json?rev=1455007&r1=1455006&r2=1455007&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/resources/ganglia_properties.json (original)
+++ incubator/ambari/trunk/ambari-server/src/main/resources/ganglia_properties.json Mon Mar 11 06:24:52 2013
@@ -19562,4 +19562,4 @@
       }
     }
   }
-}
+}
\ No newline at end of file

Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScannerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScannerTest.java?rev=1455007&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScannerTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/HBaseMasterPortScannerTest.java Mon Mar 11 06:24:52 2013
@@ -0,0 +1,183 @@
+/**
+ * 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.
+ */
+package org.apache.ambari.server.state.svccomphost;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.ambari.server.AmbariException;
+import static org.apache.ambari.server.agent.DummyHeartbeatConstants.DATANODE;
+import static org.apache.ambari.server.agent.DummyHeartbeatConstants.DummyCluster;
+import static org.apache.ambari.server.agent.DummyHeartbeatConstants.DummyOsType;
+import static org.apache.ambari.server.agent.DummyHeartbeatConstants.HDFS;
+import static org.apache.ambari.server.agent.DummyHeartbeatConstants.HBASE_MASTER;
+import static org.apache.ambari.server.agent.DummyHeartbeatConstants.NAMENODE;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceFactory;
+import org.apache.ambari.server.state.StackId;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author root
+ */
+public class HBaseMasterPortScannerTest {
+
+  private static final Logger log = LoggerFactory.getLogger(HBaseMasterPortScannerTest.class);
+  private static List<String> hostnames;
+  private static ServerSocket serverSocket;
+  private static Injector injector;
+  private static HBaseMasterPortScanner scaner;
+  private static ServiceFactory serviceFactory;
+  private static AmbariMetaInfo metaInfo;
+  private static Clusters clusters;
+  private static Cluster cluster;
+  private static Host host;
+  private static ServiceComponentHost serviceComponentHost;
+
+  public HBaseMasterPortScannerTest() {
+  }
+
+  @BeforeClass
+  public static void setUpClass() throws Exception {
+    injector = Guice.createInjector(new InMemoryDefaultTestModule());
+    injector.getInstance(GuiceJpaInitializer.class);
+    hostnames = new ArrayList<String>();
+    hostnames.add("localhost");
+    hostnames.add("localhost1");
+    hostnames.add("localhost2");
+    hostnames.add("localhost3");
+    try {
+      serverSocket = new ServerSocket(60010);
+    } catch (IOException e) {
+      try {
+        serverSocket.close();
+      } catch (IOException ex) {
+        log.debug("Could not close on port: 60010");
+        log.error(ex.getMessage());
+      }
+      log.error("Could not listen on port: 60010");
+    }
+    scaner = injector.getInstance(HBaseMasterPortScanner.class);
+    clusters = injector.getInstance(Clusters.class);
+    metaInfo = injector.getInstance(AmbariMetaInfo.class);
+    serviceFactory = injector.getInstance(ServiceFactory.class);
+    metaInfo.init();
+    clusters.addCluster(DummyCluster);
+    cluster = clusters.getCluster(DummyCluster);
+    cluster.setDesiredStackVersion(new StackId("HDP-0.2"));
+    Set<String> hostNamesSet = new HashSet<String>();
+    for (String hostname : hostnames) {
+      clusters.addHost(hostname);
+      clusters.getHost(hostname).persist();
+      Host hostObject = clusters.getHost(hostname);
+      hostObject.setIPv4("ipv4");
+      hostObject.setIPv6("ipv6");
+      hostObject.setOsType(DummyOsType);
+      hostNamesSet.add(hostname);
+      if (hostname.equals("localhost")) {
+        host = hostObject;
+      }
+    }
+    clusters.mapHostsToCluster(hostNamesSet, DummyCluster);
+    Service service = cluster.addService(HDFS);
+    service.persist();
+    service.addServiceComponent(NAMENODE).persist();
+    service.getServiceComponent(NAMENODE).addServiceComponentHost("localhost").persist();
+    service.addServiceComponent(DATANODE).persist();
+    service.getServiceComponent(DATANODE).addServiceComponentHost("localhost").persist();
+    service = serviceFactory.createNew(cluster, "HBASE");
+    cluster.addService(service);
+    service.persist();
+    service = cluster.getService("HBASE");
+    service.addServiceComponent(HBASE_MASTER).persist();
+    service.persist();
+    for (String hostname : hostnames) {
+      service.getServiceComponent(HBASE_MASTER).addServiceComponentHost(hostname).persist();
+      if (hostname.equals("localhost")) {
+        serviceComponentHost = service.getServiceComponent(HBASE_MASTER).getServiceComponentHost(hostname);
+      }
+    }
+
+  }
+
+  @AfterClass
+  public static void tearDownUpClass() {
+    try {
+      serverSocket.close();
+    } catch (IOException ex) {
+      log.debug("Could not close on port: 60010");
+      log.error(ex.getMessage());
+    }
+  }
+
+  @Before
+  public void setUp() throws AmbariException, Exception {
+    serviceComponentHost.convertToResponse().setHa_status("passive");
+  }
+
+  /**
+   * Test of updateHBaseMaster method, of class HBaseMasterPortScaner.
+   */
+  @Test
+  public void testUpdateHBaseMaster_Cluster() throws InterruptedException {
+    log.debug("updateHBaseMaster - pass Cluster");
+    scaner.updateHBaseMaster(cluster);
+    Thread.sleep(2000);
+    assertEquals("active", serviceComponentHost.convertToResponse().getHa_status());
+  }
+
+  /**
+   * Test of updateHBaseMaster method, of class HBaseMasterPortScaner.
+   */
+  @Test
+  public void testUpdateHBaseMaster_Host() throws InterruptedException {
+    log.debug("updateHBaseMaster - pass Host");
+    scaner.updateHBaseMaster(host);
+    Thread.sleep(2000);
+    assertEquals("active", serviceComponentHost.convertToResponse().getHa_status());
+  }
+
+  /**
+   * Test of updateHBaseMaster method, of class HBaseMasterPortScaner.
+   */
+  @Test
+  public void testUpdateHBaseMaster_ServiceComponentHost() throws InterruptedException {
+    log.debug("updateHBaseMaster - pass ServiceComponentHost");
+    scaner.updateHBaseMaster(serviceComponentHost);
+    Thread.sleep(2000);
+    assertEquals("active", serviceComponentHost.convertToResponse().getHa_status());
+  }
+}
\ No newline at end of file

Modified: incubator/ambari/trunk/ambari-server/src/test/resources/mapreduce_jobtracker_jmx.json
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/resources/mapreduce_jobtracker_jmx.json?rev=1455007&r1=1455006&r2=1455007&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/resources/mapreduce_jobtracker_jmx.json (original)
+++ incubator/ambari/trunk/ambari-server/src/test/resources/mapreduce_jobtracker_jmx.json Mon Mar 11 06:24:52 2013
@@ -894,4 +894,4 @@
     "ImplementationVersion" : "1.6.0_31-b04",
     "ImplementationVendor" : "Sun Microsystems"
   } ]
-}
+}
\ No newline at end of file