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-15977. Using a public repo definition file is not reporting correct versions on blueprint install (ncole)
Date Tue, 19 Apr 2016 21:30:59 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 198acaa01 -> 6eb521d96


AMBARI-15977. Using a public repo definition file is not reporting correct versions on blueprint
install (ncole)


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

Branch: refs/heads/trunk
Commit: 6eb521d96ec411cec7200c3581a79ed711ad0271
Parents: 198acaa
Author: Nate Cole <ncole@hortonworks.com>
Authored: Tue Apr 19 10:42:27 2016 -0400
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Tue Apr 19 17:30:48 2016 -0400

----------------------------------------------------------------------
 .../libraries/script/script.py                  |  7 ++
 .../ambari/server/agent/ExecutionCommand.java   |  5 ++
 .../ambari/server/agent/HeartbeatProcessor.java |  7 +-
 .../AmbariManagementControllerImpl.java         | 18 ++++-
 .../ClusterStackVersionResourceProvider.java    |  1 +
 .../VersionDefinitionResourceProvider.java      |  2 +-
 .../HostComponentVersionAdvertisedEvent.java    | 18 +++++
 .../listeners/upgrade/StackVersionListener.java | 15 ++++
 .../state/repository/VersionDefinitionXml.java  | 24 +++---
 .../custom_actions/scripts/install_packages.py  | 12 +++
 .../VersionDefinitionResourceProviderTest.java  |  4 +-
 .../upgrade/StackVersionListenerTest.java       | 29 +++++++
 .../server/view/ViewDirectoryWatcherTest.java   | 26 ++++---
 .../custom_actions/TestInstallPackages.py       | 80 ++++++++++++++++++++
 14 files changed, 221 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-common/src/main/python/resource_management/libraries/script/script.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/script/script.py
b/ambari-common/src/main/python/resource_management/libraries/script/script.py
index 31d7b2a..193138b 100644
--- a/ambari-common/src/main/python/resource_management/libraries/script/script.py
+++ b/ambari-common/src/main/python/resource_management/libraries/script/script.py
@@ -171,6 +171,13 @@ class Script(object):
       if component_version:
         self.put_structured_out({"version": component_version})
 
