incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hit...@apache.org
Subject svn commit: r1386878 - in /incubator/ambari/branches/AMBARI-666: ./ ambari-server/src/main/java/org/apache/ambari/server/ ambari-server/src/main/java/org/apache/ambari/server/state/live/ ambari-server/src/main/java/org/apache/ambari/server/state/live/h...
Date Mon, 17 Sep 2012 22:23:05 GMT
Author: hitesh
Date: Mon Sep 17 22:23:04 2012
New Revision: 1386878

URL: http://svn.apache.org/viewvc?rev=1386878&view=rev
Log:
AMBARI-739. Cluster fsm implementation. (Contributed by hitesh)

Added:
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java
  (with props)
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/HostNotFoundException.java
  (with props)
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentHostNotFoundException.java
  (with props)
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java
  (with props)
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java
  (with props)
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java
  (with props)
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClustersImpl.java
  (with props)
Modified:
    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/state/live/Cluster.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.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=1386878&r1=1386877&r2=1386878&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Mon Sep 17 22:23:04 2012
@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-739. Cluster fsm implementation. (hitesh)
+
   AMBARI-745. Add unit tests for Installer Step 1 (Welcome page). (yusaku)
 
   AMBARI-744. Add definition for service config properties. (yusaku)

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=1386878&r1=1386877&r2=1386878&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 Sep 17 22:23:04 2012
@@ -22,4 +22,8 @@ import java.io.IOException;
 
 // TODO
 public class AmbariException extends IOException {
+
+  public AmbariException(String message) {
+    super(message);
+  }
 }

Added: 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=1386878&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ClusterNotFoundException.java
Mon Sep 17 22:23:04 2012
@@ -0,0 +1,26 @@
+/**
+ * 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;
+
+public class ClusterNotFoundException extends AmbariException {
+
+  public ClusterNotFoundException(String clusterName) {
+    super("Cluster not found, clusterName=" + clusterName);
+  }
+}

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

Added: 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=1386878&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/HostNotFoundException.java
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/HostNotFoundException.java
Mon Sep 17 22:23:04 2012
@@ -0,0 +1,26 @@
+/**
+ * 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;
+
+public class HostNotFoundException extends AmbariException {
+
+  public HostNotFoundException(String hostName) {
+    super("Host not found, hostName=" + hostName);
+  }
+}

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

Added: 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=1386878&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentHostNotFoundException.java
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentHostNotFoundException.java
Mon Sep 17 22:23:04 2012
@@ -0,0 +1,31 @@
+/**
+ * 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;
+
+public class ServiceComponentHostNotFoundException extends AmbariException {
+
+  public ServiceComponentHostNotFoundException(String serviceName,
+      String serviceComponentName, String hostName) {
+    super("ServiceComponentHost not found"
+        + ", serviceName=" + serviceName
+        + ", serviceComponentName=" + serviceComponentName
+        + ", hostName=" + hostName);
+  }
+
+}

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

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Cluster.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Cluster.java?rev=1386878&r1=1386877&r2=1386878&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Cluster.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Cluster.java
Mon Sep 17 22:23:04 2012
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.state.live;
 
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
 import org.apache.ambari.server.state.live.host.HostEvent;
 import org.apache.ambari.server.state.live.host.HostState;
@@ -25,18 +26,41 @@ import org.apache.ambari.server.state.li
 public interface Cluster {
 
   /**
+   * Get the Cluster Name
+   */
+  public String getClusterName();
+
+  /**
+   * Add a new host to the cluster
+   * @throws AmbariException
+   */
+  public void addHost(String host) throws AmbariException;
+
+  /**
+   * Add a new ServiceComponentHost to the cluster
+   * @param serviceName
+   * @param componentName
+   * @param hostName
+   * @param isClient
+   */
+  public void addServiceComponentHost(String serviceName, String componentName,
+      String hostName, boolean isClient) throws AmbariException;
+
+  /**
    * Get the State for a given Host
    * @param hostName Host hostname for which to retrieve state
    * @return
+   * @throws AmbariException
    */
-  public HostState getHostState(String hostName);
+  public HostState getHostState(String hostName) throws AmbariException;
 
   /**
    * Set the State for a given Host
    * @param hostName Host's hostname for which state is to be set
    * @param state HostState to set
    */
