Skip to content

Commit

Permalink
feat(diagnostic): add interface method for invoking MBean operations (#…
Browse files Browse the repository at this point in the history
…459)

* feat(diagnostic): add interface method for invoking MBean operations

* upgrade deps for JDK 21 buildability

* build Cryostat with JDK 21
  • Loading branch information
andrewazores authored Oct 1, 2024
1 parent ca5d2ae commit 2a5c3bb
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-java@v3
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
cache: 'maven'
- name: maven-settings
Expand Down Expand Up @@ -145,7 +145,7 @@ jobs:
needs: [build-cryostat]
strategy:
matrix:
java: ['17']
java: ['21']
outputs:
amd64_image: ${{ steps.cryostat_amd64_image.outputs.image }}

Expand Down
4 changes: 2 additions & 2 deletions cryostat-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -242,7 +242,7 @@
<exclude>src/main/java/org/openjdk/jmc/**</exclude>
</excludes>
<googleJavaFormat>
<version>1.15.0</version>
<version>1.17.0</version>
<style>AOSP</style>
<reflowLongStrings>true</reflowLongStrings>
</googleJavaFormat>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public static class EventOptionException extends Exception {

public static class Factory {
public EventOptionsBuilder create(JFRConnection connection)
throws IOException, ServiceNotAvailableException,
throws IOException,
ServiceNotAvailableException,
org.openjdk.jmc.flightrecorder.configuration.FlightRecorderException {
if (!FlightRecorderServiceV2.isAvailable(connection.getHandle())) {
throw new UnsupportedOperationException("Only FlightRecorder V2 is supported");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public EventOptionsCustomizer(JFRConnection connection) {
}

public EventOptionsCustomizer set(String typeId, String option, String value)
throws FlightRecorderException, EventTypeException, EventOptionException,
throws FlightRecorderException,
EventTypeException,
EventOptionException,
OptionValueException {
if (!isInitialized()) {
initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,27 @@
public interface CryostatFlightRecorderService extends IFlightRecorderService {

IRecordingDescriptor start(IConstrainedMap<String> recordingOptions, Template eventTemplate)
throws io.cryostat.core.FlightRecorderException, FlightRecorderException,
ConnectionException, ParseException, IOException, FlightRecorderException,
ServiceNotAvailableException, QuantityConversionException, EventOptionException,
throws io.cryostat.core.FlightRecorderException,
FlightRecorderException,
ConnectionException,
ParseException,
IOException,
FlightRecorderException,
ServiceNotAvailableException,
QuantityConversionException,
EventOptionException,
EventTypeException;

default IRecordingDescriptor start(IConstrainedMap<String> recordingOptions, String template)
throws io.cryostat.core.FlightRecorderException, FlightRecorderException,
ConnectionException, ParseException, IOException, ServiceNotAvailableException,
QuantityConversionException, EventOptionException, EventTypeException {
throws io.cryostat.core.FlightRecorderException,
FlightRecorderException,
ConnectionException,
ParseException,
IOException,
ServiceNotAvailableException,
QuantityConversionException,
EventOptionException,
EventTypeException {
XMLModel model = EventConfiguration.createModel(template);
IConstrainedMap<EventOptionID> eventOptions =
new EventConfiguration(model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ReflectionException;
import javax.management.remote.JMXServiceURL;

Expand Down Expand Up @@ -56,9 +58,27 @@ public default String getJvmId() throws IDException, IOException {

public JvmIdentifier getJvmIdentifier() throws IDException, IOException;

public default <T> T invokeMBeanOperation(
String beanName,
String operation,
Object[] params,
String[] signature,
Class<T> returnType)
throws MalformedObjectNameException,
InstanceNotFoundException,
MBeanException,
ReflectionException,
IOException,
ConnectionException {
throw new ConnectionException("Unimplemented");
}

public MBeanMetrics getMBeanMetrics()
throws ConnectionException, IOException, InstanceNotFoundException,
IntrospectionException, ReflectionException;
throws ConnectionException,
IOException,
InstanceNotFoundException,
IntrospectionException,
ReflectionException;

public boolean isConnected();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.management.IntrospectionException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.openmbean.CompositeData;
Expand Down Expand Up @@ -206,6 +207,28 @@ public synchronized JvmIdentifier getJvmIdentifier() throws IDException, IOExcep
}
}

@Override
public <T> T invokeMBeanOperation(
String beanName,
String operation,
Object[] params,
String[] signature,
Class<T> returnType)
throws MalformedObjectNameException,
InstanceNotFoundException,
MBeanException,
ReflectionException,
IOException,
ConnectionException {
if (!isConnected()) {
connect();
}
return (T)
this.rjmxConnection
.getMBeanServer()
.invoke(ObjectName.getInstance(beanName), operation, params, signature);
}

private Map<String, Object> parseCompositeData(CompositeData compositeData) {
Map<String, Object> map = new HashMap<>();
for (String key : compositeData.getCompositeType().keySet()) {
Expand Down Expand Up @@ -256,14 +279,18 @@ private Object parseObject(Object obj) {
}

private Map<String, Object> getAttributeMap(ObjectName beanName)
throws InstanceNotFoundException, IntrospectionException, ReflectionException,
throws InstanceNotFoundException,
IntrospectionException,
ReflectionException,
IOException {
return getAttributeMap(beanName, m -> true);
}

private Map<String, Object> getAttributeMap(
ObjectName beanName, Predicate<MBeanAttributeInfo> attrPredicate)
throws InstanceNotFoundException, IntrospectionException, ReflectionException,
throws InstanceNotFoundException,
IntrospectionException,
ReflectionException,
IOException {
Map<String, Object> attrMap = new HashMap<>();

Expand Down Expand Up @@ -294,7 +321,9 @@ private Map<String, Object> getAttributeMap(
}

public synchronized MBeanMetrics getMBeanMetrics()
throws IOException, InstanceNotFoundException, IntrospectionException,
throws IOException,
InstanceNotFoundException,
IntrospectionException,
ReflectionException {
if (!isConnected()) {
connect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,29 @@ public IDescribedMap<EventOptionID> getDefaultEventOptions() {

@Override
public IRecordingDescriptor start(IConstrainedMap<String> recordingOptions, Template template)
throws io.cryostat.core.FlightRecorderException, FlightRecorderException,
ConnectionException, IOException, FlightRecorderException,
ServiceNotAvailableException, QuantityConversionException, EventOptionException,
throws io.cryostat.core.FlightRecorderException,
FlightRecorderException,
ConnectionException,
IOException,
FlightRecorderException,
ServiceNotAvailableException,
QuantityConversionException,
EventOptionException,
EventTypeException {
return tryConnect()
.start(recordingOptions, enableEvents(template.getName(), template.getType()));
}

private IConstrainedMap<EventOptionID> enableEvents(
String templateName, TemplateType templateType)
throws ConnectionException, IOException, io.cryostat.core.FlightRecorderException,
FlightRecorderException, ServiceNotAvailableException,
QuantityConversionException, EventOptionException, EventTypeException {
throws ConnectionException,
IOException,
io.cryostat.core.FlightRecorderException,
FlightRecorderException,
ServiceNotAvailableException,
QuantityConversionException,
EventOptionException,
EventTypeException {
if (templateName.equals("ALL")) {
return enableAllEvents();
}
Expand All @@ -254,8 +264,12 @@ private IConstrainedMap<EventOptionID> enableEvents(
}

private IConstrainedMap<EventOptionID> enableAllEvents()
throws ConnectionException, IOException, FlightRecorderException,
ServiceNotAvailableException, QuantityConversionException, EventOptionException,
throws ConnectionException,
IOException,
FlightRecorderException,
ServiceNotAvailableException,
QuantityConversionException,
EventOptionException,
EventTypeException {
EventOptionsBuilder builder = new EventOptionsBuilder.Factory().create(conn);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public Future<Map<String, AnalysisResult>> generateEvalMapInterruptibly(

private Pair<Collection<IResult>, Long> generateResultHelper(
InputStream recording, Predicate<IRule> predicate)
throws InterruptedException, IOException, ExecutionException,
throws InterruptedException,
IOException,
ExecutionException,
CouldNotLoadRecordingException {
Collection<IRule> rules =
RuleRegistry.getRules().stream().filter(predicate).collect(Collectors.toList());
Expand Down
4 changes: 2 additions & 2 deletions libcryostat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -177,7 +177,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.15.0</version>
<version>1.17.0</version>
<style>AOSP</style>
<reflowLongStrings>true</reflowLongStrings>
</googleJavaFormat>
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<com.github.spotbugs.plugin.version>4.8.6.4</com.github.spotbugs.plugin.version>
<org.junit.jupiter.version>5.11.1</org.junit.jupiter.version>
<org.hamcrest.version>3.0</org.hamcrest.version>
<org.mockito.version>5.2.0</org.mockito.version>
<org.mockito.version>5.14.1</org.mockito.version>
<org.jacoco.maven.plugin.version>0.8.12</org.jacoco.maven.plugin.version>
<com.diffplug.spotless.maven.plugin.version>2.43.0</com.diffplug.spotless.maven.plugin.version>
<org.slf4j.version>2.0.16</org.slf4j.version>
Expand Down Expand Up @@ -152,7 +152,7 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<artifactId>mockito-core</artifactId>
<version>${org.mockito.version}</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -279,7 +279,7 @@
<exclude>src/main/java/org/openjdk/jmc/**</exclude>
</excludes>
<googleJavaFormat>
<version>1.15.0</version>
<version>1.17.0</version>
<style>AOSP</style>
<reflowLongStrings>true</reflowLongStrings>
</googleJavaFormat>
Expand Down

0 comments on commit 2a5c3bb

Please sign in to comment.