Author: mahadev
Date: Wed Jan 30 09:04:19 2013
New Revision: 1440307
URL: http://svn.apache.org/viewvc?rev=1440307&view=rev
Log:
AMBARI-1301. Live status checks dont get triggered on server restart.
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
Modified: incubator/ambari/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1440307&r1=1440306&r2=1440307&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Wed Jan 30 09:04:19 2013
@@ -299,6 +299,9 @@ Trunk (unreleased changes):
AMBARI-1291. Incorrect directory for MySQL component on SLES-11.1sp1.
(mahadev)
+ AMBARI-1301. Live status checks dont get triggered on server restart.
+ (mahadev)
+
AMBARI-1.2.0 branch:
INCOMPATIBLE CHANGES
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java?rev=1440307&r1=1440306&r2=1440307&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatMonitor.java
Wed Jan 30 09:04:19 2013
@@ -18,17 +18,20 @@
package org.apache.ambari.server.agent;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.actionmanager.ActionManager;
-import org.apache.ambari.server.state.*;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.ServiceComponentHost;
import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
import org.apache.ambari.server.state.host.HostHeartbeatLostEvent;
-import org.apache.ambari.server.state.host.HostStatusUpdatesReceivedEvent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java?rev=1440307&r1=1440306&r2=1440307&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
Wed Jan 30 09:04:19 2013
@@ -32,8 +32,6 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import com.google.gson.Gson;
-import com.google.inject.persist.Transactional;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.ServiceComponentHostNotFoundException;
import org.apache.ambari.server.ServiceNotFoundException;
@@ -47,15 +45,18 @@ import org.apache.ambari.server.state.Cl
import org.apache.ambari.server.state.Config;
import org.apache.ambari.server.state.ConfigFactory;
import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponent;
import org.apache.ambari.server.state.ServiceComponentHost;
import org.apache.ambari.server.state.ServiceFactory;
import org.apache.ambari.server.state.StackId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.gson.Gson;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.assistedinject.Assisted;
+import com.google.inject.persist.Transactional;
public class ClusterImpl implements Cluster {
@@ -66,7 +67,6 @@ public class ClusterImpl implements Clus
private Clusters clusters;
private StackId desiredStackVersion;
- private StackId desiredState;
private Map<String, Service> services = null;
@@ -114,8 +114,9 @@ public class ClusterImpl implements Clus
Map<String, Map<String, ServiceComponentHost>>>();
this.serviceComponentHostsByHost = new HashMap<String,
List<ServiceComponentHost>>();
- this.desiredStackVersion =
gson.fromJson(clusterEntity.getDesiredStackVersion(), StackId.class);
-
+ this.desiredStackVersion = gson.fromJson(
+ clusterEntity.getDesiredStackVersion(), StackId.class);
+ loadServiceHostComponents();
configs = new HashMap<String, Map<String, Config>>();
if (!clusterEntity.getClusterConfigEntities().isEmpty()) {
for (ClusterConfigEntity entity :
clusterEntity.getClusterConfigEntities()) {
@@ -129,11 +130,57 @@ public class ClusterImpl implements Clus
configs.get(entity.getType()).put(entity.getTag(), config);
}
}
-
-
+ }
+
+
+ /**
+ * Make sure we load all the service host components.
+ * We need this for live status checks.
+ */
+ public void loadServiceHostComponents() {
+ loadServices();
+ LOG.info("Loading Service Host Components");
+ if (services != null) {
+ for (Map.Entry<String, Service> serviceKV: services.entrySet()) {
+ /* get all the service component hosts **/
+ Service service = serviceKV.getValue();
+ if (!serviceComponentHosts.containsKey(service.getName())) {
+ serviceComponentHosts.put(service.getName(), new HashMap<String,
+ Map<String, ServiceComponentHost>>());
+ }
+ for (Map.Entry<String, ServiceComponent> svcComponent:
+ service.getServiceComponents().entrySet()) {
+ ServiceComponent comp = svcComponent.getValue();
+ String componentName = svcComponent.getKey();
+ if
(!serviceComponentHosts.get(service.getName()).containsKey(componentName)) {
+ serviceComponentHosts.get(service.getName()).put(componentName,
+ new HashMap<String, ServiceComponentHost>());
+ }
+ /** Get Service Host Components **/
+ for (Map.Entry<String, ServiceComponentHost> svchost:
+ comp.getServiceComponentHosts().entrySet()) {
+ String hostname = svchost.getKey();
+ ServiceComponentHost svcHostComponent = svchost.getValue();
+ if (!serviceComponentHostsByHost.containsKey(hostname)) {
+ serviceComponentHostsByHost.put(hostname,
+ new ArrayList<ServiceComponentHost>());
+ }
+ List<ServiceComponentHost> compList =
serviceComponentHostsByHost.get(hostname);
+ compList.add(svcHostComponent);
+
+ if
(!serviceComponentHosts.get(service.getName()).get(componentName)
+ .containsKey(hostname)) {
+ serviceComponentHosts.get(service.getName()).get(componentName)
+ .put(hostname, svcHostComponent);
+ }
+ }
+ }
+ }
+ }
}
private void loadServices() {
+ LOG.info("clusterEntity " + clusterEntity.getClusterServiceEntities() );
if (services == null) {
synchronized (this) {
if (services == null) {
Modified:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java?rev=1440307&r1=1440306&r2=1440307&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
Wed Jan 30 09:04:19 2013
@@ -19,13 +19,16 @@
package org.apache.ambari.server.state.cluster;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
+import static org.mockito.Mockito.*;
+
+import javax.persistence.EntityManager;
import junit.framework.Assert;
@@ -38,7 +41,11 @@ import org.apache.ambari.server.api.serv
import org.apache.ambari.server.controller.ClusterResponse;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
+import org.apache.ambari.server.orm.entities.ClusterEntity;
+import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
+import org.apache.ambari.server.orm.entities.HostEntity;
+import org.apache.ambari.server.orm.entities.HostStateEntity;
+import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity;
import org.apache.ambari.server.state.AgentVersion;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
@@ -57,15 +64,17 @@ import org.apache.ambari.server.state.ho
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import com.google.gson.Gson;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
-import javax.persistence.EntityManager;
-
public class ClusterTest {
-
+ private static final Logger LOG = LoggerFactory.getLogger(ClusterTest.class);
+
private Clusters clusters;
private Cluster c1;
private Injector injector;
@@ -282,6 +291,70 @@ public class ClusterTest {
// public Config getConfig(String configType, String versionTag);
// public void addConfig(Config config);
}
+
+ public ClusterEntity createDummyData() {
+ ClusterEntity clusterEntity = new ClusterEntity();
+ clusterEntity.setClusterName("test_cluster1");
+ clusterEntity.setClusterInfo("test_cluster_info1");
+
+ HostEntity host1 = new HostEntity();
+ HostEntity host2 = new HostEntity();
+ HostEntity host3 = new HostEntity();
+
+ host1.setHostName("test_host1");
+ host2.setHostName("test_host2");
+ host3.setHostName("test_host3");
+ host1.setIpv4("192.168.0.1");
+ host2.setIpv4("192.168.0.2");
+ host3.setIpv4("192.168.0.3");
+
+ List<HostEntity> hostEntities = new ArrayList<HostEntity>();
+ hostEntities.add(host1);
+ hostEntities.add(host2);
+
+ clusterEntity.setHostEntities(hostEntities);
+ clusterEntity.setClusterConfigEntities(Collections.EMPTY_LIST);
+ //both sides of relation should be set when modifying in runtime
+ host1.setClusterEntities(Arrays.asList(clusterEntity));
+ host2.setClusterEntities(Arrays.asList(clusterEntity));
+
+ HostStateEntity hostStateEntity1 = new HostStateEntity();
+ hostStateEntity1.setCurrentState(HostState.HEARTBEAT_LOST);
+ hostStateEntity1.setHostEntity(host1);
+ HostStateEntity hostStateEntity2 = new HostStateEntity();
+ hostStateEntity2.setCurrentState(HostState.HEALTHY);
+ hostStateEntity2.setHostEntity(host2);
+ host1.setHostStateEntity(hostStateEntity1);
+ host2.setHostStateEntity(hostStateEntity2);
+
+ ClusterServiceEntity clusterServiceEntity = new ClusterServiceEntity();
+ clusterServiceEntity.setServiceName("HDFS");
+ clusterServiceEntity.setClusterEntity(clusterEntity);
+ clusterServiceEntity.setServiceComponentDesiredStateEntities(
+ Collections.EMPTY_LIST);
+ clusterServiceEntity.setServiceConfigMappings(Collections.EMPTY_LIST);
+ ServiceDesiredStateEntity stateEntity =
mock(ServiceDesiredStateEntity.class);
+ Gson gson = new Gson();
+ when(stateEntity.getDesiredStackVersion()).thenReturn(gson.toJson(new
StackId("HDP-0.1"),
+ StackId.class));
+ clusterServiceEntity.setServiceDesiredStateEntity(stateEntity);
+ List<ClusterServiceEntity> clusterServiceEntities = new
ArrayList<ClusterServiceEntity>();
+ clusterServiceEntities.add(clusterServiceEntity);
+ clusterEntity.setClusterServiceEntities(clusterServiceEntities);
+ return clusterEntity;
+ }
+
+ @Test
+ public void testClusterRecovery() throws AmbariException {
+ ClusterEntity entity = createDummyData();
+ ClusterImpl cluster = new ClusterImpl(entity, injector);
+ Service service = cluster.getService("HDFS");
+ /* make sure the services are recovered */
+ Assert.assertEquals("HDFS",service.getName());
+ Map<String, Service> services = cluster.getServices();
+ Assert.assertNotNull(services.get("HDFS"));
+ }
+
@Test
public void testConvertToResponse() throws AmbariException {