+        # if repository_version_id is passed, pass it back with the version
+        from resource_management.libraries.functions.default import default
+        repo_version_id = default("/hostLevelParams/repository_version_id", None)
+        if repo_version_id:
+          self.put_structured_out({"repository_version_id": repo_version_id})
+
+
   def should_expose_component_version(self, command_name):
     """
     Analyzes config and given command to determine if stack version should be written

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
b/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
index 31635ed..34a0918 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
@@ -392,6 +392,11 @@ public class ExecutionCommand extends AgentCommand {
      * The key indicating that there is an un-finalized upgrade which is suspended.
      */
     String UPGRADE_SUSPENDED = "upgrade_suspended";
+    /**
+     * When installing packages, optionally provide the row id the version is for in
+     * order to precisely match response data.
+     */
+    String REPO_VERSION_ID = "repository_version_id";
   }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
index 8e50da6..c587e9f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartbeatProcessor.java
@@ -481,8 +481,10 @@ public class HeartbeatProcessor extends AbstractService{
               }
 
               String newVersion = structuredOutput == null ? null : structuredOutput.version;
+              Long repoVersionId = structuredOutput == null ? null : structuredOutput.repositoryVersionId;
 
-              HostComponentVersionAdvertisedEvent event = new HostComponentVersionAdvertisedEvent(cl,
scHost, newVersion);
+              HostComponentVersionAdvertisedEvent event = new HostComponentVersionAdvertisedEvent(
+                  cl, scHost, newVersion, repoVersionId);
 
               versionEventPublisher.publish(event);
             }
@@ -736,5 +738,8 @@ public class HeartbeatProcessor extends AbstractService{
     @SerializedName("direction")
     private Direction upgradeDirection = null;
 
+    @SerializedName("repository_version_id")
+    private Long repositoryVersionId;
+
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index 6219205..6dbceba 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -261,6 +261,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
   private ClusterDAO clusterDAO;
   @Inject
   private CredentialStoreService credentialStoreService;
+  @Inject
+  private ClusterVersionDAO clusterVersionDAO;
 
   private MaintenanceStateHelper maintenanceStateHelper;
 
@@ -2205,8 +2207,18 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
     hostParams.put(REPO_INFO, repoInfo);
     hostParams.putAll(getRcaParameters());
 
-    RepositoryVersionEntity repoVersion = (null == cluster.getCurrentClusterVersion()) ?
null :
-        cluster.getCurrentClusterVersion().getRepositoryVersion();
+    RepositoryVersionEntity repoVersion = null;
+    if (null != cluster.getCurrentClusterVersion()) {
+      repoVersion = cluster.getCurrentClusterVersion().getRepositoryVersion();
+    } else {
+      List<ClusterVersionEntity> list = clusterVersionDAO.findByClusterAndState(cluster.getClusterName(),
+          RepositoryVersionState.INIT);
+      if (1 == list.size()) {
+        repoVersion = list.get(0).getRepositoryVersion();
+      }
+
+    }
+
     if (null != repoVersion) {
       try {
         VersionDefinitionXml xml = repoVersion.getRepositoryXml();
@@ -2217,6 +2229,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
         throw new AmbariException(String.format("Could not load version xml from repo version
%s",
             repoVersion.getVersion()), e);
       }
+
+      hostParams.put(KeyNames.REPO_VERSION_ID, repoVersion.getId().toString());
     }
 
     List<ServiceOsSpecific.Package> packages =

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/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 a85f939..01333d5 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
@@ -559,6 +559,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
     params.put("repository_version", repoVersion.getVersion());
     params.put("base_urls", repoList);
     params.put(KeyNames.PACKAGE_LIST, packageList);
+    params.put(KeyNames.REPO_VERSION_ID, repoVersion.getId().toString());
 
     VersionDefinitionXml xml = null;
     try {

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProvider.java
index b5b12d8..e26adde 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProvider.java
@@ -524,7 +524,7 @@ public class VersionDefinitionResourceProvider extends AbstractAuthorizedResourc
     }
 
     setResourceProperty(resource, VERSION_DEF_TYPE_PROPERTY_ID, xml.release.repositoryType,
requestedIds);
-    setResourceProperty(resource, VERSION_DEF_FULL_VERSION, xml.release.version, requestedIds);
+    setResourceProperty(resource, VERSION_DEF_FULL_VERSION, xml.release.getFullVersion(),
requestedIds);
     setResourceProperty(resource, VERSION_DEF_RELEASE_BUILD, xml.release.build, requestedIds);
     setResourceProperty(resource, VERSION_DEF_RELEASE_COMPATIBLE_WITH, xml.release.compatibleWith,
requestedIds);
     setResourceProperty(resource, VERSION_DEF_RELEASE_NOTES, xml.release.releaseNotes, requestedIds);

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentVersionAdvertisedEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentVersionAdvertisedEvent.java
b/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentVersionAdvertisedEvent.java
index 11ca72b..d40aade 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentVersionAdvertisedEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/HostComponentVersionAdvertisedEvent.java
@@ -29,6 +29,19 @@ public class HostComponentVersionAdvertisedEvent extends ClusterEvent {
   protected Cluster cluster;
   protected ServiceComponentHost sch;
   protected String version;
+  protected Long repoVersionId;
+
+  /**
+   * Constructor.
+   *
+   * @param cluster: cluster.
+   * @param sch: the service component host
+   */
+  public HostComponentVersionAdvertisedEvent(Cluster cluster, ServiceComponentHost sch,
+      String version, Long repoVersionId) {
+    this(cluster, sch, version);
+    this.repoVersionId = repoVersionId;
+  }
 
   /**
    * Constructor.
@@ -56,6 +69,10 @@ public class HostComponentVersionAdvertisedEvent extends ClusterEvent {
     return version;
   }
 
+  public Long getRepositoryVersionId() {
+    return repoVersionId;
+  }
+
   /**
    * {@inheritDoc}
    */
@@ -67,6 +84,7 @@ public class HostComponentVersionAdvertisedEvent extends ClusterEvent {
     buffer.append(", componentName=").append(sch.getServiceComponentName());
     buffer.append(", hostName=").append(sch.getHostName());
     buffer.append(", version=").append(version);
+    buffer.append(", repo_version_id=").append(repoVersionId);
     buffer.append("}");
     return buffer.toString();
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListener.java
b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListener.java
index 2a627dd..b14e9e5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListener.java
@@ -24,6 +24,7 @@ import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.EagerSingleton;
 import org.apache.ambari.server.events.HostComponentVersionAdvertisedEvent;
 import org.apache.ambari.server.events.publishers.VersionEventPublisher;
+import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.ServiceComponent;
@@ -62,6 +63,9 @@ public class StackVersionListener {
    */
   private Lock m_stackVersionLock = new ReentrantLock();
 
+  @Inject
+  private RepositoryVersionDAO repositoryVersionDAO;
+
   /**
    * Constructor.
    *
@@ -88,6 +92,17 @@ public class StackVersionListener {
 
     m_stackVersionLock.lock();
 
+    if (null != event.getRepositoryVersionId()) {
+      // !!! make sure the repo_version record actually has the same version.
+      // This is NOT true when installing a cluster using a public repo where the
+      // exact version is not known in advance.
+      RepositoryVersionEntity rve = repositoryVersionDAO.findByPK(event.getRepositoryVersionId());
+      if (null != rve && !rve.getVersion().equals(newVersion)) {
+        rve.setVersion(newVersion);
+        repositoryVersionDAO.merge(rve);
+      }
+    }
+
     // Update host component version value if needed
     try {
       ServiceComponent sc = cluster.getService(sch.getServiceName()).getServiceComponent(sch.getServiceComponentName());

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-server/src/main/java/org/apache/ambari/server/state/repository/VersionDefinitionXml.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/repository/VersionDefinitionXml.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/repository/VersionDefinitionXml.java
index 685a07c..3111a4a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/repository/VersionDefinitionXml.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/repository/VersionDefinitionXml.java
@@ -290,22 +290,22 @@ public class VersionDefinitionXml {
     xmlReader.nextTag();
     String xsdName = xmlReader.getAttributeValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI,
"noNamespaceSchemaLocation");
 
-    JAXBContext ctx = JAXBContext.newInstance(VersionDefinitionXml.class);
-    Unmarshaller unmarshaller = ctx.createUnmarshaller();
+    if (null == xsdName) {
+      throw new IllegalArgumentException("Provided XML does not have a Schema defined using
'noNamespaceSchemaLocation'");
+    }
 
-    InputStream xsdStream = null;
+    InputStream xsdStream = VersionDefinitionXml.class.getClassLoader().getResourceAsStream(xsdName);
 
-    if (null != xsdName) {
-      xsdStream = VersionDefinitionXml.class.getClassLoader().getResourceAsStream(xsdName);
+    if (null == xsdStream) {
+      throw new Exception(String.format("Could not load XSD identified by '%s'", xsdName));
+    }
 
-      if (null == xsdStream) {
-        throw new Exception(String.format("Could not load XSD identified by '%s'", xsdName));
-      }
+    JAXBContext ctx = JAXBContext.newInstance(VersionDefinitionXml.class);
+    Unmarshaller unmarshaller = ctx.createUnmarshaller();
 
-      SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-      Schema schema = factory.newSchema(new StreamSource(xsdStream));
-      unmarshaller.setSchema(schema);
-    }
+    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+    Schema schema = factory.newSchema(new StreamSource(xsdStream));
+    unmarshaller.setSchema(schema);
 
     try {
       VersionDefinitionXml xml = (VersionDefinitionXml) unmarshaller.unmarshal(xmlReader);

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py b/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py
index 709781e..3133984 100644
--- a/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py
+++ b/ambari-server/src/main/resources/custom_actions/scripts/install_packages.py
@@ -71,18 +71,24 @@ class InstallPackages(Script):
     signal.signal(signal.SIGTERM, self.abort_handler)
     signal.signal(signal.SIGINT, self.abort_handler)
 
+    self.repository_version_id = None
+
     # Select dict that contains parameters
     try:
       self.repository_version = config['roleParams']['repository_version']
       base_urls = json.loads(config['roleParams']['base_urls'])
       package_list = json.loads(config['roleParams']['package_list'])
       stack_id = config['roleParams']['stack_id']
+      if 'repository_version_id' in config['roleParams']:
+        self.repository_version_id = config['roleParams']['repository_version_id']
     except KeyError:
       # Last try
       self.repository_version = config['commandParams']['repository_version']
       base_urls = json.loads(config['commandParams']['base_urls'])
       package_list = json.loads(config['commandParams']['package_list'])
       stack_id = config['commandParams']['stack_id']
+      if 'repository_version_id' in config['commandParams']:
+        self.repository_version_id = config['commandParams']['repository_version_id']
 
     # current stack information
     self.current_stack_version_formatted = None
@@ -94,9 +100,11 @@ class InstallPackages(Script):
     self.stack_name = Script.get_stack_name()
     if self.stack_name is None:
       raise Fail("Cannot determine the stack name")
+
     self.stack_root_folder = Script.get_stack_root()
     if self.stack_root_folder is None:
       raise Fail("Cannot determine the stack's root directory")
+
     if self.repository_version is None:
       raise Fail("Cannot determine the repository version to install")
 
@@ -141,6 +149,10 @@ class InstallPackages(Script):
       'stack_id': stack_id,
       'package_installation_result': 'FAIL'
     }
+
+    if self.repository_version_id is not None:
+      self.structured_output['repository_version_id'] = self.repository_version_id
+
     self.put_structured_out(self.structured_output)
 
     if num_errors > 0:

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java
index 3637cab..c9fa9a3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java
@@ -335,12 +335,14 @@ public class VersionDefinitionResourceProviderTest {
     Assert.assertEquals(1, status.getAssociatedResources().size());
 
     Resource res = status.getAssociatedResources().iterator().next();
-    System.out.println(res.getPropertiesMap().keySet());
     // because we aren't using subresources, but return subresource-like properties, the
key is an empty string
     Assert.assertTrue(res.getPropertiesMap().containsKey(""));
     Map<String, Object> resMap = res.getPropertiesMap().get("");
     Assert.assertTrue(resMap.containsKey("operating_systems"));
 
+    Assert.assertTrue(res.getPropertiesMap().containsKey("VersionDefinition"));
+    Assert.assertEquals("2.2.0.8-5678", res.getPropertyValue("VersionDefinition/repository_version"));
+
     Request getRequest = PropertyHelper.getReadRequest("VersionDefinition");
     Set<Resource> results = versionProvider.getResources(getRequest, null);
     Assert.assertEquals(0, results.size());

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
index 784830d..3a8b396 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
@@ -20,9 +20,12 @@ package org.apache.ambari.server.events.listeners.upgrade;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.expectLastCall;
 
+import java.lang.reflect.Field;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.events.HostComponentVersionAdvertisedEvent;
 import org.apache.ambari.server.events.publishers.VersionEventPublisher;
+import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.UpgradeEntity;
 import org.apache.ambari.server.state.Cluster;
@@ -229,6 +232,32 @@ public class StackVersionListenerTest extends EasyMockSupport {
     sendEventAndVerify(VALID_NEW_VERSION);
   }
 
+  @Test
+  public void testSetRepositoryVersion() throws Exception {
+    expect(sch.getVersion()).andReturn(UNKNOWN_VERSION);
+
+    RepositoryVersionDAO dao = createNiceMock(RepositoryVersionDAO.class);
+    RepositoryVersionEntity entity = createNiceMock(RepositoryVersionEntity.class);
+    expect(entity.getVersion()).andReturn("2.4.0.0").once();
+    expect(dao.findByPK(1L)).andReturn(entity).once();
+    expect(dao.merge(entity)).andReturn(entity).once();
+
+    replayAll();
+
+    String newVersion = VALID_NEW_VERSION;
+
+    HostComponentVersionAdvertisedEvent event = new HostComponentVersionAdvertisedEvent(cluster,
sch, newVersion, 1L);
+    StackVersionListener listener = new StackVersionListener(publisher);
+    // !!! avoid injector for test class
+    Field field = StackVersionListener.class.getDeclaredField("repositoryVersionDAO");
+    field.setAccessible(true);
+    field.set(listener, dao);
+
+    listener.onAmbariEvent(event);
+
+    verifyAll();
+  }
+
   private void sendEventAndVerify(String newVersion) {
     HostComponentVersionAdvertisedEvent event = new HostComponentVersionAdvertisedEvent(cluster,
sch, newVersion);
     StackVersionListener listener = new StackVersionListener(publisher);

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDirectoryWatcherTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDirectoryWatcherTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDirectoryWatcherTest.java
index d9f8919..c1344fc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDirectoryWatcherTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewDirectoryWatcherTest.java
@@ -19,14 +19,13 @@
 
 package org.apache.ambari.server.view;
 
-import com.google.common.base.Function;
-import org.apache.ambari.server.configuration.Configuration;
-import org.apache.commons.io.FileDeleteStrategy;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
 
-import javax.annotation.Nullable;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -37,8 +36,15 @@ import java.util.concurrent.CountDownLatch;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.easymock.EasyMock.*;
+import javax.annotation.Nullable;
+
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.commons.io.FileDeleteStrategy;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.base.Function;
 
 public class ViewDirectoryWatcherTest {
 
@@ -105,7 +111,7 @@ public class ViewDirectoryWatcherTest {
     viewDirectoryWatcher.start();
     // Create a new File at destination
     createZipFile();
-    countDownLatch.await(7, SECONDS);
+    countDownLatch.await(30, SECONDS);
 
     // Expect watcher to respond
     verify(configuration, viewRegistry);

http://git-wip-us.apache.org/repos/asf/ambari/blob/6eb521d9/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/custom_actions/TestInstallPackages.py b/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
index e62978a..77e3bee 100644
--- a/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
+++ b/ambari-server/src/test/python/custom_actions/TestInstallPackages.py
@@ -973,3 +973,83 @@ class TestInstallPackages(RMFTestCase):
 
     self.assertFalse(write_actual_version_to_history_file_mock.called)
 
+  @patch("resource_management.libraries.functions.list_ambari_managed_repos.list_ambari_managed_repos")
+  @patch("resource_management.libraries.functions.packages_analyzer.allInstalledPackages")
+  @patch("resource_management.libraries.script.Script.put_structured_out")
+  @patch("resource_management.libraries.functions.stack_select.get_stack_versions")
+  @patch("resource_management.libraries.functions.repo_version_history.read_actual_version_from_history_file")
+  @patch("resource_management.libraries.functions.repo_version_history.write_actual_version_to_history_file")
+  def test_version_reporting_with_repository_version(self,
+                                                                                   write_actual_version_to_history_file_mock,
+                                                                                   read_actual_version_from_history_file_mock,
+                                                                                   stack_versions_mock,
+                                                                                   put_structured_out_mock,
allInstalledPackages_mock, list_ambari_managed_repos_mock):
+    stack_versions_mock.side_effect = [
+      [OLD_VERSION_STUB],  # before installation attempt
+      [OLD_VERSION_STUB, VERSION_STUB]
+    ]
+
+    config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
+    with open(config_file, "r") as f:
+      command_json = json.load(f)
+
+    command_json['roleParams']['repository_version'] = VERSION_STUB
+    command_json['roleParams']['repository_version_id'] = '2'
+
+    allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
+    list_ambari_managed_repos_mock.return_value = []
+    self.executeScript("scripts/install_packages.py",
+                       classname="InstallPackages",
+                       command="actionexecute",
+                       config_dict=command_json,
+                       target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
+                       os_type=('Redhat', '6.4', 'Final'),
+                       )
+    self.assertTrue(put_structured_out_mock.called)
+    self.assertEquals(put_structured_out_mock.call_args[0][0],
+                      {'package_installation_result': 'SUCCESS',
+                       'installed_repository_version': VERSION_STUB,
+                       'stack_id': 'HDP-2.2',
+                       'repository_version_id': '2',
+                       'actual_version': VERSION_STUB,
+                       'ambari_repositories': []})
+    self.assertTrue(write_actual_version_to_history_file_mock.called)
+    self.assertEquals(write_actual_version_to_history_file_mock.call_args[0], (VERSION_STUB_WITHOUT_BUILD_NUMBER,
VERSION_STUB))
+
+    stack_versions_mock.reset_mock()
+    write_actual_version_to_history_file_mock.reset_mock()
+    put_structured_out_mock.reset_mock()
+
+    # Test retrying install again
+    stack_versions_mock.side_effect = [
+      [OLD_VERSION_STUB, VERSION_STUB],
+      [OLD_VERSION_STUB, VERSION_STUB]
+    ]
+    read_actual_version_from_history_file_mock.return_value = VERSION_STUB
+
+    config_file = self.get_src_folder() + "/test/python/custom_actions/configs/install_packages_config.json"
+    with open(config_file, "r") as f:
+      command_json = json.load(f)
+
+    command_json['roleParams']['repository_version'] = VERSION_STUB
+    command_json['roleParams']['repository_version_id'] = '2'
+
+    allInstalledPackages_mock.side_effect = TestInstallPackages._add_packages
+    list_ambari_managed_repos_mock.return_value = []
+    self.executeScript("scripts/install_packages.py",
+                       classname="InstallPackages",
+                       command="actionexecute",
+                       config_dict=command_json,
+                       target=RMFTestCase.TARGET_CUSTOM_ACTIONS,
+                       os_type=('Redhat', '6.4', 'Final'),
+                       )
+    self.assertTrue(put_structured_out_mock.called)
+    self.assertEquals(put_structured_out_mock.call_args[0][0],
+                      {'package_installation_result': 'SUCCESS',
+                       'installed_repository_version': VERSION_STUB,
+                       'stack_id': 'HDP-2.2',
+                       'repository_version_id': '2',
+                       'actual_version': VERSION_STUB,
+                       'ambari_repositories': []})
+
+    self.assertFalse(write_actual_version_to_history_file_mock.called)
\ No newline at end of file


Mime
View raw message