incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hit...@apache.org
Subject svn commit: r1399430 - in /incubator/ambari/branches/AMBARI-666: ./ ambari-server/src/main/java/org/apache/ambari/server/controller/ ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/ ambari-server/src/main/java/org/apache/ambari/ser...
Date Wed, 17 Oct 2012 21:02:10 GMT
Author: hitesh
Date: Wed Oct 17 21:02:09 2012
New Revision: 1399430

URL: http://svn.apache.org/viewvc?rev=1399430&view=rev
Log:
AMBARI-878. Various tests for FSM, controller and state objects. (Contributed by hitesh)

Removed:
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/RequestInjectorForTest.java
Modified:
    incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCManagementController.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java

Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Wed Oct 17 21:02:09 2012
@@ -294,6 +294,8 @@ AMBARI-666 branch (unreleased changes)
 
   BUG FIXES
 
+  AMBARI-878. Various tests for FSM, controller and state objects. (hitesh)
+
   AMBARI-858. Installer -> Select Services page: warning popups are no longer
   appearing. (yusaku)
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
Wed Oct 17 21:02:09 2012
@@ -41,50 +41,42 @@ public interface AmbariManagementControl
   /**
    * Create the service defined by the attributes in the given request object.
    *
-   * @param request  the request object which defines the service to be created
+   * @param requests  the request object which defines the service to be created
    *
    * @throws AmbariException thrown if the service cannot be created
    */
   public void createServices(Set<ServiceRequest> request)
       throws AmbariException;
-  public void createService(ServiceRequest request)
-      throws AmbariException;
 
   /**
    * Create the component defined by the attributes in the given request object.
    *
-   * @param request  the request object which defines the component to be created
+   * @param requests  the request object which defines the component to be created
    *
    * @throws AmbariException thrown if the component cannot be created
    */
   public void createComponents(Set<ServiceComponentRequest> request)
       throws AmbariException;
-  public void createComponent(ServiceComponentRequest request)
-      throws AmbariException;
 
   /**
    * Create the host defined by the attributes in the given request object.
    *
-   * @param request  the request object which defines the host to be created
+   * @param requests  the request object which defines the host to be created
    *
    * @throws AmbariException thrown if the host cannot be created
    */
   public void createHosts(Set<HostRequest> request)
       throws AmbariException;
-  public void createHost(HostRequest request)
-      throws AmbariException;
 
   /**
    * Create the host component defined by the attributes in the given request object.
    *
-   * @param request  the request object which defines the host component to be created
+   * @param requests  the request object which defines the host component to be created
    *
    * @throws AmbariException thrown if the host component cannot be created
    */
   public void createHostComponents(
       Set<ServiceComponentHostRequest> request) throws AmbariException;
-  public void createHostComponent(
-      ServiceComponentHostRequest request) throws AmbariException;
 
 
   // ----- Read -------------------------------------------------------------
@@ -171,7 +163,7 @@ public interface AmbariManagementControl
    * Update the service identified by the given request object with the
    * values carried by the given request object.
    *
-   * @param request    the request object which defines which service to
+   * @param requests    the request object which defines which service to
    *                   update and the values to set
    *
    * @return a track action response
@@ -180,14 +172,12 @@ public interface AmbariManagementControl
    */
   public TrackActionResponse updateServices(Set<ServiceRequest> request)
       throws AmbariException;
-  public TrackActionResponse updateService(ServiceRequest request)
-      throws AmbariException;
 
   /**
    * Update the component identified by the given request object with the
    * values carried by the given request object.
    *
-   * @param request    the request object which defines which component to
+   * @param requests    the request object which defines which component to
    *                   update and the values to set
    *
    * @return a track action response
@@ -196,28 +186,24 @@ public interface AmbariManagementControl
    */
   public TrackActionResponse updateComponents(
       Set<ServiceComponentRequest> request) throws AmbariException;
-  public TrackActionResponse updateComponent(ServiceComponentRequest request)
-      throws AmbariException;
 
   /**
    * Update the host identified by the given request object with the
    * values carried by the given request object.
    *
-   * @param request    the request object which defines which host to
+   * @param requests    the request object which defines which host to
    *                   update and the values to set
    *
    * @throws AmbariException thrown if the resource cannot be updated
    */
   public void updateHosts(Set<HostRequest> request)
       throws AmbariException;
