ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [33/37] ambari git commit: AMBARI-21450. Initial cherry-picking for feature branch (ncole)
Date Thu, 13 Jul 2017 19:14:51 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
index 71e105e..c526b6e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
@@ -35,11 +35,11 @@ import org.apache.ambari.server.DuplicateResourceException;
 import org.apache.ambari.server.HostNotFoundException;
 import org.apache.ambari.server.ObjectNotFoundException;
 import org.apache.ambari.server.ParentObjectNotFoundException;
+import org.apache.ambari.server.StaticallyInject;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.ConfigurationRequest;
 import org.apache.ambari.server.controller.HostRequest;
 import org.apache.ambari.server.controller.HostResponse;
-import org.apache.ambari.server.controller.MaintenanceStateHelper;
 import org.apache.ambari.server.controller.RequestStatusResponse;
 import org.apache.ambari.server.controller.ServiceComponentHostRequest;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
@@ -74,6 +74,7 @@ import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.ImmutableSet;
 import com.google.inject.Inject;
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.AssistedInject;
@@ -83,86 +84,75 @@ import com.google.inject.persist.Transactional;
 /**
  * Resource provider for host resources.
  */
+@StaticallyInject
 public class HostResourceProvider extends AbstractControllerResourceProvider {
 
   // ----- Property ID constants ---------------------------------------------
 
   // Hosts
-  public static final String HOST_CLUSTER_NAME_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "cluster_name");
-  public static final String HOST_NAME_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "host_name");
-  public static final String HOST_PUBLIC_NAME_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "public_host_name");
-  public static final String HOST_IP_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "ip");
-  public static final String HOST_TOTAL_MEM_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "total_mem");
-  public static final String HOST_CPU_COUNT_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "cpu_count");
-  public static final String HOST_PHYSICAL_CPU_COUNT_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "ph_cpu_count");
-  public static final String HOST_OS_ARCH_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "os_arch");
-  public static final String HOST_OS_TYPE_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "os_type");
-  public static final String HOST_OS_FAMILY_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "os_family");
-  public static final String HOST_RACK_INFO_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "rack_info");
-  public static final String HOST_LAST_HEARTBEAT_TIME_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "last_heartbeat_time");
-  public static final String HOST_LAST_REGISTRATION_TIME_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "last_registration_time");
-  public static final String HOST_DISK_INFO_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "disk_info");
-
-
-  public static final String HOST_HOST_STATUS_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "host_status");
-  public static final String HOST_MAINTENANCE_STATE_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "maintenance_state");
-
-  public static final String HOST_HOST_HEALTH_REPORT_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "host_health_report");
-  public static final String HOST_RECOVERY_REPORT_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "recovery_report");
-  public static final String HOST_RECOVERY_SUMMARY_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "recovery_summary");
-  public static final String HOST_STATE_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "host_state");
-  public static final String HOST_LAST_AGENT_ENV_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "last_agent_env");
-  public static final String HOST_DESIRED_CONFIGS_PROPERTY_ID =
-      PropertyHelper.getPropertyId("Hosts", "desired_configs");
-
-  public static final String BLUEPRINT_PROPERTY_ID =
-      PropertyHelper.getPropertyId(null, "blueprint");
-  public static final String HOSTGROUP_PROPERTY_ID =
-      PropertyHelper.getPropertyId(null, "host_group");
-  public static final String HOST_NAME_NO_CATEGORY_PROPERTY_ID =
-      PropertyHelper.getPropertyId(null, "host_name");
-  public static final String HOST_COUNT_PROPERTY_ID =
-      PropertyHelper.getPropertyId(null, "host_count");
-  public static final String HOST_PREDICATE_PROPERTY_ID =
-      PropertyHelper.getPropertyId(null, "host_predicate");
+  public static final String RESPONSE_KEY = "Hosts";
+  public static final String ALL_PROPERTIES = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "*";
+
+  public static final String CLUSTER_NAME_PROPERTY_ID = "cluster_name";
+  public static final String CPU_COUNT_PROPERTY_ID = "cpu_count";
+  public static final String DESIRED_CONFIGS_PROPERTY_ID = "desired_configs";
+  public static final String DISK_INFO_PROPERTY_ID = "disk_info";
+  public static final String HOST_HEALTH_REPORT_PROPERTY_ID = "host_health_report";
+  public static final String HOST_NAME_PROPERTY_ID = "host_name";
+  public static final String HOST_STATUS_PROPERTY_ID = "host_status";
+  public static final String IP_PROPERTY_ID = "ip";
+  public static final String LAST_AGENT_ENV_PROPERTY_ID = "last_agent_env";
+  public static final String LAST_HEARTBEAT_TIME_PROPERTY_ID = "last_heartbeat_time";
+  public static final String LAST_REGISTRATION_TIME_PROPERTY_ID = "last_registration_time";
+  public static final String MAINTENANCE_STATE_PROPERTY_ID = "maintenance_state";
+  public static final String OS_ARCH_PROPERTY_ID = "os_arch";
+  public static final String OS_FAMILY_PROPERTY_ID = "os_family";
+  public static final String OS_TYPE_PROPERTY_ID = "os_type";
+  public static final String PHYSICAL_CPU_COUNT_PROPERTY_ID = "ph_cpu_count";
+  public static final String PUBLIC_NAME_PROPERTY_ID = "public_host_name";
+  public static final String RACK_INFO_PROPERTY_ID = "rack_info";
+  public static final String RECOVERY_REPORT_PROPERTY_ID = "recovery_report";
+  public static final String RECOVERY_SUMMARY_PROPERTY_ID = "recovery_summary";
+  public static final String STATE_PROPERTY_ID = "host_state";
+  public static final String TOTAL_MEM_PROPERTY_ID = "total_mem";
+
+  public static final String HOST_CLUSTER_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + CLUSTER_NAME_PROPERTY_ID;
+  public static final String HOST_CPU_COUNT_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + CPU_COUNT_PROPERTY_ID;
+  public static final String HOST_DESIRED_CONFIGS_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + DESIRED_CONFIGS_PROPERTY_ID;
+  public static final String HOST_DISK_INFO_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + DISK_INFO_PROPERTY_ID;
+  public static final String HOST_HOST_HEALTH_REPORT_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + HOST_HEALTH_REPORT_PROPERTY_ID;
+  public static final String HOST_HOST_STATUS_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + HOST_STATUS_PROPERTY_ID;
+  public static final String HOST_IP_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + IP_PROPERTY_ID;
+  public static final String HOST_LAST_AGENT_ENV_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + LAST_AGENT_ENV_PROPERTY_ID;
+  public static final String HOST_LAST_HEARTBEAT_TIME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + LAST_HEARTBEAT_TIME_PROPERTY_ID;
+  public static final String HOST_LAST_REGISTRATION_TIME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + LAST_REGISTRATION_TIME_PROPERTY_ID;
+  public static final String HOST_MAINTENANCE_STATE_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + MAINTENANCE_STATE_PROPERTY_ID;
+  public static final String HOST_HOST_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + HOST_NAME_PROPERTY_ID;
+  public static final String HOST_OS_ARCH_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + OS_ARCH_PROPERTY_ID;
+  public static final String HOST_OS_FAMILY_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + OS_FAMILY_PROPERTY_ID;
+  public static final String HOST_OS_TYPE_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + OS_TYPE_PROPERTY_ID;
+  public static final String HOST_PHYSICAL_CPU_COUNT_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + PHYSICAL_CPU_COUNT_PROPERTY_ID;
+  public static final String HOST_PUBLIC_NAME_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + PUBLIC_NAME_PROPERTY_ID;
+  public static final String HOST_RACK_INFO_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + RACK_INFO_PROPERTY_ID;
+  public static final String HOST_RECOVERY_REPORT_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + RECOVERY_REPORT_PROPERTY_ID;
+  public static final String HOST_RECOVERY_SUMMARY_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + RECOVERY_SUMMARY_PROPERTY_ID;
+  public static final String HOST_STATE_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + STATE_PROPERTY_ID;
+  public static final String HOST_TOTAL_MEM_PROPERTY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + TOTAL_MEM_PROPERTY_ID;
+
+  public static final String BLUEPRINT_PROPERTY_ID = "blueprint";
+  public static final String HOST_GROUP_PROPERTY_ID = "host_group";
+  public static final String HOST_COUNT_PROPERTY_ID = "host_count";
+  public static final String HOST_PREDICATE_PROPERTY_ID = "host_predicate";
 
   //todo use the same json structure for cluster host addition (cluster template and upscale)
