You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2015/06/19 20:06:25 UTC

ambari git commit: AMBARI-12012. Install packages doesn't update actual version with build number if installation timesout on all hosts (alejandro)

Repository: ambari
Updated Branches:
  refs/heads/trunk cbc016073 -> 24f1cdec4


AMBARI-12012. Install packages doesn't update actual version with build number if installation timesout on all hosts (alejandro)


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

Branch: refs/heads/trunk
Commit: 24f1cdec4a315e44b602867c24e2766a338a656f
Parents: cbc0160
Author: Alejandro Fernandez <af...@hortonworks.com>
Authored: Thu Jun 18 17:21:09 2015 -0700
Committer: Alejandro Fernandez <af...@hortonworks.com>
Committed: Fri Jun 19 11:00:16 2015 -0700

----------------------------------------------------------------------
 .../DistributeRepositoriesStructuredOutput.java |  2 +-
 .../AmbariManagementControllerImpl.java         |  2 +-
 .../DistributeRepositoriesActionListener.java   | 81 +++++++++++---------
 .../org/apache/ambari/server/state/Alert.java   |  1 +
 .../svccomphost/ServiceComponentHostImpl.java   |  5 ++
 .../custom_actions/scripts/install_packages.py  | 40 +++++-----
 6 files changed, 73 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/24f1cdec/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/DistributeRepositoriesStructuredOutput.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/DistributeRepositoriesStructuredOutput.java b/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/DistributeRepositoriesStructuredOutput.java