-  public void updateHost(HostRequest request)
-      throws AmbariException;
 
   /**
    * Update the host component identified by the given request object with the
    * values carried by the given request object.
    *
-   * @param request    the request object which defines which host component to
+   * @param requests    the request object which defines which host component to
    *                   update and the values to set
    *
    * @return a track action response
@@ -226,9 +212,6 @@ public interface AmbariManagementControl
    */
   public TrackActionResponse updateHostComponents(
       Set<ServiceComponentHostRequest> request) throws AmbariException;
-  public TrackActionResponse updateHostComponent(
-      ServiceComponentHostRequest request) throws AmbariException;
-
 
 
   // ----- Delete -----------------------------------------------------------
@@ -249,33 +232,29 @@ public interface AmbariManagementControl
    *
    * @return a track action response
    *
-   * @param request  the request object which identifies which service to delete
+   * @param requests  the request object which identifies which service to delete
    *
    * @throws AmbariException thrown if the resource cannot be deleted
    */
   public TrackActionResponse deleteServices(Set<ServiceRequest> request)
       throws AmbariException;
-  public TrackActionResponse deleteService(ServiceRequest request)
-      throws AmbariException;
 
   /**
    * Delete the component identified by the given request object.
    *
    * @return a track action response
    *
-   * @param request  the request object which identifies which component to delete
+   * @param requests  the request object which identifies which component to delete
    *
    * @throws AmbariException thrown if the resource cannot be deleted
    */
   public TrackActionResponse deleteComponents(
       Set<ServiceComponentRequest> request) throws AmbariException;
-  public TrackActionResponse deleteComponent(ServiceComponentRequest request)
-      throws AmbariException;
 
   /**
    * Delete the host identified by the given request object.
    *
-   * @param request  the request object which identifies which host to delete
+   * @param requests  the request object which identifies which host to delete
    *
    * @return a track action response
    *
@@ -283,13 +262,11 @@ public interface AmbariManagementControl
    */
   public TrackActionResponse deleteHosts(Set<HostRequest> request)
       throws AmbariException;
-  public TrackActionResponse deleteHost(HostRequest request)
-      throws AmbariException;
 
   /**
    * Delete the host component identified by the given request object.
    *
-   * @param request  the request object which identifies which host component to delete
+   * @param requests  the request object which identifies which host component to delete
    *
    * @return a track action response
    *
@@ -297,6 +274,5 @@ public interface AmbariManagementControl
    */
   public TrackActionResponse deleteHostComponents(
       Set<ServiceComponentHostRequest> request) throws AmbariException;
-  public TrackActionResponse deleteHostComponent(
-      ServiceComponentHostRequest request) throws AmbariException;
+
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
Wed Oct 17 21:02:09 2012
@@ -406,6 +406,7 @@ public class AmbariManagementControllerI
       }
       catch (HostNotFoundException e) {
         unknowns.add(request.getHostname());
+        continue;
       }
     }
 
@@ -1544,122 +1545,30 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public TrackActionResponse deleteService(ServiceRequest request)
-      throws AmbariException {
-    // TODO not implemented yet
-    throw new AmbariException("Delete service not supported");
-  }
-
-  @Override
-  public TrackActionResponse deleteComponent(ServiceComponentRequest request)
-      throws AmbariException {
-    // TODO not implemented yet
-    throw new AmbariException("Delete component not supported");
-  }
-
-  @Override
-  public TrackActionResponse deleteHost(HostRequest request)
-      throws AmbariException {
-    // TODO not implemented yet
-    throw new AmbariException("Delete host not supported");
-  }
-
-  @Override
-  public TrackActionResponse deleteHostComponent(
-      ServiceComponentHostRequest request) throws AmbariException {
-    // TODO not implemented yet
-    throw new AmbariException("Delete host component not supported");
-  }
-
-  @Override
   public TrackActionResponse deleteServices(Set<ServiceRequest> request)
       throws AmbariException {
     // TODO Auto-generated method stub
-    return null;
+    throw new AmbariException("Delete services not supported");
   }
 
   @Override
   public TrackActionResponse deleteComponents(
       Set<ServiceComponentRequest> request) throws AmbariException {
     // TODO Auto-generated method stub
-    return null;
+    throw new AmbariException("Delete components not supported");
   }
 
   @Override
   public TrackActionResponse deleteHosts(Set<HostRequest> request)
       throws AmbariException {
-    // TODO Auto-generated method stub
-    return null;
+    throw new AmbariException("Delete hosts not supported");
   }
 
   @Override
   public TrackActionResponse deleteHostComponents(
       Set<ServiceComponentHostRequest> request) throws AmbariException {
     // TODO Auto-generated method stub
-    return null;
-  }
-
-  @Override
-  public void createService(ServiceRequest request) throws AmbariException {
-    Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
-    requests.add(request);
-    createServices(requests);
-  }
-
-  @Override
-  public void createComponent(ServiceComponentRequest request)
-      throws AmbariException {
-    Set<ServiceComponentRequest> requests = new HashSet<ServiceComponentRequest>();
-    requests.add(request);
-    createComponents(requests);
-  }
-
-  @Override
-  public void createHost(HostRequest request) throws AmbariException {
-    Set<HostRequest> requests = new HashSet<HostRequest>();
-    requests.add(request);
-    createHosts(requests);
+    throw new AmbariException("Delete host components not supported");
   }
 