-  public static final String HOST_RACK_INFO_NO_CATEGORY_PROPERTY_ID =
-      PropertyHelper.getPropertyId(null, "rack_info");
 
   protected static final String FORCE_DELETE_COMPONENTS = "force_delete_components";
 
 
-  private static Set<String> pkPropertyIds =
-      new HashSet<String>(Arrays.asList(new String[]{
-          HOST_NAME_PROPERTY_ID}));
+  private static final Set<String> PK_PROPERTY_IDS = ImmutableSet.of(HOST_HOST_NAME_PROPERTY_ID);
 
   @Inject
-  private MaintenanceStateHelper maintenanceStateHelper;
-
-  @Inject
-  private OsFamily osFamily;
+  private static OsFamily osFamily;
 
   @Inject
   private static TopologyManager topologyManager;
@@ -220,7 +210,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
   protected Set<Resource> getResourcesAuthorized(Request request, Predicate predicate)
       throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
 
-    final Set<HostRequest> requests = new HashSet<HostRequest>();
+    final Set<HostRequest> requests = new HashSet<>();
 
     if (predicate == null) {
       requests.add(getRequest(null));
@@ -239,7 +229,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
     });
 
     Set<String>   requestedIds = getRequestPropertyIds(request, predicate);
-    Set<Resource> resources    = new HashSet<Resource>();
+    Set<Resource> resources    = new HashSet<>();
 
     for (HostResponse response : responses) {
       Resource resource = new ResourceImpl(Resource.Type.Host);
@@ -250,7 +240,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
         setResourceProperty(resource, HOST_CLUSTER_NAME_PROPERTY_ID,
             response.getClusterName(), requestedIds);
       }
-      setResourceProperty(resource, HOST_NAME_PROPERTY_ID,
+      setResourceProperty(resource, HOST_HOST_NAME_PROPERTY_ID,
           response.getHostname(), requestedIds);
       setResourceProperty(resource, HOST_PUBLIC_NAME_PROPERTY_ID,
           response.getPublicHostName(), requestedIds);
@@ -259,22 +249,15 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
       setResourceProperty(resource, HOST_TOTAL_MEM_PROPERTY_ID,
           response.getTotalMemBytes(), requestedIds);
       setResourceProperty(resource, HOST_CPU_COUNT_PROPERTY_ID,
-          (long) response.getCpuCount(), requestedIds);
+          response.getCpuCount(), requestedIds);
       setResourceProperty(resource, HOST_PHYSICAL_CPU_COUNT_PROPERTY_ID,
-          (long) response.getPhCpuCount(), requestedIds);
+          response.getPhCpuCount(), requestedIds);
       setResourceProperty(resource, HOST_OS_ARCH_PROPERTY_ID,
           response.getOsArch(), requestedIds);
       setResourceProperty(resource, HOST_OS_TYPE_PROPERTY_ID,
           response.getOsType(), requestedIds);
-
-      String hostOsFamily = osFamily.find(response.getOsType());
-      if (hostOsFamily == null) {
-        LOG.error("Can not find host OS family. For OS type = '{}' and host name = '{}'",
-            response.getOsType(), response.getHostname());
-      }
       setResourceProperty(resource, HOST_OS_FAMILY_PROPERTY_ID,
-          hostOsFamily, requestedIds);
-
+          response.getOsFamily(), requestedIds);
       setResourceProperty(resource, HOST_RACK_INFO_PROPERTY_ID,
           response.getRackInfo(), requestedIds);
       setResourceProperty(resource, HOST_LAST_HEARTBEAT_TIME_PROPERTY_ID,
@@ -286,7 +269,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
       setResourceProperty(resource, HOST_HOST_STATUS_PROPERTY_ID,
           response.getStatus(),requestedIds);
       setResourceProperty(resource, HOST_HOST_HEALTH_REPORT_PROPERTY_ID,
-          response.getHealthStatus().getHealthReport(), requestedIds);
+          response.getHealthReport(), requestedIds);
       setResourceProperty(resource, HOST_RECOVERY_REPORT_PROPERTY_ID,
           response.getRecoveryReport(), requestedIds);
       setResourceProperty(resource, HOST_RECOVERY_SUMMARY_PROPERTY_ID,
@@ -313,7 +296,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
   protected RequestStatus updateResourcesAuthorized(final Request request, Predicate predicate)
       throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
 
-    final Set<HostRequest> requests = new HashSet<HostRequest>();
+    final Set<HostRequest> requests = new HashSet<>();
     for (Map<String, Object> propertyMap : getPropertyMaps(request.getProperties().iterator().next(), predicate)) {
       requests.add(getRequest(propertyMap));
     }
@@ -363,12 +346,11 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
     Set<String> baseUnsupported = super.checkPropertyIds(propertyIds);
 
     baseUnsupported.remove(BLUEPRINT_PROPERTY_ID);
-    baseUnsupported.remove(HOSTGROUP_PROPERTY_ID);
-    baseUnsupported.remove(HOST_NAME_NO_CATEGORY_PROPERTY_ID);
-    //todo: constants
+    baseUnsupported.remove(HOST_GROUP_PROPERTY_ID);
+    baseUnsupported.remove(HOST_NAME_PROPERTY_ID);
     baseUnsupported.remove(HOST_COUNT_PROPERTY_ID);
     baseUnsupported.remove(HOST_PREDICATE_PROPERTY_ID);
-    baseUnsupported.remove(HOST_RACK_INFO_NO_CATEGORY_PROPERTY_ID);
+    baseUnsupported.remove(RACK_INFO_PROPERTY_ID);
 
     return checkConfigPropertyIds(baseUnsupported, "Hosts");
   }
