ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mradhakrish...@apache.org
Subject ambari git commit: AMBARI-21231: Mpack to Stack Linkage and Parsing mpacks at bootstrap (mradhakrishnan)
Date Fri, 07 Jul 2017 16:50:32 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-14714 d93015d6a -> 7849de66b


AMBARI-21231: Mpack to Stack Linkage and Parsing mpacks at bootstrap  (mradhakrishnan)


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

Branch: refs/heads/branch-feature-AMBARI-14714
Commit: 7849de66b948ea672c4a9e88b9bdae92a3707c04
Parents: d93015d
Author: Madhuvanthi Radhakrishnan <mradhakrishnan@hortonworks.com>
Authored: Fri Jul 7 09:49:10 2017 -0700
Committer: Madhuvanthi Radhakrishnan <mradhakrishnan@hortonworks.com>
Committed: Fri Jul 7 09:49:10 2017 -0700

----------------------------------------------------------------------
 ambari-server/src/main/assemblies/server.xml    |   8 +
 .../api/resources/MpackResourceDefinition.java  |  52 +++
 .../StackVersionResourceDefinition.java         |   8 +-
 .../server/api/services/AmbariMetaInfo.java     |   4 +-
 .../AmbariManagementControllerImpl.java         |  35 +-
 .../ambari/server/controller/MpackResponse.java |  10 +
 .../internal/MpackResourceProvider.java         |  47 ++-
 .../ambari/server/mpack/MpackManager.java       | 179 +++++++--
 .../server/mpack/MpackManagerFactory.java       |   3 +-
 .../ambari/server/orm/entities/StackEntity.java |  15 +
 .../ambari/server/stack/StackManager.java       |   5 +-
 .../org/apache/ambari/server/state/Mpacks.java  | 382 ++++++++++---------
 .../org/apache/ambari/server/state/Packlet.java |  22 ++
 .../main/resources/Ambari-DDL-Derby-CREATE.sql  |  36 +-
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |  35 +-
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |  36 +-
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |  36 +-
 .../resources/Ambari-DDL-SQLAnywhere-CREATE.sql |  36 +-
 .../resources/Ambari-DDL-SQLServer-CREATE.sql   |  36 +-
 .../src/main/resources/mpacks-v2/README.txt     |   1 +
 20 files changed, 649 insertions(+), 337 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/assemblies/server.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/assemblies/server.xml b/ambari-server/src/main/assemblies/server.xml
index 1bda878..eac7885 100644
--- a/ambari-server/src/main/assemblies/server.xml
+++ b/ambari-server/src/main/assemblies/server.xml
@@ -191,6 +191,14 @@
 	  </includes>
     </fileSet>
     <fileSet>
+      <directoryMode>700</directoryMode>
+      <directory>src/main/resources/mpacks-v2</directory>
+      <outputDirectory>/var/lib/ambari-server/resources/mpacks-v2</outputDirectory>
+      <excludes>
+        <exclude>*/**</exclude>
+      </excludes>
+    </fileSet>
+    <fileSet>
       <fileMode>755</fileMode>
       <directory>src/main/python/ambari_server</directory>
       <outputDirectory>/usr/lib/python2.6/site-packages/ambari_server</outputDirectory>

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/java/org/apache/ambari/server/api/resources/MpackResourceDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/MpackResourceDefinition.java b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/MpackResourceDefinition.java
index e33cd31..26972d8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/MpackResourceDefinition.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/MpackResourceDefinition.java
@@ -17,11 +17,18 @@
  */
 package org.apache.ambari.server.api.resources;
 
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.util.TreeNode;
+import org.apache.ambari.server.controller.internal.ResourceImpl;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.Resource.Type;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+
 /**
  * Resource Definition for Mpack Resource types.
  */
@@ -47,4 +54,49 @@ public class MpackResourceDefinition extends BaseResourceDefinition {
   public String getSingularName() {
     return "mpack";
   }
+
+  @Override
+  public List<PostProcessor> getPostProcessors() {
+    List<PostProcessor> listProcessors = new ArrayList<>();
+    listProcessors.add(new MpackHrefProcessor());
+    listProcessors.add(new MpackPostProcessor());
+    return listProcessors;
+  }
+
+  /**
+   * Post Processing the mpack href when the call comes from stack endpoint to ensure that the
+   * href is a backreference to the mpacks end point
+   */
+  private class MpackHrefProcessor extends BaseHrefPostProcessor {
+    @Override
+    public void process(Request request, TreeNode<Resource> resultNode, String href) {
+      if (href.contains("/stacks/")) {
+        ResourceImpl mpack = (ResourceImpl) resultNode.getObject();
+        Map<String, Map<String, Object>> mapInfo = mpack.getPropertiesMap();
+        Map<String, Object> mpackInfo = mapInfo.get("MpackInfo");
+
+        int idx = href.indexOf("stacks/");
+        Long mpackId = (Long)mpackInfo.get("mpack_id");
+        href = href.substring(0, idx) + "mpacks/" + mpackId;
+        resultNode.setProperty("href", href);
+      } else {
+        super.process(request, resultNode, href);
+      }
+    }
+  }
+
+  /***
+   * Post processing to change the name of the result node to current_mpack
+   */
+  private class MpackPostProcessor implements PostProcessor {
+    @Override
+    public void process(Request request, TreeNode<Resource> resultNode, String href) {
+      if (href.contains("/stacks/")) {
+        resultNode.setName("current_mpack");
+
+      }
+    }
+  }
+
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/java/org/apache/ambari/server/api/resources/StackVersionResourceDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/StackVersionResourceDefinition.java b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/StackVersionResourceDefinition.java
index ba102b5..5b32c06 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/StackVersionResourceDefinition.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/StackVersionResourceDefinition.java
@@ -7,7 +7,7 @@
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,7 +20,6 @@ package org.apache.ambari.server.api.resources;
 
 import java.util.HashSet;
 import java.util.Set;
-
 import org.apache.ambari.server.controller.spi.Resource;
 
 public class StackVersionResourceDefinition extends BaseResourceDefinition {
@@ -50,7 +49,8 @@ public class StackVersionResourceDefinition extends BaseResourceDefinition {
     children.add(new SubResourceDefinition(Resource.Type.RepositoryVersion));
     children.add(new SubResourceDefinition(Resource.Type.StackArtifact));
     children.add(new SubResourceDefinition(Resource.Type.CompatibleRepositoryVersion));
-
+    children.add(new SubResourceDefinition(Resource.Type.Mpack, null, false));
     return children;
   }
-}
+
+ }

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
index ee3b8e5..a68bf48 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
@@ -59,6 +59,7 @@ import org.apache.ambari.server.mpack.MpackManager;
 import org.apache.ambari.server.mpack.MpackManagerFactory;
 import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
 import org.apache.ambari.server.orm.dao.MetainfoDAO;
+import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
 import org.apache.ambari.server.orm.entities.MetainfoEntity;
 import org.apache.ambari.server.stack.StackDirectory;
