public MpackResponse registerMpack(MpackRequest mpackRequest)
          throws IOException, IllegalArgumentException, ResourceAlreadyExistsException {

    Long mpackResourceId;
    String mpackName = "";
    String mpackVersion = "";
    mpack = new Mpack();
    boolean isValidMetadata;
    String mpackDirectory = "";
    Path mpackTarPath;

    //Mpack registration using a software registry
    if (mpackRequest.getRegistryId() != null) {
      mpackName = mpackRequest.getMpackName();
      mpackVersion = mpackRequest.getMpackVersion();

      LOG.info("Mpack Registration via Registry :" + mpackName);

      mpack = downloadMpackMetadata(mpackRequest.getMpackUri());
      mpack.setRegistryId(mpackRequest.getRegistryId());
      isValidMetadata = validateMpackInfo(mpackName, mpackVersion, mpack.getName(), mpack.getVersion());

      if (isValidMetadata) {
        mpackTarPath = downloadMpack(mpackRequest.getMpackUri(), mpack.getDefinition());
        createMpackDirectory(mpack);
        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
      mpack = downloadMpackMetadata(mpackRequest.getMpackUri());
      mpackTarPath = downloadMpack(mpackRequest.getMpackUri(), mpack.getDefinition());

      LOG.info("Custom Mpack Registration :" + mpackRequest.getMpackUri());


      if (createMpackDirectory(mpack)) {
        mpackDirectory = mpackStaging + File.separator + mpack.getName() + File.separator + mpack.getVersion();

      }
    }
    extractMpackTar(mpack, mpackTarPath, mpackDirectory);
    mpack.setMpackUri(mpackRequest.getMpackUri());
    mpackResourceId = populateDB(mpack);

    if (mpackResourceId != null) {
      mpackMap.put(mpackResourceId, mpack);
      mpack.setResourceId(mpackResourceId);
      populateStackDB(mpack);
      return new MpackResponse(mpack);
    }
    String message = "Mpack :" + mpackRequest.getMpackName() + " version: " + mpackRequest.getMpackVersion()
            + " already exists in server";
    throw new ResourceAlreadyExistsException(message);

  }
Parses mpack.json to fetch mpack and associated packlet information and
stores the mpack to the database and mpackMap

@param mpackRequest
@return MpackResponse
@throws IOException
@throws IllegalArgumentException
@throws ResourceAlreadyExistsException
ambari-server/src/test/java/org/apache/ambari/server/mpack/MpackManagerMock.java