turcsanyip commented on code in PR #6985: URL: https://github.com/apache/nifi/pull/6985#discussion_r1145986094
########## nifi-nar-bundles/nifi-iceberg-bundle/nifi-iceberg-processors/src/test/java/org/apache/nifi/processors/iceberg/TestPutIcebergCustomValidation.java: ########## @@ -0,0 +1,129 @@ +/* + * 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.nifi.processors.iceberg; + +import org.apache.hadoop.conf.Configuration; +import org.apache.nifi.kerberos.KerberosUserService; +import org.apache.nifi.processors.iceberg.catalog.TestHiveCatalogService; +import org.apache.nifi.reporting.InitializationException; +import org.apache.nifi.serialization.record.MockRecordParser; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class TestPutIcebergCustomValidation { + + private static final String RECORD_READER_NAME = "record-reader"; + private static final String KERBEROS_USER_SERVICE_NAME = "kerberos-user-service"; + private static final String CATALOG_SERVICE_NAME = "catalog-service"; + + private static final String CATALOG_NAMESPACE = "catalogNamespace"; + private static final String TABLE_NAME = "tableName"; + + private TestRunner runner; + + @BeforeEach + public void setUp() { + PutIceberg processor = new PutIceberg(); + runner = TestRunners.newTestRunner(processor); + } + + private void initRecordReader() throws InitializationException { + MockRecordParser readerFactory = new MockRecordParser(); + + runner.addControllerService(RECORD_READER_NAME, readerFactory); + runner.enableControllerService(readerFactory); + + runner.setProperty(PutIceberg.RECORD_READER, RECORD_READER_NAME); + } + + private void initCatalogService(Configuration configuration) throws InitializationException { + TestHiveCatalogService catalogService = new TestHiveCatalogService.Builder().withConfig(configuration).build(); + + runner.addControllerService(CATALOG_SERVICE_NAME, catalogService); + runner.enableControllerService(catalogService); + + runner.setProperty(PutIceberg.CATALOG, CATALOG_SERVICE_NAME); + } + + private void initKerberosUserService() throws InitializationException { + KerberosUserService kerberosUserService = mock(KerberosUserService.class); + when(kerberosUserService.getIdentifier()).thenReturn(KERBEROS_USER_SERVICE_NAME); + + runner.addControllerService(KERBEROS_USER_SERVICE_NAME, kerberosUserService); + runner.enableControllerService(kerberosUserService); + + runner.setProperty(PutIceberg.KERBEROS_USER_SERVICE, KERBEROS_USER_SERVICE_NAME); + } + + @Test + public void testCustomValidateWithKerberosSecurityConfigAndWithoutKerberosUserService() throws InitializationException { + initRecordReader(); + + Configuration config = new Configuration(); + config.set("hadoop.security.authentication", "kerberos"); + initCatalogService(config); + + runner.setProperty(PutIceberg.CATALOG_NAMESPACE, CATALOG_NAMESPACE); + runner.setProperty(PutIceberg.TABLE_NAME, TABLE_NAME); + runner.assertNotValid(); + } + + @Test + public void testCustomValidateWithKerberosSecurityConfigAndKerberosUserService() throws InitializationException { + initRecordReader(); + + Configuration config = new Configuration(); + config.set("hadoop.security.authentication", "kerberos"); + initCatalogService(config); + + initKerberosUserService(); + + runner.setProperty(PutIceberg.CATALOG_NAMESPACE, CATALOG_NAMESPACE); + runner.setProperty(PutIceberg.TABLE_NAME, TABLE_NAME); + runner.assertValid(); + } + + @Test + public void testCustomValidateWithoutKerberosSecurityConfigAndKerberosUserService() throws InitializationException { + initRecordReader(); + + initCatalogService(new Configuration()); + + runner.setProperty(PutIceberg.CATALOG_NAMESPACE, CATALOG_NAMESPACE); + runner.setProperty(PutIceberg.TABLE_NAME, TABLE_NAME); + runner.assertValid(); + } + + @Test + public void testCustomValidateWithoutKerberosSecurityConfigAndWithKerberosUserService() throws InitializationException { + initRecordReader(); + + initCatalogService(new Configuration()); + + initKerberosUserService(); + + runner.setProperty(PutIceberg.CATALOG_NAMESPACE, CATALOG_NAMESPACE); + runner.setProperty(PutIceberg.TABLE_NAME, TABLE_NAME); + runner.assertValid(); + } Review Comment: This config (`hadoop.security.authentication` is not kerberos but having `KerberosUserService` configured on the processor) does not work so I think the processor should be invalid in this case. Even worse, the processor cannot recover after unsetting `KerberosUserService`. I think it is because the kerberos state is stored and stuck in hadoop's static context. Other hadoop related processors handle it via adding `@RequiresInstanceClassLoading`. I also tested it with a non-kerberized and a kerberized PutIceberg processor in the same flow (connecting to different Hive clusters, unsecured and secured, respectively) and the two processors interfere. After running the kerberized one, the non-kerberized cannot work. Could you please create a separate bug ticket for it and address the issue? -- 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]
