ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject ambari git commit: AMBARI-8539. Upgrade Execute: tie stage information more closely with UpgradeItem (ncole)
Date Sat, 06 Dec 2014 22:15:11 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 8eb500e60 -> e7c512c2c


AMBARI-8539. Upgrade Execute: tie stage information more closely with UpgradeItem (ncole)


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

Branch: refs/heads/trunk
Commit: e7c512c2c45256ef7cb5a26bc1b7282be0574c20
Parents: 8eb500e
Author: Nate Cole <ncole@hortonworks.com>
Authored: Fri Dec 5 08:09:39 2014 -0800
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Sat Dec 6 16:47:04 2014 -0500

----------------------------------------------------------------------
 .../resources/ResourceInstanceFactoryImpl.java  |   2 +-
 .../api/services/UpgradeGroupService.java       |   2 +-
 .../server/api/services/UpgradeItemService.java |  13 +-
 .../server/api/services/UpgradeService.java     |   1 +
 .../internal/RequestResourceProvider.java       |  44 +++-
 .../internal/StageResourceProvider.java         |   3 +-
 .../internal/UpgradeGroupResourceProvider.java  |  87 ++++++--
 .../internal/UpgradeItemResourceProvider.java   | 213 ++++++++-----------
 .../internal/UpgradeResourceProvider.java       |  36 +++-
 .../ambari/server/orm/dao/UpgradeDAO.java       |  49 ++++-
 .../ambari/server/state/UpgradeHelper.java      | 101 +++++++++
 .../internal/UpgradeResourceProviderTest.java   | 110 +++++++++-
 12 files changed, 484 insertions(+), 177 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e7c512c2/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
index b5fe94e..a353be6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
@@ -331,7 +331,7 @@ public class ResourceInstanceFactoryImpl implements ResourceInstanceFactory {
 
       case UpgradeItem:
         resourceDefinition = new SimpleResourceDefinition(
-            Resource.Type.UpgradeItem, "upgrade_item", "upgrade_items");
+            Resource.Type.UpgradeItem, "upgrade_item", "upgrade_items", Resource.Type.Task);
         break;
 
       case Stage:

http://git-wip-us.apache.org/repos/asf/ambari/blob/e7c512c2/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeGroupService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeGroupService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeGroupService.java
index da21658..ed97d66 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeGroupService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeGroupService.java
@@ -21,7 +21,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
@@ -82,6 +81,7 @@ public class UpgradeGroupService extends BaseService {
     Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
     mapIds.put(Resource.Type.Cluster, m_clusterName);
     mapIds.put(Resource.Type.Upgrade, m_upgradeId);
+    mapIds.put(Resource.Type.Request, m_upgradeId);
 
     if (null != groupId) {
       mapIds.put(Resource.Type.UpgradeGroup, groupId.toString());

http://git-wip-us.apache.org/repos/asf/ambari/blob/e7c512c2/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeItemService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeItemService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeItemService.java
index fb77853..a8a7640 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeItemService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeItemService.java
@@ -67,14 +67,12 @@ public class UpgradeItemService extends BaseService {
         createResourceInstance(id));
   }
 
-  @PUT
-  @Path("{upgradeItemId}")
-  @Produces("text/plain")
-  public Response updateUpgradeItem(String body,
+  @Path("{upgradeItemId}/tasks")
+  public TaskService getTasks(
       @Context HttpHeaders headers,
-      @Context UriInfo ui, @PathParam("upgradeItemId") Long id) {
-    return handleRequest(headers, body, ui, Request.Type.PUT,
-        createResourceInstance(id));
+      @Context UriInfo ui,
+      @PathParam("upgradeItemId") Long id) {
+    return new TaskService(m_clusterName, m_upgradeId, m_upgradeId.toString());
   }
 
   /**
@@ -86,6 +84,7 @@ public class UpgradeItemService extends BaseService {
     mapIds.put(Resource.Type.Cluster, m_clusterName);
     mapIds.put(Resource.Type.Upgrade, m_upgradeId);
     mapIds.put(Resource.Type.UpgradeGroup, m_upgradeGroupId);
+    mapIds.put(Resource.Type.Request, m_upgradeId);
 
     if (null != upgradeItemId) {
       mapIds.put(Resource.Type.UpgradeItem, upgradeItemId.toString());

http://git-wip-us.apache.org/repos/asf/ambari/blob/e7c512c2/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeService.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeService.java
index 8b66491..ddba2ff 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/UpgradeService.java
@@ -108,6 +108,7 @@ public class UpgradeService extends BaseService {
 
     if (null != upgradeId) {
       mapIds.put(Resource.Type.Upgrade, upgradeId.toString());
+      mapIds.put(Resource.Type.Request, upgradeId.toString());
     }
 
     return createResource(Resource.Type.Upgrade, mapIds);

http://git-wip-us.apache.org/repos/asf/ambari/blob/e7c512c2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
index 561f5d9..549a20d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
@@ -55,8 +55,8 @@ public class RequestResourceProvider extends AbstractControllerResourceProvider
 
   // ----- Property ID constants ---------------------------------------------
   // Requests
-  protected static final String REQUEST_CLUSTER_NAME_PROPERTY_ID = "Requests/cluster_name";
-  protected static final String REQUEST_ID_PROPERTY_ID = "Requests/id";
+  public static final String REQUEST_CLUSTER_NAME_PROPERTY_ID = "Requests/cluster_name";
+  public static final String REQUEST_ID_PROPERTY_ID = "Requests/id";
   protected static final String REQUEST_STATUS_PROPERTY_ID = "Requests/request_status";
   protected static final String REQUEST_ABORT_REASON_PROPERTY_ID = "Requests/abort_reason";
   protected static final String REQUEST_CONTEXT_ID = "Requests/request_context";
@@ -89,6 +89,32 @@ public class RequestResourceProvider extends AbstractControllerResourceProvider
       new HashSet<String>(Arrays.asList(new String[]{
           REQUEST_ID_PROPERTY_ID}));
 
+  static Set<String> PROPERTY_IDS = new HashSet<String>();
+
+  static {
+    PROPERTY_IDS.add(REQUEST_CLUSTER_NAME_PROPERTY_ID);
+    PROPERTY_IDS.add(REQUEST_STATUS_PROPERTY_ID);
+    PROPERTY_IDS.add(REQUEST_ABORT_REASON_PROPERTY_ID);
+    PROPERTY_IDS.add(REQUEST_CONTEXT_ID);
+    PROPERTY_IDS.add(REQUEST_SOURCE_SCHEDULE);
+    PROPERTY_IDS.add(REQUEST_SOURCE_SCHEDULE_ID);
+    PROPERTY_IDS.add(REQUEST_SOURCE_SCHEDULE_HREF);
+    PROPERTY_IDS.add(REQUEST_TYPE_ID);
+    PROPERTY_IDS.add(REQUEST_INPUTS_ID);
+    PROPERTY_IDS.add(REQUEST_RESOURCE_FILTER_ID);
+    PROPERTY_IDS.add(REQUEST_OPERATION_LEVEL_ID);
+    PROPERTY_IDS.add(REQUEST_CREATE_TIME_ID);
+    PROPERTY_IDS.add(REQUEST_START_TIME_ID);
+    PROPERTY_IDS.add(REQUEST_END_TIME_ID);
+    PROPERTY_IDS.add(REQUEST_EXCLUSIVE_ID);
+    PROPERTY_IDS.add(REQUEST_TASK_CNT_ID);
+    PROPERTY_IDS.add(REQUEST_FAILED_TASK_CNT_ID);
+    PROPERTY_IDS.add(REQUEST_ABORTED_TASK_CNT_ID);
+    PROPERTY_IDS.add(REQUEST_TIMED_OUT_TASK_CNT_ID);
+    PROPERTY_IDS.add(REQUEST_COMPLETED_TASK_CNT_ID);
+    PROPERTY_IDS.add(REQUEST_QUEUED_TASK_CNT_ID);
+    PROPERTY_IDS.add(REQUEST_PROGRESS_PERCENT_ID);
+  }
 
   // ----- Constructors ----------------------------------------------------
 
@@ -137,29 +163,29 @@ public class RequestResourceProvider extends AbstractControllerResourceProvider
     Boolean ascOrder = (ascOrderRaw == null ? null : Boolean.parseBoolean(ascOrderRaw));
 
     Set<Map<String, Object>> propertyMaps = new HashSet<Map<String,Object>>();
-    
+
     if (null == predicate) {
       resources.addAll(
           getRequestResources(null, null, null, maxResults, ascOrder, requestedIds));
     } else {
       for (Map<String, Object> properties : getPropertyMaps(predicate)) {
         String clusterName = (String) properties.get(REQUEST_CLUSTER_NAME_PROPERTY_ID);
-  
+
         Long requestId = null;
         if (properties.get(REQUEST_ID_PROPERTY_ID) != null) {
           requestId = Long.valueOf((String) properties.get(REQUEST_ID_PROPERTY_ID));
         }
-  
+
         String requestStatus = null;
         if (properties.get(REQUEST_STATUS_PROPERTY_ID) != null) {
           requestStatus = (String) properties.get(REQUEST_STATUS_PROPERTY_ID);
         }
-  
+
         resources.addAll(getRequestResources(clusterName, requestId, requestStatus, maxResults,
             ascOrder, requestedIds));
       }
     }
-    
+
     return resources;
   }
 
@@ -445,7 +471,7 @@ public class RequestResourceProvider extends AbstractControllerResourceProvider
     double progressPercent =
             ((hostRoleStatusCounters.get(HostRoleStatus.QUEUED) * 0.09 +
                     hostRoleStatusCounters.get(HostRoleStatus.IN_PROGRESS) * 0.35 +
-                    hostRoleStatusCounters.get(HostRoleStatus.COMPLETED)) / (double) taskCount) * 100.0;
+                    hostRoleStatusCounters.get(HostRoleStatus.COMPLETED)) / taskCount) * 100.0;
 
     setResourceProperty(resource, REQUEST_STATUS_PROPERTY_ID, requestStatus.toString(), requestedPropertyIds);
     setResourceProperty(resource, REQUEST_TASK_CNT_ID, taskCount, requestedPropertyIds);
@@ -500,7 +526,7 @@ public class RequestResourceProvider extends AbstractControllerResourceProvider
    * @return summary request status based on statuses of tasks in different
    * states.
    */
-  private HostRoleStatus calculateSummaryStatus(Map<HostRoleStatus, Integer> counters, int totalTasks) {
+  static HostRoleStatus calculateSummaryStatus(Map<HostRoleStatus, Integer> counters, int totalTasks) {
     return counters.get(HostRoleStatus.FAILED) > 0 ? HostRoleStatus.FAILED :
             // TODO (dlysnichenko): maybe change order of FAILED and ABORTED?
             counters.get(HostRoleStatus.ABORTED) > 0 ? HostRoleStatus.ABORTED :

http://git-wip-us.apache.org/repos/asf/ambari/blob/e7c512c2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
index 27ce015..c25152d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
@@ -85,7 +85,7 @@ public class StageResourceProvider extends AbstractResourceProvider implements E
   /**
    * The property ids for a stage resource.
    */
-  private static final Set<String> PROPERTY_IDS = new HashSet<String>();
+  static final Set<String> PROPERTY_IDS = new HashSet<String>();
 
   /**
    * The key property ids for a stage resource.
@@ -124,7 +124,6 @@ public class StageResourceProvider extends AbstractResourceProvider implements E
     super(PROPERTY_IDS, KEY_PROPERTY_IDS);
   }
 
-
   // ----- AbstractResourceProvider ------------------------------------------
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/e7c512c2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeGroupResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeGroupResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeGroupResourceProvider.java
index b7eb240..46dcd1e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeGroupResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeGroupResourceProvider.java
@@ -17,7 +17,9 @@
  */
 package org.apache.ambari.server.controller.internal;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -25,7 +27,6 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.StaticallyInject;
-import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
@@ -41,7 +42,7 @@ import org.apache.ambari.server.orm.dao.UpgradeDAO;
 import org.apache.ambari.server.orm.entities.UpgradeEntity;
 import org.apache.ambari.server.orm.entities.UpgradeGroupEntity;
 import org.apache.ambari.server.orm.entities.UpgradeItemEntity;
-import org.apache.ambari.server.state.UpgradeState;
+import org.apache.ambari.server.state.UpgradeHelper;
 
 import com.google.inject.Inject;
 
@@ -51,14 +52,16 @@ import com.google.inject.Inject;
 @StaticallyInject
 public class UpgradeGroupResourceProvider extends AbstractControllerResourceProvider {
 
-  protected static final String UPGRADE_ID = "UpgradeGroup/upgrade_id";
+  protected static final String UPGRADE_REQUEST_ID = "UpgradeGroup/request_id";
   protected static final String UPGRADE_GROUP_ID = "UpgradeGroup/group_id";
+  protected static final String UPGRADE_CLUSTER_NAME = "UpgradeGroup/cluster_name";
   protected static final String UPGRADE_GROUP_NAME = "UpgradeGroup/name";
   protected static final String UPGRADE_GROUP_TITLE = "UpgradeGroup/title";
-  protected static final String UPGRADE_GROUP_STATE = "UpgradeGroup/state";
+  protected static final String UPGRADE_GROUP_PROGRESS_PERCENT = "UpgradeGroup/progress_percent";
+  protected static final String UPGRADE_GROUP_STATUS = "UpgradeGroup/status";
 
   private static final Set<String> PK_PROPERTY_IDS = new HashSet<String>(
-      Arrays.asList(UPGRADE_ID, UPGRADE_GROUP_ID));
+      Arrays.asList(UPGRADE_REQUEST_ID, UPGRADE_GROUP_ID));
   private static final Set<String> PROPERTY_IDS = new HashSet<String>();
 
   private static final Map<Resource.Type, String> KEY_PROPERTY_IDS = new HashMap<Resource.Type, String>();
@@ -68,14 +71,16 @@ public class UpgradeGroupResourceProvider extends AbstractControllerResourceProv
 
   static {
     // properties
-    PROPERTY_IDS.add(UPGRADE_ID);
+    PROPERTY_IDS.add(UPGRADE_REQUEST_ID);
     PROPERTY_IDS.add(UPGRADE_GROUP_ID);
     PROPERTY_IDS.add(UPGRADE_GROUP_NAME);
     PROPERTY_IDS.add(UPGRADE_GROUP_TITLE);
+    PROPERTY_IDS.add(UPGRADE_GROUP_PROGRESS_PERCENT);
+    PROPERTY_IDS.add(UPGRADE_GROUP_STATUS);
 
     // keys
     KEY_PROPERTY_IDS.put(Resource.Type.UpgradeGroup, UPGRADE_GROUP_ID);
-    KEY_PROPERTY_IDS.put(Resource.Type.Upgrade, UPGRADE_ID);
+    KEY_PROPERTY_IDS.put(Resource.Type.Upgrade, UPGRADE_REQUEST_ID);
   }
 
   /**
@@ -104,19 +109,33 @@ public class UpgradeGroupResourceProvider extends AbstractControllerResourceProv
     Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate);
 
     for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
-      String upgradeIdStr = (String) propertyMap.get(UPGRADE_ID);
+      String upgradeIdStr = (String) propertyMap.get(UPGRADE_REQUEST_ID);
+      String clusterName = (String) propertyMap.get(UPGRADE_CLUSTER_NAME);
 
       if (null == upgradeIdStr || upgradeIdStr.isEmpty()) {
         throw new IllegalArgumentException("The upgrade id is required when querying for upgrades");
       }
 
-      long upgradeId = Long.parseLong(upgradeIdStr);
-      UpgradeEntity upgrade = m_dao.findUpgrade(upgradeId);
+      Long upgradeId = Long.valueOf(upgradeIdStr);
+      UpgradeEntity upgrade = m_dao.findUpgradeByRequestId(upgradeId);
 
       List<UpgradeGroupEntity> groups = upgrade.getUpgradeGroups();
       if (null != groups) {
+        UpgradeHelper helper = new UpgradeHelper();
+
         for (UpgradeGroupEntity group : upgrade.getUpgradeGroups()) {
-          results.add(toResource(upgrade, group, requestPropertyIds));
+          Resource r = toResource(upgrade, group, requestPropertyIds);
+
+          List<Long> stageIds = new ArrayList<Long>();
+          for (UpgradeItemEntity itemEntity : group.getItems()) {
+            stageIds.add(itemEntity.getStageId());
+          }
+
+          Set<Resource> stages = helper.getStageResources(clusterName, upgrade.getRequestId(), stageIds);
+
+          aggregate(r, stages, requestPropertyIds);
+
+          results.add(r);
         }
       }
 
@@ -149,13 +168,55 @@ public class UpgradeGroupResourceProvider extends AbstractControllerResourceProv
   private Resource toResource(UpgradeEntity upgrade, UpgradeGroupEntity group, Set<String> requestedIds) {
     ResourceImpl resource = new ResourceImpl(Resource.Type.UpgradeGroup);
 
-    setResourceProperty(resource, UPGRADE_ID, upgrade.getId(), requestedIds);
+    setResourceProperty(resource, UPGRADE_REQUEST_ID, upgrade.getRequestId(), requestedIds);
     setResourceProperty(resource, UPGRADE_GROUP_ID, group.getId(), requestedIds);
     setResourceProperty(resource, UPGRADE_GROUP_NAME, group.getName(), requestedIds);
     setResourceProperty(resource, UPGRADE_GROUP_TITLE, group.getTitle(), requestedIds);
-    setResourceProperty(resource, UPGRADE_GROUP_STATE, "NONE", requestedIds);
 
     return resource;
   }
 
+
+  /**
+   * Aggregates status and percent complete for stages and puts the results on the upgrade group
+   *
+   * @param upgradeGroup the resource representing an upgrade group
+   * @param stages the collection of resources representing stages
+   * @param requestedIds the ids for the request
+   */
+  private void aggregate(Resource upgradeGroup, Collection<Resource> stages, Set<String> requestedIds) {
+
+    Double total = new Double(0d);
+    Integer count = new Integer(0);
+
+    Map<HostRoleStatus, Integer> counters = new HashMap<HostRoleStatus, Integer>();
+    for (HostRoleStatus hostRoleStatus : HostRoleStatus.values()) {
+      counters.put(hostRoleStatus, new Integer(0));
+    }
+
+
+    for (Resource stage : stages) {
+      String status = (String) stage.getPropertyValue(StageResourceProvider.STAGE_STATUS);
+      Double percent = (Double) stage.getPropertyValue(StageResourceProvider.STAGE_PROGRESS_PERCENT);
+
+      if (null != percent) {
+        total += percent;
+        count++;
+      }
+
+      if (null != status) {
+        HostRoleStatus hrs = HostRoleStatus.valueOf(status);
+        counters.put(hrs, counters.get(hrs) + 1);
+      }
+    }
+
+    if (count > 0) {
+      setResourceProperty(upgradeGroup, UPGRADE_GROUP_PROGRESS_PERCENT, total/count, requestedIds);
+    }
+
+    HostRoleStatus summary = RequestResourceProvider.calculateSummaryStatus(counters, counters.size());
+    setResourceProperty(upgradeGroup, UPGRADE_GROUP_STATUS, summary, requestedIds);
+
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/e7c512c2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
index c481dae..85d2c9a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.server.controller.internal;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -24,63 +25,65 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.StaticallyInject;
-import org.apache.ambari.server.actionmanager.HostRoleCommand;
-import org.apache.ambari.server.actionmanager.HostRoleStatus;
-import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
 import org.apache.ambari.server.controller.spi.NoSuchResourceException;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Request;
-import org.apache.ambari.server.controller.spi.RequestStatus;
 import org.apache.ambari.server.controller.spi.Resource;
-import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
 import org.apache.ambari.server.orm.dao.UpgradeDAO;
 import org.apache.ambari.server.orm.entities.UpgradeEntity;
 import org.apache.ambari.server.orm.entities.UpgradeGroupEntity;
 import org.apache.ambari.server.orm.entities.UpgradeItemEntity;
-import org.apache.ambari.server.state.UpgradeState;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.UpgradeHelper;
 
 import com.google.inject.Inject;
-import com.google.inject.Provider;
 
 /**
- * Manages the ability to start and get status of upgrades.
+ * Manages the ability to get the status of upgrades.
  */
 @StaticallyInject
-public class UpgradeItemResourceProvider extends AbstractControllerResourceProvider {
+public class UpgradeItemResourceProvider extends ReadOnlyResourceProvider {
 
-  protected static final String UPGRADE_ID = "UpgradeItem/upgrade_id";
+  protected static final String UPGRADE_CLUSTER_NAME = "UpgradeItem/cluster_name";
+  protected static final String UPGRADE_REQUEST_ID = "UpgradeItem/request_id";
   protected static final String UPGRADE_GROUP_ID = "UpgradeItem/group_id";
-  protected static final String UPGRADE_ITEM_ID = "UpgradeItem/id";
-  protected static final String UPGRADE_ITEM_STATE = "UpgradeItem/state";
-  protected static final String UPGRADE_ITEM_TEXT = "UpgradeItem/text";
-  protected static final String UPGRADE_ITEM_STAGE_ID= "UpgradeItem/stage_id";
+  protected static final String UPGRADE_ITEM_STAGE_ID = "UpgradeItem/stage_id";
 
   private static final Set<String> PK_PROPERTY_IDS = new HashSet<String>(
-      Arrays.asList(UPGRADE_ID, UPGRADE_ITEM_ID));
+      Arrays.asList(UPGRADE_REQUEST_ID, UPGRADE_ITEM_STAGE_ID));
   private static final Set<String> PROPERTY_IDS = new HashSet<String>();
 
   private static final Map<Resource.Type, String> KEY_PROPERTY_IDS = new HashMap<Resource.Type, String>();
+  private static Map<String, String> STAGE_MAPPED_IDS = new HashMap<String, String>();
 
   @Inject
   private static UpgradeDAO m_dao = null;
 
+
   static {
     // properties
-    PROPERTY_IDS.add(UPGRADE_ID);
+    PROPERTY_IDS.add(UPGRADE_ITEM_STAGE_ID);
     PROPERTY_IDS.add(UPGRADE_GROUP_ID);
-    PROPERTY_IDS.add(UPGRADE_ITEM_ID);
-    PROPERTY_IDS.add(UPGRADE_ITEM_STATE);
-    PROPERTY_IDS.add(UPGRADE_ITEM_TEXT);
+    PROPERTY_IDS.add(UPGRADE_REQUEST_ID);
+
+    // !!! boo
+    for (String p : StageResourceProvider.PROPERTY_IDS) {
+      STAGE_MAPPED_IDS.put(p, p.replace("Stage/", "UpgradeItem/"));
+    }
+    PROPERTY_IDS.addAll(STAGE_MAPPED_IDS.values());
 
     // keys
-    KEY_PROPERTY_IDS.put(Resource.Type.UpgradeItem, UPGRADE_ITEM_ID);
+    KEY_PROPERTY_IDS.put(Resource.Type.UpgradeItem, UPGRADE_ITEM_STAGE_ID);
     KEY_PROPERTY_IDS.put(Resource.Type.UpgradeGroup, UPGRADE_GROUP_ID);
-    KEY_PROPERTY_IDS.put(Resource.Type.Upgrade, UPGRADE_ID);
+    KEY_PROPERTY_IDS.put(Resource.Type.Upgrade, UPGRADE_REQUEST_ID);
+    KEY_PROPERTY_IDS.put(Resource.Type.Cluster, UPGRADE_CLUSTER_NAME);
   }
 
   /**
@@ -93,14 +96,6 @@ public class UpgradeItemResourceProvider extends AbstractControllerResourceProvi
   }
 
   @Override
-  public RequestStatus createResources(final Request request)
-      throws SystemException,
-      UnsupportedPropertyException, ResourceAlreadyExistsException,
-      NoSuchParentResourceException {
-    throw new SystemException("Upgrade Items can only be created with an upgrade");
-  }
-
-  @Override
   public Set<Resource> getResources(Request request, Predicate predicate)
       throws SystemException, UnsupportedPropertyException,
       NoSuchResourceException, NoSuchParentResourceException {
@@ -109,127 +104,103 @@ public class UpgradeItemResourceProvider extends AbstractControllerResourceProvi
     Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate);
 
     for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
-      String upgradeIdStr = (String) propertyMap.get(UPGRADE_ID);
+      String clusterName = (String) propertyMap.get(UPGRADE_CLUSTER_NAME);
+      String requestIdStr = (String) propertyMap.get(UPGRADE_REQUEST_ID);
       String groupIdStr = (String) propertyMap.get(UPGRADE_GROUP_ID);
+      String stageIdStr = (String) propertyMap.get(UPGRADE_ITEM_STAGE_ID);
 
-      if (null == upgradeIdStr || upgradeIdStr.isEmpty()) {
+      if (null == requestIdStr || requestIdStr.isEmpty()) {
         throw new IllegalArgumentException("The upgrade id is required when querying for upgrades");
       }
 
       if (null == groupIdStr || groupIdStr.isEmpty()) {
-        throw new IllegalArgumentException("The upgrade id is required when querying for upgrades");
+        throw new IllegalArgumentException("The upgrade group id is required when querying for upgrades");
       }
 
+      Long requestId = Long.valueOf(requestIdStr);
+      Long groupId = Long.valueOf(groupIdStr);
+      Long stageId = null;
+      if (null != stageIdStr) {
+        stageId = Long.valueOf(stageIdStr);
+      }
+
+      List<UpgradeItemEntity> entities = new ArrayList<UpgradeItemEntity>();
+      if (null == stageId) {
+        UpgradeGroupEntity group = m_dao.findUpgradeGroup(groupId);
+
+        if (null == group || null == group.getItems()) {
+          throw new NoSuchResourceException(String.format("Cannot load upgrade for %s", requestIdStr));
+        }
 
-      long upgradeId = Long.parseLong(upgradeIdStr);
-      long groupId = Long.parseLong(groupIdStr);
-      UpgradeGroupEntity group = m_dao.findUpgradeGroup(groupId);
+        entities = group.getItems();
 
-      if (null == group || null == group.getItems()) {
-        throw new NoSuchResourceException(String.format("Cannot load upgrade for %s", upgradeIdStr));
+      } else {
+        UpgradeItemEntity entity = m_dao.findUpgradeItemByRequestAndStage(requestId, stageId);
+        if (null != entity) {
+          entities.add(entity);
+        }
       }
 
-      for (UpgradeItemEntity entity : group.getItems()) {
-        results.add(toResource(group.getUpgradeEntity(), entity, requestPropertyIds));
+      // !!! need to do some lookup for stages, so use a stageid -> resource for
+      // when that happens
+      Map<Long, Resource> resultMap = new HashMap<Long, Resource>();
+
+      for (UpgradeItemEntity entity : entities) {
+        Resource r = toResource(entity, requestPropertyIds);
+        resultMap.put(entity.getStageId(), r);
       }
-    }
 
-    return results;
-  }
+      if (null != clusterName) {
+        UpgradeHelper helper = new UpgradeHelper();
 
-  @Override
-  public RequestStatus updateResources(final Request request,
-      Predicate predicate)
-      throws SystemException, UnsupportedPropertyException,
-      NoSuchResourceException, NoSuchParentResourceException {
+        Set<Resource> stages = helper.getStageResources(clusterName, requestId,
+            new ArrayList<Long>(resultMap.keySet()));
+
+        for (Resource stage : stages) {
+          Long l = (Long) stage.getPropertyValue(StageResourceProvider.STAGE_STAGE_ID);
+
+          Resource r = resultMap.get(l);
+          if (null != r) {
+            for (String propertyId : StageResourceProvider.PROPERTY_IDS) {
+              setResourceProperty(r, STAGE_MAPPED_IDS.get(propertyId),
+                stage.getPropertyValue(propertyId), requestPropertyIds);
+            }
+          }
+        }
+      }
+
+      results.addAll(resultMap.values());
 
-    throw new SystemException("Upgrade Items cannot be modified at this time");
+    }
+    return results;
   }
 
-  @Override
-  public RequestStatus deleteResources(Predicate predicate)
-      throws SystemException, UnsupportedPropertyException,
-      NoSuchResourceException, NoSuchParentResourceException {
-    throw new SystemException("Cannot delete upgrade items");
+  private Cluster getCluster(Long clusterId) throws SystemException {
+    Clusters clusters = getManagementController().getClusters();
+    try {
+      return clusters.getClusterById(clusterId.longValue());
+    } catch (AmbariException e) {
+      throw new SystemException("Cannot load cluster for upgrade items");
+    }
   }
 
+
   @Override
   protected Set<String> getPKPropertyIds() {
     return PK_PROPERTY_IDS;
   }
 
-  private Resource toResource(UpgradeEntity upgrade, UpgradeItemEntity item, Set<String> requestedIds) {
+  private Resource toResource(UpgradeItemEntity item, Set<String> requestedIds) {
     ResourceImpl resource = new ResourceImpl(Resource.Type.UpgradeItem);
 
-    setResourceProperty(resource, UPGRADE_ID, upgrade.getId(), requestedIds);
-    setResourceProperty(resource, UPGRADE_GROUP_ID, item.getGroupEntity().getId(), requestedIds);
-    setResourceProperty(resource, UPGRADE_ITEM_ID, item.getId(), requestedIds);
-    if (isPropertyRequested(UPGRADE_ITEM_STATE, requestedIds)) {
-      UpgradeState state = calculateState(upgrade, item);
-      setResourceProperty(resource, UPGRADE_ITEM_STATE, state, requestedIds);
-    }
-    setResourceProperty(resource, UPGRADE_ITEM_TEXT, item.getText(), requestedIds);
-
-    return resource;
-  }
-
-  private UpgradeState calculateState(UpgradeEntity upgrade, UpgradeItemEntity item) {
-    long requestId = upgrade.getRequestId().longValue();
-    long stageId = item.getStageId().longValue();
-
-    List<HostRoleCommand> commands = getManagementController().getActionManager().getRequestTasks(requestId);
+    UpgradeGroupEntity group = item.getGroupEntity();
+    UpgradeEntity upgrade = group.getUpgradeEntity();
 
-    int pending = 0;
-    int complete = 0;
-    int in_progress = 0;
-    int failed = 0;
+    setResourceProperty(resource, UPGRADE_REQUEST_ID, upgrade.getRequestId(), requestedIds);
+    setResourceProperty(resource, UPGRADE_GROUP_ID, group.getId(), requestedIds);
+    setResourceProperty(resource, UPGRADE_ITEM_STAGE_ID, item.getStageId(), requestedIds);
 
-    for (HostRoleCommand command : commands) {
-      if (stageId != command.getStageId()) {
-        continue;
-      }
-
-      HostRoleStatus status = command.getStatus();
-      if (status.isFailedState()) {
-        failed++;
-      } else {
-        switch (status) {
-          case COMPLETED:
-            complete++;
-            break;
-          case IN_PROGRESS:
-            in_progress++;
-            break;
-          case PENDING:
-            pending++;
-            break;
-          case QUEUED:
-            in_progress++;
-            break;
-          case FAILED:
-          case ABORTED:
-          case TIMEDOUT:
-            failed++;
-            break;
-          default:
-            break;
-        }
-      }
-    }
-
-    if (failed > 0) {
-      return UpgradeState.FAILED;
-    } else if (in_progress > 0) {
-      return UpgradeState.IN_PROGRESS;
-    } else if (pending > 0) {
-      return UpgradeState.PENDING;
-    } else if (complete > 0) {
-      return UpgradeState.COMPLETE;
-    }
-
-    return UpgradeState.NONE;
+    return resource;
   }
 
-
-
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/e7c512c2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
index a2c30f7..7e07453 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -79,13 +80,12 @@ import com.google.inject.Provider;
 @StaticallyInject
 public class UpgradeResourceProvider extends AbstractControllerResourceProvider {
 
-  protected static final String UPGRADE_ID = "Upgrade/id";
   protected static final String UPGRADE_CLUSTER_NAME = "Upgrade/cluster_name";
   protected static final String UPGRADE_VERSION = "Upgrade/repository_version";
   protected static final String UPGRADE_REQUEST_ID = "Upgrade/request_id";
 
   private static final Set<String> PK_PROPERTY_IDS = new HashSet<String>(
-      Arrays.asList(UPGRADE_ID, UPGRADE_CLUSTER_NAME));
+      Arrays.asList(UPGRADE_REQUEST_ID, UPGRADE_CLUSTER_NAME));
   private static final Set<String> PROPERTY_IDS = new HashSet<String>();
 
   private static final Map<Resource.Type, String> KEY_PROPERTY_IDS = new HashMap<Resource.Type, String>();
@@ -105,15 +105,22 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
   @Inject
   private static Provider<AmbariCustomCommandExecutionHelper> commandExecutionHelper;
 
+  private static Map<String, String> REQUEST_PROPERTY_MAP = new HashMap<String, String>();
+
   static {
     // properties
-    PROPERTY_IDS.add(UPGRADE_ID);
     PROPERTY_IDS.add(UPGRADE_CLUSTER_NAME);
     PROPERTY_IDS.add(UPGRADE_VERSION);
     PROPERTY_IDS.add(UPGRADE_REQUEST_ID);
 
+    // !!! boo
+    for (String requestPropertyId : RequestResourceProvider.PROPERTY_IDS) {
+      REQUEST_PROPERTY_MAP.put(requestPropertyId, requestPropertyId.replace("Requests/", "Upgrade/"));
+    }
+    PROPERTY_IDS.addAll(REQUEST_PROPERTY_MAP.values());
+
     // keys
-    KEY_PROPERTY_IDS.put(Resource.Type.Upgrade, UPGRADE_ID);
+    KEY_PROPERTY_IDS.put(Resource.Type.Upgrade, UPGRADE_REQUEST_ID);
     KEY_PROPERTY_IDS.put(Resource.Type.Cluster, UPGRADE_CLUSTER_NAME);
   }
 
@@ -156,7 +163,7 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
     notifyCreate(Resource.Type.Upgrade, request);
 
     Resource res = new ResourceImpl(Resource.Type.Upgrade);
-    res.setProperty(UPGRADE_ID, entity.getId());
+    res.setProperty(UPGRADE_REQUEST_ID, entity.getRequestId());
     return new RequestStatusImpl(null, Collections.singleton(res));
   }
 
@@ -184,9 +191,10 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
 
       List<UpgradeEntity> upgrades = new ArrayList<UpgradeEntity>();
 
-      String upgradeIdStr = (String) propertyMap.get(UPGRADE_ID);
+      String upgradeIdStr = (String) propertyMap.get(UPGRADE_REQUEST_ID);
       if (null != upgradeIdStr) {
-        UpgradeEntity upgrade = m_upgradeDAO.findUpgrade(Long.parseLong(upgradeIdStr));
+        UpgradeEntity upgrade = m_upgradeDAO.findUpgradeByRequestId(Long.valueOf(upgradeIdStr));
+
         if (null != upgrade) {
           upgrades.add(upgrade);
         }
@@ -194,8 +202,19 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
         upgrades = m_upgradeDAO.findUpgrades(cluster.getClusterId());
       }
 
+      UpgradeHelper helper = new UpgradeHelper();
       for (UpgradeEntity entity : upgrades) {
-        results.add(toResource(entity, clusterName, requestPropertyIds));
+        Resource r = toResource(entity, clusterName, requestPropertyIds);
+        results.add(r);
+
+        // !!! not terribly efficient, but that's ok in this case.  The handful-per-year
+        // an upgrade is done won't kill performance.
+        Resource r1 = helper.getRequestResource(clusterName, entity.getRequestId());
+        for (Entry<String, String> entry : REQUEST_PROPERTY_MAP.entrySet()) {
+          Object o = r1.getPropertyValue(entry.getKey());
+
+          setResourceProperty(r, entry.getValue(), o, requestPropertyIds);
+        }
       }
     }
 
@@ -236,7 +255,6 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
       Set<String> requestedIds) {
     ResourceImpl resource = new ResourceImpl(Resource.Type.Upgrade);
 
-    setResourceProperty(resource, UPGRADE_ID, entity.getId(), requestedIds);
     setResourceProperty(resource, UPGRADE_CLUSTER_NAME, clusterName, requestedIds);
     setResourceProperty(resource, UPGRADE_REQUEST_ID, entity.getRequestId(), requestedIds);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/e7c512c2/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
index c08f809..a9b913f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
@@ -25,6 +25,7 @@ import javax.persistence.TypedQuery;
 import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.UpgradeEntity;
 import org.apache.ambari.server.orm.entities.UpgradeGroupEntity;
+import org.apache.ambari.server.orm.entities.UpgradeItemEntity;
 import org.eclipse.persistence.config.HintValues;
 import org.eclipse.persistence.config.QueryHints;
 
@@ -74,6 +75,16 @@ public class UpgradeDAO {
     return daoUtils.selectSingle(query);
   }
 
+  @RequiresSession
+  public UpgradeEntity findUpgradeByRequestId(Long requestId) {
+    TypedQuery<UpgradeEntity> query = entityManagerProvider.get().createQuery(
+        "SELECT p FROM UpgradeEntity p WHERE p.requestId = :requestId", UpgradeEntity.class);
+    query.setParameter("requestId", requestId);
+    query.setHint(QueryHints.REFRESH, HintValues.TRUE);
+
+    return daoUtils.selectSingle(query);
+  }
+
   /**
    * Creates the upgrade entity in the database
    * @param entity the entity
@@ -94,22 +105,54 @@ public class UpgradeDAO {
     for (UpgradeEntity entity : entities) {
       entityManagerProvider.get().remove(entity);
     }
-
   }
 
   /**
    * @param groupId the group id
    * @return the group, or {@code null} if not found
    */
-  public UpgradeGroupEntity findUpgradeGroup(long groupId) {
+  @RequiresSession
+  public UpgradeGroupEntity findUpgradeGroup(Long groupId) {
 
     TypedQuery<UpgradeGroupEntity> query = entityManagerProvider.get().createQuery(
         "SELECT p FROM UpgradeGroupEntity p WHERE p.upgradeGroupId = :groupId", UpgradeGroupEntity.class);
-    query.setParameter("groupId", Long.valueOf(groupId));
+    query.setParameter("groupId", groupId);
     query.setHint(QueryHints.REFRESH, HintValues.TRUE);
 
     return daoUtils.selectSingle(query);
   }
 
+  /**
+   * @param itemId the item id
+   * @return the upgrade item entity, or {@code null} if not found
+   */
+  public UpgradeItemEntity findUpgradeItem(long itemId) {
+    TypedQuery<UpgradeItemEntity> query = entityManagerProvider.get().createQuery(
+        "SELECT p FROM UpgradeItemEntity p WHERE p.upgradeItemId = :itemId", UpgradeItemEntity.class);
+    query.setParameter("itemId", Long.valueOf(itemId));
+    query.setHint(QueryHints.REFRESH, HintValues.TRUE);
+
+    return daoUtils.selectSingle(query);
+  }
+
+
+  /**
+   * @param requestId the request id
+   * @param stageId the stage id
+   * @return the upgrade entity, or {@code null} if not found
+   */
+  public UpgradeItemEntity findUpgradeItemByRequestAndStage(Long requestId, Long stageId) {
+    TypedQuery<UpgradeItemEntity> query = entityManagerProvider.get().createQuery(
+        "SELECT p FROM UpgradeItemEntity p WHERE p.stageId = :stageId AND p.upgradeGroupEntity.upgradeEntity.requestId = :requestId",
+        UpgradeItemEntity.class);
+    query.setParameter("requestId", requestId);
+    query.setParameter("stageId", stageId);
+
+    query.setHint(QueryHints.REFRESH, HintValues.TRUE);
+
+    return daoUtils.selectSingle(query);
+  }
+
+
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/e7c512c2/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java
index 4320dbe..8201a8b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java
@@ -23,12 +23,32 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.ambari.server.controller.internal.RequestImpl;
+import org.apache.ambari.server.controller.internal.RequestResourceProvider;
+import org.apache.ambari.server.controller.internal.StageResourceProvider;
+import org.apache.ambari.server.controller.internal.UpgradeResourceProvider;
+import org.apache.ambari.server.controller.predicate.AndPredicate;
+import org.apache.ambari.server.controller.predicate.EqualsPredicate;
+import org.apache.ambari.server.controller.predicate.OrPredicate;
+import org.apache.ambari.server.controller.spi.ClusterController;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.QueryResponse;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.controller.utilities.ClusterControllerHelper;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.state.stack.UpgradePack;
 import org.apache.ambari.server.state.stack.UpgradePack.ProcessingComponent;
 import org.apache.ambari.server.state.stack.upgrade.Grouping;
 import org.apache.ambari.server.state.stack.upgrade.StageWrapper;
 import org.apache.ambari.server.state.stack.upgrade.StageWrapperBuilder;
 import org.apache.ambari.server.state.stack.upgrade.TaskWrapper;
+import org.codehaus.jackson.map.ser.PropertyBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -150,4 +170,85 @@ public class UpgradeHelper {
 
 
 
+  /**
+   * Gets a set of Stages resources to aggregate an UpgradeItem with Stage.
+   *
+   * @param clusterName the cluster name
+   * @param requestId the request id containing the stages
+   * @param stageIds the list of stages to fetch
+   * @return the list of Stage resources
+   * @throws UnsupportedPropertyException
+   * @throws NoSuchResourceException
+   * @throws NoSuchParentResourceException
+   * @throws SystemException
+   */
+  // !!! FIXME this feels very wrong
+  public Set<Resource> getStageResources(String clusterName, Long requestId, List<Long> stageIds)
+      throws UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException, SystemException {
+    ClusterController clusterController = ClusterControllerHelper.getClusterController();
+
+    Request request = PropertyHelper.getReadRequest();
+
+
+    Predicate p1 = new PredicateBuilder().property(StageResourceProvider.STAGE_CLUSTER_NAME).equals(clusterName).toPredicate();
+    Predicate p2 = new PredicateBuilder().property(StageResourceProvider.STAGE_REQUEST_ID).equals(requestId).toPredicate();
+    Predicate p3 = null;
+
+    if (1 == stageIds.size()) {
+      p3 = new PredicateBuilder().property(StageResourceProvider.STAGE_STAGE_ID).equals(stageIds.get(0)).toPredicate();
+    } else if (stageIds.size() > 0) {
+      PredicateBuilder pb = new PredicateBuilder();
+
+      int i = 0;
+      for (Long stageId : stageIds) {
+        if (i++ < stageIds.size()-1) {
+          pb = pb.property(StageResourceProvider.STAGE_STAGE_ID).equals(stageId).or();
+        } else {
+          pb.property(StageResourceProvider.STAGE_STAGE_ID).equals(stageId);
+        }
+      }
+
+      p3 = pb.toPredicate();
+    }
+
+    QueryResponse response = clusterController.getResources(Resource.Type.Stage,
+        request, new AndPredicate(p1, p2, p3));
+
+    return response.getResources();
+  }
+
+  /**
+   * Gets a Request resource to aggreate with an Upgrade
+   * @param clusterName the cluster name
+   * @param requestId the request id
+   * @return the resource for the Request
+   * @throws UnsupportedPropertyException
+   * @throws NoSuchResourceException
+   * @throws NoSuchParentResourceException
+   * @throws SystemException
+   */
+  // !!! FIXME this feels very wrong
+  public Resource getRequestResource(String clusterName, Long requestId)
+      throws UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException, SystemException {
+
+    ClusterController clusterController = ClusterControllerHelper.getClusterController();
+
+    Request request = PropertyHelper.getReadRequest();
+
+    Predicate predicate = new PredicateBuilder().property(RequestResourceProvider.REQUEST_CLUSTER_NAME_PROPERTY_ID).equals(clusterName).and()
+        // !!! RequestResourceProvider is expecting a string, not a Long for the requestId
+        .property(RequestResourceProvider.REQUEST_ID_PROPERTY_ID).equals(requestId.toString()).toPredicate();
+
+    QueryResponse response = clusterController.getResources(Resource.Type.Request,
+        request, predicate);
+
+    Set<Resource> resources = response.getResources();
+    if (1 != resources.size()) {
+      throw new SystemException(String.format(
+          "Cannot uniquely identify the request resource for %s", requestId));
+    }
+
+    return resources.iterator().next();
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/e7c512c2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
index fbb4f43..cf58935 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
@@ -19,18 +19,27 @@ package org.apache.ambari.server.controller.internal;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
 
+import java.lang.reflect.Field;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.RequestStatus;
 import org.apache.ambari.server.actionmanager.Stage;
 import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.AmbariServer;
+import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
@@ -48,6 +57,7 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.UpgradeState;
+import org.apache.ambari.server.view.ViewRegistry;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -65,6 +75,8 @@ public class UpgradeResourceProviderTest {
   private RepositoryVersionDAO repoVersionDao = null;
   private Injector injector;
   private Clusters clusters;
+//  private UpgradeResourceProvider upgradeResourceProvider;
+  AmbariManagementController amc;
 
   @Before
   public void before() throws Exception {
@@ -72,9 +84,20 @@ public class UpgradeResourceProviderTest {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
 
+
+    amc = injector.getInstance(AmbariManagementController.class);
+//    upgradeResourceProvider = createProvider(amc);
+
+    Field field = AmbariServer.class.getDeclaredField("clusterController");
+    field.setAccessible(true);
+    field.set(null, amc);
+
     upgradeDao = injector.getInstance(UpgradeDAO.class);
     repoVersionDao = injector.getInstance(RepositoryVersionDAO.class);
 
+    ViewRegistry.initInstance(new ViewRegistry());
+    System.out.println(AmbariServer.getController());
+
     RepositoryVersionEntity repoVersionEntity = new RepositoryVersionEntity();
     repoVersionEntity.setDisplayName("My New Version");
     repoVersionEntity.setOperatingSystems("");
@@ -118,28 +141,21 @@ public class UpgradeResourceProviderTest {
     injector = null;
   }
 
-  /**
-   * @throws Exception
-   */
-  @Test
-  public void testCreateResources() throws Exception {
+  public org.apache.ambari.server.controller.spi.RequestStatus testCreateResources() throws Exception {
 
     Cluster cluster = clusters.getCluster("c1");
 
     List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId());
     assertEquals(0, upgrades.size());
 
-    AmbariManagementController amc = injector.getInstance(AmbariManagementController.class);
-
-    UpgradeResourceProvider provider = createProvider(amc);
-
     Map<String, Object> requestProps = new HashMap<String, Object>();
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
     requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.2.2");
 
-    Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
-    org.apache.ambari.server.controller.spi.RequestStatus status = provider.createResources(request);
+    ResourceProvider upgradeResourceProvider = createProvider(amc);
 
+    Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
+    org.apache.ambari.server.controller.spi.RequestStatus status = upgradeResourceProvider.createResources(request);
 
     upgrades = upgradeDao.findUpgrades(cluster.getClusterId());
     assertEquals(1, upgrades.size());
@@ -176,8 +192,80 @@ public class UpgradeResourceProviderTest {
 
     List<HostRoleCommand> tasks = am.getRequestTasks(requests.get(0).longValue());
     assertEquals(3, tasks.size());
+
+    return status;
   }
 
+  @Test
+  public void testGetResources() throws Exception {
+    org.apache.ambari.server.controller.spi.RequestStatus status = testCreateResources();
+
+    Set<Resource> createdResources = status.getAssociatedResources();
+    assertEquals(1, createdResources.size());
+    Resource res = createdResources.iterator().next();
+    Long id = (Long) res.getPropertyValue("Upgrade/request_id");
+    assertNotNull(id);
+    assertEquals(Long.valueOf(1), id);
+
+    // upgrade
+    Set<String> propertyIds = new HashSet<String>();
+    propertyIds.add("Upgrade");
+
+    Predicate predicate = new PredicateBuilder()
+      .property(UpgradeResourceProvider.UPGRADE_REQUEST_ID).equals("1").and()
+      .property(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME).equals("c1")
+      .toPredicate();
+    Request request = PropertyHelper.getReadRequest(propertyIds);
+
+    ResourceProvider upgradeResourceProvider = createProvider(amc);
+    Set<Resource> resources = upgradeResourceProvider.getResources(request, predicate);
+
+    assertEquals(1, resources.size());
+    res = resources.iterator().next();
+    assertNotNull(res.getPropertyValue("Upgrade/progress_percent"));
+
+
+    // upgrade groups
+    propertyIds.clear();
+    propertyIds.add("UpgradeGroup");
+
+    predicate = new PredicateBuilder()
+      .property(UpgradeGroupResourceProvider.UPGRADE_REQUEST_ID).equals("1").and()
+      .property(UpgradeGroupResourceProvider.UPGRADE_CLUSTER_NAME).equals("c1")
+      .toPredicate();
+    request = PropertyHelper.getReadRequest(propertyIds);
+
+    ResourceProvider upgradeGroupResourceProvider = new UpgradeGroupResourceProvider(amc);
+    resources = upgradeGroupResourceProvider.getResources(request, predicate);
+
+    assertEquals(3, resources.size());
+    res = resources.iterator().next();
+    assertNotNull(res.getPropertyValue("UpgradeGroup/status"));
+    assertNotNull(res.getPropertyValue("UpgradeGroup/group_id"));
+
+    // upgrade items
+    propertyIds.clear();
+    propertyIds.add("UpgradeItem");
+
+    predicate = new PredicateBuilder()
+      .property(UpgradeItemResourceProvider.UPGRADE_GROUP_ID).equals("1").and()
+      .property(UpgradeItemResourceProvider.UPGRADE_REQUEST_ID).equals("1").and()
+      .property(UpgradeItemResourceProvider.UPGRADE_CLUSTER_NAME).equals("c1")
+      .toPredicate();
+    request = PropertyHelper.getReadRequest(propertyIds);
+
+    ResourceProvider upgradeItemResourceProvider = new UpgradeItemResourceProvider(amc);
+    resources = upgradeItemResourceProvider.getResources(request, predicate);
+
+    assertEquals(3, resources.size());
+    res = resources.iterator().next();
+    assertNotNull(res.getPropertyValue("UpgradeItem/status"));
+
+  }
+
+
+
+
 
   /**
    * @param amc


Mime
View raw message