smiklosovic commented on code in PR #2988: URL: https://github.com/apache/cassandra/pull/2988#discussion_r1537875140
########## src/java/org/apache/cassandra/locator/HttpSeedProvider.java: ########## @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.locator; + +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.regex.Pattern; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static java.util.stream.Collectors.toList; +import static org.apache.cassandra.locator.HttpServiceConnector.resolveMetadataUrl; +import static org.apache.cassandra.locator.HttpServiceConnector.resolveRequestTimeoutMs; + +public class HttpSeedProvider implements SeedProvider +{ + private static final Logger logger = LoggerFactory.getLogger(HttpSeedProvider.class); + private static final Pattern NEW_LINES_PATTERN = Pattern.compile("\\n"); + + static final String SEEDS_URL_PROPERTY = "seeds_url"; + static final String REQUEST_HEADERS_PROPERTY = "request_headers"; + static final String REQUEST_TIMEOUT_PROPERTY = "request_timeout"; + static final String DEFAULT_REQUEST_TIMEOUT = "30s"; + + private final HttpServiceConnector serviceConnector; + private final Map<String, String> headers; + + public HttpSeedProvider(Map<String, String> parameters) + { + this(getProperties(parameters)); + } + + public HttpSeedProvider(Properties properties) + { + serviceConnector = new HttpServiceConnector(resolveMetadataUrl(properties, SEEDS_URL_PROPERTY), + resolveRequestTimeoutMs(properties, + REQUEST_TIMEOUT_PROPERTY, + DEFAULT_REQUEST_TIMEOUT)); + headers = resolveHeaders(properties); + } + + @Override + public List<InetAddressAndPort> getSeeds() + { + try + { + String response = serviceConnector.apiCall("", headers); + + List<String> lines = Arrays.stream(NEW_LINES_PATTERN.split(response)) + .map(String::trim) + .filter(s -> !s.isBlank()) + .distinct() + .collect(toList()); + + List<InetAddressAndPort> seeds = new ArrayList<>(lines.size()); + + for (String line : lines) + { + try + { + seeds.add(InetAddressAndPort.getByName(line)); Review Comment: If port is part of a `line` here, it will be used, if `line` does not contain port, default port of 7000 will be used. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

