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
}
}
Aggregations