Skip to content

Commit

Permalink
Merge pull request #448 from boozallen/434-quarkus-java17-migrations
Browse files Browse the repository at this point in the history
#434 Create baton migration for Quarkus Java 17 upgrade
  • Loading branch information
carter-cundiff authored Oct 31, 2024
2 parents c603056 + 318686a commit 64ed560
Show file tree
Hide file tree
Showing 41 changed files with 2,045 additions and 97 deletions.
57 changes: 38 additions & 19 deletions DRAFT_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Major Additions

## TBD
## Java 17 Upgrade
The aiSSEMBLE project is now built with Java 17. All dependencies inherited from aiSSEMBLE have been updated to a Java 17 compatible version and automatic migrations (detailed below) have been created to streamline this transition for downstream projects. It is recommended to review non-inherited dependencies and custom logic within your project, as this upgrade can break existing functionality due to deprecated classes and incompatible dependencies.

# Breaking Changes
- Note: instructions for adapting to these changes are outlined in the upgrade instructions below.

With the upgrade to Java 17, the new minimum required Maven version is now 3.9.6. This can result in deprecated classes or incompatible dependencies, please update your modules accordingly.
Note: instructions for adapting to these changes are outlined in the upgrade instructions below.

- All upgrading projects must be built with Java 17 to ensure compatibility with this release.
- The new minimum required Maven version is now `3.9.6` to ensure compatibility with Java 17.

# Known Issues
_There are no known issues with the 1.10 release._
Expand All @@ -17,7 +18,7 @@ _There are no known issues with the 1.10 release._


# How to Upgrade
The following steps will upgrade your project to 1.10. These instructions consist of multiple phases:
The following steps will upgrade your project to `1.10`. These instructions consist of multiple phases:
- Automatic Upgrades - no manual action required
- Precondition Steps - needed in all situations
- Conditional Steps (e.g., Python steps, Java steps, if you use Metadata, etc)
Expand All @@ -31,11 +32,15 @@ To reduce burden of upgrading aiSSEMBLE, the Baton project is used to automate t
| upgrade-tiltfile-aissemble-version-migration | Updates the aiSSEMBLE version within your project's Tiltfile |
| upgrade-v2-chart-files-aissemble-version-migration | Updates the Helm chart dependencies within your project's deployment resources (`<YOUR_PROJECT>-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 (`<YOUR_PROJECT>-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-version-upgrade-migration | Updates the Spark Application executor failure parameters to their new key name to ensure compatibility with Apache 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 |
| spark-pipeline-servlet-api-migration | Updates a Spark pipeline module `pom.xml` with the `javax.servlet-api` dependency to ensure compatibility with Apache Spark `3.5` which has not migrated to Jakarta packages yet |
| 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 |
| log4j-maven-shade-plugin-migration | Updates the Maven Shade Plugin with the new Log4j dependency information |
| quarkus-bom-migration | Updates all references to the `quarkus-bom` and `quarkus-universe-bom` to use the new `aissemble-quarkus-bom` for managing Quarkus dependencies |
| pom-dependency-version-migration | Updates the pom dependencies previously managed by the aiSSEMBLE `bom-component` to include their necessary versions |
| java-package-migration | Updates the affected java classes from their old package name to their new package name to ensure compatibility with the updated Java 17 dependencies. This migration primarily updates `javax.*` packages to their new `jakarta.*` packages |

To deactivate any of these migrations, add the following configuration to the `baton-maven-plugin` within your root `pom.xml`:

Expand Down Expand Up @@ -63,13 +68,28 @@ To deactivate any of these migrations, add the following configuration to the `b

### Beginning the Upgrade
To start your aiSSEMBLE upgrade, update your project's pom.xml to use the 1.10.0 version of the build-parent:
```xml
<parent>
<groupId>com.boozallen.aissemble</groupId>
<artifactId>build-parent</artifactId>
<version>1.10.0</version>
</parent>
```
```xml
<parent>
<groupId>com.boozallen.aissemble</groupId>
<artifactId>build-parent</artifactId>
<version>1.10.0</version>
</parent>
```

### BOM Component Replacement
All references to the `com.boozallen.aissemble:bom-component` should be replaced with the new `com.boozallen.aissemble:aissemble-quarkus-bom`:
```diff
<dependency>
<groupId>com.boozallen.aissemble</groupId>
- <artifactId>bom-component</artifactId>
+ <artifactId>aissemble-quarkus-bom</artifactId>
<version>${version.aissemble}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
```

## Conditional Steps

### Split Data Records for the Spark Pipeline
If your spark pipeline is using `aissemble-data-records-separate-module` profile for your data records, you must add the `<version>` tag for
Expand All @@ -82,9 +102,6 @@ the `jackson-mapper-asl` dependency artifact in the root pom.xml file to enable
</dependency>
```