-  @Override
-  public void createHostComponent(ServiceComponentHostRequest request)
-      throws AmbariException {
-    Set<ServiceComponentHostRequest> requests =
-        new HashSet<ServiceComponentHostRequest>();
-    requests.add(request);
-    createHostComponents(requests);
-  }
-
-  @Override
-  public TrackActionResponse updateService(ServiceRequest request)
-      throws AmbariException {
-    Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
-    requests.add(request);
-    return updateServices(requests);
-  }
-
-  @Override
-  public TrackActionResponse updateComponent(ServiceComponentRequest request)
-      throws AmbariException {
-    Set<ServiceComponentRequest> requests =
-        new HashSet<ServiceComponentRequest>();
-    requests.add(request);
-    return updateComponents(requests);
-  }
-
-  @Override
-  public void updateHost(HostRequest request) throws AmbariException {
-    Set<HostRequest> requests = new HashSet<HostRequest>();
-    requests.add(request);
-    updateHosts(requests);
-  }
-
-  @Override
-  public TrackActionResponse updateHostComponent(
-      ServiceComponentHostRequest request) throws AmbariException {
-    Set<ServiceComponentHostRequest> requests =
-        new HashSet<ServiceComponentHostRequest>();
-    requests.add(request);
-    return updateHostComponents(requests);
-  }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
Wed Oct 17 21:02:09 2012
@@ -131,4 +131,17 @@ public class ServiceComponentHostRequest
   public void setClusterName(String clusterName) {
     this.clusterName = clusterName;
   }
+
+
+  public String toString() {
+    StringBuilder sb = new StringBuilder();
+    sb.append("{"
+        + " clusterName=" + clusterName
+        + ", serviceName=" + serviceName
+        + ", componentName=" + componentName
+        + ", hostname=" + hostname
+        + ", desiredState=" + desiredState
+        + "}");
+    return sb.toString();
+  }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCManagementController.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCManagementController.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCManagementController.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/jdbc/JDBCManagementController.java
Wed Oct 17 21:02:09 2012
@@ -100,22 +100,6 @@ public class JDBCManagementController im
   }
 
   @Override
-  public void createService(ServiceRequest request) throws AmbariException {
-  }
-
-  @Override
-  public void createComponent(ServiceComponentRequest request) throws AmbariException {
-  }
-
-  @Override
-  public void createHost(HostRequest request) throws AmbariException {
-  }
-
-  @Override
-  public void createHostComponent(ServiceComponentHostRequest request) throws AmbariException
{
-  }
-
-  @Override
   public Set<ClusterResponse> getClusters(ClusterRequest request) throws AmbariException
{
 //    return getResources(Resource.Type.Cluster, request, predicate);
     return null;
@@ -147,24 +131,6 @@ public class JDBCManagementController im
     return null;
   }
 
-  @Override
-  public TrackActionResponse updateService(ServiceRequest request) throws AmbariException
{
-    return null;
-  }
-
-  @Override
-  public TrackActionResponse updateComponent(ServiceComponentRequest request) throws AmbariException
{
-    return null;
-  }
-
-  @Override
-  public void updateHost(HostRequest request) throws AmbariException {
-  }
-
-  @Override
-  public TrackActionResponse updateHostComponent(ServiceComponentHostRequest request) throws
AmbariException {
-    return null;
-  }
 
   @Override
   public TrackActionResponse deleteCluster(ClusterRequest request) throws AmbariException
{
@@ -172,26 +138,6 @@ public class JDBCManagementController im
     return null;
   }
 
