private void populateDB(StackDAO stackDao, ExtensionDAO extensionDao) throws AmbariException {
    // for every stack read in, ensure that we have a database entry for it;
    // don't put try/catch logic around this since a failure here will
    // cause other things to break down the road
    Collection<StackInfo> stacks = getStacks();
    for(StackInfo stack : stacks){
      String stackName = stack.getName();
      String stackVersion = stack.getVersion();

      if (stackDao.find(stackName, stackVersion) == null) {
        LOG.info("Adding stack {}-{} to the database", stackName, stackVersion);

        StackEntity stackEntity = new StackEntity();
        stackEntity.setStackName(stackName);
        stackEntity.setStackVersion(stackVersion);

        stackDao.create(stackEntity);
      }
    }

    // for every extension read in, ensure that we have a database entry for it;
    // don't put try/catch logic around this since a failure here will
    // cause other things to break down the road
    Collection<ExtensionInfo> extensions = getExtensions();
    for(ExtensionInfo extension : extensions){
      String extensionName = extension.getName();
      String extensionVersion = extension.getVersion();

      if (extensionDao.find(extensionName, extensionVersion) == null) {
        LOG.info("Adding extension {}-{} to the database", extensionName, extensionVersion);

        ExtensionEntity extensionEntity = new ExtensionEntity();
        extensionEntity.setExtensionName(extensionName);
        extensionEntity.setExtensionVersion(extensionVersion);

        extensionDao.create(extensionEntity);
      }
    }

    createLinks();
  }
Constructor. Initialize stack manager.

@param stackRootDir
         stack root directory
@param commonServicesRoot
         common services root directory
@param extensionRoot
         extensions root directory
@param osFamily
         the OS family read from resources
@param metaInfoDAO
         metainfo DAO automatically injected
@param actionMetadata
         action meta data automatically injected
@param stackDao
         stack DAO automatically injected
@param extensionDao
         extension DAO automatically injected
@param linkDao
         extension link DAO automatically injected
@param helper
         Ambari management helper automatically injected

@throws AmbariException
          if an exception occurs while processing the stacks
ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java