-  public void setHostState(String hostName, HostState state);
+  public void setHostState(String hostName, HostState state)
+      throws AmbariException;
 
   /**
    * Send event to the given Host
@@ -44,7 +68,7 @@ public interface Cluster {
    * @param event Event to be handled
    */
   public void handleHostEvent(String hostName, HostEvent event)
-      throws InvalidStateTransitonException;
+      throws AmbariException, InvalidStateTransitonException;
 
   /**
    * Get the State for a given ServiceComponentHost
@@ -54,7 +78,7 @@ public interface Cluster {
    * @return ServiceComponentHostState
    */
   public ServiceComponentHostState getServiceComponentHostState(String service,
-      String serviceComponent, String hostName);
+      String serviceComponent, String hostName) throws AmbariException;
 
   /**
    * Set the State for a given ServiceComponentHost
@@ -65,7 +89,7 @@ public interface Cluster {
    */
   public void setServiceComponentHostState(String service,
       String serviceComponent, String hostName,
-      ServiceComponentHostState state);
+      ServiceComponentHostState state) throws AmbariException;
 
   /**
    * Send an Event to a given ServiceComponentHost
@@ -76,6 +100,7 @@ public interface Cluster {
    */
   public void handleServiceComponentHostEvent(String service,
       String serviceComponent, String hostName,
-      ServiceComponentHostEvent event) throws InvalidStateTransitonException;
+      ServiceComponentHostEvent event)
+          throws AmbariException, InvalidStateTransitonException;
 
 }

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java?rev=1386878&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClusterImpl.java
Mon Sep 17 22:23:04 2012
@@ -0,0 +1,151 @@
+/**
+ * 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.live;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.HostNotFoundException;
+import org.apache.ambari.server.ServiceComponentHostNotFoundException;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.live.host.Host;
+import org.apache.ambari.server.state.live.host.HostEvent;
+import org.apache.ambari.server.state.live.host.HostImpl;
+import org.apache.ambari.server.state.live.host.HostState;
+
+public class ClusterImpl implements Cluster {
+
+  private final String clusterName;
+  private Map<String, Host> hosts;
+  private Map<String, Map<String, Map<String, ServiceComponentHost>>>
+      serviceComponentHosts;
+
+  public ClusterImpl(String clusterName) {
+    this.clusterName = clusterName;
+    this.hosts = new HashMap<String, Host>();
+    this.serviceComponentHosts = new HashMap<String,
+        Map<String,Map<String,ServiceComponentHost>>>();
+  }
+
+  private Host getHost(String hostName) throws AmbariException {
+    if (!hosts.containsKey(hostName)) {
+      throw new HostNotFoundException(hostName);
+    }
+    return hosts.get(hostName);
+  }
+
+  private ServiceComponentHost getServiceComponentHost(String serviceName,
+      String serviceComponentName, String hostName) throws AmbariException {
+    if (!serviceComponentHosts.containsKey(serviceName)
+        || !serviceComponentHosts.get(serviceName)
+            .containsKey(serviceComponentName)
+        || !serviceComponentHosts.get(serviceName).get(serviceComponentName)
+            .containsKey(hostName)) {
+      throw new ServiceComponentHostNotFoundException(serviceName,
+          serviceComponentName, hostName);
+    }
+    return serviceComponentHosts.get(serviceName).get(serviceComponentName)
+        .get(hostName);
+  }
+
+  @Override
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  @Override
+  public synchronized void addHost(String hostName) throws AmbariException {
+    if (hosts.containsKey(hostName)) {
+      throw new AmbariException("Duplicate entry for Host"
+          + ", hostName=" + hostName);
+    }
+    hosts.put(hostName, new HostImpl(hostName));
+  }
+
+  @Override
+  public synchronized void addServiceComponentHost(String serviceName,
+      String componentName, String hostName, boolean isClient)
+      throws AmbariException {
+    if (!serviceComponentHosts.containsKey(serviceName)) {
+      serviceComponentHosts.put(serviceName,
+          new HashMap<String, Map<String,ServiceComponentHost>>());
+    }
+    if (!serviceComponentHosts.get(serviceName).containsKey(componentName)) {
+      serviceComponentHosts.get(serviceName).put(componentName,
+          new HashMap<String, ServiceComponentHost>());
+    }
+
+    if (serviceComponentHosts.get(serviceName).get(componentName).
+        containsKey(hostName)) {
+      throw new AmbariException("Duplicate entry for ServiceComponentHost"
+          + ", serviceName=" + serviceName
+          + ", serviceComponentName" + componentName
+          + ", hostName= " + hostName);
+    }
+    serviceComponentHosts.get(serviceName).get(componentName).put(hostName,
+        new ServiceComponentHostImpl(componentName, hostName, isClient));
+  }
+
+  @Override
+  public HostState getHostState(String hostName) throws AmbariException{
+    return getHost(hostName).getState();
+  }
+
+  @Override
+  public void setHostState(String hostName, HostState state)
+      throws AmbariException {
+    getHost(hostName).setState(state);
+  }
+
+  @Override
+  public void handleHostEvent(String hostName, HostEvent event)
+      throws AmbariException, InvalidStateTransitonException {
+    if (!hosts.containsKey(hostName)) {
+      throw new HostNotFoundException(hostName);
+    }
+    hosts.get(hostName).handleEvent(event);
+  }
+
+  @Override
+  public ServiceComponentHostState getServiceComponentHostState(String service,
+      String serviceComponent, String hostName) throws AmbariException {
+    return
+        getServiceComponentHost(service, serviceComponent, hostName).getState();
+  }
+
+  @Override
+  public void setServiceComponentHostState(String service,
+      String serviceComponent, String hostName,
+      ServiceComponentHostState state) throws AmbariException {
+    getServiceComponentHost(service, serviceComponent, hostName)
+      .setState(state);
+  }
+
+  @Override
+  public void handleServiceComponentHostEvent(String service,
+      String serviceComponent, String hostName,
+      ServiceComponentHostEvent event)
+      throws AmbariException, InvalidStateTransitonException {
+    getServiceComponentHost(service, serviceComponent, hostName)
+      .handleEvent(event);
+
+  }
+
+}

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

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java?rev=1386878&r1=1386877&r2=1386878&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Clusters.java
Mon Sep 17 22:23:04 2012
@@ -18,13 +18,21 @@
 
 package org.apache.ambari.server.state.live;
 
+import org.apache.ambari.server.AmbariException;
+
 public interface Clusters {
 
   /**
+   * Add a new Cluster
+   * @param clusterName
+   */
+  public void addCluster(String clusterName) throws AmbariException;
+
+  /**
    * Get the Cluster given the cluster name
    * @param clusterName Name of the Cluster to retrieve
    * @return
    */