-  @Override
-  public TrackActionResponse deleteService(ServiceRequest request) throws AmbariException
{
-    return null;
-  }
-
-  @Override
-  public TrackActionResponse deleteComponent(ServiceComponentRequest request) throws AmbariException
{
-    return null;
-  }
-
-  @Override
-  public TrackActionResponse deleteHost(HostRequest request) throws AmbariException {
-    return null;
-  }
-
-  @Override
-  public TrackActionResponse deleteHostComponent(ServiceComponentHostRequest request) throws
AmbariException {
-    return null;
-  }
-
 
   // ----- Helper methods ----------------------------------------------------
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
Wed Oct 17 21:02:09 2012
@@ -85,7 +85,7 @@ public interface Cluster {
 
   public void addDesiredConfig(Config config);
 
-  public ClusterResponse convertToResponse();
+  public ClusterResponse convertToResponse() throws AmbariException;
 
   public void refresh();
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
Wed Oct 17 21:02:09 2012
@@ -94,9 +94,13 @@ public interface Clusters {
   public void mapHostsToCluster(Set<String> hostnames, String clusterName)
       throws AmbariException;
 
-  void updateClusterName(String oldName, String newName);
+  public void updateClusterName(String oldName, String newName);
 
-  Cluster getClusterById(long id) throws AmbariException;
+  public Cluster getClusterById(long id) throws AmbariException;
 
   public void debugDump(StringBuilder sb);
+
+  public Map<String, Host> getHostsForCluster(String clusterName)
+      throws AmbariException;
+
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
Wed Oct 17 21:02:09 2012
@@ -34,6 +34,7 @@ import org.apache.ambari.server.ServiceC
 import org.apache.ambari.server.controller.ServiceComponentResponse;
 import org.apache.ambari.server.orm.dao.*;
 import org.apache.ambari.server.orm.entities.*;
+import org.apache.ambari.server.state.cluster.ClusterImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,7 +58,6 @@ public class ServiceComponentImpl implem
   @Inject
   private ServiceComponentHostFactory serviceComponentHostFactory;
 
-
   boolean persisted = false;
   private ServiceComponentDesiredStateEntity desiredStateEntity;
 
@@ -173,10 +173,14 @@ public class ServiceComponentImpl implem
           + ", serviceComponentName=" + getName()
           + ", hostname=" + hostComponent.getHostName());
     }
+    // FIXME need a better approach of caching components by host
+    ClusterImpl clusterImpl = (ClusterImpl) service.getCluster();
+    clusterImpl.addServiceComponentHost(hostComponent);
     this.hostComponents.put(hostComponent.getHostName(), hostComponent);
   }
 
-  public synchronized ServiceComponentHost addServiceComponentHost(String hostName) throws
AmbariException {
+  public synchronized ServiceComponentHost addServiceComponentHost(
+      String hostName) throws AmbariException {
     // TODO validation
     // TODO ensure host belongs to cluster
     if (LOG.isDebugEnabled()) {
@@ -195,8 +199,14 @@ public class ServiceComponentImpl implem
           + ", serviceComponentName=" + getName()
           + ", hostname=" + hostName);
     }
-    ServiceComponentHost hostComponent = serviceComponentHostFactory.createNew(this, hostName,
true);
+    ServiceComponentHost hostComponent =
+        serviceComponentHostFactory.createNew(this, hostName, true);
+    // FIXME need a better approach of caching components by host
+    ClusterImpl clusterImpl = (ClusterImpl) service.getCluster();
+    clusterImpl.addServiceComponentHost(hostComponent);
+
     this.hostComponents.put(hostComponent.getHostName(), hostComponent);
+
     return hostComponent;
   }
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
Wed Oct 17 21:02:09 2012
@@ -160,7 +160,8 @@ public class ServiceImpl implements Serv
   }
 
   @Override
