[rhq] Branch 'release/jon3.1.x' - modules/plugins
by Larry O'Leary
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/WebRuntimeComponent.java | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
New commits:
commit 37bd3a21cfc97e7fe984da6fcddfe78abcd9be19
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Mon Oct 8 17:48:27 2012 -0400
[BZ 864213] fix the web resource's ability to collect response time data.
(cherry picked from master commit b44ad1b934bbc80a52bfa1d4202294a63a94802c)
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/WebRuntimeComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/WebRuntimeComponent.java
index df9da3a..072f4d7 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/WebRuntimeComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/WebRuntimeComponent.java
@@ -19,6 +19,7 @@
package org.rhq.modules.plugins.jbossas7;
import java.io.File;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
@@ -77,7 +78,14 @@ public class WebRuntimeComponent extends BaseComponent<BaseComponent<?>> {
}
@Override
- public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> requests) throws Exception {
+ public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> origReqs) throws Exception {
+ // make our own copy so, as we iterate, we can remove the item that we can process,
+ // which will leave the rest for super.getValues() to process
+ HashSet<MeasurementScheduleRequest> requests;
+ requests = new HashSet<MeasurementScheduleRequest>(origReqs.size());
+ requests.addAll(origReqs);
+
+ // now process schedule requests
for (Iterator<MeasurementScheduleRequest> iterator = requests.iterator(); iterator.hasNext(); ) {
MeasurementScheduleRequest request = iterator.next();
if (request.getName().equals(RESPONSE_TIME_METRIC)) {
11 years, 4 months
[rhq] Changes to 'spinder/criteriaUsage'
by Simeon Pinder
New branch 'spinder/criteriaUsage' available with the following commits:
commit b7c248012959381e365b1afca4a01a373ed12755
Author: Simeon Pinder <spinder(a)fulliautomatix.conchfritter.com>
Date: Mon Feb 4 16:54:58 2013 -0500
update default criteria instances in the server side plugins as code already assumes as much.
commit b42ab9daa335de32779daf8d0563f5720afe9dca
Author: Simeon Pinder <spinder(a)fulliautomatix.conchfritter.com>
Date: Mon Feb 4 16:36:42 2013 -0500
update some more usages of Criteria to return all results as code already assumes this.
commit 6f83ea4895cf4fe44e569d0fd837a4c78353c2b5
Author: Simeon Pinder <spinder(a)fulliautomatix.conchfritter.com>
Date: Mon Feb 4 16:09:35 2013 -0500
Modify criteria to return all instances as logic assumes as much.
commit 0ffe7828cbd10a63142e1fa3b69b8bac05d61565
Author: Simeon Pinder <spinder(a)fulliautomatix.conchfritter.com>
Date: Mon Feb 4 15:54:23 2013 -0500
modify ResourceClientProxy to now process all child resources.
commit 9fcf54993de428e43db31366345ab6fd25dddb5a
Author: Simeon Pinder <spinder(a)fulliautomatix.conchfritter.com>
Date: Mon Feb 4 15:37:01 2013 -0500
Reverting " update ResourceClientProxy to handle larger metric definition results." as this approach is particularly problematic to implement when i)the same processed elements could be available in subsequent chunk queries and with ii)large deployments when parsing full list or resources can take long enough to span other transactions.
This reverts commit 42d955fc9e59c1ae0a1e69aead9c0d25fca60ba6.
commit 42d955fc9e59c1ae0a1e69aead9c0d25fca60ba6
Author: Simeon Pinder <spinder(a)fulliautomatix.conchfritter.com>
Date: Fri Feb 1 09:25:14 2013 -0500
update ResourceClientProxy to handle larger metric definition results.
11 years, 4 months
[rhq] modules/core modules/plugins
by lkrejci
modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/util/JavaCommandLine.java | 200 ++++
modules/core/plugin-api/src/test/java/org/rhq/core/pluginapi/util/JavaCommandLineTest.java | 4
modules/plugins/jboss-as-7/pom.xml | 46 +
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AS7CommandLine.java | 52 -
modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/AS7CommandLineTest.java | 402 +++++++++-
5 files changed, 635 insertions(+), 69 deletions(-)
New commits:
commit 2910d155e509b6ebccdc9483a70b2910bdf0133c
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Mon Feb 4 18:53:21 2013 +0100
[BZ 907558] - JavaCommandLine and subclasses now parse the commandline lazily
to prevent calling overriden methods in super-class constructor.
A couple of other cosmetic improvements like static logger, etc.
diff --git a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/util/JavaCommandLine.java b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/util/JavaCommandLine.java
index 3319500..add1a3a 100644
--- a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/util/JavaCommandLine.java
+++ b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/util/JavaCommandLine.java
@@ -28,10 +28,13 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Pattern;
import com.sun.istack.Nullable;
@@ -49,11 +52,19 @@ import org.jetbrains.annotations.NotNull;
* or java [-options] -jar jarfile [args...]
* (to execute a jar file)
* </code></pre>
+ * <p>
+ * Note that this class offers the subclasses to ehance the parsing process by overriding the {@link #processClassArgument(String, String)}
+ * method. To be able to achieve that, the evaluation of the commandline arguments needs to happen lazily.
+ * See the {@link #parseCommandLine()} method for subclassing guidelines.
+ * <p>
+ * This class is <b>NOT</b> thread-safe.
*
* @author Ian Springer
+ * @author Lukas Krejci
*/
public class JavaCommandLine {
- /**
+
+ /**
* When parsing command line options, specifies the valid option value delimiter(s).
*
* @see JavaCommandLine#getClassOption(CommandLineOption)
@@ -74,9 +85,18 @@ public class JavaCommandLine {
private static final String SHORT_OPTION_PREFIX = "-";
private static final String LONG_OPTION_PREFIX = "--";
- private final Log log = LogFactory.getLog(JavaCommandLine.class);
+ private static final Pattern SYSTEM_PROPERTY_PATTERN = Pattern.compile("-D.+");
+
+ private static final Log log = LogFactory.getLog(JavaCommandLine.class);
+
+ //These properties are passed to the constructors
+ private final List<String> arguments;
+ private final boolean includeSystemPropertiesFromClassArguments;
+ private final Set<OptionValueDelimiter> shortClassOptionValueDelims;
+ private final Set<OptionValueDelimiter> longClassOptionValueDelims;
- private List<String> arguments;
+ //These are lazily evaluated in the getters
+ private boolean argumentsParsed;
private File javaExecutable;
private List<String> classPath;
private Map<String, String> systemProperties;
@@ -84,9 +104,6 @@ public class JavaCommandLine {
private String mainClassName;
private File executableJarFile;
private List<String> classArguments;
- private boolean includeSystemPropertiesFromClassArguments;
- private Set<OptionValueDelimiter> shortClassOptionValueDelims;
- private Set<OptionValueDelimiter> longClassOptionValueDelims;
private Map<String, String> shortClassOptionNameToOptionValueMap;
private Map<String, String> longClassOptionNameToOptionValueMap;
@@ -132,16 +149,49 @@ public class JavaCommandLine {
// Wrap as list and store as field for use by getArguments() and toString().
this.arguments = Arrays.asList(args);
-
- parseCommandLine(args);
}
- private void parseCommandLine(String[] args) {
+ /**
+ * This method can be called to process the command line from the arguments passed in the constructor.
+ * This is to support lazy evaluation of the parsed properties.
+ * <p>
+ * Any class overriding the {@link #processClassArgument(String, String)} method should make sure to call this method
+ * if it finds that the data extracted in that method is still uninitialized.
+ * <p>
+ * Typically, this will happen during a getter for such data:
+ * <pre>
+ * <code>
+ * public Data getDataExtractedFromCommandLine() {
+ * if (data == null) {
+ * parseCommandLine();
+ * }
+ *
+ * return data;
+ * }
+ * </code>
+ * </pre>
+ *
+ * The data variable would then be initialized as part of the {@link #processClassArgument(String, String)} method
+ * that gets called during the execution of this method.
+ * <p>
+ * Alternatively to the null check on the data, the subclass can use the {@link #isArgumentsParsed()} method that
+ * returns true only if this method successfully finished.
+ * <p>
+ * If you are overriding this method make sure to call <code>super.parseCommandLine()</code> before any of your other
+ * logic, otherwise you may end up with an <b>endless loop</b> (and eventually stack overflow) if you try to access
+ * any of the getters of the data extracted from the commandline (like {@link #getClassArguments()},
+ * {@link #getClassPath()}, etc).
+ */
+ protected void parseCommandLine() {
if (log.isDebugEnabled()) {
log.debug("Parsing " + this + "...");
}
- this.javaExecutable = new File(args[0]);
+ ListIterator<String> argIterator = arguments.listIterator();
+ ListIterator<String> classArgumentsIterator = arguments.listIterator();
+
+ this.javaExecutable = new File(argIterator.next());
+
this.classPath = new ArrayList<String>();
this.systemProperties = new LinkedHashMap<String, String>();
this.javaOptions = new ArrayList<String>();
@@ -149,26 +199,31 @@ public class JavaCommandLine {
boolean nextArgIsClassPath = false;
boolean nextArgIsJarFile = false;
- for (int i = 1; i < args.length; i++) {
- String arg = args[i];
+
+ while (argIterator.hasNext()) {
+ String arg = argIterator.next();
+
+ //skip along with the main iterator... once we break out of this loop, this iterator
+ //will point to the start of the class arguments.
+ classArgumentsIterator.next();
if (nextArgIsClassPath) {
this.classPath.addAll(Arrays.asList(arg.split(File.pathSeparator)));
nextArgIsClassPath = false;
} else if (nextArgIsJarFile) {
this.executableJarFile = new File(arg);
- parseClassArguments(args, i + 1);
+ parseClassArguments(argIterator, true);
break;
} else if (arg.charAt(0) != '-') {
this.mainClassName = arg;
- parseClassArguments(args, i + 1);
+ parseClassArguments(argIterator, true);
break;
} else if (arg.equals("-cp") || arg.equals("-classpath")) {
- if ((i + 1) == args.length) {
+ if (!argIterator.hasNext()) {
throw new IllegalArgumentException(arg + " option has no argument.");
}
nextArgIsClassPath = true;
} else if (arg.equals("-jar")) {
- if ((i + 1) == args.length) {
+ if (!argIterator.hasNext()) {
throw new IllegalArgumentException(arg + " option has no argument.");
}
nextArgIsJarFile = true;
@@ -180,26 +235,81 @@ public class JavaCommandLine {
}
}
+ parseClassOptions();
+
+ argumentsParsed = true;
+
+ if (classArgumentsIterator.hasNext()) {
+ parseClassArguments(classArgumentsIterator, false);
+ }
+
this.classPath = Collections.unmodifiableList(this.classPath);
this.javaOptions = Collections.unmodifiableList(this.javaOptions);
this.classArguments = Collections.unmodifiableList(this.classArguments);
this.systemProperties = Collections.unmodifiableMap(this.systemProperties);
+ }
- parseClassOptions();
+ /**
+ * @return true iff the {@link #parseCommandLine()} method was called and successfully finished.
+ */
+ protected boolean isArgumentsParsed() {
+ return argumentsParsed;
}
- private void parseClassArguments(String[] args, int beginIndex) {
- for (int i = beginIndex; i < args.length; i++) {
- String classArg = args[i];
- processClassArgument(classArg, ((i + 1) != args.length) ? args[i + 1] : null);
+ private void parseClassArguments(Iterator<String> arguments, boolean firstPass) {
+ if (!arguments.hasNext()) {
+ return;
+ }
+
+ //as strange as it seems, this adds each and every argument found in
+ //arguments as a class argument.
+ //Additionally, it will call processClassArgument() with every such class argument and the next argument in line.
+
+ String classArg = arguments.next();
+
+ while (arguments.hasNext()) {
+ String nextArg = arguments.next();
+
+ processClassArgument(classArg, nextArg, firstPass);
+
+ classArg = nextArg;
+ }
+
+ processClassArgument(classArg, null, firstPass);
+ }
+
+ private void processClassArgument(String classArg, String nextArg, boolean firstPass) {
+ if (firstPass) {
+ //in first pass, we do the processing required by this class
+ if (this.includeSystemPropertiesFromClassArguments && isSystemPropertyArgument(classArg)) {
+ parseSystemPropertyArgument(classArg);
+ }
+
this.classArguments.add(classArg);
+ } else {
+ //in the second pass, we let the subclasses process the class arguments
+ processClassArgument(classArg, nextArg);
}
}
+ /**
+ * Override this method to do additional processing of the class arguments.
+ * This method is called during the {@link #parseCommandLine()} call but after all other properties are processed.
+ * <p>
+ * It is therefore safe to call {@link #getClassArguments()}, {@link #getExecutableJarFile()} and all other getters
+ * defined by {@link JavaCommandLine}. At the time this method is called during {@link #parseCommandLine()}, the
+ * default implementation of {@link #isArgumentsParsed()} already returns true.
+ * <p>
+ * This method is called at a stage during the parsing of the commandline where all the properties are still writeable
+ * - you can modify the {@link #getSystemProperties() system properties} and other collections.
+ * <p>
+ * By default this method does nothing.
+ *
+ * @param classArg
+ * @param nextArg
+ */
protected void processClassArgument(String classArg, String nextArg) {
- if (this.includeSystemPropertiesFromClassArguments && isSystemPropertyArgument(classArg)) {
- parseSystemPropertyArgument(classArg);
- }
+ //do nothing by default.
}
private void parseClassOptions() {
@@ -285,7 +395,7 @@ public class JavaCommandLine {
}
private boolean isSystemPropertyArgument(String arg) {
- return arg.matches("-D.+");
+ return SYSTEM_PROPERTY_PATTERN.matcher(arg).matches();
}
private void parseSystemPropertyArgument(String arg) {
@@ -310,36 +420,64 @@ public class JavaCommandLine {
@NotNull
public File getJavaExecutable() {
+ if (!argumentsParsed) {
+ parseCommandLine();
+ }
+
return javaExecutable;
}
@NotNull
public List<String> getClassPath() {
+ if (!argumentsParsed) {
+ parseCommandLine();
+ }
+
return classPath;
}
@NotNull
public Map<String, String> getSystemProperties() {
+ if (!argumentsParsed) {
+ parseCommandLine();
+ }
+
return systemProperties;
}
@NotNull
public List<String> getJavaOptions() {
+ if (!argumentsParsed) {
+ parseCommandLine();
+ }
+
return javaOptions;
}
@Nullable
public String getMainClassName() {
+ if (!argumentsParsed) {
+ parseCommandLine();
+ }
+
return mainClassName;
}
@Nullable
public File getExecutableJarFile() {
+ if (!argumentsParsed) {
+ parseCommandLine();
+ }
+
return executableJarFile;
}
@NotNull
public List<String> getClassArguments() {
+ if (!argumentsParsed) {
+ parseCommandLine();
+ }
+
return classArguments;
}
@@ -351,6 +489,10 @@ public class JavaCommandLine {
*/
@Nullable
public String getClassOption(CommandLineOption option) {
+ if (!argumentsParsed) {
+ parseCommandLine();
+ }
+
return getClassOption(option, null);
}
@@ -363,6 +505,10 @@ public class JavaCommandLine {
*/
@Nullable
public String getClassOption(CommandLineOption option, String defaultValue) {
+ if (!argumentsParsed) {
+ parseCommandLine();
+ }
+
String optionValue = null;
// Note, we never store null values in either of the option value maps.
@@ -403,6 +549,10 @@ public class JavaCommandLine {
}
public boolean isClassOptionPresent(CommandLineOption option) {
+ if (!argumentsParsed) {
+ parseCommandLine();
+ }
+
String optionValue = getClassOption(option);
return (optionValue != null);
}
diff --git a/modules/core/plugin-api/src/test/java/org/rhq/core/pluginapi/util/JavaCommandLineTest.java b/modules/core/plugin-api/src/test/java/org/rhq/core/pluginapi/util/JavaCommandLineTest.java
index a8bab91..5f6a387 100644
--- a/modules/core/plugin-api/src/test/java/org/rhq/core/pluginapi/util/JavaCommandLineTest.java
+++ b/modules/core/plugin-api/src/test/java/org/rhq/core/pluginapi/util/JavaCommandLineTest.java
@@ -39,12 +39,12 @@ public class JavaCommandLineTest {
@Test(expectedExceptions = {IllegalArgumentException.class})
public void testNullArrayParam() throws Exception {
- JavaCommandLine javaCommandLine = new JavaCommandLine(null);
+ new JavaCommandLine((String[])null);
}
@Test(expectedExceptions = {IllegalArgumentException.class})
public void testEmptyArrayParam() throws Exception {
- JavaCommandLine javaCommandLine = new JavaCommandLine(new String[0]);
+ new JavaCommandLine(new String[0]);
}
public void testClass() throws Exception {
diff --git a/modules/plugins/jboss-as-7/pom.xml b/modules/plugins/jboss-as-7/pom.xml
index bee2bbb..75d5b51 100644
--- a/modules/plugins/jboss-as-7/pom.xml
+++ b/modules/plugins/jboss-as-7/pom.xml
@@ -108,6 +108,14 @@
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
+
+ <!-- For native subsystem -->
+ <dependency>
+ <groupId>org.hyperic</groupId>
+ <artifactId>sigar-dist</artifactId>
+ <type>zip</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
@@ -166,9 +174,47 @@
-->
<exclude>org/rhq/modules/plugins/jbossas7/itest/**</exclude>
</excludes>
+ <!-- This is where the antrun below puts the sigar native libs -->
+ <argLine>${jacoco.unit-test.args} -Djava.library.path=${project.build.directory}/test-libs</argLine>
</configuration>
</plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>deploy-sigar-native-to-test-classpath</id>
+ <phase>generate-test-resources</phase>
+ <configuration>
+ <tasks>
+ <echo>Copying SIGAR native libs to test-libs</echo>
+ <unzip dest="${project.build.directory}/test-libs">
+ <fileset
+ dir="${settings.localRepository}/org/hyperic/sigar-dist/${sigar.version}"
+ includes="*.zip"/>
+ <patternset>
+ <include name="**/lib/sigar.jar"/>
+ <include name="**/lib/bcel*.jar"/>
+ <include name="**/lib/*.so"/>
+ <include name="**/lib/*.sl"/>
+ <include name="**/lib/*.dll"/>
+ <include name="**/lib/*.dylib"/>
+ </patternset>
+ </unzip>
+ <move todir="${project.build.directory}/test-libs" flatten="true">
+ <fileset dir="${project.build.directory}/test-libs">
+ <include name="**/lib/*"/>
+ </fileset>
+ </move>
+ <delete dir="${project.build.directory}/test-libs/hyperic-sigar-${sigar.version}"/>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AS7CommandLine.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AS7CommandLine.java
index b44ceb3..cd654fa 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AS7CommandLine.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/AS7CommandLine.java
@@ -58,7 +58,7 @@ public class AS7CommandLine extends JavaCommandLine {
"--" + PROPERTIES_OPTION.getLongName()
};
- private final Log log = LogFactory.getLog(AS7CommandLine.class);
+ private static final Log LOG = LogFactory.getLog(AS7CommandLine.class);
private String appServerModuleName;
private List<String> appServerArgs;
@@ -72,8 +72,30 @@ public class AS7CommandLine extends JavaCommandLine {
public AS7CommandLine(ProcessInfo process) {
this(process.getCommandLine());
-
this.process = process;
+ }
+
+ @NotNull
+ public String getAppServerModuleName() {
+ if (!isArgumentsParsed()) {
+ parseCommandLine();
+ }
+
+ return this.appServerModuleName;
+ }
+
+ @NotNull
+ public List<String> getAppServerArguments() {
+ if (!isArgumentsParsed()) {
+ parseCommandLine();
+ }
+
+ return this.appServerArgs;
+ }
+
+ @Override
+ protected void parseCommandLine() {
+ super.parseCommandLine();
// In the case of AS7, the class arguments are actually the arguments to the jboss-modules.jar main class. We
// want to split out the arguments to the app server module (i.e. "org.jboss.as.standalone" or
@@ -101,16 +123,6 @@ public class AS7CommandLine extends JavaCommandLine {
}
}
- @NotNull
- public String getAppServerModuleName() {
- return this.appServerModuleName;
- }
-
- @NotNull
- public List<String> getAppServerArguments() {
- return this.appServerArgs;
- }
-
@Override
protected void processClassArgument(String classArg, String nextArg) {
super.processClassArgument(classArg, nextArg);
@@ -133,8 +145,8 @@ public class AS7CommandLine extends JavaCommandLine {
if (propertiesURL != null) {
Properties props = loadProperties(propertiesURL);
if (props != null) {
- for (Map.Entry entry : props.entrySet()) {
- Map<String, String> sysProps = getSystemProperties();
+ Map<String, String> sysProps = getSystemProperties();
+ for (Map.Entry<?, ?> entry : props.entrySet()) {
sysProps.put((String) entry.getKey(), (String) entry.getValue());
}
}
@@ -163,7 +175,7 @@ public class AS7CommandLine extends JavaCommandLine {
propertiesURL = absoluteFile.toURI().toURL();
} catch (MalformedURLException murle2) {
propertiesURL = null;
- log.error("Value of class option " + PROPERTIES_OPTION + " (" + value + ") is not a valid URL.");
+ LOG.error("Value of class option " + PROPERTIES_OPTION + " (" + value + ") is not a valid URL.");
}
}
@@ -182,7 +194,7 @@ public class AS7CommandLine extends JavaCommandLine {
File binDir = new File(homeDir, "bin");
absoluteFile = new File(binDir, file.getPath());
} else {
- log.error("Failed to resolve relative properties file path [" + file + "].");
+ LOG.error("Failed to resolve relative properties file path [" + file + "].");
return null;
}
}
@@ -198,18 +210,18 @@ public class AS7CommandLine extends JavaCommandLine {
try {
urlConnection = propertiesURL.openConnection();
} catch (IOException e) {
- log.error("Failed to connect to URL [" + propertiesURL + "].", e);
+ LOG.error("Failed to connect to URL [" + propertiesURL + "].", e);
return null;
}
InputStream inputStream;
try {
inputStream = urlConnection.getInputStream();
if (inputStream == null) {
- log.error("Failed to read from URL [" + propertiesURL + "].");
+ LOG.error("Failed to read from URL [" + propertiesURL + "].");
return null;
}
} catch (IOException e) {
- log.error("Failed to read from URL [" + propertiesURL + "].", e);
+ LOG.error("Failed to read from URL [" + propertiesURL + "].", e);
return null;
}
@@ -217,7 +229,7 @@ public class AS7CommandLine extends JavaCommandLine {
try {
props.load(inputStream);
} catch (IOException e) {
- log.error("Failed to parse properties from URL [" + propertiesURL + "].", e);
+ LOG.error("Failed to parse properties from URL [" + propertiesURL + "].", e);
return null;
}
return props;
diff --git a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/AS7CommandLineTest.java b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/AS7CommandLineTest.java
index 02084a9..bb8adcd 100644
--- a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/AS7CommandLineTest.java
+++ b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/AS7CommandLineTest.java
@@ -23,48 +23,334 @@
package org.rhq.modules.plugins.jbossas7;
import java.io.File;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import org.testng.Assert;
import org.testng.annotations.Test;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+
+import org.rhq.core.system.ProcessInfo;
+import org.rhq.core.system.SystemInfo;
+import org.rhq.core.system.SystemInfoFactory;
import org.rhq.core.util.PropertiesFileUpdate;
+import org.rhq.core.util.stream.StreamUtil;
/**
* A unit test for {@link AS7CommandLine}.
*/
-@Test
public class AS7CommandLineTest {
+ private static final File FAKE_JBOSS_HOME = new File(".");
+
+ private interface CommandLineProducer {
+ AS7CommandLine get();
+ }
+
+ public static class FakeServerProcess {
+ ProcessInfo processInfo;
+ File fakeJBossModulesJar;
+
+ void cleanUp() throws Exception {
+ processInfo.kill("KILL");
+ fakeJBossModulesJar.delete();
+ }
+
+ //this used as a main class of the process that fakes a running AS7 server
+ //It just sits idle until killed (a featureful application server, indeed :) ).
+ public static synchronized void main(String[] args) throws Exception {
+ FakeServerProcess.class.wait();
+ }
+ }
+
+ @Test
+ public void testSysPropsWithAbsolutePathAndFileProtocolWithoutProcess() throws Exception {
+ File propsFile1 = File.createTempFile("jboss1-", ".properties");
+ File propsFile2 = File.createTempFile("jboss2-", ".properties");
+
+ String propsFile1Path = "file://" + propsFile1;
+ String propsFile2Path = "file://" + propsFile2;
+
+ try {
+ testSysProps(propsFile1, propsFile2, FAKE_JBOSS_HOME,
+ getAs7CommandLine(propsFile1Path, propsFile2Path, FAKE_JBOSS_HOME));
+ } finally {
+ propsFile1.delete();
+ propsFile2.delete();
+ }
+ }
+
+ @Test
+ public void testSysPropsWithRelativePathAndFileProtocolWithoutProcess() throws Exception {
+ File propsFile1 = File.createTempFile("jboss1-", ".properties", new File("."));
+ File propsFile2 = File.createTempFile("jboss2-", ".properties", new File("."));
+
+ //create the bin subdirectory so that the path deduced by AS7CommandLine can be traversed
+ new File("bin").mkdir();
+
+ //without the process, the AS7CommandLine tries to figure out the path as relative to $JBOSS_HOME/bin
+ //since we're assigning jboss home to "." and creating the file in ".", too, we need to prepend the
+ //path with a ".." to jump out of the assumed "bin".
+ String propsFile1Path = "file:../" + propsFile1.getName();
+ String propsFile2Path = "file:../" + propsFile2.getName();
+
+ try {
+ testSysProps(propsFile1, propsFile2, FAKE_JBOSS_HOME,
+ getAs7CommandLine(propsFile1Path, propsFile2Path, FAKE_JBOSS_HOME));
+ } finally {
+ propsFile1.delete();
+ propsFile2.delete();
+ new File("bin").delete();
+ }
+ }
+
+ @Test
+ public void testSysPropsWithAbsolutePathWithoutProcess() throws Exception {
+ File propsFile1 = File.createTempFile("jboss1-", ".properties");
+ File propsFile2 = File.createTempFile("jboss2-", ".properties");
+
+ String propsFile1Path = propsFile1.getAbsolutePath();
+ String propsFile2Path = propsFile2.getAbsolutePath();
+
+ try {
+ testSysProps(propsFile1, propsFile2, FAKE_JBOSS_HOME,
+ getAs7CommandLine(propsFile1Path, propsFile2Path, FAKE_JBOSS_HOME));
+ } finally {
+ propsFile1.delete();
+ propsFile2.delete();
+ }
+ }
+
+ @Test
+ public void testSysPropsWithRelativePathWithoutProcess() throws Exception {
+ File propsFile1 = File.createTempFile("jboss1-", ".properties", new File("."));
+ File propsFile2 = File.createTempFile("jboss2-", ".properties", new File("."));
+
+ //create the bin subdirectory so that the path deduced by AS7CommandLine can be traversed
+ new File("bin").mkdir();
+
+ //without the process, the AS7CommandLine tries to figure out the path as relative to $JBOSS_HOME/bin
+ //since we're assigning jboss home to "." and creating the file in ".", too, we need to prepend the
+ //path with a ".." to jump out of the assumed "bin".
+ String propsFile1Path = "../" + propsFile1.getName();
+ String propsFile2Path = "../" + propsFile2.getName();
+
+ try {
+ testSysProps(propsFile1, propsFile2, FAKE_JBOSS_HOME,
+ getAs7CommandLine(propsFile1Path, propsFile2Path, FAKE_JBOSS_HOME));
+ } finally {
+ propsFile1.delete();
+ propsFile2.delete();
+ new File("bin").delete();
+ }
+ }
+
+ @Test
+ public void testSysPropsWithAbsolutePathWithProcess() throws Exception {
+ File propsFile1 = File.createTempFile("jboss1-", ".properties");
+ File propsFile2 = File.createTempFile("jboss2-", ".properties");
+
+ String propsFile1Path = propsFile1.getAbsolutePath();
+ String propsFile2Path = propsFile2.getAbsolutePath();
+
+ FakeServerProcess fakeServer = startFakeServer(FAKE_JBOSS_HOME, FAKE_JBOSS_HOME, propsFile1Path, propsFile2Path);
+
+ Assert.assertNotNull(fakeServer, "Failed to start or find the fake server process.");
+
+ try {
+ testSysProps(propsFile1, propsFile2, FAKE_JBOSS_HOME, getAs7CommandLine(fakeServer));
+ } finally {
+ propsFile1.delete();
+ propsFile2.delete();
+ fakeServer.cleanUp();
+ }
+ }
+
+ @Test
+ public void testSysPropsWithAbsolutePathWithProcessFromDifferentDirectory() throws Exception {
+ File propsFile1 = File.createTempFile("jboss1-", ".properties");
+ File propsFile2 = File.createTempFile("jboss2-", ".properties");
+
+ String propsFile1Path = propsFile1.getAbsolutePath();
+ String propsFile2Path = propsFile2.getAbsolutePath();
+
+ FakeServerProcess fakeServer = startFakeServer(new File(".."), FAKE_JBOSS_HOME, propsFile1Path, propsFile2Path);
+
+ Assert.assertNotNull(fakeServer, "Failed to start or find the fake server process.");
+
+ try {
+ testSysProps(propsFile1, propsFile2, FAKE_JBOSS_HOME, getAs7CommandLine(fakeServer));
+ } finally {
+ propsFile1.delete();
+ propsFile2.delete();
+ fakeServer.cleanUp();
+ }
+ }
+
+ @Test
+ public void testSysPropsWithAbsolutePathAndFileProtocolWithProcess() throws Exception {
+ File propsFile1 = File.createTempFile("jboss1-", ".properties");
+ File propsFile2 = File.createTempFile("jboss2-", ".properties");
+
+ String propsFile1Path = "file://" + propsFile1;
+ String propsFile2Path = "file://" + propsFile2;
+
+ FakeServerProcess fakeServer = startFakeServer(FAKE_JBOSS_HOME, FAKE_JBOSS_HOME, propsFile1Path, propsFile2Path);
+
+ Assert.assertNotNull(fakeServer, "Failed to start or find the fake server process.");
+
+ try {
+ testSysProps(propsFile1, propsFile2, FAKE_JBOSS_HOME, getAs7CommandLine(fakeServer));
+ } finally {
+ propsFile1.delete();
+ propsFile2.delete();
+ fakeServer.cleanUp();
+ }
+ }
- public void testSysProps() throws Exception {
+ @Test
+ public void testSysPropsWithAbsolutePathAndFileProtocolWithProcessFromDifferentDirectory() throws Exception {
File propsFile1 = File.createTempFile("jboss1-", ".properties");
+ File propsFile2 = File.createTempFile("jboss2-", ".properties");
+
+ String propsFile1Path = "file://" + propsFile1;
+ String propsFile2Path = "file://" + propsFile2;
+
+ FakeServerProcess fakeServer = startFakeServer(new File(".."), FAKE_JBOSS_HOME, propsFile1Path, propsFile2Path);
+
+ Assert.assertNotNull(fakeServer, "Failed to start or find the fake server process.");
+
+ try {
+ testSysProps(propsFile1, propsFile2, FAKE_JBOSS_HOME, getAs7CommandLine(fakeServer));
+ } finally {
+ propsFile1.delete();
+ propsFile2.delete();
+ fakeServer.cleanUp();
+ }
+ }
+
+ @Test
+ public void testSysPropsWithRelativePathAndFileProtocolWithProcess() throws Exception {
+ File propsFile1 = File.createTempFile("jboss1-", ".properties", FAKE_JBOSS_HOME);
+ File propsFile2 = File.createTempFile("jboss2-", ".properties", FAKE_JBOSS_HOME);
+
+ String propsFile1Path = "file:./" + propsFile1.getName();
+ String propsFile2Path = "file:./" + propsFile2.getName();
+
+ FakeServerProcess fakeServer = startFakeServer(FAKE_JBOSS_HOME, FAKE_JBOSS_HOME, propsFile1Path, propsFile2Path);
+
+ Assert.assertNotNull(fakeServer, "Failed to start or find the fake server process.");
+
+ try {
+ testSysProps(propsFile1, propsFile2, FAKE_JBOSS_HOME, getAs7CommandLine(fakeServer));
+ } finally {
+ propsFile1.delete();
+ propsFile2.delete();
+ fakeServer.cleanUp();
+ }
+ }
+
+ @Test
+ public void testSysPropsWithRelativePathAndFileProtocolWithProcessFromDifferentDirectory() throws Exception {
+ File cwd = new File("..");
+ File propsFile1 = File.createTempFile("jboss1-", ".properties", cwd);
+ File propsFile2 = File.createTempFile("jboss2-", ".properties", cwd);
+
+ String propsFile1Path = "file:./" + propsFile1.getName();
+ String propsFile2Path = "file:./" + propsFile2.getName();
+
+ FakeServerProcess fakeServer = startFakeServer(cwd, FAKE_JBOSS_HOME, propsFile1Path, propsFile2Path);
+
+ Assert.assertNotNull(fakeServer, "Failed to start or find the fake server process.");
+
+ try {
+ testSysProps(propsFile1, propsFile2, FAKE_JBOSS_HOME, getAs7CommandLine(fakeServer));
+ } finally {
+ propsFile1.delete();
+ propsFile2.delete();
+ fakeServer.cleanUp();
+ }
+ }
+
+ @Test
+ public void testSysPropsWithRelativePathWithProcess() throws Exception {
+ File propsFile1 = File.createTempFile("jboss1-", ".properties", FAKE_JBOSS_HOME);
+ File propsFile2 = File.createTempFile("jboss2-", ".properties", FAKE_JBOSS_HOME);
+
+ String propsFile1Path = propsFile1.getName();
+ String propsFile2Path = propsFile2.getName();
+
+ FakeServerProcess fakeServer = startFakeServer(FAKE_JBOSS_HOME, FAKE_JBOSS_HOME, propsFile1Path, propsFile2Path);
+
+ Assert.assertNotNull(fakeServer, "Failed to start or find the fake server process.");
+
+ try {
+ testSysProps(propsFile1, propsFile2, FAKE_JBOSS_HOME, getAs7CommandLine(fakeServer));
+ } finally {
+ propsFile1.delete();
+ propsFile2.delete();
+ fakeServer.cleanUp();
+ }
+ }
+
+ @Test
+ public void testSysPropsWithRelativePathWithProcessFromDifferentDirectory() throws Exception {
+ File cwd = new File("..");
+ File propsFile1 = File.createTempFile("jboss1-", ".properties", cwd);
+ File propsFile2 = File.createTempFile("jboss2-", ".properties", cwd);
+ String propsFile1Path = propsFile1.getName();
+ String propsFile2Path = propsFile2.getName();
+
+ FakeServerProcess fakeServer = startFakeServer(cwd, FAKE_JBOSS_HOME, propsFile1Path, propsFile2Path);
+
+ Assert.assertNotNull(fakeServer, "Failed to start or find the fake server process.");
+
+ try {
+ testSysProps(propsFile1, propsFile2, FAKE_JBOSS_HOME, getAs7CommandLine(fakeServer));
+ } finally {
+ propsFile1.delete();
+ propsFile2.delete();
+ fakeServer.cleanUp();
+ }
+ }
+
+ private CommandLineProducer getAs7CommandLine(final String propsFile1Path, final String propsFile2Path,
+ final File jbossHome) {
+ return new CommandLineProducer() {
+ @Override
+ public AS7CommandLine get() {
+ return new AS7CommandLine(getCommandLine(jbossHome, propsFile1Path, propsFile2Path));
+ }
+ };
+ }
+
+ private CommandLineProducer getAs7CommandLine(final FakeServerProcess serverProcess) {
+ return new CommandLineProducer() {
+ @Override
+ public AS7CommandLine get() {
+ return new AS7CommandLine(serverProcess.processInfo);
+ }
+ };
+ }
+
+ private void testSysProps(File propsFile1, File propsFile2, File jbossHome, CommandLineProducer commandLine)
+ throws Exception {
PropertiesFileUpdate propsFile1Updater = new PropertiesFileUpdate(propsFile1.getPath());
propsFile1Updater.update("prop1", "delta");
propsFile1Updater.update("prop4", "epsilon");
- File propsFile2 = File.createTempFile("jboss2-", ".properties");
PropertiesFileUpdate propsFile2Updater = new PropertiesFileUpdate(propsFile1.getPath());
propsFile2Updater.update("prop2", "zeta");
propsFile2Updater.update("prop5", "eta");
- AS7CommandLine javaCommandLine = new AS7CommandLine(new String[] { //
- "/usr/java/default/bin/java", //
- "-D[Standalone]", //
- "-server", //
- "-Dprop1=alpha", //
- "-Dprop2=beta", //
- "-Dprop3=gamma", //
- "-jar", "/home/jboss/jboss-eap-6.0.0.ER6/jboss-modules.jar", //
- "-mp", "/home/jboss/jboss-eap-6.0.0.ER6/modules", //
- "-jaxpmodule", "javax.xml.jaxp-provider", //
- "org.jboss.as.standalone", //
- "-Djboss.home.dir=/home/jboss/jboss-eap-6.0.0.ER6", //
- "-Djboss.server.base.dir=/home/jboss/jboss-eap-6.0.0.ER6/standalone", //
- "-P", "file://" + propsFile1, //
- "--properties=file://" + propsFile2 //
- });
- Map<String,String> sysprops = javaCommandLine.getSystemProperties();
+ Map<String, String> sysprops = commandLine.get().getSystemProperties();
+
Assert.assertNotNull(sysprops);
Assert.assertEquals(sysprops.size(), 8);
Assert.assertEquals(sysprops.get("[Standalone]"), "");
@@ -73,8 +359,80 @@ public class AS7CommandLineTest {
Assert.assertEquals(sysprops.get("prop3"), "gamma");
Assert.assertEquals(sysprops.get("prop4"), "epsilon");
Assert.assertEquals(sysprops.get("prop5"), "eta");
- Assert.assertEquals(sysprops.get("jboss.home.dir"), "/home/jboss/jboss-eap-6.0.0.ER6");
- Assert.assertEquals(sysprops.get("jboss.server.base.dir"), "/home/jboss/jboss-eap-6.0.0.ER6/standalone");
+ Assert.assertEquals(sysprops.get("jboss.home.dir"), jbossHome.getAbsolutePath());
+ Assert.assertEquals(sysprops.get("jboss.server.base.dir"), new File(jbossHome, "standalone").getAbsolutePath());
+ }
+
+ private FakeServerProcess startFakeServer(File cwd, File jbossHome, String propsFile1Path, String propsFile2Path)
+ throws Exception {
+ //prepare the fake jboss-modules.jar
+ Class<?> mainClass = FakeServerProcess.class;
+ File jbossModulesJar = File.createTempFile("jboss-modules-fake", ".jar");
+
+ ShrinkWrap.create(JavaArchive.class).addClass(mainClass)
+ .setManifest(new StringAsset("Main-Class: " + mainClass.getName() + "\n")).as(ZipExporter.class)
+ .exportTo(jbossModulesJar, true);
+
+ String[] commandLine = getCommandLine(jbossModulesJar, jbossHome, propsFile1Path, propsFile2Path);
+
+ ProcessBuilder pb = new ProcessBuilder(commandLine);
+ Process process = pb.directory(cwd).start();
+
+ try {
+ int exitValue = process.exitValue();
+ String stdout = StreamUtil.slurp(new InputStreamReader(process.getInputStream()));
+ String stderr = StreamUtil.slurp(new InputStreamReader(process.getErrorStream()));
+
+ Assert
+ .fail("The fake jboss as server process has finished even though it should keep running. The exit value was "
+ + exitValue
+ + ". Stdout was:\n"
+ + stdout
+ + "\n\nStderr was:\n"
+ + stderr);
+ } catch (IllegalThreadStateException e) {
+ //expected
+ }
+
+ SystemInfo sysInfo = SystemInfoFactory.createSystemInfo();
+ List<ProcessInfo> processes = sysInfo.getAllProcesses();
+
+ for (ProcessInfo pi : processes) {
+ String[] cl = pi.getCommandLine();
+ if (Arrays.equals(cl, commandLine)) {
+ FakeServerProcess ret = new FakeServerProcess();
+ ret.fakeJBossModulesJar = jbossModulesJar;
+ ret.processInfo = pi;
+ return ret;
+ }
+ }
+
+ return null;
+ }
+
+ private String[] getCommandLine(File jbossHome, String propsFile1Path, String propsFile2Path) {
+ return getCommandLine(new File(jbossHome, "jboss-modules.jar"), jbossHome, propsFile1Path, propsFile2Path);
}
+ private String[] getCommandLine(File jbossModules, File jbossHome, String propsFile1Path, String propsFile2Path) {
+ return new String[] { //
+ "java", //
+ "-D[Standalone]", //
+ "-server", //
+ "-Dprop1=alpha", //
+ "-Dprop2=beta", //
+ "-Dprop3=gamma", //
+ "-jar", jbossModules.getAbsolutePath(), //
+ "-mp", new File(jbossHome, "modules").getAbsolutePath(), //
+ "-jaxpmodule", "javax.xml.jaxp-provider", //
+ "org.jboss.as.standalone", //
+ "-Djboss.home.dir=" + jbossHome.getAbsolutePath(), //
+ "-Djboss.server.base.dir=" + new File(jbossHome, "standalone").getAbsolutePath(), //
+ "-P", propsFile1Path, //
+ "--properties=" + propsFile2Path };
+ }
+
+ public static synchronized void main(String[] args) throws Exception {
+ AS7CommandLineTest.class.wait();
+ }
}
11 years, 4 months
[rhq] modules/enterprise
by Jiri Kremser
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/SchedulesDataSource.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
New commits:
commit e7c037254aeaaecf137ebaf78bd17a2155c0b8f4
Author: Jirka Kremser <jkremser(a)redhat.com>
Date: Mon Feb 4 13:30:11 2013 +0100
[BZ 907037 - Missing Column in Schedules Table] Schedule ID column added. By default it is a hidden field and if needed, it has to be enabled in the table header menu.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/SchedulesDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/SchedulesDataSource.java
index 74cdbe0..28bb202 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/SchedulesDataSource.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/SchedulesDataSource.java
@@ -49,7 +49,6 @@ import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
*/
public class SchedulesDataSource extends RPCDataSource<MeasurementScheduleComposite, Criteria> {
- public static final String ATTR_ID = "id";
public static final String ATTR_DATA_TYPE = MeasurementScheduleCriteria.SORT_FIELD_DATA_TYPE;
public static final String ATTR_DEFINITION_ID = "definitionId";
public static final String ATTR_DESCRIPTION = "description";
@@ -78,6 +77,10 @@ public class SchedulesDataSource extends RPCDataSource<MeasurementScheduleCompos
*/
public ArrayList<ListGridField> getListGridFields() {
ArrayList<ListGridField> fields = new ArrayList<ListGridField>();
+
+ ListGridField scheduleIdField = new ListGridField(ATTR_DEFINITION_ID, MSG.dataSource_operationSchedule_field_id());
+ scheduleIdField.setHidden(true);
+ fields.add(scheduleIdField);
ListGridField displayNameField = new ListGridField(ATTR_DISPLAY_NAME, MSG.common_title_metric());
fields.add(displayNameField);
11 years, 4 months
[rhq] modules/enterprise modules/integration-tests
by Heiko W. Rupp
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertHandlerBean.java | 4
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/IntegerValue.java | 55 +++++++++
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/StringValue.java | 6 -
modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/AlertTest.java | 25 ++++
modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/OperationsTest.java | 24 ++++
modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ReportsTest.java | 56 ++++++++++
6 files changed, 164 insertions(+), 6 deletions(-)
New commits:
commit 564ac02d1aa2c0f5c9dab04c873f3150b789d703
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Mon Feb 4 09:49:19 2013 +0100
BZ 905210 retrieval of alertCount failed for requested xml content type
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertHandlerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertHandlerBean.java
index e77e8b5..b497954 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertHandlerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AlertHandlerBean.java
@@ -135,7 +135,7 @@ public class AlertHandlerBean extends AbstractRestBean {
@GET
@Path("count")
@ApiOperation("Return a count of alerts in the system depending on criteria")
- public int countAlerts(@ApiParam(value = "If non-null only send alerts that have fired after this time, time is millisecond since epoch")
+ public IntegerValue countAlerts(@ApiParam(value = "If non-null only send alerts that have fired after this time, time is millisecond since epoch")
@QueryParam("since") Long since) {
AlertCriteria criteria = new AlertCriteria();
@@ -151,7 +151,7 @@ public class AlertHandlerBean extends AbstractRestBean {
PageList<Alert> alerts = alertManager.findAlertsByCriteria(caller,criteria);
int count = alerts.getTotalSize();
- return count;
+ return new IntegerValue(count);
}
@GET
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/IntegerValue.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/IntegerValue.java
new file mode 100644
index 0000000..11d8c13
--- /dev/null
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/IntegerValue.java
@@ -0,0 +1,55 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package org.rhq.enterprise.server.rest.domain;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import com.wordnik.swagger.annotations.ApiClass;
+import com.wordnik.swagger.annotations.ApiProperty;
+
+/**
+ * Encapsulate a simple integer value
+ * @author Heiko W. Rupp
+ */
+@ApiClass("Encapsulates a simple integer value. In XML this is represented as <value value=\"...\"/>")
+@XmlRootElement(name = "value")
+public class IntegerValue {
+
+ Integer value;
+
+ @SuppressWarnings("unused")
+ public IntegerValue() {
+ }
+
+ public IntegerValue(Integer value) {
+ this.value = value;
+ }
+
+ @XmlAttribute
+ @ApiProperty("The actual value")
+ public Integer getValue() {
+ return value;
+ }
+
+ public void setValue(Integer value) {
+ this.value = value;
+ }
+}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/StringValue.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/StringValue.java
index dde8648..67a7932 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/StringValue.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/StringValue.java
@@ -1,5 +1,6 @@
package org.rhq.enterprise.server.rest.domain;
+import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import com.wordnik.swagger.annotations.ApiClass;
@@ -9,8 +10,8 @@ import com.wordnik.swagger.annotations.ApiProperty;
* Encapsulate a simple string value
* @author Heiko W. Rupp
*/
-@ApiClass("Encapsulates a simple string value")
-@XmlRootElement
+@ApiClass("Encapsulates a simple string value. In XML this is represented as <value value=\"...\"/>")
+@XmlRootElement(name = "value")
public class StringValue {
String value;
@@ -22,6 +23,7 @@ public class StringValue {
this.value = value;
}
+ @XmlAttribute
@ApiProperty("The actual value")
public String getValue() {
return value;
diff --git a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/AlertTest.java b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/AlertTest.java
index aa25197..3ccb73e 100644
--- a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/AlertTest.java
+++ b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/AlertTest.java
@@ -20,6 +20,7 @@
package org.rhq.modules.integrationTests.restApi;
import com.jayway.restassured.http.ContentType;
+import com.jayway.restassured.path.xml.XmlPath;
import org.junit.Test;
@@ -31,6 +32,7 @@ import org.rhq.modules.integrationTests.restApi.d.Group;
import static com.jayway.restassured.RestAssured.delete;
import static com.jayway.restassured.RestAssured.expect;
import static com.jayway.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.iterableWithSize;
@@ -51,13 +53,32 @@ public class AlertTest extends AbstractBase {
}
@Test
- public void testGetAlertCount() throws Exception {
+ public void testGetAlertCountJson() throws Exception {
- expect()
+ given()
+ .header(acceptJson)
+ .expect()
.statusCode(200)
+ .log().ifError()
+ .body("value", instanceOf(Number.class))
.when()
.get("/alert/count");
+ }
+
+ @Test
+ public void testGetAlertCountXml() throws Exception {
+
+ XmlPath xmlPath =
+ given()
+ .header(acceptXml)
+ .expect()
+ .statusCode(200)
+ .log().everything()
+ .when()
+ .get("/alert/count")
+ .xmlPath();
+ int count = xmlPath.getInt("value.@value");
}
@Test
diff --git a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/OperationsTest.java b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/OperationsTest.java
index 72d40c9..9472059 100644
--- a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/OperationsTest.java
+++ b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/OperationsTest.java
@@ -232,6 +232,30 @@ public class OperationsTest extends AbstractBase {
} finally {
+ // Wait until the operation has finished and then delete
+ boolean done = false;
+ int count = 0;
+ while (!done) {
+ String status =
+ given()
+ .pathParam("hid",historyId)
+ .expect()
+ .statusCode(200)
+ .log().everything()
+ .when()
+ .get("/operation/history/{hid}")
+ .jsonPath().getString("status");
+
+ if (status.equals("Success") || status.equals("Failed")) {
+ done = true;
+ } else {
+ Thread.sleep(2000);
+ }
+ assert count < 10 :"Waited for 20sec -- something is wrong";
+ }
+
+
+
// Delete the history item
given()
.pathParam("hid",historyId)
diff --git a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ReportsTest.java b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ReportsTest.java
new file mode 100644
index 0000000..f0eb501
--- /dev/null
+++ b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ReportsTest.java
@@ -0,0 +1,56 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+package org.rhq.modules.integrationTests.restApi;
+
+import com.jayway.restassured.RestAssured;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.jayway.restassured.RestAssured.given;
+
+/**
+ * Tests for the reports that also run via the Rest-api (but different base url)
+ * @author Heiko W. Rupp
+ */
+public class ReportsTest extends AbstractBase {
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+
+ RestAssured.basePath = "/coregui/reports";
+ }
+
+// @Test
+ public void testGetAlertDefinitions() throws Exception {
+
+ given()
+ .header(acceptCsv)
+ .expect()
+ .statusCode(200)
+ .log().ifError()
+ .when()
+ .get("/alertDefinitions");
+
+
+ }
+}
11 years, 4 months
[rhq] Branch 'mtho11/d3-charts2' - modules/enterprise
by mike thompson
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java | 3
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/charttype/MetricGraphData.java | 42 +++++++---
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/charttype/MetricStackedBarGraph.java | 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java | 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/D3GraphListView.java | 2
5 files changed, 38 insertions(+), 15 deletions(-)
New commits:
commit 2dbab1e4820d1a43c47ed1f9d6981d8ef9bc55c7
Author: Mike Thompson <mithomps(a)redhat.com>
Date: Fri Feb 1 13:41:25 2013 -0800
Charting - Bug fixes to dashboard chart refactor.
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java
index b633432..86056e4 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/dashboard/portlets/groups/GroupMetricsPortlet.java
@@ -29,6 +29,7 @@ import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.ContentsType;
+import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.HTMLFlow;
@@ -401,7 +402,7 @@ public class GroupMetricsPortlet extends LocatableVLayout implements CustomSetti
link.setClipValue(true);
link.setWrap(true);
link.setHeight(26);
- link.setWidth("100%");
+ link.setWidth("150px");
link.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/charttype/MetricGraphData.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/charttype/MetricGraphData.java
index 6deb6e4..dbb437a 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/charttype/MetricGraphData.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/charttype/MetricGraphData.java
@@ -47,7 +47,7 @@ public class MetricGraphData implements JsonMetricProducer {
// i18n
final protected Messages MSG = CoreGUI.getMessages();
- private static final Integer DEFAULT_CHART_HEIGHT = 250;
+ private static final Integer DEFAULT_CHART_HEIGHT = 200;
private final String chartTitleMinLabel = MSG.chart_title_min_label();
private final String chartTitleAvgLabel = MSG.chart_title_avg_label();
private final String chartTitlePeakLabel = MSG.chart_title_peak_label();
@@ -151,9 +151,6 @@ public class MetricGraphData implements JsonMetricProducer {
this.availabilityDownList = availabilityDownList;
}
-// public PageList<MeasurementOOBComposite> getMeasurementOOBCompositeList() {
-// return measurementOOBCompositeList;
-// }
public void setMeasurementOOBCompositeList(PageList<MeasurementOOBComposite> measurementOOBCompositeList) {
this.measurementOOBCompositeList = measurementOOBCompositeList;
@@ -221,7 +218,11 @@ public class MetricGraphData implements JsonMetricProducer {
if (null != definition.getDisplayName() && definition.getDisplayName().length() > 55) {
return definition.getDisplayName().substring(0, 55) + "...";
} else {
- return definition.getDisplayName();
+ if(definition == null ){
+ return "";
+ }else {
+ return definition.getDisplayName();
+ }
}
}
@@ -234,8 +235,10 @@ public class MetricGraphData implements JsonMetricProducer {
public String getYAxisUnits() {
if (adjustedMeasurementUnits == null) {
Log.error("AbstractMetricD3GraphView.adjustedMeasurementUnits is populated by getJsonMetrics. Make sure it is called first.");
+ return "";
+ }else {
+ return adjustedMeasurementUnits.toString();
}
- return adjustedMeasurementUnits.toString();
}
public String getXAxisTitle() {
@@ -368,11 +371,19 @@ public class MetricGraphData implements JsonMetricProducer {
//find all possible starting interval points
int i = 0;
for (MeasurementDataNumericHighLowComposite measurement : metricData) {
- boolean notAtStart = i > 1;
+ boolean notAtStart = i >= 1;
boolean currentBarUndefined = Double.isNaN(measurement.getValue());
boolean previousBarDefined = (notAtStart) ? !Double.isNaN(metricData.get(i - 1).getValue()) : false;
+ //Log.debug("Bar: "+i);
+ //Log.debug("Current BarUndefined: "+currentBarUndefined);
+ //Log.debug("Prev Bar Undefined: "+previousBarDefined);
+ // for first bar
+ if(i == 0 && currentBarUndefined){
+ //Log.debug("**Adding Unknown Start interval period for Bar 0");
+ startPoints.add(i);
+ }
if (currentBarUndefined && previousBarDefined && notAtStart && i < metricData.size()-1) {
- //Log.debug("Adding Down or Disabled start Point: " + i);
+ //Log.debug("** Adding Down or Disabled start Point: " + i);
startPoints.add(i+1);
}
i++;
@@ -386,7 +397,8 @@ public class MetricGraphData implements JsonMetricProducer {
boolean notAtEnd = j < metricData.size();
boolean currentBarUndefined = Double.isNaN(metricData.get(j).getValue());
boolean nextBarDefined = (notAtEnd) ? !Double.isNaN(metricData.get(j + 1).getValue()) : false;
- if (currentBarUndefined && nextBarDefined && notAtEnd) {
+ boolean nextBarNotInAnyAvailPeriod = !isAvailabilityDownOrDisabledForBar(metricData.get(j+1).getTimestamp());
+ if (currentBarUndefined && nextBarDefined && notAtEnd && nextBarNotInAnyAvailPeriod) {
Date startDate = new Date(metricData.get(startPoint).getTimestamp());
Date endDate = new Date(metricData.get(j+1).getTimestamp());
//Log.debug("\n\nStartDate: " + startDate);
@@ -397,7 +409,10 @@ public class MetricGraphData implements JsonMetricProducer {
}
}
}
- //Log.debug("intervalDatePairList.size():" + unknownIntervalList.size());
+// Log.debug("intervalDatePairList.size():" + unknownIntervalList.size());
+// for (DatePair datePair : unknownIntervalList) {
+// Log.debug("Unknown Interval: "+ datePair);
+// }
}
private boolean isAvailabilityDownOrDisabledForBar(long timestamp) {
@@ -463,5 +478,12 @@ public class MetricGraphData implements JsonMetricProducer {
return endDateTime;
}
+ @Override
+ public String toString() {
+ return "DatePair{" +
+ "startDateTime=" + startDateTime +
+ ", endDateTime=" + endDateTime +
+ '}';
+ }
}
}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/charttype/MetricStackedBarGraph.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/charttype/MetricStackedBarGraph.java
index 33998f8..e88275c 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/charttype/MetricStackedBarGraph.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/charttype/MetricStackedBarGraph.java
@@ -72,7 +72,7 @@ public final class MetricStackedBarGraph extends AbstractGraph {
// privates
console.log("Chart Height: "+chartContext.height);
- var margin = {top: 10, right: 5, bottom: 20, left: 40},
+ var margin = {top: 10, right: 5, bottom: 5, left: 40},
width = 750 - margin.left - margin.right,
adjustedChartHeight = chartContext.chartHeight - 40,
height = adjustedChartHeight - margin.top - margin.bottom,
@@ -123,7 +123,7 @@ public final class MetricStackedBarGraph extends AbstractGraph {
yAxis = $wnd.d3.svg.axis()
.scale(yScale)
.tickSubdivide(2)
- .ticks(10)
+ .ticks(5)
.tickSize(4, 4, 0)
.orient("left"),
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java
index 3c0f505..9fc4902 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/detail/summary/AbstractActivityView.java
@@ -635,7 +635,7 @@ public abstract class AbstractActivityView extends LocatableVLayout implements R
setIsModal(true);
setShowModalMask(true);
setWidth(900);
- setHeight(650);
+ setHeight(350);
setShowResizer(true);
setCanDragResize(true);
centerInPage();
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/D3GraphListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/D3GraphListView.java
index 9302529..84edc04 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/D3GraphListView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/D3GraphListView.java
@@ -333,7 +333,7 @@ public class D3GraphListView extends LocatableVLayout {
// single graph case
if (measurementId == selectedDefinitionId) {
buildSingleGraph(downAvailList, measurementOOBCompositeList, measurementDefinition,
- metric, 450);
+ metric, 250);
}
} else {
// multiple graph case
11 years, 4 months
[rhq] Branch 'bug/902406' - modules/core
by mazz
modules/core/util/src/main/java/org/rhq/core/util/StopWatch.java | 42 +++---
modules/core/util/src/test/java/org/rhq/core/util/StopWatchTest.java | 66 ++++++++++
2 files changed, 92 insertions(+), 16 deletions(-)
New commits:
commit d928dea3f5484c315f7125a6ee1100cb0ab66f69
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Feb 1 19:11:17 2013 -0500
clean up the StopWatch toString
diff --git a/modules/core/util/src/main/java/org/rhq/core/util/StopWatch.java b/modules/core/util/src/main/java/org/rhq/core/util/StopWatch.java
index c220d99..7f2e38f 100644
--- a/modules/core/util/src/main/java/org/rhq/core/util/StopWatch.java
+++ b/modules/core/util/src/main/java/org/rhq/core/util/StopWatch.java
@@ -73,36 +73,47 @@ public class StopWatch {
}
public String toString() {
- long elap = this.getElapsed();
-
- String fraction = (elap % 1000) + "";
- int pad = 3 - fraction.length();
-
- StringBuffer buf = new StringBuffer().append(elap / 1000).append('.');
-
- //for example, 15 millseconds formatted as ".015" rather than ".15"
- while (pad-- > 0) {
- buf.append("0");
- }
-
- buf.append(fraction);
+ final long elap = this.getElapsed();
+ final StringBuffer buf = new StringBuffer(formatMillis(elap));
if (markerMap.size() > 0) {
- buf.append("{StopWatch Markers:\n");
+ buf.append(" {StopWatch Markers:\n");
+ long totalMarked = 0;
TreeSet<String> keys = new TreeSet<String>(markerMap.keySet());
for (String key : keys) {
TimeSlice ts = markerMap.get(key);
+ totalMarked += (ts.end - ts.begin);
ts.writeBuf(buf);
buf.append('\n');
}
+ long unmarked = elap - totalMarked;
+ if (unmarked > 99) { // only show if the value is substantial
+ buf.append(" [unmarked=").append(formatMillis(unmarked)).append("]\n");
+ }
+
buf.append("}");
}
return buf.toString();
}
+ private String formatMillis(long millis) {
+ final String fraction = String.valueOf(millis % 1000L);
+ int pad = 3 - fraction.length();
+
+ final StringBuffer buf = new StringBuffer().append(millis / 1000L).append('.');
+
+ // for example, 15 millseconds formatted as ".015" rather than ".15"
+ while (pad-- > 0) {
+ buf.append("0");
+ }
+
+ buf.append(fraction).append(" secs");
+ return buf.toString();
+ }
+
class TimeSlice {
String marker;
long begin;
@@ -123,8 +134,7 @@ public class StopWatch {
public void writeBuf(StringBuffer buf) {
long elap = end - begin;
- buf.append(" [").append(marker).append("=").append(elap / 1000).append('.').append(elap % 1000)
- .append("] ");
+ buf.append(" [").append(marker).append("=").append(formatMillis(elap)).append("] ");
}
}
}
\ No newline at end of file
diff --git a/modules/core/util/src/test/java/org/rhq/core/util/StopWatchTest.java b/modules/core/util/src/test/java/org/rhq/core/util/StopWatchTest.java
new file mode 100644
index 0000000..2982cc0
--- /dev/null
+++ b/modules/core/util/src/test/java/org/rhq/core/util/StopWatchTest.java
@@ -0,0 +1,66 @@
+ /*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2013 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.rhq.core.util;
+
+import org.testng.annotations.Test;
+
+@Test
+public class StopWatchTest {
+ public void testQuick() {
+ StopWatch sw = new StopWatch();
+ try {
+ Thread.sleep(1100);
+ } catch (InterruptedException e) {
+ }
+ assert sw.getElapsed() > 1000L;
+ assert sw.reset() > 1000L : "reset should have returned the elapse time";
+ assert sw.getElapsed() < 300L : "timer should have been reset";
+ }
+
+ public void testMarkers() {
+ StopWatch sw = new StopWatch();
+
+ // B time
+ sw.markTimeBegin("B");
+ try {
+ Thread.sleep(400);
+ } catch (InterruptedException e) {
+ }
+ sw.markTimeEnd("B");
+
+ // unmarked
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ }
+
+ // A time
+ sw.markTimeBegin("A");
+ try {
+ Thread.sleep(600);
+ } catch (InterruptedException e) {
+ }
+ sw.markTimeEnd("A");
+ System.out.println(sw.toString());
+ }
+}
\ No newline at end of file
11 years, 4 months
[rhq] modules/plugins
by Simeon Pinder
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/JBossProductType.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
New commits:
commit 982fb93fc5e406808e9297975b30f461cee7ff0a
Author: Simeon Pinder <spinder(a)fulliautomatix.conchfritter.com>
Date: Fri Feb 1 18:19:07 2013 -0500
[BZ 906844] updating product name so discovery detail lookup over rest works to eliminate IllegalArgumentExceptions from agent log.
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/JBossProductType.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/JBossProductType.java
index 7239c02..eb86f0b 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/JBossProductType.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/JBossProductType.java
@@ -33,8 +33,8 @@ public enum JBossProductType {
AS("AS", "JBoss AS 7", "JBoss Application Server 7", "AS"),
EAP("EAP", "JBoss EAP 6", "JBoss Enterprise Application Platform 6", "EAP"),
JDG("JDG", "JBoss JDG 6", "JBoss Data Grid 6", "Data Grid"),
- EPP("EPP", "JBoss EAP 6", "JBoss Enterprise Portal Platform 6", "EPP"),
- JPP("JPP", "JBoss EAP 6", "JBoss Portal Platform 6", "JPP"),
+ EPP("EPP", "JBoss EAP 6", "JBoss Enterprise Portal Platform 6", "Portal Platform"),
+ JPP("JPP", "JBoss EAP 6", "JBoss Portal Platform 6", "Portal Platform"),
// EWP("EWP", "JBoss EWP 6", "JBoss Enterprise Web Platform 6", "EWP"),
SOA("SOA-P", "JBoss SOA-P 6", "JBoss Enterprise SOA Platform (ESB)", "SOAP");
11 years, 4 months
[rhq] Branch 'bug/902406' - modules/core
by mazz
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java | 91 ++++++++--
modules/core/util/src/main/java/org/rhq/core/util/StopWatch.java | 19 +-
2 files changed, 86 insertions(+), 24 deletions(-)
New commits:
commit 0c4f425ce9499b82c70b0447348f15273b91d0a5
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Feb 1 17:59:36 2013 -0500
add some debugging for sync timings
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
index f1746da..684db76 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
@@ -2847,7 +2847,7 @@ public class InventoryManager extends AgentService implements ContainerService,
private void mergeUnknownResources(Set<ResourceSyncInfo> unknownResourceSyncInfos) {
if (log.isDebugEnabled()) {
log.debug("Merging [" + unknownResourceSyncInfos.size()
- + "] unknown Resources and their descendants into local inventory...");
+ + "] unknown resources and descendants into inventory...");
}
if (!unknownResourceSyncInfos.isEmpty()) {
@@ -2878,37 +2878,90 @@ public class InventoryManager extends AgentService implements ContainerService,
private Set<Resource> getResourcesFromSyncInfos(Set<ResourceSyncInfo> syncInfos) {
- Set<Resource> result = new HashSet<Resource>(syncInfos.size());
+ final StopWatch stopWatch = new StopWatch();
+ final int syncInfosSize = syncInfos.size();
+ final Set<Resource> result = new HashSet<Resource>(syncInfosSize);
for (ResourceSyncInfo syncInfo : syncInfos) {
Resource resource = getResourceFromSyncInfo(syncInfo);
result.add(resource);
}
+ if (log.isDebugEnabled()) {
+ log.debug("Time to build resource tree from [" + syncInfosSize + "] sync infos=" + stopWatch.getElapsed());
+ }
+
return result;
}
private Resource getResourceFromSyncInfo(ResourceSyncInfo syncInfo) {
- Resource result;
+ final boolean isDebugEnabled = log.isDebugEnabled();
+ final StopWatch stopWatch = new StopWatch();
+ String marker = null;
+
+ /////
+ // First we need to do a breadth first traversal of the sync info tree and build a list of all resource IDs.
+
+ if (isDebugEnabled) {
+ marker = "a. Breadth-first retrieval of sync info tree";
+ stopWatch.markTimeBegin(marker);
+ }
List<Integer> resourceIdList = treeToBreadthFirstList(syncInfo);
+ int fullResourceTreeSize = resourceIdList.size();
+ if (isDebugEnabled) {
+ stopWatch.markTimeEnd(marker);
+ }
- Map<Integer, Resource> resourceMap = new HashMap<Integer, Resource>(resourceIdList.size());
+ /////
+ // Now we need to loop over batches of the resource ID list - asking the server for their resource representations.
+ // When we get the resources from the server, we put them in our resourceMap, keyed on ID.
+ Map<Integer, Resource> resourceMap = new HashMap<Integer, Resource>(resourceIdList.size());
+ int batchNumber = 0;
while (!resourceIdList.isEmpty()) {
+ // Our current batch starts at the head of the list, but
+ // we need to determine how big our current batch should be and where in the list of IDs that batch ends
int size = resourceIdList.size();
int end = (SYNC_BATCH_SIZE < size) ? SYNC_BATCH_SIZE : size;
+ batchNumber++;
+
+ // Determine the content of our current batch - this is simply a sublist of our IDs list.
+ // Note that we use .clear() once we get the batch array in order to advance our progress and help GC.
+ // This usage of .clear() will remove the processed resources from the backing list.
+ String markerPrefix = null;
+ if (isDebugEnabled) {
+ markerPrefix = String.format("b. Batch [%03d] (%d): ", batchNumber, fullResourceTreeSize);
+ marker = String.format("%sGet resource ID sublist - %d of %d remaining", markerPrefix, end, size);
+ stopWatch.markTimeBegin(marker);
+ }
List<Integer> resourceIdBatch = resourceIdList.subList(0, end);
Integer[] resourceIdArray = resourceIdBatch.toArray(new Integer[resourceIdBatch.size()]);
- // Advance our progress and possibly help GC. This will remove the processed resources from the backing list
resourceIdBatch.clear();
+ if (isDebugEnabled) {
+ stopWatch.markTimeEnd(marker);
+
+ marker = markerPrefix + "Get sublist of resources from server";
+ stopWatch.markTimeBegin(marker);
+ }
+
+ // Ask the server for the resource representation of all resource IDs in our batch.
+ // This is a potentially expensive operation depending on the size of the batch and the content of the resources.
List<Resource> resourceBatch = configuration.getServerServices().getDiscoveryServerService()
.getResourcesAsList(resourceIdArray);
- // add the newly fetched resources to the end of our master list
+ if (isDebugEnabled) {
+ stopWatch.markTimeEnd(marker);
+
+ marker = markerPrefix + "Store sublist of resources to map";
+ stopWatch.markTimeBegin(marker);
+ }
+
+ // Now that the server told us the resources in our batch, we add them to our master map.
+ // Note our usage of clear on the batch - this is to help GC.
for (Resource r : resourceBatch) {
// protect against childResources notNull assumptions downstream
if (null == r.getChildResources()) {
@@ -2916,27 +2969,33 @@ public class InventoryManager extends AgentService implements ContainerService,
}
resourceMap.put(r.getId(), r);
}
-
- // Again, help the GC
resourceBatch.clear();
+
+ if (isDebugEnabled) {
+ stopWatch.markTimeEnd(marker);
+ }
}
- if (resourceIdList.size() != resourceMap.size()) {
- log.warn("Expected [" + resourceIdList.size() + "] but found [" + resourceMap.size()
+ if (fullResourceTreeSize != resourceMap.size()) {
+ log.warn("Expected [" + fullResourceTreeSize + "] but found [" + resourceMap.size()
+ "] resources when fetching from server");
}
- boolean isDebugEnabled = log.isDebugEnabled();
- StopWatch stopWatch = null;
-
+ /////
+ // We now have all the resources associated with all sync infos in a map.
+ // We need to build the full resource tree using the sync info as the blueprint for how to order the resources in a tree.
if (isDebugEnabled) {
- stopWatch = new StopWatch();
+ marker = "c. Build the full resource tree";
+ stopWatch.markTimeBegin(marker);
}
- result = syncInfoTreeToResourceTree(syncInfo, resourceMap);
+ Resource result = syncInfoTreeToResourceTree(syncInfo, resourceMap);
+ resourceMap.clear();
if (isDebugEnabled) {
- log.debug("syncInfoTreeToResourceTree time=[" + stopWatch + "]");
+ stopWatch.markTimeEnd(marker);
+
+ log.debug("Full resource tree built from sync info - performance: " + stopWatch);
}
return result;
diff --git a/modules/core/util/src/main/java/org/rhq/core/util/StopWatch.java b/modules/core/util/src/main/java/org/rhq/core/util/StopWatch.java
index 85f7391..c220d99 100644
--- a/modules/core/util/src/main/java/org/rhq/core/util/StopWatch.java
+++ b/modules/core/util/src/main/java/org/rhq/core/util/StopWatch.java
@@ -23,13 +23,13 @@
package org.rhq.core.util;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
+import java.util.TreeSet;
public class StopWatch {
private long start;
private long end;
- private Map markerMap;
+ private Map<String, TimeSlice> markerMap;
public StopWatch() {
reset();
@@ -55,7 +55,7 @@ public class StopWatch {
public StopWatch(long start) {
this.start = start;
- markerMap = new HashMap();
+ markerMap = new HashMap<String, TimeSlice>();
}
public long reset() {
@@ -63,7 +63,7 @@ public class StopWatch {
return this.getElapsed();
} finally {
start = System.currentTimeMillis();
- markerMap = new HashMap();
+ markerMap = new HashMap<String, TimeSlice>();
}
}
@@ -88,13 +88,16 @@ public class StopWatch {
buf.append(fraction);
if (markerMap.size() > 0) {
- buf.append(" { Markers: ");
- for (Iterator i = markerMap.values().iterator(); i.hasNext();) {
- TimeSlice ts = (TimeSlice) i.next();
+ buf.append("{StopWatch Markers:\n");
+
+ TreeSet<String> keys = new TreeSet<String>(markerMap.keySet());
+ for (String key : keys) {
+ TimeSlice ts = markerMap.get(key);
ts.writeBuf(buf);
+ buf.append('\n');
}
- buf.append(" } ");
+ buf.append("}");
}
return buf.toString();
11 years, 4 months