ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject git commit: AMBARI-4965. GET call on Master service components takes too long. (swagle)
Date Wed, 05 Mar 2014 23:33:03 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 5fca4800d -> 1ff7f5731


AMBARI-4965. GET call on Master service components takes too long. (swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1ff7f573
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1ff7f573
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1ff7f573

Branch: refs/heads/trunk
Commit: 1ff7f5731c5bb385f6fa55de91ff4e03a78737c9
Parents: 5fca480
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Wed Mar 5 13:54:12 2014 -0800
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Wed Mar 5 13:54:34 2014 -0800

----------------------------------------------------------------------
 .../controller/ServiceComponentRequest.java     | 21 ++++++++++++-
 .../internal/ComponentResourceProvider.java     | 12 ++++++--
 .../apache/ambari/server/utils/DateUtils.java   | 13 --------
 .../internal/ComponentResourceProviderTest.java | 32 +++++++++++++-------
 4 files changed, 51 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1ff7f573/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentRequest.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentRequest.java
index 23e5949..63af85e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentRequest.java
@@ -29,14 +29,25 @@ public class ServiceComponentRequest {
 
   private String desiredState; // CREATE/UPDATE
 
+  private String componentCategory;
+
+  public ServiceComponentRequest(String clusterName, String serviceName,
+                                 String componentName, String desiredState) {
+    this.clusterName = clusterName;
+    this.serviceName = serviceName;
+    this.componentName = componentName;
+    this.desiredState = desiredState;
+  }
+
   public ServiceComponentRequest(String clusterName,
                                  String serviceName, String componentName,
-                                 String desiredState) {
+                                 String desiredState, String componentCategory) {
     super();
     this.clusterName = clusterName;
     this.serviceName = serviceName;
     this.componentName = componentName;
     this.desiredState = desiredState;
+    this.componentCategory = componentCategory;
   }
 
   /**
@@ -94,4 +105,12 @@ public class ServiceComponentRequest {
   public void setClusterName(String clusterName) {
     this.clusterName = clusterName;
   }
+
+  public String getComponentCategory() {
+    return componentCategory;
+  }
+
+  public void setComponentCategory(String componentCategory) {
+    this.componentCategory = componentCategory;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1ff7f573/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
index 37bb0de..59a52e5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
@@ -230,7 +230,8 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide
         (String) properties.get(COMPONENT_CLUSTER_NAME_PROPERTY_ID),
         (String) properties.get(COMPONENT_SERVICE_NAME_PROPERTY_ID),
         (String) properties.get(COMPONENT_COMPONENT_NAME_PROPERTY_ID),
-        (String) properties.get(COMPONENT_STATE_PROPERTY_ID));
+        (String) properties.get(COMPONENT_STATE_PROPERTY_ID),
+        (String) properties.get(COMPONENT_CATEGORY_PROPERTY_ID));
   }
 
   // Create the components for the given requests.
@@ -453,7 +454,7 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide
 
     Set<ServiceComponentResponse> response =
         new HashSet<ServiceComponentResponse>();
-    String category;
+    String category = null;
 
     StackId stackId = cluster.getDesiredStackVersion();
 
@@ -536,12 +537,19 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide
         ComponentInfo componentInfo = ambariMetaInfo.getComponentCategory(stackId.getStackName(),
             stackId.getStackVersion(), s.getName(), sc.getName());
         ServiceComponentResponse serviceComponentResponse = sc.convertToResponse();
+
+        String requestedCategory = request.getComponentCategory();
         if (componentInfo != null) {
           category = componentInfo.getCategory();
           if (category != null) {
             serviceComponentResponse.setCategory(category);
           }
         }
+        if (requestedCategory != null && !requestedCategory.isEmpty() &&
+            category != null && !requestedCategory.equalsIgnoreCase(category)) {
+          continue;
+        }
+
         response.add(serviceComponentResponse);
       }
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1ff7f573/ambari-server/src/main/java/org/apache/ambari/server/utils/DateUtils.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/utils/DateUtils.java b/ambari-server/src/main/java/org/apache/ambari/server/utils/DateUtils.java
index aeceedf..785f4fd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/utils/DateUtils.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/utils/DateUtils.java
@@ -94,17 +94,4 @@ public class DateUtils {
     Date now = new Date();
     return time.after(now);
   }
-
-  public static void main(String[] args) {
-    String s = "INSERT INTO ambari_sequences(sequence_name, \"value\") " +
-      "SELECT 'cluster_id_seq', nextval('clusters_cluster_id_seq') " +
-      "UNION ALL " +
-      "SELECT 'user_id_seq', nextval('users_user_id_seq') " +
-      "UNION ALL " +
-      "SELECT 'host_role_command_id_seq', COALESCE((SELECT max(task_id) FROM host_role_command),
1) + 50 " +
-      "UNION ALL " +
-      "SELECT 'configgroup_id_seq', 1";
-
-    System.out.println(s);
-  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1ff7f573/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
index 4c48db5..2cc1165 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
@@ -68,6 +68,8 @@ import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
 import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -153,8 +155,8 @@ public class ComponentResourceProviderTest {
     ServiceComponent serviceComponent2 = createNiceMock(ServiceComponent.class);
     ServiceComponent serviceComponent3 = createNiceMock(ServiceComponent.class);
     StackId stackId = createNiceMock(StackId.class);
-    ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
-
+    final ComponentInfo componentInfo1 = createNiceMock(ComponentInfo.class);
+    final ComponentInfo componentInfo2 = createNiceMock(ComponentInfo.class);
 
     Map<String, ServiceComponent> serviceComponentMap = new HashMap<String, ServiceComponent>();
     serviceComponentMap.put("Component101", serviceComponent1);
@@ -175,15 +177,17 @@ public class ComponentResourceProviderTest {
     expect(serviceComponent2.convertToResponse()).andReturn(new ServiceComponentResponse(100L,
"Cluster100", "Service100", "Component101", null, ""));
     expect(serviceComponent3.convertToResponse()).andReturn(new ServiceComponentResponse(100L,
"Cluster100", "Service100", "Component102", null, ""));
 
+    expect(ambariMetaInfo.getComponentCategory((String) anyObject(),
+      (String) anyObject(), (String) anyObject(), (String) anyObject()))
+        .andReturn(componentInfo1).times(2).andReturn(componentInfo2);
 
-    expect(ambariMetaInfo.getComponentCategory((String) anyObject(), (String) anyObject(),
-        (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes();
-
-    expect(componentInfo.getCategory()).andReturn("MASTER").anyTimes();
+    expect(componentInfo1.getCategory()).andReturn("MASTER").anyTimes();
+    expect(componentInfo2.getCategory()).andReturn("SLAVE").anyTimes();
 
     // replay
     replay(managementController, clusters, cluster, ambariMetaInfo, service,
-        serviceComponent1, serviceComponent2, serviceComponent3, stackId, componentInfo);
+      serviceComponent1, serviceComponent2, serviceComponent3, stackId,
+      componentInfo1, componentInfo2);
 
     ResourceProvider provider = new ComponentResourceProvider(
         PropertyHelper.getPropertyIds(type),
@@ -196,12 +200,17 @@ public class ComponentResourceProviderTest {
     propertyIds.add(ComponentResourceProvider.COMPONENT_COMPONENT_NAME_PROPERTY_ID);
     propertyIds.add(ComponentResourceProvider.COMPONENT_CATEGORY_PROPERTY_ID);
 
-    Predicate predicate = new PredicateBuilder().property(ComponentResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID).
-        equals("Cluster100").toPredicate();
+    Predicate predicate = new PredicateBuilder()
+      .property(ComponentResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID)
+      .equals("Cluster100")
+      .and()
+      .property(ComponentResourceProvider.COMPONENT_CATEGORY_PROPERTY_ID)
+      .equals("MASTER").toPredicate();
+
     Request request = PropertyHelper.getReadRequest(propertyIds);
     Set<Resource> resources = provider.getResources(request, predicate);
 
-    Assert.assertEquals(3, resources.size());
+    Assert.assertEquals(2, resources.size());
     for (Resource resource : resources) {
       String clusterName = (String) resource.getPropertyValue(
           ComponentResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID);
@@ -212,7 +221,8 @@ public class ComponentResourceProviderTest {
 
     // verify
     verify(managementController, clusters, cluster, ambariMetaInfo, service,
-        serviceComponent1, serviceComponent2, serviceComponent3, stackId, componentInfo);
+      serviceComponent1, serviceComponent2, serviceComponent3, stackId,
+      componentInfo1, componentInfo2);
   }
 
   @Test


Mime
View raw message