Skip to content

Commit

Permalink
Add Management API agent for http tests (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: Miles-Garnsey <miles.garnsey@datastax.com>
  • Loading branch information
emerkle826 and Miles-Garnsey committed Aug 17, 2023
1 parent 65adb8c commit 7f8b52f
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 23 deletions.
3 changes: 1 addition & 2 deletions .github/scripts/configure-ccm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ case "${TEST_TYPE}" in
mkdir -p ~/.local
cp ./.github/files/jmxremote.password ~/.local/jmxremote.password
chmod 400 ~/.local/jmxremote.password
ls -lrt /opt/hostedtoolcache/
for jdk in /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/8*/;
do
sudo chmod 777 "${jdk/}"x64/jre/lib/management/jmxremote.access
Expand Down Expand Up @@ -115,4 +114,4 @@ case "${TEST_TYPE}" in
;;
*)
echo "Skipping, no actions for TEST_TYPE=${TEST_TYPE}."
esac
esac
47 changes: 46 additions & 1 deletion .github/scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ function set_java_home() {
done
}

add_management_api () {
if [[ ! -L /tmp/datastax-mgmtapi-agent.jar ]]; then
# Do some fancy pom.xml parsing to figure out which version of the Management API client we are using
MGMT_API_VERSION=`mvn dependency:tree -f src/server/pom.xml |grep datastax-mgmtapi-client-openapi|cut -d ":" -f 4`
# Download the Management API bundle
mvn dependency:copy -Dartifact=io.k8ssandra:datastax-mgmtapi-server:$MGMT_API_VERSION -f src/server/pom.xml -DoutputDirectory=/tmp -Dmdep.stripVersion=true -Dmdep.overWriteReleases=true
# Unzip the agent for the version of Cassandra
if [[ "$CASSANDRA_VERSION" == *"3.11"* ]]; then
mvn dependency:copy -Dartifact=io.k8ssandra:datastax-mgmtapi-agent-3.x:$MGMT_API_VERSION -f src/server/pom.xml -DoutputDirectory=/tmp -Dmdep.stripVersion=true -Dmdep.overWriteReleases=true
ln -s /tmp/datastax-mgmtapi-agent-3.x.jar /tmp/datastax-mgmtapi-agent.jar
elif [[ "$CASSANDRA_VERSION" == *"4.0"* ]]; then
mvn dependency:copy -Dartifact=io.k8ssandra:datastax-mgmtapi-agent-4.x:$MGMT_API_VERSION -f src/server/pom.xml -DoutputDirectory=/tmp -Dmdep.stripVersion=true -Dmdep.overWriteReleases=true
ln -s /tmp/datastax-mgmtapi-agent-4.x.jar /tmp/datastax-mgmtapi-agent.jar
elif [[ "$CASSANDRA_VERSION" == *"4.1"* ]]; then
mvn dependency:copy -Dartifact=io.k8ssandra:datastax-mgmtapi-agent-4.1.x:$MGMT_API_VERSION -f src/server/pom.xml -DoutputDirectory=/tmp -Dmdep.stripVersion=true -Dmdep.overWriteReleases=true
ln -s /tmp/datastax-mgmtapi-agent-4.1.x.jar /tmp/datastax-mgmtapi-agent.jar
fi
fi
echo "JVM_OPTS=\"\$JVM_OPTS -javaagent:/tmp/datastax-mgmtapi-agent.jar\"" >> ~/.ccm/test/node$1/conf/cassandra-env.sh
}

