Search in sources :

Example 1 with ComponentPropertyPattern

use of com.hortonworks.streamline.streams.cluster.discovery.ambari.ComponentPropertyPattern in project streamline by hortonworks.

the class EnvironmentService method injectProtocolAndPortToComponent.

public void injectProtocolAndPortToComponent(Map<String, String> configurations, Component component, List<ComponentProcess> componentProcesses) {
    try {
        ComponentPropertyPattern componentPropertyPattern = ComponentPropertyPattern.valueOf(component.getName());
        String value = configurations.get(componentPropertyPattern.getConnectionConfName());
        if (value != null) {
            Pattern parsePattern = componentPropertyPattern.getParsePattern();
            LOG.debug("Connection configuration name: [{}], parse pattern: [{}]", value, parsePattern);
            if (parsePattern != null) {
                Matcher matcher = parsePattern.matcher(value);
                if (matcher.matches()) {
                    String protocol = matcher.group(1);
                    String portStr = matcher.group(2);
                    if (!protocol.isEmpty()) {
                        for (ComponentProcess componentProcess : componentProcesses) {
                            componentProcess.setProtocol(protocol);
                        }
                    }
                    if (!portStr.isEmpty()) {
                        try {
                            int port = Integer.parseInt(portStr);
                            for (ComponentProcess componentProcess : componentProcesses) {
                                componentProcess.setPort(port);
                            }
                        } catch (NumberFormatException e) {
                            LOG.warn("Protocol/Port information [{}] for component {} has illegal format [{}]." + "skip assigning...", value, component.getName(), parsePattern);
                            // reset protocol information
                            for (ComponentProcess componentProcess : componentProcesses) {
                                componentProcess.setPort(null);
                            }
                        }
                    }
                } else {
                    LOG.warn("Protocol/Port information [{}] for component {} doesn't seem to known format [{}]. " + "skipping assignment...", value, component.getName(), parsePattern);
                }
            }
        } else {
            LOG.warn("Protocol/Port related configuration ({}) is not set", componentPropertyPattern.getConnectionConfName());
        }
    } catch (IllegalArgumentException e) {
    // don't know port related configuration
    }
}
Also used : ComponentPropertyPattern(com.hortonworks.streamline.streams.cluster.discovery.ambari.ComponentPropertyPattern) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ComponentPropertyPattern(com.hortonworks.streamline.streams.cluster.discovery.ambari.ComponentPropertyPattern) ComponentProcess(com.hortonworks.streamline.streams.cluster.catalog.ComponentProcess)

Aggregations

ComponentProcess (com.hortonworks.streamline.streams.cluster.catalog.ComponentProcess)1 ComponentPropertyPattern (com.hortonworks.streamline.streams.cluster.discovery.ambari.ComponentPropertyPattern)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1