You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by hi...@apache.org on 2012/10/01 20:35:22 UTC

svn commit: r1392503 [2/2] - in /incubator/ambari/branches/AMBARI-666: ./ ambari-api/src/main/java/org/apache/ambari/api/controller/internal/ ambari-api/src/test/java/webserver/ ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ ambari...

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java Mon Oct  1 18:35:19 2012
@@ -19,16 +19,12 @@
 package org.apache.ambari.server.state.live;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.HostNotFoundException;
 import org.apache.ambari.server.ServiceComponentHostNotFoundException;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
-import org.apache.ambari.server.state.live.host.Host;
-import org.apache.ambari.server.state.live.host.HostEvent;
-import org.apache.ambari.server.state.live.host.HostImpl;
-import org.apache.ambari.server.state.live.host.HostState;
 import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHost;
 import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHostEvent;
 import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHostImpl;
@@ -36,57 +32,77 @@ import org.apache.ambari.server.state.li
 
 public class ClusterImpl implements Cluster {
 
-  private final String clusterName;
-  private Map<String, Host> hosts;
+  private final Clusters clusters;
+
+  private final long clusterId;
+
+  private String clusterName;
+
+  /**
+   * [ ServiceName -> [ ServiceComponentName -> [ HostName -> [ ... ] ] ] ]
+   */
   private Map<String, Map<String, Map<String, ServiceComponentHost>>>
       serviceComponentHosts;
 
-  public ClusterImpl(String clusterName) {
+  /**
+   * [ HostName -> [ ... ] ]
+   */
+  private Map<String, Map<String, Map<String, ServiceComponentHost>>>
+      serviceComponentHostsByHost;
+
+  public ClusterImpl(Clusters clusters, long clusterId, String clusterName) {
+    this.clusters = clusters;
+    this.clusterId = clusterId;
     this.clusterName = clusterName;
-    this.hosts = new HashMap<String, Host>();
     this.serviceComponentHosts = new HashMap<String,
         Map<String,Map<String,ServiceComponentHost>>>();
-  }
-
-  private Host getHost(String hostName) throws AmbariException {
-    if (!hosts.containsKey(hostName)) {
-      throw new HostNotFoundException(hostName);
-    }
-    return hosts.get(hostName);
+    this.serviceComponentHostsByHost = new HashMap<String,
+        Map<String,Map<String,ServiceComponentHost>>>();
   }
 
   public ServiceComponentHost getServiceComponentHost(String serviceName,
-      String serviceComponentName, String hostName) throws AmbariException {
+      String serviceComponentName, String hostname) throws AmbariException {
     if (!serviceComponentHosts.containsKey(serviceName)
         || !serviceComponentHosts.get(serviceName)
             .containsKey(serviceComponentName)
         || !serviceComponentHosts.get(serviceName).get(serviceComponentName)
-            .containsKey(hostName)) {
+            .containsKey(hostname)) {
       throw new ServiceComponentHostNotFoundException(serviceName,
-          serviceComponentName, hostName);
+          serviceComponentName, hostname);
     }
     return serviceComponentHosts.get(serviceName).get(serviceComponentName)
-        .get(hostName);
+        .get(hostname);
   }
 
   @Override
-  public String getClusterName() {
+  public synchronized String getClusterName() {
     return clusterName;
   }
 
   @Override
-  public synchronized void addHost(String hostName) throws AmbariException {
-    if (hosts.containsKey(hostName)) {
-      throw new AmbariException("Duplicate entry for Host"
-          + ", hostName=" + hostName);
-    }
-    hosts.put(hostName, new HostImpl(hostName));
+  public synchronized void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
   }
 
   @Override
   public synchronized void addServiceComponentHost(String serviceName,
-      String componentName, String hostName, boolean isClient)
+      String componentName, String hostname, boolean isClient)
       throws AmbariException {
+    List<Cluster> cs = clusters.getClustersForHost(hostname);
+    boolean clusterFound = false;
+    for (Cluster c : cs) {
+      if (c.getClusterId() == this.clusterId) {
+        clusterFound = true;
+        break;
+      }
+    }
+    if (!clusterFound) {
+      throw new AmbariException("Host does not belong this cluster"
+          + ", hostname=" + hostname
+          + ", clusterName=" + clusterName
+          + ", clusterId=" + clusterId);
+    }
+
     if (!serviceComponentHosts.containsKey(serviceName)) {
       serviceComponentHosts.put(serviceName,
           new HashMap<String, Map<String,ServiceComponentHost>>());
@@ -97,59 +113,60 @@ public class ClusterImpl implements Clus
     }
 
     if (serviceComponentHosts.get(serviceName).get(componentName).
-        containsKey(hostName)) {
+        containsKey(hostname)) {
       throw new AmbariException("Duplicate entry for ServiceComponentHost"
           + ", serviceName=" + serviceName
           + ", serviceComponentName" + componentName
-          + ", hostName= " + hostName);
+          + ", hostname= " + hostname);
     }
-    serviceComponentHosts.get(serviceName).get(componentName).put(hostName,
-        new ServiceComponentHostImpl(componentName, hostName, isClient));
-  }
 
-  @Override
-  public HostState getHostState(String hostName) throws AmbariException{
-    return getHost(hostName).getState();
-  }
+    if (!serviceComponentHostsByHost.containsKey(hostname)) {
+      serviceComponentHostsByHost.put(hostname,
+          new HashMap<String, Map<String,ServiceComponentHost>>());
+    }
+    if (!serviceComponentHostsByHost.get(hostname).containsKey(serviceName)) {
+      serviceComponentHostsByHost.get(hostname).put(serviceName,
+          new HashMap<String, ServiceComponentHost>());
+    }
 