## Conditional Steps

### Kafka Clients Dependency Update
Data Access and the Java testing module (`<YOUR_PROJECT>-tests/<YOUR_PROJECT>-tests-java/pom.xml`) no longer need to explicitly set the `kafka-clients` dependency. It can be removed along with its exclusion from the `quarkus-smallrye-reactive-messaging-kafka` dependency.

Expand All @@ -95,9 +112,11 @@ If you added any custom configurations to the `sparkoperator` service account pe
## Final Steps - Required for All Projects
### Finalizing the Upgrade
1. Run `./mvnw org.technologybrewery.baton:baton-maven-plugin:baton-migrate` to apply the automatic migrations
2. Run `./mvnw clean install` and resolve any manual actions that are suggested
2. Remove the `com.boozallen.aissemble:aissemble-quarkus-bom:${version.aissemble}` dependency from the root `pom.xml` and `<YOUR_PROJECT>-tests/<YOUR_PROJECT>-tests-java/pom.xml` of your project
- **NOTE:** Any Quarkus apps within your project should be updated to include the `com.boozallen.aissemble:aissemble-quarkus-bom:${version.aissemble}` within the `<dependencyManagement>` section of their respective `pom.xml` instead
3. Run `./mvnw clean install` and resolve any manual actions that are suggested
- **NOTE:** This will update any aiSSEMBLE dependencies in 'pyproject.toml' files automatically
3. Repeat the previous step until all manual actions are resolved
4. Repeat the previous step until all manual actions are resolved

