This is an automated email from the ASF dual-hosted git repository.

mradhakrishnan pushed a commit to branch branch-feature-AMBARI-14714
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/branch-feature-AMBARI-14714 by 
this push:
     new 54da5c0  [AMBARI-22992] Update error handling during mpack 
installation (#363)
54da5c0 is described below

commit 54da5c00a2c265ea67bbdccf1374964acae6e199
Author: mradha25 <mradhakrish...@hortonworks.com>
AuthorDate: Thu Feb 15 12:09:52 2018 -0800

    [AMBARI-22992] Update error handling during mpack installation (#363)
    
    * [AMBARI-22992] Update error handling during mpack installation
    
    * [AMBARI-22997] cluster-settings.xml is not present in 
/var/lib/ambari-server/resources post ambari installation
    
    * [AMBARI-22992] Update error handling during mpack installation - review 
comments
---
 ambari-server/src/main/assemblies/server.xml       |  5 ++
 .../apache/ambari/server/mpack/MpackManager.java   | 53 +++++++---------------
 2 files changed, 21 insertions(+), 37 deletions(-)

diff --git a/ambari-server/src/main/assemblies/server.xml 
b/ambari-server/src/main/assemblies/server.xml
index d31b773..cc6c82b 100644
--- a/ambari-server/src/main/assemblies/server.xml
+++ b/ambari-server/src/main/assemblies/server.xml
@@ -316,6 +316,11 @@
     </file>
     <file>
       <fileMode>755</fileMode>
+      <source>target/classes/cluster-settings.xml</source>
+      <outputDirectory>/var/lib/ambari-server/resources</outputDirectory>
+    </file>
+    <file>
+      <fileMode>755</fileMode>
       <source>target/classes/Ambari-DDL-Postgres-CREATE.sql</source>
       <outputDirectory>/var/lib/ambari-server/resources</outputDirectory>
     </file>
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManager.java 
b/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManager.java
index 0aee6a7..e272817 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManager.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManager.java
@@ -48,7 +48,6 @@ import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.state.Module;
 import org.apache.ambari.server.state.Mpack;
 import org.apache.ambari.server.state.OsSpecific;
-import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.stack.StackMetainfoXml;
 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
 import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
@@ -208,13 +207,13 @@ public class MpackManager {
     if (mpackId != null) {
       mpackMap.put(mpackId, mpack);
       mpack.setMpackId(mpackId);
-      populateStackDB(mpack);
-      return new MpackResponse(mpack);
-    } else {
-      String message = "Mpack :" + mpackRequest.getMpackName() + " version: " 
+ mpackRequest.getMpackVersion()
-        + " already exists in server";
-      throw new ResourceAlreadyExistsException(message);
+      if (populateStackDB(mpack))
+        return new MpackResponse(mpack);
     }
+    String message = "Mpack :" + mpackRequest.getMpackName() + " version: " + 
mpackRequest.getMpackVersion()
+      + " already exists in server";
+    throw new ResourceAlreadyExistsException(message);
+
   }
 
   /***
@@ -433,17 +432,8 @@ public class MpackManager {
    */
   private void createSymLinks(Mpack mpack) throws IOException {
 
-    String stackId = mpack.getStackId();
-    String stackName = "";
-    String stackVersion = "";
-    if (stackId == null) {
-      stackName = mpack.getName();
-      stackVersion = mpack.getVersion();
-    } else {
-      StackId id = new StackId(stackId);
-      stackName = id.getStackName();
-      stackVersion = id.getStackVersion();
-    }
+    String stackName = mpack.getName();
+    String stackVersion = mpack.getVersion();
     File stack = new File(stackRoot + "/" + stackName);
     Path stackPath = Paths.get(stackRoot + "/" + stackName + "/" + 
stackVersion);
     Path mpackPath = Paths.get(mpacksStaging + "/" + mpack.getName() + "/" + 
mpack.getVersion());
@@ -517,8 +507,8 @@ public class MpackManager {
     String mpackName = mpack.getName();
     String mpackVersion = mpack.getVersion();
     List resultSet = mpackDAO.findByNameVersion(mpackName, mpackVersion);
-
-    if (resultSet.size() == 0) {
+    StackEntity stackEntity = stackDAO.find(mpackName, mpackVersion);
+    if (resultSet.size() == 0 && stackEntity == null) {
       LOG.info("Adding mpack {}-{} to the database", mpackName, mpackVersion);
 
       MpackEntity mpackEntity = new MpackEntity();
@@ -540,20 +530,10 @@ public class MpackManager {
    * @param mpack
    * @throws IOException
    */
-  protected void populateStackDB(Mpack mpack) throws IOException {
-
-    String stackId = mpack.getStackId();
-    String stackName = "";
-    String stackVersion = "";
-    if (stackId == null) {
-      stackName = mpack.getName();
-      stackVersion = mpack.getVersion();
-    } else {
-      StackId id = new StackId(stackId);
-      stackName = id.getStackName();
-      stackVersion = id.getStackVersion();
-    }
+  protected boolean populateStackDB(Mpack mpack) throws IOException {
 
+    String stackName = mpack.getName();
+    String stackVersion = mpack.getVersion();
     StackEntity stackEntity = stackDAO.find(stackName, stackVersion);
     if (stackEntity == null) {
       LOG.info("Adding stack {}-{} to the database", stackName, stackVersion);
@@ -563,11 +543,10 @@ public class MpackManager {
       stackEntity.setStackVersion(stackVersion);
       stackEntity.setMpackId(mpack.getMpackId());
       stackDAO.create(stackEntity);
+      return true;
     } else {
-      LOG.info("Updating stack {}-{} to the database", stackName, 
stackVersion);
-
-      stackEntity.setMpackId(mpack.getMpackId());
-      stackDAO.merge(stackEntity);
+      LOG.error("Stack {}-{} already exists in the database", stackName, 
stackVersion);
+      return false;
     }
   }
 

-- 
To stop receiving notification emails like this one, please contact
mradhakrish...@apache.org.

Reply via email to