public List create()

in gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariDynamicServiceURLCreator.java [112:175]


    public List<String> create(String serviceName, Map<String, String> serviceParams) {
        List<String> urls = new ArrayList<>();

        Map<String, String> placeholderValues = new HashMap<>();
        List<String> componentHostnames = new ArrayList<>();
        String hostNamePlaceholder = null;

        ServiceURLPropertyConfig.URLPattern pattern = config.getURLPattern(serviceName);
        if (pattern != null) {
            for (String propertyName : pattern.getPlaceholders()) {
                ServiceURLPropertyConfig.Property configProperty = config.getConfigProperty(serviceName, propertyName);

                String propertyValue = null;
                if (configProperty != null) {
                    String propertyType = configProperty.getType();
                    if (ServiceURLPropertyConfig.Property.TYPE_SERVICE.equals(propertyType)) {
                        log.lookingUpServiceConfigProperty(configProperty.getService(), configProperty.getServiceConfig(), configProperty.getValue());
                        AmbariCluster.ServiceConfiguration svcConfig =
                            cluster.getServiceConfiguration(configProperty.getService(), configProperty.getServiceConfig());
                        if (svcConfig != null) {
                            propertyValue = svcConfig.getProperties().get(configProperty.getValue());
                        }
                    } else if (ServiceURLPropertyConfig.Property.TYPE_COMPONENT.equals(propertyType)) {
                        String compName = configProperty.getComponent();
                        if (compName != null) {
                            AmbariComponent component = cluster.getComponent(compName);
                            if (component != null) {
                                if (ServiceURLPropertyConfig.Property.PROP_COMP_HOSTNAME.equals(configProperty.getValue())) {
                                    log.lookingUpComponentHosts(compName);
                                    componentHostnames.addAll(component.getHostNames());
                                    hostNamePlaceholder = propertyName; // Remember the host name placeholder
                                } else {
                                    log.lookingUpComponentConfigProperty(compName, configProperty.getValue());
                                    propertyValue = component.getConfigProperty(configProperty.getValue());
                                }
                            }
                        }
                    } else { // Derived property
                        log.handlingDerivedProperty(serviceName, configProperty.getType(), configProperty.getName());
                        ServiceURLPropertyConfig.Property p = config.getConfigProperty(serviceName, configProperty.getName());
                        propertyValue = p.getValue();
                        if (propertyValue == null && p.getConditionHandler() != null) {
                            propertyValue = p.getConditionHandler().evaluate(config, cluster);
                        }
                    }

                    log.determinedPropertyValue(configProperty.getName(), propertyValue);
                    placeholderValues.put(configProperty.getName(), propertyValue);
                }
            }

            // For patterns with a placeholder value for the hostname (e.g., multiple URL scenarios)
            if (!componentHostnames.isEmpty()) {
                for (String componentHostname : componentHostnames) {
                    String url = pattern.get().replace("{" + hostNamePlaceholder + "}", componentHostname);
                    urls.add(createURL(url, placeholderValues));
                }
            } else { // Single URL result case
                urls.add(createURL(pattern.get(), placeholderValues));
            }
        }

        return urls;
    }