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/22 23:19:11 UTC

svn commit: r1401083 [1/3] - in /incubator/ambari/branches/AMBARI-666: ./ ambari-server/src/main/java/org/apache/ambari/server/ ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ ambari-server/src/main/java/org/apache/ambari/server/age...

Author: hitesh
Date: Mon Oct 22 21:19:10 2012
New Revision: 1401083

URL: http://svn.apache.org/viewvc?rev=1401083&view=rev
Log:
AMBARI-888. Add more tests for controller implementation. (Contributed by hitesh)

Added:
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitionException.java   (with props)
Removed:
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitonException.java
Modified:
    incubator/ambari/branches/AMBARI-666/   (props changed)
    incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/HostNotFoundException.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentHostNotFoundException.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentNotFoundException.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceNotFoundException.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
    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/jdbc/JDBCManagementController.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.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/Host.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.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/State.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/main/java/org/apache/ambari/server/state/fsm/StateMachine.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/Job.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/LocalAgentSimulator.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.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/controller/internal/ResourceProviderImplTest.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java

Propchange: incubator/ambari/branches/AMBARI-666/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Oct 22 21:19:10 2012
@@ -1,4 +1,11 @@
 .classpath
 .project
 .settings
+.idea/
+.iml/
+.DS_Store
 target
+/ambari-web/public/
+/ambari-web/node_modules/
+*.pyc
+*.py~

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=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Mon Oct 22 21:19:10 2012
@@ -323,6 +323,8 @@ AMBARI-666 branch (unreleased changes)
 
   IMPROVEMENTS
 
+  AMBARI-888. Add more tests for controller implementation. (hitesh)
+
   AMBARI-891. Initial work to refactor the Wizards in Ambari Web. (yusaku)
 
   AMBARI-883. Improve user interactions on Confirm Hosts page of the

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java Mon Oct 22 21:19:10 2012
@@ -20,7 +20,7 @@ package org.apache.ambari.server;
 
 import java.io.IOException;
 
