Author: ncole
Date: Wed Mar 6 18:45:41 2013
New Revision: 1453471
URL: http://svn.apache.org/r1453471
Log:
AMBARI-1553. List cluster-level configurations with host-level, if any
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/DesiredConfig.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
incubator/ambari/trunk/ambari-server/src/main/resources/properties.json
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAOTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/DesiredConfigTest.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=1453471&r1=1453470&r2=1453471&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Wed Mar 6 18:45:41 2013
@@ -12,6 +12,8 @@ Trunk (unreleased changes):
NEW FEATURES
+ AMBARI-1553. List cluster-level configurations with host-level, if any (ncole)
+
AMBARI-1557. Adding Hue service to the HDP stack definition along with the
necessary configuration properties. (swagle)
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1453471&r1=1453470&r2=1453471&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
Wed Mar 6 18:45:41 2013
@@ -980,11 +980,15 @@ public class AmbariManagementControllerI
if (request.getClusterName() != null) {
Cluster c = clusters.getCluster(request.getClusterName());
- response.add(c.convertToResponse());
+ ClusterResponse cr = c.convertToResponse();
+ cr.setDesiredConfigs(c.getDesiredConfigs());
+ response.add(cr);
return response;
} else if (request.getClusterId() != null) {
Cluster c = clusters.getClusterById(request.getClusterId());
- response.add(c.convertToResponse());
+ ClusterResponse cr = c.convertToResponse();
+ cr.setDesiredConfigs(c.getDesiredConfigs());
+ response.add(cr);
return response;
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java?rev=1453471&r1=1453470&r2=1453471&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterResponse.java
Wed Mar 6 18:45:41 2013
@@ -18,8 +18,11 @@
package org.apache.ambari.server.controller;
+import java.util.Map;
import java.util.Set;
+import org.apache.ambari.server.state.DesiredConfig;
+
public class ClusterResponse {
private final Long clusterId;
@@ -30,6 +33,8 @@ public class ClusterResponse {
private final String desiredStackVersion;
+ private Map<String, DesiredConfig> desiredConfigs;
+
public ClusterResponse(Long clusterId, String clusterName,
Set<String> hostNames, String desiredStackVersion) {
super();
@@ -115,4 +120,18 @@ public class ClusterResponse {
return desiredStackVersion;
}
+ /**
+ * @param desiredConfigs
+ */
+ public void setDesiredConfigs(Map<String, DesiredConfig> configs) {
+ desiredConfigs = configs;
+ }
+
+ /**
+ * @return the desired configs
+ */
+ public Map<String, DesiredConfig> getDesiredConfigs() {
+ return desiredConfigs;
+ }
+
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java?rev=1453471&r1=1453470&r2=1453471&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
Wed Mar 6 18:45:41 2013
@@ -21,7 +21,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
import org.apache.ambari.server.AmbariException;
@@ -53,6 +52,7 @@ class ClusterResourceProvider extends Ab
protected static final String CLUSTER_ID_PROPERTY_ID =
PropertyHelper.getPropertyId("Clusters", "cluster_id");
protected static final String CLUSTER_NAME_PROPERTY_ID =
PropertyHelper.getPropertyId("Clusters", "cluster_name");
protected static final String CLUSTER_VERSION_PROPERTY_ID =
PropertyHelper.getPropertyId("Clusters", "version");
+ protected static final String CLUSTER_DESIRED_CONFIGS_PROPERTY_ID =
PropertyHelper.getPropertyId("Clusters", "desired_configs");
private static Set<String> pkPropertyIds =
@@ -121,6 +121,7 @@ class ClusterResourceProvider extends Ab
Resource resource = new ResourceImpl(Resource.Type.Cluster);
setResourceProperty(resource, CLUSTER_ID_PROPERTY_ID,
response.getClusterId(), requestedIds);
setResourceProperty(resource, CLUSTER_NAME_PROPERTY_ID,
response.getClusterName(), requestedIds);
+ setResourceProperty(resource, CLUSTER_DESIRED_CONFIGS_PROPERTY_ID,
response.getDesiredConfigs(), requestedIds);
resource.setProperty(CLUSTER_VERSION_PROPERTY_ID,
response.getDesiredStackVersion());
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java?rev=1453471&r1=1453470&r2=1453471&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java
Wed Mar 6 18:45:41 2013
@@ -51,8 +51,8 @@ public class HostConfigMappingDAO {
TypedQuery<HostConfigMappingEntity> query =
entityManagerProvider.get().createQuery(
"SELECT entity FROM HostConfigMappingEntity entity " +
"WHERE entity.clusterId = ?1 AND entity.hostName = ?2 AND entity.type =
?3",
- HostConfigMappingEntity.class);
-
+ HostConfigMappingEntity.class);
+
return daoUtils.selectList(query, Long.valueOf(clusterId), hostName, type);
}
@@ -65,7 +65,7 @@ public class HostConfigMappingDAO {
"AND entity.type = ?3 " +
"AND entity.selected > 0",
HostConfigMappingEntity.class);
-
+
return daoUtils.selectSingle(query, Long.valueOf(clusterId), hostName,
type);
}
@@ -75,8 +75,17 @@ public class HostConfigMappingDAO {
"WHERE entity.clusterId = ?1 AND entity.hostName = ?2 " +
"AND entity.selected > 0",
HostConfigMappingEntity.class);
-
+
return daoUtils.selectList(query, Long.valueOf(clusterId), hostName);
}
-
+
+ public List<HostConfigMappingEntity> findSelectedHostsByType(long clusterId,
+ String type) {
+ TypedQuery<HostConfigMappingEntity> query =
entityManagerProvider.get().createQuery(
+ "SELECT entity FROM HostConfigMappingEntity entity " +
+ "WHERE entity.clusterId = ?1 AND entity.type = ?2 AND entity.selected
> 0",
+ HostConfigMappingEntity.class);
+ return daoUtils.selectList(query, Long.valueOf(clusterId), type);
+ }
+
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java?rev=1453471&r1=1453470&r2=1453471&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
Wed Mar 6 18:45:41 2013
@@ -79,8 +79,7 @@ public interface Cluster {
* @param stackVersion
*/
public void setDesiredStackVersion(StackId stackVersion);
-
-
+
/**
* Get current stack version
* @return
@@ -97,7 +96,7 @@ public interface Cluster {
* Gets all configs that match the specified type. Result is not the
* DESIRED configuration for a cluster.
* @param configType the config type to return
- * @return a map of configuration objects that have been set for the given
type
+ * @return a map of configuration objects that have been set for the given
type
*/
public Map<String, Config> getConfigsByType(String configType);
@@ -123,14 +122,14 @@ public interface Cluster {
* @return the collection of all configs that have been defined.
*/
public Collection<Config> getAllConfigs();
-
+
/**
* Adds and sets a DESIRED configuration to be applied to a cluster. There
* can be only one selected config per type.
* @param config the {@link Config} object to set as desired
*/
public void addDesiredConfig(Config config);
-
+
/**
* Gets the desired (and selected) config by type.
* @param configType the type of configuration
@@ -138,7 +137,13 @@ public interface Cluster {
* not been set.
*/
public Config getDesiredConfigByType(String configType);
-
+
+ /**
+ * Gets the desired configurations for the cluster.
+ * @return a map of type-to-configuration information.
+ */
+ public Map<String, DesiredConfig> getDesiredConfigs();
+
/**
* Creates a cluster response based on the current cluster definition
@@ -190,4 +195,5 @@ public interface Cluster {
* @throws AmbariException
*/
Service addService(String serviceName) throws AmbariException;
+
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/DesiredConfig.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/DesiredConfig.java?rev=1453471&r1=1453470&r2=1453471&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/DesiredConfig.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/state/DesiredConfig.java
Wed Mar 6 18:45:41 2013
@@ -17,6 +17,8 @@
*/
package org.apache.ambari.server.state;
+import java.util.List;
+
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
@@ -29,12 +31,20 @@ public class DesiredConfig {
private String versionTag;
private String serviceName;
-
-
+ private List<String> hostOverrides = null;
+
+ /**
+ * Sets the version tag
+ * @param version the version tag
+ */
public void setVersion(String version) {
versionTag = version;
}
-
+
+ /**
+ * Gets the version tag
+ * @return the version tag
+ */
@JsonProperty("tag")
public String getVersion() {
return versionTag;
@@ -48,17 +58,56 @@ public class DesiredConfig {
@JsonProperty("service_name")
public String getServiceName() {
return serviceName;
- }
-
+ }
+
/**
* Sets the service name (if any) for the desired config.
- * @param name
+ * @param name the service name
*/
public void setServiceName(String name) {
serviceName = name;
}
-
-
-
+ /**
+ * Sets the host overrides for the desired config. Cluster-based desired
configs only.
+ * @param overrides the host names
+ */
+ public void setHostOverrides(List<String> overrides) {
+ hostOverrides = overrides;
+ }
+
+ /**
+ * Gets the host overrides for the desired config. Cluster-based desired
configs only.
+ * @return the host names that override the desired config
+ */
+ @JsonSerialize(include = Inclusion.NON_EMPTY)
+ @JsonProperty("host_overrides")
+ public List<String> getHostOverrides() {
+ return hostOverrides;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("{");
+ sb.append("version=").append(versionTag);
+ if (null != serviceName)
+ sb.append(", service=").append(serviceName);
+ if (null != hostOverrides && hostOverrides.size() > 0) {
+ sb.append(", hosts=[");
+ int i = 0;
+ for (String h : hostOverrides)
+ {
+ if (i++ != 0)
+ sb.append(",");
+ sb.append(h);
+ }
+
+ sb.append(']');
+ }
+ sb.append("}");
+
+ return sb.toString();
+ }
+
}
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=1453471&r1=1453470&r2=1453471&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 Mar 6 18:45:41 2013
@@ -32,21 +32,26 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
+import javax.persistence.RollbackException;
+
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.ServiceComponentHostNotFoundException;
import org.apache.ambari.server.ServiceNotFoundException;
import org.apache.ambari.server.controller.ClusterResponse;
import org.apache.ambari.server.orm.dao.ClusterDAO;
import org.apache.ambari.server.orm.dao.ClusterStateDAO;
+import org.apache.ambari.server.orm.dao.HostConfigMappingDAO;
import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
import org.apache.ambari.server.orm.entities.ClusterConfigMappingEntity;
import org.apache.ambari.server.orm.entities.ClusterEntity;
import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
import org.apache.ambari.server.orm.entities.ClusterStateEntity;
+import org.apache.ambari.server.orm.entities.HostConfigMappingEntity;
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.ConfigFactory;
+import org.apache.ambari.server.state.DesiredConfig;
import org.apache.ambari.server.state.Service;
import org.apache.ambari.server.state.ServiceComponent;
import org.apache.ambari.server.state.ServiceComponentHost;
@@ -61,8 +66,6 @@ import com.google.inject.Injector;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.persist.Transactional;
-import javax.persistence.RollbackException;
-
public class ClusterImpl implements Cluster {
private static final Logger LOG =
@@ -102,15 +105,15 @@ public class ClusterImpl implements Clus
private ClusterDAO clusterDAO;
@Inject
private ClusterStateDAO clusterStateDAO;
-// @Inject
-// private ClusterServiceDAO clusterServiceDAO;
@Inject
private ServiceFactory serviceFactory;
@Inject
private ConfigFactory configFactory;
@Inject
private Gson gson;
-
+ @Inject
+ private HostConfigMappingDAO hostConfigMappingDAO;
+
private volatile boolean svcHostsLoaded = false;
@Inject
@@ -139,8 +142,8 @@ public class ClusterImpl implements Clus
}
}
}
-
-
+
+
/**
* Make sure we load all the service host components.
* We need this for live status checks.
@@ -549,7 +552,7 @@ public class ClusterImpl implements Clus
readWriteLock.writeLock().unlock();
}
}
-
+
public Collection<Config> getAllConfigs() {
readWriteLock.readLock().lock();
try {
@@ -573,6 +576,7 @@ public class ClusterImpl implements Clus
ClusterResponse r = new ClusterResponse(getClusterId(), getClusterName(),
clusters.getHostsForCluster(getClusterName()).keySet(),
getDesiredStackVersion().getStackId());
+
return r;
} finally {
readWriteLock.readLock().unlock();
@@ -703,22 +707,25 @@ public class ClusterImpl implements Clus
protected void removeEntities() throws AmbariException {
clusterDAO.removeByPK(getClusterId());
}
-
+
@Override
public void addDesiredConfig(Config config) {
-
+
Config currentDesired = getDesiredConfigByType(config.getType());
-
+
// do not set if it is already the current
if (null != currentDesired &&
currentDesired.getVersionTag().equals(config.getVersionTag())) {
return;
}
- for (ClusterConfigMappingEntity e :
clusterEntity.getConfigMappingEntities()) {
- if (e.isSelected() > 0 && e.getType().equals(config.getType()))
+ Collection<ClusterConfigMappingEntity> entities =
clusterEntity.getConfigMappingEntities();
+
+ for (ClusterConfigMappingEntity e : entities) {
+ if (e.isSelected() > 0 && e.getType().equals(config.getType())) {
e.setSelected(0);
+ }
}
-
+
ClusterConfigMappingEntity entity = new ClusterConfigMappingEntity();
entity.setClusterEntity(clusterEntity);
entity.setClusterId(clusterEntity.getClusterId());
@@ -726,22 +733,54 @@ public class ClusterImpl implements Clus
entity.setSelected(1);
entity.setType(config.getType());
entity.setVersion(config.getVersionTag());
- clusterEntity.getConfigMappingEntities().add(entity);
+ entities.add(entity);
+ clusterEntity.setConfigMappingEntities(entities);
+
clusterDAO.merge(clusterEntity);
-
+
}
-
+
+ @Override
+ public Map<String, DesiredConfig> getDesiredConfigs() {
+ Map<String, DesiredConfig> map = new HashMap<String, DesiredConfig>();
+
+ for (ClusterConfigMappingEntity e :
clusterEntity.getConfigMappingEntities()) {
+ if (e.isSelected() > 0) {
+ DesiredConfig c = new DesiredConfig();
+ c.setServiceName(null);
+ c.setVersion(e.getVersion());
+
+ List<HostConfigMappingEntity> hostMappings =
+
hostConfigMappingDAO.findSelectedHostsByType(clusterEntity.getClusterId().longValue(),
+ e.getType());
+
+ List<String> hosts = new ArrayList<String>();
+ for (HostConfigMappingEntity mappingEntity : hostMappings) {
+ hosts.add (mappingEntity.getHostName());
+ }
+
+ c.setHostOverrides(hosts);
+
+ map.put(e.getType(), c);
+
+ }
+ }
+
+ return map;
+ }
+
+
@Override
public Config getDesiredConfigByType(String configType) {
-
+
for (ClusterConfigMappingEntity e :
clusterEntity.getConfigMappingEntities()) {
if (e.isSelected() > 0 && e.getType().equals(configType)) {
return getConfig(e.getType(), e.getVersion());
}
- }
-
+ }
+
return null;
}
-
+
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/resources/properties.json
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/resources/properties.json?rev=1453471&r1=1453470&r2=1453471&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/resources/properties.json
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/resources/properties.json Wed
Mar 6 18:45:41 2013
@@ -4,7 +4,7 @@
"Clusters/cluster_name",
"Clusters/version",
"Clusters/state",
- "Clusters/desired_config",
+ "Clusters/desired_configs",
"_"
],
"Service":[
Modified:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAOTest.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAOTest.java?rev=1453471&r1=1453470&r2=1453471&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAOTest.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAOTest.java
Wed Mar 6 18:45:41 2013
@@ -25,10 +25,7 @@ import junit.framework.Assert;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.dao.HostConfigMappingDAO;
import org.apache.ambari.server.orm.entities.HostConfigMappingEntity;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -152,6 +149,31 @@ public class HostConfigMappingDAOTest {
Assert.assertEquals("Expected instance equality", entity2, target);
}
+ @Test
+ public void testFindSelectedHostsByType() throws Exception {
+ HostConfigMappingEntity entity1 = createEntity(1L, "h1", "global", "v1");
+ HostConfigMappingEntity entity2 = createEntity(1L, "h2", "global", "v1");
+
+ List<HostConfigMappingEntity> list =
hostConfigMappingDAO.findSelectedHostsByType(1L, "global");
+ Assert.assertEquals("Expected two hosts", 2, list.size());
+
+ entity2.setSelected(0);
+ hostConfigMappingDAO.merge(entity2);
+
+ list = hostConfigMappingDAO.findSelectedHostsByType(1L, "global");
+ Assert.assertEquals("Expected one host", 1, list.size());
+
+
+ list = hostConfigMappingDAO.findSelectedHostsByType(1L, "core-site");
+ Assert.assertEquals("Expected no matching hosts", 0, list.size());
+
+ entity1.setSelected(0);
+ hostConfigMappingDAO.merge(entity1);
+
+ list = hostConfigMappingDAO.findSelectedHostsByType(1L, "global");
+ Assert.assertEquals("Expected no selected hosts", 0, list.size());
+ }
+
Modified:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/DesiredConfigTest.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/DesiredConfigTest.java?rev=1453471&r1=1453470&r2=1453471&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/DesiredConfigTest.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/state/DesiredConfigTest.java
Wed Mar 6 18:45:41 2013
@@ -17,6 +17,9 @@
*/
package org.apache.ambari.server.state;
+import java.util.Arrays;
+import java.util.List;
+
import org.junit.Assert;
import org.junit.Test;
@@ -33,7 +36,13 @@ public class DesiredConfigTest {
Assert.assertEquals("Expected service 'service'", "service",
dc.getServiceName());
Assert.assertEquals("Expected version 'global'", "global",
dc.getVersion());
+ Assert.assertNull("Expected null host overrides", dc.getHostOverrides());
+
+ List<String> hosts = Arrays.asList("h1", "h2", "h3");
+ dc.setHostOverrides(hosts);
+ Assert.assertNotNull("Expected host overrides to be set",
dc.getHostOverrides());
+ Assert.assertEquals("Expected host override equality", hosts,
dc.getHostOverrides());
}
}
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=1453471&r1=1453470&r2=1453471&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 Mar 6 18:45:41 2013
@@ -53,6 +53,7 @@ import org.apache.ambari.server.state.Cl
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Config;
import org.apache.ambari.server.state.ConfigFactory;
+import org.apache.ambari.server.state.DesiredConfig;
import org.apache.ambari.server.state.Host;
import org.apache.ambari.server.state.HostState;
import org.apache.ambari.server.state.Service;
@@ -321,6 +322,48 @@ public class ClusterTest {
}
+ @Test
+ public void testDesiredConfigs() throws Exception {
+ Config config1 = configFactory.createNew(c1, "global",
+ new HashMap<String, String>() {{ put("a", "b"); }});
+ config1.setVersionTag("version1");
+
+ Config config2 = configFactory.createNew(c1, "global",
+ new HashMap<String, String>() {{ put("x", "y"); }});
+ config2.setVersionTag("version2");
+
+ Config config3 = configFactory.createNew(c1, "core-site",
+ new HashMap<String, String>() {{ put("x", "y"); }});
+ config3.setVersionTag("version2");
+
+ c1.addConfig(config1);
+ c1.addConfig(config2);
+ c1.addConfig(config3);
+
+ c1.addDesiredConfig(config1);
+ c1.addDesiredConfig(config3);
+
+ Map<String, DesiredConfig> desiredConfigs = c1.getDesiredConfigs();
+ Assert.assertFalse("Expect desired config not contain 'mapred-site'",
desiredConfigs.containsKey("mapred-site"));
+ Assert.assertTrue("Expect desired config contain " + config1.getType(),
desiredConfigs.containsKey("global"));
+ Assert.assertTrue("Expect desired config contain " + config3.getType(),
desiredConfigs.containsKey("core-site"));
+ Assert.assertEquals("Expect desired config for global should be " +
config1.getVersionTag(),
+ config1.getVersionTag(),
desiredConfigs.get(config1.getType()).getVersion());
+ DesiredConfig dc = desiredConfigs.get(config1.getType());
+ Assert.assertTrue("Expect no host-level overrides",
+ (null == dc.getHostOverrides() || dc.getHostOverrides().size() == 0));
+
+ // setup a host that also has a config override
+ Host host = clusters.getHost("h1");
+ host.addDesiredConfig(c1.getClusterId(), null, config2);
+
+ desiredConfigs = c1.getDesiredConfigs();
+ dc = desiredConfigs.get(config1.getType());
+
+ Assert.assertNotNull("Expect host-level overrides", dc.getHostOverrides());
+ Assert.assertEquals("Expect one host-level override", 1,
dc.getHostOverrides().size());
+ }
+
public ClusterEntity createDummyData() {
ClusterEntity clusterEntity = new ClusterEntity();
clusterEntity.setClusterName("test_cluster1");