@@ -297,7 +298,7 @@ public class AmbariMetaInfo {
     stackManager = stackManagerFactory.create(stackRoot, commonServicesRoot, extensionsRoot,
         osFamily, false);
 
-    mpackManager = mpackManagerFactory.create(mpacksV2Staging);
+    mpackManager = mpackManagerFactory.create(mpacksV2Staging, stackRoot);
 
     getCustomActionDefinitions(customActionRoot);
   }
@@ -1540,5 +1541,4 @@ public class AmbariMetaInfo {
     return versionDefinitions;
   }
 
-
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/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 7f173e9..8a564c9 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
@@ -153,10 +153,40 @@ import org.apache.ambari.server.stack.ExtensionHelper;
 import org.apache.ambari.server.stack.RepoUtil;
 import org.apache.ambari.server.stageplanner.RoleGraph;
 import org.apache.ambari.server.stageplanner.RoleGraphFactory;
-import org.apache.ambari.server.state.*;
-import org.apache.ambari.server.state.PropertyInfo.PropertyType;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.ServiceComponentFactory;
+import org.apache.ambari.server.state.ServiceComponentHostFactory;
+import org.apache.ambari.server.state.ConfigFactory;
+import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.ConfigHelper;
+import org.apache.ambari.server.state.StackInfo;
+import org.apache.ambari.server.state.State;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponent;
+import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.CommandScriptDefinition;
 import org.apache.ambari.server.state.PropertyInfo.PropertyType;
 import org.apache.ambari.server.state.configgroup.ConfigGroupFactory;
+import org.apache.ambari.server.state.PropertyInfo;
+import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.DesiredConfig;
+import org.apache.ambari.server.state.MaintenanceState;
+import org.apache.ambari.server.state.SecurityType;
+import org.apache.ambari.server.state.HostState;
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ComponentInfo;
+import org.apache.ambari.server.state.ServiceInfo;
+import org.apache.ambari.server.state.RepositoryVersionState;
+import org.apache.ambari.server.state.ServiceOsSpecific;
+import org.apache.ambari.server.state.UnlimitedKeyJCERequirement;
+import org.apache.ambari.server.state.ExtensionInfo;
+import org.apache.ambari.server.state.RepositoryInfo;
+import org.apache.ambari.server.state.OperatingSystemInfo;
+import org.apache.ambari.server.state.Packlet;
+import org.apache.ambari.server.state.HostComponentAdminState;
+import org.apache.ambari.server.state.PropertyDependencyInfo;
 import org.apache.ambari.server.state.quicklinksprofile.QuickLinkVisibilityController;
 import org.apache.ambari.server.state.quicklinksprofile.QuickLinkVisibilityControllerFactory;
 import org.apache.ambari.server.state.quicklinksprofile.QuickLinksProfile;
