Skip to content

Commit

Permalink
chore(jmc-core): Upstream updates (#201)
Browse files Browse the repository at this point in the history
* Updating embedded JMC-core sources to bring them in line with upstream

* Updating to JMC core 8.2.0, reworking InterruptibleReportGenerator for rules changes in core, fixing whitespace

* fixing newline at end of file

* Removing unnecessary loop

* Reverting RuleEvaluation structure for client consumers

* fix NPE due to null reportStats

* include summary, explanation, solution, and settings in text result

* use computed decimal score value if available

* Porting over RulesToolkit.evaluateParallel

---------

Co-authored-by: Andrew Azores <aazores@redhat.com>
  • Loading branch information
Josh-Matsuoka and andrewazores authored Apr 14, 2023
1 parent 9a61378 commit 2336321
Show file tree
Hide file tree
Showing 24 changed files with 599 additions and 294 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<java.version>11</java.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
<jmc.version>7.1.1</jmc.version>
<jmc.version>8.2.0</jmc.version>

<org.apache.maven.plugins.compiler.version>3.11.0</org.apache.maven.plugins.compiler.version>
<org.apache.maven.plugins.surefire.version>3.0.0</org.apache.maven.plugins.surefire.version>
Expand Down
264 changes: 206 additions & 58 deletions src/main/java/io/cryostat/core/reports/InterruptibleReportGenerator.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.openjdk.jmc.common.unit.UnitLookup.BYTE;
import static org.openjdk.jmc.common.unit.UnitLookup.DAY;
import static org.openjdk.jmc.common.unit.UnitLookup.EPOCH_MS;
import static org.openjdk.jmc.common.unit.UnitLookup.EPOCH_NS;
import static org.openjdk.jmc.common.unit.UnitLookup.HOUR;
import static org.openjdk.jmc.common.unit.UnitLookup.MEMORY;
import static org.openjdk.jmc.common.unit.UnitLookup.MINUTE;
Expand Down Expand Up @@ -270,7 +271,7 @@ public IQuantity parsePersisted(String persistedValue) throws QuantityConversion
}

public final static IConstraint<IQuantity> POSITIVE_TIMESPAN = new ComparableConstraint<>(
new TimePersisterBrokenSI(), SECOND.quantity(0), YEAR.quantity(200));
new TimePersisterBrokenSI(), SECOND.quantity(0), EPOCH_NS.quantity(Long.MAX_VALUE));
public final static IConstraint<IQuantity> PERIOD_V1 = new ComparableConstraint<>(new PeriodPersister(),
NANOSECOND.quantity(1), YEAR.quantity(1));
public final static IConstraint<IQuantity> PERIOD_V2 = new ComparableConstraint<>(new PeriodPersisterV2(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -39,7 +39,6 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -243,7 +242,7 @@ public static Set<String> createQualifiedVariableSet(
}
}
}
Collections.sort(variables);
variables.sort(null);
return new LinkedHashSet<>(variables);
}

