class ServiceEndpointCollector {

    public String getManagerServerUrl(Cluster cluster, String managerIp) {
        if (managerIp != null) {
            String orchestrator = cluster.getStack().getOrchestrator().getType();
            if (YARN.equals(orchestrator)) {
                return String.format("http://%s:8080", managerIp);
            } else {
                Gateway gateway = cluster.getGateway();
                if (gateway != null) {
                    ExposedService exposedService = exposedServiceCollector.getClouderaManagerUIService();
                    Optional<GatewayTopology> gatewayTopology = getGatewayTopologyForService(gateway, exposedService);
                    Optional<String> managerUrl = gatewayTopology
                            .map(t -> getExposedServiceUrl(managerIp, gateway, t.getTopologyName(), exposedService, false));
                    // when knox gateway is enabled, but cm is not exposed, use the default url
                    return managerUrl.orElse(String.format("https://%s/", managerIp));
                }
                return String.format("https://%s/clouderamanager/", managerIp);
            }
        }
        return null;
    }

}