You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "yifan-c (via GitHub)" <gi...@apache.org> on 2023/06/01 01:06:39 UTC

[GitHub] [cassandra-sidecar] yifan-c commented on a diff in pull request #47: CASSANDRASC-52 Sidecar Returns Own Version in Node Settings

yifan-c commented on code in PR #47:
URL: https://github.com/apache/cassandra-sidecar/pull/47#discussion_r1212458582


##########
common/src/main/java/org/apache/cassandra/sidecar/common/NodeSettings.java:
##########
@@ -16,33 +16,75 @@
  * limitations under the License.
  */
 
-
 package org.apache.cassandra.sidecar.common;
 
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Objects;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Holds information about the specific node settings
  */
 public class NodeSettings
 {
-    private final String releaseVersion;
+    private static final Logger LOGGER = LoggerFactory.getLogger(NodeSettings.class);
+    private static final String SIDECAR_VERSION = getSidecarVersion();
+
     private final String partitioner;
+    private final String releaseVersion;
+    private final String sidecarVersion;
+
+    private static String getSidecarVersion()
+    {
+        try (InputStream version = NodeSettings.class.getResourceAsStream("/sidecar.version"))
+        {
+            return IOUtils.toString(version, StandardCharsets.UTF_8);
+        }
+        catch (Exception exception)
+        {
+            LOGGER.error("Failed to ex 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 partitioner
+     * and release version information, uses Sidecar version from the currently loaded binary
      *
+     * @param partitioner    the partitioner used by the Cassandra node
      * @param releaseVersion the release version of the Cassandra node
+     */
+    public NodeSettings(String partitioner, String releaseVersion)
+    {
+        this(partitioner, releaseVersion, SIDECAR_VERSION);
+    }
+
+    /**
+     * Constructs a new {@link NodeSettings} object with the Cassandra node's partitioner,
+     * release version, and Sidecar version information
+     *
      * @param partitioner    the partitioner used by the Cassandra node
+     * @param releaseVersion the release version of the Cassandra node
+     * @param sidecarVersion the version of the Sidecar on the Cassandra node
      */
-    public NodeSettings(@JsonProperty("releaseVersion") String releaseVersion,
-                        @JsonProperty("partitioner") String partitioner)
+    public NodeSettings(@JsonProperty("partitioner")    String partitioner,
+                        @JsonProperty("releaseVersion") String releaseVersion,

Review Comment:
   I do not think the order is fixed even if you change the order in the param list, unless `@JsonPropertyOrder` is declared. 
   
   It kind of reminds me of the clarity of the payload. See the example below. It feels unclear. Because the fields in node settings response payload were only about the cassandra node below. Now, we have a field about sidecar, that is sitting next to the cassandra fields at the _same_ level. 
   We certainly cannot change the schema of the existing fields. I guess you do not want to add an extra endpoint just for sidecar. 
   What do you think about adding a sidecar json object, that includes the sidecar version and other related settings to be added in the future? 
   
   ```json
   {
     "partitioner": "Murmur3Partitioner",
     "releaseVersion": "4.0",
     "sidecarVersion": "1.0"
   }
   ```
   
   The alternative,
   ```java
   {
     "partitioner": "Murmur3Partitioner",
     "releaseVersion": "4.0",
     "sidecar": {
       "version": "1.0"
     }
   }
   ```



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org