Skip to content

Commit

Permalink
Add OpenAPI client generation (#324)
Browse files Browse the repository at this point in the history
* Repackage Maven coordinates from com.datastax to io.k8ssandra
  • Loading branch information
emerkle826 authored Jul 26, 2023
1 parent b1bc077 commit e8a223a
Show file tree
Hide file tree
Showing 21 changed files with 764 additions and 48 deletions.
39 changes: 37 additions & 2 deletions .github/workflows/maven-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,44 @@ jobs:
</servers>
</settings>
EOF
- name: Deploy
- name: Setup release version
run: |
RELEASE_VERSION="${GITHUB_REF##*/}"
RELEASE_VERSION="${RELEASE_VERSION:1}"
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
- name: Deploy Artifacts to GitHub Packages
run: |
REPO="gh::default::https://maven.pkg.github.com/${GITHUB_REPOSITORY}"
mvn -B clean deploy -P dse -Drevision="$RELEASE_VERSION" -DskipTests -DaltDeploymentRepository="${REPO}" -DaltSnapshotDeploymentRepository="${REPO}"
mvn -B clean deploy \
-P dse,dse7 \
-Drevision="${{ env.RELEASE_VERSION }}" \
-DskipTests \
-DaltDeploymentRepository="${REPO}" \
-DaltSnapshotDeploymentRepository="${REPO}"
# - name: Deploy Artifacts to Datsatx Artifactory
# run: |
# REPO="artifactory-releases::default::https://repo.datastax.com/artifactory/datastax-releases-local"
# mvn -B clean deploy \
# -P dse,dse7 \
# -Drevision="${{ env.RELEASE_VERSION }}" \
# -DskipTests \
# -DaltDeploymentRepository="${REPO}" \
# -DaltSnapshotDeploymentRepository="${REPO}"
# - name: Deploy OpenAPI client to GitHub Packages
# run: |
# REPO="gh::default::https://maven.pkg.github.com/${GITHUB_REPOSITORY}"
# mvn -B clean deploy \
# -f management-api-server/target/generated-sources/openapi/java-client/pom.xml \
# -Drevision="${{ env.RELEASE_VERSION }}" \
# -DskipTests \
# -DaltDeploymentRepository="${REPO}" \
# -DaltSnapshotDeploymentRepository="${REPO}"
- name: Deploy OpenAPI client to Datastax Artifactory
run: |
REPO="artifactory-releases::default::https://repo.datastax.com/artifactory/datastax-releases-local"
mvn -B clean deploy \
-f management-api-server/target/generated-sources/openapi/java-client/pom.xml \
-Drevision="${{ env.RELEASE_VERSION }}" \
-DskipTests \
-DaltDeploymentRepository="${REPO}" \
-DaltSnapshotDeploymentRepository="${REPO}"
48 changes: 48 additions & 0 deletions .github/workflows/openapi-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Publish OpenAPI Client
on:
workflow_dispatch:
jobs:
publish-openapi:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'zulu'
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Compute commit SHA
run: |
echo "COMMITSHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Generate OpenAPI client source
run: |
mvn -B clean process-classes -Drevision="0.1.0-${{ env.COMMITSHA }}"
- name: Setup Maven settings.xml
run: |
cat <<EOF > ~/.m2/settings.xml
<settings>
<servers>
<server>
<id>artifactory-releases</id>
<username>${{ secrets.ARTIFACTORY_USERNAME }}</username>
<password>${{ secrets.ARTIFACTORY_PASSWORD }}</password>
</server>
</servers>
</settings>
EOF
- name: Compile and deploy OpenAPI client
run: |
REPO="artifactory-releases::default::https://repo.datastax.com/artifactory/datastax-releases-local"
mvn -B clean deploy \
-f management-api-server/target/generated-sources/openapi/java-client/pom.xml \
-Drevision="0.1.0-${{ env.COMMITSHA }}" \
-DskipTests \
-DaltDeploymentRepository="${REPO}" \
-DaltSnapshotDeploymentRepository="${REPO}"
513 changes: 513 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Dockerfile-4_0
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ COPY management-api-agent-4.1.x ./management-api-agent-4.1.x
COPY management-api-common ./management-api-common
COPY management-api-server ./management-api-server
RUN mkdir -m 775 ${MAAC_PATH} && \
mvn -q -ff package -DskipTests && \
mvn -q -ff package -DskipTests -DskipOpenApi && \
find /build -type f -name "datastax-*.jar" -exec mv -t $MAAC_PATH -i '{}' + && \
rm $MAAC_PATH/datastax-mgmtapi-agent-3* && \
rm $MAAC_PATH/datastax-mgmtapi-*common* && \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-4_0.ubi8
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ COPY management-api-common /tmp/management-api-common
COPY management-api-server /tmp/management-api-server
RUN mkdir -m 775 ${MAAC_PATH} \
&& cd /tmp \
&& mvn -q -ff package -DskipTests \
&& mvn -q -ff package -DskipTests -DskipOpenApi \
&& find /tmp -type f -name "datastax-*.jar" -exec mv -t $MAAC_PATH -i '{}' + \
&& rm ${MAAC_PATH}/datastax-mgmtapi-agent-3.x* \
&& rm ${MAAC_PATH}/datastax-mgmtapi-agent-4.1.x* \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-4_1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ COPY management-api-agent-4.1.x ./management-api-agent-4.1.x
COPY management-api-common ./management-api-common
COPY management-api-server ./management-api-server
RUN mkdir -m 775 ${MAAC_PATH} && \
mvn -q -ff package -DskipTests && \
mvn -q -ff package -DskipTests -DskipOpenApi && \
find /build -type f -name "datastax-*.jar" -exec mv -t $MAAC_PATH -i '{}' + && \
rm $MAAC_PATH/datastax-mgmtapi-agent-3* && \
rm $MAAC_PATH/datastax-mgmtapi-*common* && \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-4_1.ubi8
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ COPY management-api-common /tmp/management-api-common
COPY management-api-server /tmp/management-api-server
RUN mkdir -m 775 ${MAAC_PATH} \
&& cd /tmp \
&& mvn -q -ff package -DskipTests \
&& mvn -q -ff package -DskipTests -DskipOpenApi \
&& find /tmp -type f -name "datastax-*.jar" -exec mv -t ${MAAC_PATH} -i '{}' + \
&& rm ${MAAC_PATH}/datastax-mgmtapi-agent-3.x* \
&& rm ${MAAC_PATH}/datastax-mgmtapi-agent-4.x* \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-oss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ COPY management-api-agent-4.1.x ./management-api-agent-4.1.x
COPY management-api-common ./management-api-common
COPY management-api-server ./management-api-server
RUN mkdir -m 775 ${MAAC_PATH} && \
mvn -q -ff package -DskipTests && \
mvn -q -ff package -DskipTests -DskipOpenApi && \
find /build -type f -name "datastax-*.jar" -exec mv -t $MAAC_PATH -i '{}' + && \
rm $MAAC_PATH/datastax-mgmtapi-agent-4* && \
rm $MAAC_PATH/datastax-mgmtapi-*common* && \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-oss.ubi8
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ COPY management-api-common /tmp/management-api-common
COPY management-api-server /tmp/management-api-server
RUN mkdir -m 775 ${MAAC_PATH} \
&& cd /tmp \
&& mvn -q -ff package -DskipTests \
&& mvn -q -ff package -DskipTests -DskipOpenApi \
&& find /tmp -type f -name "datastax-*.jar" -exec mv -t ${MAAC_PATH} -i '{}' + \
&& rm ${MAAC_PATH}/datastax-mgmtapi-agent-4.x* \
&& rm ${MAAC_PATH}/datastax-mgmtapi-agent-4.1.x* \
Expand Down
79 changes: 76 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,18 +391,91 @@ git commit

## API Client Generation

In addition to automatic OpenAPI document generation, a Golang client can be generated during the build by enabling the `clientgen` Maven profile. The client is built using the [OpenAPI Tools generator Maven plugin](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin) and can be used by Go projects to interact with the Management API. The client generation happens during the `process-classes` phase of the Maven build so that changes to the API implementation can be compiled into an OpenAPI document spec file [during the compile phase](#changes-to-api-endpoints) of the build. The client code is generated in the `target` directory under the [management-api-server](management-api-server) sub-module and should be located at
In addition to automatic OpenAPI document generation, a Golang client or a Java client can be generated during the build (unfortunately, only
one of them can be generated at a time, but you can run the `process-classes` goal back-to-back to generate them both). The Java client generation
is enabled by default (or can be explicitly enabled with the `java-clientgen` Maven profile). The Go client generation is disabled by default
and can be enabled with the `go-clientgen` Maven profile. The clients are built using the
[OpenAPI Tools generator Maven plugin](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin)
and can be used by projects to interact with the Management API. The client generation happens during the `process-classes`
phase of the Maven build so that changes to the API implementation can be compiled into an OpenAPI document spec file
[during the compile phase](#changes-to-api-endpoints) of the build. The client code is generated in the `target` directory under
the [management-api-server](management-api-server) sub-module and should be located at

```sh
management-api-server/target/generated-sources/openapi
```

To generate the client, run the following from the root of the project:
To generate the Go client, run the following from the root of the project:

```sh
mvn clean process-classes -Pclientgen
mvn process-classes -P go-clientgen
```

The Go client code will be generated in `management-api-server/target/generated-sources/openapi/go-client`

To generate the Java client, run the following from the root of the project:

```sh
mvn process-classes -P java-clientgen
```

or simply:

```sh
mvn process-classes
```

The Java client code will be generated in `management-api-server/target/generated-sources/openapi/java-client`

### Maven coordinates for the Java generated client

This project also has a workflow_dispatch job that will publish the current `master` branch version of the Java
generated client to the Datastax public Maven repository. To pull in this artifact in a Maven project, you will
need to add the Datastax Artifactory repository to your Maven settings:

```xml
<profiles>
<profile>
<id>datastax</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>datastax-artifactory</id>
<name>DataStax Artifactory</name>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<url>https://repo.datastax.com</url>
<layout>default</layout>
</repository>
</repositories>
</profile>
</profiles>
```

At the current time, the artifact for the Java client will have a version that contains the Git Hash of the commit it
was built from. To add the artifact to your Maven project as a dependency, you will need something like this in your pom.xml:

```xml
<project>
<dependencies>
<dependency>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi-client-openapi</artifactId>
<version>0.1.0-9d71b60</version>
</dependency>
</dependnecies>
</project>
```

where `9d71b60` is the hash of the release you want.

Eventually, this artifact will be published into Maven Central and have a regular release version (i.e. 0.1.0).

## Published Docker images

When PRs are merged into the `master` branch, if all of the integration tests pass, the CI process will build and publish all supported Docker images with GitHub commit SHA tags. These images are not intended to be used in production. They are meant for facilitating testing with dependent projects.
Expand Down
13 changes: 13 additions & 0 deletions gen_changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
previous_tag=0
for current_tag in $(git tag --sort=-creatordate)
do

if [ "$previous_tag" != 0 ];then
tag_date=$(git log -1 --pretty=format:'%ad' --date=short ${previous_tag})
printf "## ${previous_tag} (${tag_date})\n\n"
git log ${current_tag}...${previous_tag} --pretty=format:'* %s [View](https://github.com/k8ssandra/management-api-for-apache-cassandra/commit/%H)' --reverse | grep -v Merge
printf "\n\n"
fi
previous_tag=${current_tag}
done
7 changes: 3 additions & 4 deletions management-api-agent-3.x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi</artifactId>
<version>${revision}</version>
</parent>
<groupId>com.datastax</groupId>
<artifactId>datastax-mgmtapi-agent-3.x</artifactId>
<profiles>
<profile>
Expand All @@ -23,12 +22,12 @@
</activation>
<dependencies>
<dependency>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi-agent-common</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down
7 changes: 3 additions & 4 deletions management-api-agent-4.1.x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi</artifactId>
<version>${revision}</version>
</parent>
<groupId>com.datastax</groupId>
<artifactId>datastax-mgmtapi-agent-4.1.x</artifactId>
<properties>
<cassandra4.version>4.1.2</cassandra4.version>
</properties>
<dependencies>
<dependency>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi-agent-common</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down
7 changes: 3 additions & 4 deletions management-api-agent-4.x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi</artifactId>
<version>${revision}</version>
</parent>
<groupId>com.datastax</groupId>
<artifactId>datastax-mgmtapi-agent-4.x</artifactId>
<dependencies>
<dependency>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi-agent-common</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down
7 changes: 3 additions & 4 deletions management-api-agent-5.0.x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi</artifactId>
<version>${revision}</version>
</parent>
<groupId>com.datastax</groupId>
<artifactId>datastax-mgmtapi-agent-5.0.x</artifactId>
<properties>
<cassandra5.version>5.0-SNAPSHOT</cassandra5.version>
</properties>
<dependencies>
<dependency>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi-agent-common</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down
5 changes: 2 additions & 3 deletions management-api-agent-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi</artifactId>
<version>${revision}</version>
</parent>
<groupId>com.datastax</groupId>
<artifactId>datastax-mgmtapi-agent-common</artifactId>
<profiles>
<profile>
Expand All @@ -23,7 +22,7 @@
</activation>
<dependencies>
<dependency>
<groupId>com.datastax</groupId>
<groupId>io.k8ssandra</groupId>
<artifactId>datastax-mgmtapi-common</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down
Loading

0 comments on commit e8a223a

Please sign in to comment.