# What's Changed
- `pyproject.toml` files updated to allow for Python version `>=3.8`.
Expand Down
1 change: 0 additions & 1 deletion bom/bom-component/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
Expand Down
5 changes: 0 additions & 5 deletions foundation/foundation-drift-detection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import io.smallrye.reactive.messaging.memory.InMemoryConnector;
*
* Originally generated from: ${templateName}
*/
public class TestCdiContext extends PipelinesCdiContext {
public class TestCdiContext implements CdiContext {

@Override
public List<Class<?>> getCdiClasses() {
Expand All @@ -24,4 +24,8 @@ public class TestCdiContext extends PipelinesCdiContext {
return classes;
}

@Override
public List<Extension> getExtensions() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>com.boozallen.aissemble</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
<!-- See https://github.com/apache/incubator-hugegraph-toolchain/issues/464 -->
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<version>${version.javax.servlet}</version>
</dependency>
#if ($pipeline.isAlertingSupportNeeded())
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: ${verion}
version: ${version}

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,29 @@
* #L%
*/
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.InputLocation;
import org.apache.maven.model.InputLocationTracker;
import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBase;
import org.apache.maven.model.Profile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.technologybrewery.baton.BatonException;
import org.technologybrewery.baton.util.pom.PomModifications;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

import static org.technologybrewery.baton.util.pom.LocationAwareMavenReader.END;
import static org.technologybrewery.baton.util.pom.LocationAwareMavenReader.START;

public abstract class AbstractPomMigration extends AbstractAissembleMigration {
protected static final Logger logger = LoggerFactory.getLogger(AbstractPomMigration.class);

Expand All @@ -40,4 +54,60 @@ protected void detectAndSetIndent(File file) {
throw new BatonException("Failed to get indent from POM:" + file, e);
}
}

/**
* Checks if a given pom model contains any dependencies with a provided group ID and artifact ID
*/
protected boolean hasDependency(Model model, String groupId, String artifactId) {
return model.getDependencies()
.stream()
.anyMatch(dependency ->
dependency.getGroupId().equals(groupId) &&
dependency.getArtifactId().contains(artifactId)
);
}

/**
* Checks the dependency and dependency management section of a given pom model and all profiles for any matches
*/
protected List<Dependency> getMatchingDependenciesForProject(Model model, Predicate<? super Dependency> filter) {
List<Dependency> matchingDependencies = this.getMatchingDependencies(model, filter);
for (Profile profile : model.getProfiles()) {
matchingDependencies.addAll(this.getMatchingDependencies(profile, filter));
}
return matchingDependencies;
}

/**
* Checks the dependency and dependency management section of a given pom model for any matches
*/
private List<Dependency> getMatchingDependencies(ModelBase model, Predicate<? super Dependency> filter) {
List<Dependency> matchingDependencies = new ArrayList<>();

Stream.concat(
model.getDependencies()
.stream()
.filter(filter),
Optional.ofNullable(model.getDependencyManagement()).map(dependencyManagement -> dependencyManagement.getDependencies()
.stream()
.filter(filter))
.orElse(Stream.empty())
)
.forEach(matchingDependencies::add);

return matchingDependencies;
}

protected static PomModifications.Replacement replaceInTag(InputLocationTracker container, String tag, String contents) {
InputLocation start = container.getLocation(tag);
InputLocation end = container.getLocation(tag + END);
end = new InputLocation(end.getLineNumber(), end.getColumnNumber() - tag.length() - "</>".length(), end.getSource());
return new PomModifications.Replacement(start, end, contents);
}

protected static PomModifications.Deletion deleteTag(InputLocationTracker container, String tag) {
InputLocation start = container.getLocation(tag + START);
InputLocation end = container.getLocation(tag + END);
return new PomModifications.Deletion(start, end);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@
* #L%
*/

import com.boozallen.aissemble.upgrade.migration.AbstractAissembleMigration;
import com.boozallen.aissemble.upgrade.migration.AbstractPomMigration;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.InputLocation;
import org.apache.maven.model.InputLocationTracker;
import org.apache.maven.model.Model;
import org.apache.maven.model.ModelBase;
import org.apache.maven.model.Profile;
import org.technologybrewery.baton.BatonException;
import org.technologybrewery.baton.util.FileUtils;
import org.technologybrewery.baton.util.pom.PomHelper;
import org.technologybrewery.baton.util.pom.PomModifications;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.technologybrewery.baton.util.pom.LocationAwareMavenReader.END;
Expand All @@ -38,7 +32,7 @@
* to 3.x also involves a rename of the delta-core_[SCALA-VER] dependency to delta-spark_[SCALA_VER]. This migration
* renames this dependency, and ensures that the version is being pulled from build-parent.
*/
public class DeltaSparkPomMigration extends AbstractAissembleMigration {
public class DeltaSparkPomMigration extends AbstractPomMigration {

public static final String ARTIFACT_ID = "artifactId";
public static final String DELTA_VERSION = "${version.delta}";
Expand All @@ -55,7 +49,7 @@ protected boolean shouldExecuteOnFile(File file) {
@Override
protected boolean performMigration(File file) {
Model model = PomHelper.getLocationAnnotatedModel(file);
List<Dependency> deltaCoreDependencies = getDeltaCoreDependenciesForProject(model);
List<Dependency> deltaCoreDependencies = this.getMatchingDependenciesForProject(model, DeltaSparkPomMigration::isDeltaCore);
PomModifications modifications = new PomModifications();
for (Dependency dependency : deltaCoreDependencies) {
String artifactId = dependency.getArtifactId();
Expand All @@ -77,38 +71,7 @@ protected boolean performMigration(File file) {
return true;
}

private List<Dependency> getDeltaCoreDependenciesForProject(Model model) {
List<Dependency> deltaCoreDependencies = getDeltaCoreDependencies(model);
for (Profile profile : model.getProfiles()) {
deltaCoreDependencies.addAll(getDeltaCoreDependencies(profile));
}
return deltaCoreDependencies;
}

private List<Dependency> getDeltaCoreDependencies(ModelBase model) {
List<Dependency> deltaCoreDependencies = new ArrayList<>();
DependencyManagement dependencyManagement = model.getDependencyManagement();
if (dependencyManagement != null) {
dependencyManagement.getDependencies()
.stream()
.filter(DeltaSparkPomMigration::isDeltaCore)
.forEach(deltaCoreDependencies::add);
}
model.getDependencies()
.stream()
.filter(DeltaSparkPomMigration::isDeltaCore)
.forEach(deltaCoreDependencies::add);
return deltaCoreDependencies;
}

private static boolean isDeltaCore(Dependency dep) {
return dep.getGroupId().equals("io.delta") && dep.getArtifactId().startsWith("delta-core_");
}

private static PomModifications.Replacement replaceInTag(InputLocationTracker container, String tag, String contents) {
InputLocation start = container.getLocation(tag);
InputLocation end = container.getLocation(tag + END);
end = new InputLocation(end.getLineNumber(), end.getColumnNumber() - tag.length() - "</>".length(), end.getSource());
return new PomModifications.Replacement(start, end, contents);
}
}
Loading

0 comments on commit 64ed560

Please sign in to comment.