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

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

commit a82e169c7ed66c4a38795f0617711c784bb224a3
Author: Jayush Luniya <[email protected]>
AuthorDate: Thu Sep 28 10:50:13 2017 -0700

    AMBARI-22082: Create missing parent directory when expanding mpack tarball 
(jluniya)
---
 .../ambari/server/controller/MpackResponse.java    |   4 +-
 .../controller/internal/MpackResourceProvider.java |  43 ++---
 .../apache/ambari/server/mpack/MpackManager.java   | 188 +++++++++++++++------
 .../server/state/{Mpacks.java => Mpack.java}       |   6 +-
 .../org/apache/ambari/server/state/MpackTest.java  |   2 +-
 5 files changed, 161 insertions(+), 82 deletions(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java
index 16eb03c..a2fc28a 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java
@@ -18,7 +18,7 @@
 package org.apache.ambari.server.controller;
 
 
-import org.apache.ambari.server.state.Mpacks;
+import org.apache.ambari.server.state.Mpack;
 import org.apache.ambari.server.controller.internal.MpackResourceProvider;
 
 import io.swagger.annotations.ApiModelProperty;
@@ -35,7 +35,7 @@ public class MpackResponse {
   private Long registryId;
   private String stackId;
 
-  public MpackResponse(Mpacks mpacks) {
+  public MpackResponse(Mpack mpacks) {
     this.mpackId = mpacks.getMpackId();
     this.mpackVersion = mpacks.getVersion();
     this.mpackUri = mpacks.getMpacksUri();
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java
index 70b6d74..694bf3c 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java
@@ -57,12 +57,10 @@ import org.apache.ambari.server.orm.entities.MpackEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.state.Packlet;
 import org.apache.ambari.server.state.StackId;
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.Validate;
 
 import com.google.inject.Inject;
 
-
 /**
  * ResourceProvider for Mpack instances
  */
@@ -78,10 +76,11 @@ public class MpackResourceProvider extends 
AbstractControllerResourceProvider {
   public static final String MPACK_URI = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "mpack_uri";
   public static final String PACKLETS = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "packlets";
   public static final String STACK_NAME_PROPERTY_ID = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "stack_name";
-  public static final String STACK_VERSION_PROPERTY_ID = RESPONSE_KEY + 
PropertyHelper.EXTERNAL_PATH_SEP + "stack_version";
+  public static final String STACK_VERSION_PROPERTY_ID =
+    RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "stack_version";
 
   private static Set<String> pkPropertyIds = new HashSet<>(
-          Arrays.asList(MPACK_ID, STACK_NAME_PROPERTY_ID, 
STACK_VERSION_PROPERTY_ID));
+    Arrays.asList(MPACK_ID, STACK_NAME_PROPERTY_ID, 
STACK_VERSION_PROPERTY_ID));
 
   /**
    * The property ids for an mpack resource.
@@ -163,6 +162,7 @@ public class MpackResourceProvider extends 
AbstractControllerResourceProvider {
 
   /***
    * Validates the request body for the required properties in order to create 
an Mpack resource.
+   *
    * @param mpackRequest
    */
   private void validateCreateRequest(MpackRequest mpackRequest) {
@@ -171,24 +171,24 @@ public class MpackResourceProvider extends 
AbstractControllerResourceProvider {
     final Long registryId = mpackRequest.getRegistryId();
     final String mpackVersion = mpackRequest.getMpackVersion();
 
-    if(registryId == null) {
+    if (registryId == null) {
       Validate.isTrue(mpackUrl != null);
       LOG.info("Received a createMpack request"
-              + ", mpackUrl=" + mpackUrl);
+        + ", mpackUrl=" + mpackUrl);
     } else {
       Validate.notNull(mpackName, "MpackName should not be null");
       Validate.notNull(mpackVersion, "MpackVersion should not be null");
       LOG.info("Received a createMpack request"
-              + ", mpackName=" + mpackName
-              + ", mpackVersion=" + mpackVersion
-              + ", registryId=" + registryId);
+        + ", mpackName=" + mpackName
+        + ", mpackVersion=" + mpackVersion
+        + ", registryId=" + registryId);
     }
     try {
       URI uri = new URI(mpackUrl);
       URL url = uri.toURL();
-      String jsonString = IOUtils.toString(url);
-    }catch(Exception e){
-      Validate.isTrue(e == null, e.getMessage() + " is an invalid mpack uri. 
Please check the download link for the mpack again.");
+    } catch (Exception e) {
+      Validate.isTrue(e == null,
+        e.getMessage() + " is an invalid mpack uri. Please check the download 
link for the mpack again.");
     }
   }
 
@@ -201,7 +201,7 @@ public class MpackResourceProvider extends 
AbstractControllerResourceProvider {
         return null;
       //Fetch Mpack Download Url using the given registry id
       else if (!propertyMap.containsKey(MPACK_URI)) {
-        mpackRequest.setRegistryId((Long) propertyMap.get(REGISTRY_ID));
+        mpackRequest.setRegistryId(Long.valueOf((String) 
propertyMap.get(REGISTRY_ID)));
         mpackRequest.setMpackName((String) propertyMap.get(MPACK_NAME));
         mpackRequest.setMpackVersion((String) propertyMap.get(MPACK_VERSION));
       }
@@ -215,8 +215,8 @@ public class MpackResourceProvider extends 
AbstractControllerResourceProvider {
 
   @Override
   public Set<Resource> getResources(Request request, Predicate predicate)
-          throws SystemException, UnsupportedPropertyException,
-          NoSuchResourceException, NoSuchParentResourceException {
+    throws SystemException, UnsupportedPropertyException,
+    NoSuchResourceException, NoSuchParentResourceException {
 
     Set<Resource> results = new LinkedHashSet<>();
     Long mpackId = null;
@@ -279,7 +279,7 @@ public class MpackResourceProvider extends 
AbstractControllerResourceProvider {
       }
       if (results.isEmpty()) {
         throw new NoSuchResourceException(
-                "The requested resource doesn't exist: " + predicate);
+          "The requested resource doesn't exist: " + predicate);
       }
     }
     return results;
@@ -287,15 +287,16 @@ public class MpackResourceProvider extends 
AbstractControllerResourceProvider {
 
   @Override
   protected RequestStatus deleteResourcesAuthorized(final Request request, 
Predicate predicate)
-          throws SystemException, UnsupportedPropertyException, 
NoSuchResourceException, NoSuchParentResourceException {
+    throws SystemException, UnsupportedPropertyException, 
NoSuchResourceException, NoSuchParentResourceException {
 
     final Long mpackId;
     Map<String, Object> propertyMap = new 
HashMap<>(PredicateHelper.getProperties(predicate));
     DeleteStatusMetaData deleteStatusMetaData = null;
 
-    //Allow deleting mpack only if there are no cluster services deploying 
using this mpack. Support deleting mpacks only if no cluster has been deployed
+    // Allow deleting mpack only if there are no cluster services deploying 
using this mpack.
+    // Support deleting mpacks only if no cluster has been deployed
     // (i.e. you should be able to delete an mpack during install wizard only).
-    //Todo : Relax the rule
+    // TODO : Relax the rule
     if (getManagementController().getClusters().getClusters().size() > 0) {
       throw new SystemException("Delete request cannot be completed since 
there is a cluster deployed");
     } else {
@@ -315,7 +316,8 @@ public class MpackResourceProvider extends 
AbstractControllerResourceProvider {
                 @Override
                 public DeleteStatusMetaData invoke() throws AmbariException {
                   if (stackEntity != null) {
-                    repositoryVersionDAO.removeByStack(new 
StackId(stackEntity.getStackName() + "-" + stackEntity.getStackVersion()));
+                    repositoryVersionDAO
+                      .removeByStack(new StackId(stackEntity.getStackName() + 
"-" + stackEntity.getStackVersion()));
                     stackDAO.removeByMpack(mpackId);
                     notifyDelete(Resource.Type.Stack, predicate);
                   }
@@ -340,6 +342,5 @@ public class MpackResourceProvider extends 
AbstractControllerResourceProvider {
       return getRequestStatus(null, null, deleteStatusMetaData);
     }
   }
-
 }
 
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 619823c..5ae7e1d 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
@@ -27,7 +27,7 @@ import org.apache.ambari.server.orm.dao.MpackDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.orm.entities.MpackEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
-import org.apache.ambari.server.state.Mpacks;
+import org.apache.ambari.server.state.Mpack;
 import org.apache.ambari.server.state.Packlet;
 import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
@@ -59,20 +59,25 @@ import java.io.IOException;
  * mpack information.
  */
 public class MpackManager {
-  protected Map<Long, Mpacks> mpackMap = new HashMap<>();
+  protected Map<Long, Mpack> mpackMap = new HashMap<>();
   private File mpackStaging;
   private MpackDAO mpackDAO;
   private StackDAO stackDAO;
-  private Mpacks mpack;
+  private Mpack mpack;
   private File stackRoot;
   private static final String MPACK_METADATA = "mpack.json";
   private static final String MPACK_TAR_LOCATION = "staging";
+  private static final String SERVICES_DIRECTORY = "services";
 
   private final static Logger LOG = 
LoggerFactory.getLogger(MpackManager.class);
 
   @AssistedInject
-  public MpackManager(@Assisted("mpackv2Staging") File mpackStagingLocation, 
@Assisted("stackRoot") File stackRootDir, MpackDAO mpackDAOObj, StackDAO 
stackDAOObj) {
-    mpackStaging = mpackStagingLocation;
+  public MpackManager(
+    @Assisted("mpacksv2Staging") File mpacksStagingLocation,
+    @Assisted("stackRoot") File stackRootDir,
+    MpackDAO mpackDAOObj,
+    StackDAO stackDAOObj) {
+    mpackStaging = mpacksStagingLocation;
     mpackDAO = mpackDAOObj;
     stackRoot = stackRootDir;
     stackDAO = stackDAOObj;
@@ -97,13 +102,17 @@ public class MpackManager {
               if (file.isDirectory()) {
                 String mpackVersion = file.getName();
                 List resultSet = mpackDAO.findByNameVersion(mpackName, 
mpackVersion);
-                MpackEntity mpackEntity = (MpackEntity) resultSet.get(0);
 
-                //Read the mpack.json file into Mpack Object for further use.
-                String mpackJsonContents = new 
String((Files.readAllBytes(Paths.get(file + "/" + MPACK_METADATA))), "UTF-8");
-                Gson gson = new Gson();
-                Mpacks existingMpack = gson.fromJson(mpackJsonContents, 
Mpacks.class);
-                mpackMap.put(mpackEntity.getMpackId(), existingMpack);
+                if (resultSet.size() > 0) {
+                  MpackEntity mpackEntity = (MpackEntity) resultSet.get(0);
+
+                  // Read the mpack.json file into Mpack Object for further 
use.
+                  String mpackJsonContents = new 
String((Files.readAllBytes(Paths.get(file + "/" + MPACK_METADATA))),
+                    "UTF-8");
+                  Gson gson = new Gson();
+                  Mpack existingMpack = gson.fromJson(mpackJsonContents, 
Mpack.class);
+                  mpackMap.put(mpackEntity.getMpackId(), existingMpack);
+                }
               }
             }
           }
@@ -114,7 +123,6 @@ public class MpackManager {
     }
   }
 
-
   /**
    * Parses mpack.json to fetch mpack and associated packlet information and
    * stores the mpack to the database and mpackMap
@@ -125,12 +133,13 @@ public class MpackManager {
    * @throws IllegalArgumentException
    * @throws ResourceAlreadyExistsException
    */
-  public MpackResponse registerMpack(MpackRequest mpackRequest) throws 
IOException, IllegalArgumentException, ResourceAlreadyExistsException {
+  public MpackResponse registerMpack(MpackRequest mpackRequest)
+    throws IOException, IllegalArgumentException, 
ResourceAlreadyExistsException {
 
     Long mpackId;
     String mpackName = "";
     String mpackVersion = "";
-    mpack = new Mpacks();
+    mpack = new Mpack();
     boolean isValidMetadata;
     String mpackDirectory = "";
     Path mpackTarPath;
@@ -144,12 +153,14 @@ public class MpackManager {
       //Todo : Madhu implement GET /registries/{registryId}/mpacks
       mpackTarPath = downloadMpack(mpackRequest.getMpackUri());
 
-      if (createMpackDirectory(mpackTarPath)) {
+      if (createMpackDirectory(mpack, mpackTarPath)) {
         isValidMetadata = validateMpackInfo(mpackName, mpackVersion, 
mpack.getName(), mpack.getVersion());
         if (isValidMetadata) {
           mpackDirectory = mpackStaging + File.separator + mpack.getName() + 
File.separator + mpack.getVersion();
         } else {
-          String message = "Incorrect information : Mismatch in - (" + 
mpackName + "," + mpack.getName() + ") or (" + mpackVersion + "," + 
mpack.getVersion() + ")";
+          String message =
+            "Incorrect information : Mismatch in - (" + mpackName + "," + 
mpack.getName() + ") or (" + mpackVersion
+              + "," + mpack.getVersion() + ")";
           throw new IllegalArgumentException(message); //Mismatch in 
information
         }
 
@@ -157,12 +168,12 @@ public class MpackManager {
     } else {    //Mpack registration using direct download
       mpackTarPath = downloadMpack(mpackRequest.getMpackUri());
 
-      if (createMpackDirectory(mpackTarPath)) {
+      if (createMpackDirectory(mpack, mpackTarPath)) {
         mpackDirectory = mpackStaging + File.separator + mpack.getName() + 
File.separator + mpack.getVersion();
         mpack.setMpacksUri(mpackRequest.getMpackUri());
       }
     }
-    extractMpackTar(mpackTarPath, mpackDirectory);
+    extractMpackTar(mpack, mpackTarPath, mpackDirectory);
     mpackId = populateDB(mpack);
 
     if (mpackId != null) {
@@ -171,50 +182,99 @@ public class MpackManager {
       populateStackDB(mpack);
       return new MpackResponse(mpack);
     } else {
-      String message = "Mpack :" + mpackRequest.getMpackName() + " version: " 
+ mpackRequest.getMpackVersion() + " already exists in server";
+      String message = "Mpack :" + mpackRequest.getMpackName() + " version: " 
+ mpackRequest.getMpackVersion()
+        + " already exists in server";
       throw new ResourceAlreadyExistsException(message);
     }
   }
 
-  /**
-   * Mpack is downloaded as a tar.gz file. It is extracted into 
mpack-v2-staging/{mpack-name}/{mpack-version}/ directory
+  /***
+   * A generic method to extract tar files.
    *
-   * @param mpackTarPath
-   * @param mpackDirectory
+   * @param tarPath
    * @throws IOException
    */
-  private void extractMpackTar(Path mpackTarPath, String mpackDirectory) 
throws IOException {
-    TarArchiveInputStream mpackTarFile = new TarArchiveInputStream(new 
GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(new 
File(String.valueOf(mpackTarPath))))));
-    // To read individual TAR file
+  private void extractTar(Path tarPath, File untarDirectory) throws 
IOException {
+    TarArchiveInputStream tarFile = new TarArchiveInputStream(
+      new GzipCompressorInputStream(new BufferedInputStream(new 
FileInputStream(new File(String.valueOf(tarPath))))));
     TarArchiveEntry entry = null;
     File outputFile = null;
     //Create a loop to read every single entry in TAR file
-    while ((entry = mpackTarFile.getNextTarEntry()) != null) {
-      outputFile = new File(mpackStaging, entry.getName());
+    while ((entry = tarFile.getNextTarEntry()) != null) {
+      outputFile = new File(untarDirectory, entry.getName());
+
       if (entry.isDirectory()) {
-        LOG.debug("Attempting to write output directory" + 
outputFile.getAbsolutePath());
         if (!outputFile.exists()) {
-          LOG.debug("Attempting to create output directory " + 
outputFile.getAbsolutePath());
+          LOG.debug("Creating output directory " + 
outputFile.getAbsolutePath());
           if (!outputFile.mkdirs()) {
-            throw new IllegalStateException(String.format("Couldn't create 
directory %s.", outputFile.getAbsolutePath()));
+            throw new IllegalStateException("Couldn't create directory " + 
outputFile.getAbsolutePath());
           }
         }
       } else {
-        LOG.debug("Creating output file %s." + outputFile.getAbsolutePath());
+        File parentDir = outputFile.getParentFile();
+        if (!parentDir.exists()) {
+          LOG.debug("Attempting to create output directory " + 
parentDir.getAbsolutePath());
+          if (!parentDir.mkdirs()) {
+            throw new IllegalStateException("Couldn't create directory " + 
parentDir.getAbsolutePath());
+          }
+        }
+        LOG.debug("Creating output file " + outputFile.getAbsolutePath());
         final OutputStream outputFileStream = new FileOutputStream(outputFile);
-        IOUtils.copy(mpackTarFile, outputFileStream);
+        IOUtils.copy(tarFile, outputFileStream);
         outputFileStream.close();
       }
     }
-    mpackTarFile.close();
+    tarFile.close();
+  }
+
+  /**
+   * Mpack is downloaded as a tar.gz file.
+   * It is extracted into 
/var/lib/ambari-server/resources/mpack-v2/{mpack-name}/{mpack-version} directory
+   *
+   * @param mpack          Mpack to process
+   * @param mpackTarPath   Path to mpack tarball
+   * @param mpackDirectory Mpack directory
+   * @throws IOException
+   */
+  private void extractMpackTar(Mpack mpack, Path mpackTarPath, String 
mpackDirectory) throws IOException {
+
+    extractTar(mpackTarPath, mpackStaging);
+
     String mpackTarDirectory = mpackTarPath.toString();
     Path extractedMpackDirectory = Files.move
-            (Paths.get(mpackStaging + File.separator + 
mpackTarDirectory.substring(mpackTarDirectory.lastIndexOf('/') + 1, 
mpackTarDirectory.indexOf(".tar")) + File.separator),
-                    Paths.get(mpackDirectory), 
StandardCopyOption.REPLACE_EXISTING);
+      (Paths.get(mpackStaging + File.separator + mpackTarDirectory
+          .substring(mpackTarDirectory.lastIndexOf('/') + 1, 
mpackTarDirectory.indexOf(".tar")) + File.separator),
+        Paths.get(mpackDirectory), StandardCopyOption.REPLACE_EXISTING);
 
     createSymLinks();
   }
 
+  /***
+   * Create a services directory and extract all the services tar file inside 
it. This readies it for cluster deployment
+   *
+   * @param extractedMpackDirectory
+   * @param mpack
+   * @throws IOException
+   */
+  private void createServicesDirectory(Path extractedMpackDirectory, Mpack 
mpack) throws IOException {
+    File servicesDir = new File(extractedMpackDirectory.toAbsolutePath() + 
File.separator + SERVICES_DIRECTORY );
+    if (!servicesDir.exists()) {
+      servicesDir.mkdir();
+    }
+    List<Packlet> packlets = mpack.getPacklets();
+
+    for (Packlet packlet : packlets) {
+      //if (packlet.getType() == Packlet.PackletType.SERVICE_PACKLET) {
+        String packletSourceLocation = packlet.getSourceDir();
+        File serviceTargetDir = new File(servicesDir + File.separator + 
packlet.getName());
+        extractTar(Paths.get(extractedMpackDirectory + File.separator + 
packlet.getSourceDir()), servicesDir);
+        Path extractedServiceDirectory = Files.move(Paths.get(servicesDir + 
File.separator + packletSourceLocation
+            .substring(packletSourceLocation.indexOf("/") + 1, 
packletSourceLocation.indexOf(".tar.gz"))),
+          serviceTargetDir.toPath(), StandardCopyOption.REPLACE_EXISTING);
+      }
+    }
+  
+
   /**
    * Reads the mpack.json file within the {mpack-name}.tar.gz file and 
populates Mpack object.
    * Extract the mpack-name and mpack-version from mpack.json to create the 
new mpack directory to hold the mpack files.
@@ -223,9 +283,11 @@ public class MpackManager {
    * @return boolean
    * @throws IOException
    */
-  private Boolean createMpackDirectory(Path mpackTarPath) throws IOException {
-    TarArchiveInputStream mpackTarFile = new TarArchiveInputStream(new 
GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(new 
File(mpackTarPath.toString())))));
-    // To read individual TAR file
+  private Boolean createMpackDirectory(Mpack mpack, Path mpackTarPath)
+    throws IOException, ResourceAlreadyExistsException {
+
+    TarArchiveInputStream mpackTarFile = new TarArchiveInputStream(
+      new GzipCompressorInputStream(new BufferedInputStream(new 
FileInputStream(new File(mpackTarPath.toString())))));
     TarArchiveEntry entry = null;
     String individualFiles;
     int offset;
@@ -247,7 +309,7 @@ public class MpackManager {
         //Read the mpack.json file into Mpack Object for further use.
         String mpackJsonContents = new String(content, "UTF-8");
         Gson gson = new Gson();
-        Mpacks tempMpack = gson.fromJson(mpackJsonContents, Mpacks.class);
+        Mpack tempMpack = gson.fromJson(mpackJsonContents, Mpack.class);
         mpack.copyFrom(tempMpack);
 
         mpackTarFile.close();
@@ -257,11 +319,14 @@ public class MpackManager {
           return mpackDirectory.mkdir();
         else
           return true;
+        } else {
+          String message =
+            "Mpack: " + mpack.getName() + " version: " + mpack.getVersion() + 
" already exists in server";
+          throw new ResourceAlreadyExistsException(message);
+        }
       }
-    }
-
     return false;
-  }
+    }
 
   /***
    * Create a linkage between the staging directory and the working directory 
i.e from mpacks-v2 to stackRoot.
@@ -280,9 +345,9 @@ public class MpackManager {
     Files.createSymbolicLink(stackPath, mpackPath);
   }
 
-
   /***
    * Download the mpack from the given uri
+   *
    * @param mpackURI
    * @return
    */
@@ -295,7 +360,6 @@ public class MpackManager {
     return targetPath;
   }
 
-
   /**
    * Compares if the user's mpack information matches the downloaded mpack 
information.
    *
@@ -305,12 +369,21 @@ public class MpackManager {
    * @param actualMpackVersion
    * @return boolean
    */
-  protected boolean validateMpackInfo(String expectedMpackName, String 
expectedMpackVersion, String actualMpackName, String actualMpackVersion) {
-    if (expectedMpackName.equalsIgnoreCase(actualMpackName) && 
expectedMpackVersion.equalsIgnoreCase(actualMpackVersion))
+  protected boolean validateMpackInfo(
+    String expectedMpackName,
+    String expectedMpackVersion,
+    String actualMpackName,
+    String actualMpackVersion) {
+
+    String strippedActualMpackVersion = actualMpackVersion.substring(0, 
actualMpackVersion.lastIndexOf('.'));
+    if (expectedMpackName.equalsIgnoreCase(actualMpackName) && 
expectedMpackVersion
+      .equalsIgnoreCase(strippedActualMpackVersion)) {
       return true;
-    else
-      LOG.info("Incorrect information : Mismatch in - (" + expectedMpackName + 
"," + actualMpackName + ") or (" + expectedMpackVersion + "," + 
actualMpackVersion + ")");
-    return false;
+    } else {
+      LOG.info("Incorrect information : Mismatch in - (" + expectedMpackName + 
"," + actualMpackName + ") or ("
+        + expectedMpackVersion + "," + actualMpackVersion + ")");
+      return false;
+    }
   }
 
   /**
@@ -320,7 +393,7 @@ public class MpackManager {
    * @return
    * @throws IOException
    */
-  protected Long populateDB(Mpacks mpacks) throws IOException {
+  protected Long populateDB(Mpack mpacks) throws IOException {
     String mpackName = mpacks.getName();
     String mpackVersion = mpacks.getVersion();
     List resultSet = mpackDAO.findByNameVersion(mpackName, mpackVersion);
@@ -339,11 +412,13 @@ public class MpackManager {
   }
 
   /***
-   * Makes an entry or updates the entry in the stack table to establish a 
link between the mpack and the associated stack
+   * Makes an entry or updates the entry in the stack table to establish a 
link between the mpack and the
+   * associated stack
+   *
    * @param mpacks
    * @throws IOException
    */
-  protected void populateStackDB(Mpacks mpacks) throws IOException {
+  protected void populateStackDB(Mpack mpacks) throws IOException {
 
     String stackId = mpack.getStackId();
     String[] stackMetaData = stackId.split("-");
@@ -364,6 +439,7 @@ public class MpackManager {
       stackDAO.merge(stackEntity);
     }
   }
+
   /**
    * Fetches the packlet info stored in the memory for mpacks/{mpack_id} call.
    *
@@ -371,7 +447,7 @@ public class MpackManager {
    * @return ArrayList
    */
   public ArrayList<Packlet> getPacklets(Long mpackId) {
-    Mpacks mpack = mpackMap.get(mpackId);
+    Mpack mpack = mpackMap.get(mpackId);
     if (mpack.getPacklets() != null)
       return mpack.getPacklets();
     return null;
@@ -379,13 +455,15 @@ public class MpackManager {
 
   /***
    * Remove the mpack and stack directories when a request comes in to delete 
a particular mpack.
+   *
    * @param mpackEntity
    * @throws IOException
    */
   public boolean removeMpack(MpackEntity mpackEntity, StackEntity stackEntity) 
throws IOException {
 
     boolean stackDelete = false;
-    File mpackDirToDelete = new File(mpackStaging + File.separator + 
mpackEntity.getMpackName() + File.separator + mpackEntity.getMpackVersion());
+    File mpackDirToDelete = new File(
+      mpackStaging + File.separator + mpackEntity.getMpackName() + 
File.separator + mpackEntity.getMpackVersion());
     File mpackDirectory = new File(mpackStaging + "/" + 
mpackEntity.getMpackName());
     String mpackName = mpackEntity.getMpackName() + "-" + 
mpackEntity.getMpackVersion() + ".tar.gz";
     Path mpackTarFile = Paths.get(mpackStaging + File.separator + 
MPACK_TAR_LOCATION +File.separator + mpackName);
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/Mpacks.java 
b/ambari-server/src/main/java/org/apache/ambari/server/state/Mpack.java
similarity index 98%
rename from 
ambari-server/src/main/java/org/apache/ambari/server/state/Mpacks.java
rename to ambari-server/src/main/java/org/apache/ambari/server/state/Mpack.java
index 8b7d055..83470ea 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Mpacks.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Mpack.java
@@ -25,7 +25,7 @@ import java.util.HashMap;
 /**
  * Represents the state of an mpack.
  */
-public class Mpacks {
+public class Mpack {
 
   private Long mpackId;
 
@@ -160,7 +160,7 @@ public class Mpacks {
       return false;
     }
 
-    Mpacks other = (Mpacks) obj;
+    Mpack other = (Mpack) obj;
 
     if (name != other.name) {
       return false;
@@ -249,7 +249,7 @@ public class Mpacks {
     return sb.toString();
   }
 
-  public void copyFrom(Mpacks mpack) {
+  public void copyFrom(Mpack mpack) {
     if (this.name == null)
       this.name = mpack.getName();
     if (this.mpackId == null)
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/state/MpackTest.java 
b/ambari-server/src/test/java/org/apache/ambari/server/state/MpackTest.java
index 388c256..f21ca64 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/MpackTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/MpackTest.java
@@ -28,7 +28,7 @@ import com.google.gson.Gson;
 public class MpackTest {
   @Test
   public void testMpacks() {
-    Mpacks mpack = new Mpacks();
+    Mpack mpack = new Mpack();
     mpack.setName("name");
     mpack.setMpackId((long)100);
     mpack.setDescription("desc");

Reply via email to