@@ -378,7 +360,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
 
   @Override
   protected Set<String> getPKPropertyIds() {
-    return pkPropertyIds;
+    return PK_PROPERTY_IDS;
   }
 
 
@@ -397,7 +379,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
     Set<Map<String, Object>> properties = request.getProperties();
     if (properties != null && ! properties.isEmpty()) {
       //todo: for now, either all or none of the hosts need to specify a hg.  Unable to mix.
-      String hgName = (String) properties.iterator().next().get(HOSTGROUP_PROPERTY_ID);
+      String hgName = (String) properties.iterator().next().get(HOST_GROUP_PROPERTY_ID);
       isHostGroupRequest = hgName != null && ! hgName.isEmpty();
     }
     return isHostGroupRequest;
@@ -413,21 +395,21 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
   private HostRequest getRequest(Map<String, Object> properties) {
 
     if (properties == null) {
-      return  new HostRequest(null, null, null);
+      return new HostRequest(null, null);
     }
 
     HostRequest hostRequest = new HostRequest(
         getHostNameFromProperties(properties),
-        (String) properties.get(HOST_CLUSTER_NAME_PROPERTY_ID),
-        null);
+        (String) properties.get(HOST_CLUSTER_NAME_PROPERTY_ID)
+    );
     hostRequest.setPublicHostName((String) properties.get(HOST_PUBLIC_NAME_PROPERTY_ID));
 
     String rackInfo = (String) ((null != properties.get(HOST_RACK_INFO_PROPERTY_ID))? properties.get(HOST_RACK_INFO_PROPERTY_ID):
-            properties.get(HOST_RACK_INFO_NO_CATEGORY_PROPERTY_ID));
+            properties.get(RACK_INFO_PROPERTY_ID));
 
     hostRequest.setRackInfo(rackInfo);
     hostRequest.setBlueprintName((String) properties.get(BLUEPRINT_PROPERTY_ID));
-    hostRequest.setHostGroupName((String) properties.get(HOSTGROUP_PROPERTY_ID));
+    hostRequest.setHostGroupName((String) properties.get(HOST_GROUP_PROPERTY_ID));
 
     Object o = properties.get(HOST_MAINTENANCE_STATE_PROPERTY_ID);
     if (null != o) {
@@ -446,7 +428,6 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
    * Accepts a request with registered hosts and if the request contains a cluster name then will map all of the
    * hosts onto that cluster.
    * @param request Request that must contain registered hosts, and optionally a cluster.
-   * @throws AmbariException
    */
   public synchronized void createHosts(Request request)
       throws AmbariException {
@@ -460,16 +441,16 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
     AmbariManagementController controller = getManagementController();
     Clusters                   clusters   = controller.getClusters();
 
-    Set<String> duplicates = new HashSet<String>();
-    Set<String> unknowns = new HashSet<String>();
-    Set<String> allHosts = new HashSet<String>();
+    Set<String> duplicates = new HashSet<>();
+    Set<String> unknowns = new HashSet<>();
+    Set<String> allHosts = new HashSet<>();
 
 
-    Set<HostRequest> hostRequests = new HashSet<HostRequest>();
+    Set<HostRequest> hostRequests = new HashSet<>();
     for (Map<String, Object> propertyMap : propertySet) {
       HostRequest hostRequest = getRequest(propertyMap);
       hostRequests.add(hostRequest);
-      if (! propertyMap.containsKey(HOSTGROUP_PROPERTY_ID)) {
+      if (! propertyMap.containsKey(HOST_GROUP_PROPERTY_ID)) {
         createHostResource(clusters, duplicates, unknowns, allHosts, hostRequest);
       }
     }
@@ -486,7 +467,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
       }
       throw new IllegalArgumentException("Invalid request contains"
           + " duplicate hostnames"
-          + ", hostnames=" + names.toString());
+          + ", hostnames=" + names);
     }
 
     if (!unknowns.isEmpty()) {
@@ -501,12 +482,12 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
       }
 
       throw new IllegalArgumentException("Attempted to add unknown hosts to a cluster.  " +
-          "These hosts have not been registered with the server: " + names.toString());
+          "These hosts have not been registered with the server: " + names);
     }
 
-    Map<String, Set<String>> hostClustersMap = new HashMap<String, Set<String>>();
-    Map<String, Map<String, String>> hostAttributes = new HashMap<String, Map<String, String>>();
-    Set<String> allClusterSet = new HashSet<String>();
+    Map<String, Set<String>> hostClustersMap = new HashMap<>();
+    Map<String, Map<String, String>> hostAttributes = new HashMap<>();
+    Set<String> allClusterSet = new HashSet<>();
 
     for (HostRequest hostRequest : hostRequests) {
       if (hostRequest.getHostname() != null &&
@@ -514,20 +495,14 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
           hostRequest.getClusterName() != null &&
           !hostRequest.getClusterName().isEmpty()){
 
-        Set<String> clusterSet = new HashSet<String>();
+        Set<String> clusterSet = new HashSet<>();
         clusterSet.add(hostRequest.getClusterName());
         allClusterSet.add(hostRequest.getClusterName());
         hostClustersMap.put(hostRequest.getHostname(), clusterSet);
-        if (hostRequest.getHostAttributes() != null) {
-          hostAttributes.put(hostRequest.getHostname(), hostRequest.getHostAttributes());
-        }
       }
     }
     clusters.updateHostWithClusterAndAttributes(hostClustersMap, hostAttributes);
 
-    for (String clusterName : allClusterSet) {
-      clusters.getCluster(clusterName).recalculateAllClusterVersionStates();
-    }
   }
 
   private void createHostResource(Clusters clusters, Set<String> duplicates,
@@ -543,9 +518,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
     }
 
     if (LOG.isDebugEnabled()) {
-      LOG.debug("Received a createHost request"
-          + ", hostname=" + request.getHostname()
-          + ", request=" + request);
+      LOG.debug("Received a createHost request, hostname={}, request={}", request.getHostname(), request);
     }
 
     if (allHosts.contains(request.getHostname())) {
@@ -597,7 +570,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
   }
 
   protected Set<HostResponse> getHosts(Set<HostRequest> requests) throws AmbariException {
-    Set<HostResponse> response = new HashSet<HostResponse>();
+    Set<HostResponse> response = new HashSet<>();
 
     AmbariManagementController controller = getManagementController();
 
@@ -615,6 +588,9 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
     return response;
   }
 
