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-22014. Patch upgrade is going into incorrect state during package installation with invalid VDF (ncole)
Date Mon, 25 Sep 2017 20:14:40 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk b653ee0a5 -> 4c49b4bd0


AMBARI-22014. Patch upgrade is going into incorrect state during package installation with
invalid VDF (ncole)


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

Branch: refs/heads/trunk
Commit: 4c49b4bd006cdd3929f5e341552b200af608bc32
Parents: b653ee0
Author: Nate Cole <ncole@hortonworks.com>
Authored: Mon Sep 25 15:23:42 2017 -0400
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Mon Sep 25 16:14:35 2017 -0400

----------------------------------------------------------------------
 .../server/controller/ControllerModule.java     |   2 +
 .../controller/ResourceProviderFactory.java     |   6 +-
 .../AbstractControllerResourceProvider.java     |   2 +-
 .../ClusterStackVersionResourceProvider.java    |   9 +-
 .../internal/DefaultProviderModule.java         |   2 -
 ...ClusterStackVersionResourceProviderTest.java | 223 ++++++-------------
 6 files changed, 87 insertions(+), 157 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4c49b4bd/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index e151e63..968e9b6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -62,6 +62,7 @@ import org.apache.ambari.server.cleanup.ClasspathScannerUtils;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.configuration.Configuration.ConnectionPoolType;
 import org.apache.ambari.server.configuration.Configuration.DatabaseType;
+import org.apache.ambari.server.controller.internal.ClusterStackVersionResourceProvider;
 import org.apache.ambari.server.controller.internal.ComponentResourceProvider;
 import org.apache.ambari.server.controller.internal.CredentialResourceProvider;
 import org.apache.ambari.server.controller.internal.HostComponentResourceProvider;
@@ -467,6 +468,7 @@ public class ControllerModule extends AbstractModule {
         .implement(ResourceProvider.class, Names.named("credential"), CredentialResourceProvider.class)
         .implement(ResourceProvider.class, Names.named("kerberosDescriptor"), KerberosDescriptorResourceProvider.class)
         .implement(ResourceProvider.class, Names.named("upgrade"), UpgradeResourceProvider.class)
+        .implement(ResourceProvider.class, Names.named("clusterStackVersion"), ClusterStackVersionResourceProvider.class)
         .build(ResourceProviderFactory.class));
 
     install(new FactoryModuleBuilder().implement(

http://git-wip-us.apache.org/repos/asf/ambari/blob/4c49b4bd/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
index 3912138..9cd1d74 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
@@ -22,6 +22,7 @@ package org.apache.ambari.server.controller;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.ambari.server.controller.internal.ClusterStackVersionResourceProvider;
 import org.apache.ambari.server.controller.internal.UpgradeResourceProvider;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.Resource.Type;
@@ -68,4 +69,7 @@ public interface ResourceProviderFactory {
   @Named("upgrade")
   UpgradeResourceProvider getUpgradeResourceProvider(AmbariManagementController managementController);
 
-}
+  @Named("clusterStackVersion")
+  ClusterStackVersionResourceProvider getClusterStackVersionResourceProvider(AmbariManagementController
managementController);
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/4c49b4bd/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
index b35b2a8..b4b13eb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
@@ -183,7 +183,7 @@ public abstract class AbstractControllerResourceProvider extends AbstractAuthori
       case StackVersion:
         return new StackVersionResourceProvider(propertyIds, keyPropertyIds, managementController);
       case ClusterStackVersion:
-        return new ClusterStackVersionResourceProvider(managementController);
+        return resourceProviderFactory.getClusterStackVersionResourceProvider(managementController);
       case HostStackVersion:
         return new HostStackVersionResourceProvider(managementController);
       case StackService:

http://git-wip-us.apache.org/repos/asf/ambari/blob/4c49b4bd/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
index f8a679a..ba5a4e7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
@@ -213,6 +213,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
   /**
    * Constructor.
    */
+  @Inject
   public ClusterStackVersionResourceProvider(
           AmbariManagementController managementController) {
     super(propertyIds, keyPropertyIds, managementController);
@@ -454,7 +455,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
     }
   }
 
-  @Transactional
+  @Transactional(rollbackOn = {RuntimeException.class, SystemException.class, AmbariException.class})
   RequestStatus createOrUpdateHostVersions(Cluster cluster,
       RepositoryVersionEntity repoVersionEntity, VersionDefinitionXml versionDefinitionXml,
       StackId stackId, boolean forceInstalled, Map<String, Object> propertyMap)
@@ -666,11 +667,13 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
     }
   }
 
