void checkHostAndClusterVersions() {
    List<HostVersionEntity> hostVersions = hostVersionDAO.findAll();
    for (HostVersionEntity hostVersion : hostVersions) {
      if (hostVersion.getState().equals(RepositoryVersionState.INSTALLING)) {
        hostVersion.setState(RepositoryVersionState.INSTALL_FAILED);
        String msg = String.format(
                "Recovered state of host version %s on host %s from %s to %s",
                hostVersion.getRepositoryVersion().getDisplayName(),
                hostVersion.getHostName(),
                RepositoryVersionState.INSTALLING,
                RepositoryVersionState.INSTALL_FAILED);
        LOG.warn(msg);
        hostVersionDAO.merge(hostVersion);
      }
    }

    List<ServiceComponentDesiredStateEntity> components = serviceComponentDAO.findAll();
    for (ServiceComponentDesiredStateEntity component : components) {
      if (RepositoryVersionState.INSTALLING == component.getRepositoryState()) {
        component.setRepositoryState(RepositoryVersionState.INSTALL_FAILED);
        serviceComponentDAO.merge(component);
        String msg = String.format(
            "Recovered state of cluster %s of component %s/%s for version %s from %s to %s",
            component.getClusterId(),
            component.getServiceName(),
            component.getComponentName(),
            component.getDesiredRepositoryVersion().getDisplayName(),
            RepositoryVersionState.INSTALLING,
            RepositoryVersionState.INSTALL_FAILED);
        LOG.warn(msg);
      }
    }
  }
Is executed on server start.
Checks server state and recovers it to valid if required.
ambari-server/src/main/java/org/apache/ambari/server/StateRecoveryManager.java