diff --git a/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingMigration.java b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingMigration.java index a8c0489ff..1a7b3022c 100644 --- a/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingMigration.java +++ b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingMigration.java @@ -39,10 +39,6 @@ public class SparkPipelineMessagingMigration extends AbstractPomMigration { private static final String SMALLRYE_REACTIVE_MESSAGING_GROUP_ID = "io.smallrye.reactive"; private static final String SMALLRYE_REACTIVE_MESSAGING_ARTIFACT_ID = "smallrye-reactive-messaging"; private static final String SMALLRYE_REACTIVE_MESSAGING_KAFKA_ARTIFACT_ID = "smallrye-reactive-messaging-kafka"; - private static final String SMALLRYE_REACTIVE_CDI_EVENTS_IMPORT = "import io.smallrye.reactive.messaging.kafka.KafkaCDIEvents;"; - private static final String SMALLRYE_REACTIVE_CDI_EVENTS_OBJECT = "KafkaCDIEvents.class"; - private static final String SMALLRYE_REACTIVE_KAFKA_CONNECTOR_IMPORT = "import io.smallrye.reactive.messaging.kafka.KafkaConnector;"; - private static final String SMALLRYE_REACTIVE_KAFKA_CONNECTOR_OBJECT = "KafkaConnector.class"; private static final String AISSEMBLE_GROUP_ID = "com.boozallen.aissemble"; private static final String AISSEMBLE_MESSAGING_KAFKA_ARTIFACT_ID = "extensions-messaging-kafka"; @@ -68,12 +64,8 @@ protected boolean shouldExecuteOnFile(File pomFile) { boolean addKafkaCdiContext = this.hasDependency(model, SMALLRYE_REACTIVE_MESSAGING_GROUP_ID, SMALLRYE_REACTIVE_MESSAGING_KAFKA_ARTIFACT_ID); if (addKafkaCdiContext) { - // Get the PipelinesCdiContext.java file - File pipelinesCdiContextFile = searchForFileInCdi(new File(pomFile.getParentFile(), "src/main/java"), "PipelinesCdiContext.java"); - - // Check if any of the CdiContainerFactory.java, PipelinesCdiContext.java, or pom.xml needs to be migrated - return shouldMigratePipelinesCdiContextFile(pipelinesCdiContextFile) || shouldMigratePomFile(model) || - shouldMigrateCdiContainerFactoryFile(cdiContainerFactoryFile, addKafkaCdiContext); + // Check if any of the CdiContainerFactory.java or pom.xml needs to be migrated + return shouldMigratePomFile(model) || shouldMigrateCdiContainerFactoryFile(cdiContainerFactoryFile, addKafkaCdiContext); } // Check if only the CdiContainerFactory.java needs to be migrated @@ -112,21 +104,9 @@ protected boolean performMigration(File pomFile) { logger.info("Skipping file as CDI messaging dependency is already present"); pomFileMigrationSuccess = true; } - - // Get the PipelinesCdiContext.java file - File pipelinesCdiContextFile = searchForFileInCdi(new File(pomFile.getParentFile(), "src/main/java"), "PipelinesCdiContext.java"); - - boolean pipelinesCdiContextFileMigrationSuccess = false; - if (shouldMigratePipelinesCdiContextFile(pipelinesCdiContextFile)) { - // Remove the old kafka beans from the file - pipelinesCdiContextFileMigrationSuccess = this.migratePipelinesCdiContextFile(pipelinesCdiContextFile); - } else { - logger.info("Skipping migration as Kafka beans/imports are already removed"); - pipelinesCdiContextFileMigrationSuccess = true; - } - // Return the results of all three file migrations (pom.xml, CdiContainerFactory.java, PipelinesCdiContext.java) - return pomFileMigrationSuccess && cdiContainerFactoryFileMigrationSuccess && pipelinesCdiContextFileMigrationSuccess; + // Return the results of both file migrations (pom.xml, CdiContainerFactory.java) + return pomFileMigrationSuccess && cdiContainerFactoryFileMigrationSuccess; } // Return the results of the only file migration (CdiContainerFactory.java) @@ -203,53 +183,6 @@ private boolean migrateCdiContainerFactoryFile(File file, boolean addKafkaCdiCon } } - /* - * Determine if the PipelinesCdiContext.java needs to be migrated - */ - private boolean shouldMigratePipelinesCdiContextFile(File file) { - if (file != null) { - try { - // Check if the unecessary imports still exist - boolean hasKafkaCdiEventsImport = Files.readString(file.toPath()).contains(SMALLRYE_REACTIVE_CDI_EVENTS_IMPORT); - boolean hasKafkaConnectorImport = Files.readString(file.toPath()).contains(SMALLRYE_REACTIVE_KAFKA_CONNECTOR_IMPORT); - - return hasKafkaCdiEventsImport || hasKafkaConnectorImport; - } catch (IOException e) { - throw new BatonException("Failed to read pipeline CDI context file: " + file.getAbsolutePath(), e); - } - } else { - logger.warn("Failed to find '{}' for migration", file); - return false; - } - } - - /* - * Migrate the PipelinesCdiContext.java to remove the Kafka beans and imports as they are no longer necessary - */ - private boolean migratePipelinesCdiContextFile(File file) { - logger.info("Removing unnecessary Kafka beans and imports from the file: {}", file.getAbsolutePath()); - try { - List newFileContents = new ArrayList<>(); - List originalFile = FileUtils.readAllFileLines(file); - - // Iterate through the file - for (String line : originalFile) { - - // Add the line if it's not one unecessary beans/imports - if (!line.contains(SMALLRYE_REACTIVE_CDI_EVENTS_IMPORT) && !line.contains(SMALLRYE_REACTIVE_CDI_EVENTS_OBJECT) && - !line.contains(SMALLRYE_REACTIVE_KAFKA_CONNECTOR_IMPORT) && !line.contains(SMALLRYE_REACTIVE_KAFKA_CONNECTOR_OBJECT)) { - newFileContents.add(line); - } - } - - FileUtils.writeFile(file, newFileContents); - return true; - } - catch (IOException e) { - throw new BatonException("Failed to remove Kafka beans/imports from the file: " + file.getAbsolutePath(), e); - } - } - /* * Determine if the pom.xml needs to be migrated */ diff --git a/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingMigrationSteps.java b/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingMigrationSteps.java index 85a6094d9..0163cbe0c 100644 --- a/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingMigrationSteps.java +++ b/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingMigrationSteps.java @@ -70,12 +70,6 @@ public void the_CDI_container_factory_is_updated_with_the_messaging_and_kafka_co assertTestFileMatchesExpectedFile("CDI container factory was not updated with the new kafka and messaging context objects"); } - @Then("the pipeline CDI context has the unecessary Kafka beans and imports removed") - public void the_pipeline_CDI_context_has_the_unecessary_Kafka_beans_and_imports_removed() { - this.testFile = getTestPom("smallrye-kafka/src/main/java/test/path/cdi/PipelinesCdiContext.java"); - assertTestFileMatchesExpectedFile("pipeline CDI context did not have the unecessary Kafka beans and imports removed"); - } - @Then("the CDI container factory is updated with the messaging context object") public void the_CDI_container_factory_is_updated_with_the_messaging_context_object() { this.testFile = getTestPom("smallrye-non-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java"); diff --git a/foundation/foundation-upgrade/src/test/resources/specifications/v1_10_0/spark-pipeline-messaging-migration.feature b/foundation/foundation-upgrade/src/test/resources/specifications/v1_10_0/spark-pipeline-messaging-migration.feature index b18dc3b11..5c90e8795 100644 --- a/foundation/foundation-upgrade/src/test/resources/specifications/v1_10_0/spark-pipeline-messaging-migration.feature +++ b/foundation/foundation-upgrade/src/test/resources/specifications/v1_10_0/spark-pipeline-messaging-migration.feature @@ -6,7 +6,6 @@ Feature: Migrate a Spark pipeline module with the new CDI classes to ensure mess When the Spark Pipeline Messaging migration executes Then the aissemble kafka messaging dependency is added to the POM And the CDI container factory is updated with the messaging and kafka context objects - And the pipeline CDI context has the unecessary Kafka beans and imports removed Scenario: A Spark pipeline module with a different smallrye dependency is migrated to include the messaging CDI context Given a POM with the "jar" packaging type diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-kafka/src/main/java/test/path/cdi/PipelinesCdiContext.java b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-kafka/src/main/java/test/path/cdi/PipelinesCdiContext.java deleted file mode 100644 index c7a62b80b..000000000 --- a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-kafka/src/main/java/test/path/cdi/PipelinesCdiContext.java +++ /dev/null @@ -1,58 +0,0 @@ -package test.path.cdi; - -/*- - * #%L - * aiSSEMBLE::Foundation::Upgrade - * %% - * Copyright (C) 2021 Booz Allen - * %% - * This software package is licensed under the Booz Allen Public License. All Rights Reserved. - * #L% - */ - -import java.util.List; - -import javax.enterprise.inject.spi.Extension; -import com.boozallen.aissemble.core.filestore.EnvironmentVariableFileStoreConfig; - -import com.boozallen.aissemble.core.metadata.producer.MetadataProducer; -import io.smallrye.reactive.messaging.kafka.KafkaCDIEvents; -import io.smallrye.reactive.messaging.kafka.KafkaConnector; - -/** - * Configures the CDI context for this application. - * - * Please **DO** modify with your customizations, as appropriate. - * - * Originally generated from: templates/pipeline.cdi.context.impl.java.vm - */ -public class PipelinesCdiContext extends PipelinesCdiContextBase { - - /** - * {@inheritDoc} - */ - @Override - public List> getCdiClasses() { - List> customBeans = super.getCdiClasses(); - - // Add any custom CDI classes here - customBeans.add(KafkaConnector.class); - customBeans.add(KafkaCDIEvents.class); - customBeans.add(MetadataProducer.class); - - return customBeans; - } - - /** - * {@inheritDoc} - */ - @Override - public List getExtensions() { - List extensions = super.getExtensions(); - - // Add any custom extensions to Weld here - - return extensions; - } - -} diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/src/main/java/test/path/cdi/PipelinesCdiContext.java b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/src/main/java/test/path/cdi/PipelinesCdiContext.java deleted file mode 100644 index 76fd86477..000000000 --- a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/src/main/java/test/path/cdi/PipelinesCdiContext.java +++ /dev/null @@ -1,54 +0,0 @@ -package test.path.cdi; - -/*- - * #%L - * aiSSEMBLE::Foundation::Upgrade - * %% - * Copyright (C) 2021 Booz Allen - * %% - * This software package is licensed under the Booz Allen Public License. All Rights Reserved. - * #L% - */ - -import java.util.List; - -import javax.enterprise.inject.spi.Extension; -import com.boozallen.aissemble.core.filestore.EnvironmentVariableFileStoreConfig; - -import com.boozallen.aissemble.core.metadata.producer.MetadataProducer; - -/** - * Configures the CDI context for this application. - * - * Please **DO** modify with your customizations, as appropriate. - * - * Originally generated from: templates/pipeline.cdi.context.impl.java.vm - */ -public class PipelinesCdiContext extends PipelinesCdiContextBase { - - /** - * {@inheritDoc} - */ - @Override - public List> getCdiClasses() { - List> customBeans = super.getCdiClasses(); - - // Add any custom CDI classes here - customBeans.add(MetadataProducer.class); - - return customBeans; - } - - /** - * {@inheritDoc} - */ - @Override - public List getExtensions() { - List extensions = super.getExtensions(); - - // Add any custom extensions to Weld here - - return extensions; - } - -}