+  /**
+   * @param osFamily provides OS to OS family lookup; may be null if OS family is ignored anyway (eg. for liveness check)
+   */
   protected static Set<HostResponse> getHosts(AmbariManagementController controller, HostRequest request)
       throws AmbariException {
 
@@ -622,7 +598,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
     //TODO/FIXME what is the requirement for filtering on host attributes?
 
     List<Host> hosts;
-    Set<HostResponse> response = new HashSet<HostResponse>();
+    Set<HostResponse> response = new HashSet<>();
     Cluster           cluster  = null;
 
     Clusters                   clusters   = controller.getClusters();
@@ -642,7 +618,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
     if (hostName == null) {
       hosts = clusters.getHosts();
     } else {
-      hosts = new ArrayList<Host>();
+      hosts = new ArrayList<>();
       try {
         hosts.add(clusters.getHost(request.getHostname()));
       } catch (HostNotFoundException e) {
@@ -654,7 +630,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
     // retrieve the cluster desired configs once instead of per host
     Map<String, DesiredConfig> desiredConfigs = null;
     if (null != cluster) {
-      cluster.getDesiredConfigs();
+      desiredConfigs = cluster.getDesiredConfigs();
     }
 
     for (Host h : hosts) {
@@ -665,6 +641,13 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
           r.setClusterName(clusterName);
           r.setDesiredHostConfigs(h.getDesiredHostConfigs(cluster, desiredConfigs));
           r.setMaintenanceState(h.getMaintenanceState(cluster.getClusterId()));
+          if (osFamily != null) {
+            String hostOsFamily = osFamily.find(r.getOsType());
+            if (hostOsFamily == null) {
+              LOG.error("Can not find host OS family. For OS type = '{}' and host name = '{}'", r.getOsType(), r.getHostname());
+            }
+            r.setOsFamily(hostOsFamily);
+          }
 
           response.add(r);
         } else if (hostName != null) {
@@ -678,7 +661,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
         if (clustersForHost != null && clustersForHost.size() != 0) {
           Cluster clusterForHost = clustersForHost.iterator().next();
           r.setClusterName(clusterForHost.getClusterName());
-          r.setDesiredHostConfigs(h.getDesiredHostConfigs(clusterForHost, desiredConfigs));
+          r.setDesiredHostConfigs(h.getDesiredHostConfigs(clusterForHost, null));
           r.setMaintenanceState(h.getMaintenanceState(clusterForHost.getClusterId()));
         }
 
@@ -706,9 +689,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
 
     for (HostRequest request : requests) {
       if (LOG.isDebugEnabled()) {
-        LOG.debug("Received an updateHost request"
-            + ", hostname=" + request.getHostname()
-            + ", request=" + request);
+        LOG.debug("Received an updateHost request, hostname={}, request={}", request.getHostname(), request);
       }
 
       Host host = clusters.getHost(request.getHostname());
@@ -726,13 +707,6 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
         // do nothing
       }
 
-      if (null != request.getHostAttributes()) {
-        if(!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, resourceId, RoleAuthorization.HOST_ADD_DELETE_HOSTS)) {
-          throw new AuthorizationException("The authenticated user is not authorized to update host attributes");
-        }
-        host.setHostAttributes(request.getHostAttributes());
-      }
-
       String  rackInfo        = host.getRackInfo();
       String  requestRackInfo = request.getRackInfo();
       boolean rackChange      = requestRackInfo != null && !requestRackInfo.equals(rackInfo);
@@ -803,12 +777,9 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
         }
       }
 
-      if (clusterName != null && !clusterName.isEmpty()) {
-        clusters.getCluster(clusterName).recalculateAllClusterVersionStates();
-        if (rackChange) {
-          // Authorization check for this update was performed before we got to this point.
-          controller.registerRackChange(clusterName);
-        }
+      if (StringUtils.isNotBlank(clusterName) && rackChange) {
+        // Authorization check for this update was performed before we got to this point.
+        controller.registerRackChange(clusterName);
       }
 
       //todo: if attempt was made to update a property other than those
@@ -931,9 +902,6 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
       }
     }
     clusters.publishHostsDeletion(allClustersWithHosts, hostNames);
