You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by tb...@apache.org on 2013/06/11 23:51:53 UTC
svn commit: r1491983 - in /incubator/ambari/trunk/ambari-server/src:
main/java/org/apache/ambari/server/controller/internal/
test/java/org/apache/ambari/server/controller/internal/
test/java/org/apache/ambari/server/controller/jmx/
Author: tbeerbower
Date: Tue Jun 11 21:51:52 2013
New Revision: 1491983
URL: http://svn.apache.org/r1491983
Log:
AMBARI-2356 - API call to get multiple configurations in batch not working
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ResourceImplTest.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java?rev=1491983&r1=1491982&r2=1491983&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java Tue Jun 11 21:51:52 2013
@@ -375,8 +375,16 @@ public class ClusterControllerImpl imple
return propertyProviders.get(type);
}
+ /**
+ * Get the associated resource comparator.
+ *
+ * @return the resource comparator
+ */
+ protected Comparator<Resource> getComparator() {
+ return comparator;
+ }
- // ----- ResourceIterable inner class --------------------------------------
+// ----- ResourceIterable inner class --------------------------------------
private static class ResourceIterable implements Iterable<Resource> {
@@ -491,17 +499,19 @@ public class ClusterControllerImpl imple
// ----- ResourceComparator inner class ------------------------------------
- private class ResourceComparator implements Comparator<Resource> {
+ protected class ResourceComparator implements Comparator<Resource> {
@Override
public int compare(Resource resource1, Resource resource2) {
+ Resource.Type resourceType = resource1.getType();
- int compVal = resource1.getType().compareTo(resource2.getType());
+ // compare based on resource type
+ int compVal = resourceType.compareTo(resource2.getType());
if (compVal == 0) {
+ Schema schema = getSchema(resourceType);
- Schema schema = getSchema(resource1.getType());
-
+ // compare based on resource key properties
for (Resource.Type type : Resource.Type.values()) {
String keyPropertyId = schema.getKeyPropertyId(type);
if (keyPropertyId != null) {
@@ -513,10 +523,12 @@ public class ClusterControllerImpl imple
}
}
}
- return compVal;
+
+ // compare based on the resource strings
+ return resource1.toString().compareTo(resource2.toString());
}
- // compare and account for null values
+ // compare two values and account for null
private int compareValues(Object val1, Object val2) {
if (val1 == null || val2 == null) {
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java?rev=1491983&r1=1491982&r2=1491983&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ResourceImpl.java Tue Jun 11 21:51:52 2013
@@ -131,8 +131,24 @@ public class ResourceImpl implements Res
return sb.toString();
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
- // ----- utility methods ---------------------------------------------------
+ ResourceImpl resource = (ResourceImpl) o;
+
+ return type == resource.type &&
+ !(propertiesMap != null ? !propertiesMap.equals(resource.propertiesMap) : resource.propertiesMap != null);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 31 * type.hashCode() + (propertiesMap != null ? propertiesMap.hashCode() : 0);
+ return result;
+ }
+
+// ----- utility methods ---------------------------------------------------
private String getCategoryKey(String category) {
return category == null ? "" : category;
Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java?rev=1491983&r1=1491982&r2=1491983&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java Tue Jun 11 21:51:52 2013
@@ -27,6 +27,7 @@ import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
@@ -425,39 +426,50 @@ public class ClusterControllerImplTest {
Assert.assertTrue(keyPropertyIds.containsAll(predicatePropertyIds));
}
-// @Test
-// public void testGetSchema() {
-// ProviderModule module = new TestProviderModule();
-//
-// ClusterController controller = new ClusterControllerImpl(module);
-// Schema schema = controller.getSchema(Resource.Type.Host);
-//
-// ResourceProvider resourceProvider = module.getResourceProvider(Resource.Type.Host);
-//
-// Map<Resource.Type, String> keyPropertyIds = resourceProvider.getKeyPropertyIds();
-// for (Map.Entry<Resource.Type, String> entry : keyPropertyIds.entrySet()) {
-// Assert.assertEquals(entry.getValue(), schema.getKeyPropertyId(entry.getKey()));
-// }
-//
-// Map<String, Set<String>> categories = schema.getCategoryProperties();
-// for (String propertyId : resourceProvider.getPropertyIdsForSchema()) {
-// String category = PropertyHelper.getPropertyCategory(propertyId);
-// Set<String> properties = categories.get(category);
-// Assert.assertNotNull(properties);
-// Assert.assertTrue(properties.contains(PropertyHelper.getPropertyName(propertyId)));
-// }
-//
-// List<PropertyProvider> propertyProviders = module.getPropertyProviders(Resource.Type.Host);
-//
-// for (PropertyProvider propertyProvider : propertyProviders) {
-// for (String propertyId : propertyProvider.getPropertyIds()) {
-// String category = PropertyHelper.getPropertyCategory(propertyId);
-// Set<String> properties = categories.get(category);
-// Assert.assertNotNull(properties);
-// Assert.assertTrue(properties.contains(PropertyHelper.getPropertyName(propertyId)));
-// }
-// }
-// }
+ @Test
+ public void testComparator() {
+
+ TestProviderModule providerModule = new TestProviderModule();
+ ClusterControllerImpl controller = new ClusterControllerImpl(providerModule);
+
+ Comparator<Resource> comparator = controller.getComparator();
+
+ Resource resource1 = new ResourceImpl(Resource.Type.Host);
+ Resource resource2 = new ResourceImpl(Resource.Type.Host);
+ Resource resource3 = new ResourceImpl(Resource.Type.Service);
+
+ Assert.assertEquals(0, comparator.compare(resource1, resource2));
+ Assert.assertEquals(0, comparator.compare(resource2, resource1));
+ Assert.assertTrue(comparator.compare(resource1, resource3) < 0);
+ Assert.assertTrue(comparator.compare(resource3, resource1) > 0);
+
+ resource1.setProperty(PropertyHelper.getPropertyId("Hosts", "cluster_name"), "c1");
+ resource1.setProperty(PropertyHelper.getPropertyId("Hosts", "host_name"), "h1");
+
+ resource2.setProperty(PropertyHelper.getPropertyId("Hosts", "cluster_name"), "c1");
+ resource2.setProperty(PropertyHelper.getPropertyId("Hosts", "host_name"), "h1");
+
+ Assert.assertEquals(0, comparator.compare(resource1, resource2));
+ Assert.assertEquals(0, comparator.compare(resource2, resource1));
+
+ resource2.setProperty(PropertyHelper.getPropertyId("Hosts", "host_name"), "h2");
+
+ Assert.assertTrue(comparator.compare(resource1, resource2) < 0);
+ Assert.assertTrue(comparator.compare(resource2, resource1) > 0);
+
+ resource2.setProperty(PropertyHelper.getPropertyId("Hosts", "host_name"), "h1");
+
+ resource1.setProperty("p1", "foo");
+ resource2.setProperty("p1", "foo");
+
+ Assert.assertEquals(0, comparator.compare(resource1, resource2));
+ Assert.assertEquals(0, comparator.compare(resource2, resource1));
+
+ resource2.setProperty("p1", "bar");
+
+ Assert.assertFalse(comparator.compare(resource1, resource2) == 0);
+ Assert.assertFalse(comparator.compare(resource2, resource1) == 0);
+ }
private static class TestProviderModule implements ProviderModule {
private Map<Resource.Type, ResourceProvider> providers = new HashMap<Resource.Type, ResourceProvider>();
Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java?rev=1491983&r1=1491982&r2=1491983&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java Tue Jun 11 21:51:52 2013
@@ -132,14 +132,17 @@ public class RequestResourceProviderTest
AmbariManagementController managementController = createMock(AmbariManagementController.class);
- Set<RequestStatusResponse> allResponse = new HashSet<RequestStatusResponse>();
- allResponse.add(new RequestStatusResponse(100L));
+ Set<RequestStatusResponse> response1 = new HashSet<RequestStatusResponse>();
+ response1.add(new RequestStatusResponse(100L));
+
+ Set<RequestStatusResponse> response2 = new HashSet<RequestStatusResponse>();
+ response2.add(new RequestStatusResponse(101L));
// set expectations
expect(managementController.getRequestStatus(AbstractResourceProviderTest.Matcher.getRequestRequest(100L))).
- andReturn(allResponse).once();
+ andReturn(response1).once();
expect(managementController.getRequestStatus(AbstractResourceProviderTest.Matcher.getRequestRequest(101L))).
- andReturn(allResponse).once();
+ andReturn(response2).once();
// replay
replay(managementController);
Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ResourceImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ResourceImplTest.java?rev=1491983&r1=1491982&r2=1491983&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ResourceImplTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ResourceImplTest.java Tue Jun 11 21:51:52 2013
@@ -160,5 +160,28 @@ public class ResourceImplTest {
}
}
}
+
+ @Test
+ public void testEquals() {
+ Resource resource1 = new ResourceImpl(Resource.Type.Cluster);
+ Resource resource2 = new ResourceImpl(Resource.Type.Cluster);
+ Resource resource3 = new ResourceImpl(Resource.Type.Host);
+
+ Assert.assertTrue(resource1.equals(resource2));
+ Assert.assertTrue(resource2.equals(resource1));
+ Assert.assertFalse(resource1.equals(resource3));
+ Assert.assertFalse(resource3.equals(resource1));
+ Assert.assertFalse(resource2.equals(resource3));
+ Assert.assertFalse(resource3.equals(resource2));
+
+ resource1.setProperty("p1", "foo");
+ resource2.setProperty("p1", "bar");
+ Assert.assertFalse(resource1.equals(resource2));
+ Assert.assertFalse(resource2.equals(resource1));
+
+ resource2.setProperty("p1", "foo");
+ Assert.assertTrue(resource1.equals(resource2));
+ Assert.assertTrue(resource2.equals(resource1));
+ }
}
Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java?rev=1491983&r1=1491982&r2=1491983&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/jmx/JMXPropertyProviderTest.java Tue Jun 11 21:51:52 2013
@@ -319,6 +319,7 @@ public class JMXPropertyProviderTest {
resource.setProperty(HOST_COMPONENT_HOST_NAME_PROPERTY_ID, "domu-12-31-39-14-ee-b3.compute-1.internal");
resource.setProperty(HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID, "DATANODE");
+ resource.setProperty("unique_id", i);
resources.add(resource);
}