frankgh commented on code in PR #15: URL: https://github.com/apache/cassandra-analytics/pull/15#discussion_r1331992931
########## cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/validation/SidecarValidation.java: ########## @@ -0,0 +1,58 @@ +/* + * 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.spark.validation; + +import java.util.concurrent.TimeUnit; + +import org.apache.cassandra.sidecar.client.SidecarClient; +import org.apache.cassandra.sidecar.common.data.HealthResponse; + +/** + * A startup validation that checks the connectivity and health of Sidecar + */ +public class SidecarValidation implements StartupValidation +{ + private static final int TIMEOUT_SECONDS = 30; Review Comment: @yifan-c any thoughts about making this configurable? ########## cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/data/CassandraDataLayer.java: ########## @@ -639,6 +644,16 @@ public CassandraRing createCassandraRingFromRing(Partitioner partitioner, return new CassandraRing(partitioner, keyspace, replicationFactor, instances); } + // Startup Validation + + @Override + public void startupValidate() + { + StartupValidator.instance().register(new SidecarValidation(sidecar)); + StartupValidator.instance().register(new CassandraValidation(sidecar)); + StartupValidator.instance().perform(); + } Review Comment: hmm. Thinking a bit more about this, perform gates validation on whether they are enabled or not. So I'm still undecided ########## cassandra-analytics-core/src/test/java/org/apache/cassandra/spark/validation/TrustStoreValidationTests.java: ########## @@ -0,0 +1,94 @@ +/* + * 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.spark.validation; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import org.apache.cassandra.secrets.SecretsProvider; +import org.apache.cassandra.secrets.TestSecretsProvider; + +/** + * Unit tests that cover startup validation of a TrustStore + */ +public class TrustStoreValidationTests +{ + @Test() + public void testNullSecrets() + { + TrustStoreValidation validation = new TrustStoreValidation(null); + + Assertions.assertThrows(RuntimeException.class, validation::perform); + } + + @Test() + public void testUnconfiguredTrustStore() + { + SecretsProvider secrets = TestSecretsProvider.unconfigured(); + TrustStoreValidation validation = new TrustStoreValidation(secrets); + + Assertions.assertDoesNotThrow(validation::perform); // TrustStore is optional + } + + @Test() + public void testMissingTrustStore() + { + SecretsProvider secrets = TestSecretsProvider.forTrustStore("PKCS12", "keystore-missing.p12", "qwerty"); Review Comment: some projects offer a README or script to regenerate the keystore files needed for testing. I think that's useful for new contributors. See https://github.com/eclipse-vertx/vert.x/blob/master/src/test/resources/tls/ssl.txt for reference ########## cassandra-analytics-core/src/test/java/org/apache/cassandra/spark/validation/KeyStoreValidationTests.java: ########## @@ -0,0 +1,94 @@ +/* + * 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.spark.validation; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import org.apache.cassandra.secrets.SecretsProvider; +import org.apache.cassandra.secrets.TestSecretsProvider; + +/** + * Unit tests that cover startup validation of a KeyStore + */ +public class KeyStoreValidationTests +{ + @Test() + public void testNullSecrets() + { + KeyStoreValidation validation = new KeyStoreValidation(null); + + Assertions.assertThrows(RuntimeException.class, validation::perform); Review Comment: +1 , I think we want to assert the exception on the inner exception that RuntimeException is wrapping ########## cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/validation/KeyStoreValidation.java: ########## @@ -0,0 +1,75 @@ +/* + * 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.spark.validation; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.security.Key; +import java.security.KeyStore; +import java.security.PrivateKey; +import java.util.Enumeration; + +import org.apache.cassandra.secrets.SecretsProvider; + +/** + * A startup validation that checks the KeyStore + */ +public class KeyStoreValidation implements StartupValidation +{ + private final SecretsProvider secrets; + + public KeyStoreValidation(SecretsProvider secrets) + { + this.secrets = secrets; + } + + @Override + public void validate() + { + try + { + if (!secrets.hasKeyStoreSecrets()) + { + throw new RuntimeException("KeyStore is unconfigured"); Review Comment: ```suggestion throw new RuntimeException("KeyStore is not configured"); ``` ########## cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/data/CassandraDataLayer.java: ########## @@ -639,6 +644,16 @@ public CassandraRing createCassandraRingFromRing(Partitioner partitioner, return new CassandraRing(partitioner, keyspace, replicationFactor, instances); } + // Startup Validation + + @Override + public void startupValidate() + { + StartupValidator.instance().register(new SidecarValidation(sidecar)); + StartupValidator.instance().register(new CassandraValidation(sidecar)); + StartupValidator.instance().perform(); + } Review Comment: maybe if we do validations upfront, it will be easier to determine where the issues are occurring, so I think it makes sense ########## cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/validation/StartupValidatable.java: ########## @@ -0,0 +1,25 @@ +/* + * 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.spark.validation; + +public interface StartupValidatable Review Comment: +1 , I think we want javadocs for this interface and the method ########## cassandra-analytics-core/src/main/java/org/apache/cassandra/spark/bulkwriter/BulkSparkConf.java: ########## @@ -203,7 +203,7 @@ else if (!batchSizeIsZero && sstableBatchSize != DEFAULT_BATCH_SIZE_IN_ROWS) /* * This method Will throw if the SSL configuration is incorrect (PATH provided w/o password, for example) */ - protected void validateSslConfiguration() + public void validateSslConfiguration() Review Comment: Can we overload this method, and add a new method : ``` public void validateSslConfiguration(boolean extendedValidation) ``` For the existing calling sites, they will still call `validateSslConfiguration()` which in turns calls the method without extended validation `validateSslConfiguration(false)`. Then extended validation adds the Keystore and Truststore validation that we are doing in `KeyStoreValidation` `TrustStoreValidation`. Alternatively, we can extend the existing Keystore/TrustStore validation classes to take the parameters from the configuration (ie. keystore path/base64 password). -- 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]
