ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [15/37] ambari git commit: AMBARI-21450. Initial cherry-picking for feature branch (ncole)
Date Thu, 13 Jul 2017 19:14:33 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/test/java/org/apache/ambari/server/StateRecoveryManagerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/StateRecoveryManagerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/StateRecoveryManagerTest.java
index 3cb6b4b..b048d04 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/StateRecoveryManagerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/StateRecoveryManagerTest.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
@@ -18,46 +18,47 @@
 
 package org.apache.ambari.server;
 
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.util.Modules;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.sql.SQLException;
+
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
 import org.apache.ambari.server.orm.dao.HostVersionDAO;
-import org.apache.ambari.server.orm.entities.ClusterEntity;
-import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
+import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
 import org.apache.ambari.server.orm.entities.HostVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
 import org.apache.ambari.server.state.RepositoryVersionState;
 import org.easymock.Capture;
+import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.sql.SQLException;
-import java.util.ArrayList;
-
-import static org.easymock.EasyMock.and;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.junit.Assert.*;
+import com.google.common.collect.Lists;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.util.Modules;
 
 public class StateRecoveryManagerTest {
 
   private Injector injector;
   private HostVersionDAO hostVersionDAOMock;
-  private ClusterVersionDAO clusterVersionDAOMock;
+  private ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAOMock;
 
   @Before
   public void setup() throws Exception {
     // Create instances of mocks
-    clusterVersionDAOMock = createNiceMock(ClusterVersionDAO.class);
     hostVersionDAOMock = createNiceMock(HostVersionDAO.class);
+    serviceComponentDesiredStateDAOMock = createNiceMock(ServiceComponentDesiredStateDAO.class);
     // Initialize injector
     InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();
     injector = Guice.createInjector(Modules.override(module).with(new MockModule()));
@@ -75,43 +76,41 @@ public class StateRecoveryManagerTest {
 
     // Adding all possible host version states
 
-    final Capture<RepositoryVersionState> installFailedHostVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> installingHostVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> installedHostVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> outOfSyncHostVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> upgradeFailedHostVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> upgradingHostVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> upgradedHostVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> currentHostVersionCapture = new Capture<RepositoryVersionState>();
-
-    expect(hostVersionDAOMock.findAll()).andReturn(new ArrayList<HostVersionEntity>() {{
-      add(getHostVersionMock("install_failed_version", RepositoryVersionState.INSTALL_FAILED, installFailedHostVersionCapture));
-      add(getHostVersionMock("installing_version", RepositoryVersionState.INSTALLING, installingHostVersionCapture));
-      add(getHostVersionMock("installed_version", RepositoryVersionState.INSTALLED, installedHostVersionCapture));
-      add(getHostVersionMock("out_of_sync_version", RepositoryVersionState.OUT_OF_SYNC, outOfSyncHostVersionCapture));
-      add(getHostVersionMock("current_version", RepositoryVersionState.CURRENT, currentHostVersionCapture));
-    }});
+    final Capture<RepositoryVersionState> installFailedHostVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> installingHostVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> installedHostVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> outOfSyncHostVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> upgradeFailedHostVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> upgradingHostVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> upgradedHostVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> currentHostVersionCapture = EasyMock.newCapture();
+
+    expect(hostVersionDAOMock.findAll()).andReturn(Lists.newArrayList(
+      getHostVersionMock("install_failed_version", RepositoryVersionState.INSTALL_FAILED, installFailedHostVersionCapture),
+      getHostVersionMock("installing_version", RepositoryVersionState.INSTALLING, installingHostVersionCapture),
+      getHostVersionMock("installed_version", RepositoryVersionState.INSTALLED, installedHostVersionCapture),
+      getHostVersionMock("out_of_sync_version", RepositoryVersionState.OUT_OF_SYNC, outOfSyncHostVersionCapture),
+      getHostVersionMock("current_version", RepositoryVersionState.CURRENT, currentHostVersionCapture)));
 
     // Adding all possible cluster version states
 
-    final Capture<RepositoryVersionState> installFailedClusterVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> installingClusterVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> installedClusterVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> outOfSyncClusterVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> upgradeFailedClusterVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> upgradingClusterVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> upgradedClusterVersionCapture = new Capture<RepositoryVersionState>();
-    final Capture<RepositoryVersionState> currentClusterVersionCapture = new Capture<RepositoryVersionState>();
-
-    expect(clusterVersionDAOMock.findAll()).andReturn(new ArrayList<ClusterVersionEntity>() {{
-      add(getClusterVersionMock("install_failed_version", RepositoryVersionState.INSTALL_FAILED, installFailedClusterVersionCapture));
-      add(getClusterVersionMock("installing_version", RepositoryVersionState.INSTALLING, installingClusterVersionCapture));
-      add(getClusterVersionMock("installed_version", RepositoryVersionState.INSTALLED, installedClusterVersionCapture));
-      add(getClusterVersionMock("out_of_sync_version", RepositoryVersionState.OUT_OF_SYNC, outOfSyncClusterVersionCapture));
-      add(getClusterVersionMock("current_version", RepositoryVersionState.CURRENT, currentClusterVersionCapture));
-    }});
-
-    replay(hostVersionDAOMock, clusterVersionDAOMock);
+    final Capture<RepositoryVersionState> installFailedClusterVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> installingClusterVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> installedClusterVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> outOfSyncClusterVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> upgradeFailedClusterVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> upgradingClusterVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> upgradedClusterVersionCapture = EasyMock.newCapture();
+    final Capture<RepositoryVersionState> currentClusterVersionCapture = EasyMock.newCapture();
+
+    expect(serviceComponentDesiredStateDAOMock.findAll()).andReturn(Lists.newArrayList(
+      getDesiredStateEntityMock("install_failed_version", RepositoryVersionState.INSTALL_FAILED, installFailedClusterVersionCapture),
+      getDesiredStateEntityMock("installing_version", RepositoryVersionState.INSTALLING, installingClusterVersionCapture),
+      getDesiredStateEntityMock("installed_version", RepositoryVersionState.INSTALLED, installedClusterVersionCapture),
+      getDesiredStateEntityMock("out_of_sync_version", RepositoryVersionState.OUT_OF_SYNC, outOfSyncClusterVersionCapture),
+      getDesiredStateEntityMock("current_version", RepositoryVersionState.CURRENT, currentClusterVersionCapture)));
+
+    replay(hostVersionDAOMock, serviceComponentDesiredStateDAOMock);
 
     stateRecoveryManager.checkHostAndClusterVersions();
 
@@ -156,35 +155,30 @@ public class StateRecoveryManagerTest {
     return hvMock;
   }
 
+  private ServiceComponentDesiredStateEntity getDesiredStateEntityMock(String name, RepositoryVersionState state, Capture<RepositoryVersionState> newStateCapture) {
 
-  private ClusterVersionEntity getClusterVersionMock(String name, RepositoryVersionState state,
-                                               Capture<RepositoryVersionState> newStateCaptor) {
-    ClusterVersionEntity cvMock = createNiceMock(ClusterVersionEntity.class);
-    expect(cvMock.getState()).andReturn(state);
-
-    cvMock.setState(capture(newStateCaptor));
+    ServiceComponentDesiredStateEntity mock = createNiceMock(ServiceComponentDesiredStateEntity.class);
+    expect(mock.getRepositoryState()).andReturn(state);
+    mock.setRepositoryState(capture(newStateCapture));
     expectLastCall();
 
-    RepositoryVersionEntity rvMock = createNiceMock(RepositoryVersionEntity.class);
-    expect(rvMock.getDisplayName()).andReturn(name);
+    RepositoryVersionEntity repositoryVersionMock = createNiceMock(RepositoryVersionEntity.class);
+    expect(repositoryVersionMock.getVersion()).andReturn(name);
 
-    expect(cvMock.getRepositoryVersion()).andReturn(rvMock);
+    expect(mock.getDesiredRepositoryVersion()).andReturn(repositoryVersionMock);
 
-    ClusterEntity ceMock = createNiceMock(ClusterEntity.class);
-    expect(ceMock.getClusterName()).andReturn("somecluster");
+    replay(mock, repositoryVersionMock);
 
-    expect(cvMock.getClusterEntity()).andReturn(ceMock);
+    return mock;
+  }
 
-    replay(cvMock, rvMock, ceMock);
 
-    return cvMock;
-  }
 
   public class MockModule extends AbstractModule {
     @Override
     protected void configure() {
       bind(HostVersionDAO.class).toInstance(hostVersionDAOMock);
-      bind(ClusterVersionDAO.class).toInstance(clusterVersionDAOMock);
+      bind(ServiceComponentDesiredStateDAO.class).toInstance(serviceComponentDesiredStateDAOMock);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
index c28ba5d..64a1e3a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
@@ -36,6 +36,8 @@ import org.apache.ambari.server.agent.AgentCommand.AgentCommandType;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ConfigFactory;
@@ -45,14 +47,13 @@ import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent
 import org.apache.ambari.server.utils.StageUtils;
 import org.codehaus.jettison.json.JSONException;
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 
-import junit.framework.Assert;
-
 public class ExecutionCommandWrapperTest {
 
   private static final String HOST1 = "dev01.ambari.apache.org";
@@ -109,25 +110,25 @@ public class ExecutionCommandWrapperTest {
 
     Cluster cluster1 = clusters.getCluster(CLUSTER1);
 
-    SERVICE_SITE_CLUSTER = new HashMap<String, String>();
+    SERVICE_SITE_CLUSTER = new HashMap<>();
     SERVICE_SITE_CLUSTER.put(SERVICE_SITE_NAME1, SERVICE_SITE_VAL1);
     SERVICE_SITE_CLUSTER.put(SERVICE_SITE_NAME2, SERVICE_SITE_VAL2);
     SERVICE_SITE_CLUSTER.put(SERVICE_SITE_NAME3, SERVICE_SITE_VAL3);
     SERVICE_SITE_CLUSTER.put(SERVICE_SITE_NAME4, SERVICE_SITE_VAL4);
 
-    SERVICE_SITE_SERVICE = new HashMap<String, String>();
+    SERVICE_SITE_SERVICE = new HashMap<>();
     SERVICE_SITE_SERVICE.put(SERVICE_SITE_NAME1, SERVICE_SITE_VAL1_S);
     SERVICE_SITE_SERVICE.put(SERVICE_SITE_NAME5, SERVICE_SITE_VAL5_S);
 
-    SERVICE_SITE_HOST = new HashMap<String, String>();
+    SERVICE_SITE_HOST = new HashMap<>();
     SERVICE_SITE_HOST.put(SERVICE_SITE_NAME2, SERVICE_SITE_VAL2_H);
     SERVICE_SITE_HOST.put(SERVICE_SITE_NAME6, SERVICE_SITE_VAL6_H);
 
-    GLOBAL_CLUSTER = new HashMap<String, String>();
+    GLOBAL_CLUSTER = new HashMap<>();
     GLOBAL_CLUSTER.put(GLOBAL_NAME1, GLOBAL_CLUSTER_VAL1);
     GLOBAL_CLUSTER.put(GLOBAL_NAME2, GLOBAL_CLUSTER_VAL2);
 
-    CONFIG_ATTRIBUTES = new HashMap<String, Map<String,String>>();
+    CONFIG_ATTRIBUTES = new HashMap<>();
 
     //Cluster level global config
     configFactory.createNew(cluster1, GLOBAL_CONFIG, CLUSTER_VERSION_TAG, GLOBAL_CLUSTER, CONFIG_ATTRIBUTES);
@@ -155,7 +156,7 @@ public class ExecutionCommandWrapperTest {
         RoleCommand.START,
         new ServiceComponentHostStartEvent(Role.NAMENODE.toString(),
             hostName, System.currentTimeMillis()), clusterName, "HDFS", false, false);
-    List<Stage> stages = new ArrayList<Stage>();
+    List<Stage> stages = new ArrayList<>();
     stages.add(s);
     Request request = new Request(stages, "clusterHostInfo", clusters);
     db.persistActions(request);
@@ -164,14 +165,20 @@ public class ExecutionCommandWrapperTest {
   @Test
   public void testGetExecutionCommand() throws JSONException, AmbariException {
 
+    Cluster cluster = clusters.getCluster(CLUSTER1);
+
+    OrmTestHelper helper = injector.getInstance(OrmTestHelper.class);
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster);
+
+    cluster.addService("HDFS", repositoryVersion);
 
-    Map<String, Map<String, String>> confs = new HashMap<String, Map<String, String>>();
-    Map<String, String> configurationsGlobal = new HashMap<String, String>();
+    Map<String, Map<String, String>> confs = new HashMap<>();
+    Map<String, String> configurationsGlobal = new HashMap<>();
     configurationsGlobal.put(GLOBAL_NAME1, GLOBAL_VAL1);
     confs.put(GLOBAL_CONFIG, configurationsGlobal);
 
-    Map<String, Map<String, String>> confTags = new HashMap<String, Map<String, String>>();
-    Map<String, String> confTagServiceSite = new HashMap<String, String>();
+    Map<String, Map<String, String>> confTags = new HashMap<>();
+    Map<String, String> confTagServiceSite = new HashMap<>();
 
     confTagServiceSite.put("tag", CLUSTER_VERSION_TAG);
     confTagServiceSite.put("service_override_tag", SERVICE_VERSION_TAG);
@@ -223,7 +230,7 @@ public class ExecutionCommandWrapperTest {
 
 
     //Union of all keys of service site configs
-    Set<String> serviceSiteKeys = new HashSet<String>();
+    Set<String> serviceSiteKeys = new HashSet<>();
     serviceSiteKeys.addAll(SERVICE_SITE_CLUSTER.keySet());
     serviceSiteKeys.addAll(SERVICE_SITE_SERVICE.keySet());
     serviceSiteKeys.addAll(SERVICE_SITE_HOST.keySet());
@@ -234,7 +241,7 @@ public class ExecutionCommandWrapperTest {
 
   @Test
   public void testGetMergedConfig() {
-    Map<String, String> baseConfig = new HashMap<String, String>();
+    Map<String, String> baseConfig = new HashMap<>();
 
     baseConfig.put(SERVICE_SITE_NAME1, SERVICE_SITE_VAL1);
     baseConfig.put(SERVICE_SITE_NAME2, SERVICE_SITE_VAL2);
@@ -242,7 +249,7 @@ public class ExecutionCommandWrapperTest {
     baseConfig.put(SERVICE_SITE_NAME4, SERVICE_SITE_VAL4);
     baseConfig.put(SERVICE_SITE_NAME5, SERVICE_SITE_VAL5);
 
-    Map<String, String> overrideConfig = new HashMap<String, String>();
+    Map<String, String> overrideConfig = new HashMap<>();
 
     overrideConfig.put(SERVICE_SITE_NAME2, SERVICE_SITE_VAL2_H);
     overrideConfig.put(SERVICE_SITE_NAME6, SERVICE_SITE_VAL6_H);
@@ -252,7 +259,7 @@ public class ExecutionCommandWrapperTest {
       overrideConfig);
 
 
-    Set<String> configsKeys = new HashSet<String>();
+    Set<String> configsKeys = new HashSet<>();
     configsKeys.addAll(baseConfig.keySet());
     configsKeys.addAll(overrideConfig.keySet());
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/test/java/org/apache/ambari/server/alerts/ComponentVersionAlertRunnableTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/alerts/ComponentVersionAlertRunnableTest.java b/ambari-server/src/test/java/org/apache/ambari/server/alerts/ComponentVersionAlertRunnableTest.java
index 6c07138..e41f568 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/alerts/ComponentVersionAlertRunnableTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/alerts/ComponentVersionAlertRunnableTest.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
@@ -38,7 +38,6 @@ import org.apache.ambari.server.events.publishers.AlertEventPublisher;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
-import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.UpgradeEntity;
 import org.apache.ambari.server.stack.StackManagerFactory;
@@ -48,9 +47,12 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ComponentInfo;
 import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.stack.OsFamily;
+import org.apache.ambari.server.state.stack.upgrade.Direction;
 import org.easymock.EasyMock;
 import org.easymock.EasyMockSupport;
 import org.junit.After;
@@ -140,6 +142,17 @@ public class ComponentVersionAlertRunnableTest extends EasyMockSupport {
     expect(m_desidredStackId.getStackName()).andReturn("SOME-STACK").atLeastOnce();
     expect(m_desidredStackId.getStackVersion()).andReturn("STACK-VERSION").atLeastOnce();
 
+    RepositoryVersionEntity repositoryVersionEntity = createNiceMock(RepositoryVersionEntity.class);
+    expect(repositoryVersionEntity.getVersion()).andReturn(EXPECTED_VERSION).anyTimes();
+
+    // services
+    Service service = createNiceMock(Service.class);
+    expect(service.getDesiredRepositoryVersion()).andReturn(repositoryVersionEntity).atLeastOnce();
+
+    ServiceComponent serviceComponent = createNiceMock(ServiceComponent.class);
+    expect(serviceComponent.getDesiredStackId()).andReturn(m_desidredStackId).atLeastOnce();
+    expect(service.getServiceComponent(EasyMock.anyString())).andReturn(serviceComponent).atLeastOnce();
+
     // components
     ServiceComponentHost sch1_1 = createNiceMock(ServiceComponentHost.class);
     ServiceComponentHost sch1_2 = createNiceMock(ServiceComponentHost.class);
@@ -149,19 +162,15 @@ public class ComponentVersionAlertRunnableTest extends EasyMockSupport {
     expect(sch1_1.getServiceName()).andReturn("FOO").atLeastOnce();
     expect(sch1_1.getServiceComponentName()).andReturn("FOO_COMPONENT").atLeastOnce();
     expect(sch1_1.getVersion()).andReturn(EXPECTED_VERSION).atLeastOnce();
-    expect(sch1_1.getDesiredStackVersion()).andReturn(m_desidredStackId).atLeastOnce();
     expect(sch1_2.getServiceName()).andReturn("BAR").atLeastOnce();
     expect(sch1_2.getServiceComponentName()).andReturn("BAR_COMPONENT").atLeastOnce();
     expect(sch1_2.getVersion()).andReturn(EXPECTED_VERSION).atLeastOnce();
-    expect(sch1_2.getDesiredStackVersion()).andReturn(m_desidredStackId).atLeastOnce();
     expect(sch2_1.getServiceName()).andReturn("FOO").atLeastOnce();
     expect(sch2_1.getServiceComponentName()).andReturn("FOO_COMPONENT").atLeastOnce();
     expect(sch2_1.getVersion()).andReturn(EXPECTED_VERSION).atLeastOnce();
-    expect(sch2_1.getDesiredStackVersion()).andReturn(m_desidredStackId).atLeastOnce();
     expect(sch2_2.getServiceName()).andReturn("BAZ").atLeastOnce();
     expect(sch2_2.getServiceComponentName()).andReturn("BAZ_COMPONENT").atLeastOnce();
     expect(sch2_2.getVersion()).andReturn(EXPECTED_VERSION).atLeastOnce();
-    expect(sch2_2.getDesiredStackVersion()).andReturn(m_desidredStackId).atLeastOnce();
 
     m_hostComponentMap.get(HOSTNAME_1).add(sch1_1);
     m_hostComponentMap.get(HOSTNAME_1).add(sch1_2);
@@ -179,14 +188,7 @@ public class ComponentVersionAlertRunnableTest extends EasyMockSupport {
     expect(m_cluster.getClusterId()).andReturn(CLUSTER_ID).atLeastOnce();
     expect(m_cluster.getClusterName()).andReturn(CLUSTER_NAME).atLeastOnce();
     expect(m_cluster.getHosts()).andReturn(m_hosts).atLeastOnce();
-
-    ClusterVersionEntity clusterVersionEntity = createNiceMock(ClusterVersionEntity.class);
-    RepositoryVersionEntity repositoryVersionEntity = createNiceMock(RepositoryVersionEntity.class);
-    expect(clusterVersionEntity.getRepositoryVersion()).andReturn(
-        repositoryVersionEntity).anyTimes();
-
-    expect(repositoryVersionEntity.getVersion()).andReturn(EXPECTED_VERSION).anyTimes();
-    expect(m_cluster.getCurrentClusterVersion()).andReturn(clusterVersionEntity).anyTimes();
+    expect(m_cluster.getService(EasyMock.anyString())).andReturn(service).atLeastOnce();
 
     // mock clusters
     expect(m_clusters.getClusters()).andReturn(clusterMap).atLeastOnce();
@@ -224,9 +226,8 @@ public class ComponentVersionAlertRunnableTest extends EasyMockSupport {
   @Test
   public void testUpgradeInProgress() throws Exception {
     UpgradeEntity upgrade = createNiceMock(UpgradeEntity.class);
-    expect(upgrade.getToRepositoryVersion()).andReturn(EasyMock.createNiceMock(RepositoryVersionEntity.class)).atLeastOnce();
-    expect(upgrade.getFromRepositoryVersion()).andReturn(EasyMock.createNiceMock(RepositoryVersionEntity.class)).atLeastOnce();
-    expect(m_cluster.getUpgradeInProgress()).andReturn(upgrade).atLeastOnce();
+    expect(upgrade.getDirection()).andReturn(Direction.UPGRADE).atLeastOnce();
+    expect(m_cluster.getUpgradeInProgress()).andReturn(upgrade).once();
 
     replayAll();
 
@@ -305,7 +306,6 @@ public class ComponentVersionAlertRunnableTest extends EasyMockSupport {
     expect(sch.getServiceName()).andReturn("FOO").atLeastOnce();
     expect(sch.getServiceComponentName()).andReturn("FOO_COMPONENT").atLeastOnce();
     expect(sch.getVersion()).andReturn(WRONG_VERSION).atLeastOnce();
-    expect(sch.getDesiredStackVersion()).andReturn(m_desidredStackId).atLeastOnce();
 
     replayAll();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeEventCreatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeEventCreatorTest.java
index fdc4752..a8e21f6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeEventCreatorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeEventCreatorTest.java
@@ -40,7 +40,7 @@ public class UpgradeEventCreatorTest extends AuditEventCreatorTestBase{
     UpgradeEventCreator creator = new UpgradeEventCreator();
 
     Map<String,Object> properties = new HashMap<>();
-    properties.put(UpgradeResourceProvider.UPGRADE_REPO_VERSION, "1.9");
+    properties.put(UpgradeResourceProvider.UPGRADE_REPO_VERSION_ID, "1234");
     properties.put(UpgradeResourceProvider.UPGRADE_TYPE, "ROLLING");
     properties.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "mycluster");
 
@@ -50,7 +50,7 @@ public class UpgradeEventCreatorTest extends AuditEventCreatorTestBase{
     AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
 
     String actual = event.getAuditMessage();
-    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Upgrade addition), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Repository version(1.9), Upgrade type(ROLLING), Cluster name(mycluster)";
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Upgrade addition), RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Repository version ID(1234), Upgrade type(ROLLING), Cluster name(mycluster)";
 
     Assert.assertTrue("Class mismatch", event instanceof AddUpgradeRequestAuditEvent);
     Assert.assertEquals(expected, actual);

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/test/java/org/apache/ambari/server/checks/HardcodedStackVersionPropertiesCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/HardcodedStackVersionPropertiesCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/HardcodedStackVersionPropertiesCheckTest.java
index 92d79a1..6582cf7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/HardcodedStackVersionPropertiesCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/HardcodedStackVersionPropertiesCheckTest.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
@@ -18,11 +18,13 @@
 
 package org.apache.ambari.server.checks;
 
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import java.util.regex.Pattern;
 
-import static org.junit.Assert.*;
+import org.junit.Test;
 
 public class HardcodedStackVersionPropertiesCheckTest {
 
@@ -57,4 +59,4 @@ public class HardcodedStackVersionPropertiesCheckTest {
     content = "kgflkfld fdf\nld;ls;f d hdp.version=2.3.4.0-1234 \n sfdfdsfds \n fdsfds";
     assertTrue(HardcodedStackVersionPropertiesCheck.stringContainsVersionHardcode(content, pattern));
   }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java
index c45c59d..986a0f1 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/InstallPackagesCheckTest.java
@@ -24,10 +24,8 @@ import java.util.List;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
-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.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.HostVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
@@ -58,7 +56,7 @@ import com.google.inject.Provider;
 @PrepareForTest(HostComponentSummary.class)   // This class has a static method that will be mocked
 public class InstallPackagesCheckTest {
   private final Clusters clusters = Mockito.mock(Clusters.class);
-  private final ClusterVersionDAO clusterVersionDAO = Mockito.mock(ClusterVersionDAO.class);
+
   private final HostVersionDAO hostVersionDAO = Mockito.mock(HostVersionDAO.class);
   private final RepositoryVersionDAO repositoryVersionDAO = Mockito.mock(RepositoryVersionDAO.class);
   private AmbariMetaInfo ambariMetaInfo = Mockito.mock(AmbariMetaInfo.class);
@@ -101,13 +99,6 @@ public class InstallPackagesCheckTest {
       }
     };
 
-    installPackagesCheck.clusterVersionDAOProvider = new Provider<ClusterVersionDAO>() {
-      @Override
-      public ClusterVersionDAO get() {
-        return clusterVersionDAO;
-      }
-    };
-
     installPackagesCheck.hostVersionDaoProvider = new Provider<HostVersionDAO>() {
       @Override
       public HostVersionDAO get() {
@@ -132,17 +123,13 @@ public class InstallPackagesCheckTest {
 
     Mockito.when(cluster.getCurrentStackVersion()).thenReturn(stackId);
     Mockito.when(clusters.getCluster(clusterName)).thenReturn(cluster);
-    ClusterVersionEntity clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class);
-    Mockito.when(clusterVersionEntity.getState()).thenReturn(RepositoryVersionState.INSTALLED);
-    Mockito.when(clusterVersionDAO.findByClusterAndStackAndVersion(
-        clusterName, targetStackId, repositoryVersion)).thenReturn(clusterVersionEntity);
-    final List<String> hostNames = new ArrayList<String>();
+    final List<String> hostNames = new ArrayList<>();
     hostNames.add("host1");
     hostNames.add("host2");
     hostNames.add("host3");
 
-    final List<Host> hosts = new ArrayList<Host>();
-    final List<HostVersionEntity> hostVersionEntities = new ArrayList<HostVersionEntity>();
+    final List<Host> hosts = new ArrayList<>();
+    final List<HostVersionEntity> hostVersionEntities = new ArrayList<>();
     for(String hostName : hostNames) {
       Host host =  Mockito.mock(Host.class);
       Mockito.when(host.getHostName()).thenReturn(hostName);
@@ -168,21 +155,10 @@ public class InstallPackagesCheckTest {
 
     // Case 2: Install Packages failed on host1
     Mockito.when(hostVersionEntities.get(0).getState()).thenReturn(RepositoryVersionState.INSTALL_FAILED);
-    Mockito.when(clusterVersionEntity.getState()).thenReturn(RepositoryVersionState.INSTALL_FAILED);
     check = new PrerequisiteCheck(null, null);
     installPackagesCheck.perform(check, checkRequest);
     Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
     Assert.assertNotNull(check.getFailedOn());
     Assert.assertTrue(check.getFailedOn().contains("host1"));
-
-    // Case 3: Install Packages failed on host1 and host1 was put in Maintenance Mode
-    Mockito.when(hostVersionEntities.get(0).getState()).thenReturn(RepositoryVersionState.INSTALL_FAILED);
-    Mockito.when(hosts.get(0).getMaintenanceState(1L)).thenReturn(MaintenanceState.ON);
-    Mockito.when(clusterVersionEntity.getState()).thenReturn(RepositoryVersionState.INSTALL_FAILED);
-    check = new PrerequisiteCheck(null, null);
-    installPackagesCheck.perform(check, checkRequest);
-    Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
-    Assert.assertNotNull(check.getFailedOn());
-    Assert.assertTrue(check.getFailedOn().contains(clusterName));
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/test/java/org/apache/ambari/server/checks/PreviousUpgradeCompletedTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/PreviousUpgradeCompletedTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/PreviousUpgradeCompletedTest.java
index 21b2514..3233e55 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/PreviousUpgradeCompletedTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/PreviousUpgradeCompletedTest.java
@@ -44,14 +44,14 @@ public class PreviousUpgradeCompletedTest {
   private final Cluster cluster = Mockito.mock(Cluster.class);
   private StackId sourceStackId = new StackId("HDP", "2.2");
   private StackId targetStackId = new StackId("HDP", "2.2");
-  private final RepositoryVersionEntity sourceRepositoryVersion = Mockito.mock(RepositoryVersionEntity.class);
-  private final RepositoryVersionEntity targetRepositoryVersion = Mockito.mock(RepositoryVersionEntity.class);
-  private String sourceVersion = "2.2.6.0-1234";
-  private String destVersion = "2.2.8.0-5678";
+  private String sourceRepositoryVersion = "2.2.6.0-1234";
+  private String destRepositoryVersion = "2.2.8.0-5678";
   private String clusterName = "cluster";
   private PrereqCheckRequest checkRequest = new PrereqCheckRequest(clusterName);
   private PreviousUpgradeCompleted puc = new PreviousUpgradeCompleted();
 
+  private RepositoryVersionEntity toRepsitoryVersion;
+
   /**
    *
    */
@@ -67,7 +67,7 @@ public class PreviousUpgradeCompletedTest {
     stack.setStackName(stackId.getStackName());
     stack.setStackVersion(stackId.getStackVersion());
 
-    checkRequest.setRepositoryVersion(sourceVersion);
+    checkRequest.setRepositoryVersion(sourceRepositoryVersion);
     checkRequest.setSourceStackId(sourceStackId);
     checkRequest.setTargetStackId(targetStackId);
 
@@ -78,6 +78,8 @@ public class PreviousUpgradeCompletedTest {
       }
     };
 
+    toRepsitoryVersion = Mockito.mock(RepositoryVersionEntity.class);
+    Mockito.when(toRepsitoryVersion.getVersion()).thenReturn(destRepositoryVersion);
   }
 
   @Test
@@ -92,8 +94,7 @@ public class PreviousUpgradeCompletedTest {
     UpgradeEntity upgradeInProgress = Mockito.mock(UpgradeEntity.class);
     Mockito.when(upgradeInProgress.getDirection()).thenReturn(Direction.UPGRADE);
     Mockito.when(upgradeInProgress.getClusterId()).thenReturn(1L);
-    Mockito.when(upgradeInProgress.getFromRepositoryVersion()).thenReturn(sourceRepositoryVersion);
-    Mockito.when(upgradeInProgress.getToRepositoryVersion()).thenReturn(targetRepositoryVersion);
+    Mockito.when(upgradeInProgress.getRepositoryVersion()).thenReturn(toRepsitoryVersion);
 
     Mockito.when(cluster.getUpgradeInProgress()).thenReturn(upgradeInProgress);
     check = new PrerequisiteCheck(null, null);

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
index 613e47f..5c423b5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/YarnTimelineServerStatePreservingCheckTest.java
@@ -22,7 +22,6 @@ import java.util.Map;
 
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
-import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
@@ -77,17 +76,13 @@ public class YarnTimelineServerStatePreservingCheckTest {
     Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster);
     Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.2"));
 
-    Map<String, Service> services = new HashMap<String, Service>();
+    Map<String, Service> services = new HashMap<>();
     Mockito.when(cluster.getServices()).thenReturn(services);
 
-    ClusterVersionEntity clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class);
-    Mockito.when(cluster.getCurrentClusterVersion()).thenReturn(clusterVersionEntity);
-
     RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class);
-    Mockito.when(clusterVersionEntity.getRepositoryVersion()).thenReturn(repositoryVersionEntity);
     Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.2.4.2");
 
-    Map<String, String> checkProperties = new HashMap<String, String>();
+    Map<String, String> checkProperties = new HashMap<>();
     checkProperties.put("min-applicable-stack-version","HDP-2.2.4.2");
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
     Mockito.when(prerequisiteCheckConfig.getCheckProperties(
@@ -119,14 +114,14 @@ public class YarnTimelineServerStatePreservingCheckTest {
 
     final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class);
     Mockito.when(desiredConfig.getTag()).thenReturn("tag");
-    Map<String, DesiredConfig> configMap = new HashMap<String, DesiredConfig>();
+    Map<String, DesiredConfig> configMap = new HashMap<>();
     configMap.put("yarn-site", desiredConfig);
     configMap.put("core-site", desiredConfig);
 
     Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap);
     final Config config = Mockito.mock(Config.class);
     Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config);
-    final Map<String, String> properties = new HashMap<String, String>();
+    final Map<String, String> properties = new HashMap<>();
     Mockito.when(config.getProperties()).thenReturn(properties);
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
@@ -150,13 +145,10 @@ public class YarnTimelineServerStatePreservingCheckTest {
       }
     });
     Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.2"));
-    ClusterVersionEntity clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class);
-    Mockito.when(cluster.getCurrentClusterVersion()).thenReturn(clusterVersionEntity);
     RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class);
-    Mockito.when(clusterVersionEntity.getRepositoryVersion()).thenReturn(repositoryVersionEntity);
     Mockito.when(m_clusters.getCluster("c1")).thenReturn(cluster);
 
-    Map<String, String> checkProperties = new HashMap<String, String>();
+    Map<String, String> checkProperties = new HashMap<>();
     checkProperties.put("min-applicable-stack-version","HDP-2.2.4.2");
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
     Mockito.when(prerequisiteCheckConfig.getCheckProperties(
@@ -198,13 +190,10 @@ public class YarnTimelineServerStatePreservingCheckTest {
       }
     });
     Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("MYSTACK-12.2"));
-    ClusterVersionEntity clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class);
-    Mockito.when(cluster.getCurrentClusterVersion()).thenReturn(clusterVersionEntity);
     RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class);
-    Mockito.when(clusterVersionEntity.getRepositoryVersion()).thenReturn(repositoryVersionEntity);
     Mockito.when(m_clusters.getCluster("c1")).thenReturn(cluster);
 
-    Map<String, String> checkProperties = new HashMap<String, String>();
+    Map<String, String> checkProperties = new HashMap<>();
     checkProperties.put("min-applicable-stack-version", "HDP-2.2.4.2");
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
     Mockito.when(prerequisiteCheckConfig.getCheckProperties(

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
index 79ae063..66a6e98 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.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
@@ -37,6 +37,7 @@ import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
 import org.apache.ambari.server.actionmanager.Request;
 import org.apache.ambari.server.actionmanager.Stage;
+import org.apache.ambari.server.agent.CommandRepository;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.internal.ComponentResourceProviderTest;
@@ -47,6 +48,14 @@ import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.metadata.ActionMetadata;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
+import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
+import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
+import org.apache.ambari.server.orm.dao.StackDAO;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
+import org.apache.ambari.server.orm.entities.ServiceComponentVersionEntity;
+import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.state.Cluster;
@@ -57,17 +66,19 @@ import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.MaintenanceState;
 import org.apache.ambari.server.state.PropertyInfo;
+import org.apache.ambari.server.state.RepositoryInfo;
 import org.apache.ambari.server.state.SecurityType;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
-import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.UserGroupInfo;
 import org.apache.ambari.server.state.ValueAttributesInfo;
+import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
 import org.apache.ambari.server.topology.TopologyManager;
 import org.apache.ambari.server.utils.StageUtils;
+import org.apache.commons.collections.MapUtils;
 import org.easymock.Capture;
 import org.easymock.EasyMock;
 import org.easymock.EasyMockRule;
@@ -131,7 +142,7 @@ public class AmbariCustomCommandExecutionHelperTest {
     StageUtils.setConfiguration(injector.getInstance(Configuration.class));
 
     SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
-    createClusterFixture("c1", "HDP-2.0.6", "c1");
+    createClusterFixture("c1", new StackId("HDP-2.0.6"), "2.0.6-1234", "c1");
 
     EasyMock.expect(hostRoleCommand.getTaskId()).andReturn(1L);
     EasyMock.expect(hostRoleCommand.getStageId()).andReturn(1L);
@@ -146,7 +157,7 @@ public class AmbariCustomCommandExecutionHelperTest {
     stackInfo.setName("HDP");
     stackInfo.setVersion("2.0.6");
     StackId stackId = new StackId(stackInfo);
-    Map<String, DesiredConfig> desiredConfigMap = new HashMap<String, DesiredConfig>();
+    Map<String, DesiredConfig> desiredConfigMap = new HashMap<>();
     Map<PropertyInfo, String> userProperties = new HashMap<>();
     Map<PropertyInfo, String> groupProperties = new HashMap<>();
     PropertyInfo userProperty = new PropertyInfo();
@@ -169,7 +180,7 @@ public class AmbariCustomCommandExecutionHelperTest {
     userProperties.put(userProperty, "zookeeperUser");
     groupProperties.put(groupProperty, "zookeeperGroup");
     Map<String, Set<String>> userGroupsMap = new HashMap<>();
-    userGroupsMap.put("zookeeperUser", new HashSet<String>(Arrays.asList("zookeeperGroup")));
+    userGroupsMap.put("zookeeperUser", new HashSet<>(Arrays.asList("zookeeperGroup")));
     Cluster cluster = clusters.getCluster("c1");
     EasyMock.expect(configHelper.getPropertiesWithPropertyType(
       stackId, PropertyInfo.PropertyType.USER, cluster, desiredConfigMap)).andReturn(userProperties).anyTimes();
@@ -247,11 +258,7 @@ public class AmbariCustomCommandExecutionHelperTest {
            new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c1-c6402"))
        ),
        new RequestOperationLevel(Resource.Type.Service, "c1", "GANGLIA", null, null),
-        new HashMap<String, String>() {
-          {
-          }
-        },
-       false);
+        new HashMap<String, String>(), false);
 
     EasyMock.replay(hostRoleCommand, actionManager, configHelper);
 
@@ -286,10 +293,7 @@ public class AmbariCustomCommandExecutionHelperTest {
             new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c1-c6401")),
             new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c1-c6402"))),
         new RequestOperationLevel(Resource.Type.Service, "c1", "GANGLIA", null, null),
-        new HashMap<String, String>() {
-          {
-          }
-        }, false);
+        new HashMap<String, String>(), false);
 
     EasyMock.replay(hostRoleCommand, actionManager, configHelper);
 
@@ -326,10 +330,7 @@ public class AmbariCustomCommandExecutionHelperTest {
             new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c1-c6401")),
             new RequestResourceFilter("GANGLIA", "GANGLIA_MONITOR", Collections.singletonList("c1-c6402"))),
         new RequestOperationLevel(Resource.Type.Host, "c1", "GANGLIA", null, null),
-        new HashMap<String, String>() {
-          {
-          }
-        }, false);
+        new HashMap<String, String>(), false);
 
     EasyMock.replay(hostRoleCommand, actionManager, configHelper);
 
@@ -375,10 +376,7 @@ public class AmbariCustomCommandExecutionHelperTest {
         Collections.singletonList("c6402"))),
 
         new RequestOperationLevel(Resource.Type.Service, "c1", "ZOOKEEPER", null, null),
-        new HashMap<String, String>() {
-          {
-          }
-        }, false);
+        new HashMap<String, String>(), false);
 
     EasyMock.replay(hostRoleCommand, actionManager, configHelper);
     ambariManagementController.createAction(actionRequest, requestProperties);
@@ -418,10 +416,7 @@ public class AmbariCustomCommandExecutionHelperTest {
         Collections.singletonList("c6402"))),
 
         new RequestOperationLevel(Resource.Type.Service, "c1", "ZOOKEEPER", null, null),
-        new HashMap<String, String>() {
-          {
-          }
-        }, false);
+        new HashMap<String, String>(), false);
 
     EasyMock.replay(hostRoleCommand, actionManager, configHelper);
     ambariManagementController.createAction(actionRequest, requestProperties);
@@ -472,7 +467,7 @@ public class AmbariCustomCommandExecutionHelperTest {
 
     HashSet<String> localComponents = new HashSet<>();
     EasyMock.expect(execCmd.getLocalComponents()).andReturn(localComponents).anyTimes();
-    EasyMock.replay(configHelper,stage, execCmdWrapper, execCmd);
+    EasyMock.replay(configHelper, stage, execCmdWrapper, execCmd);
 
     ambariCustomCommandExecutionHelper.addExecutionCommandsToStage(actionExecutionContext, stage, new HashMap<String, String>(), null);
     Map<String, String> configMap = timeOutCapture.getValues().get(0);
@@ -522,7 +517,7 @@ public class AmbariCustomCommandExecutionHelperTest {
 
     HashSet<String> localComponents = new HashSet<>();
     EasyMock.expect(execCmd.getLocalComponents()).andReturn(localComponents).anyTimes();
-    EasyMock.replay(stage, execCmdWrapper, execCmd);
+    EasyMock.replay(configHelper, stage, execCmdWrapper, execCmd);
 
     ambariCustomCommandExecutionHelper.addExecutionCommandsToStage(actionExecutionContext, stage, new HashMap<String, String>(), null);
   }
@@ -531,7 +526,7 @@ public class AmbariCustomCommandExecutionHelperTest {
   public void testIsTopologyRefreshRequired() throws Exception {
     AmbariCustomCommandExecutionHelper helper = injector.getInstance(AmbariCustomCommandExecutionHelper.class);
 
-    createClusterFixture("c2", "HDP-2.1.1", "c2");
+    createClusterFixture("c2", new StackId("HDP-2.1.1"), "2.1.1.0-1234", "c2");
 
     Assert.assertTrue(helper.isTopologyRefreshRequired("START", "c2", "HDFS"));
     Assert.assertTrue(helper.isTopologyRefreshRequired("RESTART", "c2", "HDFS"));
@@ -557,31 +552,103 @@ public class AmbariCustomCommandExecutionHelperTest {
     EasyMock.replay(hostRoleCommand, actionManager, configHelper);
 
     ambariManagementController.createAction(actionRequest, requestProperties);
-    StackId stackId = clusters.getCluster("c1").getDesiredStackVersion();
-    Map<String, ServiceInfo> services = ambariManagementController.getAmbariMetaInfo().getServices(stackId.getStackName(), stackId.getStackVersion());
+
     Request request = requestCapture.getValue();
     Stage stage = request.getStages().iterator().next();
     List<ExecutionCommandWrapper> commands = stage.getExecutionCommands("c1-c6401");
     ExecutionCommand command = commands.get(0).getExecutionCommand();
-    for (String service : services.keySet()) {
-      Assert.assertEquals(command.getAvailableServices().get(service), services.get(service).getVersion());
-    }
+
+    // ZK is the only service that is versionable
+    Assert.assertFalse(MapUtils.isEmpty(command.getComponentVersionMap()));
+    Assert.assertEquals(1, command.getComponentVersionMap().size());
+    Assert.assertTrue(command.getComponentVersionMap().containsKey("ZOOKEEPER"));
   }
 
-  private void createClusterFixture(String clusterName, String stackVersion, String hostPrefix) throws AmbariException, AuthorizationException {
+  @Test
+  public void testCommandRepository() throws Exception {
+    Cluster cluster = clusters.getCluster("c1");
+    Service serviceYARN = cluster.getService("YARN");
+    Service serviceZK = cluster.getService("ZOOKEEPER");
+    ServiceComponent componentRM = serviceYARN.getServiceComponent("RESOURCEMANAGER");
+    ServiceComponent componentZKC = serviceZK.getServiceComponent("ZOOKEEPER_CLIENT");
+    Host host = clusters.getHost("c1-c6401");
+
+    AmbariCustomCommandExecutionHelper helper = injector.getInstance(AmbariCustomCommandExecutionHelper.class);
+    StackDAO stackDAO = injector.getInstance(StackDAO.class);
+    RepositoryVersionDAO repoVersionDAO = injector.getInstance(RepositoryVersionDAO.class);
+    ServiceComponentDesiredStateDAO componentDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class);
+    RepositoryVersionHelper repoVersionHelper = injector.getInstance(RepositoryVersionHelper.class);
+
+    CommandRepository commandRepo = helper.getCommandRepository(cluster, componentRM, host);
+
+    Assert.assertEquals(1, commandRepo.getRepositories().size());
+    CommandRepository.Repository repo = commandRepo.getRepositories().iterator().next();
+    Assert.assertEquals("http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0", repo.getBaseUrl());
+
+    RepositoryInfo ri = new RepositoryInfo();
+    ri.setBaseUrl("http://foo");
+    ri.setRepoName("HDP");
+    ri.setRepoId("new-id");
+    ri.setOsType("redhat6");
+    String operatingSystems = repoVersionHelper.serializeOperatingSystems(Collections.singletonList(ri));
+
+
+    StackEntity stackEntity = stackDAO.find(cluster.getDesiredStackVersion().getStackName(),
+        cluster.getDesiredStackVersion().getStackVersion());
+
+    RepositoryVersionEntity repositoryVersion = new RepositoryVersionEntity(stackEntity,
+        "2.1.1.1-1234", "2.1.1.1-1234", operatingSystems);
+    repositoryVersion = repoVersionDAO.merge(repositoryVersion);
+
+    // add a repo version associated with a component
+    ServiceComponentDesiredStateEntity componentEntity = componentDAO.findByName(cluster.getClusterId(),
+        serviceYARN.getName(), componentRM.getName());
+
+    ServiceComponentVersionEntity componentVersionEntity = new ServiceComponentVersionEntity();
+    componentVersionEntity.setRepositoryVersion(repositoryVersion);
+    componentVersionEntity.setUserName("admin");
+
+    componentEntity.setDesiredRepositoryVersion(repositoryVersion);
+    componentEntity.addVersion(componentVersionEntity);
+    componentEntity = componentDAO.merge(componentEntity);
+
+    // !!! make sure the override is set
+    commandRepo = helper.getCommandRepository(cluster, componentRM, host);
+
+    Assert.assertEquals(1, commandRepo.getRepositories().size());
+    repo = commandRepo.getRepositories().iterator().next();
+    Assert.assertEquals("http://foo", repo.getBaseUrl());
+
+    // verify that ZK is NOT overwritten
+    commandRepo = helper.getCommandRepository(cluster, componentZKC, host);
+
+    Assert.assertEquals(1, commandRepo.getRepositories().size());
+    repo = commandRepo.getRepositories().iterator().next();
+    Assert.assertEquals("http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.0.6.0", repo.getBaseUrl());
+  }
+
+  private void createClusterFixture(String clusterName, StackId stackId,
+    String respositoryVersion, String hostPrefix) throws AmbariException, AuthorizationException {
+
     String hostC6401 = hostPrefix + "-c6401";
     String hostC6402 = hostPrefix + "-c6402";
 
-    createCluster(clusterName, stackVersion);
+    OrmTestHelper ormTestHelper = injector.getInstance(OrmTestHelper.class);
+    RepositoryVersionEntity repositoryVersion = ormTestHelper.getOrCreateRepositoryVersion(stackId,
+        respositoryVersion);
+
+    createCluster(clusterName, stackId.getStackId());
 
     addHost(hostC6401, clusterName);
     addHost(hostC6402, clusterName);
 
-    clusters.getCluster(clusterName);
-    createService(clusterName, "YARN", null);
-    createService(clusterName, "GANGLIA", null);
-    createService(clusterName, "ZOOKEEPER", null);
-    createService(clusterName, "FLUME", null);
+    Cluster cluster = clusters.getCluster(clusterName);
+    Assert.assertNotNull(cluster);
+
+    createService(clusterName, "YARN", repositoryVersion);
+    createService(clusterName, "GANGLIA", repositoryVersion);
+    createService(clusterName, "ZOOKEEPER", repositoryVersion);
+    createService(clusterName, "FLUME", repositoryVersion);
 
     createServiceComponent(clusterName, "YARN", "RESOURCEMANAGER", State.INIT);
     createServiceComponent(clusterName, "YARN", "NODEMANAGER", State.INIT);
@@ -592,7 +659,6 @@ public class AmbariCustomCommandExecutionHelperTest {
     // this component should be not installed on any host
     createServiceComponent(clusterName, "FLUME", "FLUME_HANDLER", State.INIT);
 
-
     createServiceComponentHost(clusterName, "YARN", "RESOURCEMANAGER", hostC6401, null);
     createServiceComponentHost(clusterName, "YARN", "NODEMANAGER", hostC6401, null);
     createServiceComponentHost(clusterName, "GANGLIA", "GANGLIA_SERVER", hostC6401, State.INIT);
@@ -612,7 +678,7 @@ public class AmbariCustomCommandExecutionHelperTest {
     }
   }
   private void setOsFamily(Host host, String osFamily, String osVersion) {
-    Map<String, String> hostAttributes = new HashMap<String, String>();
+    Map<String, String> hostAttributes = new HashMap<>();
     hostAttributes.put("os_family", osFamily);
     hostAttributes.put("os_release_version", osVersion);
 
@@ -625,17 +691,17 @@ public class AmbariCustomCommandExecutionHelperTest {
     ambariManagementController.createCluster(r);
   }
 
-  private void createService(String clusterName,
-      String serviceName, State desiredState) throws AmbariException, AuthorizationException {
-    String dStateStr = null;
-    if (desiredState != null) {
-      dStateStr = desiredState.toString();
-    }
-    ServiceRequest r1 = new ServiceRequest(clusterName, serviceName, dStateStr);
-    Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
+  private void createService(String clusterName, String serviceName,
+      RepositoryVersionEntity repositoryVersion) throws AmbariException, AuthorizationException {
+
+    ServiceRequest r1 = new ServiceRequest(clusterName, serviceName,
+        repositoryVersion.getId(), null, "false");
+
+    Set<ServiceRequest> requests = new HashSet<>();
     requests.add(r1);
 
-    ServiceResourceProviderTest.createServices(ambariManagementController, requests);
+    ServiceResourceProviderTest.createServices(ambariManagementController,
+        injector.getInstance(RepositoryVersionDAO.class), requests);
   }
 
   private void createServiceComponent(String clusterName,
@@ -648,7 +714,7 @@ public class AmbariCustomCommandExecutionHelperTest {
     ServiceComponentRequest r = new ServiceComponentRequest(clusterName,
         serviceName, componentName, dStateStr);
     Set<ServiceComponentRequest> requests =
-        new HashSet<ServiceComponentRequest>();
+      new HashSet<>();
     requests.add(r);
     ComponentResourceProviderTest.createComponents(ambariManagementController, requests);
   }
@@ -662,7 +728,7 @@ public class AmbariCustomCommandExecutionHelperTest {
     ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName,
         serviceName, componentName, hostname, dStateStr);
     Set<ServiceComponentHostRequest> requests =
-        new HashSet<ServiceComponentHostRequest>();
+      new HashSet<>();
     requests.add(r);
     ambariManagementController.createHostComponents(requests);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java
index e9b4aa7..61a5ed6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/RootServiceResponseFactoryTest.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
@@ -109,8 +109,7 @@ public class RootServiceResponseFactoryTest {
     RootServiceResponseFactory.Components ambariServerComponent = RootServiceResponseFactory.Components.AMBARI_SERVER;
 
     // Request null service name, not-null component name
-    request = new RootServiceComponentRequest(null,
-        ambariServerComponent.name());
+    request = new RootServiceComponentRequest(null, ambariServerComponent.name());
 
     try {
       rootServiceComponents = responseFactory.getRootServiceComponents(request);
@@ -119,8 +118,8 @@ public class RootServiceResponseFactoryTest {
     }
 
     // Request existent service name, null component name
-    request = new RootServiceComponentRequest(
-        RootServiceResponseFactory.Services.AMBARI.name(), null);
+    String serviceName = RootServiceResponseFactory.Services.AMBARI.name();
+    request = new RootServiceComponentRequest(serviceName, null);
 
     rootServiceComponents = responseFactory.getRootServiceComponents(request);
     assertEquals(
@@ -142,7 +141,7 @@ public class RootServiceResponseFactoryTest {
         }
       } else {
         assertTrue(rootServiceComponents.contains(new RootServiceComponentResponse(
-            component.name(), RootServiceResponseFactory.NOT_APPLICABLE,
+            serviceName, component.name(), RootServiceResponseFactory.NOT_APPLICABLE,
             Collections.<String, String> emptyMap())));
       }
     }


Mime
View raw message