-    for (String clustername : hostsClusters) {
-      clusters.getCluster(clustername).recalculateAllClusterVersionStates();
-    }
   }
 
   private void validateHostInDeleteFriendlyState(HostRequest hostRequest, Clusters clusters, boolean forceDelete) throws AmbariException {
@@ -999,9 +967,6 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
 
   /**
    * Removes hostname from the stateful cluster topology
-   * @param clusters
-   * @param hostRequest
-   * @throws AmbariException
    */
   private void removeHostFromClusterTopology(Clusters clusters, HostRequest hostRequest) throws AmbariException{
     if (hostRequest.getClusterName() == null) {
@@ -1032,10 +997,10 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
    * @return the host name for the host request
    */
   private String getHostNameFromProperties(Map<String, Object> properties) {
-    String hostname = (String) properties.get(HOST_NAME_PROPERTY_ID);
+    String hostname = (String) properties.get(HOST_HOST_NAME_PROPERTY_ID);
 
     return hostname != null ? hostname :
-        (String) properties.get(HOST_NAME_NO_CATEGORY_PROPERTY_ID);
+        (String) properties.get(HOST_NAME_PROPERTY_ID);
   }
 
   //todo: for api/v1/hosts we also end up here so we need to ensure proper 400 response

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java
index 5fc3652..fb4831e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -19,7 +19,6 @@ package org.apache.ambari.server.controller.internal;
 
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JDK_LOCATION;
 
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -34,7 +33,6 @@ import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.RequestFactory;
 import org.apache.ambari.server.actionmanager.Stage;
 import org.apache.ambari.server.actionmanager.StageFactory;
-import org.apache.ambari.server.agent.ExecutionCommand.KeyNames;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.ActionExecutionContext;
@@ -61,17 +59,14 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.ServiceComponentHost;
-import org.apache.ambari.server.state.ServiceInfo;
-import org.apache.ambari.server.state.ServiceOsSpecific;
 import org.apache.ambari.server.state.StackId;
-import org.apache.ambari.server.state.repository.VersionDefinitionXml;
+import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
 import org.apache.ambari.server.utils.StageUtils;
 import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.Validate;
 
 import com.google.common.collect.Sets;
-import com.google.gson.Gson;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
 
@@ -107,7 +102,7 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
 
   protected static final String INSTALL_PACKAGES_ACTION = "install_packages";
   protected static final String STACK_SELECT_ACTION = "ru_set_all";
-  protected static final String INSTALL_PACKAGES_FULL_NAME = "Install version";
+  protected static final String INSTALL_PACKAGES_FULL_NAME = "Install Version";
 
 
   private static Set<String> pkPropertyIds = Sets.newHashSet(
@@ -147,8 +142,6 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
   @Inject
   private static RepositoryVersionDAO repositoryVersionDAO;
 
-  private static Gson gson = StageUtils.getGson();
-
   @Inject
   private static StageFactory stageFactory;
 
@@ -161,6 +154,8 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
   @Inject
   private static Configuration configuration;
 
+  @Inject
+  private static RepositoryVersionHelper repoVersionHelper;
 
   /**
    * Constructor.
@@ -398,8 +393,11 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
                       "not defined. Repo version=%s, stackId=%s",
         osFamily, desiredRepoVersion, stackId));
     }
-    // For every host at cluster, determine packages for all installed services
-    List<ServiceOsSpecific.Package> packages = new ArrayList<>();
+
+    if (repoInfo.isEmpty()){
+      LOG.error(String.format("Repository list is empty. Ambari may not be managing the repositories for %s", osFamily));
+    }
+
     Set<String> servicesOnHost = new HashSet<>();
 
     if (forceInstallOnNonMemberHost) {
@@ -421,7 +419,6 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
           LOG.error("Service not found for component {}!", componentName, e);
           throw new IllegalArgumentException("Service not found for component : " + componentName);
         }
-
       }
 
     } else {
@@ -430,53 +427,9 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
         servicesOnHost.add(component.getServiceName());
       }
     }
-    List<String> blacklistedPackagePrefixes = configuration.getRollingUpgradeSkipPackagesPrefixes();
-    for (String serviceName : servicesOnHost) {
-      ServiceInfo info;
-      try {
-        info = ami.getService(stackName, stackVersion, serviceName);
-      } catch (AmbariException e) {
-        throw new SystemException("Can not enumerate services", e);
-      }
-      List<ServiceOsSpecific.Package> packagesForService = managementController.getPackagesForServiceHost(info,
-              new HashMap<String, String>(), // Contents are ignored
-        osFamily);
-      for (ServiceOsSpecific.Package aPackage : packagesForService) {
-        if (! aPackage.getSkipUpgrade()) {
-          boolean blacklisted = false;
-          for(String prefix : blacklistedPackagePrefixes) {
-            if (aPackage.getName().startsWith(prefix)) {
-              blacklisted = true;
-              break;
-            }
-          }
-          if (! blacklisted) {
-            packages.add(aPackage);
-          }
-        }
-      }
-    }
-    final String packageList = gson.toJson(packages);
-    final String repoList = gson.toJson(repoInfo);
-
-    Map<String, String> params = new HashMap<String, String>(){{
-      put("stack_id", stackId.getStackId());
-      put("repository_version", desiredRepoVersion);
-      put("base_urls", repoList);
-      put(KeyNames.PACKAGE_LIST, packageList);
-    }};
 
-    VersionDefinitionXml xml = null;
-    try {
-      xml = repoVersionEnt.getRepositoryXml();
-    } catch (Exception e) {
-      throw new SystemException(String.format("Could not load xml from repo version %s",
-          repoVersionEnt.getVersion()));
-    }
-
-    if (null != xml && StringUtils.isNotBlank(xml.getPackageVersion(osFamily))) {
-      params.put(KeyNames.PACKAGE_VERSION, xml.getPackageVersion(osFamily));
-    }
+    Map<String, String> roleParams = repoVersionHelper.buildRoleParams(managementController, repoVersionEnt,
+        osFamily, servicesOnHost);
 
     // Create custom action
     RequestResourceFilter filter = new RequestResourceFilter(null, null,
@@ -485,9 +438,11 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
     ActionExecutionContext actionContext = new ActionExecutionContext(
             cluster.getClusterName(), INSTALL_PACKAGES_ACTION,
             Collections.singletonList(filter),
-            params);
+            roleParams);
     actionContext.setTimeout(Short.valueOf(configuration.getDefaultAgentTaskTimeout(true)));
 
+    repoVersionHelper.addCommandRepository(actionContext, osFamily, repoVersionEnt, repoInfo);
+
     String caption = String.format(INSTALL_PACKAGES_FULL_NAME + " on host %s", hostName);
     RequestStageContainer req = createRequest(caption);
 
@@ -534,7 +489,6 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
       if (!forceInstallOnNonMemberHost) {
         hostVersEntity.setState(RepositoryVersionState.INSTALLING);
         hostVersionDAO.merge(hostVersEntity);
-        cluster.recalculateClusterVersionState(repoVersionEnt);
       }
       req.persist();
     } catch (AmbariException e) {
@@ -548,7 +502,7 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
     Stage stage;
     long stageId;
     ActionExecutionContext actionContext;
-    Map<String, String> commandParams = new HashMap();
+    Map<String, String> commandParams = new HashMap<>();
     commandParams.put("version", desiredRepoVersion);
 
     stage = stageFactory.createNew(req.getId(),

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStatusHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStatusHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStatusHelper.java
index 69f1c44..981c039 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStatusHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStatusHelper.java
@@ -18,6 +18,9 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import java.util.Collections;
+import java.util.Set;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.HostRequest;
@@ -29,9 +32,6 @@ import org.apache.ambari.server.state.State;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Collections;
-import java.util.Set;
-
 public class HostStatusHelper {
 
   protected final static Logger LOG =
@@ -72,8 +72,7 @@ public class HostStatusHelper {
     HostResponse hostResponse;
 
     try {
-      HostRequest hostRequest = new HostRequest(hostName, clusterName,
-        Collections.<String, String>emptyMap());
+      HostRequest hostRequest = new HostRequest(hostName, clusterName);
       Set<HostResponse> hosts = HostResourceProvider.getHosts(managementController, hostRequest);
 
       hostResponse = hosts.size() == 1 ? hosts.iterator().next() : null;

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProvider.java
index 689942d..7b03912 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProvider.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -47,13 +47,12 @@ import org.apache.ambari.server.state.CheckHelper;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ServiceInfo;
-import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.UpgradeHelper;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.apache.ambari.server.state.stack.UpgradePack;
 import org.apache.ambari.server.state.stack.upgrade.Direction;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
-
+import org.apache.commons.lang.BooleanUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,7 +65,7 @@ import com.google.inject.Provider;
  */
 @StaticallyInject
 public class PreUpgradeCheckResourceProvider extends ReadOnlyResourceProvider {
-  private static Logger LOG = LoggerFactory.getLogger(PreUpgradeCheckResourceProvider.class);
+  private static final Logger LOG = LoggerFactory.getLogger(PreUpgradeCheckResourceProvider.class);
 
   //----- Property ID constants ---------------------------------------------
 
@@ -79,12 +78,12 @@ public class PreUpgradeCheckResourceProvider extends ReadOnlyResourceProvider {
   public static final String UPGRADE_CHECK_CHECK_TYPE_PROPERTY_ID         = PropertyHelper.getPropertyId("UpgradeChecks", "check_type");
   public static final String UPGRADE_CHECK_CLUSTER_NAME_PROPERTY_ID       = PropertyHelper.getPropertyId("UpgradeChecks", "cluster_name");
   public static final String UPGRADE_CHECK_UPGRADE_TYPE_PROPERTY_ID       = PropertyHelper.getPropertyId("UpgradeChecks", "upgrade_type");
-  public static final String UPGRADE_CHECK_TARGET_STACK_ID                = PropertyHelper.getPropertyId("UpgradeChecks", "target_stack");
   /**
    * Optional parameter to specify the preferred Upgrade Pack to use.
    */
   public static final String UPGRADE_CHECK_UPGRADE_PACK_PROPERTY_ID       = PropertyHelper.getPropertyId("UpgradeChecks", "upgrade_pack");
   public static final String UPGRADE_CHECK_REPOSITORY_VERSION_PROPERTY_ID = PropertyHelper.getPropertyId("UpgradeChecks", "repository_version");
+  public static final String UPGRADE_CHECK_FOR_REVERT_PROPERTY_ID = PropertyHelper.getPropertyId("UpgradeChecks", "for_revert");
 
   @Inject
   private static Provider<Clusters> clustersProvider;
@@ -116,9 +115,9 @@ public class PreUpgradeCheckResourceProvider extends ReadOnlyResourceProvider {
       UPGRADE_CHECK_CHECK_TYPE_PROPERTY_ID,
       UPGRADE_CHECK_CLUSTER_NAME_PROPERTY_ID,
       UPGRADE_CHECK_UPGRADE_TYPE_PROPERTY_ID,
-      UPGRADE_CHECK_TARGET_STACK_ID,
       UPGRADE_CHECK_UPGRADE_PACK_PROPERTY_ID,
-      UPGRADE_CHECK_REPOSITORY_VERSION_PROPERTY_ID);
+      UPGRADE_CHECK_REPOSITORY_VERSION_PROPERTY_ID,
+      UPGRADE_CHECK_FOR_REVERT_PROPERTY_ID);
 
 
   @SuppressWarnings("serial")
@@ -138,16 +137,16 @@ public class PreUpgradeCheckResourceProvider extends ReadOnlyResourceProvider {
     super(propertyIds, keyPropertyIds, managementController);
   }
 
+  @Override
   public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException,
     NoSuchResourceException, NoSuchParentResourceException {
 
-    final Set<Resource> resources = new HashSet<Resource>();
+    final Set<Resource> resources = new HashSet<>();
     final Set<String> requestedIds = getRequestPropertyIds(request, predicate);
     final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
 
     for (Map<String, Object> propertyMap: propertyMaps) {
       final String clusterName = propertyMap.get(UPGRADE_CHECK_CLUSTER_NAME_PROPERTY_ID).toString();
-      StackId targetStack = new StackId(propertyMap.get(UPGRADE_CHECK_TARGET_STACK_ID).toString());
 
       UpgradeType upgradeType = UpgradeType.ROLLING;
       if (propertyMap.containsKey(UPGRADE_CHECK_UPGRADE_TYPE_PROPERTY_ID)) {
@@ -174,12 +173,17 @@ public class PreUpgradeCheckResourceProvider extends ReadOnlyResourceProvider {
 
       if (propertyMap.containsKey(UPGRADE_CHECK_REPOSITORY_VERSION_PROPERTY_ID)) {
         String repositoryVersionId = propertyMap.get(UPGRADE_CHECK_REPOSITORY_VERSION_PROPERTY_ID).toString();
-        RepositoryVersionEntity repositoryVersionEntity = repositoryVersionDAO.findByStackNameAndVersion(targetStack.getStackName(), repositoryVersionId);
+        RepositoryVersionEntity repositoryVersionEntity = repositoryVersionDAO.findByStackNameAndVersion(stackName, repositoryVersionId);
         // set some required properties on the check request
         upgradeCheckRequest.setRepositoryVersion(repositoryVersionId);
         upgradeCheckRequest.setTargetStackId(repositoryVersionEntity.getStackId());
       }
 
+      if (propertyMap.containsKey(UPGRADE_CHECK_FOR_REVERT_PROPERTY_ID)) {
+        Boolean forRevert = BooleanUtils.toBooleanObject(propertyMap.get(UPGRADE_CHECK_FOR_REVERT_PROPERTY_ID).toString());
+        upgradeCheckRequest.setRevert(forRevert);
+      }
+
       //ambariMetaInfo.getStack(stackName, cluster.getCurrentStackVersion().getStackVersion()).getUpgradePacks()
       // TODO AMBARI-12698, filter the upgrade checks to run based on the stack and upgrade type, or the upgrade pack.
       UpgradePack upgradePack = null;
@@ -188,7 +192,7 @@ public class PreUpgradeCheckResourceProvider extends ReadOnlyResourceProvider {
       try{
         // Hint: PreChecks currently executing only before UPGRADE direction
         upgradePack = upgradeHelper.get().suggestUpgradePack(clusterName, sourceStackVersion,
-            upgradeCheckRequest.getRepositoryVersion(), Direction.UPGRADE, upgradeType, targetStack.getStackName(), preferredUpgradePackName);
+            upgradeCheckRequest.getRepositoryVersion(), Direction.UPGRADE, upgradeType, preferredUpgradePackName);
       } catch (AmbariException e) {
         throw new SystemException(e.getMessage(), e);
       }
@@ -226,7 +230,6 @@ public class PreUpgradeCheckResourceProvider extends ReadOnlyResourceProvider {
         setResourceProperty(resource, UPGRADE_CHECK_CHECK_TYPE_PROPERTY_ID, prerequisiteCheck.getType(), requestedIds);
         setResourceProperty(resource, UPGRADE_CHECK_CLUSTER_NAME_PROPERTY_ID, prerequisiteCheck.getClusterName(), requestedIds);
         setResourceProperty(resource, UPGRADE_CHECK_UPGRADE_TYPE_PROPERTY_ID, upgradeType, requestedIds);
-        setResourceProperty(resource, UPGRADE_CHECK_TARGET_STACK_ID, targetStack.getStackId(), requestedIds);
         if (upgradeCheckRequest.getRepositoryVersion() != null) {
           setResourceProperty(resource, UPGRADE_CHECK_REPOSITORY_VERSION_PROPERTY_ID, upgradeCheckRequest.getRepositoryVersion(), requestedIds);
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
index 46b0cb7..34b7b92 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -25,6 +25,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 org.apache.ambari.server.AmbariException;
@@ -43,10 +44,10 @@ 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.controller.utilities.PropertyHelper;
-import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
+import org.apache.ambari.server.orm.dao.HostVersionDAO;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
-import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
+import org.apache.ambari.server.orm.entities.HostVersionEntity;
 import org.apache.ambari.server.orm.entities.OperatingSystemEntity;
 import org.apache.ambari.server.orm.entities.RepositoryEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
@@ -55,7 +56,6 @@ import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.security.authorization.AuthorizationHelper;
 import org.apache.ambari.server.security.authorization.ResourceType;
 import org.apache.ambari.server.security.authorization.RoleAuthorization;
-import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.OperatingSystemInfo;
 import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.ServiceInfo;
@@ -64,14 +64,14 @@ import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.repository.ManifestServiceInfo;
 import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.lang.StringUtils;
 
-import com.google.common.collect.Lists;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Sets;
 import com.google.gson.Gson;
 import com.google.inject.Inject;
-import com.google.inject.Provider;
 import com.google.inject.persist.Transactional;
 
 /**
@@ -101,11 +101,7 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
   public static final String REPOSITORY_VERSION_HAS_CHILDREN                   = "RepositoryVersions/has_children";
 
   @SuppressWarnings("serial")
-  private static Set<String> pkPropertyIds = new HashSet<String>() {
-    {
-      add(REPOSITORY_VERSION_ID_PROPERTY_ID);
-    }
-  };
+  private static Set<String> pkPropertyIds = Sets.newHashSet(REPOSITORY_VERSION_ID_PROPERTY_ID);
 
   @SuppressWarnings("serial")
   public static Set<String> propertyIds = Sets.newHashSet(
@@ -126,13 +122,11 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
       REPOSITORY_VERSION_STACK_SERVICES);
 
   @SuppressWarnings("serial")
-  public static Map<Type, String> keyPropertyIds = new HashMap<Type, String>() {
-    {
-      put(Type.Stack, REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID);
-      put(Type.StackVersion, REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID);
-      put(Type.RepositoryVersion, REPOSITORY_VERSION_ID_PROPERTY_ID);
-    }
-  };
+  public static Map<Type, String> keyPropertyIds = new ImmutableMap.Builder<Type, String>()
+      .put(Type.Stack, REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID)
+      .put(Type.StackVersion, REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID)
+      .put(Type.RepositoryVersion, REPOSITORY_VERSION_ID_PROPERTY_ID)
+      .build();
 
   @Inject
   private Gson gson;
@@ -141,23 +135,20 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
   private RepositoryVersionDAO repositoryVersionDAO;
 
   @Inject
-  private ClusterVersionDAO clusterVersionDAO;
-
-  @Inject
   private AmbariMetaInfo ambariMetaInfo;
 
   @Inject
   private RepositoryVersionHelper repositoryVersionHelper;
 
-  @Inject
-  private Provider<Clusters> clusters;
-
   /**
    * Data access object used for lookup up stacks.
    */
   @Inject
   private StackDAO stackDAO;
 
+  @Inject
+  HostVersionDAO hostVersionDAO;
+
   /**
    * Create a new resource provider.
    *
@@ -226,12 +217,12 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
   @Override
   protected Set<Resource> getResourcesAuthorized(Request request, Predicate predicate)
       throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
-    final Set<Resource> resources = new HashSet<Resource>();
+    final Set<Resource> resources = new HashSet<>();
     final Set<String> requestedIds = getRequestPropertyIds(request, predicate);
     final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
 
 
-    List<RepositoryVersionEntity> requestedEntities = new ArrayList<RepositoryVersionEntity>();
+    List<RepositoryVersionEntity> requestedEntities = new ArrayList<>();
     for (Map<String, Object> propertyMap: propertyMaps) {
       final StackId stackId = getStackInformationFromUrl(propertyMap);
 
@@ -358,19 +349,6 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
 
           repositoryVersionDAO.merge(entity);
 
-          //
-          // Update metaInfo table as well
-          //
-          if (operatingSystemEntities != null) {
-            String entityStackName = entity.getStackName();
-            String entityStackVersion = entity.getStackVersion();
-            for (OperatingSystemEntity osEntity : operatingSystemEntities) {
-              List<RepositoryEntity> repositories = osEntity.getRepositories();
-              for (RepositoryEntity repository : repositories) {
-                ambariMetaInfo.updateRepoBaseURL(entityStackName, entityStackVersion, osEntity.getOsType(), repository.getRepositoryId(), repository.getBaseUrl());
-              }
-            }
-          }
         }
         return null;
       }
@@ -384,7 +362,7 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
       throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
     final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
 
-    final List<RepositoryVersionEntity> entitiesToBeRemoved = new ArrayList<RepositoryVersionEntity>();
+    final List<RepositoryVersionEntity> entitiesToBeRemoved = new ArrayList<>();
     for (Map<String, Object> propertyMap : propertyMaps) {
       final Long id;
       try {
@@ -398,22 +376,34 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
         throw new NoSuchResourceException("There is no repository version with id " + id);
       }
 
-      StackEntity stackEntity = entity.getStack();
-      String stackName = stackEntity.getStackName();
-      String stackVersion = stackEntity.getStackVersion();
-
-      final List<ClusterVersionEntity> clusterVersionEntities = clusterVersionDAO.findByStackAndVersion(
-          stackName, stackVersion, entity.getVersion());
-
-      final List<RepositoryVersionState> forbiddenToDeleteStates = Lists.newArrayList(
+      final Set<RepositoryVersionState> forbiddenToDeleteStates = Sets.newHashSet(
           RepositoryVersionState.CURRENT,
           RepositoryVersionState.INSTALLED,
           RepositoryVersionState.INSTALLING);
-      for (ClusterVersionEntity clusterVersionEntity : clusterVersionEntities) {
-        if (clusterVersionEntity.getRepositoryVersion().getId().equals(id) && forbiddenToDeleteStates.contains(clusterVersionEntity.getState())) {
-          throw new SystemException("Repository version can't be deleted as it is " +
-              clusterVersionEntity.getState().name() + " on cluster " + clusterVersionEntity.getClusterEntity().getClusterName());
+
+      List<HostVersionEntity> hostVersions = hostVersionDAO.findByRepositoryAndStates(
+          entity, forbiddenToDeleteStates);
+
+      if (CollectionUtils.isNotEmpty(hostVersions)) {
+        Map<RepositoryVersionState, Set<String>> hostsInUse = new HashMap<>();
+
+        for (HostVersionEntity hostVersion : hostVersions) {
+          if (!hostsInUse.containsKey(hostVersion.getState())) {
+            hostsInUse.put(hostVersion.getState(), new HashSet<String>());
+          }
+
+          hostsInUse.get(hostVersion.getState()).add(hostVersion.getHostName());
+        }
+
+        Set<String> errors = new HashSet<>();
+        for (Entry<RepositoryVersionState, Set<String>> entry : hostsInUse.entrySet()) {
+          errors.add(String.format("%s on %s", entry.getKey(), StringUtils.join(entry.getValue(), ", ")));
         }
+
+
+        throw new SystemException(
+            String.format("Repository version can't be deleted as it is used by the following hosts: %s",
+                StringUtils.join(errors, ';')));
       }
 
       entitiesToBeRemoved.add(entity);
@@ -456,7 +446,7 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
     final String requiredStackId = requiredStack.getStackId();
 
     // List of all repo urls that are already added at stack
-    Set<String> existingRepoUrls = new HashSet<String>();
+    Set<String> existingRepoUrls = new HashSet<>();
     List<RepositoryVersionEntity> existingRepoVersions = dao.findByStack(requiredStack);
     for (RepositoryVersionEntity existingRepoVersion : existingRepoVersions) {
       for (OperatingSystemEntity operatingSystemEntity : existingRepoVersion.getOperatingSystems()) {
@@ -469,12 +459,12 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
     }
 
     // check that repositories contain only supported operating systems
-    final Set<String> osSupported = new HashSet<String>();
+    final Set<String> osSupported = new HashSet<>();
     for (OperatingSystemInfo osInfo: metaInfo.getOperatingSystems(requiredStackName, requiredStackVersion)) {
       osSupported.add(osInfo.getOsType());
     }
 
-    final Set<String> osRepositoryVersion = new HashSet<String>();
+    final Set<String> osRepositoryVersion = new HashSet<>();
 
     for (OperatingSystemEntity os: repositoryVersion.getOperatingSystems()) {
       osRepositoryVersion.add(os.getOsType());

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RootServiceHostComponentResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RootServiceHostComponentResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RootServiceHostComponentResourceProvider.java
index 51aaeec..7617e61 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RootServiceHostComponentResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RootServiceHostComponentResourceProvider.java
@@ -35,14 +35,14 @@ 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.Resource;
+import org.apache.ambari.server.controller.spi.Resource.Type;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
-import org.apache.ambari.server.controller.spi.Resource.Type;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 
 public class RootServiceHostComponentResourceProvider extends
     ReadOnlyResourceProvider {
-  
+
   public static final String SERVICE_NAME_PROPERTY_ID = PropertyHelper
       .getPropertyId("RootServiceHostComponents", "service_name");
   public static final String HOST_NAME_PROPERTY_ID = PropertyHelper
@@ -55,9 +55,9 @@ public class RootServiceHostComponentResourceProvider extends
       .getPropertyId("RootServiceHostComponents", "component_state");
   public static final String PROPERTIES_PROPERTY_ID = PropertyHelper
       .getPropertyId("RootServiceHostComponents", "properties");
-  
-  
-  private Set<String> pkPropertyIds = new HashSet<String>(
+
+
+  private Set<String> pkPropertyIds = new HashSet<>(
       Arrays.asList(new String[] { SERVICE_NAME_PROPERTY_ID, HOST_NAME_PROPERTY_ID, COMPONENT_NAME_PROPERTY_ID }));
 
 
@@ -67,13 +67,13 @@ public class RootServiceHostComponentResourceProvider extends
     super(propertyIds, keyPropertyIds, managementController);
   }
 
-  
+
   @Override
   public Set<Resource> getResources(Request request, Predicate predicate)
       throws SystemException, UnsupportedPropertyException,
       NoSuchResourceException, NoSuchParentResourceException {
 
-    final Set<RootServiceHostComponentRequest> requests = new HashSet<RootServiceHostComponentRequest>();
+    final Set<RootServiceHostComponentRequest> requests = new HashSet<>();
 
     if (predicate == null) {
       requests.add(getRequest(Collections.<String, Object>emptyMap()));
@@ -92,26 +92,26 @@ public class RootServiceHostComponentResourceProvider extends
       }
     });
 
-    Set<Resource> resources = new HashSet<Resource>();
+    Set<Resource> resources = new HashSet<>();
 
     for (RootServiceHostComponentResponse response : responses) {
       Resource resource = new ResourceImpl(Resource.Type.RootServiceHostComponent);
 
       setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID,
           response.getServiceName(), requestedIds);
-      
+
       setResourceProperty(resource, HOST_NAME_PROPERTY_ID,
           response.getHostName(), requestedIds);
-      
+
       setResourceProperty(resource, COMPONENT_NAME_PROPERTY_ID,
           response.getComponentName(), requestedIds);
-      
+
       setResourceProperty(resource, COMPONENT_STATE_PROPERTY_ID,
           response.getComponentState(), requestedIds);
-      
+
       setResourceProperty(resource, COMPONENT_VERSION_PROPERTY_ID,
           response.getComponentVersion(), requestedIds);
-      
+
       setResourceProperty(resource, PROPERTIES_PROPERTY_ID,
           response.getProperties(), requestedIds);
 
@@ -120,7 +120,7 @@ public class RootServiceHostComponentResourceProvider extends
 
     return resources;
   }
-  
+
   private RootServiceHostComponentRequest getRequest(Map<String, Object> properties) {
     return new RootServiceHostComponentRequest((String) properties.get(SERVICE_NAME_PROPERTY_ID),
                                                (String) properties.get(HOST_NAME_PROPERTY_ID),
@@ -135,14 +135,10 @@ public class RootServiceHostComponentResourceProvider extends
   // Get the root service host components for the given set of requests
   protected Set<RootServiceHostComponentResponse> getRootServiceHostComponents(
       Set<RootServiceHostComponentRequest> requests) throws AmbariException {
-    Set<RootServiceHostComponentResponse> response = new HashSet<RootServiceHostComponentResponse>();
+    Set<RootServiceHostComponentResponse> response = new HashSet<>();
     for (RootServiceHostComponentRequest request : requests) {
-      String serviceName = request.getServiceName();
       try {
         Set<RootServiceHostComponentResponse> rootServiceHostComponents = getRootServiceHostComponents(request);
-        for (RootServiceHostComponentResponse rootServiceHostComponentResponse : rootServiceHostComponents ) {
-          rootServiceHostComponentResponse.setServiceName(serviceName);
-        }
 
         response.addAll(rootServiceHostComponents);
       } catch (AmbariException e) {
@@ -163,7 +159,7 @@ public class RootServiceHostComponentResourceProvider extends
     AmbariManagementController controller = getManagementController();
     //Get all hosts of all clusters
     Set<HostResponse> hosts = HostResourceProvider.getHosts(controller,
-        new HostRequest(request.getHostName(), null, null));
+        new HostRequest(request.getHostName(), null));
 
     return controller.getRootServiceResponseFactory().getRootServiceHostComponent(request, hosts);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
index 2a91bfe..f960490 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
@@ -105,7 +105,7 @@ public class ScaleClusterRequest extends BaseClusterRequest {
       throw new InvalidTopologyTemplateException("Blueprint name must be specified for all host groups");
     }
 
-    String hgName = String.valueOf(properties.get(HostResourceProvider.HOSTGROUP_PROPERTY_ID));
+    String hgName = String.valueOf(properties.get(HostResourceProvider.HOST_GROUP_PROPERTY_ID));
     if (hgName == null || hgName.equals("null")) {
       throw new InvalidTopologyTemplateException("A name must be specified for all host groups");
     }
@@ -180,8 +180,6 @@ public class ScaleClusterRequest extends BaseClusterRequest {
     String rackInfo = null;
     if (properties.containsKey(HostResourceProvider.HOST_RACK_INFO_PROPERTY_ID)) {
       rackInfo = (String) properties.get(HostResourceProvider.HOST_RACK_INFO_PROPERTY_ID);
-    } else if (properties.containsKey(HostResourceProvider.HOST_RACK_INFO_NO_CATEGORY_PROPERTY_ID)) {
-      rackInfo = (String) properties.get(HostResourceProvider.HOST_RACK_INFO_NO_CATEGORY_PROPERTY_ID);
     } else {
       LOGGER.debug("No rack info provided");
     }
@@ -220,9 +218,7 @@ public class ScaleClusterRequest extends BaseClusterRequest {
   //todo: this was copied exactly from HostResourceProvider
   private String getHostNameFromProperties(Map<String, Object> properties) {
     String hostName = (String) properties.get(HostResourceProvider.HOST_NAME_PROPERTY_ID);
-    if (hostName == null) {
-      hostName = (String) properties.get(HostResourceProvider.HOST_NAME_NO_CATEGORY_PROPERTY_ID);
-    }
+
     return hostName;
   }
 


Mime
View raw message