From ad25749d2963a78c18355f360ce0242dbeebd198 Mon Sep 17 00:00:00 2001 From: Carter Cundiff Date: Thu, 10 Oct 2024 14:07:42 -0400 Subject: [PATCH] #391 Update pipeline step messaging to be compatible with Java 17 --- DRAFT_RELEASE_NOTES.md | 2 + build-parent/pom.xml | 2 +- .../context/KafkaConnectorCdiContext.java | 4 + .../extensions-messaging-quarkus/pom.xml | 9 +- .../templates/cdi.container.factory.java.vm | 6 +- .../pipeline.chart.pom.configuration.vm | 140 ++++++++-------- .../data-delivery-spark/pipeline.pom.xml.vm | 4 + .../pipeline.cdi.context.base.java.vm | 3 +- .../pipeline.cdi.context.impl.java.vm | 5 - .../migration/AbstractPomMigration.java | 43 +++++ ...kPipelineMessagingCdiFactoryMigration.java | 151 ++++++++++++++++++ .../SparkPipelineMessagingPomMigration.java | 87 ++++++++++ .../src/main/resources/migrations.json | 22 +++ ...lineMessagingCdiFactoryMigrationSteps.java | 99 ++++++++++++ ...arkPipelineMessagingPomMigrationSteps.java | 75 +++++++++ ...ne-messaging-cdi-factory-migration.feature | 36 +++++ ...k-pipeline-messaging-pom-migration.feature | 36 +++++ .../migration/non-jar/pom.xml | 70 ++++++++ .../migration/non-smallrye/pom.xml | 65 ++++++++ .../migration/smallrye-kafka/pom.xml | 70 ++++++++ .../test/path/cdi/CdiContainerFactory.java | 68 ++++++++ .../migration/smallrye-non-kafka/pom.xml | 70 ++++++++ .../test/path/cdi/CdiContainerFactory.java | 68 ++++++++ .../validation/smallrye-kafka/pom.xml | 74 +++++++++ .../test/path/cdi/CdiContainerFactory.java | 72 +++++++++ .../validation/smallrye-non-kafka/pom.xml | 70 ++++++++ .../test/path/cdi/CdiContainerFactory.java | 70 ++++++++ 27 files changed, 1337 insertions(+), 84 deletions(-) create mode 100644 foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/AbstractPomMigration.java create mode 100644 foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingCdiFactoryMigration.java create mode 100644 foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingPomMigration.java create mode 100644 foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingCdiFactoryMigrationSteps.java create mode 100644 foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingPomMigrationSteps.java create mode 100644 foundation/foundation-upgrade/src/test/resources/specifications/v1_10_0/spark-pipeline-messaging-cdi-factory-migration.feature create mode 100644 foundation/foundation-upgrade/src/test/resources/specifications/v1_10_0/spark-pipeline-messaging-pom-migration.feature create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/non-jar/pom.xml create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/non-smallrye/pom.xml create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-kafka/pom.xml create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-non-kafka/pom.xml create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-non-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/pom.xml create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-non-kafka/pom.xml create mode 100644 foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-non-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java diff --git a/DRAFT_RELEASE_NOTES.md b/DRAFT_RELEASE_NOTES.md index fbc61f0f9..f2e4093c9 100644 --- a/DRAFT_RELEASE_NOTES.md +++ b/DRAFT_RELEASE_NOTES.md @@ -32,6 +32,8 @@ To reduce burden of upgrading aiSSEMBLE, the Baton project is used to automate t | upgrade-v2-chart-files-aissemble-version-migration | Updates the Helm chart dependencies within your project's deployment resources (`-deploy/src/main/resources/apps/`) to use the latest version of the aiSSEMBLE | | upgrade-v1-chart-files-aissemble-version-migration | Updates the docker image tags within your project's deployment resources (`-deploy/src/main/resources/apps/`) to use the latest version of the aiSSEMBLE | | spark-version-upgrade-migration | Updates the Spark Application executor failure parameters to their new key name to ensure compatibility with spark `3.5` | +| spark-pipeline-messaging-pom-migration | Updates a Spark pipeline module `pom.xml` with the new CDI classes dependency to ensure messaging compatibility with Java 17 | +| spark-pipeline-messaging-cdi-factory-migration | Updates a Spark pipeline module `CdiContainerFactory.java` with the new CDI classes to ensure messaging compatibility with Java 17 | | it-infrastructure-java-upgrade-migration | Updates the Java docker image version in the integration test docker module to JDK 17 | | log4j-maven-shade-plugin-migration | Updates the Maven Shade Plugin with the new Log4j dependency information | diff --git a/build-parent/pom.xml b/build-parent/pom.xml index 7d713929e..4f2bcd19e 100644 --- a/build-parent/pom.xml +++ b/build-parent/pom.xml @@ -55,7 +55,7 @@ 2.1.1 42.5.1 4.7.7.Final - 4.4.6 + 4.5.9 ^1.26.18 >=0.95.0 >=0.18.0 diff --git a/extensions/extensions-messaging/extensions-messaging-kafka/src/main/java/com/boozallen/aissemble/kafka/context/KafkaConnectorCdiContext.java b/extensions/extensions-messaging/extensions-messaging-kafka/src/main/java/com/boozallen/aissemble/kafka/context/KafkaConnectorCdiContext.java index 89816baf9..60c956b3a 100644 --- a/extensions/extensions-messaging/extensions-messaging-kafka/src/main/java/com/boozallen/aissemble/kafka/context/KafkaConnectorCdiContext.java +++ b/extensions/extensions-messaging/extensions-messaging-kafka/src/main/java/com/boozallen/aissemble/kafka/context/KafkaConnectorCdiContext.java @@ -19,6 +19,8 @@ import io.smallrye.reactive.messaging.kafka.KafkaCDIEvents; import io.smallrye.reactive.messaging.kafka.KafkaConnector; +import io.smallrye.reactive.messaging.kafka.commit.KafkaThrottledLatestProcessedCommit; +import io.smallrye.reactive.messaging.kafka.fault.KafkaFailStop; /** * {@link KafkaConnectorCdiContext} contains the classes needed by CDI when @@ -34,6 +36,8 @@ public List> getCdiClasses() { List> classes = new ArrayList<>(); classes.add(KafkaConnector.class); classes.add(KafkaCDIEvents.class); + classes.add(KafkaThrottledLatestProcessedCommit.Factory.class); + classes.add(KafkaFailStop.Factory.class); return classes; } diff --git a/extensions/extensions-messaging/extensions-messaging-quarkus/pom.xml b/extensions/extensions-messaging/extensions-messaging-quarkus/pom.xml index f7888f4a5..7969a0356 100644 --- a/extensions/extensions-messaging/extensions-messaging-quarkus/pom.xml +++ b/extensions/extensions-messaging/extensions-messaging-quarkus/pom.xml @@ -19,6 +19,11 @@ foundation-messaging-java ${project.version} + + jakarta.enterprise + jakarta.enterprise.cdi-api + ${version.jakarta.cdi} + io.quarkus quarkus-rest-client-jackson @@ -37,10 +42,6 @@ - - io.quarkus - quarkus-resteasy - io.quarkus quarkus-arc diff --git a/foundation/foundation-mda/src/main/resources/templates/cdi.container.factory.java.vm b/foundation/foundation-mda/src/main/resources/templates/cdi.container.factory.java.vm index c5e83d53a..b02a31247 100644 --- a/foundation/foundation-mda/src/main/resources/templates/cdi.container.factory.java.vm +++ b/foundation/foundation-mda/src/main/resources/templates/cdi.container.factory.java.vm @@ -9,6 +9,7 @@ import org.jboss.weld.environment.se.WeldContainer; import com.boozallen.aissemble.core.cdi.CdiContainer; import com.boozallen.aissemble.core.cdi.CdiContext; import com.boozallen.aissemble.messaging.core.cdi.MessagingCdiContext; +import com.boozallen.aissemble.kafka.context.KafkaConnectorCdiContext; #if ($pipeline.isAlertingSupportNeeded()) import com.boozallen.aissemble.alerting.core.cdi.AlertingCdiContext; #end @@ -58,9 +59,10 @@ public final class CdiContainerFactory { protected static List getContexts() { List contexts = new ArrayList<>(); contexts.add(new PipelinesCdiContext()); - ## TODO: would be nice to only include if we need messaging, but right now we assume messaging everywhere +## TODO: would be nice to only include if we need messaging, but right now we assume kafka messaging everywhere contexts.add(new MessagingCdiContext()); - ## TODO: pull generated functionality into an overwritable template so we can adapt to MDA model changes + contexts.add(new KafkaConnectorCdiContext()); +## TODO: pull generated functionality into an overwritable template so we can adapt to MDA model changes #if ($pipeline.isAlertingSupportNeeded()) contexts.add(new AlertingCdiContext()); #end diff --git a/foundation/foundation-mda/src/main/resources/templates/data-delivery-common/pipeline.chart.pom.configuration.vm b/foundation/foundation-mda/src/main/resources/templates/data-delivery-common/pipeline.chart.pom.configuration.vm index a0f5f216c..da2c5fa8f 100644 --- a/foundation/foundation-mda/src/main/resources/templates/data-delivery-common/pipeline.chart.pom.configuration.vm +++ b/foundation/foundation-mda/src/main/resources/templates/data-delivery-common/pipeline.chart.pom.configuration.vm @@ -1,70 +1,70 @@ - - org.codehaus.mojo - exec-maven-plugin - 3.1.0 - - - main-chart - compile - - exec - - - helm - - template - ${aissemble.helm.repo.protocol}://${aissemble.helm.repo}/aissemble-spark-application-chart - --version - ${version.aissemble} - --values - ${mainValuesPath}/${moduleArtifactId}-base-values.yaml,${mainValuesPath}/${moduleArtifactId}-dev-values.yaml - -s - templates/deployment.yaml - - target/apps/${moduleArtifactId}-dev-chart.yaml - - - - test-chart - compile - - exec - - - helm - - template - ${aissemble.helm.repo.protocol}://${aissemble.helm.repo}/aissemble-spark-application-chart - --version - ${version.aissemble} - --values - ${mainValuesPath}/${moduleArtifactId}-base-values.yaml,${testValuesPath}/${moduleArtifactId}-test-values.yaml - -s - templates/deployment.yaml - - target/apps/${moduleArtifactId}-test-chart.yaml - - - - ci-chart - compile - - exec - - - helm - - template - ${aissemble.helm.repo.protocol}://${aissemble.helm.repo}/aissemble-spark-application-chart - --version - ${version.aissemble} - --values - ${mainValuesPath}/${moduleArtifactId}-base-values.yaml,${mainValuesPath}/${moduleArtifactId}-ci-values.yaml - -s - templates/deployment.yaml - - target/apps/${moduleArtifactId}-ci-chart.yaml - - - - \ No newline at end of file + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + + main-chart + compile + + exec + + + helm + + template + ${aissemble.helm.repo.protocol}://${aissemble.helm.repo}/aissemble-spark-application-chart + --version + ${version.aissemble} + --values + ${mainValuesPath}/${moduleArtifactId}-base-values.yaml,${mainValuesPath}/${moduleArtifactId}-dev-values.yaml + -s + templates/deployment.yaml + + target/apps/${moduleArtifactId}-dev-chart.yaml + + + + test-chart + compile + + exec + + + helm + + template + ${aissemble.helm.repo.protocol}://${aissemble.helm.repo}/aissemble-spark-application-chart + --version + ${version.aissemble} + --values + ${mainValuesPath}/${moduleArtifactId}-base-values.yaml,${testValuesPath}/${moduleArtifactId}-test-values.yaml + -s + templates/deployment.yaml + + target/apps/${moduleArtifactId}-test-chart.yaml + + + + ci-chart + compile + + exec + + + helm + + template + ${aissemble.helm.repo.protocol}://${aissemble.helm.repo}/aissemble-spark-application-chart + --version + ${version.aissemble} + --values + ${mainValuesPath}/${moduleArtifactId}-base-values.yaml,${mainValuesPath}/${moduleArtifactId}-ci-values.yaml + -s + templates/deployment.yaml + + target/apps/${moduleArtifactId}-ci-chart.yaml + + + + diff --git a/foundation/foundation-mda/src/main/resources/templates/data-delivery-spark/pipeline.pom.xml.vm b/foundation/foundation-mda/src/main/resources/templates/data-delivery-spark/pipeline.pom.xml.vm index b340810e1..84cd2c4c0 100644 --- a/foundation/foundation-mda/src/main/resources/templates/data-delivery-spark/pipeline.pom.xml.vm +++ b/foundation/foundation-mda/src/main/resources/templates/data-delivery-spark/pipeline.pom.xml.vm @@ -128,6 +128,10 @@ com.boozallen.aissemble foundation-metadata-producer + + com.boozallen.aissemble + extensions-messaging-kafka + com.boozallen.aissemble extensions-data-delivery-spark diff --git a/foundation/foundation-mda/src/main/resources/templates/pipeline.cdi.context.base.java.vm b/foundation/foundation-mda/src/main/resources/templates/pipeline.cdi.context.base.java.vm index ee5056758..1e5dc0f23 100644 --- a/foundation/foundation-mda/src/main/resources/templates/pipeline.cdi.context.base.java.vm +++ b/foundation/foundation-mda/src/main/resources/templates/pipeline.cdi.context.base.java.vm @@ -11,9 +11,8 @@ import ${basePackage}.${step.capitalizedName}; #foreach ($store in $pipeline.fileStores) import ${basePackage}.filestore.${store.fullName}; #end -import com.boozallen.aissemble.core.cdi.CdiContext; -import io.smallrye.config.inject.ConfigExtension; +import com.boozallen.aissemble.core.cdi.CdiContext; import com.boozallen.aiops.data.delivery.messaging.PipelineMessagingConfig; diff --git a/foundation/foundation-mda/src/main/resources/templates/pipeline.cdi.context.impl.java.vm b/foundation/foundation-mda/src/main/resources/templates/pipeline.cdi.context.impl.java.vm index 28309ae38..49dab3091 100644 --- a/foundation/foundation-mda/src/main/resources/templates/pipeline.cdi.context.impl.java.vm +++ b/foundation/foundation-mda/src/main/resources/templates/pipeline.cdi.context.impl.java.vm @@ -3,11 +3,8 @@ package ${basePackage}.cdi; import java.util.List; import jakarta.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. @@ -26,8 +23,6 @@ public class PipelinesCdiContext extends PipelinesCdiContextBase { List> customBeans = super.getCdiClasses(); // Add any custom CDI classes here - customBeans.add(KafkaConnector.class); - customBeans.add(KafkaCDIEvents.class); customBeans.add(MetadataProducer.class); return customBeans; diff --git a/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/AbstractPomMigration.java b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/AbstractPomMigration.java new file mode 100644 index 000000000..b07f5f0d4 --- /dev/null +++ b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/AbstractPomMigration.java @@ -0,0 +1,43 @@ +package com.boozallen.aissemble.upgrade.migration; +/*- + * #%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 org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.technologybrewery.baton.BatonException; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.stream.Stream; + +public abstract class AbstractPomMigration extends AbstractAissembleMigration { + protected static final Logger logger = LoggerFactory.getLogger(AbstractPomMigration.class); + + public static final String POM = "pom"; + public static final String GUARANTEED_TAG = ""; + + protected String indent; + + protected void detectAndSetIndent(File file) { + try (Stream lines = Files.lines(file.toPath())) { + indent = lines.filter(line -> line.contains(GUARANTEED_TAG)) + .findFirst() + .map(artifact -> artifact.substring(0, artifact.indexOf(GUARANTEED_TAG))) + .orElse(null); + if (StringUtils.isEmpty(indent)) { + logger.info("Failed to detect indent for POM. Using default. {}", file); + indent = " "; + } + } catch (IOException e) { + throw new BatonException("Failed to get indent from POM:" + file, e); + } + } +} \ No newline at end of file diff --git a/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingCdiFactoryMigration.java b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingCdiFactoryMigration.java new file mode 100644 index 000000000..ab07118b6 --- /dev/null +++ b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingCdiFactoryMigration.java @@ -0,0 +1,151 @@ +package com.boozallen.aissemble.upgrade.migration.v1_10_0; + +/*- + * #%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.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.model.Model; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; +import org.technologybrewery.baton.BatonException; +import org.technologybrewery.baton.util.FileUtils; + +import com.boozallen.aissemble.upgrade.migration.AbstractPomMigration; + + +/** + * Updates a Spark pipeline module CdiContainerFactory.java with the new CDI classes to ensure messaging compatibility with Java 17 + */ +public class SparkPipelineMessagingCdiFactoryMigration extends AbstractPomMigration { + private static final Logger logger = LoggerFactory.getLogger(SparkPipelineMessagingCdiFactoryMigration.class); + + 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 AISSEMBLE_CDI_CONTAINER_IMPORT = "import com.boozallen.aissemble.core.cdi.CdiContainer;"; + private static final String AISSEMBLE_MESSAGING_CDI_IMPORT = "import com.boozallen.aissemble.messaging.core.cdi.MessagingCdiContext;"; + private static final String AISSEMBLE_MESSAGING_CDI_OBJECT = "new MessagingCdiContext()"; + private static final String AISSEMBLE_KAFKA_MESSAGING_CDI_IMPORT = "import com.boozallen.aissemble.kafka.context.KafkaConnectorCdiContext;"; + private static final String AISSEMBLE_KAFKA_MESSAGING_CDI_OBJECT = "new KafkaConnectorCdiContext()"; + private static final String AISSEMBLE_PIPELINE_CDI_OBJECT = "new PipelinesCdiContext()"; + + @Override + protected boolean shouldExecuteOnFile(File cdiContainerFactoryFile) { + // Check if the pipeline pom contains any smallrye-reactive-messaging dependencies + Model model = this.getMavenProject().getModel(); + + if (this.hasDependency(model, SMALLRYE_REACTIVE_MESSAGING_GROUP_ID, SMALLRYE_REACTIVE_MESSAGING_ARTIFACT_ID) + && model.getPackaging().equals("jar")) { + + // Check if the pipeline pom contains the smallrye-reactive-messaging-kafka dependency + boolean addKafkaCdiContext = this.hasDependency(model, SMALLRYE_REACTIVE_MESSAGING_GROUP_ID, SMALLRYE_REACTIVE_MESSAGING_KAFKA_ARTIFACT_ID); + + // Check if only the CdiContainerFactory.java needs to be migrated + return shouldMigrateCdiContainerFactoryFile(cdiContainerFactoryFile, addKafkaCdiContext); + } else { + return false; + } + } + + @Override + protected boolean performMigration(File cdiContainerFactoryFile) { + Model model = this.getMavenProject().getModel(); + + // Check if the pipeline pom contains the smallrye-reactive-messaging-kafka dependency + boolean addKafkaCdiContext = this.hasDependency(model, SMALLRYE_REACTIVE_MESSAGING_GROUP_ID, SMALLRYE_REACTIVE_MESSAGING_KAFKA_ARTIFACT_ID); + + // Update the file with the new import(s) and CDI context object(s) + return this.migrateCdiContainerFactoryFile(cdiContainerFactoryFile, addKafkaCdiContext); + } + + /* + * Determine if the CdiContainerFactory.java needs to be migrated + */ + private boolean shouldMigrateCdiContainerFactoryFile(File file, boolean addKafkaCdiContext) { + try { + // Check if the new imports already exist + boolean hasMessagingCdiImport = Files.readString(file.toPath()).contains(AISSEMBLE_MESSAGING_CDI_IMPORT); + boolean hasKafkaCdiImport = Files.readString(file.toPath()).contains(AISSEMBLE_KAFKA_MESSAGING_CDI_IMPORT); + + return !hasMessagingCdiImport || (!hasKafkaCdiImport && addKafkaCdiContext); + } catch (IOException e) { + throw new BatonException("Failed to read CDI container file: " + file.getAbsolutePath(), e); + } + } + + /* + * Migrate the CdiContainerFactory.java to add the new context object(s) and respective import(s) + */ + private boolean migrateCdiContainerFactoryFile(File file, boolean addKafkaCdiContext) { + logger.info("Migrating file with new CDI context object(s): {}", file.getAbsolutePath()); + try { + List newFileContents = new ArrayList<>(); + List originalFile = FileUtils.readAllFileLines(file); + + boolean cdiContextAdded = false; + boolean cdiImportAdded = false; + boolean hasMessagingCdiImport = Files.readString(file.toPath()).contains(AISSEMBLE_MESSAGING_CDI_IMPORT); + boolean hasKafkaCdiImport = Files.readString(file.toPath()).contains(AISSEMBLE_KAFKA_MESSAGING_CDI_IMPORT); + + // Iterate through the file + for (String line : originalFile) { + + // Prepend the necessary imports to the CdiContainer import - should always be present + if (line.equals(AISSEMBLE_CDI_CONTAINER_IMPORT)) { + if (!hasMessagingCdiImport) { + newFileContents.add(AISSEMBLE_MESSAGING_CDI_IMPORT); + } + + if (!hasKafkaCdiImport && addKafkaCdiContext) { + newFileContents.add(AISSEMBLE_KAFKA_MESSAGING_CDI_IMPORT); + } + cdiImportAdded = true; + } + // Append the necessary CDI Java objects to the getContexts() method + else if (line.contains(".add(" + AISSEMBLE_PIPELINE_CDI_OBJECT + ");")) { + if (!hasMessagingCdiImport) { + newFileContents.add(line.replace(AISSEMBLE_PIPELINE_CDI_OBJECT, AISSEMBLE_MESSAGING_CDI_OBJECT)); + } + + if (!hasKafkaCdiImport && addKafkaCdiContext) { + newFileContents.add(line.replace(AISSEMBLE_PIPELINE_CDI_OBJECT, AISSEMBLE_KAFKA_MESSAGING_CDI_OBJECT)); + } + cdiContextAdded = true; + } + + newFileContents.add(line); + } + + FileUtils.writeFile(file, newFileContents); + return cdiImportAdded && cdiContextAdded; + } catch (IOException e) { + throw new BatonException("Failed to update the file with the new CDI context object(s): " + file.getAbsolutePath(), e); + } + } + + + /** + * Checks if a given pom model contains any dependencies with a provided group ID and artifact ID + */ + private boolean hasDependency(Model model, String groupId, String artifactId) { + return model.getDependencies() + .stream() + .anyMatch(dependency -> + dependency.getGroupId().equals(groupId) && + dependency.getArtifactId().contains(artifactId) + ); + } +} diff --git a/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingPomMigration.java b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingPomMigration.java new file mode 100644 index 000000000..2113c1cc1 --- /dev/null +++ b/foundation/foundation-upgrade/src/main/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingPomMigration.java @@ -0,0 +1,87 @@ +package com.boozallen.aissemble.upgrade.migration.v1_10_0; + +/*- + * #%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.io.File; + +import org.apache.maven.model.Model; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; +import org.technologybrewery.baton.util.pom.PomHelper; +import org.technologybrewery.baton.util.pom.PomModifications; +import org.technologybrewery.baton.util.pom.PomModifications.Insertion; + +import com.boozallen.aissemble.upgrade.migration.AbstractPomMigration; + +import static org.technologybrewery.baton.util.pom.LocationAwareMavenReader.END; +import static org.apache.commons.lang3.StringUtils.repeat; + +/** + * Updates a Spark pipeline module pom.xml with the new CDI classes dependency to ensure messaging compatibility with Java 17 + */ +public class SparkPipelineMessagingPomMigration extends AbstractPomMigration { + private static final Logger logger = LoggerFactory.getLogger(SparkPipelineMessagingPomMigration.class); + + 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 AISSEMBLE_GROUP_ID = "com.boozallen.aissemble"; + private static final String AISSEMBLE_MESSAGING_KAFKA_ARTIFACT_ID = "extensions-messaging-kafka"; + + @Override + protected boolean shouldExecuteOnFile(File pomFile) { + Model model = PomHelper.getLocationAnnotatedModel(pomFile); + + // Check if the pipeline pom is type jar + if (model.getPackaging().equals("jar")) { + + // Check if the pipeline pom contains the smallrye-reactive-messaging-kafka dependency and + // doesn't have the extensions-messaging-kafka dependency + return this.hasDependency(model, SMALLRYE_REACTIVE_MESSAGING_GROUP_ID, SMALLRYE_REACTIVE_MESSAGING_KAFKA_ARTIFACT_ID) + && !this.hasDependency(model, AISSEMBLE_GROUP_ID, AISSEMBLE_MESSAGING_KAFKA_ARTIFACT_ID); + + } else { + return false; + } + } + + @Override + protected boolean performMigration(File pomFile) { + logger.info("Migrating file with new CDI messaging dependency: {}", pomFile.getAbsolutePath()); + Model model = PomHelper.getLocationAnnotatedModel(pomFile); + + detectAndSetIndent(pomFile); + PomModifications modifications = new PomModifications(); + modifications.add(new Insertion(model.getLocation("dependencies" + END), 1, this::getDependencyContent)); + + return PomHelper.writeModifications(pomFile, modifications.finalizeMods()); + } + + /** + * Checks if a given pom model contains any dependencies with a provided group ID and artifact ID + */ + private boolean hasDependency(Model model, String groupId, String artifactId) { + return model.getDependencies() + .stream() + .anyMatch(dependency -> + dependency.getGroupId().equals(groupId) && + dependency.getArtifactId().contains(artifactId) + ); + } + + private String getDependencyContent(String ignore) { + return repeat(indent, 2) + "\n" + + repeat(indent, 3) + "" + AISSEMBLE_GROUP_ID + "\n" + + repeat(indent, 3) + "" + AISSEMBLE_MESSAGING_KAFKA_ARTIFACT_ID + "\n" + + repeat(indent, 2) + "\n"; + } +} diff --git a/foundation/foundation-upgrade/src/main/resources/migrations.json b/foundation/foundation-upgrade/src/main/resources/migrations.json index 8d976b734..f08acdb6c 100644 --- a/foundation/foundation-upgrade/src/main/resources/migrations.json +++ b/foundation/foundation-upgrade/src/main/resources/migrations.json @@ -15,6 +15,28 @@ } ] }, + { + "name": "spark-pipeline-messaging-pom-migration", + "implementation": "com.boozallen.aissemble.upgrade.migration.v1_10_0.SparkPipelineMessagingPomMigration", + "fileSets": [ + { + "includes": [ + "*-pipelines/*/pom.xml" + ] + } + ] + }, + { + "name": "spark-pipeline-messaging-cdi-factory-migration", + "implementation": "com.boozallen.aissemble.upgrade.migration.v1_10_0.SparkPipelineMessagingCdiFactoryMigration", + "fileSets": [ + { + "includes": [ + "src/main/java/**/cdi/CdiContainerFactory.java" + ] + } + ] + }, { "name": "it-infrastructure-java-upgrade-migration", "implementation": "com.boozallen.aissemble.upgrade.migration.v1_10_0.ItInfrastructureJavaUpgradeMigration", diff --git a/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingCdiFactoryMigrationSteps.java b/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingCdiFactoryMigrationSteps.java new file mode 100644 index 000000000..1647b055c --- /dev/null +++ b/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingCdiFactoryMigrationSteps.java @@ -0,0 +1,99 @@ +package com.boozallen.aissemble.upgrade.migration.v1_10_0; + +/*- + * #%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.io.File; +import java.util.Arrays; + +import org.apache.maven.model.Dependency; +import org.apache.maven.project.MavenProject; + +import com.boozallen.aissemble.upgrade.migration.AbstractMigrationTest; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class SparkPipelineMessagingCdiFactoryMigrationSteps extends AbstractMigrationTest { + private static String TEST_DIR = "v1_10_0/SparkPipelineMessagingMigration/migration/"; + private String dependency; + private SparkPipelineMessagingCdiFactoryMigration migration = new SparkPipelineMessagingCdiFactoryMigration();; + private MavenProject mavenProject = new MavenProject(); + + @Given("a maven project with the {string} packaging type") + public void a_maven_project_with_the_packaging_type(String packaging) { + this.mavenProject.setPackaging(packaging); + } + + @Given("a maven project {string} dependency") + public void a_maven_project_dependency(String dependency) { + this.dependency = dependency; + if (dependency.equals("smallrye-reactive-messaging-kafka")) { + Dependency kafkaDependency = new Dependency(); + kafkaDependency.setGroupId("io.smallrye.reactive"); + kafkaDependency.setArtifactId(dependency); + + this.mavenProject.setDependencies(Arrays.asList(kafkaDependency)); + this.testFile = getTestFileInDir("smallrye-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java"); + } else { + Dependency otherDependency = new Dependency(); + otherDependency.setGroupId("io.smallrye.reactive"); + otherDependency.setArtifactId(dependency); + + this.mavenProject.setDependencies(Arrays.asList(otherDependency)); + this.testFile = getTestFileInDir("smallrye-non-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java"); + } + } + + @Given("the pipeline module has already been migrated") + public void the_pipeline_module_has_already_been_migrated() { + if (dependency.equals("smallrye-reactive-messaging-kafka")) { + this.testFile = getTestFile("v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java"); + } else { + this.testFile = getTestFile("v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-non-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java"); + } + } + + @Given("no maven project smallrye dependencies") + public void no_maven_project_smallrye_dependencies() { + Dependency otherDependency = new Dependency(); + otherDependency.setGroupId("io.test"); + otherDependency.setArtifactId("test.dependency"); + this.mavenProject.setDependencies(Arrays.asList(otherDependency)); + } + + @When("the Spark Pipeline Messaging migration executes") + public void the_spark_pipeline_messaging_migration_executes() { + this.migration.setMavenProject(this.mavenProject); + performMigration(this.migration); + } + + @Then("the CDI container factory is updated with the messaging and kafka context objects") + public void the_CDI_container_factory_is_updated_with_the_messaging_and_kafka_context_objects() { + assertMigrationSuccess(); + assertTestFileMatchesExpectedFile("CDI container factory was not updated with the new kafka and messaging context objects"); + } + + @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() { + assertMigrationSuccess(); + assertTestFileMatchesExpectedFile("CDI container factory was not updated with the new messaging context objects"); + } + + @Then("the Spark Pipeline Messaging migration is skipped") + public void the_spark_pipeline_messaging_migration_is_skipped() { + assertMigrationSkipped(); + } + + protected File getTestFileInDir(String Filename) { + return getTestFile(TEST_DIR + Filename); + } +} diff --git a/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingPomMigrationSteps.java b/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingPomMigrationSteps.java new file mode 100644 index 000000000..a7aea5ad6 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/java/com/boozallen/aissemble/upgrade/migration/v1_10_0/SparkPipelineMessagingPomMigrationSteps.java @@ -0,0 +1,75 @@ +package com.boozallen.aissemble.upgrade.migration.v1_10_0; + +/*- + * #%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.io.File; + +import com.boozallen.aissemble.upgrade.migration.AbstractMigrationTest; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class SparkPipelineMessagingPomMigrationSteps extends AbstractMigrationTest { + private static String TEST_DIR = "v1_10_0/SparkPipelineMessagingMigration/migration/"; + private String dependency; + + @Given("a POM with the {string} packaging type") + public void a_pom_with_the_packaging_type(String packaging) { + if (!packaging.equals("jar")) { + this.testFile = getTestPom("non-jar/pom.xml"); + } + } + + @Given("a {string} dependency") + public void a_dependency(String dependency) { + this.dependency = dependency; + if (dependency.equals("smallrye-reactive-messaging-kafka")) { + this.testFile = getTestPom("smallrye-kafka/pom.xml"); + } else { + this.testFile = getTestPom("smallrye-non-kafka/pom.xml"); + } + } + + @Given("the pipeline module pom has already been migrated") + public void the_pipeline_module_pom_has_already_been_migrated() { + if (dependency.equals("smallrye-reactive-messaging-kafka")) { + this.testFile = getTestFile("v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/pom.xml"); + } else { + this.testFile = getTestFile("v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-non-kafka/pom.xml"); + } + } + + @Given("no smallrye dependencies") + public void no_smallrye_dependencies() { + this.testFile = getTestPom("non-smallrye/pom.xml"); + } + + @When("the Spark Pipeline Messaging Pom migration executes") + public void the_spark_pipeline_messaging_pom_migration_executes() { + performMigration(new SparkPipelineMessagingPomMigration()); + } + + @Then("the aissemble kafka messaging dependency is added to the POM") + public void the_aissemble_kafka_messaging_dependency_is_added_to_the_pom() { + assertMigrationSuccess(); + assertTestFileMatchesExpectedFile("aissemble kafka messaging dependency was not added to the POM"); + } + + @Then("the Spark Pipeline Messaging Pom migration is skipped") + public void the_spark_pipeline_messaging_pom_migration_is_skipped() { + assertMigrationSkipped(); + } + + protected File getTestPom(String pomName) { + return getTestFile(TEST_DIR + pomName); + } +} diff --git a/foundation/foundation-upgrade/src/test/resources/specifications/v1_10_0/spark-pipeline-messaging-cdi-factory-migration.feature b/foundation/foundation-upgrade/src/test/resources/specifications/v1_10_0/spark-pipeline-messaging-cdi-factory-migration.feature new file mode 100644 index 000000000..ce39bb575 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/specifications/v1_10_0/spark-pipeline-messaging-cdi-factory-migration.feature @@ -0,0 +1,36 @@ +Feature: Migrate a Spark pipeline module CDI factoru with the new CDI classes to ensure messaging compatibility with Java 17 + + Scenario: A Spark pipeline module with smallrye kafka is migrated to include the messaging CDI context and kafka CDI context + Given a maven project with the "jar" packaging type + And a maven project "smallrye-reactive-messaging-kafka" dependency + When the Spark Pipeline Messaging migration executes + Then the CDI container factory is updated with the messaging and kafka context objects + + 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 + And a maven project "smallrye-reactive-messaging-rabbitmq" dependency + When the Spark Pipeline Messaging migration executes + Then the CDI container factory is updated with the messaging context object + + Scenario Outline: A migrated Spark pipeline module will not migrate again + Given a POM with the "jar" packaging type + And a maven project "" dependency + And the pipeline module has already been migrated + When the Spark Pipeline Messaging migration executes + Then the Spark Pipeline Messaging migration is skipped + + Examples: + | dependency | + | smallrye-reactive-messaging-kafka | + | smallrye-reactive-messaging-rabbitmq | + + Scenario: A Spark pipeline module without a smallrye dependency is not migrated + Given a POM with the "jar" packaging type + And no maven project smallrye dependencies + When the Spark Pipeline Messaging migration executes + Then the Spark Pipeline Messaging migration is skipped + + Scenario: A Pyspark pipeline module is not migrated + Given a POM with the "habushu" packaging type + When the Spark Pipeline Messaging migration executes + Then the Spark Pipeline Messaging migration is skipped diff --git a/foundation/foundation-upgrade/src/test/resources/specifications/v1_10_0/spark-pipeline-messaging-pom-migration.feature b/foundation/foundation-upgrade/src/test/resources/specifications/v1_10_0/spark-pipeline-messaging-pom-migration.feature new file mode 100644 index 000000000..2ff5d1dc2 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/specifications/v1_10_0/spark-pipeline-messaging-pom-migration.feature @@ -0,0 +1,36 @@ +Feature: Migrate a Spark pipeline module pom.xml with the new CDI classes dependency to ensure messaging compatibility with Java 17 + + Scenario: A Spark pipeline module with smallrye kafka is migrated to include the aissemble kafka messaging dependency + Given a POM with the "jar" packaging type + And a "smallrye-reactive-messaging-kafka" dependency + When the Spark Pipeline Messaging Pom migration executes + Then the aissemble kafka messaging dependency is added to the POM + + 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 + And a "smallrye-reactive-messaging-rabbitmq" dependency + When the Spark Pipeline Messaging Pom migration executes + Then the Spark Pipeline Messaging Pom migration is skipped + + Scenario Outline: A migrated Spark pipeline module will not migrate again + Given a POM with the "jar" packaging type + And a "" dependency + And the pipeline module pom has already been migrated + When the Spark Pipeline Messaging Pom migration executes + Then the Spark Pipeline Messaging Pom migration is skipped + + Examples: + | dependency | + | smallrye-reactive-messaging-kafka | + | smallrye-reactive-messaging-rabbitmq | + + Scenario: A Spark pipeline module without a smallrye dependency is not migrated + Given a POM with the "jar" packaging type + And no smallrye dependencies + When the Spark Pipeline Messaging Pom migration executes + Then the Spark Pipeline Messaging Pom migration is skipped + + Scenario: A Pyspark pipeline module is not migrated + Given a POM with the "habushu" packaging type + When the Spark Pipeline Messaging Pom migration executes + Then the Spark Pipeline Messaging Pom migration is skipped diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/non-jar/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/non-jar/pom.xml new file mode 100644 index 000000000..9cc04bc5f --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/non-jar/pom.xml @@ -0,0 +1,70 @@ + + + + + 4.0.0 + + + com.test + test-pipelines + 1.0.0-SNAPSHOT + + + spark-pipeline-messaging + habushu + + test::Pipelines::Spark Pipeline Messaging + ${pipeline.description} + + + + + net.masterthought + maven-cucumber-reporting + + + + + + + org.technologybrewery.krausening + krausening + + + com.boozallen.aissemble + foundation-core-java + + + com.boozallen.aissemble + foundation-metadata-producer + + + com.boozallen.aissemble + extensions-data-delivery-spark + + + com.boozallen.aissemble + extensions-data-delivery-spark + tests + test-jar + test + ${version.aissemble} + + + io.smallrye.reactive + smallrye-reactive-messaging-kafka + ${version.smallrye.reactive.messaging} + + + + diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/non-smallrye/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/non-smallrye/pom.xml new file mode 100644 index 000000000..11e0b3890 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/non-smallrye/pom.xml @@ -0,0 +1,65 @@ + + + + + 4.0.0 + + + com.test + test-pipelines + 1.0.0-SNAPSHOT + + + spark-pipeline-messaging + jar + + test::Pipelines::Spark Pipeline Messaging + ${pipeline.description} + + + + + net.masterthought + maven-cucumber-reporting + + + + + + + org.technologybrewery.krausening + krausening + + + com.boozallen.aissemble + foundation-core-java + + + com.boozallen.aissemble + foundation-metadata-producer + + + com.boozallen.aissemble + extensions-data-delivery-spark + + + com.boozallen.aissemble + extensions-data-delivery-spark + tests + test-jar + test + ${version.aissemble} + + + + diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-kafka/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-kafka/pom.xml new file mode 100644 index 000000000..4e891ce8c --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-kafka/pom.xml @@ -0,0 +1,70 @@ + + + + + 4.0.0 + + + com.test + test-pipelines + 1.0.0-SNAPSHOT + + + spark-pipeline-messaging + jar + + test::Pipelines::Spark Pipeline Messaging + ${pipeline.description} + + + + + net.masterthought + maven-cucumber-reporting + + + + + + + org.technologybrewery.krausening + krausening + + + com.boozallen.aissemble + foundation-core-java + + + com.boozallen.aissemble + foundation-metadata-producer + + + com.boozallen.aissemble + extensions-data-delivery-spark + + + com.boozallen.aissemble + extensions-data-delivery-spark + tests + test-jar + test + ${version.aissemble} + + + io.smallrye.reactive + smallrye-reactive-messaging-kafka + ${version.smallrye.reactive.messaging} + + + + diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java new file mode 100644 index 000000000..cc96e0b5e --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java @@ -0,0 +1,68 @@ +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.ArrayList; +import java.util.List; + +import org.apache.commons.collections4.CollectionUtils; +import org.jboss.weld.environment.se.WeldContainer; + +import com.boozallen.aissemble.core.cdi.CdiContainer; +import com.boozallen.aissemble.core.cdi.CdiContext; + +/** + * Factory that creates the proper CDI Context for this series of pipelines. + * + * Please **DO** modify with your customizations, as appropriate. + * + * Originally generated from: templates/cdi.container.factory.java.vm + */ +public final class CdiContainerFactory { + + private CdiContainerFactory() { + // private construct to prevent instantiation of all static class + } + + /** + * Creates a new WeldContainer with the set of {@link CdiContext} + * implementations needed for these pipelines. + * + * @return Weld Container instance + */ + public static WeldContainer getCdiContainer() { + return getCdiContainer(null); + } + + /** + * Creates a new WeldContainer with the set of {@link CdiContext} + * implementations needed for these pipelines with the ability to add in + * additional contexts in an ad-hoc fashion. + * + * @param additionalContexts + * @return Weld Container instance + */ + public static WeldContainer getCdiContainer(List additionalContexts) { + List contexts = getContexts(); + if (CollectionUtils.isNotEmpty(additionalContexts)) { + contexts.addAll(additionalContexts); + } + return CdiContainer.create(contexts); + } + + protected static List getContexts() { + List contexts = new ArrayList<>(); + contexts.add(new PipelinesCdiContext()); + + return contexts; + } + +} diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-non-kafka/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-non-kafka/pom.xml new file mode 100644 index 000000000..e7d9bec45 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-non-kafka/pom.xml @@ -0,0 +1,70 @@ + + + + + 4.0.0 + + + com.test + test-pipelines + 1.0.0-SNAPSHOT + + + spark-pipeline-messaging + jar + + test::Pipelines::Spark Pipeline Messaging + ${pipeline.description} + + + + + net.masterthought + maven-cucumber-reporting + + + + + + + org.technologybrewery.krausening + krausening + + + com.boozallen.aissemble + foundation-core-java + + + com.boozallen.aissemble + foundation-metadata-producer + + + com.boozallen.aissemble + extensions-data-delivery-spark + + + com.boozallen.aissemble + extensions-data-delivery-spark + tests + test-jar + test + ${version.aissemble} + + + io.smallrye.reactive + smallrye-reactive-messaging-rabbitmq + ${version.smallrye.reactive.messaging} + + + + diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-non-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-non-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java new file mode 100644 index 000000000..cc96e0b5e --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/migration/smallrye-non-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java @@ -0,0 +1,68 @@ +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.ArrayList; +import java.util.List; + +import org.apache.commons.collections4.CollectionUtils; +import org.jboss.weld.environment.se.WeldContainer; + +import com.boozallen.aissemble.core.cdi.CdiContainer; +import com.boozallen.aissemble.core.cdi.CdiContext; + +/** + * Factory that creates the proper CDI Context for this series of pipelines. + * + * Please **DO** modify with your customizations, as appropriate. + * + * Originally generated from: templates/cdi.container.factory.java.vm + */ +public final class CdiContainerFactory { + + private CdiContainerFactory() { + // private construct to prevent instantiation of all static class + } + + /** + * Creates a new WeldContainer with the set of {@link CdiContext} + * implementations needed for these pipelines. + * + * @return Weld Container instance + */ + public static WeldContainer getCdiContainer() { + return getCdiContainer(null); + } + + /** + * Creates a new WeldContainer with the set of {@link CdiContext} + * implementations needed for these pipelines with the ability to add in + * additional contexts in an ad-hoc fashion. + * + * @param additionalContexts + * @return Weld Container instance + */ + public static WeldContainer getCdiContainer(List additionalContexts) { + List contexts = getContexts(); + if (CollectionUtils.isNotEmpty(additionalContexts)) { + contexts.addAll(additionalContexts); + } + return CdiContainer.create(contexts); + } + + protected static List getContexts() { + List contexts = new ArrayList<>(); + contexts.add(new PipelinesCdiContext()); + + return contexts; + } + +} diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/pom.xml new file mode 100644 index 000000000..431855726 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/pom.xml @@ -0,0 +1,74 @@ + + + + + 4.0.0 + + + com.test + test-pipelines + 1.0.0-SNAPSHOT + + + spark-pipeline-messaging + jar + + test::Pipelines::Spark Pipeline Messaging + ${pipeline.description} + + + + + net.masterthought + maven-cucumber-reporting + + + + + + + org.technologybrewery.krausening + krausening + + + com.boozallen.aissemble + foundation-core-java + + + com.boozallen.aissemble + foundation-metadata-producer + + + com.boozallen.aissemble + extensions-data-delivery-spark + + + com.boozallen.aissemble + extensions-data-delivery-spark + tests + test-jar + test + ${version.aissemble} + + + io.smallrye.reactive + smallrye-reactive-messaging-kafka + ${version.smallrye.reactive.messaging} + + + com.boozallen.aissemble + extensions-messaging-kafka + + + + diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java new file mode 100644 index 000000000..917984a3a --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java @@ -0,0 +1,72 @@ +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.ArrayList; +import java.util.List; + +import org.apache.commons.collections4.CollectionUtils; +import org.jboss.weld.environment.se.WeldContainer; + +import com.boozallen.aissemble.messaging.core.cdi.MessagingCdiContext; +import com.boozallen.aissemble.kafka.context.KafkaConnectorCdiContext; +import com.boozallen.aissemble.core.cdi.CdiContainer; +import com.boozallen.aissemble.core.cdi.CdiContext; + +/** + * Factory that creates the proper CDI Context for this series of pipelines. + * + * Please **DO** modify with your customizations, as appropriate. + * + * Originally generated from: templates/cdi.container.factory.java.vm + */ +public final class CdiContainerFactory { + + private CdiContainerFactory() { + // private construct to prevent instantiation of all static class + } + + /** + * Creates a new WeldContainer with the set of {@link CdiContext} + * implementations needed for these pipelines. + * + * @return Weld Container instance + */ + public static WeldContainer getCdiContainer() { + return getCdiContainer(null); + } + + /** + * Creates a new WeldContainer with the set of {@link CdiContext} + * implementations needed for these pipelines with the ability to add in + * additional contexts in an ad-hoc fashion. + * + * @param additionalContexts + * @return Weld Container instance + */ + public static WeldContainer getCdiContainer(List additionalContexts) { + List contexts = getContexts(); + if (CollectionUtils.isNotEmpty(additionalContexts)) { + contexts.addAll(additionalContexts); + } + return CdiContainer.create(contexts); + } + + protected static List getContexts() { + List contexts = new ArrayList<>(); + contexts.add(new MessagingCdiContext()); + contexts.add(new KafkaConnectorCdiContext()); + contexts.add(new PipelinesCdiContext()); + + return contexts; + } + +} diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-non-kafka/pom.xml b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-non-kafka/pom.xml new file mode 100644 index 000000000..e7d9bec45 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-non-kafka/pom.xml @@ -0,0 +1,70 @@ + + + + + 4.0.0 + + + com.test + test-pipelines + 1.0.0-SNAPSHOT + + + spark-pipeline-messaging + jar + + test::Pipelines::Spark Pipeline Messaging + ${pipeline.description} + + + + + net.masterthought + maven-cucumber-reporting + + + + + + + org.technologybrewery.krausening + krausening + + + com.boozallen.aissemble + foundation-core-java + + + com.boozallen.aissemble + foundation-metadata-producer + + + com.boozallen.aissemble + extensions-data-delivery-spark + + + com.boozallen.aissemble + extensions-data-delivery-spark + tests + test-jar + test + ${version.aissemble} + + + io.smallrye.reactive + smallrye-reactive-messaging-rabbitmq + ${version.smallrye.reactive.messaging} + + + + diff --git a/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-non-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-non-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java new file mode 100644 index 000000000..9e91f0180 --- /dev/null +++ b/foundation/foundation-upgrade/src/test/resources/test-files/v1_10_0/SparkPipelineMessagingMigration/validation/smallrye-non-kafka/src/main/java/test/path/cdi/CdiContainerFactory.java @@ -0,0 +1,70 @@ +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.ArrayList; +import java.util.List; + +import org.apache.commons.collections4.CollectionUtils; +import org.jboss.weld.environment.se.WeldContainer; + +import com.boozallen.aissemble.messaging.core.cdi.MessagingCdiContext; +import com.boozallen.aissemble.core.cdi.CdiContainer; +import com.boozallen.aissemble.core.cdi.CdiContext; + +/** + * Factory that creates the proper CDI Context for this series of pipelines. + * + * Please **DO** modify with your customizations, as appropriate. + * + * Originally generated from: templates/cdi.container.factory.java.vm + */ +public final class CdiContainerFactory { + + private CdiContainerFactory() { + // private construct to prevent instantiation of all static class + } + + /** + * Creates a new WeldContainer with the set of {@link CdiContext} + * implementations needed for these pipelines. + * + * @return Weld Container instance + */ + public static WeldContainer getCdiContainer() { + return getCdiContainer(null); + } + + /** + * Creates a new WeldContainer with the set of {@link CdiContext} + * implementations needed for these pipelines with the ability to add in + * additional contexts in an ad-hoc fashion. + * + * @param additionalContexts + * @return Weld Container instance + */ + public static WeldContainer getCdiContainer(List additionalContexts) { + List contexts = getContexts(); + if (CollectionUtils.isNotEmpty(additionalContexts)) { + contexts.addAll(additionalContexts); + } + return CdiContainer.create(contexts); + } + + protected static List getContexts() { + List contexts = new ArrayList<>(); + contexts.add(new MessagingCdiContext()); + contexts.add(new PipelinesCdiContext()); + + return contexts; + } + +}