Expand All @@ -263,5 +262,4 @@ private static URI createTrailingSlashURI(String uri) {
}
return URI.create(uri + '/');
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -50,6 +50,7 @@
import java.util.Map;
import java.util.Observable;
import java.util.Stack;
import java.util.logging.Logger;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
Expand Down Expand Up @@ -259,9 +260,10 @@ public void saveToFile(File file) throws IOException {
// NOTE: The pretty printer writes that the encoding is UTF-8, so we must make sure it is.
// Ensure charset exists before opening file for writing.
Charset charset = Charset.forName("UTF-8"); //$NON-NLS-1$
Writer osw = new OutputStreamWriter(new FileOutputStream(file), charset);
if (writeTo(osw)) {
setDirty(false);
try (Writer osw = new OutputStreamWriter(new FileOutputStream(file), charset)) {
if (writeTo(osw)) {
setDirty(false);
}
}
}

Expand All @@ -275,15 +277,12 @@ public void saveToFile(File file) throws IOException {
* @return true iff the model was successfully written to the {@link Writer}.
*/
public boolean writeTo(Writer writer) {
PrintWriter pw = new PrintWriter(writer);
try {
try (PrintWriter pw = new PrintWriter(writer)) {
PrettyPrinter pp = new PrettyPrinter(pw, m_validator.getElementsTooKeepOnOneLine());
pp.print(this);
pw.flush();
// PrintWriter never throws any exceptions, so this is how we find out if something went wrong.
return !pw.checkError();
} finally {
IOToolkit.closeSilently(pw);
}
}

Expand Down Expand Up @@ -321,8 +320,9 @@ public void checkErrors() {
// NOTE: This will only keep one result per node, although many may have been found.
m_resultLookup.put(r.getObject(), r);
if (r.isError()) {
// FIXME: Get a logger when this is in a better bundle.
System.out.println(r.getObject() + ": " + r.getText()); //$NON-NLS-1$
Logger logger = Logger
.getLogger("org.openjdk.jmc.flightrecorder.controlpanel.ui.configuration.model.xml"); //$NON-NLS-1$
logger.severe(r.getObject() + ": " + r.getText()); //$NON-NLS-1$
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,15 @@ public final class EventConfiguration implements IEventConfiguration {

public static void validate(InputStream xmlStream, String streamName, SchemaVersion version)
throws ParseException, IOException {
InputStream schemaStream = version.createSchemaStream();
if (schemaStream != null) {
try {
try (InputStream schemaStream = version.createSchemaStream()) {
if (schemaStream != null) {
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); //$NON-NLS-1$
XMLModel.validate(xmlStream, streamName, schemaFactory.newSchema(new StreamSource(schemaStream)));
} catch (SAXException e) {
throw new IOException("Trouble parsing schema for version " + version, e); //$NON-NLS-1$
} finally {
IOToolkit.closeSilently(schemaStream);
} else {
throw new IOException("Could not locate schema for version " + version); //$NON-NLS-1$
}
} else {
throw new IOException("Could not locate schema for version " + version); //$NON-NLS-1$
} catch (SAXException e) {
throw new IOException("Trouble parsing schema for version " + version, e); //$NON-NLS-1$
}
}

Expand All @@ -140,7 +137,9 @@ public static XMLModel createModel(String xmlText) throws ParseException, IOExce
}

public static XMLModel createModel(File file) throws FileNotFoundException, IOException, ParseException {
return createModel(new FileInputStream(file));
try (FileInputStream fis = new FileInputStream(file)) {
return createModel(fis);
}
}

public static XMLModel createModel(InputStream inStream) throws IOException, ParseException {
Expand Down Expand Up @@ -542,8 +541,8 @@ public boolean equalSettings(IEventConfiguration other) {
* We're doing this last as it might be expensive. Otherwise, we could just have called
* equals() on the maps.
*/
return ourOptions.keySet().size() == other.getEventOptions(ourOptions.emptyWithSameConstraints())
.keySet().size();
return ourOptions.keySet().size() == other.getEventOptions(ourOptions.emptyWithSameConstraints()).keySet()
.size();
}

public Set<IEventTypeID> getConfigEventTypes() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/openjdk/jmc/jdp/client/JDPClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/openjdk/jmc/jdp/common/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -43,6 +43,7 @@ public interface Configuration {
public static final short DEFAULT_TTL = 0;
public static final String DEFAULT_MULTICAST_ADDRESS = "224.0.23.178"; //$NON-NLS-1$
public static final int DEFAULT_MAX_HEART_BEAT_TIMEOUT = 12000;
public static final boolean DEFAULT_JDP_ENABLE_AUTO_DISCOVERY = false;

/**
* The multicast group to join.
Expand Down
37 changes: 34 additions & 3 deletions src/main/java/org/openjdk/jmc/rjmx/ConnectionToolkit.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -56,6 +56,7 @@
import org.openjdk.jmc.common.version.JavaVMVersionToolkit;
import org.openjdk.jmc.common.version.JavaVersion;
import org.openjdk.jmc.rjmx.internal.RJMXConnection;
import org.openjdk.jmc.ui.common.jvm.JVMDescriptor;

/**
* Toolkit providing utility methods to retrieve MBean proxy objects, invoke JMX operations and
Expand Down Expand Up @@ -346,7 +347,6 @@ public static int getDefaultPort() {
* otherwise.
*/
public static boolean isJRockit(IConnectionHandle connectionHandle) {

String vmName = getVMName(connectionHandle);
return JavaVMVersionToolkit.isJRockitJVMName(vmName);
}
Expand All @@ -365,6 +365,38 @@ public static boolean isHotSpot(IConnectionHandle connectionHandle) {
return vmName != null && JavaVMVersionToolkit.isHotspotJVMName(vmName);
}

/**
* Returns {@code true} if the connection handle is associated with an Oracle built JVM,
* {@code false} otherwise. If the information is already present in the {@link JVMDescriptor},
* this method will not cause any JMXRMI calls. If the information is lacking, an attempt will
* be made to look it up in the connected JVM. If the attempt fails, false will be returned.
*
* @return {@code true} if the connection handle describes an Oracle JVM, or {@code false}
* otherwise or if it could not be determined.
*/
public static boolean isOracle(IConnectionHandle handle) {
JVMDescriptor descriptor = handle.getServerDescriptor().getJvmInfo();
// This should normally not happen for discovered JVMs, but users can create custom connections
String name = null;
if (descriptor != null) {
name = descriptor.getJvmName();
} else {
// We try checking if connected
if (handle.isConnected()) {
MBeanServerConnection connection = handle.getServiceOrNull(MBeanServerConnection.class);
if (connection != null) {
try {
name = getRuntimeBean(connection).getVmName();
} catch (IOException e) {
// Worst case we classify JVM name wrong
RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not check if Oracle JVM", e);
}
}
}
}
return name != null && (name.contains("Java HotSpot"));
}

/**
* This will return true if the java version is above or equal the supplied value. (For example
* 1.7.0_40).
Expand Down Expand Up @@ -411,5 +443,4 @@ private static JavaVersion getJavaVersion(IConnectionHandle connectionHandle) {
}
return null;
}

}
25 changes: 23 additions & 2 deletions src/main/java/org/openjdk/jmc/rjmx/JVMSupportToolkit.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -83,6 +83,27 @@ public static String[] checkConsoleSupport(IConnectionHandle connection) {
return new String[0];
}

/**
* Checks if Flight Recorder is available for use
*
* @param connection
* @return If it is an Oracle JVM or there is a FlightRecorder VM option, then return true.
* Otherwise, return false. This is used for verifying JDK 8 JVMs that are not built
* with JFR enabled, e.g., OpenJDK 8
*/
public static boolean hasFlightRecorder(IConnectionHandle connection) {
if (ConnectionToolkit.isOracle(connection)) {
return true;
}
MBeanServerConnection server = connection.getServiceOrNull(MBeanServerConnection.class);
try {
HotspotManagementToolkit.getVMOption(server, "FlightRecorder");
return true;
} catch (Exception e) { // RuntimeMBeanException thrown if FlightRecorder is not present
return false;
}
}

/**
* Checks if Flight Recorder is disabled.
*
Expand Down Expand Up @@ -136,7 +157,7 @@ public static String getNoFlightRecorderErrorMessage(IConnectionHandle handle, b
}

/**
* Returns information about whether to server denoted by the handle supports Flight Recorder
* Returns information about whether the server supports Flight Recorder.
*
* @param handle
* the server to check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -56,4 +56,37 @@ public static void setup() {
}
}

public static void clearJMXRMISystemProperties() {
try {
Properties jmxRmiProperties = JMXRMIPreferences.getInstance().getProperties();
if (jmxRmiProperties != null) {
for (String prop : jmxRmiProperties.stringPropertyNames()) {
System.clearProperty(prop);
}
}
} catch (Exception e) {
RJMXPlugin.getDefault().getLogger().log(Level.FINE, "Failed to remove JMXRMI SystemProperties", e); //$NON-NLS-1$
}
}

public static boolean isKeyStoreConfigured() {
try {
Properties jmxRmiProperties = JMXRMIPreferences.getInstance().getProperties();
if (jmxRmiProperties != null) {
int totalPrefCnt = 0;
for (String prop : jmxRmiProperties.stringPropertyNames()) {
Object val = jmxRmiProperties.get(prop);
if (val != null && !val.toString().isEmpty()) {
++totalPrefCnt;
}
}
if (totalPrefCnt == 4) {
return true;
}
}
} catch (Exception e) {
RJMXPlugin.getDefault().getLogger().log(Level.FINE, "Did not load jmxRmiProperties", e); //$NON-NLS-1$
}
return false;
}
}
Loading

0 comments on commit 2336321

Please sign in to comment.