-  private ActionExecutionContext getHostVersionInstallCommand(RepositoryVersionEntity repoVersion,
+  @Transactional
+  ActionExecutionContext getHostVersionInstallCommand(RepositoryVersionEntity repoVersion,
       Cluster cluster, AmbariManagementController managementController, AmbariMetaInfo ami,
       final StackId stackId, Set<String> repoServices, Stage stage1, Host host)
           throws SystemException {
 
+
     // Determine repositories for host
     String osFamily = host.getOsFamily();
 
@@ -684,7 +687,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
 
     if (null == osEntity || CollectionUtils.isEmpty(osEntity.getRepositories())) {
       throw new SystemException(String.format("Repositories for os type %s are " +
-          "not defined. Repo version=%s, stackId=%s",
+          "not defined for version %s of Stack %s.",
             osFamily, repoVersion.getVersion(), stackId));
     }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/4c49b4bd/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
index 074f8e1..5e5bff5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
@@ -106,8 +106,6 @@ public class DefaultProviderModule extends AbstractProviderModule {
         return new UpgradeItemResourceProvider(managementController);
       case UpgradeSummary:
         return new UpgradeSummaryResourceProvider(managementController);
-      case ClusterStackVersion:
-        return new ClusterStackVersionResourceProvider(managementController);
       case PreUpgradeCheck:
         return new PreUpgradeCheckResourceProvider(managementController);
       case HostStackVersion:

http://git-wip-us.apache.org/repos/asf/ambari/blob/4c49b4bd/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
index c766f1e..a1415703 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
@@ -31,7 +31,6 @@ import static org.easymock.EasyMock.verify;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.lang.reflect.Field;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -68,6 +67,7 @@ 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.Resource.Type;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
@@ -117,6 +117,7 @@ import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
@@ -124,7 +125,6 @@ import com.google.gson.JsonParser;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.Provider;
 import com.google.inject.util.Modules;
 
 import junit.framework.AssertionFailedError;
@@ -146,6 +146,10 @@ public class ClusterStackVersionResourceProviderTest {
   private HostVersionDAO hostVersionDAO;
   private HostComponentStateDAO hostComponentStateDAO;
 
+  private Clusters clusters;
+  private ActionManager actionManager;
+  private AmbariManagementController managementController;
+
   public static final String OS_JSON = "[\n" +
           "   {\n" +
           "      \"repositories\":[\n" +
@@ -179,6 +183,10 @@ public class ClusterStackVersionResourceProviderTest {
     configuration = new Configuration(properties);
     stageFactory = createNiceMock(StageFactory.class);
 
+    clusters = createNiceMock(Clusters.class);
+    actionManager = createNiceMock(ActionManager.class);
+    managementController = createMock(AmbariManagementController.class);
+
     // Initialize injector
     injector = Guice.createInjector(Modules.override(inMemoryModule).with(new MockModule()));
     injector.getInstance(GuiceJpaInitializer.class);
@@ -208,10 +216,6 @@ public class ClusterStackVersionResourceProviderTest {
   }
 
   private void testCreateResources(Authentication authentication) throws Exception {
-    Resource.Type type = Resource.Type.ClusterStackVersion;
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Clusters clusters = createNiceMock(Clusters.class);
     Cluster cluster = createNiceMock(Cluster.class);
     Map<String, String> hostLevelParams = new HashMap<>();
     StackId stackId = new StackId("HDP", "2.0.1");
@@ -258,28 +262,15 @@ public class ClusterStackVersionResourceProviderTest {
     expect(schAMS.getServiceName()).andReturn("AMBARI_METRICS").anyTimes();
     expect(schAMS.getServiceComponentName()).andReturn("METRICS_COLLECTOR").anyTimes();
     // First host contains versionable components
-    final List<ServiceComponentHost> schsH1 = new ArrayList<ServiceComponentHost>(){{
-      add(schDatanode);
-      add(schNamenode);
-      add(schAMS);
-    }};
+    final List<ServiceComponentHost> schsH1 = Lists.newArrayList(schDatanode, schNamenode,
schAMS);
     // Second host does not contain versionable components
-    final List<ServiceComponentHost> schsH2 = new ArrayList<ServiceComponentHost>(){{
-      add(schAMS);
-    }};
-
+    final List<ServiceComponentHost> schsH2 = Lists.newArrayList(schAMS);
 
     ServiceOsSpecific.Package hdfsPackage = new ServiceOsSpecific.Package();
     hdfsPackage.setName("hdfs");
     List<ServiceOsSpecific.Package> packages = Collections.singletonList(hdfsPackage);
 
-    ActionManager actionManager = createNiceMock(ActionManager.class);
-
     RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
-    ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
-    ResourceProvider csvResourceProvider = createNiceMock(ClusterStackVersionResourceProvider.class);
-
-    AbstractControllerResourceProvider.init(resourceProviderFactory);
 
     Map<String, Map<String, String>> hostConfigTags = new HashMap<>();
     expect(configHelper.getEffectiveDesiredTags(anyObject(ClusterImpl.class), anyObject(String.class))).andReturn(hostConfigTags);
@@ -290,12 +281,10 @@ public class ClusterStackVersionResourceProviderTest {
     expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
     expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
     expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
-            EasyMock.anyObject(), anyObject(String.class))).
-            andReturn(packages).times((hostCount - 1) * 2); // 1 host has no versionable
components, other hosts have 2 services
-//            // that's why we don't send commands to it
-
-    expect(resourceProviderFactory.getHostResourceProvider(EasyMock.anyObject(), EasyMock.anyObject(),
-            eq(managementController))).andReturn(csvResourceProvider).anyTimes();
+            EasyMock.<Map<String, String>>anyObject(), anyObject(String.class))).
+            andReturn(packages).anyTimes();
+    expect(managementController.findConfigurationTagsWithOverrides(anyObject(Cluster.class),
EasyMock.anyString()))
+      .andReturn(new HashMap<String, Map<String, String>>()).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
     expect(clusters.getHostsForCluster(anyObject(String.class))).andReturn(
@@ -357,18 +346,14 @@ public class ClusterStackVersionResourceProviderTest {
     StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class));
     StageUtils.setConfiguration(injector.getInstance(Configuration.class));
 
+    ResourceProvider provider = createProvider(managementController);
+    injector.injectMembers(provider);
+
     // replay
-    replay(managementController, response, clusters, resourceProviderFactory, csvResourceProvider,
+    replay(managementController, response, clusters,
             cluster, repositoryVersionDAOMock, configHelper, schDatanode, schNamenode, schAMS,
actionManager,
             executionCommand, executionCommandWrapper,stage, stageFactory);
 
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        type,
-        PropertyHelper.getPropertyIds(type),
-        PropertyHelper.getKeyPropertyIds(type),
-        managementController);
-
-    injector.injectMembers(provider);
 
     // add the property map to a set for the request.  add more maps for multiple creates
     Set<Map<String, Object>> propertySet = new LinkedHashSet<>();
@@ -618,10 +603,6 @@ public class ClusterStackVersionResourceProviderTest {
    }
 
    private void testCreateResourcesWithRepoDefinition(Authentication authentication) throws
Exception {
-    Resource.Type type = Resource.Type.ClusterStackVersion;
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Clusters clusters = createNiceMock(Clusters.class);
     Cluster cluster = createNiceMock(Cluster.class);
     StackId stackId = new StackId("HDP", "2.0.1");
 
@@ -706,7 +687,7 @@ public class ClusterStackVersionResourceProviderTest {
 
     RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
     ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
-    ResourceProvider csvResourceProvider = createNiceMock(ClusterStackVersionResourceProvider.class);
+    ResourceProvider csvResourceProvider = createNiceMock(ResourceProvider.class);
 
     AbstractControllerResourceProvider.init(resourceProviderFactory);
 
@@ -725,6 +706,10 @@ public class ClusterStackVersionResourceProviderTest {
     expect(resourceProviderFactory.getHostResourceProvider(EasyMock.anyObject(), EasyMock.anyObject(),
             eq(managementController))).andReturn(csvResourceProvider).anyTimes();
 
+    expect(managementController.findConfigurationTagsWithOverrides(anyObject(Cluster.class),
EasyMock.anyString()))
+      .andReturn(new HashMap<String, Map<String, String>>()).anyTimes();
+
+
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
     expect(clusters.getHostsForCluster(anyObject(String.class))).andReturn(
         hostsForCluster).anyTimes();
@@ -796,12 +781,7 @@ public class ClusterStackVersionResourceProviderTest {
             cluster, repositoryVersionDAOMock, configHelper, schDatanode, schNamenode, schHBM,
actionManager,
             executionCommandWrapper,stage, stageFactory);
 
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        type,
-        PropertyHelper.getPropertyIds(type),
-        PropertyHelper.getKeyPropertyIds(type),
-        managementController);
-
+    ResourceProvider provider = createProvider(managementController);
     injector.injectMembers(provider);
 
     // add the property map to a set for the request.  add more maps for multiple creates
@@ -859,10 +839,6 @@ public class ClusterStackVersionResourceProviderTest {
 
     String os_json = json.toString();
 
-    Resource.Type type = Resource.Type.ClusterStackVersion;
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Clusters clusters = createNiceMock(Clusters.class);
     Cluster cluster = createNiceMock(Cluster.class);
     StackId stackId = new StackId("HDP", "2.0.1");
 
@@ -946,10 +922,7 @@ public class ClusterStackVersionResourceProviderTest {
     ActionManager actionManager = createNiceMock(ActionManager.class);
 
     RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
-    ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
-    ResourceProvider csvResourceProvider = createNiceMock(ClusterStackVersionResourceProvider.class);
-
-    AbstractControllerResourceProvider.init(resourceProviderFactory);
+    ResourceProvider csvResourceProvider = createNiceMock(ResourceProvider.class);
 
     Map<String, Map<String, String>> hostConfigTags = new HashMap<>();
     expect(configHelper.getEffectiveDesiredTags(anyObject(ClusterImpl.class), anyObject(String.class))).andReturn(hostConfigTags);
@@ -963,8 +936,8 @@ public class ClusterStackVersionResourceProviderTest {
             EasyMock.anyObject(), anyObject(String.class))).
             andReturn(packages).anyTimes(); // only one host has the versionable component
 
-    expect(resourceProviderFactory.getHostResourceProvider(EasyMock.anyObject(), EasyMock.anyObject(),
-            eq(managementController))).andReturn(csvResourceProvider).anyTimes();
+    expect(managementController.findConfigurationTagsWithOverrides(anyObject(Cluster.class),
EasyMock.anyString()))
+    .andReturn(new HashMap<String, Map<String, String>>()).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
     expect(clusters.getHostsForCluster(anyObject(String.class))).andReturn(
@@ -992,11 +965,9 @@ public class ClusterStackVersionResourceProviderTest {
     expect(cluster.transitionHostsToInstalling(anyObject(RepositoryVersionEntity.class),
         anyObject(VersionDefinitionXml.class), eq(false))).andReturn(hostsNeedingInstallCommands).atLeastOnce();
 
-//    ExecutionCommand executionCommand = createNiceMock(ExecutionCommand.class);
     ExecutionCommand executionCommand = new ExecutionCommand();
     ExecutionCommandWrapper executionCommandWrapper = createNiceMock(ExecutionCommandWrapper.class);
 
-//    expect(executionCommand.getHostLevelParams()).andReturn(new HashMap<String, String>()).atLeastOnce();
     expect(executionCommandWrapper.getExecutionCommand()).andReturn(executionCommand).anyTimes();
 
     Stage stage = createNiceMock(Stage.class);
@@ -1031,16 +1002,11 @@ public class ClusterStackVersionResourceProviderTest {
     StageUtils.setConfiguration(injector.getInstance(Configuration.class));
 
     // replay
-    replay(managementController, response, clusters, hdfsService, hbaseService, resourceProviderFactory,
csvResourceProvider,
+    replay(managementController, response, clusters, hdfsService, hbaseService, csvResourceProvider,
             cluster, repositoryVersionDAOMock, configHelper, schDatanode, schNamenode, schHBM,
actionManager,
             executionCommandWrapper,stage, stageFactory);
 
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        type,
-        PropertyHelper.getPropertyIds(type),
-        PropertyHelper.getKeyPropertyIds(type),
-        managementController);
-
+    ResourceProvider provider = createProvider(managementController);
     injector.injectMembers(provider);
 
     // add the property map to a set for the request.  add more maps for multiple creates
@@ -1096,10 +1062,6 @@ public class ClusterStackVersionResourceProviderTest {
    }
 
    private void testCreateResourcesMixed(Authentication authentication) throws Exception
{
-    Resource.Type type = Resource.Type.ClusterStackVersion;
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Clusters clusters = createNiceMock(Clusters.class);
     Cluster cluster = createNiceMock(Cluster.class);
     Map<String, String> hostLevelParams = new HashMap<>();
     StackId stackId = new StackId("HDP", "2.0.1");
@@ -1164,16 +1126,9 @@ public class ClusterStackVersionResourceProviderTest {
     expect(schAMS.getServiceName()).andReturn("AMBARI_METRICS").anyTimes();
     expect(schAMS.getServiceComponentName()).andReturn("METRICS_COLLECTOR").anyTimes();
     // First host contains versionable components
-    final List<ServiceComponentHost> schsH1 = new ArrayList<ServiceComponentHost>(){{
-      add(schDatanode);
-      add(schNamenode);
-      add(schAMS);
-    }};
+    final List<ServiceComponentHost> schsH1 = Lists.newArrayList(schDatanode, schNamenode,
schAMS);
     // Second host does not contain versionable components
-    final List<ServiceComponentHost> schsH2 = new ArrayList<ServiceComponentHost>(){{
-      add(schAMS);
-    }};
-
+    final List<ServiceComponentHost> schsH2 = Lists.newArrayList(schAMS);
 
     ServiceOsSpecific.Package hdfsPackage = new ServiceOsSpecific.Package();
     hdfsPackage.setName("hdfs");
@@ -1182,10 +1137,6 @@ public class ClusterStackVersionResourceProviderTest {
     ActionManager actionManager = createNiceMock(ActionManager.class);
 
     RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
-    ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
-    ResourceProvider csvResourceProvider = createNiceMock(ClusterStackVersionResourceProvider.class);
-
-    AbstractControllerResourceProvider.init(resourceProviderFactory);
 
     Map<String, Map<String, String>> hostConfigTags = new HashMap<>();
     expect(configHelper.getEffectiveDesiredTags(anyObject(ClusterImpl.class), anyObject(String.class))).andReturn(hostConfigTags);
@@ -1196,12 +1147,11 @@ public class ClusterStackVersionResourceProviderTest {
     expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
     expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
     expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
-            EasyMock.anyObject(), anyObject(String.class))).
-            andReturn(packages).times((hostCount - 1) * 2); // 1 host has no versionable
components, other hosts have 2 services
-//            // that's why we don't send commands to it
+            EasyMock.<Map<String, String>>anyObject(), anyObject(String.class))).
+            andReturn(packages).anyTimes();
 
-    expect(resourceProviderFactory.getHostResourceProvider(EasyMock.anyObject(), EasyMock.anyObject(),
-            eq(managementController))).andReturn(csvResourceProvider).anyTimes();
+    expect(managementController.findConfigurationTagsWithOverrides(anyObject(Cluster.class),
EasyMock.anyString()))
+      .andReturn(new HashMap<String, Map<String, String>>()).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
     expect(clusters.getHostsForCluster(anyObject(String.class))).andReturn(
@@ -1267,16 +1217,11 @@ public class ClusterStackVersionResourceProviderTest {
 
 
     // replay
-    replay(managementController, response, clusters, resourceProviderFactory, csvResourceProvider,
+    replay(managementController, response, clusters,
             cluster, repositoryVersionDAOMock, configHelper, schDatanode, schNamenode, schAMS,
actionManager,
             executionCommand, executionCommandWrapper,stage, stageFactory);
 
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        type,
-        PropertyHelper.getPropertyIds(type),
-        PropertyHelper.getKeyPropertyIds(type),
-        managementController);
-
+    ResourceProvider provider = createProvider(managementController);
     injector.injectMembers(provider);
 
     // add the property map to a set for the request.  add more maps for multiple creates
@@ -1329,10 +1274,6 @@ public class ClusterStackVersionResourceProviderTest {
    */
   @Test
   public void testCreateResourcesInInstalledState() throws Exception {
-    Resource.Type type = Resource.Type.ClusterStackVersion;
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Clusters clusters = createNiceMock(Clusters.class);
     Cluster cluster = createNiceMock(Cluster.class);
     StackId stackId = new StackId("HDP", "2.2.0");
     String repoVersion = "2.2.0.1-885";
@@ -1408,8 +1349,7 @@ public class ClusterStackVersionResourceProviderTest {
 
     RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
     ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
-    ResourceProvider csvResourceProvider = createNiceMock(
-        ClusterStackVersionResourceProvider.class);
+    ResourceProvider csvResourceProvider = createNiceMock(ResourceProvider.class);
 
     AbstractControllerResourceProvider.init(resourceProviderFactory);
 
@@ -1454,10 +1394,7 @@ public class ClusterStackVersionResourceProviderTest {
         csvResourceProvider, cluster, repositoryVersionDAOMock, configHelper, schDatanode,
         stageFactory, hostVersionDAO);
 
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(type,
-        PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type),
-        managementController);
-
+    ResourceProvider provider = createProvider(managementController);
     injector.injectMembers(provider);
 
     // add the property map to a set for the request. add more maps for multiple
@@ -1501,10 +1438,6 @@ public class ClusterStackVersionResourceProviderTest {
 
   @Test
   public void testCreateResourcesPPC() throws Exception {
-    Resource.Type type = Resource.Type.ClusterStackVersion;
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Clusters clusters = createNiceMock(Clusters.class);
     Cluster cluster = createNiceMock(Cluster.class);
     Map<String, String> hostLevelParams = new HashMap<>();
     StackId stackId = new StackId("HDP", "2.0.1");
@@ -1567,16 +1500,9 @@ public class ClusterStackVersionResourceProviderTest {
     expect(schAMS.getServiceName()).andReturn("AMBARI_METRICS").anyTimes();
     expect(schAMS.getServiceComponentName()).andReturn("METRICS_COLLECTOR").anyTimes();
     // First host contains versionable components
-    final List<ServiceComponentHost> schsH1 = new ArrayList<ServiceComponentHost>(){{
-      add(schDatanode);
-      add(schNamenode);
-      add(schAMS);
-    }};
+    final List<ServiceComponentHost> schsH1 = Lists.newArrayList(schDatanode, schNamenode,
schAMS);
     // Second host does not contain versionable components
-    final List<ServiceComponentHost> schsH2 = new ArrayList<ServiceComponentHost>(){{
-      add(schAMS);
-    }};
-
+    final List<ServiceComponentHost> schsH2 = Lists.newArrayList(schAMS);
 
     ServiceOsSpecific.Package hdfsPackage = new ServiceOsSpecific.Package();
     hdfsPackage.setName("hdfs");
@@ -1600,8 +1526,11 @@ public class ClusterStackVersionResourceProviderTest {
     expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
     expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
             (Map<String, String>) anyObject(List.class), anyObject(String.class))).
-            andReturn(packages).anyTimes(); // 1 host has no versionable components, other
hosts have 2 services
-  //            // that's why we don't send commands to it
+            andReturn(packages).anyTimes();
+
+    expect(managementController.findConfigurationTagsWithOverrides(anyObject(Cluster.class),
EasyMock.anyString()))
+      .andReturn(new HashMap<String, Map<String, String>>()).anyTimes();
+
 
     expect(resourceProviderFactory.getHostResourceProvider(anyObject(Set.class), anyObject(Map.class),
             eq(managementController))).andReturn(csvResourceProvider).anyTimes();
@@ -1672,12 +1601,7 @@ public class ClusterStackVersionResourceProviderTest {
             cluster, repoVersion, repositoryVersionDAOMock, configHelper, schDatanode, schNamenode,
schAMS, actionManager,
             executionCommand, executionCommandWrapper,stage, stageFactory);
 
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        type,
-        PropertyHelper.getPropertyIds(type),
-        PropertyHelper.getKeyPropertyIds(type),
-        managementController);
-
+    ResourceProvider provider = createProvider(managementController);
     injector.injectMembers(provider);
 
     // add the property map to a set for the request.  add more maps for multiple creates
@@ -1711,10 +1635,6 @@ public class ClusterStackVersionResourceProviderTest {
 
   @Test
   public void testGetSorted() throws Exception {
-
-    Resource.Type type = Resource.Type.ClusterStackVersion;
-
-    final Clusters clusters = createNiceMock(Clusters.class);
     Cluster cluster = createNiceMock(Cluster.class);
     StackId stackId = new StackId("HDP", "2.2.0");
 
@@ -1766,19 +1686,17 @@ public class ClusterStackVersionResourceProviderTest {
         csvResourceProvider, cluster, repositoryVersionDAOMock, configHelper,
         stageFactory, hostVersionDAO);
 
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(type,
-        PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type),
-        /*managementController*/null);
+    ResourceProvider provider = createProvider(managementController);
     injector.injectMembers(provider);
 
-    Field field = ClusterStackVersionResourceProvider.class.getDeclaredField("clusters");
-    field.setAccessible(true);
-    field.set(null, new Provider<Clusters>() {
-      @Override
-      public Clusters get() {
-        return clusters;
-      }
-    });
+//    Field field = ClusterStackVersionResourceProvider.class.getDeclaredField("clusters");
+//    field.setAccessible(true);
+//    field.set(null, new Provider<Clusters>() {
+//      @Override
+//      public Clusters get() {
+//        return clusters;
+//      }
+//    });
 
     // set the security auth
     SecurityContextHolder.getContext().setAuthentication(
@@ -1913,10 +1831,6 @@ public class ClusterStackVersionResourceProviderTest {
    }
 
    private void testCreateResourcesExistingUpgrade(Authentication authentication) throws
Exception {
-    Resource.Type type = Resource.Type.ClusterStackVersion;
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Clusters clusters = createNiceMock(Clusters.class);
     Cluster cluster = createNiceMock(Cluster.class);
 
     expect(managementController.getClusters()).andReturn(clusters).anyTimes();
@@ -1934,12 +1848,7 @@ public class ClusterStackVersionResourceProviderTest {
     // replay
     replay(managementController, clusters, cluster);
 
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        type,
-        PropertyHelper.getPropertyIds(type),
-        PropertyHelper.getKeyPropertyIds(type),
-        managementController);
-
+    ResourceProvider provider = createProvider(managementController);
     injector.injectMembers(provider);
 
     // add the property map to a set for the request.  add more maps for multiple creates
@@ -1971,6 +1880,17 @@ public class ClusterStackVersionResourceProviderTest {
     verify(cluster);
 
   }
+
+   private ClusterStackVersionResourceProvider createProvider(AmbariManagementController
amc) {
+     ResourceProviderFactory factory = injector.getInstance(ResourceProviderFactory.class);
+     AbstractControllerResourceProvider.init(factory);
+
+     Resource.Type type = Type.ClusterStackVersion;
+     return (ClusterStackVersionResourceProvider) AbstractControllerResourceProvider.getResourceProvider(type,
+         PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type),
+         amc);
+   }
+
   private class MockModule extends AbstractModule {
     @Override
     protected void configure() {
@@ -1980,6 +1900,9 @@ public class ClusterStackVersionResourceProviderTest {
       bind(StageFactory.class).toInstance(stageFactory);
       bind(HostVersionDAO.class).toInstance(hostVersionDAO);
       bind(HostComponentStateDAO.class).toInstance(hostComponentStateDAO);
+      bind(Clusters.class).toInstance(clusters);
+      bind(ActionManager.class).toInstance(actionManager);
+      bind(AmbariManagementController.class).toInstance(managementController);
     }
   }
 


Mime
View raw message