-  public synchronized ServiceComponent addServiceComponent(String serviceComponentName) throws
AmbariException {
+  public synchronized ServiceComponent addServiceComponent(
+      String serviceComponentName) throws AmbariException {
     if (LOG.isDebugEnabled()) {
       LOG.debug("Adding a ServiceComponent to Service"
           + ", clusterName=" + cluster.getClusterName()

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
Wed Oct 17 21:02:09 2012
@@ -151,14 +151,15 @@ public class ClusterImpl implements Clus
     }
   }
 
-  synchronized void addServiceComponentHost(ServiceComponentHost svcCompHost)
-      throws AmbariException {
+  public synchronized void addServiceComponentHost(
+      ServiceComponentHost svcCompHost) throws AmbariException {
     final String hostname = svcCompHost.getHostName();
     final String serviceName = svcCompHost.getServiceName();
     final String componentName = svcCompHost.getServiceComponentName();
     Set<Cluster> cs = clusters.getClustersForHost(hostname);
     boolean clusterFound = false;
-    for (Cluster c = cs.iterator().next(); ; cs.iterator().hasNext()) {
+    while (cs.iterator().hasNext()) {
+      Cluster c = cs.iterator().next();
       if (c.getClusterId() == this.getClusterId()) {
         clusterFound = true;
         break;
@@ -215,8 +216,11 @@ public class ClusterImpl implements Clus
   @Override
   public synchronized List<ServiceComponentHost> getServiceComponentHosts(
       String hostname) {
-    return Collections.unmodifiableList(
-        serviceComponentHostsByHost.get(hostname));
+    if (serviceComponentHostsByHost.containsKey(hostname)) {
+      return Collections.unmodifiableList(
+          serviceComponentHostsByHost.get(hostname));
+    }
+    return new ArrayList<ServiceComponentHost>();
   }
 
   @Override
@@ -320,9 +324,10 @@ public class ClusterImpl implements Clus
   }
 
   @Override
-  public synchronized ClusterResponse convertToResponse() {
+  public synchronized ClusterResponse convertToResponse()
+      throws AmbariException {
     ClusterResponse r = new ClusterResponse(getClusterId(), getClusterName(),
-        new HashSet<String>(serviceComponentHostsByHost.keySet()));
+        clusters.getHostsForCluster(getClusterName()).keySet());
     return r;
   }
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
Wed Oct 17 21:02:09 2012
@@ -56,6 +56,7 @@ public class ClustersImpl implements Clu
   private Map<Long, Cluster> clustersById;
   private Map<String, Host> hosts;
   private Map<String, Set<Cluster>> hostClusterMap;
+  private Map<String, Set<Host>> clusterHostMap;
 
   private Injector injector;
   private ClusterDAO clusterDAO;
@@ -76,6 +77,7 @@ public class ClustersImpl implements Clu
     clustersById = new HashMap<Long, Cluster>();
     hosts = new HashMap<String, Host>();
     hostClusterMap = new HashMap<String, Set<Cluster>>();
+    clusterHostMap = new HashMap<String, Set<Host>>();
     LOG.info("Initializing the ClustersImpl");
   }
 
@@ -98,6 +100,7 @@ public class ClustersImpl implements Clu
 
       clusters.put(clusterName, cluster);
       clustersById.put(cluster.getClusterId(), cluster);
+      clusterHostMap.put(clusterName, new HashSet<Host>());
     } catch (RollbackException e) {
       LOG.warn("Unable to create cluster " + clusterName, e);
       throw new AmbariException("Unable to create cluster " + clusterName, e);
@@ -218,6 +221,7 @@ public class ClustersImpl implements Clu
     host.addToCluster(cluster);
 
     hostClusterMap.get(hostname).add(cluster);
+    clusterHostMap.get(clusterName).add(host);
     if (LOG.isDebugEnabled()) {
       LOG.debug("Mapping a host to a cluster"
           + ", clusterName=" + clusterName
@@ -242,7 +246,7 @@ public class ClustersImpl implements Clu
 
   @Override
   public synchronized void mapHostsToCluster(Set<String> hostnames,
-                                             String clusterName) throws AmbariException {
+      String clusterName) throws AmbariException {
     for (String hostname : hostnames) {
       mapHostToCluster(hostname, clusterName);
     }
@@ -269,4 +273,15 @@ public class ClustersImpl implements Clu
     sb.append(" ]");
   }
 
+  @Override
+  public Map<String, Host> getHostsForCluster(String clusterName)
+      throws AmbariException {
+    getCluster(clusterName);
+    Map<String, Host> hosts = new HashMap<String, Host>();
+    for (Host h : clusterHostMap.get(clusterName)) {
+      hosts.put(h.getHostName(), h);
+    }
+    return hosts;
+  }
+
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
Wed Oct 17 21:02:09 2012
@@ -120,10 +120,13 @@ public class AmbariManagementControllerT
     }
     ServiceComponentRequest r = new ServiceComponentRequest(clusterName,
         serviceName, componentName, null, dStateStr);
-    controller.createComponent(r);
+    Set<ServiceComponentRequest> requests =
+        new HashSet<ServiceComponentRequest>();
+    requests.add(r);
+    controller.createComponents(requests);
 
     try {
-      controller.createComponent(r);
+      controller.createComponents(requests);
       fail("Duplicate ServiceComponent creation should fail");
     } catch (Exception e) {
       // Expected
@@ -139,10 +142,13 @@ public class AmbariManagementControllerT
     }
     ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName,
         serviceName, componentName, hostname, null, dStateStr);
-    controller.createHostComponent(r);
+    Set<ServiceComponentHostRequest> requests =
+        new HashSet<ServiceComponentHostRequest>();
+    requests.add(r);
+    controller.createHostComponents(requests);
 
     try {
-      controller.createHostComponent(r);
+      controller.createHostComponents(requests);
       fail("Duplicate ServiceComponentHost creation should fail");
     } catch (Exception e) {
       // Expected
@@ -262,17 +268,33 @@ public class AmbariManagementControllerT
     String host2 = "h2";
     clusters.addHost(host2);
     clusters.getHost("h2").persist();
+
+    try {
+      createServiceComponentHost(clusterName, serviceName, componentName1,
+          host1, State.INIT);
+      fail("ServiceComponentHost creation should fail for invalid host"
+          + " as host not mapped to cluster");
+    } catch (Exception e) {
+      // Expected
+    }
+
+    clusters.mapHostToCluster(host1, clusterName);
+    clusters.mapHostToCluster(host2, clusterName);
+
     try {
       createServiceComponentHost(clusterName, serviceName, componentName1,
           host1, State.INSTALLING);
       fail("ServiceComponentHost creation should fail for invalid state");
     } catch (Exception e) {
       // Expected
+      e.printStackTrace();
     }
 
     try {
+      ServiceComponentHost sch =
       clusters.getCluster(clusterName).getService(serviceName)
           .getServiceComponent(componentName1).getServiceComponentHost(host1);
+      LOG.error("**** " + sch.getHostName());
       fail("ServiceComponentHost creation should have failed");
     } catch (Exception e) {
       // Expected
@@ -324,8 +346,11 @@ public class AmbariManagementControllerT
 
     HostRequest r1 = new HostRequest("h1", clusterNames, hostAttributes);
     r1.toString();
+
+    Set<HostRequest> requests = new HashSet<HostRequest>();
+    requests.add(r1);
     try {
-      controller.createHost(r1);
+      controller.createHosts(requests);
       fail("Create host should fail for non-bootstrapped host");
     } catch (Exception e) {
       // Expected
@@ -334,8 +359,6 @@ public class AmbariManagementControllerT
     clusters.addHost("h1");
     clusters.addHost("h2");
 
-    controller.createHost(r1);
-
     clusterNames = new ArrayList<String>();
     clusterNames.add("foo1");
     clusterNames.add("foo2");
@@ -343,8 +366,10 @@ public class AmbariManagementControllerT
     hostAttributes = new HashMap<String, String>();
     HostRequest r2 = new HostRequest("h2", clusterNames, hostAttributes);
 
+    requests.add(r2);
+
     try {
-      controller.createHost(r2);
+      controller.createHosts(requests);
       fail("Create host should fail for invalid clusters");
     } catch (Exception e) {
       // Expected
@@ -353,7 +378,7 @@ public class AmbariManagementControllerT
     clusters.addCluster("foo1");
     clusters.addCluster("foo2");
 
-    controller.createHost(r2);
+    controller.createHosts(requests);
 
     Assert.assertNotNull(clusters.getHost("h1"));
     Assert.assertNotNull(clusters.getHost("h2"));
@@ -397,8 +422,10 @@ public class AmbariManagementControllerT
 
     ServiceRequest r1 = new ServiceRequest(clusterName, serviceName, null,
         State.INSTALLED.toString());
+    Set<ServiceRequest> requests1 = new HashSet<ServiceRequest>();
+    requests1.add(r1);
 
-    controller.updateService(r1);
+    controller.updateServices(requests1);
     Assert.assertEquals(State.INSTALLED,
         clusters.getCluster(clusterName).getService(serviceName)
         .getDesiredState());
@@ -431,8 +458,10 @@ public class AmbariManagementControllerT
 
     ServiceRequest r2 = new ServiceRequest(clusterName, serviceName, null,
         State.STARTED.toString());
+    Set<ServiceRequest> requests2 = new HashSet<ServiceRequest>();
+    requests2.add(r2);
+    controller.updateServices(requests2);
 
-    controller.updateService(r2);
     Assert.assertEquals(State.STARTED,
         clusters.getCluster(clusterName).getService(serviceName)
         .getDesiredState());

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
Wed Oct 17 21:02:09 2012
@@ -156,12 +156,14 @@ public class ServiceComponentTest {
      */
   }
 
-  private void addHostToCluster(String hostname) throws AmbariException {
+  private void addHostToCluster(String hostname,
+      String clusterName) throws AmbariException {
     clusters.addHost(hostname);
     Host h = clusters.getHost(hostname);
     h.setIPv4(hostname + "ipv4");
     h.setIPv6(hostname + "ipv6");
     h.persist();
+    clusters.mapHostToCluster(hostname, clusterName);
   }
 
   @Test
@@ -184,8 +186,8 @@ public class ServiceComponentTest {
       // Expected
     }
 
-    addHostToCluster("h1");
-    addHostToCluster("h2");
+    addHostToCluster("h1", service.getCluster().getClusterName());
+    addHostToCluster("h2", service.getCluster().getClusterName());
 
     ServiceComponentHost sch1 =
         serviceComponentHostFactory.createNew(sc, "h1", false);

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java?rev=1399430&r1=1399429&r2=1399430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
Wed Oct 17 21:02:09 2012
@@ -22,6 +22,7 @@ import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
@@ -31,12 +32,20 @@ import junit.framework.Assert;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.agent.DiskInfo;
 import org.apache.ambari.server.agent.HostInfo;
+import org.apache.ambari.server.controller.ClusterResponse;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.state.AgentVersion;
 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.HostState;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponent;
+import org.apache.ambari.server.state.ServiceComponentFactory;
+import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceComponentHostFactory;
+import org.apache.ambari.server.state.ServiceFactory;
 import org.apache.ambari.server.state.StackVersion;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
 import org.apache.ambari.server.state.host.HostHealthyHeartbeatEvent;
@@ -49,21 +58,31 @@ public class ClusterTest {
 
   private Clusters clusters;
   private Cluster c1;
-  String h1 = "h1";
-  String s1 = "s1";
-  String sc1 = "sc1";
   private Injector injector;
+  private ServiceFactory serviceFactory;
+  private ServiceComponentFactory serviceComponentFactory;
+  private ServiceComponentHostFactory serviceComponentHostFactory;
 
   @Before
   public void setup() throws AmbariException {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
     clusters = injector.getInstance(Clusters.class);
+    serviceFactory = injector.getInstance(ServiceFactory.class);
+    serviceComponentFactory = injector.getInstance(
+        ServiceComponentFactory.class);
+    serviceComponentHostFactory = injector.getInstance(
+        ServiceComponentHostFactory.class);
     clusters.addCluster("c1");
     c1 = clusters.getCluster("c1");
     Assert.assertEquals("c1", c1.getClusterName());
-    clusters.addHost(h1);
-    clusters.mapHostToCluster(h1, "c1");
+    Assert.assertEquals(1, c1.getClusterId());
+    clusters.addHost("h1");
+    Host host = clusters.getHost("h1");
+    host.setIPv4("ipv4");
+    host.setIPv6("ipv6");
+    host.persist();
+    clusters.mapHostToCluster("h1", "c1");
   }
 
   @After
@@ -88,21 +107,21 @@ public class ClusterTest {
 
   @Test
   public void testGetHostState() throws AmbariException {
-    Assert.assertEquals(HostState.INIT, clusters.getHost(h1).getState());
+    Assert.assertEquals(HostState.INIT, clusters.getHost("h1").getState());
   }
 
   @Test
   public void testSetHostState() throws AmbariException {
-    clusters.getHost(h1).setState(HostState.HEARTBEAT_LOST);
+    clusters.getHost("h1").setState(HostState.HEARTBEAT_LOST);
     Assert.assertEquals(HostState.HEARTBEAT_LOST,
-        clusters.getHost(h1).getState());
+        clusters.getHost("h1").getState());
   }
 
   @Test
   public void testHostEvent() throws AmbariException,
       InvalidStateTransitonException {
     HostInfo hostInfo = new HostInfo();
-    hostInfo.setHostName(h1);
+    hostInfo.setHostName("h1");
     hostInfo.setInterfaces("fip_4");
     hostInfo.setArchitecture("os_arch");
     hostInfo.setOS("os_type");
@@ -117,17 +136,17 @@ public class ClusterTest {
     AgentVersion agentVersion = new AgentVersion("0.0.x");
     long currentTime = 1001;
 
-    clusters.getHost(h1).handleEvent(new HostRegistrationRequestEvent(
-        h1, agentVersion, currentTime, hostInfo));
+    clusters.getHost("h1").handleEvent(new HostRegistrationRequestEvent(
+        "h1", agentVersion, currentTime, hostInfo));
 
     Assert.assertEquals(HostState.WAITING_FOR_HOST_STATUS_UPDATES,
-        clusters.getHost(h1).getState());
+        clusters.getHost("h1").getState());
 
-    clusters.getHost(h1).setState(HostState.HEARTBEAT_LOST);
+    clusters.getHost("h1").setState(HostState.HEARTBEAT_LOST);
 
     try {
-      clusters.getHost(h1).handleEvent(
-          new HostHealthyHeartbeatEvent(h1, currentTime));
+      clusters.getHost("h1").handleEvent(
+          new HostHealthyHeartbeatEvent("h1", currentTime));
       fail("Exception should be thrown on invalid event");
     }
     catch (InvalidStateTransitonException e) {
@@ -152,12 +171,10 @@ public class ClusterTest {
 
     Assert.assertNotNull(c2);
 
-//    Assert.assertEquals(clusterName.hashCode(), c2.getClusterId()); This is not true
     Assert.assertEquals(clusterName, c2.getClusterName());
 
     c2.setClusterName("foo2");
     Assert.assertEquals("foo2", c2.getClusterName());
-//    Assert.assertEquals(clusterName.hashCode(), c2.getClusterId());
 
     Assert.assertNotNull(c2.getDesiredStackVersion());
     Assert.assertEquals("", c2.getDesiredStackVersion().getStackVersion());
@@ -168,37 +185,88 @@ public class ClusterTest {
   }
 
   @Test
-  public void testAddAndGetServices() {
+  public void testAddAndGetServices() throws AmbariException {
     // TODO write unit tests for
     // public void addService(Service service) throws AmbariException;
     // public Service getService(String serviceName) throws AmbariException;
     // public Map<String, Service> getServices();
+
+    Service s1 = serviceFactory.createNew(c1, "s1");
+    Service s2 = serviceFactory.createNew(c1, "s2");
+
+    c1.addService(s1);
+    c1.addService(s2);
+
+    s1.persist();
+    s2.persist();
+
+    Service s3 = serviceFactory.createNew(c1, "s2");
+
+    try {
+      c1.addService(s3);
+      fail("Expected error on adding dup service");
+    } catch (Exception e) {
+      // Expected
+    }
+
+    Service s = c1.getService("s1");
+    Assert.assertNotNull(s);
+    Assert.assertEquals("s1", s.getName());
+    Assert.assertEquals(c1.getClusterId(), s.getClusterId());
+
+    try {
+      c1.getService("s3");
+      fail("Expected error for unknown service");
+    } catch (Exception e) {
+      // Expected
+    }
+
+    Map<String, Service> services = c1.getServices();
+    Assert.assertEquals(2, services.size());
+    Assert.assertTrue(services.containsKey("s1"));
+    Assert.assertTrue(services.containsKey("s2"));
   }
 
 
   @Test
-  public void testGetServiceComponentHosts() {
+  public void testGetServiceComponentHosts() throws AmbariException {
     // TODO write unit tests
     // public List<ServiceComponentHost> getServiceComponentHosts(String hostname);
+
+    Service s = serviceFactory.createNew(c1, "s");
+    c1.addService(s);
+    s.persist();
+    ServiceComponent sc = serviceComponentFactory.createNew(s, "sc");
+    s.addServiceComponent(sc);
+    sc.persist();
+    ServiceComponentHost sch =
+        serviceComponentHostFactory.createNew(sc, "h1", false);
+    sc.addServiceComponentHost(sch);
+    sch.persist();
+
+    List<ServiceComponentHost> scHosts = c1.getServiceComponentHosts("h1");
+    Assert.assertEquals(1, scHosts.size());
   }
 
 
   @Test
   public void testGetAndSetConfigs() {
-    // TODO write unit tests
+    // FIXME write unit tests
     // public Map<String, Config> getConfigsByType(String configType);
     // public Config getConfig(String configType, String versionTag);
     // public void addConfig(Config config);
   }
 
   @Test
-  public void testConvertToResponse() {
-    // TODO write unit tests
-  }
-
-  @Test
-  public void testDebugDump() {
-    // TODO write unit tests
+  public void testConvertToResponse() throws AmbariException {
+    ClusterResponse r = c1.convertToResponse();
+    Assert.assertEquals(c1.getClusterId(), r.getClusterId().longValue());
+    Assert.assertEquals(c1.getClusterName(), r.getClusterName());
+    Assert.assertEquals(1, r.getHostNames().size());
+
+    // TODO write unit tests for debug dump
+    StringBuilder sb = new StringBuilder();
+    c1.debugDump(sb);
   }
 
 }



Mime
View raw message