case "${TEST_TYPE}" in
"")
echo "ERROR: Environment variable TEST_TYPE is unspecified."
Expand Down Expand Up @@ -85,10 +106,34 @@ case "${TEST_TYPE}" in
ps uax | grep cass
# dependending on the version of cassandra, we may need to use a different jdk
set_java_home ${JDK_VERSION}
# Add in Management API agent jarfile
for i in `seq 1 2` ; do
add_management_api $i
mkdir -p /tmp/log/cassandra$i/ && touch /tmp/log/cassandra$i/stdout.log
done
ccm start -v --no-wait --skip-wait-other-notice || true
echo "${TEST_TYPE}" | grep -q ccm && sleep 30 || sleep 120
ccm status
ccm node1 nodetool -- -u cassandra -pw cassandrapassword status
# Stop CCM now so we can restart it with Management API
ccm stop
# Start Management API
MGMT_API_LOG_DIR=/tmp/log/cassandra1 bash -c 'nohup java -jar /tmp/datastax-mgmtapi-server.jar --db-socket=/tmp/db1.sock --host=unix:///tmp/mgmtapi1.sock --host=http://127.0.0.1:8080 --db-home=`dirname ~/.ccm/test/node1`/node1 &'
MGMT_API_LOG_DIR=/tmp/log/cassandra2 bash -c 'nohup java -jar /tmp/datastax-mgmtapi-server.jar --db-socket=/tmp/db2.sock --host=unix:///tmp/mgmtapi2.sock --host=http://127.0.0.2:8080 --db-home=`dirname ~/.ccm/test/node2`/node2 &'
# wait for Cassandra to be ready
for i in `seq 1 30` ; do
# keep curl from exiting with non-zero
HTTPCODE1=`curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8080/api/v0/probes/readiness` || true
HTTPCODE2=`curl -s -o /dev/null -w "%{http_code}" http://127.0.0.2:8080/api/v0/probes/readiness` || true
if [ "${HTTPCODE1}" != "200" -o "${HTTPCODE2}" != "200" ]
then
echo "Cassandra not ready yet. Sleeping.... $i"
else
echo "Cassandra started via Management API successfully"
break
fi
sleep 5
done
# Reaper requires JDK11 for compilation
set_java_home 11
case "${STORAGE_TYPE}" in
Expand Down Expand Up @@ -199,4 +244,4 @@ case "${TEST_TYPE}" in
;;
*)
echo "Skipping, no actions for TEST_TYPE=${TEST_TYPE}."
esac
esac
2 changes: 1 addition & 1 deletion .github/workflows/check_pr_linked_issue.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
name: Check linked issues
steps:
- uses: nearform/github-action-check-linked-issues@v1
- uses: nearform-actions/github-action-check-linked-issues@v1
continue-on-error: true
id: check-linked-issues
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ jobs:
JDK_VERSION: ${{ matrix.jdk-version }}