-  @Override
-  public void setHostState(String hostName, HostState state)
-      throws AmbariException {
-    getHost(hostName).setState(state);
-  }
+    ServiceComponentHost impl =
+        new ServiceComponentHostImpl(clusterId,
+            serviceName, componentName, hostname, isClient);
 
-  @Override
-  public void handleHostEvent(String hostName, HostEvent event)
-      throws AmbariException, InvalidStateTransitonException {
-    if (!hosts.containsKey(hostName)) {
-      throw new HostNotFoundException(hostName);
-    }
-    hosts.get(hostName).handleEvent(event);
+    serviceComponentHosts.get(serviceName).get(componentName).put(hostname,
+        impl);
+    serviceComponentHostsByHost.get(hostname).get(serviceName).put(
+        componentName, impl);
   }
 
   @Override
-  public ServiceComponentHostState getServiceComponentHostState(String service,
-      String serviceComponent, String hostName) throws AmbariException {
+  public synchronized ServiceComponentHostState getServiceComponentHostState(String service,
+      String serviceComponent, String hostname) throws AmbariException {
     return
-        getServiceComponentHost(service, serviceComponent, hostName).getState();
+        getServiceComponentHost(service, serviceComponent, hostname).getState();
   }
 
   @Override
-  public void setServiceComponentHostState(String service,
-      String serviceComponent, String hostName,
+  public synchronized void setServiceComponentHostState(String service,
+      String serviceComponent, String hostname,
       ServiceComponentHostState state) throws AmbariException {
-    getServiceComponentHost(service, serviceComponent, hostName)
+    getServiceComponentHost(service, serviceComponent, hostname)
       .setState(state);
   }
 
   @Override
-  public void handleServiceComponentHostEvent(String service,
-      String serviceComponent, String hostName,
+  public synchronized void handleServiceComponentHostEvent(String service,
+      String serviceComponent, String hostname,
       ServiceComponentHostEvent event)
       throws AmbariException, InvalidStateTransitonException {
-    getServiceComponentHost(service, serviceComponent, hostName)
+    getServiceComponentHost(service, serviceComponent, hostname)
       .handleEvent(event);
 
   }
 
+  @Override
+  public long getClusterId() {
+    return clusterId;
+  }
+
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java Mon Oct  1 18:35:19 2012
@@ -22,8 +22,11 @@ import java.util.List;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.state.live.host.Host;
-import org.apache.ambari.server.state.live.host.HostState;
 
+/**
+ * Single entity that tracks all clusters and hosts that are managed
+ * by the Ambari server
+ */
 public interface Clusters {
 
   /**
@@ -39,26 +42,48 @@ public interface Clusters {
    */
   public Cluster getCluster(String clusterName) throws AmbariException;
 
-  public boolean handleHeartbeat(String hostname, long timestamp);
-
-  public void updateStatus(String hostname, String status);
-
+  /**
+   * Get all hosts being tracked by the Ambari server
+   * @return
+   */
   public List<Host> getAllHosts();
 
-  public List<String> getHostComponents(String hostname);
-
-  public void handleRegistration(String hostname);
-
   /**
    * Returns all the cluster names for this hostname.
    * @param hostname
    * @return List of cluster names
+   * @throws AmbariException
+   */
+  public List<Cluster> getClustersForHost(String hostname)
+      throws AmbariException;
+
+  /**
+   * Get a Host object managed by this server
+   * @param hostname Name of the host requested
+   * @return Host object
+   * @throws AmbariException
    */
-  public List<Cluster> getClusters(String hostname);
+  public Host getHost(String hostname) throws AmbariException;
 
   /**
-   * Get a Host object
+   * Add a Host object to be managed by this server
+   * @param hostname Host to be added
+   * @throws AmbariException
    */
-  public Host getHost(String host) throws AmbariException;
+  public void addHost(String hostname) throws AmbariException;
+
+  /**
+   * Map host to the given cluster.
+   * A host can belong to multiple clusters.
+   * @param hostname
+   * @param clusterName
+   * @throws AmbariException
+   */
+  public void mapHostToCluster(String hostname, String clusterName)
+      throws AmbariException;
+
+  // TODO for Jitendra to fix in Heartbeat Handler as this function
+  // will not be supported
+  public List<String> getHostComponents(String hostname);
 
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java Mon Oct  1 18:35:19 2012
@@ -18,23 +18,33 @@
 
 package org.apache.ambari.server.state.live;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ClusterNotFoundException;
+import org.apache.ambari.server.HostNotFoundException;
 import org.apache.ambari.server.state.live.host.Host;
+import org.apache.ambari.server.state.live.host.HostImpl;
 
 public class ClustersImpl implements Clusters {
 
   private Map<String, Cluster> clusters;
-
-  // TODO
-  // private Map<String, Host> hosts;
+  private Map<Long, Cluster> clustersById;
+  private Map<String, Host> hosts;
+  private Map<String, Set<Cluster>> hostClusterMap;
 
   public ClustersImpl() {
     clusters = new HashMap<String, Cluster>();
+    clustersById = new HashMap<Long, Cluster>();
+    hosts = new HashMap<String, Host>();
+    hostClusterMap = new HashMap<String, Set<Cluster>>();
+
   }
 
   @Override
@@ -44,11 +54,18 @@ public class ClustersImpl implements Clu
       throw new AmbariException("Duplicate entry for Cluster"
           + ", clusterName= " + clusterName);
     }
-    clusters.put(clusterName, new ClusterImpl(clusterName));
+    // TODO persist cluster into DB
+    // retrieve new cluster id
+    // add cluster id -> cluster mapping into clustersById
+    long clusterId = 0;
+    Cluster impl = new ClusterImpl(this, clusterId, clusterName);
+    clusters.put(clusterName, impl);
+    clustersById.put(clusterId, impl);
   }
 
   @Override
-  public Cluster getCluster(String clusterName) throws AmbariException {
+  public synchronized Cluster getCluster(String clusterName)
+      throws AmbariException {
     if (!clusters.containsKey(clusterName)) {
       throw new ClusterNotFoundException(clusterName);
     }
@@ -56,43 +73,49 @@ public class ClustersImpl implements Clu
   }
 
   @Override
-  public boolean handleHeartbeat(String hostname, long timestamp) {
-    // TODO Auto-generated method stub
-    return false;
+  public synchronized List<Host> getAllHosts() {
+    return new ArrayList<Host>(hosts.values());
   }
 
   @Override
-  public void updateStatus(String hostname, String status) {
-    // TODO Auto-generated method stub
-    
-  }
-
-  @Override
-  public List<Host> getAllHosts() {
-    // TODO Auto-generated method stub
-    return null;
+  public synchronized List<Cluster> getClustersForHost(String hostname)
+      throws AmbariException {
+    if (!hostClusterMap.containsKey(hostname)) {
+      throw new HostNotFoundException(hostname);
+    }
+    List<Cluster> cList = new ArrayList<Cluster>();
+    cList.addAll(hostClusterMap.get(hostname));
+    return cList;
   }
 
   @Override
-  public List<String> getHostComponents(String hostname) {
-    // TODO Auto-generated method stub
-    return null;
+  public synchronized Host getHost(String hostname) throws AmbariException {
+    return hosts.get(hostname);
   }
 
   @Override
-  public void handleRegistration(String hostname) {
-    // TODO Auto-generated method stub
-    
+  public synchronized void addHost(String hostname) throws AmbariException {
+    if (hosts.containsKey(hostname)) {
+      throw new AmbariException("Duplicate entry for Host"
+          + ", hostName= " + hostname);
+    }
+    hosts.put(hostname, new HostImpl(hostname));
+    hostClusterMap.put(hostname, new HashSet<Cluster>());
   }
 
   @Override
-  public List<Cluster> getClusters(String hostname) {
-    // TODO Auto-generated method stub
-    return null;
+  public synchronized void mapHostToCluster(String hostname,
+      String clusterName) throws AmbariException {
+    getCluster(clusterName);
+    getHost(hostname);
+    if (!hostClusterMap.containsKey(hostname)) {
+      throw new HostNotFoundException(hostname);
+    }
+    hostClusterMap.get(hostname).add(getCluster(clusterName));
   }
 
   @Override
-  public Host getHost(String host) throws AmbariException {
+  public List<String> getHostComponents(String hostname) {
     // TODO Auto-generated method stub
     return null;
   }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java Mon Oct  1 18:35:19 2012
@@ -136,12 +136,12 @@ public class HostImpl implements Host {
    // Transition from INIT state
    // when the initial registration request is received
    .addTransition(HostState.INIT, HostState.WAITING_FOR_HOST_STATUS_UPDATES,
-       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())       
-       
+       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())
+
    // Transition from WAITING_FOR_STATUS_UPDATES state
    // when the host has responded to its status update requests
    // TODO this will create problems if the host is not healthy
-   // TODO Based on discussion with Jitendra, ignoring this for now    
+   // TODO Based on discussion with Jitendra, ignoring this for now
    .addTransition(HostState.WAITING_FOR_HOST_STATUS_UPDATES, HostState.HEALTHY,
        HostEventType.HOST_STATUS_UPDATES_RECEIVED,
        new HostStatusUpdatesReceivedTransition())
@@ -168,10 +168,10 @@ public class HostImpl implements Host {
    .addTransition(HostState.HEALTHY, HostState.UNHEALTHY,
        HostEventType.HOST_HEARTBEAT_UNHEALTHY,
        new HostBecameUnhealthyTransition())
-   // if a new registration request is received   
+   // if a new registration request is received
    .addTransition(HostState.HEALTHY,
        HostState.WAITING_FOR_HOST_STATUS_UPDATES,
-       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())       
+       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())
 
    // Transitions from UNHEALTHY state
    // when a normal heartbeat is received
@@ -186,20 +186,20 @@ public class HostImpl implements Host {
    .addTransition(HostState.UNHEALTHY, HostState.HEARTBEAT_LOST,
        HostEventType.HOST_HEARTBEAT_LOST,
        new HostHeartbeatLostTransition())
-   // if a new registration request is received   
+   // if a new registration request is received
    .addTransition(HostState.UNHEALTHY,
        HostState.WAITING_FOR_HOST_STATUS_UPDATES,
-       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())       
+       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())
 
    // Transitions from HEARTBEAT_LOST state
    // when a heartbeat is not received within the configured timeout period
    .addTransition(HostState.HEARTBEAT_LOST, HostState.HEARTBEAT_LOST,
        HostEventType.HOST_HEARTBEAT_LOST)
-   // if a new registration request is received   
+   // if a new registration request is received
    .addTransition(HostState.HEARTBEAT_LOST,
        HostState.WAITING_FOR_HOST_STATUS_UPDATES,
-       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())       
-       
+       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())
+
    .installTopology();
 
   private final StateMachine<HostState, HostEventType, HostEvent> stateMachine;

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostStatusUpdatesReceivedEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostStatusUpdatesReceivedEvent.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostStatusUpdatesReceivedEvent.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostStatusUpdatesReceivedEvent.java Mon Oct  1 18:35:19 2012
@@ -21,7 +21,7 @@ package org.apache.ambari.server.state.l
 public class HostStatusUpdatesReceivedEvent extends HostEvent {
 
   private final long timestamp;
-  
+
   // TODO need to add any additional information required for verification
   // tracking
   public HostStatusUpdatesReceivedEvent(String hostName,

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/svccomphost/ServiceComponentHost.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/svccomphost/ServiceComponentHost.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/svccomphost/ServiceComponentHost.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/svccomphost/ServiceComponentHost.java Mon Oct  1 18:35:19 2012
@@ -27,6 +27,17 @@ import org.apache.ambari.server.state.li
 public interface ServiceComponentHost {
 
   /**
+   * Get the Cluster that this object maps to
+   */
+  public long getClusterId();
+
+  /**
+   * Get the Service this object maps to
+   * @return Name of the Service
+   */
+  public String getServiceName();
+
+  /**
    * Get the ServiceComponent this object maps to
    * @return Name of the ServiceComponent
    */

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/svccomphost/ServiceComponentHostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/svccomphost/ServiceComponentHostImpl.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/svccomphost/ServiceComponentHostImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/svccomphost/ServiceComponentHostImpl.java Mon Oct  1 18:35:19 2012
@@ -41,6 +41,8 @@ public class ServiceComponentHostImpl im
 
   private ServiceComponentHostState state;
 
+  private final long clusterId;
+  private final String serviceName;
   private final String serviceComponentName;
   private final String hostName;
 
@@ -357,7 +359,8 @@ public class ServiceComponentHostImpl im
     }
   }
 
-  public ServiceComponentHostImpl(String serviceComponentName,
+  public ServiceComponentHostImpl(long clusterId,
+      String serviceName, String serviceComponentName,
       String hostName, boolean isClient) {
     super();
     if (isClient) {
@@ -368,6 +371,8 @@ public class ServiceComponentHostImpl im
     ReadWriteLock rwLock = new ReentrantReadWriteLock();
     this.readLock = rwLock.readLock();
     this.writeLock = rwLock.writeLock();
+    this.clusterId = clusterId;
+    this.serviceName = serviceName;
     this.serviceComponentName = serviceComponentName;
     this.hostName = hostName;
     this.state = new ServiceComponentHostState();
@@ -533,4 +538,14 @@ public class ServiceComponentHostImpl im
     }
   }
 
+  @Override
+  public long getClusterId() {
+    return clusterId;
+  }
+
+  @Override
+  public String getServiceName() {
+    return serviceName;
+  }
+
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyList.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyList.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyList.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyList.java Mon Oct  1 18:35:19 2012
@@ -25,8 +25,8 @@ public class JaxbMapKeyList {
   @XmlElement public String  key;
   @XmlElement public List<String> value;
 
-  private JaxbMapKeyList() {} 
-  
+  private JaxbMapKeyList() {}
+
   public JaxbMapKeyList(String key, List<String> value)
   {
     this.key   = key;

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMap.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMap.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMap.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMap.java Mon Oct  1 18:35:19 2012
@@ -25,8 +25,8 @@ public class JaxbMapKeyMap {
   @XmlElement public String  key;
   @XmlElement public List<JaxbMapKeyVal> value;
 
-  private JaxbMapKeyMap() {} 
-  
+  private JaxbMapKeyMap() {}
+
   public JaxbMapKeyMap(String key, List<JaxbMapKeyVal> value)
   {
     this.key   = key;

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMapAdapter.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMapAdapter.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMapAdapter.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMapAdapter.java Mon Oct  1 18:35:19 2012
@@ -28,7 +28,7 @@ public class JaxbMapKeyMapAdapter extend
     XmlAdapter<List<JaxbMapKeyMap>, Map<String, Map<String, String>>> {
 
   private static JaxbMapKeyValAdapter mapAdapter = new JaxbMapKeyValAdapter();
-  
+
   @Override
   public List<JaxbMapKeyMap> marshal(Map<String, Map<String, String>> map)
       throws Exception {
@@ -56,4 +56,4 @@ public class JaxbMapKeyMapAdapter extend
     }
     return map;
   }
-}
\ No newline at end of file
+}

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyVal.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyVal.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyVal.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyVal.java Mon Oct  1 18:35:19 2012
@@ -30,11 +30,11 @@ public class JaxbMapKeyVal {
   @XmlElement public String  key;
   @XmlElement public String value;
 
-  private JaxbMapKeyVal() {} 
-  
+  private JaxbMapKeyVal() {}
+
   public JaxbMapKeyVal(String key, String value)
   {
     this.key   = key;
     this.value = value;
   }
-}
\ No newline at end of file
+}

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java Mon Oct  1 18:35:19 2012
@@ -56,36 +56,36 @@ public class TestActionScheduler {
    // ha.setManifest("1-977-manifest");
     s.addHostAction(hostname, ha);
     when(db.getPendingStages()).thenReturn(stages);
-    
+
     //Keep large number of attempts so that the task is not expired finally
     //Small action timeout to test rescheduling
     ActionScheduler scheduler = new ActionScheduler(1000, 100, db, aq, fsm, 10000);
     // Start the thread
     scheduler.start();
-    
+
     Thread.sleep(1000);
     List<AgentCommand> ac = aq.dequeueAll(hostname);
     assertEquals(1, ac.size());
     assertTrue(ac.get(0) instanceof ExecutionCommand);
     assertEquals("1-977", ((ExecutionCommand) (ac.get(0))).getCommandId());
-    
+
     //The action status has not changed, it should be queued again.
     Thread.sleep(1000);
     ac = aq.dequeueAll(hostname);
     assertEquals(1, ac.size());
     assertTrue(ac.get(0) instanceof ExecutionCommand);
     assertEquals("1-977", ((ExecutionCommand) (ac.get(0))).getCommandId());
-    
+
     //Now change the action status
     hrc.setStatus(HostRoleStatus.COMPLETED);
     ac = aq.dequeueAll(hostname);
-    
+
     //Wait for sometime, it shouldn't be scheduled this time.
     Thread.sleep(1000);
     ac = aq.dequeueAll(hostname);
     assertEquals(0, ac.size());
   }
-  
+
   /**
    * Test whether scheduler times out an action
    */
@@ -108,13 +108,13 @@ public class TestActionScheduler {
     // ha.setManifest("1-977-manifest");
     s.addHostAction(hostname, ha);
     when(db.getPendingStages()).thenReturn(stages);
-    
+
     //Keep large number of attempts so that the task is not expired finally
     //Small action timeout to test rescheduling
     ActionScheduler scheduler = new ActionScheduler(100, 100, db, aq, fsm, 3);
     // Start the thread
     scheduler.start();
-    
+
     Thread.sleep(500);
     //TODO timeoutHostRole must be called exactly once but in this case the state
     //in the db continues to be pending therefore it is processed multiple times.

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java Mon Oct  1 18:35:19 2012
@@ -51,17 +51,17 @@ public class AgentResourceTest extends J
   HeartBeatHandler handler;
   ActionManager actionManager;
   Injector injector;
-  
+
   public AgentResourceTest() {
     super(new WebAppDescriptor.Builder(PACKAGE_NAME).servletClass(ServletContainer.class)
         .build());
   }
-  
+
   public class MockModule extends AbstractModule {
-    
+
     RegistrationResponse response = new RegistrationResponse();
     HeartBeatResponse hresponse = new HeartBeatResponse();
-    
+
     @Override
     protected void configure() {
       handler = mock(HeartBeatHandler.class);
@@ -81,9 +81,9 @@ public class AgentResourceTest extends J
       bind(ActionManager.class).toInstance(actionManager);
       bind(AgentCommand.class).to(ExecutionCommand.class);
       bind(HeartBeatHandler.class).toInstance(handler);
-    }    
+    }
   }
-  
+
   @Override
   public void setUp() throws Exception {
     super.setUp();
@@ -91,7 +91,7 @@ public class AgentResourceTest extends J
     injector = Guice.createInjector(new MockModule());
     injector.injectMembers(handler);
   }
-  
+
   private JSONObject createDummyJSONRegister() throws JSONException {
     JSONObject json = new JSONObject();
     json.append("responseId" , -1);
@@ -99,7 +99,7 @@ public class AgentResourceTest extends J
     json.append("hostname",   "dummyHost");
     return json;
   }
-  
+
   private JSONObject createDummyHeartBeat() throws JSONException {
     JSONObject json = new JSONObject();
     json.put("responseId", -1);
@@ -107,7 +107,7 @@ public class AgentResourceTest extends J
     json.put("hostname", "dummyHost");
     return json;
   }
-  
+
   @Test
   public void agentRegistration() throws UniformInterfaceException, JSONException {
     RegistrationResponse response;
@@ -117,14 +117,14 @@ public class AgentResourceTest extends J
     LOG.info("Returned from Server " + response.getResponseStatus());
     Assert.assertEquals(response.getResponseStatus(), RegistrationStatus.OK);
   }
-  
+
   @Test
   public void agentHeartBeat() throws UniformInterfaceException, JSONException {
     HeartBeatResponse response;
     WebResource resource = resource();
     response = resource.path("/heartbeat/dummyhost").type(MediaType.APPLICATION_JSON)
         .post(HeartBeatResponse.class, createDummyHeartBeat());
-    LOG.info("Returned from Server: " + "clusterid = " + response.getClusterId() 
+    LOG.info("Returned from Server: " + "clusterid = " + response.getClusterId()
         + " responseid=" +   response.getResponseId());
     Assert.assertEquals(response.getResponseId(), 0L);
   }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapResourceTest.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapResourceTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapResourceTest.java Mon Oct  1 18:35:19 2012
@@ -51,17 +51,17 @@ import com.sun.jersey.test.framework.Web
  *  Testing bootstrap API.
  */
 public class BootStrapResourceTest extends JerseyTest {
-  
+
   static String PACKAGE_NAME = "org.apache.ambari.server.api.rest";
   private static Log LOG = LogFactory.getLog(AgentResourceTest.class);
   Injector injector;
   BootStrapImpl bsImpl;
-  
+
   public BootStrapResourceTest() {
     super(new WebAppDescriptor.Builder(PACKAGE_NAME).servletClass(ServletContainer.class)
         .build());
   }
-  
+
   public class MockModule extends AbstractModule {
     @Override
     protected void configure() {
@@ -70,22 +70,22 @@ public class BootStrapResourceTest exten
       when(bsImpl.runBootStrap(any(SshHostInfo.class))).thenReturn(generateBSResponse());
       bind(BootStrapImpl.class).toInstance(bsImpl);
       requestStaticInjection(BootStrapResource.class);
-    }    
+    }
   }
-  
+
   @Override
   public void setUp() throws Exception {
     super.setUp();
     injector = Guice.createInjector(new MockModule());
   }
-  
+
   protected JSONObject createDummySshInfo() throws JSONException {
     JSONObject json = new JSONObject();
     json.put("sshkey", "awesome");
     json.put("hosts", new ArrayList<String>());
     return json;
   }
-  
+
   protected BSResponse generateBSResponse() {
     BSResponse response = new BSResponse();
     response.setLog("Logging");
@@ -93,7 +93,7 @@ public class BootStrapResourceTest exten
     response.setStatus(BSRunStat.OK);
     return response;
   }
-  
+
   protected BootStrapStatus generateDummyBSStatus() {
     BootStrapStatus status = new BootStrapStatus();
     status.setLog("Logging ");
@@ -101,24 +101,24 @@ public class BootStrapResourceTest exten
     status.setHostsStatus(new ArrayList<BSHostStatus>());
     return status;
   }
-  
+
   @Test
   public void bootStrapGet() throws UniformInterfaceException, JSONException {
     WebResource webResource = resource();
     BootStrapStatus status = webResource.path("/bootstrap/0").type(
         MediaType.APPLICATION_JSON)
         .get(BootStrapStatus.class);
-    LOG.info("GET Response from the API " + status.getLog() + " " + 
+    LOG.info("GET Response from the API " + status.getLog() + " " +
         status.getStatus());
     Assert.assertEquals(status.getStatus(), BSStat.ERROR);
   }
-  
+
   @Test
   public void bootStrapPost() throws UniformInterfaceException, JSONException {
     WebResource webResource = resource();
     JSONObject object = webResource.path("/bootstrap").type(
         MediaType.APPLICATION_JSON).post(JSONObject.class, createDummySshInfo());
-    
+
     Assert.assertEquals("OK", object.get("status"));
   }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapTest.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/bootstrap/BootStrapTest.java Mon Oct  1 18:35:19 2012
@@ -44,23 +44,23 @@ import org.junit.rules.TemporaryFolder;
 public class BootStrapTest extends TestCase {
   private static Log LOG = LogFactory.getLog(BootStrapTest.class);
   public TemporaryFolder temp = new TemporaryFolder();
-  
+
   @Before
   public void setUp() throws IOException {
     temp.create();
   }
-  
+
   @After
   public void tearDown() throws IOException {
     temp.delete();
   }
-  
+
   @Test
   public void testRun() throws Exception {
     Properties properties = new Properties();
     String bootdir =  temp.newFolder("bootdir").toString();
     LOG.info("Bootdir is " + bootdir);
-    properties.setProperty(Configuration.BOOTSTRAP_DIR, 
+    properties.setProperty(Configuration.BOOTSTRAP_DIR,
        bootdir);
     properties.setProperty(Configuration.BOOTSTRAP_SCRIPT, "echo");
     properties.setProperty(Configuration.SRVR_KSTR_DIR_KEY, "target" + File.separator + "classes");
@@ -84,14 +84,14 @@ public class BootStrapTest extends TestC
         Thread.sleep(100);
         num++;
     }
-    LOG.info("Status: log " + status.getLog() + " status=" + status.getStatus() 
+    LOG.info("Status: log " + status.getLog() + " status=" + status.getStatus()
         );
     /* Note its an echo command so it should echo host1,host2 */
     Assert.assertTrue(status.getLog().contains("host1,host2"));
     Assert.assertEquals(BSStat.SUCCESS, status.getStatus());
   }
-  
-  
+
+
   @Test
   public void testPolling() throws Exception {
     File tmpFolder = temp.newFolder("bootstrap");
@@ -115,8 +115,8 @@ public class BootStrapTest extends TestC
     Assert.assertEquals(polledHostStatus.get(1).getHostName(), "host2");
     Assert.assertEquals(polledHostStatus.get(1).getLog(), "err_log_2");
     Assert.assertEquals(polledHostStatus.get(1).getStatus(), "DONE");
-    
+
 
   }
-  
+
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/security/CertGenerationTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/security/CertGenerationTest.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/security/CertGenerationTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/security/CertGenerationTest.java Mon Oct  1 18:35:19 2012
@@ -42,24 +42,24 @@ public class CertGenerationTest extends 
 	
   private static Log LOG = LogFactory.getLog(CertGenerationTest.class);
   public TemporaryFolder temp = new TemporaryFolder();
-  
+
   Injector injector;
-  
+
   private static CertificateManager certMan;
-  
+
   @Inject
   static void init(CertificateManager instance) {
     certMan = instance;
   }
 
-  
+
   private class SecurityModule extends AbstractModule {
     @Override
     protected void configure() {
       requestStaticInjection(CertGenerationTest.class);
     }
   }
-	  
+	
   @Before
   public void setUp() throws IOException {
     temp.create();
@@ -69,37 +69,37 @@ public class CertGenerationTest extends 
     FileOutputStream out = new FileOutputStream(temp.getRoot().getAbsolutePath() + File.separator + Configuration.CONFIG_FILE);
     props.store(out, "");
     out.close();
-  
+
     injector = Guice.createInjector(new SecurityModule());
     certMan = injector.getInstance(CertificateManager.class);
-  
+
     certMan.initRootCert();
   }
-	  
+	
   @After
   public void tearDown() throws IOException {
 	  temp.delete();
   }
-	  
+	
   @Test
   public void testServerCertGen() throws Exception {
-    
+
     File serverCrt = new File(temp.getRoot().getAbsoluteFile() +
     						  File.separator + Configuration.SRVR_CRT_NAME_DEFAULT);
     assertTrue(serverCrt.exists());
   }
-  
+
   @Test
   public void testServerKeyGen() throws Exception {
-    
+
     File serverKey = new File(temp.getRoot().getAbsoluteFile() +
     						  File.separator + Configuration.SRVR_KEY_NAME_DEFAULT);
     assertTrue(serverKey.exists());
   }
-  
+
   @Test
   public void testServerKeystoreGen() throws Exception {
-    
+
     File serverKeyStrore = new File(temp.getRoot().getAbsoluteFile() +
     						  File.separator + Configuration.KSTR_NAME_DEFAULT);
     assertTrue(serverKeyStrore.exists());

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java Mon Oct  1 18:35:19 2012
@@ -56,7 +56,8 @@ public class TestClusterImpl {
     clusters.addCluster("c1");
     c1 = clusters.getCluster("c1");
     Assert.assertEquals("c1", c1.getClusterName());
-    c1.addHost(h1);
+    clusters.addHost(h1);
+    clusters.mapHostToCluster(h1, "c1");
     c1.addServiceComponentHost(s1, sc1, h1, false);
   }
 
@@ -68,10 +69,10 @@ public class TestClusterImpl {
 
   @Test
   public void testAddHost() throws AmbariException {
-    c1.addHost("h2");
+    clusters.addHost("h2");
 
     try {
-      c1.addHost("h2");
+      clusters.addHost("h2");
       fail("Duplicate add should fail");
     }
     catch (AmbariException e) {
@@ -82,6 +83,16 @@ public class TestClusterImpl {
 
   @Test
   public void testAddServiceComponentHost() throws AmbariException {
+    try {
+      c1.addServiceComponentHost("s2", "sc2", "h2", false);
+      fail("Expected failure on invalid cluster/host");
+    } catch (Exception e) {
+      // Expected
+    }
+
+    clusters.addCluster("c2");
+    clusters.addHost("h2");
+    clusters.mapHostToCluster("h2", "c2");
     c1.addServiceComponentHost("s2", "sc2", "h2", false);
 
     try {
@@ -96,13 +107,14 @@ public class TestClusterImpl {
 
   @Test
   public void testGetHostState() throws AmbariException {
-    Assert.assertEquals(HostState.INIT, c1.getHostState(h1));
+    Assert.assertEquals(HostState.INIT, clusters.getHost(h1).getState());
   }
 
   @Test
   public void testSetHostState() throws AmbariException {
-    c1.setHostState(h1, HostState.HEARTBEAT_LOST);
-    Assert.assertEquals(HostState.HEARTBEAT_LOST, c1.getHostState(h1));
+    clusters.getHost(h1).setState(HostState.HEARTBEAT_LOST);
+    Assert.assertEquals(HostState.HEARTBEAT_LOST,
+        clusters.getHost(h1).getState());
   }
 
   @Test
@@ -124,16 +136,17 @@ public class TestClusterImpl {
     AgentVersion agentVersion = new AgentVersion("0.0.x");
     long currentTime = 1001;
 
-    c1.handleHostEvent(h1, new HostRegistrationRequestEvent(h1, agentVersion,
-        currentTime, hostInfo));
+    clusters.getHost(h1).handleEvent(new HostRegistrationRequestEvent(
+        h1, agentVersion, currentTime, hostInfo));
 
     Assert.assertEquals(HostState.WAITING_FOR_HOST_STATUS_UPDATES,
-        c1.getHostState(h1));
+        clusters.getHost(h1).getState());
 
-    c1.setHostState(h1, HostState.HEARTBEAT_LOST);
+    clusters.getHost(h1).setState(HostState.HEARTBEAT_LOST);
 
     try {
-      c1.handleHostEvent(h1, new HostHealthyHeartbeatEvent(h1, currentTime));
+      clusters.getHost(h1).handleEvent(
+          new HostHealthyHeartbeatEvent(h1, currentTime));
       fail("Exception should be thrown on invalid event");
     }
     catch (InvalidStateTransitonException e) {

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClustersImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClustersImpl.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClustersImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClustersImpl.java Mon Oct  1 18:35:19 2012
@@ -19,10 +19,14 @@
 package org.apache.ambari.server.state.live;
 
 import static org.junit.Assert.fail;
+
+import java.util.List;
+
 import junit.framework.Assert;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ClusterNotFoundException;
+import org.apache.ambari.server.state.live.host.Host;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -54,7 +58,7 @@ public class TestClustersImpl {
   }
 
   @Test
-  public void testAddCluster() throws AmbariException {
+  public void testAddAndGetCluster() throws AmbariException {
 
     String c1 = "foo";
     String c2 = "foo";
@@ -86,4 +90,80 @@ public class TestClustersImpl {
     Assert.assertEquals(c2, clusters.getCluster(c2).getClusterName());
 
   }
+
+
+  @Test
+  public void testAddAndGetHost() throws AmbariException {
+    String h1 = "h1";
+    String h2 = "h2";
+    String h3 = "h3";
+
+    clusters.addHost(h1);
+
+    try {
+      clusters.addHost(h1);
+      fail("Expected exception on duplicate host entry");
+    } catch (Exception e) {
+      // Expected
+    }
+
+    clusters.addHost(h2);
+    clusters.addHost(h3);
+
+    List<Host> hosts = clusters.getAllHosts();
+    Assert.assertEquals(3, hosts.size());
+
+    Assert.assertNotNull(clusters.getHost(h1));
+    Assert.assertNotNull(clusters.getHost(h2));
+    Assert.assertNotNull(clusters.getHost(h3));
+
+  }
+
+  @Test
+  public void testClusterHostMapping() throws AmbariException {
+    String c1 = "c1";
+    String c2 = "c2";
+    String h1 = "h1";
+    String h2 = "h2";
+    String h3 = "h3";
+
+    try {
+      clusters.mapHostToCluster(h1, c1);
+      fail("Expected exception for invalid cluster/host");
+    } catch (Exception e) {
+      // Expected
+    }
+
+    clusters.addCluster(c1);
+    clusters.addCluster(c2);
+    Assert.assertNotNull(clusters.getCluster(c1));
+    Assert.assertNotNull(clusters.getCluster(c2));
+    try {
+      clusters.mapHostToCluster(h1, c1);
+      fail("Expected exception for invalid host");
+    } catch (Exception e) {
+      // Expected
+    }
+
+    clusters.addHost(h1);
+    clusters.addHost(h2);
+    clusters.addHost(h3);
+    Assert.assertNotNull(clusters.getHost(h1));
+
+    clusters.mapHostToCluster(h1, c1);
+    clusters.mapHostToCluster(h1, c2);
+    clusters.mapHostToCluster(h2, c1);
+    clusters.mapHostToCluster(h2, c2);
+    clusters.mapHostToCluster(h1, c2);
+
+    List<Cluster> c = clusters.getClustersForHost(h3);
+    Assert.assertEquals(0, c.size());
+
+    c = clusters.getClustersForHost(h1);
+    Assert.assertEquals(2, c.size());
+
+    c = clusters.getClustersForHost(h2);
+    Assert.assertEquals(2, c.size());
+
+  }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.java Mon Oct  1 18:35:19 2012
@@ -210,7 +210,7 @@ public class TestHostImpl {
       fail("Invalid event should have triggered an exception");
     } catch (Exception e) {
       // Expected
-    }       
+    }
     verifyHostState(host, HostState.HEARTBEAT_LOST);
 
     try {
@@ -218,20 +218,20 @@ public class TestHostImpl {
       fail("Invalid event should have triggered an exception");
     } catch (Exception e) {
       // Expected
-    }       
+    }
     verifyHostState(host, HostState.HEARTBEAT_LOST);
   }
-  
+
   @Test
   public void testHostRegistrationsInAnyState() throws Exception {
     HostImpl host = new HostImpl("foo");
     long counter = 0;
 
     registerHost(host);
-    
+
     ensureHostUpdatesReceived(host);
     registerHost(host);
-    
+
     ensureHostUpdatesReceived(host);
     sendHealthyHeartbeat(host, ++counter);
     verifyHostState(host, HostState.HEALTHY);
@@ -247,9 +247,9 @@ public class TestHostImpl {
     verifyHostState(host, HostState.HEARTBEAT_LOST);
     registerHost(host);
     ensureHostUpdatesReceived(host);
-    
+
     host.setState(HostState.INIT);
     registerHost(host);
-    
+
   }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/svccomphost/TestServiceComponentHostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/svccomphost/TestServiceComponentHostImpl.java?rev=1392503&r1=1392502&r2=1392503&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/svccomphost/TestServiceComponentHostImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/svccomphost/TestServiceComponentHostImpl.java Mon Oct  1 18:35:19 2012
@@ -31,10 +31,12 @@ import org.junit.Test;
 
 public class TestServiceComponentHostImpl {
 
-  private ServiceComponentHostImpl createNewServiceComponentHost(String svcComponent,
+  private ServiceComponentHostImpl createNewServiceComponentHost(long clusterId,
+      String svc,
+      String svcComponent,
       String hostName, boolean isClient) {
-    ServiceComponentHostImpl impl = new ServiceComponentHostImpl(svcComponent,
-        hostName, isClient);
+    ServiceComponentHostImpl impl = new ServiceComponentHostImpl(clusterId, svc,
+        svcComponent, hostName, isClient);
     Assert.assertEquals(ServiceComponentHostLiveState.INIT,
         impl.getState().getLiveState());
     return impl;
@@ -42,8 +44,8 @@ public class TestServiceComponentHostImp
 
   @Test
   public void testNewServiceComponentHostImpl() {
-    createNewServiceComponentHost("svcComp", "h1", false);
-    createNewServiceComponentHost("svcComp", "h1", true);
+    createNewServiceComponentHost(1, "svc", "svcComp", "h1", false);
+    createNewServiceComponentHost(1, "svc", "svcComp", "h1", true);
   }
 
   private ServiceComponentHostEvent createEvent(ServiceComponentHostImpl impl,
@@ -53,8 +55,6 @@ public class TestServiceComponentHostImp
     return event;
   }
 
-
-
   private void runStateChanges(ServiceComponentHostImpl impl,
       ServiceComponentHostEventType startEvent,
       ServiceComponentHostLiveState startState,
@@ -160,8 +160,8 @@ public class TestServiceComponentHostImp
 
   @Test
   public void testClientStateFlow() throws Exception {
-    ServiceComponentHostImpl impl = createNewServiceComponentHost("svcComp",
-        "h1", true);
+    ServiceComponentHostImpl impl = createNewServiceComponentHost(1, "svc",
+        "svcComp", "h1", true);
 
     runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
         ServiceComponentHostLiveState.INIT,
@@ -198,8 +198,8 @@ public class TestServiceComponentHostImp
 
   @Test
   public void testDaemonStateFlow() throws Exception {
-    ServiceComponentHostImpl impl = createNewServiceComponentHost("svcComp",
-        "h1", false);
+    ServiceComponentHostImpl impl = createNewServiceComponentHost(1, "svc",
+        "svcComp", "h1", false);
 
     runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
         ServiceComponentHostLiveState.INIT,