private Set<String> deleteUnsupportedComponents(Cluster cluster, RepositoryVersionEntity repoVersion) throws AmbariException {
    Set<String> deletedComponents = new HashSet<>();
    for (ServiceComponent component : serviceComponentSupport.unsupportedComponents(cluster, repoVersion.getStackName(), repoVersion.getStackVersion())) {
      DeleteHostComponentStatusMetaData deleteMetaData = new DeleteHostComponentStatusMetaData();
      cluster.getService(component.getServiceName()).deleteServiceComponent(component.getName(), deleteMetaData);
      STOMPComponentsDeleteHandler.processDeleteByMetaDataException(deleteMetaData);
      STOMPComponentsDeleteHandler.processDeleteByMetaData(deleteMetaData);
      deleteUpgradeHistory(cluster, history -> component.getName().equals(history.getComponentName()));
      deletedComponents.add(component.getName());
    }
    return deletedComponents;
  }
Upgrade Server Action that deletes the components and services which are no
longer supported in the target stack. The deletable component or service
should be in deletable state (stopped) before executing this.
<p/>
This will orphan Kerberos keytabs and identities that belonged to the removed
services and components. Since removing these automatically is a new and
untested feature, its best to leave this type of cleanup to a future
implementation.
ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/DeleteUnsupportedServicesAndComponents.java