- name: Run Tests
run: ./.github/scripts/run-tests.sh || ./.github/scripts/run-tests.sh
run: ./.github/scripts/run-tests.sh
env:
TEST_TYPE: ${{ matrix.test-type }}
CASSANDRA_VERSION: ${{ matrix.cassandra-version }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void run(ReaperApplicationConfiguration config, Environment environment)
private void initializeManagement(AppContext context, Cryptograph cryptograph) {
if (context.managementConnectionFactory == null) {
LOG.info("no management connection factory given in context, creating default");
if (context.config.getHttpManagement() == null || !context.config.getHttpManagement().getEnabled()) {
if (context.config.getHttpManagement() == null || !context.config.getHttpManagement().isEnabled()) {
LOG.info("HTTP management connection config not set, or set disabled. Creating JMX connection factory instead");
context.managementConnectionFactory = new JmxManagementConnectionFactory(context, cryptograph);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ public static final class HttpManagement {
@JsonProperty
private Boolean enabled = false;

public Boolean getEnabled() {
public Boolean isEnabled() {
return enabled;
}
// TODO: Add ports and root paths here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.codahale.metrics.MetricRegistry;
import com.datastax.mgmtapi.client.api.DefaultApi;
import com.datastax.mgmtapi.client.invoker.ApiClient;
import com.datastax.mgmtapi.client.invoker.ApiException;
import org.apache.cassandra.repair.RepairParallelism;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -141,7 +142,13 @@ public Map<String, List<String>> listTablesByKeyspace() {

@Override
public String getCassandraVersion() {
return null; // TODO: implement me.
try {
return apiClient.getReleaseVersion();
} catch (ApiException ae) {
LOG.error("Failed to get Cassandra version", ae);
}
// should not get here
return "UNKNOWN";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ cryptograph:
systemPropertySecret: REAPER_ENCRYPTION_KEY

httpManagement:
isEnabled: true
enabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Feature: Using Reaper
Then there is 0 snapshot returned when listing snapshots
When the last added cluster is deleted
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@all_nodes_reachable
@cassandra_3_11_onwards
Expand All @@ -66,7 +66,7 @@ Feature: Using Reaper
Then there is 0 snapshot returned when listing snapshots
When the last added cluster is deleted
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@sidecar
@http_management
Expand All @@ -88,7 +88,7 @@ Feature: Using Reaper
When the last added cluster is force deleted
And reaper has 0 scheduled repairs for cluster called "test"
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@sidecar
@cassandra_3_11_onwards
Expand All @@ -111,7 +111,7 @@ Feature: Using Reaper
When the last added schedule is deleted for the last added cluster
And the last added cluster is deleted
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@sidecar
@http_management
Expand All @@ -138,7 +138,7 @@ Feature: Using Reaper
When all added schedules are deleted for the last added cluster
And the last added cluster is deleted
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@sidecar
@all_nodes_reachable
Expand All @@ -158,7 +158,7 @@ Feature: Using Reaper
When all added schedules are deleted for the last added cluster
And the last added cluster is deleted
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@sidecar
@all_nodes_reachable
Expand All @@ -179,7 +179,7 @@ Feature: Using Reaper
When all added schedules are deleted for the last added cluster
And the last added cluster is deleted
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@sidecar
@all_nodes_reachable
Expand All @@ -199,7 +199,7 @@ Feature: Using Reaper
When all added schedules are deleted for the last added cluster
And the last added cluster is deleted
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@sidecar
@cassandra_3_11_onwards
Expand All @@ -223,7 +223,7 @@ Feature: Using Reaper
When all added schedules are deleted for the last added cluster
And the last added cluster is deleted
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@sidecar
@cassandra_3_11_onwards
Expand All @@ -246,6 +246,7 @@ Feature: Using Reaper
And all added repair runs are deleted for the last added cluster
And the last added cluster is deleted
Then reaper has no longer the last added cluster in storage
${cucumber.upgrade-versions}

# this has a problem in the upgrade integration tests, ref: 88d4d5c
@cassandra_3_11_onwards
Expand All @@ -267,6 +268,7 @@ Feature: Using Reaper
And all added repair runs are deleted for the last added cluster
And the last added cluster is deleted
Then reaper has no longer the last added cluster in storage
${cucumber.upgrade-versions}

@sidecar
@all_nodes_reachable
Expand All @@ -293,7 +295,7 @@ Feature: Using Reaper
And all added repair runs are deleted for the last added cluster
And the last added cluster is deleted
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@sidecar
@all_nodes_reachable
Expand All @@ -319,7 +321,7 @@ Feature: Using Reaper
When all added repair runs are deleted for the last added cluster
And the last added cluster is deleted
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@all_nodes_reachable
@cassandra_3_11_onwards
Expand Down Expand Up @@ -369,7 +371,7 @@ Feature: Using Reaper
And all added repair runs are deleted for the last added cluster
And the last added cluster is deleted
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@sidecar
@all_nodes_reachable
Expand Down Expand Up @@ -402,7 +404,7 @@ Feature: Using Reaper
And I cannot start an unknown schedule
When the last added cluster is force deleted
Then reaper has no longer the last added cluster in storage

${cucumber.upgrade-versions}

@sidecar
@cassandra_3_11_onwards
Expand All @@ -426,4 +428,5 @@ Feature: Using Reaper
When I list the last 10 repairs, I can see 4 repairs at "PAUSED" state
When I list the last 10 repairs, I can see 6 repairs at "ABORTED" state
When the last added cluster is force deleted
Then reaper has no longer the last added cluster in storage
Then reaper has no longer the last added cluster in storage
${cucumber.upgrade-versions}

0 comments on commit 7f8b52f

Please sign in to comment.