index f1d6aad..662b856 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/DistributeRepositoriesStructuredOutput.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/DistributeRepositoriesStructuredOutput.java
@@ -48,7 +48,7 @@ public class DistributeRepositoriesStructuredOutput {
   private String packageInstallationResult;
 
   /**
-   * The actual version returned
+   * The actual version returned, even when a failure during install occurs.
    */
   @SerializedName("actual_version")
   private String actualVersion;

http://git-wip-us.apache.org/repos/asf/ambari/blob/24f1cdec/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 42f4708..de9ae52 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
@@ -953,7 +953,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
       try {
         if (!clusters.getClustersForHost(request.getHostname()).contains(cluster)) {
           // case where host exists but not associated with given cluster
-          LOG.error("Host doesn't belong to cluster");
+          LOG.error("Host doesn't belong to cluster - " + request.getHostname());
           throw new ParentObjectNotFoundException("Parent Host resource doesn't exist",
               new HostNotFoundException(request.getClusterName(), request.getHostname()));
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/24f1cdec/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java
index 5600ef1..7ba29ee 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java
@@ -99,7 +99,7 @@ public class DistributeRepositoriesActionListener {
     String repositoryVersion = null;
 
     if (event.getCommandReport() == null) {
-      LOG.error("Command report is null, marking action as INSTALL_FAILED");
+      LOG.error("Command report is null, will set all INSTALLING versions for host {} to INSTALL_FAILED.", event.getHostname());
     } else {
       // Parse structured output
       try {
@@ -111,56 +111,63 @@ public class DistributeRepositoriesActionListener {
 
         if (event.getCommandReport().getStatus().equals(HostRoleStatus.COMPLETED.toString())) {
           newHostState = RepositoryVersionState.INSTALLED;
+        }
 
-          if (null != structuredOutput.getActualVersion() &&
-              null != structuredOutput.getInstalledRepositoryVersion() &&
-              null != structuredOutput.getStackId() &&
-              !structuredOutput.getActualVersion().equals(structuredOutput.getInstalledRepositoryVersion())) {
-
-            // !!! getInstalledRepositoryVersion() from the agent is the one
-            // entered in the UI.  getActualVersion() is computed.
-
-            StackId stackId = new StackId(structuredOutput.getStackId());
-            RepositoryVersionEntity version = repoVersionDAO.findByStackAndVersion(
-                stackId, structuredOutput.getInstalledRepositoryVersion());
+        // Handle the case in which the version to install did not contain the build number,
+        // but the structured output does contain the build number.
+        if (null != structuredOutput.getActualVersion() && !structuredOutput.getActualVersion().isEmpty() &&
+            null != structuredOutput.getInstalledRepositoryVersion() && !structuredOutput.getInstalledRepositoryVersion().isEmpty() &&
+            null != structuredOutput.getStackId() && !structuredOutput.getStackId().isEmpty() &&
+            !structuredOutput.getActualVersion().equals(structuredOutput.getInstalledRepositoryVersion())) {
+
+          // !!! getInstalledRepositoryVersion() from the agent is the one
+          // entered in the UI.  getActualVersion() is computed.
+
+          StackId stackId = new StackId(structuredOutput.getStackId());
+          RepositoryVersionEntity version = repoVersionDAO.findByStackAndVersion(
+              stackId, structuredOutput.getInstalledRepositoryVersion());
+
+          if (null != version) {
+            LOG.info("Repository version {} was found, but {} is the actual value",
+                structuredOutput.getInstalledRepositoryVersion(),
+                structuredOutput.getActualVersion());
+            // !!! the entered version is not correct
+            version.setVersion(structuredOutput.getActualVersion());
+            repoVersionDAO.merge(version);
+            repositoryVersion = structuredOutput.getActualVersion();
+          } else {
+            // !!! extra check that the actual version is correct
+            stackId = new StackId(structuredOutput.getStackId());
+            version = repoVersionDAO.findByStackAndVersion(stackId,
+                structuredOutput.getActualVersion());
+
+            LOG.debug("Repository version {} was not found, check for {}.  Found={}",
+                structuredOutput.getInstalledRepositoryVersion(),
+                structuredOutput.getActualVersion(),
+                Boolean.valueOf(null != version));
 
             if (null != version) {
-              LOG.info("Repository version {} was found, but {} is the actual value",
-                  structuredOutput.getInstalledRepositoryVersion(),
-                  structuredOutput.getActualVersion());
-              // !!! the entered version is not correct
-              version.setVersion(structuredOutput.getActualVersion());
-              repoVersionDAO.merge(version);
               repositoryVersion = structuredOutput.getActualVersion();
-            } else {
-              // !!! extra check that the actual version is correct
-              stackId = new StackId(structuredOutput.getStackId());
-              version = repoVersionDAO.findByStackAndVersion(stackId,
-                  structuredOutput.getActualVersion());
-
-              LOG.debug("Repository version {} was not found, check for {}.  Found={}",
-                  structuredOutput.getInstalledRepositoryVersion(),
-                  structuredOutput.getActualVersion(),
-                  Boolean.valueOf(null != version));
-
-              if (null != version) {
-                repositoryVersion = structuredOutput.getActualVersion();
-              }
             }
           }
         }
       } catch (JsonSyntaxException e) {
-        LOG.error("Can not parse structured output %s", e);
+        LOG.error("Cannot parse structured output %s", e);
       }
     }
 
     List<HostVersionEntity> hostVersions = hostVersionDAO.get().findByHost(event.getHostname());
-    // We have to iterate over all host versions. Otherwise server-side command aborts (that do not
-    // provide exact host stack version info) would be ignored
+      // We have to iterate over all host versions for this host. Otherwise server-side command aborts (that do not
+      // provide exact host stack version info) would be ignored
     for (HostVersionEntity hostVersion : hostVersions) {
-      if (repositoryVersion != null && ! hostVersion.getRepositoryVersion().getVersion().equals(repositoryVersion)) {
+
+      if (repositoryVersion != null && !hostVersion.getRepositoryVersion().getVersion().equals(repositoryVersion)) {
         continue;
       }
+
+      // If repository version is null, it means that we were not able to determine any information (perhaps structured-out was empty),
+      // so we should transition from INSTALLING to INSTALL_FAILED
+
       // If we know exact host stack version, there will be single execution of a code below
       if (hostVersion.getState() == RepositoryVersionState.INSTALLING) {
         hostVersion.setState(newHostState);
@@ -172,7 +179,7 @@ public class DistributeRepositoriesActionListener {
               hostVersion.getRepositoryVersion().getStackId(),
               hostVersion.getRepositoryVersion().getVersion());
         } catch (AmbariException e) {
-          LOG.error("Cannot get cluster with Id " + clusterId.toString(), e);
+          LOG.error("Cannot get cluster with Id " + clusterId.toString() + " to recalculate its ClusterVersion.", e);
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/24f1cdec/ambari-server/src/main/java/org/apache/ambari/server/state/Alert.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Alert.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Alert.java
index be99d96..f91d372 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Alert.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Alert.java
@@ -238,6 +238,7 @@ public class Alert {
   public String toString() {
     StringBuilder sb = new StringBuilder();
     sb.append('{');
+    sb.append("cluster=").append(cluster).append(", ");
     sb.append("state=").append(state).append(", ");
     sb.append("name=").append(name).append(", ");
     sb.append("service=").append(service).append(", ");

http://git-wip-us.apache.org/repos/asf/ambari/blob/24f1cdec/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
index 484bf79..1e757f6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
@@ -918,6 +918,11 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
     }
 
     if (!oldState.equals(getState())) {
+      LOG.info("Host role transitioned to a new state"
+               + ", serviceComponentName=" + getServiceComponentName()
+               + ", hostName=" + getHostName()
+               + ", oldState=" + oldState
+               + ", currentState=" + getState());
       if (LOG.isDebugEnabled()) {
         LOG.debug("ServiceComponentHost transitioned to a new state"
             + ", serviceComponentName=" + getServiceComponentName()

http://git-wip-us.apache.org/repos/asf/ambari/blob/24f1cdec/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 f8b2308..ffe9815 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
@@ -44,7 +44,7 @@ class InstallPackages(Script):
   REPO_FILE_NAME_PREFIX = 'HDP-'
 
   def actionexecute(self, env):
-    delayed_fail = False
+    num_errors = 0
     package_install_result = False
 
     # Parse parameters
@@ -83,12 +83,19 @@ class InstallPackages(Script):
 
       installed_repositories = list_ambari_managed_repos()
     except Exception, err:
-      print "Can not distribute repositories."
+      print "Cannot distribute repositories."
       print traceback.format_exc()
-      delayed_fail = True
+      num_errors += 1
+
+    # Build structured output with initial values
+    structured_output = {
+      'ambari_repositories': installed_repositories,
+      'installed_repository_version': repository_version,
+      'stack_id': stack_id
+    }
 
     # Install packages
-    if not delayed_fail:
+    if not num_errors:
       packages_were_checked = False
       try:
         packages_installed_before = []
@@ -100,9 +107,9 @@ class InstallPackages(Script):
           Package(name, use_repos=list(current_repo_files) if OSCheck.is_ubuntu_family() else current_repositories)
         package_install_result = True
       except Exception, err:
-        print "Can not install packages."
+        print "Cannot install packages."
         print traceback.format_exc()
-        delayed_fail = True
+        num_errors += 1
 
         # Remove already installed packages in case of fail
         if packages_were_checked and packages_installed_before:
@@ -121,24 +128,19 @@ class InstallPackages(Script):
             if package_version_string and (package_version_string in package):
               Package(package, action="remove")
 
-    # Build structured output
-    structured_output = {
-      'ambari_repositories': installed_repositories,
-      'installed_repository_version': repository_version,
-      'stack_id': stack_id,
-      'package_installation_result': 'SUCCESS' if package_install_result else 'FAIL'
-    }
+    # Add more values to structured_out
+    structured_output['package_installation_result'] = 'SUCCESS' if package_install_result else 'FAIL'
 
-    if package_install_result:
-      new_versions = self.hdp_versions()
-      deltas = set(new_versions) - set(old_versions)
-      if 1 == len(deltas):
-        structured_output['actual_version'] = next(iter(deltas))
+    # Even if it failed or did a partial install, report the new version if possible.
+    new_versions = self.hdp_versions()
+    deltas = set(new_versions) - set(old_versions)
+    if 1 == len(deltas):
+      structured_output['actual_version'] = next(iter(deltas))
 
     self.put_structured_out(structured_output)
 
     # Provide correct exit code
-    if delayed_fail:
+    if num_errors > 0:
       raise Fail("Failed to distribute repositories/install packages")
 
   def install_repository(self, url_info, repository_version, append_to_file):