-  public Cluster getCluster(String clusterName);
+  public Cluster getCluster(String clusterName) throws AmbariException;
 
 }

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java?rev=1386878&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ClustersImpl.java
Mon Sep 17 22:23:04 2012
@@ -0,0 +1,56 @@
+/**
+ * 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.live;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ClusterNotFoundException;
+
+public class ClustersImpl implements Clusters {
+
+  private Map<String, Cluster> clusters;
+
+  // TODO
+  // private Map<String, Host> hosts;
+
+  public ClustersImpl() {
+    clusters = new HashMap<String, Cluster>();
+  }
+
+  @Override
+  public synchronized void addCluster(String clusterName)
+      throws AmbariException {
+    if (clusters.containsKey(clusterName)) {
+      throw new AmbariException("Duplicate entry for Cluster"
+          + ", clusterName= " + clusterName);
+    }
+    clusters.put(clusterName, new ClusterImpl(clusterName));
+  }
+
+  @Override
+  public Cluster getCluster(String clusterName) throws AmbariException {
+    if (!clusters.containsKey(clusterName)) {
+      throw new ClusterNotFoundException(clusterName);
+    }
+    return clusters.get(clusterName);
+  }
+
+}

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

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java?rev=1386878&r1=1386877&r2=1386878&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java
Mon Sep 17 22:23:04 2012
@@ -201,8 +201,9 @@ public class HostImpl implements Host {
 
   private final StateMachine<HostState, HostEventType, HostEvent> stateMachine;
 
-  public HostImpl() {
+  public HostImpl(String hostName) {
     super();
+    this.hostName = hostName;
     this.stateMachine = stateMachineFactory.make(this);
     ReadWriteLock rwLock = new ReentrantReadWriteLock();
     this.readLock = rwLock.readLock();

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java?rev=1386878&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java
Mon Sep 17 22:23:04 2012
@@ -0,0 +1,195 @@
+/**
+ * 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.live;
+
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.state.ConfigVersion;
+import org.apache.ambari.server.state.StackVersion;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.live.host.HostRegistrationRequestEvent;
+import org.apache.ambari.server.state.live.host.HostState;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestClusterImpl {
+
+  private Clusters clusters;
+  private Cluster c1;
+  String h1 = "h1";
+  String s1 = "s1";
+  String sc1 = "sc1";
+
+  @Before
+  public void setup() throws AmbariException {
+    clusters = new ClustersImpl();
+    clusters.addCluster("c1");
+    c1 = clusters.getCluster("c1");
+    Assert.assertEquals("c1", c1.getClusterName());
+    c1.addHost(h1);
+    c1.addServiceComponentHost(s1, sc1, h1, false);
+  }
+
+  @After
+  public void teardown() {
+    clusters = null;
+    c1 = null;
+  }
+
+  @Test
+  public void testAddHost() throws AmbariException {
+    c1.addHost("h2");
+
+    try {
+      c1.addHost("h2");
+      fail("Duplicate add should fail");
+    }
+    catch (AmbariException e) {
+      // Expected
+    }
+
+  }
+
+  @Test
+  public void testAddServiceComponentHost() throws AmbariException {
+    c1.addServiceComponentHost("s2", "sc2", "h2", false);
+
+    try {
+      c1.addServiceComponentHost("s2", "sc2", "h2", false);
+      fail("Duplicate add should fail");
+    }
+    catch (AmbariException e) {
+      // Expected
+    }
+
+  }
+
+  @Test
+  public void testGetHostState() throws AmbariException {
+    Assert.assertEquals(HostState.INIT, c1.getHostState(h1));
+  }
+
+  @Test
+  public void testSetHostState() throws AmbariException {
+    c1.setHostState(h1, HostState.HEARTBEAT_LOST);
+    Assert.assertEquals(HostState.HEARTBEAT_LOST, c1.getHostState(h1));
+  }
+
+  @Test
+  public void testHostEvent() throws AmbariException,
+      InvalidStateTransitonException {
+    HostInfo hostInfo = new HostInfo();
+    hostInfo.setHostName(h1);
+    hostInfo.setInterfaces("fip_4");
+    hostInfo.setArchitecture("os_arch");
+    hostInfo.setOS("os_type");
+    hostInfo.setMemoryTotal(10);
+    hostInfo.setMemorySize(100);
+    hostInfo.setProcessorCount(10);
+    List<DiskInfo> mounts = new ArrayList<DiskInfo>();
+    mounts.add(new DiskInfo("/dev/sda", "/mnt/disk1",
+        "5000000", "4000000", "10%", "size"));
+    hostInfo.setMounts(mounts);
+
+    AgentVersion agentVersion = new AgentVersion("0.0.x");
+    long currentTime = 1001;
+
+    c1.handleHostEvent(h1, new HostRegistrationRequestEvent(h1, agentVersion,
+        currentTime, hostInfo));
+
+    Assert.assertEquals(HostState.WAITING_FOR_VERIFICATION,
+        c1.getHostState(h1));
+
+    c1.setHostState(h1, HostState.VERIFIED);
+
+    try {
+      c1.handleHostEvent(h1, new HostRegistrationRequestEvent(h1, agentVersion,
+          currentTime, hostInfo));
+      fail("Exception should be thrown on invalid event");
+    }
+    catch (InvalidStateTransitonException e) {
+      // Expected
+    }
+
+  }
+
+  @Test
+  public void testGetServiceComponentHostState() throws AmbariException {
+    Assert.assertNotNull(c1.getServiceComponentHostState(s1, sc1, h1));
+    Assert.assertEquals(ServiceComponentHostLiveState.INIT,
+        c1.getServiceComponentHostState(s1, sc1, h1).getLiveState());
+  }
+
+  @Test
+  public void testSetServiceComponentHostState() throws AmbariException {
+    ConfigVersion cVersion = new ConfigVersion("0.0.c");
+    StackVersion sVersion = new StackVersion("hadoop-x.y.z");
+    ServiceComponentHostLiveState liveState =
+        ServiceComponentHostLiveState.INSTALL_FAILED;
+    ServiceComponentHostState expected =
+        new ServiceComponentHostState(cVersion, sVersion, liveState);
+    c1.setServiceComponentHostState(s1, sc1, h1, expected);
+
+    ServiceComponentHostState actual =
+        c1.getServiceComponentHostState(s1, sc1, h1);
+
+    Assert.assertEquals(expected, actual);
+    Assert.assertEquals(ServiceComponentHostLiveState.INSTALL_FAILED,
+        actual.getLiveState());
+
+  }
+
+  @Test
+  public void testServiceComponentHostEvent()
+      throws AmbariException, InvalidStateTransitonException {
+    ConfigVersion cVersion = new ConfigVersion("0.0.c");
+    StackVersion sVersion = new StackVersion("hadoop-x.y.z");
+    ServiceComponentHostLiveState liveState =
+        ServiceComponentHostLiveState.INSTALL_FAILED;
+    ServiceComponentHostState expected =
+        new ServiceComponentHostState(cVersion, sVersion, liveState);
+    c1.setServiceComponentHostState(s1, sc1, h1, expected);
+
+    try {
+      c1.handleServiceComponentHostEvent(s1, sc1, h1,
+          new ServiceComponentHostInstallEvent(sc1, h1, 1001));
+      fail("Exception should be thrown on invalid event");
+    }
+    catch (InvalidStateTransitonException e) {
+      // Expected
+    }
+
+    c1.handleServiceComponentHostEvent(s1, sc1, h1,
+        new ServiceComponentHostOpRestartedEvent(sc1, h1, 1002));
+
+    Assert.assertEquals(ServiceComponentHostLiveState.INSTALLING,
+        c1.getServiceComponentHostState(s1, sc1, h1).getLiveState());
+
+  }
+
+}

Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClustersImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClustersImpl.java?rev=1386878&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClustersImpl.java
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClustersImpl.java
Mon Sep 17 22:23:04 2012
@@ -0,0 +1,89 @@
+/**
+ * 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.live;
+
+import static org.junit.Assert.fail;
+import junit.framework.Assert;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ClusterNotFoundException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestClustersImpl {
+
+  private Clusters clusters;
+
+  @Before
+  public void setup() {
+    clusters = new ClustersImpl();
+  }
+
+  @After
+  public void teardown() {
+    clusters = null;
+  }
+
+  @Test
+  public void testGetInvalidCluster() throws AmbariException {
+    try {
+      clusters.getCluster("foo");
+      fail("Exception should be thrown on invalid get");
+    }
+    catch (ClusterNotFoundException e) {
+      // Expected
+    }
+
+  }
+
+  @Test
+  public void testAddCluster() throws AmbariException {
+
+    String c1 = "foo";
+    String c2 = "foo";
+    clusters.addCluster(c1);
+
+    try {
+      clusters.addCluster(c1);
+      fail("Exception should be thrown on invalid add");
+    }
+    catch (AmbariException e) {
+      // Expected
+    }
+
+    try {
+      clusters.addCluster(c2);
+      fail("Exception should be thrown on invalid add");
+    }
+    catch (AmbariException e) {
+      // Expected
+    }
+
+    c2 = "foo2";
+    clusters.addCluster(c2);
+
+    Assert.assertNotNull(clusters.getCluster(c1));
+    Assert.assertNotNull(clusters.getCluster(c2));
+
+    Assert.assertEquals(c1, clusters.getCluster(c1).getClusterName());
+    Assert.assertEquals(c2, clusters.getCluster(c2).getClusterName());
+
+  }
+}

Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClustersImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.java?rev=1386878&r1=1386877&r2=1386878&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.java
Mon Sep 17 22:23:04 2012
@@ -48,7 +48,7 @@ public class TestHostImpl {
     info.setOS("os_type");
     info.setMemoryTotal(10);
 
-    HostImpl host = new HostImpl();
+    HostImpl host = new HostImpl("foo");
     host.importHostInfo(info);
 
     Assert.assertEquals(info.getHostName(), host.getHostName());
@@ -116,13 +116,13 @@ public class TestHostImpl {
 
   @Test
   public void testHostFSMInit() {
-    HostImpl host = new HostImpl();
+    HostImpl host = new HostImpl("foo");
     verifyHostState(host, HostState.INIT);
   }
 
   @Test
   public void testHostRegistrationFlow() throws Exception {
-    HostImpl host = new HostImpl();
+    HostImpl host = new HostImpl("foo");
     registerHost(host);
     verifyHostState(host, HostState.WAITING_FOR_VERIFICATION);
 
@@ -154,7 +154,7 @@ public class TestHostImpl {
 
   @Test
   public void testHostHeartbeatFlow() throws Exception {
-    HostImpl host = new HostImpl();
+    HostImpl host = new HostImpl("foo");
     registerHost(host);
     verifyHost(host);
 



Mime
View raw message