frankgh commented on code in PR #47: URL: https://github.com/apache/cassandra-sidecar/pull/47#discussion_r1213747158
########## common/src/main/java/org/apache/cassandra/sidecar/common/NodeSettings.java: ########## @@ -16,33 +16,80 @@ * limitations under the License. */ - package org.apache.cassandra.sidecar.common; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.Map; import java.util.Objects; import com.fasterxml.jackson.annotation.JsonProperty; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Holds information about the specific node settings */ public class NodeSettings { + private static final Logger LOGGER = LoggerFactory.getLogger(NodeSettings.class); + private static final String VERSION = "version"; + private static final String SIDECAR_VERSION = getSidecarVersion(); + private final String releaseVersion; private final String partitioner; + private final Map<String, String> sidecar; + + private static String getSidecarVersion() + { + final String resource = "/sidecar.version"; + try (InputStream input = NodeSettings.class.getResourceAsStream(resource); + ByteArrayOutputStream output = new ByteArrayOutputStream()) + { + byte[] buffer = new byte[32]; + int length; + while ((length = input.read(buffer)) >= 0) + { + output.write(buffer, 0, length); + } + return output.toString(StandardCharsets.UTF_8.name()); + } + catch (Exception exception) + { + LOGGER.error("Failed to retrieve Sidecar version", exception); + } + return "unknown"; + } /** - * Constructs a new {@link NodeSettings} object with the Cassandra node's release version and partitioner - * information. + * Constructs a new {@link NodeSettings} object with the Cassandra node's release version + * and partitioner information, uses Sidecar version from the currently loaded binary * * @param releaseVersion the release version of the Cassandra node * @param partitioner the partitioner used by the Cassandra node */ + public NodeSettings(String releaseVersion, String partitioner) + { + this(releaseVersion, partitioner, Collections.singletonMap(VERSION, SIDECAR_VERSION)); Review Comment: a tiny object creation optimization is to declare the map as a static field. That way we no longer need to declare `SIDECAR_VERSION`. The downside of this approach is that the code will change if we add any other field to the map in the future where the new value in the map is dynamic. -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org