-// TODO
+@SuppressWarnings("serial")
 public class AmbariException extends IOException {
 
   public AmbariException(String message) {

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java Mon Oct 22 21:19:10 2012
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server;
 
+@SuppressWarnings("serial")
 public class ClusterNotFoundException extends AmbariException {
 
   public ClusterNotFoundException(String clusterName) {

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/HostNotFoundException.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/HostNotFoundException.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/HostNotFoundException.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/HostNotFoundException.java Mon Oct 22 21:19:10 2012
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server;
 
+@SuppressWarnings("serial")
 public class HostNotFoundException extends AmbariException {
 
   public HostNotFoundException(String hostName) {

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentHostNotFoundException.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentHostNotFoundException.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentHostNotFoundException.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentHostNotFoundException.java Mon Oct 22 21:19:10 2012
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server;
 
+@SuppressWarnings("serial")
 public class ServiceComponentHostNotFoundException extends AmbariException {
 
   public ServiceComponentHostNotFoundException(String clusterName,

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentNotFoundException.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentNotFoundException.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentNotFoundException.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentNotFoundException.java Mon Oct 22 21:19:10 2012
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server;
 
+@SuppressWarnings("serial")
 public class ServiceComponentNotFoundException extends AmbariException {
 
   public ServiceComponentNotFoundException (String clusterName,

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceNotFoundException.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceNotFoundException.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceNotFoundException.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceNotFoundException.java Mon Oct 22 21:19:10 2012
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server;
 
+@SuppressWarnings("serial")
 public class ServiceNotFoundException extends AmbariException {
 
   public ServiceNotFoundException(String clusterName, String serviceName) {

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java Mon Oct 22 21:19:10 2012
@@ -53,7 +53,8 @@ public class ActionManager {
     scheduler = new ActionScheduler(schedulerSleepTime, actionTimeout, db,
         actionQueue, fsm, 2);
     this.fsm = fsm;
-    requestCounter = new AtomicLong(db.getLastPersistedRequestIdWhenInitialized());
+    requestCounter = new AtomicLong(
+        db.getLastPersistedRequestIdWhenInitialized());
   }
 
   public void start() {

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java Mon Oct 22 21:19:10 2012
@@ -30,7 +30,7 @@ import org.apache.ambari.server.state.Cl
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
-import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpFailedEvent;
 import org.apache.ambari.server.utils.StageUtils;
 import org.apache.commons.logging.Log;
@@ -86,7 +86,7 @@ class ActionScheduler implements Runnabl
       }
     }
   }
-  
+
   private void doWork() throws AmbariException {
     List<Stage> stages = db.getStagesInProgress();
     LOG.info("Scheduler wakes up");
@@ -95,7 +95,7 @@ class ActionScheduler implements Runnabl
       LOG.info("No stage in progress..nothing to do");
       return;
     }
-    
+
     for (Stage s : stages) {
       List<ExecutionCommand> commandsToSchedule = new ArrayList<ExecutionCommand>();
       Map<String, RoleStats> roleStats = processInProgressStage(s, commandsToSchedule);
@@ -120,13 +120,13 @@ class ActionScheduler implements Runnabl
       for (ExecutionCommand cmd : commandsToSchedule) {
         try {
           scheduleHostRole(s, cmd);
-        } catch (InvalidStateTransitonException e) {
+        } catch (InvalidStateTransitionException e) {
           LOG.warn("Could not schedule host role "+cmd.toString(), e);
           db.abortHostRole(cmd.getHostname(), s.getRequestId(), s.getStageId(),
               cmd.getRole());
         }
       }
-      
+
       //Check if ready to go to next stage
       boolean goToNextStage = true;
       for (String role: roleStats.keySet()) {
@@ -141,10 +141,10 @@ class ActionScheduler implements Runnabl
       }
     }
   }
-  
+
   /**
-   * @param commandsToSchedule 
-   * @return Stats for the roles in the stage. It is used to determine whether stage 
+   * @param commandsToSchedule
+   * @return Stats for the roles in the stage. It is used to determine whether stage
    * has succeeded or failed.
    */
   private Map<String, RoleStats> processInProgressStage(Stage s,
@@ -161,7 +161,7 @@ class ActionScheduler implements Runnabl
           stats = new RoleStats(s.getHosts().size(), 1);
           roleStats.put(roleStr, stats);
         }
-        HostRoleStatus status = s.getHostRoleStatus(host, roleStr);    
+        HostRoleStatus status = s.getHostRoleStatus(host, roleStr);
         LOG.info("Last attempt time =" + s.getLastAttemptTime(host, roleStr)
             + ", actiontimeout =" + this.actionTimeout + ", current time="
             + now+", status ="+status+", attempt count="+s.getAttemptCount(host, roleStr));
@@ -186,7 +186,7 @@ class ActionScheduler implements Runnabl
               ServiceComponentHost svcCompHost =
                   svcComp.getServiceComponentHost(host);
               svcCompHost.handleEvent(timeoutEvent);
-            } catch (InvalidStateTransitonException e) {
+            } catch (InvalidStateTransitionException e) {
               LOG.info("Transition failed for host: "+host+", role: "+roleStr, e);
             } catch (AmbariException ex) {
               LOG.info("Invalid live state", ex);
@@ -204,12 +204,12 @@ class ActionScheduler implements Runnabl
     return roleStats;
   }
 
-  private boolean timeOutActionNeeded(HostRoleStatus status, Stage stage, 
+  private boolean timeOutActionNeeded(HostRoleStatus status, Stage stage,
       String host, String role, long currentTime) {
     LOG.info("Last attempt time =" + stage.getLastAttemptTime(host, role)
         + ", actiontimeout =" + this.actionTimeout + ", current time="
         + currentTime+", role="+role+", status="+status);
-    
+
     if (( !status.equals(HostRoleStatus.QUEUED) ) &&
         ( ! status.equals(HostRoleStatus.IN_PROGRESS) )) {
       return false;
@@ -221,7 +221,7 @@ class ActionScheduler implements Runnabl
   }
 
   private void scheduleHostRole(Stage s, ExecutionCommand cmd)
-      throws InvalidStateTransitonException, AmbariException {
+      throws InvalidStateTransitionException, AmbariException {
     long now = System.currentTimeMillis();
     String roleStr = cmd.getRole().toString();
     String hostname = cmd.getHostname();
@@ -237,7 +237,7 @@ class ActionScheduler implements Runnabl
         svcCompHost.handleEvent(s.getFsmEvent(hostname, roleStr));
         s.setStartTime(hostname,roleStr, now);
         s.setHostRoleStatus(hostname, roleStr, HostRoleStatus.QUEUED);
-      } catch (InvalidStateTransitonException e) {
+      } catch (InvalidStateTransitionException e) {
         LOG.info(
             "Transition failed for host: " + hostname + ", role: "
                 + roleStr, e);
@@ -323,7 +323,7 @@ class ActionScheduler implements Runnabl
         return true;
       }
     }
-    
+
     public String toString() {
       StringBuilder builder = new StringBuilder();
       builder.append("numQueued="+numQueued);

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java Mon Oct 22 21:19:10 2012
@@ -34,7 +34,7 @@ import org.apache.ambari.server.state.Se
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.State;
-import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.apache.ambari.server.state.host.HostHealthyHeartbeatEvent;
 import org.apache.ambari.server.state.host.HostRegistrationRequestEvent;
 import org.apache.ambari.server.state.host.HostStatusUpdatesReceivedEvent;
@@ -90,7 +90,7 @@ public class HeartBeatHandler {
         hostObject.handleEvent(new HostUnhealthyHeartbeatEvent(hostname, now,
             null));
       }
-    } catch (InvalidStateTransitonException ex) {
+    } catch (InvalidStateTransitionException ex) {
       hostObject.setState(HostState.INIT);
       RegistrationCommand regCmd = new RegistrationCommand();
       response.setRegistrationCommand(regCmd);
@@ -123,7 +123,7 @@ public class HeartBeatHandler {
           scHost.handleEvent(new ServiceComponentHostOpSucceededEvent(scHost
               .getServiceComponentName(), hostname, now));
         }
-      } catch (InvalidStateTransitonException ex) {
+      } catch (InvalidStateTransitionException ex) {
         throw new AmbariException("State machine exception", ex);
       }
       LOG.info("Report for "+report.toString() +", processed successfully");
@@ -174,7 +174,7 @@ public class HeartBeatHandler {
   }
 
   public RegistrationResponse handleRegistration(Register register)
-      throws InvalidStateTransitonException, AmbariException {
+      throws InvalidStateTransitionException, AmbariException {
     String hostname = register.getHostname();
     long now = System.currentTimeMillis();
     Host hostObject;
@@ -196,7 +196,7 @@ public class HeartBeatHandler {
       statusCmd.setRoles(roles);
       cmds.add(statusCmd);
     }
-    
+
     hostObject.handleEvent(new HostRegistrationRequestEvent(hostname,
         new AgentVersion("v1"), now, register.getHardwareProfile()));
     RegistrationResponse response = new RegistrationResponse();

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java Mon Oct 22 21:19:10 2012
@@ -24,7 +24,7 @@ import org.apache.ambari.server.actionma
 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.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.apache.ambari.server.state.host.HostHeartbeatLostEvent;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -76,7 +76,7 @@ public class HeartbeatMonitor implements
   //Go through all the nodes, check for last heartbeat or any waiting state
   //If heartbeat is lost, update node fsm state, purge the action queue
   //notify action manager for node failure.
-  private void doWork() throws InvalidStateTransitonException {
+  private void doWork() throws InvalidStateTransitionException {
     List<Host> allHosts = fsm.getHosts();
     LOG.info("Number of hosts to monitor: "+allHosts.size());
     long now = System.currentTimeMillis();

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/rest/AgentResource.java Mon Oct 22 21:19:10 2012
@@ -33,7 +33,7 @@ import org.apache.ambari.server.agent.He
 import org.apache.ambari.server.agent.HeartBeatResponse;
 import org.apache.ambari.server.agent.Register;
 import org.apache.ambari.server.agent.RegistrationResponse;
-import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -64,7 +64,7 @@ public class AgentResource {
    * @response.representation.406.doc Error in register message format
    * @response.representation.408.doc Request Timed out
    * @param message Register message
-   * @throws InvalidStateTransitonException
+   * @throws InvalidStateTransitionException
    * @throws AmbariException
    * @throws Exception
    */
@@ -74,10 +74,10 @@ public class AgentResource {
   @Produces({MediaType.APPLICATION_JSON})
   public RegistrationResponse register(Register message,
       @Context HttpServletRequest req)
-      throws WebApplicationException, AmbariException, InvalidStateTransitonException {
+      throws WebApplicationException, AmbariException, InvalidStateTransitionException {
     LOG.info("Received message from agent " + message.toString());
     /* Call into the heartbeat handler */
-    
+
     RegistrationResponse response = hh.handleRegistration(message);
     return response;
   }

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=1401083&r1=1401082&r2=1401083&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 Mon Oct 22 21:19:10 2012
@@ -77,14 +77,14 @@ public interface AmbariManagementControl
    */
   public void createHostComponents(
       Set<ServiceComponentHostRequest> request) throws AmbariException;
-  
+
   /**
    * Creates a configuration.
-   * 
+   *
    * @param request the request object which defines the configuration.
-   * 
+   *
    * @return a track action response
-   * 
+   *
    * @throws AmbariException when the configuration cannot be created.
    */
   public TrackActionResponse createConfiguration(ConfigurationRequest request) throws AmbariException;
@@ -152,14 +152,14 @@ public interface AmbariManagementControl
    */
   public Set<ServiceComponentHostResponse> getHostComponents(
       ServiceComponentHostRequest request) throws AmbariException;
-  
+
   /**
    * Gets the configurations identified by the given request object.
-   * 
+   *
    * @param request   the request object
-   * 
+   *
    * @return  a set of configuration responses
-   * 
+   *
    * @throws AmbariException if the configurations could not be read
    */
   public Set<ConfigurationResponse> getConfigurations(ConfigurationRequest request) throws AmbariException;
@@ -247,7 +247,7 @@ public interface AmbariManagementControl
    *
    * @throws AmbariException thrown if the resource cannot be deleted
    */
-  public TrackActionResponse deleteCluster(ClusterRequest request) throws AmbariException;
+  public void deleteCluster(ClusterRequest request) throws AmbariException;
 
   /**
    * Delete the service identified by the given request object.
@@ -282,7 +282,7 @@ public interface AmbariManagementControl
    *
    * @throws AmbariException thrown if the resource cannot be deleted
    */
-  public TrackActionResponse deleteHosts(Set<HostRequest> request)
+  public void deleteHosts(Set<HostRequest> 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=1401083&r1=1401082&r2=1401083&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 Mon Oct 22 21:19:10 2012
@@ -28,6 +28,7 @@ import java.util.Set;
 import java.util.TreeMap;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ClusterNotFoundException;
 import org.apache.ambari.server.HostNotFoundException;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
@@ -104,7 +105,8 @@ public class AmbariManagementControllerI
   public void createCluster(ClusterRequest request)
       throws AmbariException {
     if (request.getClusterName() == null
-        || request.getClusterName().isEmpty()) {
+        || request.getClusterName().isEmpty()
+        || request.getClusterId() != null) {
       // FIXME throw correct error
       throw new AmbariException("Invalid arguments");
     }
@@ -118,6 +120,21 @@ public class AmbariManagementControllerI
     // FIXME validate stack version
     // FIXME add support for desired configs at cluster level
 
+    boolean foundInvalidHosts = false;
+    if (request.getHostNames() != null) {
+      for (String hostname : request.getHostNames()) {
+        try {
+          clusters.getHost(hostname);
+        } catch (HostNotFoundException e) {
+          foundInvalidHosts = true;
+        }
+      }
+    }
+    if (foundInvalidHosts) {
+      // FIXME throw correct error
+      throw new AmbariException("Invalid arguments, invalid hosts found");
+    }
+
     clusters.addCluster(request.getClusterName());
 
     if (request.getHostNames() != null) {
@@ -134,7 +151,7 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public void createServices(Set<ServiceRequest> requests)
+  public synchronized void createServices(Set<ServiceRequest> requests)
       throws AmbariException {
 
     if (requests.isEmpty()) {
@@ -162,6 +179,8 @@ public class AmbariManagementControllerI
             + ", request=" + request);
       }
 
+      // FIXME Validate against meta data
+
       if (!serviceNames.containsKey(request.getClusterName())) {
         serviceNames.put(request.getClusterName(), new HashSet<String>());
       }
@@ -230,6 +249,9 @@ public class AmbariManagementControllerI
       Map<String, Config> configs = new HashMap<String, Config>();
 
       State state = State.INIT;
+
+      // FIXME should the below part be removed?
+      // What about take over situations?
       if (request.getDesiredState() != null
           && !request.getDesiredState().isEmpty()) {
         state = State.valueOf(request.getDesiredState());
@@ -248,7 +270,7 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public void createComponents(
+  public synchronized void createComponents(
       Set<ServiceComponentRequest> requests) throws AmbariException {
 
     if (requests.isEmpty()) {
@@ -282,6 +304,8 @@ public class AmbariManagementControllerI
             + ", request=" + request);
       }
 
+      // FIXME Validate against meta data
+
       if (!componentNames.containsKey(request.getClusterName())) {
         componentNames.put(request.getClusterName(),
             new HashMap<String, Set<String>>());
@@ -386,7 +410,7 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public void createHosts(Set<HostRequest> requests)
+  public synchronized void createHosts(Set<HostRequest> requests)
       throws AmbariException {
 
     if (requests.isEmpty()) {
@@ -425,6 +449,20 @@ public class AmbariManagementControllerI
         unknowns.add(request.getHostname());
         continue;
       }
+
+      if (request.getClusterNames() != null) {
+        for (String clusterName : request.getClusterNames()) {
+          try {
+            clusters.getCluster(clusterName);
+          } catch (ClusterNotFoundException e) {
+            // invalid cluster mapping
+            throw new AmbariException("Trying to map host to a non-existent"
+                + " cluster"
+                + ", hostname=" + request.getHostname()
+                + ", clusterName=" + clusterName);
+          }
+        }
+      }
     }
 
     if (!duplicates.isEmpty()) {
@@ -474,7 +512,7 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public void createHostComponents(Set<ServiceComponentHostRequest> requests)
+  public synchronized void createHostComponents(Set<ServiceComponentHostRequest> requests)
       throws AmbariException {
 
     if (requests.isEmpty()) {
@@ -660,34 +698,34 @@ public class AmbariManagementControllerI
     }
 
   }
-  
-  
-  public TrackActionResponse createConfiguration(ConfigurationRequest request) throws AmbariException {
+
+
+  public synchronized TrackActionResponse createConfiguration(ConfigurationRequest request) throws AmbariException {
     if (null == request.getClusterName() || request.getClusterName().isEmpty() ||
         null == request.getType() || request.getType().isEmpty() ||
         null == request.getVersionTag() || request.getVersionTag().isEmpty() ||
         null == request.getConfigs() || request.getConfigs().isEmpty()) {
       throw new AmbariException ("Invalid Arguments.");
     }
-      
+
     Cluster cluster = clusters.getCluster(request.getClusterName());
-      
+
     Map<String, Config> configs = cluster.getDesiredConfigsByType(request.getType());
     if (null == configs) {
       configs = new HashMap<String, Config>();
     }
-    
+
     Config config = configs.get(request.getVersionTag());
     if (configs.containsKey(request.getVersionTag()))
       throw new AmbariException("Configuration with that tag exists for '" + request.getType() + "'");
-    
+
     config = configFactory.createNew (cluster, request.getType(), request.getConfigs());
     config.setVersionTag(request.getVersionTag());
-    
+
     config.persist();
-    
+
     cluster.addDesiredConfig(config);
-    
+
     // TODO
     return null;
   }
@@ -745,7 +783,7 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public Set<ClusterResponse> getClusters(ClusterRequest request)
+  public synchronized Set<ClusterResponse> getClusters(ClusterRequest request)
       throws AmbariException {
     Set<ClusterResponse> response = new HashSet<ClusterResponse>();
 
@@ -759,8 +797,7 @@ public class AmbariManagementControllerI
 
     Map<String, Cluster> allClusters = clusters.getClusters();
     for (Cluster c : allClusters.values()) {
-      if (request.getStackVersion() != null
-          && !request.getStackVersion().isEmpty()) {
+      if (request.getStackVersion() != null) {
         if (!request.getStackVersion().equals(
             c.getDesiredStackVersion().getStackVersion())) {
           // skip non matching stack versions
@@ -773,7 +810,7 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public Set<ServiceResponse> getServices(ServiceRequest request)
+  public synchronized Set<ServiceResponse> getServices(ServiceRequest request)
       throws AmbariException {
     if (request.getClusterName() == null
         || request.getClusterName().isEmpty()) {
@@ -816,7 +853,7 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public Set<ServiceComponentResponse> getComponents(
+  public synchronized Set<ServiceComponentResponse> getComponents(
       ServiceComponentRequest request) throws AmbariException {
     if (request.getClusterName() == null
         || request.getClusterName().isEmpty()) {
@@ -875,11 +912,12 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public Set<HostResponse> getHosts(HostRequest request)
+  public synchronized Set<HostResponse> getHosts(HostRequest request)
       throws AmbariException {
     Set<HostResponse> response = new HashSet<HostResponse>();
 
     // FIXME what is the requirement for filtering on host attributes?
+    // FIXME do we need get all hosts in given list of clusters?
 
     List<Host> hosts = null;
     if (request.getHostname() != null) {
@@ -893,7 +931,7 @@ public class AmbariManagementControllerI
     for (Host h : hosts) {
       HostResponse r = h.convertToResponse();
       Set<Cluster> cs =
-          clusters.getClustersForHost(request.getHostname());
+          clusters.getClustersForHost(h.getHostName());
       for (Cluster c : cs) {
         r.getClusterNames().add(c.getClusterName());
       }
@@ -903,7 +941,7 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public Set<ServiceComponentHostResponse> getHostComponents(
+  public synchronized Set<ServiceComponentHostResponse> getHostComponents(
       ServiceComponentHostRequest request) throws AmbariException {
     if (request.getClusterName() == null
         || request.getClusterName().isEmpty()) {
@@ -992,15 +1030,15 @@ public class AmbariManagementControllerI
     return response;
   }
 
-  
+
   @Override
-  public Set<ConfigurationResponse> getConfigurations(ConfigurationRequest request) throws AmbariException {
+  public synchronized Set<ConfigurationResponse> getConfigurations(ConfigurationRequest request) throws AmbariException {
     if (request.getClusterName() == null) {
       throw new AmbariException("Invalid arguments");
     }
-    
+
     Cluster cluster = clusters.getCluster(request.getClusterName());
-    
+
     Set<ConfigurationResponse> responses = new HashSet<ConfigurationResponse>();
 
     // !!! if only one, then we need full properties
@@ -1016,7 +1054,7 @@ public class AmbariManagementControllerI
     else {
       if (null != request.getType()) {
         Map<String, Config> configs = cluster.getDesiredConfigsByType(request.getType());
-        
+
         for (Entry<String, Config> entry : configs.entrySet()) {
           ConfigurationResponse response = new ConfigurationResponse(
               cluster.getClusterName(), request.getType(),
@@ -1025,14 +1063,14 @@ public class AmbariManagementControllerI
         }
       }
     }
-    
+
     return responses;
 
   }
-  
+
 
   @Override
-  public TrackActionResponse updateCluster(ClusterRequest request)
+  public synchronized TrackActionResponse updateCluster(ClusterRequest request)
       throws AmbariException {
     // for now only update host list supported
     if (request.getClusterName() == null
@@ -1091,6 +1129,7 @@ public class AmbariManagementControllerI
     long requestId = actionManager.getNextRequestId();
 
     // FIXME cannot work with a single stage
+    // multiple stages may be needed for reconfigure
     long stageId = 0;
     Stage stage = createNewStage(cluster, requestId);
     stage.setStageId(stageId);
@@ -1118,7 +1157,12 @@ public class AmbariManagementControllerI
                     nowTimestamp);
               } else {
                 // FIXME throw correct error
-                throw new AmbariException("Invalid transition"
+                throw new AmbariException("Invalid transition for "
+                    + ", clusterName=" + cluster.getClusterName()
+                    + ", clusterId=" + cluster.getClusterId()
+                    + ", serviceName=" + scHost.getServiceName()
+                    + ", componentName=" + scHost.getServiceComponentName()
+                    + ", hostname=" + scHost.getHostName()
                     + ", oldDesiredState=" + oldSchState
                     + ", newDesiredState" + newState);
               }
@@ -1131,7 +1175,12 @@ public class AmbariManagementControllerI
                     nowTimestamp);
               } else {
                 // FIXME throw correct error
-                throw new AmbariException("Invalid transition"
+                throw new AmbariException("Invalid transition for "
+                    + ", clusterName=" + cluster.getClusterName()
+                    + ", clusterId=" + cluster.getClusterId()
+                    + ", serviceName=" + scHost.getServiceName()
+                    + ", componentName=" + scHost.getServiceComponentName()
+                    + ", hostname=" + scHost.getHostName()
                     + ", oldDesiredState=" + oldSchState
                     + ", newDesiredState" + newState);
               }
@@ -1199,9 +1248,29 @@ public class AmbariManagementControllerI
 
   }
 
+  private boolean isValidTransition(State oldState, State newState) {
+    switch(newState) {
+      case INSTALLED:
+        if (oldState == State.INIT
+            || oldState == State.UNINSTALLED
+            || oldState == State.INSTALLED
+            || oldState == State.STARTED) {
+          return true;
+        }
+        break;
+      case STARTED:
+        if (oldState == State.INSTALLED
+            || oldState == State.STARTED) {
+          return true;
+        }
+        break;
+    }
+    return false;
+  }
+
 
   @Override
-  public TrackActionResponse updateServices(Set<ServiceRequest> requests)
+  public synchronized TrackActionResponse updateServices(Set<ServiceRequest> requests)
       throws AmbariException {
 
     if (requests.isEmpty()) {
@@ -1292,6 +1361,16 @@ public class AmbariManagementControllerI
 
       State oldState = s.getDesiredState();
       if (newState != oldState) {
+        if (!isValidTransition(oldState, newState)) {
+          // FIXME throw correct error
+          throw new AmbariException("Invalid transition for "
+              + ", clusterName=" + cluster.getClusterName()
+              + ", clusterId=" + cluster.getClusterId()
+              + ", serviceName=" + s.getName()
+              + ", oldDesiredState=" + oldState
+              + ", newDesiredState" + newState);
+
+        }
         if (!changedServices.containsKey(newState)) {
           changedServices.put(newState, new ArrayList<Service>());
         }
@@ -1309,6 +1388,20 @@ public class AmbariManagementControllerI
       for (ServiceComponent sc : s.getServiceComponents().values()) {
         State oldScState = sc.getDesiredState();
         if (newState != oldScState) {
+          if (sc.isClientComponent() &&
+              !newState.isValidClientComponentState()) {
+            continue;
+          }
+          if (!isValidTransition(oldScState, newState)) {
+            // FIXME throw correct error
+            throw new AmbariException("Invalid transition for "
+                + ", clusterName=" + cluster.getClusterName()
+                + ", clusterId=" + cluster.getClusterId()
+                + ", serviceName=" + sc.getServiceName()
+                + ", componentName=" + sc.getName()
+                + ", oldDesiredState=" + oldScState
+                + ", newDesiredState" + newState);
+          }
           if (!changedComps.containsKey(newState)) {
             changedComps.put(newState, new ArrayList<ServiceComponent>());
           }
@@ -1319,22 +1412,38 @@ public class AmbariManagementControllerI
               + ", clusterName=" + request.getClusterName()
               + ", serviceName=" + s.getName()
               + ", componentName=" + sc.getName()
-              + ", currentState=" + sc.getDesiredState()
-              + ", newState=" + newState);
+              + ", oldDesiredState=" + oldScState
+              + ", newDesiredState=" + newState);
         }
-        for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
-          if (newState == sch.getDesiredState()) {
+        for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()){
+          State oldSchState = sch.getDesiredState();
+          if (newState == oldSchState) {
             if (LOG.isDebugEnabled()) {
               LOG.debug("Ignoring ServiceComponentHost"
                   + ", clusterName=" + request.getClusterName()
                   + ", serviceName=" + s.getName()
                   + ", componentName=" + sc.getName()
                   + ", hostname=" + sch.getHostName()
-                  + ", currentState=" + sch.getDesiredState()
-                  + ", newState=" + newState);
+                  + ", oldDesiredState=" + oldSchState
+                  + ", newDesiredState=" + newState);
             }
             continue;
           }
+          if (sc.isClientComponent() &&
+              !newState.isValidClientComponentState()) {
+            continue;
+          }
+          if (!isValidTransition(oldSchState, newState)) {
+            // FIXME throw correct error
+            throw new AmbariException("Invalid transition for "
+                + ", clusterName=" + cluster.getClusterName()
+                + ", clusterId=" + cluster.getClusterId()
+                + ", serviceName=" + sch.getServiceName()
+                + ", componentName=" + sch.getServiceComponentName()
+                + ", hostname=" + sch.getHostName()
+                + ", oldDesiredState=" + oldSchState
+                + ", newDesiredState" + newState);
+          }
           if (!changedScHosts.containsKey(sc.getName())) {
             changedScHosts.put(sc.getName(),
                 new HashMap<State, List<ServiceComponentHost>>());
@@ -1349,8 +1458,8 @@ public class AmbariManagementControllerI
                 + ", serviceName=" + s.getName()
                 + ", componentName=" + sc.getName()
                 + ", hostname=" + sch.getHostName()
-                + ", currentState=" + sch.getDesiredState()
-                + ", newState=" + newState);
+                + ", oldDesiredState=" + oldSchState
+                + ", newDesiredState=" + newState);
           }
           changedScHosts.get(sc.getName()).get(newState).add(sch);
         }
@@ -1372,7 +1481,7 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public TrackActionResponse updateComponents(
+  public synchronized TrackActionResponse updateComponents(
       Set<ServiceComponentRequest> requests) throws AmbariException {
 
     if (requests.isEmpty()) {
@@ -1473,10 +1582,26 @@ public class AmbariManagementControllerI
         throw new AmbariException("Invalid desired state");
       }
 
+      if (sc.isClientComponent() &&
+          !newState.isValidClientComponentState()) {
+        throw new AmbariException("Invalid desired state for a client"
+            + " component");
+      }
+
       seenNewStates.add(newState);
 
-      State oldState = sc.getDesiredState();
-      if (newState != oldState) {
+      State oldScState = sc.getDesiredState();
+      if (newState != oldScState) {
+        if (!isValidTransition(oldScState, newState)) {
+          // FIXME throw correct error
+          throw new AmbariException("Invalid transition for "
+              + ", clusterName=" + cluster.getClusterName()
+              + ", clusterId=" + cluster.getClusterId()
+              + ", serviceName=" + sc.getServiceName()
+              + ", componentName=" + sc.getName()
+              + ", oldDesiredState=" + oldScState
+              + ", newDesiredState" + newState);
+        }
         if (!changedComps.containsKey(newState)) {
           changedComps.put(newState, new ArrayList<ServiceComponent>());
         }
@@ -1485,8 +1610,8 @@ public class AmbariManagementControllerI
               + ", clusterName=" + request.getClusterName()
               + ", serviceName=" + s.getName()
               + ", componentName=" + sc.getName()
-              + ", currentState=" + sc.getDesiredState()
-              + ", newState=" + newState);
+              + ", oldDesiredState=" + oldScState
+              + ", newDesiredState=" + newState);
         }
         changedComps.get(newState).add(sc);
       }
@@ -1496,18 +1621,30 @@ public class AmbariManagementControllerI
       // at some point do we need to do stuff based on live state?
 
       for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
-        if (newState == sch.getDesiredState()) {
+        State oldSchState = sch.getDesiredState();
+        if (newState == oldSchState) {
           if (LOG.isDebugEnabled()) {
             LOG.debug("Ignoring ServiceComponentHost"
                 + ", clusterName=" + request.getClusterName()
                 + ", serviceName=" + s.getName()
                 + ", componentName=" + sc.getName()
                 + ", hostname=" + sch.getHostName()
-                + ", currentState=" + sch.getDesiredState()
-                + ", newState=" + newState);
+                + ", oldDesiredState=" + oldSchState
+                + ", newDesiredState=" + newState);
           }
           continue;
         }
+        if (!isValidTransition(oldSchState, newState)) {
+          // FIXME throw correct error
+          throw new AmbariException("Invalid transition for "
+              + ", clusterName=" + cluster.getClusterName()
+              + ", clusterId=" + cluster.getClusterId()
+              + ", serviceName=" + sch.getServiceName()
+              + ", componentName=" + sch.getServiceComponentName()
+              + ", hostname=" + sch.getHostName()
+              + ", oldDesiredState=" + oldSchState
+              + ", newDesiredState" + newState);
+        }
         if (!changedScHosts.containsKey(sc.getName())) {
           changedScHosts.put(sc.getName(),
               new HashMap<State, List<ServiceComponentHost>>());
@@ -1522,8 +1659,8 @@ public class AmbariManagementControllerI
               + ", serviceName=" + s.getName()
               + ", componentName=" + sc.getName()
               + ", hostname=" + sch.getHostName()
-              + ", currentState=" + sch.getDesiredState()
-              + ", newState=" + newState);
+              + ", oldDesiredState=" + oldSchState
+              + ", newDesiredState=" + newState);
         }
         changedScHosts.get(sc.getName()).get(newState).add(sch);
       }
@@ -1537,6 +1674,9 @@ public class AmbariManagementControllerI
 
     // TODO additional validation?
 
+    // TODO if all components reach a common state, should service state be
+    // modified?
+
     Cluster cluster = clusters.getCluster(clusterNames.iterator().next());
 
     return doStageCreation(cluster, null,
@@ -1544,7 +1684,7 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public void updateHosts(Set<HostRequest> requests)
+  public synchronized void updateHosts(Set<HostRequest> requests)
       throws AmbariException {
 
     if (requests.isEmpty()) {
@@ -1577,7 +1717,7 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public TrackActionResponse updateHostComponents(
+  public synchronized TrackActionResponse updateHostComponents(
       Set<ServiceComponentHostRequest> requests) throws AmbariException {
 
     if (requests.isEmpty()) {
@@ -1688,22 +1828,39 @@ public class AmbariManagementControllerI
         throw new AmbariException("Invalid desired state");
       }
 
+      if (sc.isClientComponent() &&
+          !newState.isValidClientComponentState()) {
+        throw new AmbariException("Invalid desired state for a client"
+            + " component");
+      }
+
       seenNewStates.add(newState);
 
-      State oldState = sch.getDesiredState();
-      if (newState == oldState) {
+      State oldSchState = sch.getDesiredState();
+      if (newState == oldSchState) {
         if (LOG.isDebugEnabled()) {
           LOG.debug("Ignoring ServiceComponentHost"
               + ", clusterName=" + request.getClusterName()
               + ", serviceName=" + s.getName()
               + ", componentName=" + sc.getName()
               + ", hostname=" + sch.getHostName()
-              + ", currentState=" + sch.getDesiredState()
-              + ", newState=" + newState);
+              + ", oldDesiredState=" + oldSchState
+              + ", newDesiredState=" + newState);
         }
         continue;
       }
 
+      if (!isValidTransition(oldSchState, newState)) {
+        // FIXME throw correct error
+        throw new AmbariException("Invalid transition for "
+            + ", clusterName=" + cluster.getClusterName()
+            + ", clusterId=" + cluster.getClusterId()
+            + ", serviceName=" + sch.getServiceName()
+            + ", componentName=" + sch.getServiceComponentName()
+            + ", hostname=" + sch.getHostName()
+            + ", oldDesiredState=" + oldSchState
+            + ", newDesiredState" + newState);
+      }
       if (!changedScHosts.containsKey(sc.getName())) {
         changedScHosts.put(sc.getName(),
             new HashMap<State, List<ServiceComponentHost>>());
@@ -1718,8 +1875,8 @@ public class AmbariManagementControllerI
             + ", serviceName=" + s.getName()
             + ", componentName=" + sc.getName()
             + ", hostname=" + sch.getHostName()
-            + ", currentState=" + sch.getDesiredState()
-            + ", newState=" + newState);
+            + ", oldDesiredState=" + oldSchState
+            + ", newDesiredState=" + newState);
       }
       changedScHosts.get(sc.getName()).get(newState).add(sch);
     }
@@ -1743,10 +1900,35 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public TrackActionResponse deleteCluster(ClusterRequest request)
+  public synchronized void deleteCluster(ClusterRequest request)
       throws AmbariException {
-    // TODO not implemented yet
-    throw new AmbariException("Delete cluster not supported");
+    if (request.getClusterName() == null
+        || request.getClusterName().isEmpty()) {
+      // FIXME throw correct error
+      throw new AmbariException("Invalid arguments");
+    }
+    LOG.info("Received a delete cluster request"
+        + ", clusterName=" + request.getClusterName());
+    Cluster cluster = clusters.getCluster(request.getClusterName());
+    if (!cluster.getServices().isEmpty()) {
+      // FIXME should we be looking at live state of all components and
+      // host components?
+      boolean nonDeletableService = false;
+      for (Service service : cluster.getServices().values()) {
+        if (!service.canBeRemoved()) {
+          nonDeletableService = true;
+          LOG.warn("Found non removable service when trying to delete cluster"
+              + ", clusterName=" + request.getClusterName()
+              + ", serviceName=" + service.getName());
+        }
+      }
+      if (nonDeletableService) {
+        throw new AmbariException("Cannot delete cluster as it has services"
+            + " that cannot be deleted");
+      }
+    }
+    cluster.deleteAllServices();
+    clusters.deleteCluster(request.getClusterName());
   }
 
   @Override
@@ -1764,7 +1946,7 @@ public class AmbariManagementControllerI
   }
 
   @Override
-  public TrackActionResponse deleteHosts(Set<HostRequest> request)
+  public void deleteHosts(Set<HostRequest> request)
       throws AmbariException {
     throw new AmbariException("Delete hosts not supported");
   }

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=1401083&r1=1401082&r2=1401083&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 Mon Oct 22 21:19:10 2012
@@ -100,7 +100,7 @@ public class JDBCManagementController im
   public void createCluster(ClusterRequest request) throws AmbariException {
 //    createResources(Resource.Type.Cluster, request);
   }
-  
+
   @Override
   public TrackActionResponse createConfiguration(ConfigurationRequest request)
       throws AmbariException {
@@ -133,7 +133,7 @@ public class JDBCManagementController im
   public Set<ServiceComponentHostResponse> getHostComponents(ServiceComponentHostRequest request) throws AmbariException {
     return null;
   }
-  
+
   @Override
   public Set<ConfigurationResponse> getConfigurations(ConfigurationRequest request) throws AmbariException {
     return null;
@@ -147,9 +147,8 @@ public class JDBCManagementController im
 
 
   @Override
-  public TrackActionResponse deleteCluster(ClusterRequest request) throws AmbariException {
+  public void deleteCluster(ClusterRequest request) throws AmbariException {
 //    deleteResources(Resource.Type.Cluster, predicate);
-    return null;
   }
 
 
@@ -693,10 +692,9 @@ public class JDBCManagementController im
   }
 
   @Override
-  public TrackActionResponse deleteHosts(Set<HostRequest> request)
+  public void deleteHosts(Set<HostRequest> request)
       throws AmbariException {
     // TODO Auto-generated method stub
-    return null;
   }
 
   @Override

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java Mon Oct 22 21:19:10 2012
@@ -50,7 +50,7 @@ public class StageDAO {
     if (result != null) {
       return result;
     } else {
-      return -1;
+      return 0;
     }
   }
 

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=1401083&r1=1401082&r2=1401083&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 Mon Oct 22 21:19:10 2012
@@ -92,4 +92,8 @@ public interface Cluster {
   public void debugDump(StringBuilder sb);
 
   Service addService(String serviceName) throws AmbariException;
+
+  public void deleteAllServices() throws AmbariException;
+
+  public void deleteService(String serviceName) throws AmbariException;
 }

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=1401083&r1=1401082&r2=1401083&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 Mon Oct 22 21:19:10 2012
@@ -103,4 +103,6 @@ public interface Clusters {
   public Map<String, Host> getHostsForCluster(String clusterName)
       throws AmbariException;
 
+  public void deleteCluster(String clusterName);
+
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java Mon Oct 22 21:19:10 2012
@@ -24,7 +24,7 @@ import java.util.Map;
 import org.apache.ambari.server.agent.DiskInfo;
 import org.apache.ambari.server.agent.HostInfo;
 import org.apache.ambari.server.controller.HostResponse;
-import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.apache.ambari.server.state.job.Job;
 
 public interface Host {
@@ -233,10 +233,10 @@ public interface Host {
   /**
    * Send an event to the Host's StateMachine
    * @param event HostEvent
-   * @throws InvalidStateTransitonException
+   * @throws InvalidStateTransitionException
    */
   public void handleEvent(HostEvent event)
-      throws InvalidStateTransitonException;
+      throws InvalidStateTransitionException;
 
   /**
    * Get time spent in the current state i.e. the time since last state change.

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java Mon Oct 22 21:19:10 2012
@@ -68,4 +68,11 @@ public interface Service {
 
   ServiceComponent addServiceComponent(String serviceComponentName)
       throws AmbariException;
+
+  /**
+   * Find out whether the service and its components
+   * are in a state that it can be removed from a cluster
+   * @return
+   */
+  public boolean canBeRemoved();
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java Mon Oct 22 21:19:10 2012
@@ -67,4 +67,7 @@ public interface ServiceComponent {
   void persist();
 
   public void debugDump(StringBuilder sb);
+
+  public boolean isClientComponent();
+
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java Mon Oct 22 21:19:10 2012
@@ -23,7 +23,7 @@ import java.util.Map;
 
 import com.google.inject.persist.Transactional;
 import org.apache.ambari.server.controller.ServiceComponentHostResponse;
-import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.apache.ambari.server.state.job.Job;
 
 
@@ -67,10 +67,10 @@ public interface ServiceComponentHost {
   /**
    * Send a ServiceComponentHostState event to the StateMachine
    * @param event Event to handle
-   * @throws InvalidStateTransitonException
+   * @throws InvalidStateTransitionException
    */
   public void handleEvent(ServiceComponentHostEvent event)
-      throws InvalidStateTransitonException;
+      throws InvalidStateTransitionException;
 
   public State getDesiredState();
 

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=1401083&r1=1401082&r2=1401083&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 Mon Oct 22 21:19:10 2012
@@ -66,6 +66,7 @@ public class ServiceComponentImpl implem
   private Map<String, ServiceComponentHost> hostComponents;
   private Injector injector;
 
+  private final boolean isClientComponent;
 
   private void init() {
     // TODO
@@ -73,7 +74,8 @@ public class ServiceComponentImpl implem
   }
 
   @AssistedInject
-  public ServiceComponentImpl(@Assisted Service service, @Assisted String componentName, Injector injector) {
+  public ServiceComponentImpl(@Assisted Service service,
+      @Assisted String componentName, Injector injector) {
     this.injector = injector;
     injector.injectMembers(this);
     this.service = service;
@@ -85,6 +87,10 @@ public class ServiceComponentImpl implem
     setDesiredStackVersion(new StackVersion(""));
 
     this.hostComponents = new HashMap<String, ServiceComponentHost>();
+
+    // FIXME use meta data library to decide client or not
+    this.isClientComponent = false;
+
     init();
   }
 
@@ -97,6 +103,9 @@ public class ServiceComponentImpl implem
     this.service = service;
     this.desiredStateEntity = serviceComponentDesiredStateEntity;
 
+    // FIXME use meta data library to decide client or not
+    this.isClientComponent = false;
+
     this.desiredConfigs = new HashMap<String, Config>();
     this.hostComponents = new HashMap<String, ServiceComponentHost>();
     for (HostComponentStateEntity hostComponentStateEntity : desiredStateEntity.getHostComponentStateEntities()) {
@@ -359,5 +368,10 @@ public class ServiceComponentImpl implem
     }
   }
 
+  @Override
+  public boolean isClientComponent() {
+    return this.isClientComponent;
+  }
+
 
 }

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=1401083&r1=1401082&r2=1401083&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 Mon Oct 22 21:19:10 2012
@@ -85,7 +85,6 @@ public class ServiceImpl implements Serv
     serviceEntity.setServiceDesiredStateEntity(serviceDesiredStateEntity);
 
     this.cluster = cluster;
-    this.configs = new HashMap<String, Config>();
     this.desiredConfigs = new HashMap<String, Config>();
     this.components = new HashMap<String, ServiceComponent>();
     setDesiredStackVersion(new StackVersion(""));
@@ -242,9 +241,7 @@ public class ServiceImpl implements Serv
 
   private synchronized Map<String, String> getConfigVersions() {
     Map<String, String> configVersions = new HashMap<String, String>();
-    for (Config c : configs.values()) {
-      configVersions.put(c.getType(), c.getVersionTag());
-    }
+    // FIXME config impl required
     return configVersions;
   }
 
@@ -329,4 +326,10 @@ public class ServiceImpl implements Serv
       serviceDesiredStateDAO.refresh(serviceDesiredStateEntity);
     }
   }
+
+  @Override
+  public boolean canBeRemoved() {
+    // TODO Auto-generated method stub
+    return false;
+  }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/State.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/State.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/State.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/State.java Mon Oct 22 21:19:10 2012
@@ -107,4 +107,17 @@ public enum State {
     }
   }
 
+  public boolean isValidClientComponentState() {
+    switch (State.values()[this.state]) {
+      case STARTING:
+      case STARTED:
+      case START_FAILED:
+      case STOP_FAILED:
+      case STOPPING:
+        return false;
+      default:
+        return true;
+    }
+  }
+
 }

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=1401083&r1=1401082&r2=1401083&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 Mon Oct 22 21:19:10 2012
@@ -21,6 +21,7 @@ package org.apache.ambari.server.state.c
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -116,23 +117,23 @@ public class ClusterImpl implements Clus
     this.serviceComponentHostsByHost = new HashMap<String,
         List<ServiceComponentHost>>();
     this.desiredStackVersion = new StackVersion("");
-    
+
     configs = new HashMap<String, Map<String,Config>>();
     if (!clusterEntity.getClusterConfigEntities().isEmpty()) {
       for (ClusterConfigEntity entity : clusterEntity.getClusterConfigEntities()) {
-        
+
         if (!configs.containsKey(entity.getType())) {
           configs.put(entity.getType(), new HashMap<String, Config>());
         }
 
         Config config = configFactory.createExisting(this, entity);
-        
+
         configs.get(entity.getType()).put(entity.getTag(), config);
       }
     }
-      
-    
-    
+
+
+
   }
 
   public ServiceComponentHost getServiceComponentHost(String serviceName,
@@ -174,13 +175,21 @@ public class ClusterImpl implements Clus
 
   public synchronized void addServiceComponentHost(
       ServiceComponentHost svcCompHost) throws AmbariException {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Trying to add ServiceComponentHost to ClusterHostMap cache"
+          + ", serviceName=" + svcCompHost.getServiceName()
+          + ", componentName=" + svcCompHost.getServiceComponentName()
+          + ", hostname=" + svcCompHost.getHostName());
+    }
+
     final String hostname = svcCompHost.getHostName();
     final String serviceName = svcCompHost.getServiceName();
     final String componentName = svcCompHost.getServiceComponentName();
     Set<Cluster> cs = clusters.getClustersForHost(hostname);
     boolean clusterFound = false;
-    while (cs.iterator().hasNext()) {
-      Cluster c = cs.iterator().next();
+    Iterator<Cluster> iter = cs.iterator();
+    while (iter.hasNext()) {
+      Cluster c = iter.next();
       if (c.getClusterId() == this.getClusterId()) {
         clusterFound = true;
         break;
@@ -375,4 +384,14 @@ public class ClusterImpl implements Clus
     clusterEntity = clusterDAO.findById(clusterEntity.getClusterId());
     clusterDAO.refresh(clusterEntity);
   }
+
+  @Override
+  public void deleteAllServices() throws AmbariException {
+    // TODO Auto-generated method stub
+  }
+
+  @Override
+  public void deleteService(String serviceName) throws AmbariException {
+    // TODO Auto-generated method stub
+  }
 }

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=1401083&r1=1401082&r2=1401083&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 Mon Oct 22 21:19:10 2012
@@ -32,13 +32,18 @@ import com.google.inject.Singleton;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ClusterNotFoundException;
 import org.apache.ambari.server.HostNotFoundException;
+import org.apache.ambari.server.agent.DiskInfo;
 import org.apache.ambari.server.orm.dao.ClusterDAO;
 import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.HostEntity;
+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.HostHealthStatus;
+import org.apache.ambari.server.state.HostHealthStatus.HealthStatus;
+import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.host.HostFactory;
 import org.apache.ambari.server.state.host.HostImpl;
 import org.slf4j.Logger;
@@ -169,7 +174,6 @@ public class ClustersImpl implements Clu
       HostEntity hostEntity = hostDAO.findByName(hostname);
       if (hostEntity != null) {
         Host host = hostFactory.create(hostEntity, true);
-
         Set<Cluster> cSet = new HashSet<Cluster>();
         for (ClusterEntity clusterEntity : hostEntity.getClusterEntities()) {
           if (clustersById.containsKey(clusterEntity.getClusterId())) {
@@ -199,6 +203,12 @@ public class ClustersImpl implements Clu
     hostEntity.setClusterEntities(new ArrayList<ClusterEntity>());
     //not stored to DB
     Host host = hostFactory.create(hostEntity, false);
+    host.setAgentVersion(new AgentVersion(""));
+    List<DiskInfo> emptyDiskList = new ArrayList<DiskInfo>();
+    host.setDisksInfo(emptyDiskList);
+    host.setHealthStatus(new HostHealthStatus(HealthStatus.UNKNOWN, ""));
+    host.setHostAttributes(new HashMap<String, String>());
+    host.setState(HostState.INIT);
 
     hosts.put(hostname, host);
     hostClusterMap.put(hostname, new HashSet<Cluster>());
@@ -284,4 +294,9 @@ public class ClustersImpl implements Clu
     return hosts;
   }
 
+  @Override
+  public void deleteCluster(String clusterName) {
+    // TODO Auto-generated method stub
+  }
+
 }

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitionException.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitionException.java?rev=1401083&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitionException.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitionException.java Mon Oct 22 21:19:10 2012
@@ -0,0 +1,45 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.ambari.server.state.fsm;
+
+/**
+ * Exception thrown when a StateMachine encounters an invalid
+ * event at its current state.
+ */
+@SuppressWarnings("serial")
+public class InvalidStateTransitionException extends Exception {
+
+  private Enum<?> currentState;
+  private Enum<?> event;
+
+  public InvalidStateTransitionException(Enum<?> currentState, Enum<?> event) {
+    super("Invalid event: " + event + " at " + currentState);
+    this.currentState = currentState;
+    this.event = event;
+  }
+
+  public Enum<?> getCurrentState() {
+    return currentState;
+  }
+
+  public Enum<?> getEvent() {
+    return event;
+  }
+
+}

Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitionException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachine.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachine.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachine.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachine.java Mon Oct 22 21:19:10 2012
@@ -24,5 +24,5 @@ public interface StateMachine
   public STATE getCurrentState();
   public void setCurrentState(STATE state);
   public STATE doTransition(EVENTTYPE eventType, EVENT event)
-        throws InvalidStateTransitonException;
+        throws InvalidStateTransitionException;
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java Mon Oct 22 21:19:10 2012
@@ -281,7 +281,7 @@ final public class StateMachineFactory
    */
   private STATE doTransition
            (OPERAND operand, STATE oldState, EVENTTYPE eventType, EVENT event)
-      throws InvalidStateTransitonException {
+      throws InvalidStateTransitionException {
     // We can assume that stateMachineTable is non-null because we call
     //  maybeMakeStateMachineTable() when we build an InnerStateMachine ,
     //  and this code only gets called from inside a working InnerStateMachine .
@@ -294,7 +294,7 @@ final public class StateMachineFactory
         return transition.doTransition(operand, oldState, event, eventType);
       }
     }
-    throw new InvalidStateTransitonException(oldState, eventType);
+    throw new InvalidStateTransitionException(oldState, eventType);
   }
 
   private synchronized void maybeMakeStateMachineTable() {
@@ -332,7 +332,7 @@ final public class StateMachineFactory
           EVENTTYPE extends Enum<EVENTTYPE>, EVENT> {
     STATE doTransition(OPERAND operand, STATE oldState,
                        EVENT event, EVENTTYPE eventType)
-       throws InvalidStateTransitonException;
+       throws InvalidStateTransitionException;
   }
 
   private class SingleInternalArc
@@ -373,11 +373,11 @@ final public class StateMachineFactory
     @Override
     public STATE doTransition(OPERAND operand, STATE oldState,
                               EVENT event, EVENTTYPE eventType)
-        throws InvalidStateTransitonException {
+        throws InvalidStateTransitionException {
       STATE postState = hook.transition(operand, event);
 
       if (!validPostStates.contains(postState)) {
-        throw new InvalidStateTransitonException(oldState, eventType);
+        throw new InvalidStateTransitionException(oldState, eventType);
       }
       return postState;
     }
@@ -436,7 +436,7 @@ final public class StateMachineFactory
 
     @Override
     public synchronized STATE doTransition(EVENTTYPE eventType, EVENT event)
-         throws InvalidStateTransitonException  {
+         throws InvalidStateTransitionException  {
       currentState = StateMachineFactory.this.doTransition
           (operand, currentState, eventType, event);
       return currentState;

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java Mon Oct 22 21:19:10 2012
@@ -41,7 +41,7 @@ import org.apache.ambari.server.orm.enti
 import org.apache.ambari.server.orm.entities.HostStateEntity;
 import org.apache.ambari.server.state.*;
 import org.apache.ambari.server.state.HostHealthStatus.HealthStatus;
-import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 import org.apache.ambari.server.state.fsm.SingleArcTransition;
 import org.apache.ambari.server.state.fsm.StateMachine;
 import org.apache.ambari.server.state.fsm.StateMachineFactory;
@@ -361,7 +361,7 @@ public class HostImpl implements Host {
 
   @Override
   public void handleEvent(HostEvent event)
-      throws InvalidStateTransitonException {
+      throws InvalidStateTransitionException {
     if (LOG.isDebugEnabled()) {
       LOG.debug("Handling Host event, eventType=" + event.getType().name()
           + ", event=" + event.toString());
@@ -371,7 +371,7 @@ public class HostImpl implements Host {
       writeLock.lock();
       try {
         stateMachine.doTransition(event.getType(), event);
-      } catch (InvalidStateTransitonException e) {
+      } catch (InvalidStateTransitionException e) {
         LOG.error("Can't handle Host event at current state"
             + ", host=" + this.getHostName()
             + ", currentState=" + oldState
@@ -593,7 +593,8 @@ public class HostImpl implements Host {
   public List<DiskInfo> getDisksInfo() {
     try {
       readLock.lock();
-      return Collections.unmodifiableList(gson.<List<DiskInfo>>fromJson(hostEntity.getDisksInfo(), diskInfoType));
+      return gson.<List<DiskInfo>>fromJson(
+                hostEntity.getDisksInfo(), diskInfoType);
     } finally {
       readLock.unlock();
     }
@@ -614,7 +615,8 @@ public class HostImpl implements Host {
   public HostHealthStatus getHealthStatus() {
     try {
       readLock.lock();
-      return gson.fromJson(hostStateEntity.getHealthStatus(), HostHealthStatus.class);
+      return gson.fromJson(hostStateEntity.getHealthStatus(),
+          HostHealthStatus.class);
     } finally {
       readLock.unlock();
     }
@@ -635,8 +637,8 @@ public class HostImpl implements Host {
   public Map<String, String> getHostAttributes() {
     try {
       readLock.lock();
-      return Collections.unmodifiableMap(
-              gson.<Map<String, String>>fromJson(hostEntity.getHostAttributes(), hostAttributesType));
+      return gson.<Map<String, String>>fromJson(hostEntity.getHostAttributes(),
+          hostAttributesType);
     } finally {
       readLock.unlock();
     }
@@ -647,7 +649,8 @@ public class HostImpl implements Host {
     try {
       writeLock.lock();
       //TODO should this add attributes and not replace them?
-      hostEntity.setHostAttributes(gson.toJson(hostAttributes, hostAttributesType));
+      hostEntity.setHostAttributes(gson.toJson(hostAttributes,
+          hostAttributesType));
       saveIfPersisted();
     } finally {
       writeLock.unlock();
@@ -723,7 +726,8 @@ public class HostImpl implements Host {
   public AgentVersion getAgentVersion() {
     try {
       readLock.lock();
-      return gson.fromJson(hostStateEntity.getAgentVersion(), AgentVersion.class);
+      return gson.fromJson(hostStateEntity.getAgentVersion(),
+          AgentVersion.class);
     }
     finally {
       readLock.unlock();

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/Job.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/Job.java?rev=1401083&r1=1401082&r2=1401083&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/Job.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/Job.java Mon Oct 22 21:19:10 2012
@@ -18,7 +18,7 @@
 
 package org.apache.ambari.server.state.job;
 
-import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
 
 public interface Job {
 
@@ -68,8 +68,8 @@ public interface Job {
   /**
    * Send a JobEvent to the Job's StateMachine
    * @param event JobEvent
-   * @throws InvalidStateTransitonException
+   * @throws InvalidStateTransitionException
    */
   public void handleEvent(JobEvent event)
-      throws InvalidStateTransitonException;
+      throws InvalidStateTransitionException;
 }