pauloricardomg commented on code in PR #351: URL: https://github.com/apache/cassandra-sidecar/pull/351#discussion_r3262168302
########## server/src/main/java/org/apache/cassandra/sidecar/configmanagement/CassandraConfigurationOverlay.java: ########## @@ -0,0 +1,172 @@ +/* + * 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.sidecar.configmanagement; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Represents a configuration overlay - a sparse set of configuration values that overwrite base template + * values or add new configuration attributes. + * + * <p>The {@code cassandraYaml} field is a version-agnostic JSON representation of {@code cassandra.yaml} + * settings. It may contain settings from any Cassandra version supported by Sidecar (4.0, 4.1, 5.0, etc.). + * No version-specific validation is performed by this class; validation against a version-aware schema is + * the responsibility of the Configuration Manager. + * + * <p>The {@code extraJvmOpts} field contains JVM options that are appended to the Cassandra JVM startup + * command. These are opaque strings not subject to schema validation. + */ +public class CassandraConfigurationOverlay +{ + private static final ObjectMapper MAPPER = new ObjectMapper(); + + @NotNull + private final JsonNode cassandraYaml; + + @NotNull + private final List<String> extraJvmOpts; + + @JsonCreator + public CassandraConfigurationOverlay(@JsonProperty("cassandraYaml") @Nullable JsonNode cassandraYaml, + @JsonProperty("extraJvmOpts") @Nullable List<String> extraJvmOpts) + { + if (cassandraYaml == null) + { + this.cassandraYaml = MAPPER.createObjectNode(); + } + else if (!cassandraYaml.isObject()) + { + throw new IllegalArgumentException("cassandraYaml must be a JSON object, got " + cassandraYaml.getNodeType()); + } + else + { + this.cassandraYaml = cassandraYaml; + } + this.extraJvmOpts = extraJvmOpts != null + ? Collections.unmodifiableList(new ArrayList<>(extraJvmOpts)) + : Collections.emptyList(); + } + + /** + * @return the cassandra.yaml overlay as a version-agnostic JSON object + */ + @JsonProperty("cassandraYaml") + @NotNull + public JsonNode cassandraYaml() + { + return cassandraYaml; Review Comment: Since this is an internal API, I opted to avoid defensive copies on every accessor call to minimize unnecessary object creation. I updated the constructor to deep-copy the input ObjectNode to prevent external mutation through the original reference, and updated the accessor Javadoc to mention that callers must not mutate the returned node (use updated() instead). This gives us immutability guarantees at construction time without the overhead of copying on every read. See commit e95958e1. -- 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]

