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/09 02:04:45 UTC
svn commit: r1395819 - in /incubator/ambari/branches/AMBARI-666: ./
ambari-server/src/main/java/org/apache/ambari/server/controller/
ambari-server/src/main/java/org/apache/ambari/server/state/
ambari-server/src/main/java/org/apache/ambari/server/state/...
Author: hitesh
Date: Tue Oct 9 00:04:44 2012
New Revision: 1395819
URL: http://svn.apache.org/viewvc?rev=1395819&view=rev
Log:
AMBARI-825. Controller layer implementation part 3. (hitesh)
Added:
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersImplTest.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostImplTest.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobImplTest.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImplTest.java (with props)
Removed:
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/TestClusterImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/TestClustersImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/host/TestHostImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/TestJobImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/TestServiceComponentHostImpl.java
Modified:
incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.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/ServiceComponentImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.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=1395819&r1=1395818&r2=1395819&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Tue Oct 9 00:04:44 2012
@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
NEW FEATURES
+ AMBARI-825. Controller layer implementation part 3. (hitesh)
+
AMBARI-823. Fix security filter on the server agent ports and remove
duplication on servlet contexts for certs signing. (mahadev)
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=1395819&r1=1395818&r2=1395819&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 Tue Oct 9 00:04:44 2012
@@ -34,6 +34,7 @@ import org.apache.ambari.server.state.Se
import org.apache.ambari.server.state.ServiceComponentHost;
import org.apache.ambari.server.state.ServiceComponentHostEvent;
import org.apache.ambari.server.state.ServiceComponentImpl;
+import org.apache.ambari.server.state.StackVersion;
import org.apache.ambari.server.state.State;
import org.apache.ambari.server.state.ServiceImpl;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostImpl;
@@ -88,6 +89,8 @@ public class AmbariManagementControllerI
+ ", request=" + request);
}
+ // TODO validate stack version
+
clusters.addCluster(request.getClusterName());
if (request.getHostNames() != null) {
@@ -95,6 +98,12 @@ public class AmbariManagementControllerI
request.getClusterName());
}
+ Cluster c = clusters.getCluster(request.getClusterName());
+ if (request.getStackVersion() != null) {
+ c.setDesiredStackVersion(
+ new StackVersion(request.getStackVersion()));
+ }
+
// TODO
return null;
}
@@ -188,7 +197,8 @@ public class AmbariManagementControllerI
sc = s.getServiceComponent(request.getComponentName());
if (sc != null) {
// TODO fix exception
- throw new AmbariException("ServiceComponent already exists within cluster"
+ throw new AmbariException("ServiceComponent already exists"
+ + " within cluster"
+ ", clusterName=" + cluster.getClusterName()
+ ", clusterId=" + cluster.getClusterId()
+ ", serviceName=" + s.getName()
@@ -434,7 +444,7 @@ public class AmbariManagementControllerI
execCmd.setCommandId(stage.getActionId());
execCmd.setClusterName(scHost.getClusterName());
- // Generate topology info
+ // Generate cluster host info
// TODO fix - use something from somewhere to generate this at some point
Map<String, List<String>> clusterHostInfo =
new TreeMap<String, List<String>>();
@@ -749,7 +759,6 @@ public class AmbariManagementControllerI
}
}
-
// TODO additional validation?
// TODO order hostcomponents to determine stages
@@ -817,6 +826,12 @@ public class AmbariManagementControllerI
nowTimestamp);
stage.addHostAction(scHost.getHostName(), ha);
}
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Adding new stage for updateService request"
+ + ", clusterName=" + request.getClusterName()
+ + ", serviceName=" + request.getServiceName()
+ + ", stage=" + stage);
+ }
stages.add(stage);
}
@@ -917,9 +932,10 @@ public class AmbariManagementControllerI
long nowTimestamp = System.currentTimeMillis();
long requestId = requestCounter.incrementAndGet();
-
+ long stageId = 0;
List<Stage> stages = new ArrayList<Stage>();
Stage stage = createNewStage(cluster, requestId);
+ stage.setStageId(++stageId);
for (ServiceComponentHost scHost : changedScHosts) {
Map<String, Config> configs = null;
ServiceComponentHostEvent event;
@@ -962,6 +978,14 @@ public class AmbariManagementControllerI
nowTimestamp);
stage.addHostAction(scHost.getHostName(), ha);
}
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Adding new stage for updateComponent request"
+ + ", clusterName=" + request.getClusterName()
+ + ", serviceName=" + request.getServiceName()
+ + ", componentName=" + request.getComponentName()
+ + ", stage=" + stage);
+ }
+ stages.add(stage);
for (ServiceComponentHost sch : changedScHosts) {
sch.setDesiredState(newState);
@@ -1073,9 +1097,11 @@ public class AmbariManagementControllerI
long nowTimestamp = System.currentTimeMillis();
long requestId = requestCounter.incrementAndGet();
+ long stageId = 0;
List<Stage> stages = new ArrayList<Stage>();
Stage stage = createNewStage(cluster, requestId);
+ stage.setStageId(++stageId);
Map<String, Config> configs = null;
ServiceComponentHostEvent event;
@@ -1117,6 +1143,15 @@ public class AmbariManagementControllerI
HostAction ha = createHostAction(stage, sch, configs, event,
nowTimestamp);
stage.addHostAction(sch.getHostName(), ha);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Adding new stage for createHostComponent request"
+ + ", clusterName=" + request.getClusterName()
+ + ", serviceName=" + request.getServiceName()
+ + ", componentName=" + request.getComponentName()
+ + ", hostname=" + request.getHostname()
+ + ", stage=" + stage);
+ }
+ stages.add(stage);
sch.setDesiredState(newState);
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java?rev=1395819&r1=1395818&r2=1395819&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceResponse.java Tue Oct 9 00:04:44 2012
@@ -22,31 +22,27 @@ import java.util.Map;
public class ServiceResponse {
- private Long clusterId; // REF
+ private Long clusterId;
- private String clusterName; // REF
+ private String clusterName;
private String serviceName;
- private String currentStackVersion;
-
private String desiredStackVersion;
private String desiredState;
// Config type -> version mapping
- private Map<String, String> configVersions; // CREATE/UPDATE
-
+ private Map<String, String> configVersions;
public ServiceResponse(Long clusterId, String clusterName,
- String serviceName, String currentStackVersion,
+ String serviceName,
Map<String, String> configVersions,
String desiredStackVersion, String desiredState) {
super();
this.clusterId = clusterId;
this.clusterName = clusterName;
this.serviceName = serviceName;
- this.currentStackVersion = currentStackVersion;
this.configVersions = configVersions;
this.setDesiredStackVersion(desiredStackVersion);
this.setDesiredState(desiredState);
@@ -67,20 +63,6 @@ public class ServiceResponse {
}
/**
- * @return the currentStackVersion
- */
- public String getCurrentStackVersion() {
- return currentStackVersion;
- }
-
- /**
- * @param currentStackVersion the currentStackVersion to set
- */
- public void setCurrentStackVersion(String currentStackVersion) {
- this.currentStackVersion = currentStackVersion;
- }
-
- /**
* @return the configVersions
*/
public Map<String, String> getConfigVersions() {
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=1395819&r1=1395818&r2=1395819&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 Tue Oct 9 00:04:44 2012
@@ -54,18 +54,10 @@ public interface Service {
public void setDesiredStackVersion(StackVersion stackVersion);
- public State getState();
-
- public void setState(State state);
-
public Map<String, Config> getConfigs();
public void updateConfigs(Map<String, Config> configs);
- public StackVersion getStackVersion();
-
- public void setStackVersion(StackVersion stackVersion);
-
public ServiceResponse convertToResponse();
}
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=1395819&r1=1395818&r2=1395819&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 Tue Oct 9 00:04:44 2012
@@ -46,18 +46,10 @@ public interface ServiceComponent {
public void setDesiredStackVersion(StackVersion stackVersion);
- public State getState();
-
- public void setState(State state);
-
public Map<String, Config> getConfigs();
public void updateConfigs(Map<String, Config> configs);
- public StackVersion getStackVersion();
-
- public void setStackVersion(StackVersion stackVersion);
-
public Map<String, ServiceComponentHost> getServiceComponentHosts();
public ServiceComponentHost getServiceComponentHost(String hostname)
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=1395819&r1=1395818&r2=1395819&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 Tue Oct 9 00:04:44 2012
@@ -36,9 +36,7 @@ public class ServiceComponentImpl implem
private final Service service;
private final String componentName;
- private State state;
private Map<String, Config> configs;
- private StackVersion stackVersion;
private State desiredState;
private Map<String, Config> desiredConfigs;
@@ -56,11 +54,9 @@ public class ServiceComponentImpl implem
String componentName) {
this.service = service;
this.componentName = componentName;
- this.state = State.INIT;
this.desiredState = State.INIT;
this.configs = new HashMap<String, Config>();
this.desiredConfigs = new HashMap<String, Config>();
- this.stackVersion = new StackVersion("");
this.desiredStackVersion = new StackVersion("");
this.hostComponents = new HashMap<String, ServiceComponentHost>();
init();
@@ -83,25 +79,6 @@ public class ServiceComponentImpl implem
}
@Override
- public synchronized State getState() {
- return state;
- }
-
- @Override
- public synchronized void setState(State state) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Setting State of Service"
- + ", clusterName=" + service.getCluster().getClusterName()
- + ", clusterId=" + service.getCluster().getClusterId()
- + ", serviceName=" + service.getName()
- + ", serviceComponentName=" + componentName
- + ", oldState=" + this.state
- + ", newState=" + state);
- }
- this.state = state;
- }
-
- @Override
public synchronized Map<String, Config> getConfigs() {
return Collections.unmodifiableMap(configs);
}
@@ -112,25 +89,6 @@ public class ServiceComponentImpl implem
}
@Override
- public synchronized StackVersion getStackVersion() {
- return stackVersion;
- }
-
- @Override
- public synchronized void setStackVersion(StackVersion stackVersion) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Setting StackVersion of Service"
- + ", clusterName=" + service.getCluster().getClusterName()
- + ", clusterId=" + service.getCluster().getClusterId()
- + ", serviceName=" + service.getName()
- + ", serviceComponentName=" + componentName
- + ", oldStackVersion=" + this.stackVersion
- + ", newStackVersion=" + stackVersion);
- }
- this.stackVersion = stackVersion;
- }
-
- @Override
public synchronized Map<String, ServiceComponentHost>
getServiceComponentHosts() {
return Collections.unmodifiableMap(hostComponents);
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=1395819&r1=1395818&r2=1395819&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 Tue Oct 9 00:04:44 2012
@@ -36,12 +36,10 @@ public class ServiceImpl implements Serv
private final Cluster cluster;
private final String serviceName;
- private State state;
private State desiredState;
private Map<String, Config> configs;
private Map<String, Config> desiredConfigs;
private Map<String, ServiceComponent> components;
- private StackVersion stackVersion;
private StackVersion desiredStackVersion;
private void init() {
@@ -52,11 +50,9 @@ public class ServiceImpl implements Serv
public ServiceImpl(Cluster cluster, String serviceName) {
this.cluster = cluster;
this.serviceName = serviceName;
- this.state = State.INIT;
this.desiredState = State.INIT;
this.configs = new HashMap<String, Config>();
this.desiredConfigs = new HashMap<String, Config>();
- this.stackVersion = new StackVersion("");
this.desiredStackVersion = new StackVersion("");
this.components = new HashMap<String, ServiceComponent>();
init();
@@ -78,47 +74,6 @@ public class ServiceImpl implements Serv
}
@Override
- public synchronized State getState() {
- return state;
- }
-
- @Override
- public synchronized void setState(State state) {
- if (state == null) {
- // TODO throw error?
- return;
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("Setting state of Service"
- + ", oldState=" + this.state
- + ", newState=" + state);
- }
- this.state = state;
- }
-
- @Override
- public synchronized StackVersion getStackVersion() {
- return stackVersion;
- }
-
- @Override
- public synchronized void setStackVersion(StackVersion stackVersion) {
- if (stackVersion == null) {
- // TODO throw error?
- return;
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("Setting StackVersion of Service"
- + ", clusterName=" + cluster.getClusterName()
- + ", clusterId=" + cluster.getClusterId()
- + ", serviceName=" + serviceName
- + ", oldStackVersion=" + this.stackVersion
- + ", newStackVersion=" + stackVersion);
- }
- this.stackVersion = stackVersion;
- }
-
- @Override
public synchronized Map<String, Config> getConfigs() {
return Collections.unmodifiableMap(configs);
}
@@ -175,10 +130,6 @@ public class ServiceImpl implements Serv
@Override
public synchronized void setDesiredState(State state) {
- if (state == null) {
- // TODO throw error?
- return;
- }
if (LOG.isDebugEnabled()) {
LOG.debug("Setting DesiredState of Service"
+ ", clusterName=" + cluster.getClusterName()
@@ -207,10 +158,6 @@ public class ServiceImpl implements Serv
@Override
public synchronized void setDesiredStackVersion(StackVersion stackVersion) {
- if (stackVersion == null) {
- // TODO throw error?
- return;
- }
if (LOG.isDebugEnabled()) {
LOG.debug("Setting DesiredStackVersion of Service"
+ ", clusterName=" + cluster.getClusterName()
@@ -235,7 +182,6 @@ public class ServiceImpl implements Serv
ServiceResponse r = new ServiceResponse(cluster.getClusterId(),
cluster.getClusterName(),
serviceName,
- stackVersion.getStackVersion(),
getConfigVersions(),
desiredStackVersion.getStackVersion(),
desiredState.toString());
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=1395819&r1=1395818&r2=1395819&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 Tue Oct 9 00:04:44 2012
@@ -80,7 +80,7 @@ public class ClusterImpl implements Clus
Map<String,Map<String,ServiceComponentHost>>>();
this.serviceComponentHostsByHost = new HashMap<String,
List<ServiceComponentHost>>();
- this.desiredStackVersion = null;
+ this.desiredStackVersion = new StackVersion("");
this.configs = new HashMap<String, Map<String,Config>>();
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java?rev=1395819&r1=1395818&r2=1395819&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java Tue Oct 9 00:04:44 2012
@@ -37,9 +37,14 @@ import org.apache.ambari.server.state.cl
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class AmbariManagementControllerTest {
+ private static final Logger LOG =
+ LoggerFactory.getLogger(AmbariManagementControllerTest.class);
+
private AmbariManagementController controller;
private Clusters clusters;
private ActionDBAccessor db = new ActionDBInMemoryImpl();
@@ -173,7 +178,7 @@ public class AmbariManagementControllerT
for (ServiceResponse svc : response) {
Assert.assertTrue(svc.getServiceName().equals(serviceName)
|| svc.getServiceName().equals(serviceName2));
- Assert.assertEquals("", svc.getDesiredStackVersion());
+ Assert.assertEquals("1.0.0", svc.getDesiredStackVersion());
Assert.assertEquals(State.INIT.toString(), svc.getDesiredState());
}
@@ -322,26 +327,39 @@ public class AmbariManagementControllerT
}
@Test
- public void testInstallService() throws AmbariException {
+ public void testInstallAndStartService() throws AmbariException {
testCreateServiceComponentHost();
String clusterName = "foo1";
String serviceName = "HDFS";
- ServiceRequest r = new ServiceRequest(clusterName, serviceName, null,
+ ServiceRequest r1 = new ServiceRequest(clusterName, serviceName, null,
State.INSTALLED.toString());
- controller.updateService(r);
+ controller.updateService(r1);
+
+ // TODO validate stages?
+ List<Stage> stages = db.getAllStages(1);
+ Assert.assertEquals(2, stages.size());
+
+ for (Stage stage : stages) {
+ LOG.info("Stage Details for Install Service: " + stage);
+ }
+
+ ServiceRequest r2 = new ServiceRequest(clusterName, serviceName, null,
+ State.STARTED.toString());
+
+ controller.updateService(r2);
// TODO validate stages?
-// List<Stage> stages = db.getAllStages(1);
-//
-// for (Stage stage : stages) {
-// for (String h : stage.getHosts()) {
-// System.out.println("Stage " + stage.getStageId()
-// + " : Host " + h);
-// }
-// }
+ stages = db.getAllStages(2);
+ Assert.assertEquals(2, stages.size());
+
+ for (Stage stage : stages) {
+ LOG.info("Stage Details for Start Service: " + stage);
+ }
+
+
}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java?rev=1395819&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java Tue Oct 9 00:04:44 2012
@@ -0,0 +1,122 @@
+/**
+ * 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;
+
+import junit.framework.Assert;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.state.cluster.ClustersImpl;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ServiceTest {
+
+ private Clusters clusters;
+ private Cluster cluster;
+ private String clusterName;
+
+ @Before
+ public void setup() throws AmbariException {
+ clusters = new ClustersImpl();
+ clusterName = "foo";
+ clusters.addCluster(clusterName);
+ cluster = clusters.getCluster(clusterName);
+ Assert.assertNotNull(cluster);
+ }
+
+ @After
+ public void teardown() throws AmbariException {
+ clusters = null;
+ cluster = null;
+ }
+
+ @Test
+ public void testCreateService() throws AmbariException {
+ String serviceName = "s1";
+ Service s = new ServiceImpl(cluster, serviceName);
+ cluster.addService(s);
+ Service service = cluster.getService(serviceName);
+
+ Assert.assertNotNull(service);
+ Assert.assertEquals(serviceName, service.getName());
+ Assert.assertEquals(cluster.getClusterId(),
+ service.getCluster().getClusterId());
+ Assert.assertEquals(cluster.getClusterName(),
+ service.getCluster().getClusterName());
+ Assert.assertEquals(State.INIT, service.getDesiredState());
+ Assert.assertTrue(
+ service.getDesiredStackVersion().getStackVersion().isEmpty());
+ }
+
+ @Test
+ public void testGetAndSetServiceInfo() throws AmbariException {
+ String serviceName = "s1";
+ Service s = new ServiceImpl(cluster, serviceName);
+ cluster.addService(s);
+ Service service = cluster.getService(serviceName);
+
+ Assert.assertNotNull(service);
+
+ service.setDesiredStackVersion(new StackVersion("1.1.0"));
+ Assert.assertEquals("1.1.0",
+ service.getDesiredStackVersion().getStackVersion());
+
+
+ service.setDesiredState(State.INSTALLING);
+ Assert.assertEquals(State.INSTALLING, service.getDesiredState());
+
+ }
+
+
+
+ /*
+
+
+
+ public ServiceComponent getServiceComponent(String componentName)
+ throws AmbariException;
+
+ public Map<String, ServiceComponent> getServiceComponents();
+
+ public void addServiceComponents(Map<String, ServiceComponent> components)
+ throws AmbariException;
+
+ public void addServiceComponent(ServiceComponent component)
+ throws AmbariException;
+
+
+ public Map<String, Config> getDesiredConfigs();
+
+ public void updateDesiredConfigs(Map<String, Config> configs);
+
+
+ public Map<String, Config> getConfigs();
+
+ public void updateConfigs(Map<String, Config> configs);
+
+ public StackVersion getStackVersion();
+
+ public void setStackVersion(StackVersion stackVersion);
+
+ public ServiceResponse convertToResponse();
+
+
+ */
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java?rev=1395819&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java Tue Oct 9 00:04:44 2012
@@ -0,0 +1,133 @@
+/**
+ * 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.cluster;
+
+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.AgentVersion;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.cluster.ClustersImpl;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.host.HostHealthyHeartbeatEvent;
+import org.apache.ambari.server.state.host.HostRegistrationRequestEvent;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ClusterImplTest {
+
+ 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());
+ clusters.addHost(h1);
+ clusters.mapHostToCluster(h1, "c1");
+ }
+
+ @After
+ public void teardown() {
+ clusters = null;
+ c1 = null;
+ }
+
+ @Test
+ public void testAddHost() throws AmbariException {
+ clusters.addHost("h2");
+
+ try {
+ clusters.addHost("h2");
+ fail("Duplicate add should fail");
+ }
+ catch (AmbariException e) {
+ // Expected
+ }
+
+ }
+
+
+ @Test
+ public void testGetHostState() throws AmbariException {
+ Assert.assertEquals(HostState.INIT, clusters.getHost(h1).getState());
+ }
+
+ @Test
+ public void testSetHostState() throws AmbariException {
+ clusters.getHost(h1).setState(HostState.HEARTBEAT_LOST);
+ Assert.assertEquals(HostState.HEARTBEAT_LOST,
+ clusters.getHost(h1).getState());
+ }
+
+ @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;
+
+ clusters.getHost(h1).handleEvent(new HostRegistrationRequestEvent(
+ h1, agentVersion, currentTime, hostInfo));
+
+ Assert.assertEquals(HostState.WAITING_FOR_HOST_STATUS_UPDATES,
+ clusters.getHost(h1).getState());
+
+ clusters.getHost(h1).setState(HostState.HEARTBEAT_LOST);
+
+ try {
+ clusters.getHost(h1).handleEvent(
+ new HostHealthyHeartbeatEvent(h1, currentTime));
+ fail("Exception should be thrown on invalid event");
+ }
+ catch (InvalidStateTransitonException e) {
+ // Expected
+ }
+
+ }
+
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersImplTest.java?rev=1395819&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersImplTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersImplTest.java Tue Oct 9 00:04:44 2012
@@ -0,0 +1,173 @@
+/**
+ * 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.cluster;
+
+import static org.junit.Assert.fail;
+
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ClusterNotFoundException;
+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.cluster.ClustersImpl;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ClustersImplTest {
+
+ 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 testAddAndGetCluster() 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());
+
+ }
+
+
+ @Test
+ public void testAddAndGetHost() throws AmbariException {
+ String h1 = "h1";
+ String h2 = "h2";
+ String h3 = "h3";
+
+ clusters.addHost(h1);
+
+ try {
+ clusters.addHost(h1);
+ fail("Expected exception on duplicate host entry");
+ } catch (Exception e) {
+ // Expected
+ }
+
+ clusters.addHost(h2);
+ clusters.addHost(h3);
+
+ List<Host> hosts = clusters.getHosts();
+ Assert.assertEquals(3, hosts.size());
+
+ Assert.assertNotNull(clusters.getHost(h1));
+ Assert.assertNotNull(clusters.getHost(h2));
+ Assert.assertNotNull(clusters.getHost(h3));
+
+ }
+
+ @Test
+ public void testClusterHostMapping() throws AmbariException {
+ String c1 = "c1";
+ String c2 = "c2";
+ String h1 = "h1";
+ String h2 = "h2";
+ String h3 = "h3";
+
+ try {
+ clusters.mapHostToCluster(h1, c1);
+ fail("Expected exception for invalid cluster/host");
+ } catch (Exception e) {
+ // Expected
+ }
+
+ clusters.addCluster(c1);
+ clusters.addCluster(c2);
+ Assert.assertNotNull(clusters.getCluster(c1));
+ Assert.assertNotNull(clusters.getCluster(c2));
+ try {
+ clusters.mapHostToCluster(h1, c1);
+ fail("Expected exception for invalid host");
+ } catch (Exception e) {
+ // Expected
+ }
+
+ clusters.addHost(h1);
+ clusters.addHost(h2);
+ clusters.addHost(h3);
+ Assert.assertNotNull(clusters.getHost(h1));
+
+ clusters.mapHostToCluster(h1, c1);
+ clusters.mapHostToCluster(h1, c2);
+ clusters.mapHostToCluster(h2, c1);
+ clusters.mapHostToCluster(h2, c2);
+ clusters.mapHostToCluster(h1, c2);
+
+ Set<Cluster> c = clusters.getClustersForHost(h3);
+ Assert.assertEquals(0, c.size());
+
+ c = clusters.getClustersForHost(h1);
+ Assert.assertEquals(2, c.size());
+
+ c = clusters.getClustersForHost(h2);
+ Assert.assertEquals(2, c.size());
+
+ }
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostImplTest.java?rev=1395819&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostImplTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostImplTest.java Tue Oct 9 00:04:44 2012
@@ -0,0 +1,263 @@
+/**
+ * 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.host;
+
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ambari.server.agent.DiskInfo;
+import org.apache.ambari.server.agent.HostInfo;
+import org.apache.ambari.server.state.AgentVersion;
+import org.apache.ambari.server.state.HostHealthStatus;
+import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.HostHealthStatus.HealthStatus;
+import org.apache.ambari.server.state.host.HostHealthyHeartbeatEvent;
+import org.apache.ambari.server.state.host.HostHeartbeatLostEvent;
+import org.apache.ambari.server.state.host.HostImpl;
+import org.apache.ambari.server.state.host.HostRegistrationRequestEvent;
+import org.apache.ambari.server.state.host.HostStatusUpdatesReceivedEvent;
+import org.apache.ambari.server.state.host.HostUnhealthyHeartbeatEvent;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class HostImplTest {
+
+ @Test
+ public void testHostInfoImport() {
+ HostInfo info = new HostInfo();
+ info.setMemorySize(100);
+ info.setProcessorCount(10);
+ List<DiskInfo> mounts = new ArrayList<DiskInfo>();
+ mounts.add(new DiskInfo("/dev/sda", "/mnt/disk1",
+ "5000000", "4000000", "10%", "size"));
+ info.setMounts(mounts);
+
+ info.setHostName("foo");
+ info.setInterfaces("fip_4");
+ info.setArchitecture("os_arch");
+ info.setOS("os_type");
+ info.setMemoryTotal(10);
+
+ HostImpl host = new HostImpl("foo");
+ host.importHostInfo(info);
+
+ Assert.assertEquals(info.getHostName(), host.getHostName());
+ Assert.assertEquals(info.getFreeMemory(), host.getAvailableMemBytes());
+ Assert.assertEquals(info.getMemoryTotal(), host.getTotalMemBytes());
+ Assert.assertEquals(info.getProcessorCount(), host.getCpuCount());
+ Assert.assertEquals(info.getMounts().size(), host.getDisksInfo().size());
+ Assert.assertEquals(info.getArchitecture(), host.getOsArch());
+ Assert.assertEquals(info.getOS(), host.getOsType());
+ }
+
+ private void registerHost(HostImpl host) throws Exception {
+ HostInfo info = new HostInfo();
+ info.setMemorySize(100);
+ info.setProcessorCount(10);
+ List<DiskInfo> mounts = new ArrayList<DiskInfo>();
+ mounts.add(new DiskInfo("/dev/sda", "/mnt/disk1",
+ "5000000", "4000000", "10%", "size"));
+ info.setMounts(mounts);
+
+ info.setHostName("foo");
+ info.setInterfaces("fip_4");
+ info.setArchitecture("os_arch");
+ info.setOS("os_type");
+ info.setMemoryTotal(10);
+
+ AgentVersion agentVersion = null;
+ long currentTime = System.currentTimeMillis();
+
+ HostRegistrationRequestEvent e =
+ new HostRegistrationRequestEvent("foo", agentVersion, currentTime,
+ info);
+ host.handleEvent(e);
+ Assert.assertEquals(currentTime, host.getLastRegistrationTime());
+ }
+
+ private void ensureHostUpdatesReceived(HostImpl host) throws Exception {
+ HostStatusUpdatesReceivedEvent e =
+ new HostStatusUpdatesReceivedEvent(host.getHostName(), 1);
+ host.handleEvent(e);
+ }
+
+ private void verifyHostState(HostImpl host, HostState state) {
+ Assert.assertEquals(state, host.getState());
+ }
+
+ private void sendHealthyHeartbeat(HostImpl host, long counter)
+ throws Exception {
+ HostHealthyHeartbeatEvent e = new HostHealthyHeartbeatEvent(
+ host.getHostName(), counter);
+ host.handleEvent(e);
+ }
+
+ private void sendUnhealthyHeartbeat(HostImpl host, long counter)
+ throws Exception {
+ HostHealthStatus healthStatus = new HostHealthStatus(HealthStatus.UNHEALTHY,
+ "Unhealthy server");
+ HostUnhealthyHeartbeatEvent e = new HostUnhealthyHeartbeatEvent(
+ host.getHostName(), counter, healthStatus);
+ host.handleEvent(e);
+ }
+
+ private void timeoutHost(HostImpl host) throws Exception {
+ HostHeartbeatLostEvent e = new HostHeartbeatLostEvent(
+ host.getHostName());
+ host.handleEvent(e);
+ }
+
+ @Test
+ public void testHostFSMInit() {
+ HostImpl host = new HostImpl("foo");
+ verifyHostState(host, HostState.INIT);
+ }
+
+ @Test
+ public void testHostRegistrationFlow() throws Exception {
+ HostImpl host = new HostImpl("foo");
+ registerHost(host);
+ verifyHostState(host, HostState.WAITING_FOR_HOST_STATUS_UPDATES);
+
+ boolean exceptionThrown = false;
+ try {
+ registerHost(host);
+ } catch (Exception e) {
+ // Expected
+ exceptionThrown = true;
+ }
+ if (!exceptionThrown) {
+ fail("Expected invalid transition exception to be thrown");
+ }
+
+ ensureHostUpdatesReceived(host);
+ verifyHostState(host, HostState.HEALTHY);
+
+ exceptionThrown = false;
+ try {
+ ensureHostUpdatesReceived(host);
+ } catch (Exception e) {
+ // Expected
+ exceptionThrown = true;
+ }
+ if (!exceptionThrown) {
+ fail("Expected invalid transition exception to be thrown");
+ }
+ }
+
+ @Test
+ public void testHostHeartbeatFlow() throws Exception {
+ HostImpl host = new HostImpl("foo");
+ registerHost(host);
+ ensureHostUpdatesReceived(host);
+
+ // TODO need to verify audit logs generated
+ // TODO need to verify health status updated properly
+
+ long counter = 0;
+ sendHealthyHeartbeat(host, ++counter);
+ verifyHostState(host, HostState.HEALTHY);
+ Assert.assertEquals(counter, host.getLastHeartbeatTime());
+
+ sendHealthyHeartbeat(host, ++counter);
+ verifyHostState(host, HostState.HEALTHY);
+ Assert.assertEquals(counter, host.getLastHeartbeatTime());
+ Assert.assertEquals(HealthStatus.HEALTHY,
+ host.getHealthStatus().getHealthStatus());
+
+ sendUnhealthyHeartbeat(host, ++counter);
+ verifyHostState(host, HostState.UNHEALTHY);
+ Assert.assertEquals(counter, host.getLastHeartbeatTime());
+ Assert.assertEquals(HealthStatus.UNHEALTHY,
+ host.getHealthStatus().getHealthStatus());
+
+ sendUnhealthyHeartbeat(host, ++counter);
+ verifyHostState(host, HostState.UNHEALTHY);
+ Assert.assertEquals(counter, host.getLastHeartbeatTime());
+ Assert.assertEquals(HealthStatus.UNHEALTHY,
+ host.getHealthStatus().getHealthStatus());
+
+ sendHealthyHeartbeat(host, ++counter);
+ verifyHostState(host, HostState.HEALTHY);
+ Assert.assertEquals(counter, host.getLastHeartbeatTime());
+ Assert.assertEquals(HealthStatus.HEALTHY,
+ host.getHealthStatus().getHealthStatus());
+
+ timeoutHost(host);
+ verifyHostState(host, HostState.HEARTBEAT_LOST);
+ Assert.assertEquals(counter, host.getLastHeartbeatTime());
+ Assert.assertEquals(HealthStatus.UNKNOWN,
+ host.getHealthStatus().getHealthStatus());
+
+ timeoutHost(host);
+ verifyHostState(host, HostState.HEARTBEAT_LOST);
+ Assert.assertEquals(counter, host.getLastHeartbeatTime());
+ Assert.assertEquals(HealthStatus.UNKNOWN,
+ host.getHealthStatus().getHealthStatus());
+
+ try {
+ sendUnhealthyHeartbeat(host, ++counter);
+ fail("Invalid event should have triggered an exception");
+ } catch (Exception e) {
+ // Expected
+ }
+ verifyHostState(host, HostState.HEARTBEAT_LOST);
+
+ try {
+ sendHealthyHeartbeat(host, ++counter);
+ fail("Invalid event should have triggered an exception");
+ } catch (Exception e) {
+ // Expected
+ }
+ verifyHostState(host, HostState.HEARTBEAT_LOST);
+ }
+
+ @Test
+ public void testHostRegistrationsInAnyState() throws Exception {
+ HostImpl host = new HostImpl("foo");
+ long counter = 0;
+
+ registerHost(host);
+
+ ensureHostUpdatesReceived(host);
+ registerHost(host);
+
+ ensureHostUpdatesReceived(host);
+ sendHealthyHeartbeat(host, ++counter);
+ verifyHostState(host, HostState.HEALTHY);
+ registerHost(host);
+ ensureHostUpdatesReceived(host);
+
+ sendUnhealthyHeartbeat(host, ++counter);
+ verifyHostState(host, HostState.UNHEALTHY);
+ registerHost(host);
+ ensureHostUpdatesReceived(host);
+
+ timeoutHost(host);
+ verifyHostState(host, HostState.HEARTBEAT_LOST);
+ registerHost(host);
+ ensureHostUpdatesReceived(host);
+
+ host.setState(HostState.INIT);
+ registerHost(host);
+
+ }
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobImplTest.java?rev=1395819&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobImplTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobImplTest.java Tue Oct 9 00:04:44 2012
@@ -0,0 +1,153 @@
+/**
+ * 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.job;
+
+import org.apache.ambari.server.state.job.Job;
+import org.apache.ambari.server.state.job.JobCompletedEvent;
+import org.apache.ambari.server.state.job.JobEvent;
+import org.apache.ambari.server.state.job.JobFailedEvent;
+import org.apache.ambari.server.state.job.JobId;
+import org.apache.ambari.server.state.job.JobImpl;
+import org.apache.ambari.server.state.job.JobProgressUpdateEvent;
+import org.apache.ambari.server.state.job.JobState;
+import org.apache.ambari.server.state.job.JobType;
+import org.apache.ambari.server.state.job.NewJobEvent;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JobImplTest {
+
+ private Job createNewJob(long id, String jobName, long startTime) {
+ JobId jId = new JobId(id, new JobType(jobName));
+ Job job = new JobImpl(jId, startTime);
+ return job;
+ }
+
+ private Job getRunningJob(long id, String jobName, long startTime)
+ throws Exception {
+ Job job = createNewJob(id, jobName, startTime);
+ verifyProgressUpdate(job, ++startTime);
+ return job;
+ }
+
+ private Job getCompletedJob(long id, String jobName, long startTime,
+ boolean failedJob) throws Exception {
+ Job job = getRunningJob(1, "JobNameFoo", startTime);
+ completeJob(job, failedJob, ++startTime);
+ return job;
+ }
+
+ private void verifyNewJob(Job job, long startTime) {
+ Assert.assertEquals(JobState.INIT, job.getState());
+ Assert.assertEquals(startTime, job.getStartTime());
+ }
+
+
+ @Test
+ public void testNewJob() {
+ long currentTime = System.currentTimeMillis();
+ Job job = createNewJob(1, "JobNameFoo", currentTime);
+ verifyNewJob(job, currentTime);
+ }
+
+ private void verifyProgressUpdate(Job job, long updateTime)
+ throws Exception {
+ JobProgressUpdateEvent e = new JobProgressUpdateEvent(job.getId(),
+ updateTime);
+ job.handleEvent(e);
+ Assert.assertEquals(JobState.IN_PROGRESS, job.getState());
+ Assert.assertEquals(updateTime, job.getLastUpdateTime());
+ }
+
+
+ @Test
+ public void testJobProgressUpdates() throws Exception {
+ long currentTime = 1;
+ Job job = createNewJob(1, "JobNameFoo", currentTime);
+ verifyNewJob(job, currentTime);
+
+ verifyProgressUpdate(job, ++currentTime);
+ verifyProgressUpdate(job, ++currentTime);
+ verifyProgressUpdate(job, ++currentTime);
+
+ }
+
+ private void completeJob(Job job, boolean failJob, long endTime)
+ throws Exception {
+ JobEvent e = null;
+ JobState endState = null;
+ if (failJob) {
+ e = new JobFailedEvent(job.getId(), endTime);
+ endState = JobState.FAILED;
+ } else {
+ e = new JobCompletedEvent(job.getId(), endTime);
+ endState = JobState.COMPLETED;
+ }
+ job.handleEvent(e);
+ Assert.assertEquals(endState, job.getState());
+ Assert.assertEquals(endTime, job.getLastUpdateTime());
+ Assert.assertEquals(endTime, job.getCompletionTime());
+ }
+
+
+ @Test
+ public void testJobSuccessfulCompletion() throws Exception {
+ long currentTime = 1;
+ Job job = getRunningJob(1, "JobNameFoo", currentTime);
+ completeJob(job, false, ++currentTime);
+ }
+
+ @Test
+ public void testJobFailedCompletion() throws Exception {
+ long currentTime = 1;
+ Job job = getRunningJob(1, "JobNameFoo", currentTime);
+ completeJob(job, true, ++currentTime);
+ }
+
+ @Test
+ public void completeNewJob() throws Exception {
+ long currentTime = 1;
+ Job job = createNewJob(1, "JobNameFoo", currentTime);
+ verifyNewJob(job, currentTime);
+ completeJob(job, false, ++currentTime);
+ }
+
+ @Test
+ public void failNewJob() throws Exception {
+ long currentTime = 1;
+ Job job = createNewJob(1, "JobNameFoo", currentTime);
+ verifyNewJob(job, currentTime);
+ completeJob(job, true, ++currentTime);
+ }
+
+ @Test
+ public void reInitCompletedJob() throws Exception {
+ Job job = getCompletedJob(1, "JobNameFoo", 1, false);
+ JobId jId = new JobId(2, new JobType("JobNameFoo"));
+ NewJobEvent e = new NewJobEvent(jId, 100);
+ job.handleEvent(e);
+ Assert.assertEquals(JobState.INIT, job.getState());
+ Assert.assertEquals(100, job.getStartTime());
+ Assert.assertEquals(-1, job.getLastUpdateTime());
+ Assert.assertEquals(-1, job.getCompletionTime());
+ Assert.assertEquals(2, job.getId().jobId);
+ }
+
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/job/JobImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImplTest.java?rev=1395819&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImplTest.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImplTest.java Tue Oct 9 00:04:44 2012
@@ -0,0 +1,279 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.state.svccomphost;
+
+import static org.mockito.Mockito.*;
+
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.State;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponent;
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceComponentHostEventType;
+import org.apache.ambari.server.state.ServiceComponentImpl;
+import org.apache.ambari.server.state.ServiceImpl;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostImpl;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostInstallEvent;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpFailedEvent;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpInProgressEvent;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpRestartedEvent;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpSucceededEvent;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStopEvent;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostUninstallEvent;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostWipeoutEvent;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ServiceComponentHostImplTest {
+
+ private ServiceComponentHostImpl createNewServiceComponentHost(long clusterId,
+ String svc,
+ String svcComponent,
+ String hostName, boolean isClient) {
+ Cluster c = mock(Cluster.class);
+ Service s = new ServiceImpl(c, svc);
+ ServiceComponent sc = new ServiceComponentImpl(s, svcComponent);
+ ServiceComponentHostImpl impl = new ServiceComponentHostImpl(
+ sc, hostName, isClient);
+ Assert.assertEquals(State.INIT,
+ impl.getState());
+ return impl;
+ }
+
+ @Test
+ public void testNewServiceComponentHostImpl() {
+ createNewServiceComponentHost(1, "svc", "svcComp", "h1", false);
+ createNewServiceComponentHost(1, "svc", "svcComp", "h1", true);
+ }
+
+ private ServiceComponentHostEvent createEvent(ServiceComponentHostImpl impl,
+ long timestamp, ServiceComponentHostEventType eventType) {
+ switch (eventType) {
+ case HOST_SVCCOMP_INSTALL:
+ return new ServiceComponentHostInstallEvent(
+ impl.getServiceComponentName(), impl.getHostName(), timestamp);
+ case HOST_SVCCOMP_START:
+ return new ServiceComponentHostStartEvent(
+ impl.getServiceComponentName(), impl.getHostName(), timestamp);
+ case HOST_SVCCOMP_STOP:
+ return new ServiceComponentHostStopEvent(
+ impl.getServiceComponentName(), impl.getHostName(), timestamp);
+ case HOST_SVCCOMP_UNINSTALL:
+ return new ServiceComponentHostUninstallEvent(
+ impl.getServiceComponentName(), impl.getHostName(), timestamp);
+ case HOST_SVCCOMP_OP_FAILED:
+ return new ServiceComponentHostOpFailedEvent(
+ impl.getServiceComponentName(), impl.getHostName(), timestamp);
+ case HOST_SVCCOMP_OP_SUCCEEDED:
+ return new ServiceComponentHostOpSucceededEvent(
+ impl.getServiceComponentName(), impl.getHostName(), timestamp);
+ case HOST_SVCCOMP_OP_IN_PROGRESS:
+ return new ServiceComponentHostOpInProgressEvent(
+ impl.getServiceComponentName(), impl.getHostName(), timestamp);
+ case HOST_SVCCOMP_OP_RESTART:
+ return new ServiceComponentHostOpRestartedEvent(
+ impl.getServiceComponentName(), impl.getHostName(), timestamp);
+ case HOST_SVCCOMP_WIPEOUT:
+ return new ServiceComponentHostWipeoutEvent(
+ impl.getServiceComponentName(), impl.getHostName(), timestamp);
+ }
+ return null;
+ }
+
+ private void runStateChanges(ServiceComponentHostImpl impl,
+ ServiceComponentHostEventType startEvent,
+ State startState,
+ State inProgressState,
+ State failedState,
+ State completedState)
+ throws Exception {
+ long timestamp = 0;
+
+ Assert.assertEquals(startState,
+ impl.getState());
+ ServiceComponentHostEvent installEvent = createEvent(impl, ++timestamp,
+ startEvent);
+
+ long startTime = timestamp;
+ impl.handleEvent(installEvent);
+ Assert.assertEquals(startTime, impl.getLastOpStartTime());
+ Assert.assertEquals(-1, impl.getLastOpLastUpdateTime());
+ Assert.assertEquals(-1, impl.getLastOpEndTime());
+ Assert.assertEquals(inProgressState,
+ impl.getState());
+
+ ServiceComponentHostEvent installEvent2 = createEvent(impl, ++timestamp,
+ startEvent);
+ boolean exceptionThrown = false;
+ try {
+ impl.handleEvent(installEvent2);
+ } catch (Exception e) {
+ exceptionThrown = true;
+ }
+ Assert.assertTrue("Exception not thrown on invalid event", exceptionThrown);
+ Assert.assertEquals(startTime, impl.getLastOpStartTime());
+ Assert.assertEquals(-1, impl.getLastOpLastUpdateTime());
+ Assert.assertEquals(-1, impl.getLastOpEndTime());
+ Assert.assertEquals(inProgressState,
+ impl.getState());
+
+ ServiceComponentHostOpInProgressEvent inProgressEvent1 = new
+ ServiceComponentHostOpInProgressEvent(impl.getServiceComponentName(),
+ impl.getHostName(), ++timestamp);
+ impl.handleEvent(inProgressEvent1);
+ Assert.assertEquals(startTime, impl.getLastOpStartTime());
+ Assert.assertEquals(timestamp, impl.getLastOpLastUpdateTime());
+ Assert.assertEquals(-1, impl.getLastOpEndTime());
+ Assert.assertEquals(inProgressState,
+ impl.getState());
+
+ ServiceComponentHostOpInProgressEvent inProgressEvent2 = new
+ ServiceComponentHostOpInProgressEvent(impl.getServiceComponentName(),
+ impl.getHostName(), ++timestamp);
+ impl.handleEvent(inProgressEvent2);
+ Assert.assertEquals(startTime, impl.getLastOpStartTime());
+ Assert.assertEquals(timestamp, impl.getLastOpLastUpdateTime());
+ Assert.assertEquals(-1, impl.getLastOpEndTime());
+ Assert.assertEquals(inProgressState,
+ impl.getState());
+
+
+ ServiceComponentHostOpFailedEvent failEvent = new
+ ServiceComponentHostOpFailedEvent(impl.getServiceComponentName(),
+ impl.getHostName(), ++timestamp);
+ long endTime = timestamp;
+ impl.handleEvent(failEvent);
+ Assert.assertEquals(startTime, impl.getLastOpStartTime());
+ Assert.assertEquals(timestamp, impl.getLastOpLastUpdateTime());
+ Assert.assertEquals(endTime, impl.getLastOpEndTime());
+ Assert.assertEquals(failedState,
+ impl.getState());
+
+ ServiceComponentHostOpRestartedEvent restartEvent = new
+ ServiceComponentHostOpRestartedEvent(impl.getServiceComponentName(),
+ impl.getHostName(), ++timestamp);
+ startTime = timestamp;
+ impl.handleEvent(restartEvent);
+ Assert.assertEquals(startTime, impl.getLastOpStartTime());
+ Assert.assertEquals(-1, impl.getLastOpLastUpdateTime());
+ Assert.assertEquals(-1, impl.getLastOpEndTime());
+ Assert.assertEquals(inProgressState,
+ impl.getState());
+
+ ServiceComponentHostOpInProgressEvent inProgressEvent3 = new
+ ServiceComponentHostOpInProgressEvent(impl.getServiceComponentName(),
+ impl.getHostName(), ++timestamp);
+ impl.handleEvent(inProgressEvent3);
+ Assert.assertEquals(startTime, impl.getLastOpStartTime());
+ Assert.assertEquals(timestamp, impl.getLastOpLastUpdateTime());
+ Assert.assertEquals(-1, impl.getLastOpEndTime());
+ Assert.assertEquals(inProgressState,
+ impl.getState());
+
+ ServiceComponentHostOpSucceededEvent succeededEvent = new
+ ServiceComponentHostOpSucceededEvent(impl.getServiceComponentName(),
+ impl.getHostName(), ++timestamp);
+ endTime = timestamp;
+ impl.handleEvent(succeededEvent);
+ Assert.assertEquals(startTime, impl.getLastOpStartTime());
+ Assert.assertEquals(timestamp, impl.getLastOpLastUpdateTime());
+ Assert.assertEquals(endTime, impl.getLastOpEndTime());
+ Assert.assertEquals(completedState,
+ impl.getState());
+
+ }
+
+ @Test
+ public void testClientStateFlow() throws Exception {
+ ServiceComponentHostImpl impl = createNewServiceComponentHost(1, "svc",
+ "svcComp", "h1", true);
+
+ runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
+ State.INIT,
+ State.INSTALLING,
+ State.INSTALL_FAILED,
+ State.INSTALLED);
+
+ boolean exceptionThrown = false;
+ try {
+ runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_START,
+ State.INSTALLED,
+ State.STARTING,
+ State.START_FAILED,
+ State.STARTED);
+ }
+ catch (Exception e) {
+ exceptionThrown = true;
+ }
+ Assert.assertTrue("Exception not thrown on invalid event", exceptionThrown);
+
+ runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_UNINSTALL,
+ State.INSTALLED,
+ State.UNINSTALLING,
+ State.UNINSTALL_FAILED,
+ State.UNINSTALLED);
+
+ runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_WIPEOUT,
+ State.UNINSTALLED,
+ State.WIPING_OUT,
+ State.WIPEOUT_FAILED,
+ State.INIT);
+
+ }
+
+ @Test
+ public void testDaemonStateFlow() throws Exception {
+ ServiceComponentHostImpl impl = createNewServiceComponentHost(1, "svc",
+ "svcComp", "h1", false);
+
+ runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
+ State.INIT,
+ State.INSTALLING,
+ State.INSTALL_FAILED,
+ State.INSTALLED);
+
+ runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_START,
+ State.INSTALLED,
+ State.STARTING,
+ State.START_FAILED,
+ State.STARTED);
+
+ runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_STOP,
+ State.STARTED,
+ State.STOPPING,
+ State.STOP_FAILED,
+ State.INSTALLED);
+
+ runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_UNINSTALL,
+ State.INSTALLED,
+ State.UNINSTALLING,
+ State.UNINSTALL_FAILED,
+ State.UNINSTALLED);
+
+ runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_WIPEOUT,
+ State.UNINSTALLED,
+ State.WIPING_OUT,
+ State.WIPEOUT_FAILED,
+ State.INIT);
+
+ }
+
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native