@@ -485,6 +515,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
   @Override
   public MpackResponse registerMpack(MpackRequest request) throws IOException, AuthorizationException, ResourceAlreadyExistsException{
     MpackResponse mpackResponse = ambariMetaInfo.registerMpack(request);
+    updateStacks();
     return mpackResponse;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/java/org/apache/ambari/server/controller/MpackResponse.java
----------------------------------------------------------------------
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 05687c2..d111913 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
@@ -29,6 +29,7 @@ public class MpackResponse {
   private String mpackName;
   private String mpackUri;
   private Long registryId;
+  private String stackId;
 
   public MpackResponse(Mpacks mpacks) {
     this.mpackId = mpacks.getMpackId();
@@ -36,6 +37,7 @@ public class MpackResponse {
     this.mpackUri = mpacks.getMpacksUri();
     this.mpackName = mpacks.getName();
     this.registryId = mpacks.getRegistryId();
+    this.stackId = mpacks.getStackId();
   }
 
   public String getMpackVersion() {
@@ -50,6 +52,14 @@ public class MpackResponse {
     return mpackId;
   }
 
+  public String getStackId() {
+    return stackId;
+  }
+
+  public void setStackId(String stackId) {
+    this.stackId = stackId;
+  }
+
   public String getMpackName() {
     return mpackName;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/MpackResourceProvider.java
----------------------------------------------------------------------
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 65eaeb6..6f90e04 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
@@ -43,12 +43,11 @@ import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.MpackResponse;
 import org.apache.ambari.server.controller.MpackRequest;
-
-
 import org.apache.ambari.server.controller.utilities.PredicateHelper;
 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.Packlet;
 
 /**
@@ -63,10 +62,11 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider {
   public static final String MPACK_VERSION = "MpackInfo/mpack_version";
   public static final String MPACK_URI = "MpackInfo/mpack_uri";
   public static final String PACKLETS = "MpackInfo/packlets";
-
+  public static final String STACK_NAME_PROPERTY_ID = "MpackInfo/stack_name";
+  public static final String STACK_VERSION_PROPERTY_ID = "MpackInfo/stack_version";
 
   private static Set<String> pkPropertyIds = new HashSet<>(
-          Arrays.asList(MPACK_ID));
+          Arrays.asList(MPACK_ID, STACK_NAME_PROPERTY_ID, STACK_VERSION_PROPERTY_ID));
 
   /**
    * The property ids for an mpack resource.
@@ -81,6 +81,9 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider {
   @Inject
   protected static MpackDAO mpackDAO;
 
+  @Inject
+  protected static StackDAO stackDAO;
+
   static {
     // properties
     PROPERTY_IDS.add(MPACK_ID);
@@ -89,9 +92,13 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider {
     PROPERTY_IDS.add(MPACK_VERSION);
     PROPERTY_IDS.add(MPACK_URI);
     PROPERTY_IDS.add(PACKLETS);
+    PROPERTY_IDS.add(STACK_NAME_PROPERTY_ID);
+    PROPERTY_IDS.add(STACK_VERSION_PROPERTY_ID);
 
     // keys
     KEY_PROPERTY_IDS.put(Resource.Type.Mpack, MPACK_ID);
+    KEY_PROPERTY_IDS.put(Resource.Type.Stack, STACK_NAME_PROPERTY_ID);
+    KEY_PROPERTY_IDS.put(Resource.Type.StackVersion, STACK_VERSION_PROPERTY_ID);
 
   }
 
@@ -161,7 +168,7 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider {
           NoSuchResourceException, NoSuchParentResourceException {
 
     Set<Resource> results = new LinkedHashSet<>();
-
+    Long mpackId = null;
     //Fetch all mpacks
     if (predicate == null) {
       List<MpackEntity> entities = mpackDAO.findAll();
@@ -180,9 +187,32 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider {
     } //Fetch a particular mpack based on id
     else {
       Map<String, Object> propertyMap = new HashMap<>(PredicateHelper.getProperties(predicate));
+      if (propertyMap.containsKey(STACK_NAME_PROPERTY_ID) && propertyMap.containsKey(STACK_VERSION_PROPERTY_ID)) {
+        String stackName = (String) propertyMap.get(STACK_NAME_PROPERTY_ID);
+        String stackVersion = (String) propertyMap.get(STACK_VERSION_PROPERTY_ID);
+        StackEntity stackEntity = stackDAO.find(stackName, stackVersion);
+        mpackId = stackEntity.getCurrentMpackId();
+        if (mpackId != null) {
+          MpackEntity entity = mpackDAO.findById(mpackId);
+          Resource resource = new ResourceImpl(Resource.Type.Mpack);
+          if (null != entity) {
+            resource.setProperty(MPACK_ID, entity.getMpackId());
+            resource.setProperty(MPACK_NAME, entity.getMpackName());
+            resource.setProperty(MPACK_VERSION, entity.getMpackVersion());
+            resource.setProperty(STACK_NAME_PROPERTY_ID, stackName);
+            resource.setProperty(STACK_VERSION_PROPERTY_ID, stackVersion);
+            results.add(resource);
+          }
+        }
+        return results;
+      }
+
       if (propertyMap.containsKey(MPACK_ID)) {
-        String mpackId = (String) propertyMap.get(MPACK_ID);
-        MpackEntity entity = mpackDAO.findById(Long.parseLong((mpackId)));
+        Object objMpackId = propertyMap.get(MPACK_ID);
+        if(objMpackId != null)
+          mpackId = Long.valueOf((String) objMpackId);
+
+        MpackEntity entity = mpackDAO.findById(mpackId);
         Resource resource = new ResourceImpl(Resource.Type.Mpack);
         if (null != entity) {
           resource.setProperty(MPACK_ID, entity.getMpackId());
@@ -201,7 +231,6 @@ public class MpackResourceProvider extends AbstractControllerResourceProvider {
                 "The requested resource doesn't exist: " + predicate);
       }
     }
-
     return results;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManager.java
----------------------------------------------------------------------
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 a031af3..f19320e 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
@@ -24,7 +24,9 @@ import org.apache.ambari.server.controller.MpackRequest;
 import org.apache.ambari.server.controller.MpackResponse;
 import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
 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.Packlet;
 import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
@@ -59,17 +61,59 @@ public class MpackManager {
   protected Map<Long, Mpacks> mpackMap = new HashMap<>();
   private File mpackStaging;
   private MpackDAO mpackDAO;
+  private StackDAO stackDAO;
   private Mpacks mpack;
+  private File stackRoot;
+  private static final String MPACK_METADATA = "mpack.json";
+  private static final String MPACK_TAR_LOCATION = "staging";
 
   private final static Logger LOG = LoggerFactory.getLogger(MpackManager.class);
 
   @AssistedInject
-  public MpackManager(@Assisted("mpackv2Staging") File mpackStagingLoc, MpackDAO mpackDAOObj) {
-    mpackStaging = mpackStagingLoc;
+  public MpackManager(@Assisted("mpackv2Staging") File mpackStagingLocation, @Assisted("stackRoot") File stackRootDir, MpackDAO mpackDAOObj, StackDAO stackDAOObj) {
+    mpackStaging = mpackStagingLocation;
     mpackDAO = mpackDAOObj;
-    //Todo : Madhu Load all mpack.json into mpackMap during ambari-server startup
+    stackRoot = stackRootDir;
+    stackDAO = stackDAOObj;
+
+    parseMpackDirectories();
+
+  }
+
+  /**
+   * Parses mpackdirectories during boostrap/ambari-server restart
+   * Reads from /var/lib/ambari-server/mpacks-v2/
+   *
+   * @throws IOException
+   */
+  private void parseMpackDirectories() {
+    try {
+      for (final File dirEntry : mpackStaging.listFiles()) {
+        if (dirEntry.isDirectory()) {
+          String mpackName = dirEntry.getName();
+          if (!mpackName.equals(MPACK_TAR_LOCATION)) {
+            for (final File file : dirEntry.listFiles()) {
+              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);
+              }
+            }
+          }
+        }
+      }
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
   }
 
+
   /**
    * Parses mpack.json to fetch mpack and associated packlet information and
    * stores the mpack to the database and mpackMap
@@ -81,48 +125,53 @@ public class MpackManager {
    * @throws ResourceAlreadyExistsException
    */
   public MpackResponse registerMpack(MpackRequest mpackRequest) throws IOException, IllegalArgumentException, ResourceAlreadyExistsException {
-    //Todo : Madhu Update StacksAPI
 
     Long mpackId;
-    mpack = new Mpacks();
     String mpackName = "";
     String mpackVersion = "";
-    boolean isValidMetadata = true;
+    mpack = new Mpacks();
+    boolean isValidMetadata;
+    String mpackDirectory = "";
+    Path mpackTarPath;
 
     //Mpack registration using a software registry
     if (mpackRequest.getRegistryId() != null) {
       mpackName = mpackRequest.getMpackName();
       mpackVersion = mpackRequest.getMpackVersion();
       mpack.setRegistryId(mpackRequest.getRegistryId());
-      //Validate the Post request
-      isValidMetadata = validateMpackInfo(mpackName, mpackVersion, mpack.getName(), mpack.getVersion());
+
       //Todo : Madhu implement GET /registries/{registryId}/mpacks
-    } else {
-      //Mpack registration using direct download
-      mpack.setMpacksUri(mpackRequest.getMpackUri());
-    }
+      mpackTarPath = downloadMpack(mpackRequest.getMpackUri());
 
-    //Download the mpack and return the path.
-    Path mpackTarPath = downloadMpack(mpackRequest.getMpackUri(), mpackStaging + File.separator);
-    //create a directory as mpack-staging-path/mpack-name/mpack-version
-    if (createMpackDirectory(mpackTarPath)) {
-      //expand the mpack.tar.gz file inside the directory created above
-      String mpackDirectory = mpackStaging + File.separator + mpack.getName() + File.separator + mpack.getVersion();
-      extractMpackTar(mpackTarPath, mpackDirectory);
-    }
-    if (isValidMetadata) {
-      mpackId = populateDB(mpack);
-      if (mpackId != null) {
-        mpackMap.put(mpackId, mpack);
-        mpack.setMpackId(mpackId);
-        return new MpackResponse(mpack);
-      } else {
-        String message = "Mpack :" + mpackRequest.getMpackName() + " version: " + mpackRequest.getMpackVersion() + " already exists in server";
-        throw new ResourceAlreadyExistsException(message);
+      if (createMpackDirectory(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() + ")";
+          throw new IllegalArgumentException(message); //Mismatch in information
+        }
+
+      }
+    } else {    //Mpack registration using direct download
+      mpackTarPath = downloadMpack(mpackRequest.getMpackUri());
+
+      if (createMpackDirectory(mpackTarPath)) {
+        mpackDirectory = mpackStaging + File.separator + mpack.getName() + File.separator + mpack.getVersion();
+        mpack.setMpacksUri(mpackRequest.getMpackUri());
       }
+    }
+    extractMpackTar(mpackTarPath, mpackDirectory);
+    mpackId = populateDB(mpack);
+
+    if (mpackId != null) {
+      mpackMap.put(mpackId, mpack);
+      mpack.setMpackId(mpackId);
+      populateStackDB(mpack);
+      return new MpackResponse(mpack);
     } else {
-      String message = "Incorrect information : Mismatch in - (" + mpackName + "," + mpack.getName() + ") or (" + mpackVersion + "," + mpack.getVersion() + ")";
-      throw new IllegalArgumentException(message); //Mismatch in information
+      String message = "Mpack :" + mpackRequest.getMpackName() + " version: " + mpackRequest.getMpackVersion() + " already exists in server";
+      throw new ResourceAlreadyExistsException(message);
     }
   }
 
@@ -161,6 +210,8 @@ public class MpackManager {
     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);
+
+    createSymLinks();
   }
 
   /**
@@ -188,7 +239,6 @@ public class MpackManager {
         // Get Size of the file and create a byte array for the size
         byte[] content = new byte[(int) entry.getSize()];
         offset = 0;
-        LOG.info("File Name in TAR File is: " + fileName);
         LOG.debug("Size of the File is: " + entry.getSize());
         // Read file from the archive into byte array
         mpackTarFile.read(content, offset, content.length - offset);
@@ -196,29 +246,49 @@ 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();
-        mpack = gson.fromJson(mpackJsonContents, Mpacks.class);
+        Mpacks tempMpack = gson.fromJson(mpackJsonContents, Mpacks.class);
+        mpack.copyFrom(tempMpack);
 
         mpackTarFile.close();
 
-        return new File(mpackStaging + File.separator + mpack.getName()).mkdir();
-
+        File mpackDirectory = new File(mpackStaging + File.separator + mpack.getName());
+        if (!mpackDirectory.exists())
+          return mpackDirectory.mkdir();
+        else
+          return true;
       }
     }
 
     return false;
   }
 
+  /***
+   * Create a linkage between the staging directory and the working directory i.e from mpacks-v2 to stackRoot.
+   * This will enable StackManager to parse the newly registered mpack as part of the stacks.
+   * @throws IOException
+   */
+  private void createSymLinks() throws IOException {
+    String stackId = mpack.getStackId();
+    String[] stackMetaData = stackId.split("-");
+    String stackName = stackMetaData[0];
+    String stackVersion = stackMetaData[1];
+    Path stackPath = Paths.get(stackRoot + "/" + stackName + "/" + stackVersion);
+    Path mpackPath = Paths.get(mpackStaging + "/" + mpack.getName() + "/" + mpack.getVersion());
+    if(Files.isSymbolicLink(stackPath))
+      Files.delete(stackPath);
+    Files.createSymbolicLink(stackPath, mpackPath);
+  }
+
 
   /***
    * Download the mpack from the given uri
-   * @param sourceURI
-   * @param targetDirectory
+   * @param mpackURI
    * @return
    */
-  public static Path downloadMpack(String sourceURI, String targetDirectory) throws IOException {
-    URL url = new URL(sourceURI);
-    String fileName = sourceURI.substring(sourceURI.lastIndexOf('/') + 1, sourceURI.length());
-    Path targetPath = new File(targetDirectory + File.separator + fileName).toPath();
+  public Path downloadMpack(String mpackURI) throws IOException {
+    URL url = new URL(mpackURI);
+    String fileName = mpackURI.substring(mpackURI.lastIndexOf('/') + 1, mpackURI.length());
+    Path targetPath = new File(mpackStaging.toString() + File.separator + MPACK_TAR_LOCATION + File.separator + fileName).toPath();
     Files.copy(url.openStream(), targetPath, StandardCopyOption.REPLACE_EXISTING);
 
     return targetPath;
@@ -267,8 +337,35 @@ public class MpackManager {
     return null;
   }
 
+  /***
+   * 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 {
+
+    String stackId = mpack.getStackId();
+    String[] stackMetaData = stackId.split("-");
+    String stackName = stackMetaData[0];
+    String stackVersion = stackMetaData[1];
+
+    StackEntity stackEntity = stackDAO.find(stackName, stackVersion);
+    if (stackEntity == null) {
+      LOG.info("Adding stack {}-{} to the database", stackName, stackVersion);
+      stackEntity = new StackEntity();
+      stackEntity.setStackName(stackName);
+      stackEntity.setStackVersion(stackVersion);
+      stackEntity.setCurrentMpackId(mpacks.getMpackId());
+      stackDAO.create(stackEntity);
+    } else {
+      LOG.info("Updating stack {}-{} to the database", stackName, stackVersion);
+      stackEntity.setCurrentMpackId(mpacks.getMpackId());
+      stackDAO.merge(stackEntity);
+    }
+  }
   /**
    * Fetches the packlet info stored in the memory for mpacks/{mpack_id} call.
+   *
    * @param mpackId
    * @return ArrayList
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManagerFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManagerFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManagerFactory.java
index 67820c8..2336b1a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManagerFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/mpack/MpackManagerFactory.java
@@ -31,7 +31,8 @@ public interface MpackManagerFactory {
   /**
    * @param mpackStaging
    *        the folder location where mpack is downloaded. (not {@code null}).
+   * @param stackRoot
    * @return a mpack manager instance.
    */
-  MpackManager create(@Assisted("mpackv2Staging") File mpackStaging);
+  MpackManager create(@Assisted("mpackv2Staging") File mpackStaging, @Assisted("stackRoot") File stackRoot);
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StackEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StackEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StackEntity.java
index 2cfe07c..0cb8628 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StackEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StackEntity.java
@@ -59,6 +59,20 @@ public class StackEntity {
   @Column(name = "stack_version", length = 255, nullable = false)
   private String stackVersion;
 
+
+  @Column(name = "current_mpack_id")
+  private Long currentMpackId;
+
+
+  public Long getCurrentMpackId() {
+    return currentMpackId;
+  }
+
+  public void setCurrentMpackId(Long currentMpackId) {
+    this.currentMpackId = currentMpackId;
+  }
+
+
   /**
    * Constructor.
    */
@@ -154,6 +168,7 @@ public class StackEntity {
     buffer.append("id=").append(stackId);
     buffer.append(", name=").append(stackName);
     buffer.append(", version=").append(stackVersion);
+    buffer.append(", current_mpack_id=").append(currentMpackId);
     buffer.append("}");
     return buffer.toString();
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
index d19aeba..9ac9107 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
@@ -116,7 +116,7 @@ public class StackManager {
   /**
    * Constructor. Initialize stack manager.
    *
-   * @param stackRoot
+   * @param stackRootDir
    *          stack root directory
    * @param commonServicesRoot
    *          common services root directory
@@ -141,7 +141,7 @@ public class StackManager {
    *           if an exception occurs while processing the stacks
    */
   @AssistedInject
-  public StackManager(@Assisted("stackRoot") File stackRoot,
+  public StackManager(@Assisted("stackRoot") File stackRootDir,
       @Assisted("commonServicesRoot") @Nullable File commonServicesRoot,
       @Assisted("extensionRoot") @Nullable File extensionRoot,
       @Assisted OsFamily osFamily, @Assisted boolean validate,
@@ -151,6 +151,7 @@ public class StackManager {
 
     LOG.info("Initializing the stack manager...");
 
+    stackRoot = stackRootDir;
     if (validate) {
       validateStackDirectory(stackRoot);
       validateCommonServicesDirectory(commonServicesRoot);

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/java/org/apache/ambari/server/state/Mpacks.java
----------------------------------------------------------------------
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/Mpacks.java
index 9a457b0..8b7d055 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/Mpacks.java
@@ -27,211 +27,245 @@ import java.util.HashMap;
  */
 public class Mpacks {
 
-    private Long mpackId;
+  private Long mpackId;
 
-    private Long registryId;
+  private Long registryId;
 
-    @SerializedName("name")
-    private String name;
+  @SerializedName("name")
+  private String name;
 
-    @SerializedName("version")
-    private String version;
+  @SerializedName("version")
+  private String version;
 
-    @SerializedName("description")
-    private String description;
+  @SerializedName("description")
+  private String description;
 
-    @SerializedName("prerequisites")
-    private HashMap<String,String> prerequisites;
+  @SerializedName("prerequisites")
+  private HashMap<String, String> prerequisites;
 
-    @SerializedName("packlets")
-    private ArrayList<Packlet> packlets;
+  @SerializedName("packlets")
+  private ArrayList<Packlet> packlets;
 
-    private String mpacksUri;
-
-    public Long getMpackId() {
-        return mpackId;
-    }
-
-    public void setMpackId(Long mpackId) {
-        this.mpackId = mpackId;
+  @SerializedName("stack-id")
+  private String stackId;
+
+  private String mpacksUri;
+
+  public Long getMpackId() {
+    return mpackId;
+  }
+
+  public void setMpackId(Long mpackId) {
+    this.mpackId = mpackId;
+  }
+
+  public Long getRegistryId() {
+    return registryId;
+  }
+
+  public void setRegistryId(Long registryId) {
+    this.registryId = registryId;
+  }
+
+  public String getMpacksUri() {
+    return mpacksUri;
+  }
+
+  public void setMpacksUri(String mpacksUri) {
+    this.mpacksUri = mpacksUri;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getVersion() {
+    return version;
+  }
+
+  public void setVersion(String version) {
+    this.version = version;
+  }
+
+  public String getDescription() {
+    return description;
+  }
+
+  public void setDescription(String description) {
+    this.description = description;
+  }
+
+  public HashMap<String, String> getPrerequisites() {
+    return prerequisites;
+  }
+
+  public void setPrerequisites(HashMap<String, String> prerequisites) {
+    this.prerequisites = prerequisites;
+  }
+
+  public ArrayList<Packlet> getPacklets() {
+    return packlets;
+  }
+
+  public void setPacklets(ArrayList<Packlet> packlets) {
+    this.packlets = packlets;
+  }
+
+
+  public String getStackId() {
+    return stackId;
+  }
+
+  public void setStackId(String stackId) {
+    this.stackId = stackId;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((mpackId == null) ? 0 : mpackId.hashCode());
+    result = prime * result + ((name == null) ? 0 : name.hashCode());
+    result = prime * result + ((version == null) ? 0 : version.hashCode());
+    result = prime * result + ((registryId == null) ? 0 : registryId.hashCode());
+    result = prime * result + ((description == null) ? 0 : description.hashCode());
+    result = prime * result + ((prerequisites == null) ? 0 : prerequisites.hashCode());
+    result = prime * result + ((packlets == null) ? 0 : packlets.hashCode());
+    result = prime * result + ((stackId == null) ? 0 : stackId.hashCode());
+    result = prime * result + ((mpacksUri == null) ? 0 : mpacksUri.hashCode());
+    return result;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj) {
+      return true;
     }
 
-    public Long getRegistryId() {
-        return registryId;
+    if (obj == null) {
+      return false;
     }
 
-    public void setRegistryId(Long registryId) {
-        this.registryId = registryId;
+    if (getClass() != obj.getClass()) {
+      return false;
     }
 
-    public String getMpacksUri() {
-        return mpacksUri;
-    }
+    Mpacks other = (Mpacks) obj;
 
-    public void setMpacksUri(String mpacksUri) {
-        this.mpacksUri = mpacksUri;
+    if (name != other.name) {
+      return false;
     }
 
-    public String getName() {
-        return name;
+    if (version == null) {
+      if (other.version != null) {
+        return false;
+      }
+    } else if (!version.equals(other.version)) {
+      return false;
     }
 
-    public void setName(String name) {
-        this.name = name;
+    if (description == null) {
+      if (other.description != null) {
+        return false;
+      }
+    } else if (!description.equals(other.description)) {
+      return false;
     }
 
-    public String getVersion() {
-        return version;
+    if (mpackId == null) {
+      if (other.mpackId != null) {
+        return false;
+      }
+    } else if (!mpackId.equals(other.mpackId)) {
+      return false;
     }
 
-    public void setVersion(String version) {
-        this.version = version;
+    if (registryId == null) {
+      if (other.registryId != null) {
+        return false;
+      }
+    } else if (!registryId.equals(other.registryId)) {
+      return false;
     }
 
-    public String getDescription() {
-        return description;
+    if (prerequisites == null) {
+      if (other.prerequisites != null) {
+        return false;
+      }
+    } else if (!prerequisites.equals(other.prerequisites)) {
+      return false;
     }
 
-    public void setDescription(String description) {
-        this.description = description;
+    if (packlets == null) {
+      if (other.packlets != null) {
+        return false;
+      }
+    } else if (!packlets.equals(other.packlets)) {
+      return false;
     }
 
-    public HashMap<String, String> getPrerequisites() {
-        return prerequisites;
+    if (mpacksUri == null) {
+      if (other.mpacksUri != null) {
+        return false;
+      }
+    } else if (!mpacksUri.equals(other.mpacksUri)) {
+      return false;
     }
 
-    public void setPrerequisites(HashMap<String, String> prerequisites) {
-        this.prerequisites = prerequisites;
+    if (stackId == null) {
+      if (other.stackId != null) {
+        return false;
+      }
+    } else if (!stackId.equals(other.stackId)) {
+      return false;
     }
 
-    public ArrayList<Packlet> getPacklets() {
-        return packlets;
-    }
-
-    public void setPacklets(ArrayList<Packlet> packlets) {
-        this.packlets = packlets;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((mpackId == null) ? 0 : mpackId.hashCode());
-        result = prime * result + ((name == null) ? 0 : name.hashCode());
-        result = prime * result + ((version == null) ? 0 : version.hashCode());
-        result = prime * result + ((registryId == null) ? 0 : registryId.hashCode());
-        result = prime * result + ((description == null) ? 0 : description.hashCode());
-        result = prime * result + ((prerequisites == null) ? 0 : prerequisites.hashCode());
-        result = prime * result + ((packlets == null) ? 0 : packlets.hashCode());
-        result = prime * result + ((mpacksUri == null) ? 0 : mpacksUri.hashCode());
-        return result;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-
-        if (obj == null) {
-            return false;
-        }
-
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-
-        Mpacks other = (Mpacks) obj;
-
-        if (name != other.name) {
-            return false;
-        }
-
-        if (version == null) {
-            if (other.version != null) {
-                return false;
-            }
-        } else if (!version.equals(other.version)) {
-            return false;
-        }
-
-        if (description == null) {
-            if (other.description != null) {
-                return false;
-            }
-        } else if (!description.equals(other.description)) {
-            return false;
-        }
-
-        if (mpackId == null) {
-            if (other.mpackId != null) {
-                return false;
-            }
-        } else if (!mpackId.equals(other.mpackId)) {
-            return false;
-        }
-
-        if (registryId == null) {
-            if (other.registryId != null) {
-                return false;
-            }
-        } else if (!registryId.equals(other.registryId)) {
-            return false;
-        }
-
-        if (registryId == null) {
-            if (other.registryId != null) {
-                return false;
-            }
-        } else if (!registryId.equals(other.registryId)) {
-            return false;
-        }
-
-        if (registryId == null) {
-            if (other.registryId != null) {
-                return false;
-            }
-        } else if (!registryId.equals(other.registryId)) {
-            return false;
-        }
-
-        if (prerequisites == null) {
-            if (other.prerequisites != null) {
-                return false;
-            }
-        } else if (!prerequisites.equals(other.prerequisites)) {
-            return false;
-        }
-
-        if (packlets == null) {
-            if (other.packlets != null) {
-                return false;
-            }
-        } else if (!packlets.equals(other.packlets)) {
-            return false;
-        }
-
-        return true;
-    }
-
-    @Override
-    public String toString() {
-        StringBuilder sb = new StringBuilder();
-        sb.append('{');
-        sb.append("name=").append(name).append(", ");
-        sb.append("mpackId=").append(mpackId).append(", ");
-        sb.append("version=").append(version).append(", ");
-        sb.append("registryId=").append(registryId).append(", ");
-        sb.append("description=").append(description).append(", ");
-        sb.append("prereq=").append(prerequisites.toString()).append(", ");
-        sb.append("packlets=").append(packlets.toString()).append(", ");
+    return true;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder();
+    sb.append('{');
+    sb.append("name=").append(name).append(", ");
+    sb.append("mpackId=").append(mpackId).append(", ");
+    sb.append("version=").append(version).append(", ");
+    sb.append("stackid=").append(stackId).append(", ");
+    sb.append("registryId=").append(registryId).append(", ");
+    sb.append("description=").append(description).append(", ");
+    sb.append("prereq=").append(prerequisites.toString()).append(", ");
+    sb.append("packlets=").append(packlets.toString()).append(", ");
         sb.append('}');
-        return sb.toString();
-    }
+    return sb.toString();
+  }
+
+  public void copyFrom(Mpacks mpack) {
+    if (this.name == null)
+      this.name = mpack.getName();
+    if (this.mpackId == null)
+      this.mpackId = mpack.getMpackId();
+    if (this.version == null)
+      this.version = mpack.getVersion();
+    if (this.stackId == null)
+      this.stackId = mpack.getStackId();
+    if (this.registryId == null)
+      this.registryId = mpack.getRegistryId();
+    if (this.description == null)
+      this.description = mpack.getDescription();
+    if (this.prerequisites == null)
+      this.prerequisites = mpack.getPrerequisites();
+    if (this.packlets == null)
+      this.packlets = mpack.getPacklets();
+
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/java/org/apache/ambari/server/state/Packlet.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Packlet.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Packlet.java
index 0bd2479..1fa8dee 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Packlet.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Packlet.java
@@ -27,6 +27,8 @@ public class Packlet {
   private String name;
   @SerializedName("version")
   private String version;
+  @SerializedName("service-id")
+  private String serviceId;
   @SerializedName("source_dir")
   private String sourceDir;
 
@@ -62,6 +64,16 @@ public class Packlet {
     this.sourceDir = sourceDir;
   }
 
+
+  public String getServiceId() {
+    return serviceId;
+  }
+
+  public void setServiceId(String serviceId) {
+    this.serviceId = serviceId;
+  }
+
+
   /**
    * {@inheritDoc}
    */
@@ -72,6 +84,7 @@ public class Packlet {
     result = prime * result + ((type == null) ? 0 : type.hashCode());
     result = prime * result + ((name == null) ? 0 : name.hashCode());
     result = prime * result + ((version == null) ? 0 : version.hashCode());
+    result = prime * result + ((serviceId == null) ? 0 : serviceId.hashCode());
     result = prime * result + ((sourceDir == null) ? 0 : sourceDir.hashCode());
     return result;
   }
@@ -115,6 +128,14 @@ public class Packlet {
       return false;
     }
 
+    if (serviceId == null) {
+      if (other.serviceId != null) {
+        return false;
+      }
+    } else if (!serviceId.equals(other.serviceId)) {
+      return false;
+    }
+
     if (sourceDir == null) {
       if (other.sourceDir != null) {
         return false;
@@ -132,6 +153,7 @@ public class Packlet {
     sb.append("type=").append(type).append(", ");
     sb.append("name=").append(name).append(", ");
     sb.append("version=").append(version).append(", ");
+    sb.append("service id=").append(serviceId).append(", ");
     sb.append("source directory=").append(sourceDir).append(", ");
     sb.append('}');
     return sb.toString();

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
index d01a670..43057fb 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
@@ -17,11 +17,30 @@
 --
 
 ------create tables and grant privileges to db user---------
+CREATE TABLE registries(
+ id BIGINT NOT NULL,
+ registy_name VARCHAR(255) NOT NULL,
+ registry_type VARCHAR(255) NOT NULL,
+ registry_uri VARCHAR(255) NOT NULL,
+ CONSTRAINT PK_registries PRIMARY KEY (id));
+
+CREATE TABLE mpacks(
+ id BIGINT NOT NULL,
+ mpack_name VARCHAR(255) NOT NULL,
+ mpack_version VARCHAR(255) NOT NULL,
+ mpack_uri VARCHAR(255),
+ registry_id BIGINT,
+ CONSTRAINT PK_mpacks PRIMARY KEY (id),
+ CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id),
+ CONSTRAINT uni_mpack_name_version UNIQUE(mpack_name, mpack_version));
+
 CREATE TABLE stack(
   stack_id BIGINT NOT NULL,
   stack_name VARCHAR(255) NOT NULL,
   stack_version VARCHAR(255) NOT NULL,
+  current_mpack_id BIGINT,
   CONSTRAINT PK_stack PRIMARY KEY (stack_id),
+  CONSTRAINT FK_mpacks FOREIGN KEY (current_mpack_id) REFERENCES mpacks(id),
   CONSTRAINT UQ_stack UNIQUE (stack_name, stack_version));
 
 CREATE TABLE extension(
@@ -898,23 +917,6 @@ CREATE TABLE ambari_operation_history(
   CONSTRAINT PK_ambari_operation_history PRIMARY KEY (id)
 );
 
-CREATE TABLE registries(
- id BIGINT NOT NULL,
- registy_name VARCHAR(255) NOT NULL,
- registry_type VARCHAR(255) NOT NULL,
- registry_uri VARCHAR(255) NOT NULL,
- CONSTRAINT PK_registries PRIMARY KEY (id));
-
-CREATE TABLE mpacks(
- id BIGINT NOT NULL,
- mpack_name VARCHAR(255) NOT NULL,
- mpack_version VARCHAR(255) NOT NULL,
- mpack_uri VARCHAR(255),
- registry_id BIGINT,
- CONSTRAINT PK_mpacks PRIMARY KEY (id),
- CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id),
- CONSTRAINT uni_mpack_name_version UNIQUE(mpack_name, mpack_version));
-
 -- tasks indices --
 CREATE INDEX idx_stage_request_id ON stage (request_id);
 CREATE INDEX idx_hrc_request_id ON host_role_command (request_id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index 415350a..f20882b 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -36,12 +36,30 @@ prepare statement from @engine_stmt;
 execute statement;
 DEALLOCATE PREPARE statement;
 
+CREATE TABLE registries(
+ id BIGINT NOT NULL,
+ registy_name VARCHAR(255) NOT NULL,
+ registry_type VARCHAR(255) NOT NULL,
+ registry_uri VARCHAR(255) NOT NULL,
+ CONSTRAINT PK_registries PRIMARY KEY (id));
+
+CREATE TABLE mpacks(
+ id BIGINT NOT NULL,
+ mpack_name VARCHAR(255) NOT NULL,
+ mpack_version VARCHAR(255) NOT NULL,
+ mpack_uri VARCHAR(255),
+ registry_id BIGINT,
+ CONSTRAINT PK_mpacks PRIMARY KEY (id),
+ CONSTRAINT uni_mpack_name_version UNIQUE(mpack_name, mpack_version),
+ CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id));
 
 CREATE TABLE stack(
   stack_id BIGINT NOT NULL,
   stack_name VARCHAR(100) NOT NULL,
   stack_version VARCHAR(100) NOT NULL,
+  current_mpack_id BIGINT,
   CONSTRAINT PK_stack PRIMARY KEY (stack_id),
+  CONSTRAINT FK_mpacks FOREIGN KEY (current_mpack_id) REFERENCES mpacks(id),
   CONSTRAINT UQ_stack UNIQUE (stack_name, stack_version));
 
 CREATE TABLE extension(
@@ -1062,23 +1080,6 @@ CREATE TABLE alert_notice (
   FOREIGN KEY (history_id) REFERENCES alert_history(alert_id)
 );
 
-CREATE TABLE registries(
- id BIGINT NOT NULL,
- registy_name VARCHAR(255) NOT NULL,
- registry_type VARCHAR(255) NOT NULL,
- registry_uri VARCHAR(255) NOT NULL,
- CONSTRAINT PK_registries PRIMARY KEY (id));
-
-CREATE TABLE mpacks(
- id BIGINT NOT NULL,
- mpack_name VARCHAR(255) NOT NULL,
- mpack_version VARCHAR(255) NOT NULL,
- mpack_uri VARCHAR(255),
- registry_id BIGINT,
- CONSTRAINT PK_mpacks PRIMARY KEY (id),
- CONSTRAINT uni_mpack_name_version UNIQUE(mpack_name, mpack_version),
- CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id));
-
 CREATE INDEX idx_alert_history_def_id on alert_history(alert_definition_id);
 CREATE INDEX idx_alert_history_service on alert_history(service_name);
 CREATE INDEX idx_alert_history_host on alert_history(host_name);

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index bb2a559..05779b0 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -17,11 +17,30 @@
 --
 
 ------create tables---------
+CREATE TABLE registries(
+ id BIGINT NOT NULL,
+ registy_name VARCHAR(255) NOT NULL,
+ registry_type VARCHAR(255) NOT NULL,
+ registry_uri VARCHAR(255) NOT NULL,
+ CONSTRAINT PK_registries PRIMARY KEY (id));
+
+CREATE TABLE mpacks(
+ id BIGINT NOT NULL,
+ mpack_name VARCHAR(255) NOT NULL,
+ mpack_version VARCHAR(255) NOT NULL,
+ mpack_uri VARCHAR(255),
+ registry_id BIGINT,
+ CONSTRAINT PK_mpacks PRIMARY KEY (id),
+ CONSTRAINT uni_mpack_name_version UNIQUE(mpack_name, mpack_version),
+ CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id));
+
 CREATE TABLE stack(
   stack_id NUMBER(19) NOT NULL,
   stack_name VARCHAR2(255) NOT NULL,
   stack_version VARCHAR2(255) NOT NULL,
+  current_mpack_id BIGINT,
   CONSTRAINT PK_stack PRIMARY KEY (stack_id),
+  CONSTRAINT FK_mpacks FOREIGN KEY (current_mpack_id) REFERENCES mpacks(id),
   CONSTRAINT UQ_stack UNIQUE (stack_name, stack_version));
 
 CREATE TABLE extension(
@@ -1041,23 +1060,6 @@ CREATE TABLE alert_notice (
   FOREIGN KEY (history_id) REFERENCES alert_history(alert_id)
 );
 
-CREATE TABLE registries(
- id BIGINT NOT NULL,
- registy_name VARCHAR(255) NOT NULL,
- registry_type VARCHAR(255) NOT NULL,
- registry_uri VARCHAR(255) NOT NULL,
- CONSTRAINT PK_registries PRIMARY KEY (id));
-
-CREATE TABLE mpacks(
- id BIGINT NOT NULL,
- mpack_name VARCHAR(255) NOT NULL,
- mpack_version VARCHAR(255) NOT NULL,
- mpack_uri VARCHAR(255),
- registry_id BIGINT,
- CONSTRAINT PK_mpacks PRIMARY KEY (id),
- CONSTRAINT uni_mpack_name_version UNIQUE(mpack_name, mpack_version),
- CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id));
-
 CREATE INDEX idx_alert_history_def_id on alert_history(alert_definition_id);
 CREATE INDEX idx_alert_history_service on alert_history(service_name);
 CREATE INDEX idx_alert_history_host on alert_history(host_name);

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index de9eb68..afb676d 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -17,11 +17,30 @@
 --
 
 ------create tables and grant privileges to db user---------
+CREATE TABLE registries(
+ id BIGINT NOT NULL,
+ registy_name VARCHAR(255) NOT NULL,
+ registry_type VARCHAR(255) NOT NULL,
+ registry_uri VARCHAR(255) NOT NULL,
+ CONSTRAINT PK_registries PRIMARY KEY (id));
+
+CREATE TABLE mpacks(
+ id BIGINT NOT NULL,
+ mpack_name VARCHAR(255) NOT NULL,
+ mpack_version VARCHAR(255) NOT NULL,
+ mpack_uri VARCHAR(255),
+ registry_id BIGINT,
+ CONSTRAINT PK_mpacks PRIMARY KEY (id),
+ CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id),
+ CONSTRAINT uni_mpack_name_version UNIQUE(mpack_name, mpack_version));
+
 CREATE TABLE stack(
   stack_id BIGINT NOT NULL,
   stack_name VARCHAR(255) NOT NULL,
   stack_version VARCHAR(255) NOT NULL,
+  current_mpack_id BIGINT,
   CONSTRAINT PK_stack PRIMARY KEY (stack_id),
+  CONSTRAINT FK_mpacks FOREIGN KEY (current_mpack_id) REFERENCES mpacks(id),
   CONSTRAINT UQ_stack UNIQUE (stack_name, stack_version));
 
 CREATE TABLE extension(
@@ -1557,23 +1576,6 @@ CREATE TABLE qrtz_locks
   PRIMARY KEY (SCHED_NAME,LOCK_NAME)
 );
 
-CREATE TABLE registries(
- id BIGINT NOT NULL,
- registy_name VARCHAR(255) NOT NULL,
- registry_type VARCHAR(255) NOT NULL,
- registry_uri VARCHAR(255) NOT NULL,
- CONSTRAINT PK_registries PRIMARY KEY (id));
-
-CREATE TABLE mpacks(
- id BIGINT NOT NULL,
- mpack_name VARCHAR(255) NOT NULL,
- mpack_version VARCHAR(255) NOT NULL,
- mpack_uri VARCHAR(255),
- registry_id BIGINT,
- CONSTRAINT PK_mpacks PRIMARY KEY (id),
- CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id)
- CONSTRAINT uni_mpack_name_version UNIQUE(mpack_name, mpack_version));
-
 create index idx_qrtz_j_req_recovery on qrtz_job_details(SCHED_NAME,REQUESTS_RECOVERY);
 create index idx_qrtz_j_grp on qrtz_job_details(SCHED_NAME,JOB_GROUP);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
index fb9b878..8df88f1 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
@@ -16,11 +16,30 @@
 -- limitations under the License.
 --
 
+CREATE TABLE registries(
+ id BIGINT NOT NULL,
+ registy_name VARCHAR(255) NOT NULL,
+ registry_type VARCHAR(255) NOT NULL,
+ registry_uri VARCHAR(255) NOT NULL,
+ CONSTRAINT PK_registries PRIMARY KEY (id));
+
+CREATE TABLE mpacks(
+ id BIGINT NOT NULL,
+ mpack_name VARCHAR(255) NOT NULL,
+ mpack_version VARCHAR(255) NOT NULL,
+ mpack_uri VARCHAR(255),
+ registry_id BIGINT,
+ CONSTRAINT PK_mpacks PRIMARY KEY (id),
+ CONSTRAINT uni_mpack_name_version UNIQUE(mpack_name, mpack_version),
+ CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id));
+
 CREATE TABLE stack(
   stack_id NUMERIC(19) NOT NULL,
   stack_name VARCHAR(255) NOT NULL,
   stack_version VARCHAR(255) NOT NULL,
+  current_mpack_id BIGINT,
   CONSTRAINT PK_stack PRIMARY KEY (stack_id),
+  CONSTRAINT FK_mpacks FOREIGN KEY (current_mpack_id) REFERENCES mpacks(id),
   CONSTRAINT UQ_stack UNIQUE (stack_name, stack_version));
 
 CREATE TABLE extension(
@@ -1041,23 +1060,6 @@ CREATE TABLE alert_notice (
   FOREIGN KEY (history_id) REFERENCES alert_history(alert_id)
 );
 
-CREATE TABLE registries(
- id BIGINT NOT NULL,
- registy_name VARCHAR(255) NOT NULL,
- registry_type VARCHAR(255) NOT NULL,
- registry_uri VARCHAR(255) NOT NULL,
- CONSTRAINT PK_registries PRIMARY KEY (id));
-
-CREATE TABLE mpacks(
- id BIGINT NOT NULL,
- mpack_name VARCHAR(255) NOT NULL,
- mpack_version VARCHAR(255) NOT NULL,
- mpack_uri VARCHAR(255),
- registry_id BIGINT,
- CONSTRAINT PK_mpacks PRIMARY KEY (id),
- CONSTRAINT uni_mpack_name_version UNIQUE(mpack_name, mpack_version),
- CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id));
-
 CREATE INDEX idx_alert_history_def_id on alert_history(alert_definition_id);
 CREATE INDEX idx_alert_history_service on alert_history(service_name);
 CREATE INDEX idx_alert_history_host on alert_history(host_name);

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
index c42892f..b9a18f3 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -29,11 +29,30 @@ sqlcmd -S localhost\SQLEXPRESS -i C:\app\ambari-server-1.3.0-SNAPSHOT\resources\
 ------create the database------
 
 ------create tables and grant privileges to db user---------
+CREATE TABLE registries(
+ id BIGINT NOT NULL,
+ registy_name VARCHAR(255) NOT NULL,
+ registry_type VARCHAR(255) NOT NULL,
+ registry_uri VARCHAR(255) NOT NULL,
+ CONSTRAINT PK_registries PRIMARY KEY (id));
+
+CREATE TABLE mpacks(
+ id BIGINT NOT NULL,
+ mpack_name VARCHAR(255) NOT NULL,
+ mpack_version VARCHAR(255) NOT NULL,
+ mpack_uri VARCHAR(255),
+ registry_id BIGINT,
+ CONSTRAINT PK_mpacks PRIMARY KEY (id),
+ CONSTRAINT uni_mpack_name_version UNIQUE(mpack_name, mpack_version),
+ CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id));
+
 CREATE TABLE stack(
   stack_id BIGINT NOT NULL,
   stack_name VARCHAR(255) NOT NULL,
   stack_version VARCHAR(255) NOT NULL,
+  current_mpack_id BIGINT,
   CONSTRAINT PK_stack PRIMARY KEY CLUSTERED (stack_id),
+  CONSTRAINT FK_mpacks FOREIGN KEY (current_mpack_id) REFERENCES mpacks(id),
   CONSTRAINT UQ_stack UNIQUE (stack_name, stack_version));
 
 CREATE TABLE extension(
@@ -1065,23 +1084,6 @@ CREATE TABLE alert_notice (
   FOREIGN KEY (history_id) REFERENCES alert_history(alert_id)
 );
 
-CREATE TABLE registries(
- id BIGINT NOT NULL,
- registy_name VARCHAR(255) NOT NULL,
- registry_type VARCHAR(255) NOT NULL,
- registry_uri VARCHAR(255) NOT NULL,
- CONSTRAINT PK_registries PRIMARY KEY (id));
-
-CREATE TABLE mpacks(
- id BIGINT NOT NULL,
- mpack_name VARCHAR(255) NOT NULL,
- mpack_version VARCHAR(255) NOT NULL,
- mpack_uri VARCHAR(255),
- registry_id BIGINT,
- CONSTRAINT PK_mpacks PRIMARY KEY (id),
- CONSTRAINT uni_mpack_name_version UNIQUE(mpack_name, mpack_version),
- CONSTRAINT FK_registries FOREIGN KEY (registry_id) REFERENCES registries(id));
-
 CREATE INDEX idx_alert_history_def_id on alert_history(alert_definition_id);
 CREATE INDEX idx_alert_history_service on alert_history(service_name);
 CREATE INDEX idx_alert_history_host on alert_history(host_name);

http://git-wip-us.apache.org/repos/asf/ambari/blob/7849de66/ambari-server/src/main/resources/mpacks-v2/README.txt
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/mpacks-v2/README.txt b/ambari-server/src/main/resources/mpacks-v2/README.txt
new file mode 100644
index 0000000..fae891f
--- /dev/null
+++ b/ambari-server/src/main/resources/mpacks-v2/README.txt
@@ -0,0 +1 @@
+This folder is reserved for mpacks.
\ No newline at end of file


Mime
View raw message