Explorar o código

AMBARI-7019. sqoop-env and other configs exists for unavailable services(after upgrade from ambari 1.6.1 -> 1.7.0).(vbrodetskyi)

Vitaly Brodetskyi %!s(int64=11) %!d(string=hai) anos
pai
achega
926acf4fc6

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -657,7 +657,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
     if(request.getType().equals(Configuration.GLOBAL_CONFIG_TAG)) {
       Map<String, Map<String, String>> configTypes = new HashMap<String, Map<String, String>>();
       configTypes.put(Configuration.GLOBAL_CONFIG_TAG, request.getProperties());
-      configHelper.moveDeprecatedGlobals(cluster.getCurrentStackVersion(), configTypes);
+      configHelper.moveDeprecatedGlobals(cluster.getCurrentStackVersion(), configTypes, cluster.getClusterName());
 
       for(Map.Entry<String, Map<String, String>> configType : configTypes.entrySet()) {
         String configTypeName = configType.getKey();

+ 3 - 3
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java

@@ -870,9 +870,9 @@ public class ClusterResourceProvider extends BaseBlueprintProcessor {
    * @param blueprintConfigurations  map of blueprint configurations keyed by type
    */
   private void handleGlobalsBackwardsCompability(Stack stack,
-      Map<String, Map<String, String>> blueprintConfigurations) {
+      Map<String, Map<String, String>> blueprintConfigurations, String clusterName) {
     StackId stackId = new StackId(stack.getName(), stack.getVersion());
-    configHelper.moveDeprecatedGlobals(stackId, blueprintConfigurations);
+    configHelper.moveDeprecatedGlobals(stackId, blueprintConfigurations, clusterName);
   }
 
   /**
@@ -1051,7 +1051,7 @@ public class ClusterResourceProvider extends BaseBlueprintProcessor {
       HostGroupEntity entity = group.getEntity();
       Map<String, Map<String, Config>> groupConfigs = new HashMap<String, Map<String, Config>>();
       
-      handleGlobalsBackwardsCompability(stack, group.getConfigurationProperties());
+      handleGlobalsBackwardsCompability(stack, group.getConfigurationProperties(), clusterName);
       for (Map.Entry<String, Map<String, String>> entry: group.getConfigurationProperties().entrySet()) {
         String type = entry.getKey();
         String service = stack.getServiceForConfigType(type);

+ 6 - 6
ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java

@@ -414,14 +414,14 @@ public class ConfigHelper {
    * @param stackId
    * @param propertyName
    */
-  public Set<String> findConfigTypesByPropertyName(StackId stackId, String propertyName) throws AmbariException {
+  public Set<String> findConfigTypesByPropertyName(StackId stackId, String propertyName, String clusterName) throws AmbariException {
     StackInfo stack = ambariMetaInfo.getStackInfo(stackId.getStackName(),
         stackId.getStackVersion());
     
     Set<String> result = new HashSet<String>();
-    
-    for(ServiceInfo serviceInfo:stack.getServices()) {
-      Set<PropertyInfo> stackProperties = ambariMetaInfo.getProperties(stack.getName(), stack.getVersion(), serviceInfo.getName());
+
+    for(Service service : clusters.getCluster(clusterName).getServices().values()) {
+      Set<PropertyInfo> stackProperties = ambariMetaInfo.getProperties(stack.getName(), stack.getVersion(), service.getName());
       
       for (PropertyInfo stackProperty : stackProperties) {
         if(stackProperty.getName().equals(propertyName)) {
@@ -488,7 +488,7 @@ public class ConfigHelper {
    *
    * @param configurations  map of configurations keyed by type
    */
-  public void moveDeprecatedGlobals(StackId stackId, Map<String, Map<String, String>> configurations) {
+  public void moveDeprecatedGlobals(StackId stackId, Map<String, Map<String, String>> configurations, String clusterName) {
     Map<String, String> globalConfigurations = new HashMap<String, String>();
     
     if(configurations.get(Configuration.GLOBAL_CONFIG_TAG) == null ||
@@ -508,7 +508,7 @@ public class ConfigHelper {
       
       Set<String> newConfigTypes = null;
       try{
-        newConfigTypes = this.findConfigTypesByPropertyName(stackId, propertyName);
+        newConfigTypes = this.findConfigTypesByPropertyName(stackId, propertyName, clusterName);
       } catch(AmbariException e) {
         LOG.error("Exception while getting configurations from the stacks", e);
         return;

+ 4 - 2
ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java

@@ -812,7 +812,8 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
 
     if (clusterMap != null && !clusterMap.isEmpty()) {
       for (final Cluster cluster : clusterMap.values()) {
-        Set<String> configTypes = configHelper.findConfigTypesByPropertyName(cluster.getCurrentStackVersion(), CONTENT_FIELD_NAME);
+        Set<String> configTypes = configHelper.findConfigTypesByPropertyName(cluster.getCurrentStackVersion(),
+                CONTENT_FIELD_NAME, cluster.getClusterName());
 
         for(String configType:configTypes) {
           if(!configType.endsWith(ENV_CONFIGS_POSTFIX)) {
@@ -853,7 +854,8 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
           String propertyName = property.getKey();
           String propertyValue = property.getValue();
 
-          Set<String> newConfigTypes = configHelper.findConfigTypesByPropertyName(cluster.getCurrentStackVersion(), propertyName);
+          Set<String> newConfigTypes = configHelper.findConfigTypesByPropertyName(cluster.getCurrentStackVersion(),
+                  propertyName, cluster.getClusterName());
           // if it's custom user service global.xml can be still there.
           newConfigTypes.remove(Configuration.GLOBAL_CONFIG_TAG);
 

+ 3 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

@@ -8936,6 +8936,7 @@ public class AmbariManagementControllerTest {
 
       Set<ServiceRequest> serviceRequests = new HashSet<ServiceRequest>();
       serviceRequests.add(new ServiceRequest("c1", "HDFS", null));
+      serviceRequests.add(new ServiceRequest("c1", "HIVE", null));
 
       ServiceResourceProviderTest.createServices(amc, serviceRequests);
 
@@ -9144,9 +9145,10 @@ public class AmbariManagementControllerTest {
       ServiceResourceProviderTest.updateServices(amc, serviceRequests, mapRequestProps, true, false);
       serviceRequests.clear();
       serviceRequests.add(new ServiceRequest("c1", null, null));
-      org.junit.Assert.assertEquals(1, ServiceResourceProviderTest.getServices(amc, serviceRequests).size());
+      org.junit.Assert.assertEquals(2, ServiceResourceProviderTest.getServices(amc, serviceRequests).size());
       serviceRequests.clear();
       serviceRequests.add(new ServiceRequest("c1", "HDFS", null));
+      serviceRequests.add(new ServiceRequest("c1", "HIVE", null));
       ServiceResourceProviderTest.deleteServices(amc, serviceRequests);
       serviceRequests.clear();
       serviceRequests.add(new ServiceRequest("c1", null, null));

+ 5 - 4
ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java

@@ -224,7 +224,7 @@ public class UpgradeCatalog170Test {
     Injector injector = createNiceMock(Injector.class);
     ConfigHelper configHelper = createNiceMock(ConfigHelper.class);
     AmbariManagementController amc = createNiceMock(AmbariManagementController.class);
-    Cluster cluster = createStrictMock(Cluster.class);
+    Cluster cluster = createNiceMock(Cluster.class);
     Clusters clusters = createStrictMock(Clusters.class);
     Config config = createStrictMock(Config.class);
     Config pigConfig = createStrictMock(Config.class);
@@ -323,9 +323,10 @@ public class UpgradeCatalog170Test {
     expect(cluster.getDesiredConfigByType("global")).andReturn(config).anyTimes();
     expect(config.getProperties()).andReturn(globalConfigs).anyTimes();
     expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.1")).anyTimes();
-    expect(configHelper.findConfigTypesByPropertyName(new StackId("HDP", "2.1"), "prop1")).andReturn(envDicts).once();
-    expect(configHelper.findConfigTypesByPropertyName(new StackId("HDP", "2.1"), "smokeuser_keytab")).andReturn(new HashSet<String>()).once();
-    expect(configHelper.findConfigTypesByPropertyName(new StackId("HDP", "2.1"), "content")).andReturn(envDicts).once();
+    expect(cluster.getClusterName()).andReturn("c1").anyTimes();
+    expect(configHelper.findConfigTypesByPropertyName(new StackId("HDP", "2.1"), "prop1", "c1")).andReturn(envDicts).once();
+    expect(configHelper.findConfigTypesByPropertyName(new StackId("HDP", "2.1"), "smokeuser_keytab", "c1")).andReturn(new HashSet<String>()).once();
+    expect(configHelper.findConfigTypesByPropertyName(new StackId("HDP", "2.1"), "content", "c1")).andReturn(envDicts).once();
     expect(configHelper.getPropertyValueFromStackDefenitions(cluster, "hadoop-env", "content")).andReturn("env file contents").once();
 
     expect(injector.getInstance(UserDAO.class)).andReturn(userDAO).anyTimes();