public void createExtensionLinks(StackManager stackManager, List<ExtensionInfo> extensions) throws AmbariException {
    Map<String, List<StackInfo>> stackMap = stackManager.getStacksByName();
    for (List<StackInfo> stacks : stackMap.values()) {
      Collections.sort(stacks);
      Collections.reverse(stacks);
    }

    Collections.sort(extensions);
    Collections.reverse(extensions);
    for (ExtensionInfo extension : extensions) {
      if (extension.isActive() && extension.isAutoLink()) {
        LOG.debug("Autolink - looking for matching stack versions for extension:{}/{} ", extension.getName(), extension.getVersion());
        for (ExtensionMetainfoXml.Stack supportedStack : extension.getStacks()) {
          List<StackInfo> stacks = stackMap.get(supportedStack.getName());
          for (StackInfo stack : stacks) {
            // If the stack version is not currently linked to a version of the extension and it meets the minimum stack version then link them
            if (stack.getExtension(extension.getName()) == null && VersionUtils.compareVersions(stack.getVersion(), supportedStack.getVersion()) > -1) {
              LOG.debug("Autolink - extension: {}/{} stack: {}/{}", extension.getName(), extension.getVersion(),
                       stack.getName(), stack.getVersion());
              createExtensionLink(stackManager, stack, extension);
            }
            else {
              LOG.debug("Autolink - not a match extension: {}/{} stack: {}/{}", extension.getName(), extension.getVersion(),
                       stack.getName(), stack.getVersion());
            }
          }
        }
      }
      else {
        LOG.debug("Autolink - skipping extension: {}/{}.  It is either not active or set to autolink.", extension.getName(), extension.getVersion());
      }
    }
  }
This method will create a link between an extension version and a stack version (Extension Link).

An extension version is like a stack version but it contains custom services.  Linking an extension
version to the current stack version allows the cluster to install the custom services contained in
the extension version.
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementHelper.java