etc/agentspawn/src/main/resources/template-configuration.xml | 2 etc/agentspawn/src/scripts/agentcopy-agent-configuration.xml | 2 modules/core/domain/src/main/java/org/rhq/core/domain/criteria/MeasurementDataTraitCriteria.java | 127 ++++ modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementData.java | 4 modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfiguration.java | 16 modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationConstants.java | 7 modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationUpgrade.java | 13 modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java | 3 modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentSetupInstructions.java | 10 modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/SetupPromptCommand.java | 8 modules/enterprise/agent/src/main/resources/agent-configuration.xml | 9 modules/enterprise/agent/src/test/resources/test-agent-configuration.xml | 2 modules/enterprise/agent/src/test/resources/test-agent1-cfg-mvn.xml | 2 modules/enterprise/agent/src/test/resources/test-agent2-cfg-mvn.xml | 2 modules/enterprise/agent/src/test/resources/test-agent2-configuration.xml | 2 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java | 16 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertsView.java | 5 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java | 34 + modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/MeasurementDataGWTService.java | 3 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitDataSource.java | 147 +++++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitListView.java | 66 ++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementScheduleListView.java | 3 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java | 4 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/monitoring/traits/TraitsDataSource.java | 58 ++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/monitoring/traits/TraitsView.java | 48 + modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java | 5 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/traits/TraitsDataSource.java | 58 ++ modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/traits/TraitsView.java | 45 + modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java | 13 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java | 3 modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/MeasurementDataGWTServiceImpl.java | 5 modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-add-map.xhtml | 32 + modules/enterprise/gui/webdav-war/webdav-war.iml | 169 ------ modules/enterprise/server/jar/pom.xml | 7 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerBean.java | 32 + modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerLocal.java | 15 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerRemote.java | 9 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/webservices/WebservicesManagerBean.java | 6 modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java | 256 ++++++++++ modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3PerformanceTest.java | 101 +++ modules/enterprise/server/plugins/groovy-script/pom.xml | 229 ++++++++ modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ClasspathInitializer.groovy | 10 modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy | 65 ++ modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorException.groovy | 22 modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy | 38 + modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/FetchDelegate.groovy | 12 modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy | 45 + modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptException.groovy | 22 modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy | 91 +++ modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegate.groovy | 38 + modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortField.groovy | 15 modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml | 74 ++ modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy | 67 ++ modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntity.groovy | 12 modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy | 7 modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ClasspathInitializerTest.groovy | 33 + modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy | 116 ++++ modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy | 57 ++ modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy | 126 ++++ modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegateTest.groovy | 88 +++ modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/access_mgr.groovy | 4 modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/access_nonexistent_mgr.groovy | 3 modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/create_criteria.groovy | 17 modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/throw_exception.groovy | 3 modules/enterprise/server/plugins/pom.xml | 1 modules/enterprise/server/sars/agent-sar/src/main/resources/META-INF/embedded-agent-configuration.xml | 2 modules/helpers/perftest-data-gen/install_files.sh | 6 modules/helpers/perftest-data-gen/pom.xml | 1 modules/helpers/perftest-data-gen/src/main/java/org/rhq/etc/perftestDataGen/DataGen.java | 19 modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java | 27 - modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml | 1 modules/plugins/rhq-agent/src/test/resources/test-agent-configuration.xml | 2 pom.xml | 1 73 files changed, 2378 insertions(+), 225 deletions(-)
New commits: commit 271474dd691b04cc01106d83baee292cfd6689a2 Merge: 4d5b070... 66234db... Author: Lukas Krejci lkrejci@redhat.com Date: Tue Aug 24 18:10:33 2010 +0200
Merge branch 'master' into code-smell
diff --cc modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java index ba0ea81,4f1045e..2ada67b --- a/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java +++ b/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java @@@ -106,9 -115,7 +117,9 @@@ public class MySqlDiscoveryComponent im version = conn.getMetaData().getDatabaseProductVersion(); } catch (SQLException e) { // TODO GH: How to put this back to the server while inventorying this resource in an unconfigured state - log.info("Exception detecting mysql instance version", e); + log.info("Exception detecting mysql instance version" + e.getMessage()); + } finally { + JDBCUtil.safeClose(conn); } return version; } @@@ -126,4 -133,4 +137,4 @@@
return DriverManager.getConnection(url); } --} ++}
commit 66234dbf61b0ae04d40786a00185a3321bd43e93 Merge: 3023ab1... 9decb0a... Author: John Sanda jsanda@redhat.com Date: Mon Aug 23 00:42:39 2010 -0400
Merge branch 'master' of ssh://git.fedorahosted.org/git/rhq/rhq
commit 9decb0a2e1342a5e935d2c05330f9d23dbc95242 Author: Ian Springer ian.springer@redhat.com Date: Tue Aug 24 00:06:08 2010 -0400
various minor fixes and tweaks
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java index 3369352..90b795e 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertDataSource.java @@ -20,13 +20,11 @@ package org.rhq.enterprise.gui.coregui.client.alert;
import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set;
import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.core.DataClass; @@ -60,8 +58,6 @@ import org.rhq.enterprise.gui.coregui.client.util.message.Message; * @author Ian Springer */ public class AlertDataSource extends RPCDataSource<Alert> { - private static final DateTimeFormat DATE_TIME_FORMAT = DateTimeFormat.getMediumDateTimeFormat(); - private AlertGWTServiceAsync alertService = GWTServiceLookup.getAlertService();
protected AlertDataSource() { @@ -107,7 +103,7 @@ public class AlertDataSource extends RPCDataSource<Alert> { DataSourceTextField priorityField = new DataSourceTextField(AlertCriteria.SORT_FIELD_PRIORITY, "Priority", 15); fields.add(priorityField);
- DataSourceTextField ctimeField = new DataSourceTextField(AlertCriteria.SORT_FIELD_CTIME, "Creation Time"); + DataSourceIntegerField ctimeField = new DataSourceIntegerField(AlertCriteria.SORT_FIELD_CTIME, "Creation Time"); fields.add(ctimeField);
DataSourceBooleanField boolField = new DataSourceBooleanField("ack", "Ack'd"); @@ -132,15 +128,12 @@ public class AlertDataSource extends RPCDataSource<Alert> { public void onSuccess(Void blah) { CoreGUI.getMessageCenter().notify( new Message("Deleted [" + alertIds.length + "] alerts", Message.Severity.Info)); - System.out.println("Deleted Alerts with id's: " + Arrays.toString(alertIds) + "."); alertsView.refresh(); }
public void onFailure(Throwable caught) { CoreGUI.getErrorHandler().handleError( - "Failed to delete Alerts with id's: " + Arrays.toString(alertIds), caught); - System.err.println("Failed to delete Alerts with id's " + Arrays.toString(alertIds) + " - cause: " - + caught); + "Failed to delete alerts with id's: " + Arrays.toString(alertIds), caught); } }); } @@ -159,7 +152,7 @@ public class AlertDataSource extends RPCDataSource<Alert> {
public void onSuccess(PageList<Alert> result) { long fetchTime = System.currentTimeMillis() - start; - System.out.println(result.size() + " Alerts fetched in: " + fetchTime + "ms"); + System.out.println(result.size() + " alerts fetched in: " + fetchTime + "ms");
response.setData(buildRecords(result)); // For paging to work, we have to specify size of full result set. @@ -206,7 +199,7 @@ public class AlertDataSource extends RPCDataSource<Alert> { record.setAttribute("resourceName", from.getAlertDefinition().getResource().getName()); record.setAttribute("name", from.getAlertDefinition().getName()); record.setAttribute("priority", from.getAlertDefinition().getPriority().name()); - record.setAttribute("ctime", DATE_TIME_FORMAT.format(new Date(from.getCtime()))); + record.setAttribute("ctime", from.getCtime()); if (from.getAcknowledgeTime() > 0) { record.setAttribute("ack", "true"); } @@ -264,7 +257,6 @@ public class AlertDataSource extends RPCDataSource<Alert> { dc.setAttribute("message", log.getMessage());
notifications[i++] = dc; - } record.setAttribute("notificationLogs", notifications); return record; diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertsView.java index 8983ffe..83d3481 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertsView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/AlertsView.java @@ -44,6 +44,7 @@ import org.rhq.core.domain.criteria.AlertCriteria; import org.rhq.enterprise.gui.coregui.client.LinkManager; import org.rhq.enterprise.gui.coregui.client.components.table.Table; import org.rhq.enterprise.gui.coregui.client.components.table.TableAction; +import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
/** * A view that displays a paginated table of fired {@link org.rhq.core.domain.alert.Alert alert}s, along with the @@ -101,7 +102,9 @@ public class AlertsView extends Table { listGrid.getField("resourceName").setWidth("20%"); // listGrid.getField("recoveryInfo").setWidth("20%"); listGrid.getField("priority").setWidth("7%"); - listGrid.getField("ctime").setWidth("13%"); + ListGridField ctimeField = listGrid.getField("ctime"); + ctimeField.setWidth("13%"); + ctimeField.setCellFormatter(new TimestampCellFormatter()); listGrid.getField("ack").setWidth("5%");
listGrid.getField("resourceName").setCellFormatter(new CellFormatter() { diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitDataSource.java index 3b92ea4..d529087 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitDataSource.java @@ -48,7 +48,6 @@ public abstract class AbstractMeasurementDataTraitDataSource extends RPCDataSour
protected AbstractMeasurementDataTraitDataSource() { setCanMultiSort(true); - List<DataSourceField> fields = createFields(); addFields(fields); } @@ -56,6 +55,8 @@ public abstract class AbstractMeasurementDataTraitDataSource extends RPCDataSour protected List<DataSourceField> createFields() { List<DataSourceField> fields = new ArrayList<DataSourceField>();
+ // Note: The fields + DataSourceIntegerField idField = new DataSourceIntegerField(MeasurementDataTraitCriteria.SORT_FIELD_SCHEDULE_ID, "Id"); idField.setHidden(true); @@ -67,14 +68,14 @@ public abstract class AbstractMeasurementDataTraitDataSource extends RPCDataSour
// TODO: Include description from metric def?
- DataSourceIntegerField timestampField = new DataSourceIntegerField(MeasurementDataTraitCriteria.SORT_FIELD_TIMESTAMP, - "Last Changed"); - fields.add(timestampField); - DataSourceTextField valueField = new DataSourceTextField(MeasurementDataTraitCriteria.SORT_FIELD_VALUE, "Value"); fields.add(valueField);
+ DataSourceIntegerField timestampField = new DataSourceIntegerField(MeasurementDataTraitCriteria.SORT_FIELD_TIMESTAMP, + "Last Changed"); + fields.add(timestampField); + return fields; }
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitListView.java index fb30a06..47bfa5f 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitListView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitListView.java @@ -20,6 +20,7 @@ package org.rhq.enterprise.gui.coregui.client.inventory.common;
import com.smartgwt.client.data.Criteria; import com.smartgwt.client.data.SortSpecifier; +import com.smartgwt.client.types.SelectionStyle; import com.smartgwt.client.types.SortDirection; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; @@ -53,6 +54,9 @@ public abstract class AbstractMeasurementDataTraitListView extends Table { super.onInit();
ListGrid listGrid = getListGrid(); + listGrid.setSelectionType(SelectionStyle.SINGLE); + + // Set widths and cell formatters on the fields. listGrid.getField(MeasurementDataTraitCriteria.SORT_FIELD_NAME).setWidth("20%"); listGrid.getField(MeasurementDataTraitCriteria.SORT_FIELD_VALUE).setWidth("60%"); ListGridField timestampField = listGrid.getField(MeasurementDataTraitCriteria.SORT_FIELD_TIMESTAMP); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementScheduleListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementScheduleListView.java index 55379d1..bcb0f00 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementScheduleListView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementScheduleListView.java @@ -57,6 +57,8 @@ public abstract class AbstractMeasurementScheduleListView extends Table { super.onInit();
ListGrid listGrid = getListGrid(); + + // Set widths and cell formatters on the fields. listGrid.getField(MeasurementScheduleCriteria.SORT_FIELD_DISPLAY_NAME).setWidth("20%"); listGrid.getField(MeasurementScheduleCriteria.SORT_FIELD_DESCRIPTION).setWidth("40%"); listGrid.getField(MeasurementScheduleCriteria.SORT_FIELD_DATA_TYPE).setWidth("10%"); @@ -67,6 +69,7 @@ public abstract class AbstractMeasurementScheduleListView extends Table { intervalField.setCellFormatter(new MillisecondsCellFormatter()); intervalField.setWidth("25%");
+ // Add action buttons and widgets. addTableAction("Enable", Table.SelectionEnablement.ANY, null, new TableAction() { public void executeAction(ListGridRecord[] selection) { getDataSource().enableSchedules(AbstractMeasurementScheduleListView.this); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java index 1b6f6cd..950d28c 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/RPCDataSource.java @@ -19,6 +19,7 @@ package org.rhq.enterprise.gui.coregui.client.util;
import java.util.Collection; +import java.util.List;
import com.smartgwt.client.data.DSRequest; import com.smartgwt.client.data.DSResponse; @@ -36,6 +37,7 @@ import org.rhq.enterprise.gui.coregui.client.CoreGUI; * Base GWT-RPC oriented DataSource class. * * @author Greg Hinkle + * @author Ian Springer */ public abstract class RPCDataSource<T> extends DataSource {
@@ -171,9 +173,16 @@ public abstract class RPCDataSource<T> extends DataSource { return response; }
- public void addFields(Collection<DataSourceField> fields) { + /** + * Add the specified fields to this data source. When the data source is associated with a + * {@link com.smartgwt.client.widgets.grid.ListGrid}, the fields will be displayed in the order they are specified + * here. + * + * @param fields the fields to be added + */ + public void addFields(List<DataSourceField> fields) { for (DataSourceField field : fields) { - addField(field); + addField(field); } } } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java index 410853f..7e2eef4 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/Message.java @@ -30,6 +30,7 @@ public class Message { protected Date fired = new Date(); protected Severity severity;
+ // TODO: Add Debug severity? public enum Severity { Info, Warning, Error };
public Message(String title, Severity severity) { @@ -43,6 +44,4 @@ public class Message { this.severity = severity; }
- - }
commit 3023ab1440402effbdae2b366ac05f44a58ae5d1 Author: John Sanda jsanda@redhat.com Date: Mon Aug 23 00:42:17 2010 -0400
Adding initial support for setting up user-defined classpath
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ClasspathInitializer.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ClasspathInitializer.groovy new file mode 100644 index 0000000..584c364 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ClasspathInitializer.groovy @@ -0,0 +1,10 @@ +package org.rhq.enterprise.server.plugins.groovy + +import org.codehaus.groovy.control.CompilerConfiguration + +class ClasspathInitializer { + + def initClasspath(String paths, String libDirs, scriptClassLoader) { + paths.eachLine { scriptClassLoader.addClasspath(it.trim()) } + } +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy index fc34aa0..6c9c44d 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy @@ -52,10 +52,13 @@ class ScriptRunner implements ServerPluginComponent, ControlFacet { compilerConfig.scriptBaseClass = RHQScript.class.name
def scriptName = parameters.getSimpleValue("script", null) + def paths = parameters.getSimpleValue("classpath", '')
log.debug("Preparing to execute script, $scriptName")
def scriptClassLoader = new GroovyClassLoader(Thread.currentThread().contextClassLoader, compilerConfig) + new ClasspathInitializer().initClasspath(paths, null, scriptClassLoader) + def scriptRoots = new URL[1] scriptRoots[0] = new File(scriptName).toURI().toURL() def scriptEngine = new GroovyScriptEngine(scriptRoots, scriptClassLoader) diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml b/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml index 86a2e3a..fe6e665 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml +++ b/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml @@ -27,9 +27,22 @@ <!--</c:simple-property>--> <!--</c:map-property>--> <!--</c:list-property>--> + <c:simple-property name="classpath" + type="longString" + required="false" + description="A list of classpath entries. Each entry must be placed on its own line. + This can refer to class directories, groovy source directories, and JAR + files."/> + <c:simple-property name="libDirs" + displayName="Library Directories" + type="longString" + required="false" + description="A list of JAR file directories. Each path must be placed on its own + line. Each JAR file found in a directory will be added to the + classspath."/> </serverplugin:parameters> serverplugin:results - <c:simple-property name="results"/> + <c:simple-property name="results" type="longString"/> </serverplugin:results> </serverplugin:control> </serverplugin:plugin-component> diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ClasspathInitializerTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ClasspathInitializerTest.groovy new file mode 100644 index 0000000..028f72c --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ClasspathInitializerTest.groovy @@ -0,0 +1,33 @@ +package org.rhq.enterprise.server.plugins.groovy + +import org.testng.annotations.Test + +import static org.testng.Assert.* + +class ClasspathInitializerTest { + + @Test + void addPathsToClasspathInSpecifiedOrder() { + def paths = """ + /foo/scripts + /foo/classes + /foo/lib/dep1.jar + /foo/lib/dep2.jar + """.trim() + + def expected = ['/foo/scripts', '/foo/classes', '/foo/lib/dep1.jar', '/foo/lib/dep2.jar'] + def actual = [] + + def classLoader = [addClasspath: {String path -> actual << path }] + + new ClasspathInitializer().initClasspath(paths, '', classLoader) + + assertEquals(actual, expected, "Failed to add paths or add them in correct order to classpath") + } + +// @Test +// void addJarsInEachLibDirToClasspath() { +// +// } + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy index 6900943..0b2b90c 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy @@ -99,6 +99,11 @@ class ScriptRunnerTest { ) }
+ @Test + void addPathsToScriptClasspath() { + + } + def executeScript(String script) { def params = new Configuration() params.put(new PropertySimple('script', getScriptPath(script)))
commit 3247f3ba5b2cc365e787f720505e695059074c42 Author: John Sanda jsanda@redhat.com Date: Sun Aug 22 21:45:33 2010 -0400
Fixing compilation error
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/webservices/WebservicesManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/webservices/WebservicesManagerBean.java index 6c2c7f1..96dcdd2 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/webservices/WebservicesManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/webservices/WebservicesManagerBean.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Set;
import javax.ejb.Stateless; +import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import javax.xml.bind.annotation.XmlSeeAlso; @@ -76,6 +77,7 @@ import org.rhq.core.domain.criteria.Criteria; import org.rhq.core.domain.criteria.EventCriteria; import org.rhq.core.domain.criteria.GroupOperationHistoryCriteria; import org.rhq.core.domain.criteria.InstalledPackageCriteria; +import org.rhq.core.domain.criteria.MeasurementDataTraitCriteria; import org.rhq.core.domain.criteria.MeasurementDefinitionCriteria; import org.rhq.core.domain.criteria.MeasurementScheduleCriteria; import org.rhq.core.domain.criteria.OperationDefinitionCriteria; @@ -575,6 +577,10 @@ public class WebservicesManagerBean implements WebservicesRemote { return measurementDataManager.getAggregate(subject, scheduleId, startTime, endTime); }
+ public PageList<MeasurementDataTrait> findTraitsByCriteria(Subject subject, MeasurementDataTraitCriteria criteria) { + return measurementDataManager.findTraitsByCriteria(subject, criteria); + } + //MEASUREMENTDATAMANAGER: END ----------------------------------
//MEASUREMENTDEFINITIONMANAGER: BEGIN ----------------------------------
commit 9354219518ccaf95c7cc5bee0e5c73c456d1b424 Author: John Sanda jsanda@redhat.com Date: Sun Aug 22 21:37:06 2010 -0400
Adding logging
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy index 7dcc19b..b2cf489 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy @@ -14,6 +14,8 @@ class CriteriaGenerator { def clazz def criteria
+ log.debug("Preparing to generate $className") + try { clazz = Class.forName(className) } diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy index 033c149..534c050 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy @@ -1,9 +1,12 @@ package org.rhq.enterprise.server.plugins.groovy
import org.rhq.enterprise.server.util.LookupUtil +import org.apache.commons.logging.LogFactory
class RHQScript extends Script {
+ static def log = LogFactory.getLog(RHQScript) + Map entityMap = [:]
Object run() { @@ -17,6 +20,7 @@ class RHQScript extends Script { return LookupUtil."$method"() } catch (MissingMethodException e) { + log.warn("Could not find a manager SLSB under the name $name", e) throw new RHQScriptException("Unable to locate $name", e) } } diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy index 3937c51..fc34aa0 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy @@ -13,24 +13,31 @@ import org.rhq.enterprise.server.plugin.pc.ControlResults import org.rhq.enterprise.server.plugin.pc.ScheduledJobInvocationContext import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent import org.rhq.enterprise.server.plugin.pc.ServerPluginContext +import org.apache.commons.logging.LogFactory
class ScriptRunner implements ServerPluginComponent, ControlFacet {
+ static def log = LogFactory.getLog(ScriptRunner) + String entityPackagePrefix = "org.rhq.core.domain"
Map entityMap = [:]
void initialize(ServerPluginContext context) { - def reflections = new Reflections(new ConfigurationBuilder() - .setUrls(ClasspathHelper.getUrlsForPackagePrefix(entityPackagePrefix)) - .setScanners(new TypeAnnotationsScanner())); + log.debug("Initializing plugin") + log.debug("Preparing to scan classpath for entities and build entity map cache") + + def reflections = new Reflections(new ConfigurationBuilder() + .setUrls(ClasspathHelper.getUrlsForPackagePrefix(entityPackagePrefix)) + .setScanners(new TypeAnnotationsScanner())); def classes = reflections.getTypesAnnotatedWith(Entity.class)
+ log.debug("Found ${classes.size()} entities") + classes.each { entityMap << [(it.simpleName.toString()): it] } }
void start() { - }
void stop() { @@ -38,7 +45,6 @@ class ScriptRunner implements ServerPluginComponent, ControlFacet { }
void shutdown() { - }
ControlResults invoke(String name, Configuration parameters) { @@ -47,6 +53,8 @@ class ScriptRunner implements ServerPluginComponent, ControlFacet {
def scriptName = parameters.getSimpleValue("script", null)
+ log.debug("Preparing to execute script, $scriptName") + def scriptClassLoader = new GroovyClassLoader(Thread.currentThread().contextClassLoader, compilerConfig) def scriptRoots = new URL[1] scriptRoots[0] = new File(scriptName).toURI().toURL() @@ -63,9 +71,11 @@ class ScriptRunner implements ServerPluginComponent, ControlFacet {
try { def scriptResult = script.run() + log.debug("Finished executing $scriptName") results.complexResults.put(new PropertySimple("results", scriptResult)) } catch (Throwable t) { + log.warn("An error occurred while executing $scriptName", t) results.error = t }
commit bd5c6b8622181643df09c1c775b2861f313efd1b Merge: fdc507c... 2fee0bd... Author: John Sanda jsanda@redhat.com Date: Sun Aug 22 21:19:48 2010 -0400
Merge branch 'master' of ssh://git.fedorahosted.org/git/rhq/rhq
commit 2fee0bd59336c0ca99782ea2580c81bfe894d615 Author: Ian Springer ian.springer@redhat.com Date: Mon Aug 23 19:12:50 2010 -0400
implement Resource and group Monitoring>Traits subtabs
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/MeasurementDataTraitCriteria.java b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/MeasurementDataTraitCriteria.java new file mode 100644 index 0000000..2fd4dcf --- /dev/null +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/MeasurementDataTraitCriteria.java @@ -0,0 +1,127 @@ +/* + * RHQ Management Platform + * Copyright (C) 2010 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.domain.criteria; + +import org.rhq.core.domain.measurement.MeasurementDataTrait; +import org.rhq.core.domain.util.PageOrdering; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +/** + * RHQ {@link Criteria} object for filtered, sortable queries of {@link MeasurementDataTrait} data sets. + * + * @author Ian Springer + */ +@XmlAccessorType(XmlAccessType.FIELD) +@SuppressWarnings("unused") +public class MeasurementDataTraitCriteria extends Criteria { + private static final long serialVersionUID = 1L; + + // sort fields + public static final String SORT_FIELD_SCHEDULE_ID = "scheduleId"; + public static final String SORT_FIELD_TIMESTAMP = "timestamp"; + public static final String SORT_FIELD_NAME = "name"; + public static final String SORT_FIELD_VALUE = "value"; + + // filter fields + public static final String FILTER_FIELD_SCHEDULE_ID = "scheduleId"; + public static final String FILTER_FIELD_RESOURCE_ID = "resourceId"; + public static final String FILTER_FIELD_GROUP_ID = "groupId"; + public static final String FILTER_FIELD_MAX_TIMESTAMP = "maxTimestamp"; + + private Integer filterScheduleId; // requires overrides + private Integer filterResourceId; // requires overrides + private Integer filterGroupId; // requires overrides + private Boolean filterMaxTimestamp; // requires overrides + + private boolean fetchSchedule; + + private PageOrdering sortScheduleId; // requires overrides + private PageOrdering sortTimestamp; // requires overrides + private PageOrdering sortName; // requires overrides + + public MeasurementDataTraitCriteria() { + filterOverrides.put(FILTER_FIELD_SCHEDULE_ID, "id.scheduleId = ?"); + filterOverrides.put(FILTER_FIELD_RESOURCE_ID, "schedule.resource.id = ?"); + filterOverrides.put(FILTER_FIELD_GROUP_ID, "schedule.resource.id IN " // + + "( SELECT res.id " // + + " FROM Resource res " // + + " JOIN res.implicitGroups ig " // + + " WHERE ig.id = ? )"); + filterOverrides.put(FILTER_FIELD_MAX_TIMESTAMP, "id.timestamp = " // + + "( SELECT MAX(mdt.id.timestamp) " + + " FROM MeasurementDataTrait mdt " + + " WHERE mdt.id.scheduleId = id.scheduleId )"); + + sortOverrides.put(SORT_FIELD_SCHEDULE_ID, "id.scheduleId"); + sortOverrides.put(SORT_FIELD_TIMESTAMP, "id.timestamp"); + sortOverrides.put(SORT_FIELD_NAME, "schedule.definition.displayName"); + } + + @Override + public Class getPersistentClass() { + return MeasurementDataTrait.class; + } + + public void addFilterScheduleId(Integer filterScheduleId) { + this.filterScheduleId = filterScheduleId; + } + + public void addFilterResourceId(Integer filterResourceId) { + if (this.filterGroupId != null) { + throw new IllegalArgumentException("This criteria cannot be filtered by both a Resource id and a group id."); + } + this.filterResourceId = filterResourceId; + } + + public void addFilterGroupId(Integer filterGroupId) { + if (this.filterResourceId != null) { + throw new IllegalArgumentException("This criteria cannot be filtered by both a Resource id and a group id."); + } + this.filterGroupId = filterGroupId; + } + + public void addFilterMaxTimestamp(Boolean filterMaxTimestamp) { + this.filterMaxTimestamp = filterMaxTimestamp; + } + + public void fetchSchedule(boolean fetchSchedule) { + this.fetchSchedule = fetchSchedule; + } + + public void addSortScheduleId(PageOrdering sortScheduleId) { + addSortField(SORT_FIELD_SCHEDULE_ID); + this.sortScheduleId = sortScheduleId; + } + + public void addSortTimestamp(PageOrdering sortTimestamp) { + addSortField(SORT_FIELD_TIMESTAMP); + this.sortTimestamp = sortTimestamp; + } + + public void addSortName(PageOrdering sortName) { + addSortField(SORT_FIELD_NAME); + this.sortName = sortName; + } +} \ No newline at end of file diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementData.java b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementData.java index 7fefa3e..7c96309 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementData.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/MeasurementData.java @@ -96,6 +96,10 @@ public abstract class MeasurementData implements Serializable { this.name = name; }
+ public MeasurementSchedule getSchedule() { + return schedule; + } + public abstract Object getValue();
@Override diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java new file mode 100644 index 0000000..9d0952b --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/TimestampCellFormatter.java @@ -0,0 +1,34 @@ +package org.rhq.enterprise.gui.coregui.client.components.table; + +import com.google.gwt.i18n.client.DateTimeFormat; +import com.smartgwt.client.widgets.grid.CellFormatter; +import com.smartgwt.client.widgets.grid.ListGridRecord; + +import java.util.Date; + +/** + * Formats a timestamp (i.e. milliseconds since Epoch). + * + * @author Ian Springer + */ +public class TimestampCellFormatter implements CellFormatter { + private static final DateTimeFormat DATE_TIME_FORMAT = DateTimeFormat.getMediumDateTimeFormat(); + + public String format(Object value, ListGridRecord record, int rowNum, int colNum) { + if (value == null) { + return ""; + } + long longValue; + if (value instanceof Long) { + longValue = (Long)value; + } else if (value instanceof Integer) { + longValue = (Integer)value; + } else if (value instanceof String) { + longValue = Long.parseLong((String)value); + } else { + throw new IllegalArgumentException("value parameter is not a Long, an Integer, or a String."); + } + Date date = new Date(longValue); + return DATE_TIME_FORMAT.format(date); + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/MeasurementDataGWTService.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/MeasurementDataGWTService.java index cf1a9a2..9297d96 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/MeasurementDataGWTService.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/MeasurementDataGWTService.java @@ -24,6 +24,7 @@ import java.util.Set; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+import org.rhq.core.domain.criteria.MeasurementDataTraitCriteria; import org.rhq.core.domain.criteria.MeasurementDefinitionCriteria; import org.rhq.core.domain.criteria.MeasurementScheduleCriteria; import org.rhq.core.domain.measurement.DisplayType; @@ -74,4 +75,6 @@ public interface MeasurementDataGWTService extends RemoteService {
void updateSchedulesForCompatibleGroup(int resourceGroupId, int[] measurementDefinitionIds, long collectionInterval);
+ PageList<MeasurementDataTrait> findTraitsByCriteria(MeasurementDataTraitCriteria criteria); + } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitDataSource.java new file mode 100644 index 0000000..3b92ea4 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitDataSource.java @@ -0,0 +1,146 @@ +/* + * RHQ Management Platform + * Copyright (C) 2010 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.gui.coregui.client.inventory.common; + +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.smartgwt.client.data.Criteria; +import com.smartgwt.client.data.DSRequest; +import com.smartgwt.client.data.DSResponse; +import com.smartgwt.client.data.DataSourceField; +import com.smartgwt.client.data.fields.*; +import com.smartgwt.client.rpc.RPCResponse; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import org.rhq.core.domain.criteria.MeasurementDataTraitCriteria; +import org.rhq.core.domain.measurement.MeasurementDataTrait; +import org.rhq.core.domain.util.PageList; +import org.rhq.enterprise.gui.coregui.client.CoreGUI; +import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; +import org.rhq.enterprise.gui.coregui.client.gwt.MeasurementDataGWTServiceAsync; +import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * A server-side SmartGWT DataSource for reading {@link MeasurementDataTrait trait data}. + * + * @author Ian Springer + */ +public abstract class AbstractMeasurementDataTraitDataSource extends RPCDataSource<MeasurementDataTrait> { + private MeasurementDataGWTServiceAsync measurementService = GWTServiceLookup.getMeasurementDataService(); + + protected AbstractMeasurementDataTraitDataSource() { + setCanMultiSort(true); + + List<DataSourceField> fields = createFields(); + addFields(fields); + } + + protected List<DataSourceField> createFields() { + List<DataSourceField> fields = new ArrayList<DataSourceField>(); + + DataSourceIntegerField idField = new DataSourceIntegerField(MeasurementDataTraitCriteria.SORT_FIELD_SCHEDULE_ID, + "Id"); + idField.setHidden(true); + fields.add(idField); + + DataSourceTextField nameField = new DataSourceTextField(MeasurementDataTraitCriteria.SORT_FIELD_NAME, + "Trait"); + fields.add(nameField); + + // TODO: Include description from metric def? + + DataSourceIntegerField timestampField = new DataSourceIntegerField(MeasurementDataTraitCriteria.SORT_FIELD_TIMESTAMP, + "Last Changed"); + fields.add(timestampField); + + DataSourceTextField valueField = new DataSourceTextField(MeasurementDataTraitCriteria.SORT_FIELD_VALUE, + "Value"); + fields.add(valueField); + + return fields; + } + + protected void executeFetch(final DSRequest request, final DSResponse response) { + final long startTime = System.currentTimeMillis(); + + final MeasurementDataTraitCriteria criteria = getCriteria(request); + + this.measurementService.findTraitsByCriteria(criteria, new AsyncCallback<PageList<MeasurementDataTrait>>() { + public void onFailure(Throwable caught) { + CoreGUI.getErrorHandler().handleError("Failed to fetch traits for criteria " + criteria, + caught); + response.setStatus(RPCResponse.STATUS_FAILURE); + processResponse(request.getRequestId(), response); + } + + public void onSuccess(PageList<MeasurementDataTrait> result) { + long fetchDuration = System.currentTimeMillis() - startTime; + System.out.println(result.size() + " traits fetched in: " + fetchDuration + "ms"); + + response.setData(buildRecords(result)); + // For paging to work, we have to specify size of full result set. + response.setTotalRows(result.getTotalSize()); + processResponse(request.getRequestId(), response); + } + }); + } + + protected MeasurementDataTraitCriteria getCriteria(DSRequest request) { + MeasurementDataTraitCriteria criteria = new MeasurementDataTraitCriteria(); + + Criteria requestCriteria = request.getCriteria(); + if (requestCriteria != null) { + Map values = requestCriteria.getValues(); + for (Object key : values.keySet()) { + String fieldName = (String) key; + if (fieldName.equals(MeasurementDataTraitCriteria.FILTER_FIELD_RESOURCE_ID)) { + Integer resourceId = (Integer) values.get(fieldName); + criteria.addFilterResourceId(resourceId); + } else if (fieldName.equals(MeasurementDataTraitCriteria.FILTER_FIELD_GROUP_ID)) { + Integer groupId = (Integer) values.get(fieldName); + criteria.addFilterGroupId(groupId); + } + } + } + + criteria.setPageControl(getPageControl(request)); + return criteria; + } + + @Override + public MeasurementDataTrait copyValues(ListGridRecord from) { + return null; + } + + @Override + public ListGridRecord copyValues(MeasurementDataTrait from) { + ListGridRecord record = new ListGridRecord(); + + record.setAttribute(MeasurementDataTraitCriteria.SORT_FIELD_SCHEDULE_ID, from.getScheduleId()); + record.setAttribute(MeasurementDataTraitCriteria.SORT_FIELD_TIMESTAMP, from.getTimestamp()); + record.setAttribute(MeasurementDataTraitCriteria.SORT_FIELD_NAME, from.getSchedule().getDefinition().getDisplayName()); + record.setAttribute(MeasurementDataTraitCriteria.SORT_FIELD_VALUE, from.getValue()); + + // TODO: resourceId and resourceGroupId (in subclasses) + + return record; + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitListView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitListView.java new file mode 100644 index 0000000..fb30a06 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/common/AbstractMeasurementDataTraitListView.java @@ -0,0 +1,62 @@ +/* + * RHQ Management Platform + * Copyright (C) 2010 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.gui.coregui.client.inventory.common; + +import com.smartgwt.client.data.Criteria; +import com.smartgwt.client.data.SortSpecifier; +import com.smartgwt.client.types.SortDirection; +import com.smartgwt.client.widgets.grid.ListGrid; +import com.smartgwt.client.widgets.grid.ListGridField; +import org.rhq.core.domain.criteria.MeasurementDataTraitCriteria; +import org.rhq.enterprise.gui.coregui.client.components.table.Table; +import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter; + +/** + * A view that displays a non-paginated table of {@link org.rhq.core.domain.measurement.MeasurementDataTrait trait}s, + * along with the ability to sort those traits. + * + * @author Ian Springer + */ +public abstract class AbstractMeasurementDataTraitListView extends Table { + private static final SortSpecifier[] SORT_SPECIFIERS = new SortSpecifier[] { new SortSpecifier( + MeasurementDataTraitCriteria.SORT_FIELD_NAME, SortDirection.ASCENDING) }; + + public AbstractMeasurementDataTraitListView(String title, AbstractMeasurementDataTraitDataSource dataSource, + Criteria criteria, String[] excludedFieldNames) { + super(title, criteria, SORT_SPECIFIERS, excludedFieldNames); + setDataSource(dataSource); + } + + @Override + public AbstractMeasurementDataTraitDataSource getDataSource() { + return (AbstractMeasurementDataTraitDataSource) super.getDataSource(); + } + + @Override + protected void onInit() { + super.onInit(); + + ListGrid listGrid = getListGrid(); + listGrid.getField(MeasurementDataTraitCriteria.SORT_FIELD_NAME).setWidth("20%"); + listGrid.getField(MeasurementDataTraitCriteria.SORT_FIELD_VALUE).setWidth("60%"); + ListGridField timestampField = listGrid.getField(MeasurementDataTraitCriteria.SORT_FIELD_TIMESTAMP); + timestampField.setWidth("20%"); + timestampField.setCellFormatter(new TimestampCellFormatter()); + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java index a9a6989..5f05bef 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java @@ -43,6 +43,7 @@ import org.rhq.enterprise.gui.coregui.client.components.tab.TwoLevelTabSelectedH import org.rhq.enterprise.gui.coregui.client.components.tab.TwoLevelTabSet; import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup; import org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.monitoring.schedules.SchedulesView; +import org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.monitoring.traits.TraitsView; import org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.summary.OverviewView; import org.rhq.enterprise.gui.coregui.client.inventory.resource.ResourceSearchView; import org.rhq.enterprise.gui.coregui.client.inventory.resource.type.ResourceTypeRepository; @@ -91,7 +92,7 @@ public class ResourceGroupDetailView extends VLayout implements BookmarkableView summaryTab.registerSubTabs("Overview", "Timeline");
monitoringTab = new TwoLevelTab("Monitoring", "/images/icons/Monitor_grey_16.png"); - monitoringTab.registerSubTabs("Graphs", "Tables", "Schedules", "Call Time"); + monitoringTab.registerSubTabs("Graphs", "Tables", "Traits", "Schedules", "Call Time");
inventoryTab = new TwoLevelTab("Inventory", "/images/icons/Inventory_grey_16.png"); inventoryTab.registerSubTabs("Members", "Connection Settings"); @@ -138,6 +139,7 @@ public class ResourceGroupDetailView extends VLayout implements BookmarkableView + groupId)); monitoringTab.updateSubTab("Tables", new FullHTMLPane("/rhq/group/monitor/tables-plain.xhtml?groupId=" + groupId)); + monitoringTab.updateSubTab("Traits", new TraitsView(groupId)); monitoringTab.updateSubTab("Schedules", new SchedulesView(groupId));
//new FullHTMLPane("/rhq/group/monitor/schedules-plain.xhtml?groupId=" + groupId)); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/monitoring/traits/TraitsDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/monitoring/traits/TraitsDataSource.java new file mode 100644 index 0000000..a9abcaf --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/monitoring/traits/TraitsDataSource.java @@ -0,0 +1,58 @@ +/* + * RHQ Management Platform + * Copyright (C) 2010 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.monitoring.traits; + +import com.smartgwt.client.data.DataSourceField; +import com.smartgwt.client.data.fields.DataSourceIntegerField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import org.rhq.core.domain.criteria.MeasurementDataTraitCriteria; +import org.rhq.core.domain.measurement.MeasurementDataTrait; +import org.rhq.enterprise.gui.coregui.client.inventory.common.AbstractMeasurementDataTraitDataSource; + +import java.util.List; + +/** + * A DataSource for reading traits for the current group. + * + * @author Ian Springer + */ +public class TraitsDataSource extends AbstractMeasurementDataTraitDataSource { + private int groupId; + + public TraitsDataSource(int groupId) { + this.groupId = groupId; + } + + @Override + protected List<DataSourceField> createFields() { + List<DataSourceField> fields = super.createFields(); + DataSourceField groupIdField = new DataSourceIntegerField(MeasurementDataTraitCriteria.FILTER_FIELD_GROUP_ID, + "Group Id"); + groupIdField.setHidden(true); + fields.add(groupIdField); + return fields; + } + + @Override + public ListGridRecord copyValues(MeasurementDataTrait from) { + ListGridRecord record = super.copyValues(from); + record.setAttribute(MeasurementDataTraitCriteria.FILTER_FIELD_GROUP_ID, this.groupId); + return record; + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/monitoring/traits/TraitsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/monitoring/traits/TraitsView.java new file mode 100644 index 0000000..e071fe8 --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/monitoring/traits/TraitsView.java @@ -0,0 +1,48 @@ +/* + * RHQ Management Platform + * Copyright (C) 2010 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.monitoring.traits; + +import com.smartgwt.client.data.Criteria; +import org.rhq.core.domain.criteria.MeasurementDataTraitCriteria; +import org.rhq.enterprise.gui.coregui.client.inventory.common.AbstractMeasurementDataTraitListView; +import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.monitoring.traits.TraitsDataSource; + +/** + * The group Monitoring>Traits subtab. + * + * @author Ian Springer + */ +public class TraitsView extends AbstractMeasurementDataTraitListView { + + private static final String TITLE = "Traits"; + + private static final String[] EXCLUDED_FIELD_NAMES = new String[] { MeasurementDataTraitCriteria.FILTER_FIELD_GROUP_ID }; + + public TraitsView(int groupId) { + super(TITLE, new TraitsDataSource(groupId), createCriteria(groupId), EXCLUDED_FIELD_NAMES); + // TODO (ips): add column for Resource name + // TODO (ips): group rows by trait + } + + private static Criteria createCriteria(int groupId) { + Criteria criteria = new Criteria(); + criteria.addCriteria(MeasurementDataTraitCriteria.FILTER_FIELD_GROUP_ID, groupId); + return criteria; + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java index 5c0671c..d6a7d8b 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java @@ -44,6 +44,7 @@ import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.configura import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.inventory.PluginConfigurationEditView; import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.monitoring.GraphListView; import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.monitoring.schedules.SchedulesView; +import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.monitoring.traits.TraitsView; import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.summary.DashboardView; import org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.summary.OverviewView;
@@ -141,8 +142,8 @@ public class ResourceDetailView extends VLayout implements BookmarkableView, Res monitoringTab.updateSubTab("Graphs", new GraphListView(resource)); // new FullHTMLPane("/rhq/common/monitor/graphs.xhtml?id=" + resource.getId())); monitoringTab.updateSubTab("Tables", new FullHTMLPane("/rhq/common/monitor/tables-plain.xhtml?id=" + resource.getId())); - monitoringTab.updateSubTab("Traits", new FullHTMLPane("/rhq/resource/monitor/traits-plain.xhtml?id=" - + resource.getId())); + monitoringTab.updateSubTab("Traits", new TraitsView(resource.getId())); + //new FullHTMLPane("/rhq/resource/monitor/traits-plain.xhtml?id=" + resource.getId())); monitoringTab.updateSubTab("Availability", new FullHTMLPane( "/rhq/resource/monitor/availabilityHistory-plain.xhtml?id=" + resource.getId())); monitoringTab.updateSubTab("Schedules", new SchedulesView(resource.getId())); diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/traits/TraitsDataSource.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/traits/TraitsDataSource.java new file mode 100644 index 0000000..77cb4bb --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/traits/TraitsDataSource.java @@ -0,0 +1,58 @@ +/* + * RHQ Management Platform + * Copyright (C) 2010 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.monitoring.traits; + +import com.smartgwt.client.data.DataSourceField; +import com.smartgwt.client.data.fields.DataSourceIntegerField; +import com.smartgwt.client.widgets.grid.ListGridRecord; +import org.rhq.core.domain.criteria.MeasurementDataTraitCriteria; +import org.rhq.core.domain.measurement.MeasurementDataTrait; +import org.rhq.enterprise.gui.coregui.client.inventory.common.AbstractMeasurementDataTraitDataSource; + +import java.util.List; + +/** + * A DataSource for reading traits for the current Resource. + * + * @author Ian Springer + */ +public class TraitsDataSource extends AbstractMeasurementDataTraitDataSource { + private int resourceId; + + public TraitsDataSource(int resourceId) { + this.resourceId = resourceId; + } + + @Override + protected List<DataSourceField> createFields() { + List<DataSourceField> fields = super.createFields(); + DataSourceField resourceIdField = new DataSourceIntegerField(MeasurementDataTraitCriteria.FILTER_FIELD_RESOURCE_ID, + "Resource Id"); + resourceIdField.setHidden(true); + fields.add(resourceIdField); + return fields; + } + + @Override + public ListGridRecord copyValues(MeasurementDataTrait from) { + ListGridRecord record = super.copyValues(from); + record.setAttribute(MeasurementDataTraitCriteria.FILTER_FIELD_RESOURCE_ID, this.resourceId); + return record; + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/traits/TraitsView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/traits/TraitsView.java new file mode 100644 index 0000000..8ae344c --- /dev/null +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/monitoring/traits/TraitsView.java @@ -0,0 +1,45 @@ +/* + * RHQ Management Platform + * Copyright (C) 2010 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.monitoring.traits; + +import com.smartgwt.client.data.Criteria; +import org.rhq.core.domain.criteria.MeasurementDataTraitCriteria; +import org.rhq.enterprise.gui.coregui.client.inventory.common.AbstractMeasurementDataTraitListView; + +/** + * The Resource Monitoring>Traits subtab. + * + * @author Ian Springer + */ +public class TraitsView extends AbstractMeasurementDataTraitListView { + + private static final String TITLE = "Traits"; + + private static final String[] EXCLUDED_FIELD_NAMES = new String[] { MeasurementDataTraitCriteria.FILTER_FIELD_RESOURCE_ID }; + + public TraitsView(int resourceId) { + super(TITLE, new TraitsDataSource(resourceId), createCriteria(resourceId), EXCLUDED_FIELD_NAMES); + } + + private static Criteria createCriteria(int resourceId) { + Criteria criteria = new Criteria(); + criteria.addCriteria(MeasurementDataTraitCriteria.FILTER_FIELD_RESOURCE_ID, resourceId); + return criteria; + } +} diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/MeasurementDataGWTServiceImpl.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/MeasurementDataGWTServiceImpl.java index 52b5619..78232b6 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/MeasurementDataGWTServiceImpl.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/MeasurementDataGWTServiceImpl.java @@ -21,6 +21,7 @@ package org.rhq.enterprise.gui.coregui.server.gwt; import java.util.List; import java.util.Set;
+import org.rhq.core.domain.criteria.MeasurementDataTraitCriteria; import org.rhq.core.domain.criteria.MeasurementDefinitionCriteria; import org.rhq.core.domain.criteria.MeasurementScheduleCriteria; import org.rhq.core.domain.measurement.DisplayType; @@ -136,6 +137,10 @@ public class MeasurementDataGWTServiceImpl extends AbstractGWTServiceImpl implem collectionInterval); }
+ public PageList<MeasurementDataTrait> findTraitsByCriteria(MeasurementDataTraitCriteria criteria) { + return SerialUtility.prepare(dataManager.findTraitsByCriteria(getSessionSubject(), criteria), + "MeasurementDataService.findTraitsByCriteria"); + } }
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerBean.java index b3b4eff..3fece05 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerBean.java @@ -1,6 +1,6 @@ /* * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. + * Copyright (C) 2005-2010 Red Hat, Inc. * All rights reserved. * * This program is free software; you can redistribute it and/or modify @@ -55,6 +55,7 @@ import org.rhq.core.db.DatabaseType; import org.rhq.core.db.DatabaseTypeFactory; import org.rhq.core.db.Postgresql83DatabaseType; import org.rhq.core.domain.auth.Subject; +import org.rhq.core.domain.criteria.MeasurementDataTraitCriteria; import org.rhq.core.domain.measurement.DataType; import org.rhq.core.domain.measurement.DisplayType; import org.rhq.core.domain.measurement.MeasurementData; @@ -69,6 +70,7 @@ import org.rhq.core.domain.resource.Resource; import org.rhq.core.domain.resource.ResourceType; import org.rhq.core.domain.resource.group.ResourceGroup; import org.rhq.core.domain.util.OrderingField; +import org.rhq.core.domain.util.PageList; import org.rhq.core.domain.util.PageOrdering; import org.rhq.core.server.PersistenceUtility; import org.rhq.core.util.collection.ArrayUtils; @@ -88,6 +90,8 @@ import org.rhq.enterprise.server.measurement.instrumentation.MeasurementMonitor; import org.rhq.enterprise.server.measurement.uibean.MetricDisplaySummary; import org.rhq.enterprise.server.measurement.util.MeasurementDataManagerUtility; import org.rhq.enterprise.server.resource.group.ResourceGroupManagerLocal; +import org.rhq.enterprise.server.util.CriteriaQueryGenerator; +import org.rhq.enterprise.server.util.CriteriaQueryRunner;
/** * A manager for {@link MeasurementData}s. @@ -823,6 +827,32 @@ public class MeasurementDataManagerBean implements MeasurementDataManagerLocal, return result; }
+ public PageList<MeasurementDataTrait> findTraitsByCriteria(Subject subject, MeasurementDataTraitCriteria criteria) { + CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria); + + Map<String, Object> filterFields = generator.getFilterFields(criteria); + if (!this.authorizationManager.isInventoryManager(subject)) { + if (filterFields.get(MeasurementDataTraitCriteria.FILTER_FIELD_GROUP_ID) != null) { + generator.setAuthorizationResourceFragment(CriteriaQueryGenerator.AuthorizationTokenType.GROUP, + subject.getId()); + } else { + generator.setAuthorizationResourceFragment(CriteriaQueryGenerator.AuthorizationTokenType.RESOURCE, + subject.getId()); + } + } + + CriteriaQueryRunner<MeasurementDataTrait> queryRunner = new CriteriaQueryRunner(criteria, generator, + this.entityManager); + PageList<MeasurementDataTrait> results = queryRunner.execute(); + + // Fetch the definitions, so the results include the trait names. + for (MeasurementDataTrait result : results) { + result.getSchedule().getDefinition(); + } + + return results; + } + private MeasurementDataManagerUtility getConnectedUtilityInstance() { return MeasurementDataManagerUtility.getInstance(rhqDs); } diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerLocal.java index de557d0..7e4d87c 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerLocal.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerLocal.java @@ -1,6 +1,6 @@ /* * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. + * Copyright (C) 2005-2010 Red Hat, Inc. * All rights reserved. * * This program is free software; you can redistribute it and/or modify @@ -26,6 +26,8 @@ import java.util.Set; import javax.ejb.Local;
import org.rhq.core.domain.auth.Subject; +import org.rhq.core.domain.criteria.MeasurementDataTraitCriteria; +import org.rhq.core.domain.criteria.MeasurementScheduleCriteria; import org.rhq.core.domain.measurement.DisplayType; import org.rhq.core.domain.measurement.MeasurementData; import org.rhq.core.domain.measurement.MeasurementDataNumeric; @@ -37,6 +39,7 @@ import org.rhq.core.domain.measurement.composite.MeasurementDataNumericHighLowCo import org.rhq.core.domain.resource.Resource; import org.rhq.core.domain.resource.ResourceType; import org.rhq.core.domain.resource.group.ResourceGroup; +import org.rhq.core.domain.util.PageList; import org.rhq.enterprise.server.common.EntityContext; import org.rhq.enterprise.server.measurement.uibean.MetricDisplaySummary;
@@ -150,6 +153,16 @@ public interface MeasurementDataManagerLocal { List<MeasurementDataTrait> findCurrentTraitsForResource(Subject subject, int resourceId, DisplayType displayType);
/** + * Finds traits that match the specified {@link MeasurementDataTraitCriteria criteria}. + * + * @param subject the user that is requesting the traits + * @param criteria the criteria by which to filter the traits + * + * @return the traits that match the specified {@link MeasurementDataTraitCriteria criteria}; never null + */ + PageList<MeasurementDataTrait> findTraitsByCriteria(Subject subject, MeasurementDataTraitCriteria criteria); + + /** * Get live metrics for a given MeasurementSchedule * * @param sched MeasurementSchedule to obtain the data for diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerRemote.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerRemote.java index 6549d2c..032f8f9 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerRemote.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/measurement/MeasurementDataManagerRemote.java @@ -1,6 +1,6 @@ /* * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. + * Copyright (C) 2005-2010 Red Hat, Inc. * All rights reserved. * * This program is free software; you can redistribute it and/or modify @@ -29,10 +29,12 @@ import javax.jws.soap.SOAPBinding; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.rhq.core.domain.auth.Subject; +import org.rhq.core.domain.criteria.MeasurementDataTraitCriteria; import org.rhq.core.domain.measurement.DisplayType; import org.rhq.core.domain.measurement.MeasurementData; import org.rhq.core.domain.measurement.MeasurementDataTrait; import org.rhq.core.domain.measurement.composite.MeasurementDataNumericHighLowComposite; +import org.rhq.core.domain.util.PageList; import org.rhq.enterprise.server.jaxb.adapter.MeasurementDataNumericHighLowCompositeAdapter; import org.rhq.enterprise.server.system.ServerVersion;
@@ -60,6 +62,11 @@ public interface MeasurementDataManagerRemote { @WebParam(name = "displayType") DisplayType displayType);
@WebMethod + PageList<MeasurementDataTrait> findTraitsByCriteria( // + @WebParam(name = "subject") Subject subject, // + @WebParam(name = "criteria") MeasurementDataTraitCriteria criteria); + + @WebMethod Set<MeasurementData> findLiveData(// @WebParam(name = "subject") Subject subject, // @WebParam(name = "resourceId") int resourceId, //
commit 593d4cf0d05238b64584c14d9955f403e01f4f40 Author: John Mazzitelli mazz@redhat.com Date: Mon Aug 23 13:05:15 2010 -0400
bz 626497 - add rhq.agent.server.alias to be able to change the name of the server alias to look up (default is "rhqserver"). if you don't define it (e.g. comment it out of the config xml), the DNS lookup is never performed thus forcing the user to configure the server bind address explicitly
diff --git a/etc/agentspawn/src/main/resources/template-configuration.xml b/etc/agentspawn/src/main/resources/template-configuration.xml index 3a0d65a..4992b96 100644 --- a/etc/agentspawn/src/main/resources/template-configuration.xml +++ b/etc/agentspawn/src/main/resources/template-configuration.xml @@ -15,7 +15,7 @@ RHQ Agent Configuration - Default Template For Agent Spawn Utility <map /> <node name="spawn"> <!-- TO BE OVERRIDDEN --> <map> - <entry key="rhq.agent.configuration-schema-version" value="5" /> + <entry key="rhq.agent.configuration-schema-version" value="6" /> <entry key="rhq.agent.configuration-setup-flag" value="true" /> <entry key="rhq.agent.name" value="127.0.0.1"/> <!-- TO BE OVERRIDDEN -->
diff --git a/etc/agentspawn/src/scripts/agentcopy-agent-configuration.xml b/etc/agentspawn/src/scripts/agentcopy-agent-configuration.xml index 7d8110e..69b74f3 100644 --- a/etc/agentspawn/src/scripts/agentcopy-agent-configuration.xml +++ b/etc/agentspawn/src/scripts/agentcopy-agent-configuration.xml @@ -9,7 +9,7 @@ <map /> <node name="@@@AGENT_NODE@@@"> <map> - <entry key="rhq.agent.configuration-schema-version" value="5" /> + <entry key="rhq.agent.configuration-schema-version" value="6" /> <entry key="rhq.agent.configuration-setup-flag" value="true" /> <entry key="rhq.agent.name" value="agentcopy-@@@AGENT_NODE@@@"/> <entry key="rhq.agent.server.transport" value="@@@rhq.agent.server.transport@@@" /> diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfiguration.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfiguration.java index ae41e6f..11a2981 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfiguration.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfiguration.java @@ -200,9 +200,17 @@ public class AgentConfiguration { public String getServerBindAddress() { String address = m_preferences.get(AgentConfigurationConstants.SERVER_BIND_ADDRESS, null); if (address == null) { - try { - address = InetAddress.getByName("rhqserver").getCanonicalHostName(); - } catch (Exception e1) { + String alias = m_preferences.get(AgentConfigurationConstants.SERVER_ALIAS, null); + if (alias != null) { + try { + address = InetAddress.getByName(alias).getCanonicalHostName(); + } catch (Exception e1) { + LOG.debug(AgentI18NResourceKeys.SERVER_ALIAS_UNKNOWN, alias, e1); + address = null; + } + } + + if (address == null) { try { address = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e2) { @@ -1413,7 +1421,7 @@ public class AgentConfiguration { try { m_preferences.flush(); } catch (Exception e) { - LOG.warn(LOG.getMsgString(AgentI18NResourceKeys.CANNOT_STORE_PREFERENCES), changedPreference, e); + LOG.warn(AgentI18NResourceKeys.CANNOT_STORE_PREFERENCES, changedPreference, e); } } } \ No newline at end of file diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationConstants.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationConstants.java index c32d04b..6f21139 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationConstants.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationConstants.java @@ -58,7 +58,7 @@ public interface AgentConfigurationConstants { /** * This is the current schema version that our agent configuration knows about. */ - int CURRENT_CONFIG_SCHEMA_VERSION = 5; + int CURRENT_CONFIG_SCHEMA_VERSION = 6;
/** * Flag to indicate if the agent's configuration has been setup. @@ -112,6 +112,11 @@ public interface AgentConfigurationConstants { String DEFAULT_SERVER_TRANSPORT_PARAMS = "/jboss-remoting-servlet-invoker/ServerInvokerServlet";
/** + * The DNS alias for the RHQ Server - used when the server IP address is not explicitly set. + */ + String SERVER_ALIAS = PROPERTY_NAME_PREFIX + "server.alias"; + + /** * The flag that, if <code>true</code>, will tell the agent to attempt to auto-detect the JON Server coming online * and going offline. */ diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationUpgrade.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationUpgrade.java index 562a487..6c0a2ce 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationUpgrade.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentConfigurationUpgrade.java @@ -58,6 +58,7 @@ public class AgentConfigurationUpgrade extends PreferencesUpgrade { list.add(new Step2to3()); // goes from v2 to v3 list.add(new Step3to4()); // goes from v3 to v4 list.add(new Step4to5()); // goes from v4 to v5 + list.add(new Step5to6()); return list; }
@@ -126,4 +127,16 @@ public class AgentConfigurationUpgrade extends PreferencesUpgrade { } } } + + static class Step5to6 extends PreferencesUpgradeStep { + public int getSupportedConfigurationSchemaVersion() { + return 6; + } + + public void upgrade(Preferences preferences) { + // This new schema version added rhq.server.alias - to support backwards compatibility, we want + // to set this to "rhqserver" which will cause the same behavior that was exhibited in previous versions + preferences.put(AgentConfigurationConstants.SERVER_ALIAS, "rhqserver"); + } + } } \ No newline at end of file diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java index eadb493..7920df0 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentI18NResourceKeys.java @@ -28,6 +28,9 @@ import mazz.i18n.annotation.I18NResourceBundle; */ @I18NResourceBundle(baseName = "agent-messages", defaultLocale = "en") public interface AgentI18NResourceKeys { + @I18NMessage("The configured server alias [{0}] cannot be resolved - will use localhost address. Cause: {1}") + String SERVER_ALIAS_UNKNOWN = "AgentConfiguration.server-alias-unknown"; + @I18NMessage("Specified bad console type [{0}]") String AGENT_INPUT_READER_FACTORY_BAD_TYPE = "AgentMain.input-reader-factory-bad-type";
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentSetupInstructions.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentSetupInstructions.java index 985c764..faf3692 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentSetupInstructions.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/i18n/AgentSetupInstructions.java @@ -78,6 +78,16 @@ public interface AgentSetupInstructions { + "and all the different values allowed for the specific transport being used.") }) String SETUP_INSTRUCTION_SERVERTRANSPORTPARAMS_HELP = "PromptCommand.setup.instruction.serveruri.transportparams.help";
+ // SERVER ALIAS + String SETUP_INSTRUCTION_SERVERALIAS_PREF = AgentConfigurationConstants.SERVER_ALIAS; + String SETUP_INSTRUCTION_SERVERALIAS_DEFAULT = null; + @I18NMessages( { @I18NMessage("RHQ Server Alias") }) + String SETUP_INSTRUCTION_SERVERALIAS_PROMPT = "PromptCommand.setup.instruction.serveralias.prompt"; + @I18NMessages( { @I18NMessage("If the RHQ Server hostname or IP address was not set,\n\\n" + + "this DNS alias name will be looked up and used as the RHQ Server host.\n\\n" + + "Not setting this preference will disable this DNS alias lookup feature") }) + String SETUP_INSTRUCTION_SERVERALIAS_HELP = "PromptCommand.setup.instruction.serveralias.help"; + // SERVER AUTO-DETECTION String SETUP_INSTRUCTION_SERVERAUTODETECT_PREF = AgentConfigurationConstants.SERVER_AUTO_DETECTION; String SETUP_INSTRUCTION_SERVERAUTODETECT_DEFAULT = Boolean diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/SetupPromptCommand.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/SetupPromptCommand.java index 4c9226a..7c8152a 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/SetupPromptCommand.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/promptcmd/SetupPromptCommand.java @@ -81,7 +81,8 @@ public class SetupPromptCommand implements AgentPromptCommand { if (args.length == 1) { performBasicSetup(agent.getConfiguration().getPreferences(), new AgentPromptInfo(agent), agent.getOut()); } else if ((args.length == 2) && args[1].equals(MSG.getMsg(AgentI18NResourceKeys.SETUP_ADVANCED))) { - performAdvancedSetup(agent.getConfiguration().getPreferences(), new AgentPromptInfo(agent), agent.getOut()); + performAdvancedSetup(agent.getConfiguration().getPreferences(), new AgentPromptInfo(agent), agent + .getOut()); } else if ((args.length == 2) && args[1].equals(MSG.getMsg(AgentI18NResourceKeys.SETUP_ALL))) { performAllSetup(agent.getConfiguration().getPreferences(), new AgentPromptInfo(agent), agent.getOut()); } else { @@ -248,6 +249,11 @@ public class SetupPromptCommand implements AgentPromptCommand { .getMsg(AgentSetupInstructions.SETUP_INSTRUCTION_SERVERTRANSPORTPARAMS_PROMPT), SETUPMSG .getMsg(AgentSetupInstructions.SETUP_INSTRUCTION_SERVERTRANSPORTPARAMS_HELP)));
+ instr.add(new DefaultSetupInstruction(AgentSetupInstructions.SETUP_INSTRUCTION_SERVERALIAS_PREF, + AgentSetupInstructions.SETUP_INSTRUCTION_SERVERALIAS_DEFAULT, null, SETUPMSG + .getMsg(AgentSetupInstructions.SETUP_INSTRUCTION_SERVERALIAS_PROMPT), SETUPMSG + .getMsg(AgentSetupInstructions.SETUP_INSTRUCTION_SERVERALIAS_HELP))); + instr.add(new SecurityEnabledSetupInstruction(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, AgentSetupInstructions.SETUP_INSTRUCTION_SERVERCLIENTAUTHMODE_PREF, AgentSetupInstructions.SETUP_INSTRUCTION_SERVERCLIENTAUTHMODE_DEFAULT, diff --git a/modules/enterprise/agent/src/main/resources/agent-configuration.xml b/modules/enterprise/agent/src/main/resources/agent-configuration.xml index f36b459..66e1d59 100644 --- a/modules/enterprise/agent/src/main/resources/agent-configuration.xml +++ b/modules/enterprise/agent/src/main/resources/agent-configuration.xml @@ -59,7 +59,7 @@ commands named "config", "setconfig" and "setup" and the command line options file conforms to. This is the schema for the rhq.agent preferences. --> - <entry key="rhq.agent.configuration-schema-version" value="5" /> + <entry key="rhq.agent.configuration-schema-version" value="6" />
<!-- _______________________________________________________________ @@ -106,6 +106,7 @@ commands named "config", "setconfig" and "setup" and the command line options rhq.agent.server.bind-address rhq.agent.server.bind-port rhq.agent.server.transport-params + rhq.agent.server.alias
The RHQ Server endpoint configuration.
@@ -114,8 +115,9 @@ commands named "config", "setconfig" and "setup" and the command line options to separate the transport parameters.
Note that the server address is left undefined - the agent - will default to the DNS alias of "rhqserver" and if that is not - defined, it will default to the localhost or 127.0.0.1. + will default to the DNS alias (see rhq.agent.server.alias) + and if that is not defined, it will default to the localhost + or 127.0.0.1. --> <entry key="rhq.agent.server.transport" value="servlet" /> <entry key="rhq.agent.server.bind-port" value="7080" /> @@ -123,6 +125,7 @@ commands named "config", "setconfig" and "setup" and the command line options <entry key="rhq.agent.server.bind-address" value="127.0.0.1" /> --> <entry key="rhq.agent.server.transport-params" value="/jboss-remoting-servlet-invoker/ServerInvokerServlet" /> + <entry key="rhq.agent.server.alias" value="rhqserver" />
<!-- _______________________________________________________________ diff --git a/modules/enterprise/agent/src/test/resources/test-agent-configuration.xml b/modules/enterprise/agent/src/test/resources/test-agent-configuration.xml index e832f13..a3da93e 100644 --- a/modules/enterprise/agent/src/test/resources/test-agent-configuration.xml +++ b/modules/enterprise/agent/src/test/resources/test-agent-configuration.xml @@ -29,7 +29,7 @@
<!-- the "real" settings --> <entry key="rhq.agent.name" value="jboss-on" /> - <entry key="rhq.agent.configuration-schema-version" value="5" /> + <entry key="rhq.agent.configuration-schema-version" value="6" /> <entry key="rhq.agent.configuration-setup-flag" value="true" /> <entry key="rhq.agent.server.transport" value="socket" /> <entry key="rhq.agent.server.bind-address" value="127.0.0.1" /> diff --git a/modules/enterprise/agent/src/test/resources/test-agent1-cfg-mvn.xml b/modules/enterprise/agent/src/test/resources/test-agent1-cfg-mvn.xml index 84187f9..2d8c91f 100644 --- a/modules/enterprise/agent/src/test/resources/test-agent1-cfg-mvn.xml +++ b/modules/enterprise/agent/src/test/resources/test-agent1-cfg-mvn.xml @@ -29,7 +29,7 @@
<!-- the "real" settings --> <entry key="rhq.agent.name" value="jboss-on" /> - <entry key="rhq.agent.configuration-schema-version" value="5" /> + <entry key="rhq.agent.configuration-schema-version" value="6" /> <entry key="rhq.agent.configuration-setup-flag" value="true" /> <entry key="rhq.agent.server.transport" value="socket" /> <entry key="rhq.agent.server.bind-address" value="127.0.0.1" /> diff --git a/modules/enterprise/agent/src/test/resources/test-agent2-cfg-mvn.xml b/modules/enterprise/agent/src/test/resources/test-agent2-cfg-mvn.xml index 2dd7334..7321e5b 100644 --- a/modules/enterprise/agent/src/test/resources/test-agent2-cfg-mvn.xml +++ b/modules/enterprise/agent/src/test/resources/test-agent2-cfg-mvn.xml @@ -48,7 +48,7 @@
<!-- the "real" settings --> <entry key="rhq.agent.name" value="jboss-on" /> - <entry key="rhq.agent.configuration-schema-version" value="5" /> + <entry key="rhq.agent.configuration-schema-version" value="6" /> <entry key="rhq.agent.configuration-setup-flag" value="true" /> <entry key="rhq.agent.server.transport" value="socket" /> <entry key="rhq.agent.server.bind-address" value="127.0.0.1" /> diff --git a/modules/enterprise/agent/src/test/resources/test-agent2-configuration.xml b/modules/enterprise/agent/src/test/resources/test-agent2-configuration.xml index 6a7aaff..d5b4738 100644 --- a/modules/enterprise/agent/src/test/resources/test-agent2-configuration.xml +++ b/modules/enterprise/agent/src/test/resources/test-agent2-configuration.xml @@ -18,7 +18,7 @@
<!-- the "real" settings --> <entry key="rhq.agent.name" value="jboss-on2" /> - <entry key="rhq.agent.configuration-schema-version" value="5" /> + <entry key="rhq.agent.configuration-schema-version" value="6" /> <entry key="rhq.agent.configuration-setup-flag" value="true" /> <entry key="rhq.agent.server.transport" value="socket" /> <entry key="rhq.agent.server.bind-address" value="127.0.0.1" /> diff --git a/modules/enterprise/server/sars/agent-sar/src/main/resources/META-INF/embedded-agent-configuration.xml b/modules/enterprise/server/sars/agent-sar/src/main/resources/META-INF/embedded-agent-configuration.xml index b2702cd..68e8719 100644 --- a/modules/enterprise/server/sars/agent-sar/src/main/resources/META-INF/embedded-agent-configuration.xml +++ b/modules/enterprise/server/sars/agent-sar/src/main/resources/META-INF/embedded-agent-configuration.xml @@ -23,7 +23,7 @@ Embedded RHQ Agent Configuration file conforms to. This is the schema for the rhq.agent preferences. --> - <entry key="rhq.agent.configuration-schema-version" value="5" /> + <entry key="rhq.agent.configuration-schema-version" value="6" />
<!-- _______________________________________________________________ diff --git a/modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml index dbfdfe2..df799fe 100644 --- a/modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml +++ b/modules/plugins/rhq-agent/src/main/resources/META-INF/rhq-plugin.xml @@ -379,6 +379,7 @@ </c:constraint> </c:simple-property> <c:simple-property name="rhq.agent.server.transport-params" type="string" activationPolicy="restart" required="false" default="/jboss-remoting-servlet-invoker/ServerInvokerServlet" displayName="RHQ Server Transport Parameters" description="Custom set of transport parameters used when sending commands to the RHQ Server. Please see the documentation for more information on transport params." /> + <c:simple-property name="rhq.agent.server.alias" type="string" activationPolicy="restart" required="false" default="rhqserver" displayName="RHQ Server Alias" description="If the RHQ Server IP address is not defined, this is the DNS alias name that will be looked up to determine the RHQ Server IP address." /> <c:simple-property name="rhq.communications.connector.transport" type="string" activationPolicy="restart" required="true" default="socket" displayName="Agent Transport Protocol" description="The transport protocol used to receive commands from the RHQ Server. e.g. socket, sslsocket. If you want secure communications, you must use an SSL-enabled transport"> <c:property-options> <c:option name="socket" value="socket" default="true" /> diff --git a/modules/plugins/rhq-agent/src/test/resources/test-agent-configuration.xml b/modules/plugins/rhq-agent/src/test/resources/test-agent-configuration.xml index 7dc685c..a5209a8 100644 --- a/modules/plugins/rhq-agent/src/test/resources/test-agent-configuration.xml +++ b/modules/plugins/rhq-agent/src/test/resources/test-agent-configuration.xml @@ -18,7 +18,7 @@
<!-- the "real" settings --> <entry key="rhq.agent.name" value="jboss-on" /> - <entry key="rhq.agent.configuration-schema-version" value="5" /> + <entry key="rhq.agent.configuration-schema-version" value="6" /> <entry key="rhq.agent.configuration-setup-flag" value="true" /> <entry key="rhq.agent.server.transport" value="socket" /> <entry key="rhq.agent.server.bind-address" value="127.0.0.1" />
commit fdc507c69f1ac14bf1c457b03098931f094385fd Author: John Sanda jsanda@redhat.com Date: Sun Aug 22 06:28:23 2010 -0400
Adding logic to handle script exceptions
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy index 28f2056..3937c51 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy @@ -58,10 +58,16 @@ class ScriptRunner implements ServerPluginComponent, ControlFacet { // Calling setEntityMap() worked though. //script.entityMap = entityMap script.setEntityMap(entityMap) - def scriptResult = script.run()
- ControlResults results = new ControlResults() - results.complexResults.put(new PropertySimple("results", scriptResult)) + def results = new ControlResults() + + try { + def scriptResult = script.run() + results.complexResults.put(new PropertySimple("results", scriptResult)) + } + catch (Throwable t) { + results.error = t + }
return results; } diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy index 0924ab7..6900943 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy @@ -16,6 +16,7 @@ import org.testng.annotations.BeforeMethod import org.testng.annotations.Test import static org.testng.Assert.assertEquals import static org.testng.Assert.assertTrue +import static org.testng.Assert.assertNotNull import org.rhq.core.domain.test.TestEntity
class ScriptRunnerTest { @@ -54,9 +55,13 @@ class ScriptRunnerTest { } }
- @Test(expectedExceptions = [RHQScriptException]) void throwExceptionWhenManagerAccessedDoesNotExist() { - executeScript('access_nonexistent_mgr.groovy') + def result = executeScript('access_nonexistent_mgr.groovy') + assertEquals( + result.error, + "$RHQScriptException.name: Unable to locate NonexistentManager", + "Expected error to be set when script tries to access nonexistent manager" + ) }
@Test @@ -83,6 +88,17 @@ class ScriptRunnerTest { } }
+ @Test + void handleScriptExceptions() { + def result = executeScript('throw_exception.groovy') + + assertEquals( + "$result.error", + "$RuntimeException.name: script failed!", + "error property should be set when script throws an exception" + ) + } + def executeScript(String script) { def params = new Configuration() params.put(new PropertySimple('script', getScriptPath(script))) diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/throw_exception.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/throw_exception.groovy new file mode 100644 index 0000000..728e2ed --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/throw_exception.groovy @@ -0,0 +1,3 @@ +package org.rhq.enterprise.server.plugins.groovy + +throw new RuntimeException("script failed!")
commit c88a6b75de474c9d123523260a12aa176712ad01 Author: John Sanda jsanda@redhat.com Date: Sat Aug 21 09:36:35 2010 -0400
Adding opencsv test dependency that was missing from server/jar
diff --git a/modules/enterprise/gui/webdav-war/webdav-war.iml b/modules/enterprise/gui/webdav-war/webdav-war.iml deleted file mode 100644 index 2147216..0000000 --- a/modules/enterprise/gui/webdav-war/webdav-war.iml +++ /dev/null @@ -1,169 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module relativePaths="true" MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> - <component name="FacetManager"> - <facet type="web" name="Web"> - <configuration> - <descriptors> - <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" optional="false" version="2.5" /> - </descriptors> - <webroots> - <root url="file://$MODULE_DIR$/src/main/webapp" relative="/" /> - <root url="file://$MODULE_DIR$//home/ghinkle/projects/jbosson/rhq/modules/enterprise/gui/webdav-war/src/main/webapp" relative="/" /> - <root url="file://$MODULE_DIR$//home/ghinkle/projects/jbosson/rhq/modules/enterprise/gui/webdav-war/src/main/webapp-filtered" relative="/" /> - </webroots> - <building> - <setting name="EXPLODED_URL" value="file://$MODULE_DIR$/../../../../../out/exploded/webdav-warWeb" /> - <setting name="EXPLODED_ENABLED" value="true" /> - <setting name="JAR_URL" value="file://" /> - <setting name="JAR_ENABLED" value="false" /> - <setting name="EXCLUDE_EXPLODED_DIRECTORY" value="true" /> - </building> - <packaging> - <containerElement type="library" name="Maven: i18nlog:i18nlog:1.0.9" level="project"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/lib/" /> - </containerElement> - <containerElement type="module" name="rhq-core-gui"> - <attribute name="method" value="5" /> - <attribute name="URI" value="/WEB-INF/lib/rhq-core-gui-1.2.0-SNAPSHOT.jar" /> - </containerElement> - <containerElement type="library" name="Maven: org.richfaces.framework:richfaces-api:3.3.0.GA" level="project"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/lib/" /> - </containerElement> - <containerElement type="library" name="Maven: commons-collections:commons-collections:3.2" level="project"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/lib/" /> - </containerElement> - <containerElement type="library" name="Maven: commons-beanutils:commons-beanutils:1.6.1" level="project"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/lib/" /> - </containerElement> - <containerElement type="library" name="Maven: org.richfaces.framework:richfaces-impl:3.3.0.GA" level="project"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/lib/" /> - </containerElement> - <containerElement type="library" name="Maven: commons-digester:commons-digester:1.8" level="project"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/lib/" /> - </containerElement> - <containerElement type="library" name="Maven: org.richfaces.ui:richfaces-ui:3.3.0.GA" level="project"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/lib/" /> - </containerElement> - <containerElement type="library" name="Maven: ettrema:milton-api:1.2" level="project"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/lib/" /> - </containerElement> - <containerElement type="library" name="Maven: ettrema:milton-servlet:1.2" level="project"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/lib/" /> - </containerElement> - <containerElement type="library" name="Maven: org.slf4j:slf4j-jdk14:1.5.6" level="project"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/lib/" /> - </containerElement> - <containerElement type="library" name="Maven: org.slf4j:slf4j-api:1.5.6" level="project"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/lib/" /> - </containerElement> - <containerElement type="library" name="Maven: javax.servlet:jstl:1.1.2" level="project"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/lib/" /> - </containerElement> - <containerElement type="module" name="webdav-war"> - <attribute name="method" value="1" /> - <attribute name="URI" value="/WEB-INF/classes" /> - </containerElement> - </packaging> - </configuration> - </facet> - </component> - <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false"> - <output url="file://$MODULE_DIR$/target/classes" /> - <output-test url="file://$MODULE_DIR$/target/test-classes" /> - <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> - <excludeFolder url="file://$MODULE_DIR$/target" /> - </content> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - <orderEntry type="module-library"> - <library> - <CLASSES> - <root url="jar://$APPLICATION_HOME_DIR$/lib/javaee.jar!/" /> - </CLASSES> - <JAVADOC /> - <SOURCES /> - </library> - </orderEntry> - <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.0.jboss" level="project" /> - <orderEntry type="library" exported="" name="Maven: i18nlog:i18nlog:1.0.9" level="project" /> - <orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.1" level="project" /> - <orderEntry type="library" name="Maven: javax.xml.stream:stax-api:1.0-2" level="project" /> - <orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" /> - <orderEntry type="library" name="Maven: log4j:log4j:1.2.14" level="project" /> - <orderEntry type="library" name="Maven: org.testng:testng:jdk15:5.7" level="project" /> - <orderEntry type="library" name="Maven: junit:junit:3.8.1" level="project" /> - <orderEntry type="library" name="Maven: org.jetbrains:annotations:7.0.2" level="project" /> - <orderEntry type="module" module-name="rhq-core-domain" /> - <orderEntry type="module" module-name="rhq-core-util" /> - <orderEntry type="library" name="Maven: jdom:jdom:1.0" level="project" /> - <orderEntry type="module" module-name="rhq-core-gui" exported="" /> - <orderEntry type="library" exported="" name="Maven: org.richfaces.framework:richfaces-api:3.3.0.GA" level="project" /> - <orderEntry type="library" exported="" name="Maven: commons-collections:commons-collections:3.2" level="project" /> - <orderEntry type="library" exported="" name="Maven: commons-beanutils:commons-beanutils:1.6.1" level="project" /> - <orderEntry type="library" exported="" name="Maven: org.richfaces.framework:richfaces-impl:3.3.0.GA" level="project" /> - <orderEntry type="library" exported="" name="Maven: commons-digester:commons-digester:1.8" level="project" /> - <orderEntry type="library" exported="" name="Maven: org.richfaces.ui:richfaces-ui:3.3.0.GA" level="project" /> - <orderEntry type="module" module-name="rhq-enterprise-server" /> - <orderEntry type="module" module-name="rhq-enterprise-comm" /> - <orderEntry type="module" module-name="rhq-core-comm-api" /> - <orderEntry type="library" name="Maven: dom4j:dom4j:1.6.1-jboss" level="project" /> - <orderEntry type="library" name="Maven: gnu-getopt:getopt:1.0.13" level="project" /> - <orderEntry type="library" name="Maven: jboss:jboss-common:1.2.0.GA" level="project" /> - <orderEntry type="library" name="Maven: jboss:jboss-jmx:4.2.1.GA" level="project" /> - <orderEntry type="library" name="Maven: jboss:jboss-remoting:2.2.1.GA" level="project" /> - <orderEntry type="library" name="Maven: jboss:jboss-serialization:1.0.3.GA" level="project" /> - <orderEntry type="library" name="Maven: oswego-concurrent:concurrent:1.3.4-jboss" level="project" /> - <orderEntry type="module" module-name="rhq-core-client-api" /> - <orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-impl:2.1.6" level="project" /> - <orderEntry type="module" module-name="rhq-core-dbutils" /> - <orderEntry type="library" name="Maven: ant:ant:1.6.5" level="project" /> - <orderEntry type="library" name="Maven: commons-httpclient:commons-httpclient:3.0.1" level="project" /> - <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.2" level="project" /> - <orderEntry type="library" name="Maven: commons-validator:commons-validator:1.1.4" level="project" /> - <orderEntry type="library" name="Maven: jboss:jboss-cache:1.4.1.SP3" level="project" /> - <orderEntry type="library" name="Maven: jboss:jbpm:3.1.1" level="project" /> - <orderEntry type="library" name="Maven: org.snmp4j:snmp4j:1.8.2" level="project" /> - <orderEntry type="library" name="Maven: postgresql:postgresql:8.3-604.jdbc3" level="project" /> - <orderEntry type="library" name="Maven: rss4j:rss4j:0.92-on.2" level="project" /> - <orderEntry type="library" exported="" name="Maven: org.slf4j:slf4j-jdk14:1.5.6" level="project" /> - <orderEntry type="library" exported="" name="Maven: org.slf4j:slf4j-api:1.5.6" level="project" /> - <orderEntry type="library" name="Maven: hibernate:hibernate3:3.2.r14201-2" level="project" /> - <orderEntry type="library" name="Maven: hibernate-annotations:hibernate-annotations:3.2.1.GA" level="project" /> - <orderEntry type="library" name="Maven: javax.persistence:persistence-api:1.0" level="project" /> - <orderEntry type="library" exported="" name="Maven: javax.servlet:jstl:1.1.2" level="project" /> - <orderEntry type="library" name="Maven: jboss:jboss-ejb-api:4.2.1.GA" level="project" /> - <orderEntry type="library" name="Maven: jboss:jboss-j2ee:4.2.1.GA" level="project" /> - <orderEntry type="module-library"> - <library> - <CLASSES> - <root url="jar://$M2_REPO$/com/ettrema/milton-api/1.4.1/milton-api-1.4.1.jar!/" /> - </CLASSES> - <JAVADOC /> - <SOURCES /> - </library> - </orderEntry> - <orderEntry type="module-library"> - <library> - <CLASSES> - <root url="jar://$M2_REPO$/com/ettrema/milton-servlet/1.4.1/milton-servlet-1.4.1.jar!/" /> - </CLASSES> - <JAVADOC /> - <SOURCES /> - </library> - </orderEntry> - </component> -</module> - diff --git a/modules/enterprise/server/jar/pom.xml b/modules/enterprise/server/jar/pom.xml index b0b3484..04d3557 100644 --- a/modules/enterprise/server/jar/pom.xml +++ b/modules/enterprise/server/jar/pom.xml @@ -393,6 +393,13 @@ <version>${version}</version> <scope>test</scope> </dependency> + + <dependency> + <groupId>net.sf.opencsv</groupId> + <artifactId>opencsv</artifactId> + <version>1.8</version> + <scope>test</scope> + </dependency>
</dependencies>
commit aa341e76cdb545e6651c332094e29446204942bc Author: John Sanda jsanda@redhat.com Date: Sat Aug 21 08:59:16 2010 -0400
Adding groovy script plugin to build
diff --git a/modules/enterprise/server/plugins/pom.xml b/modules/enterprise/server/plugins/pom.xml index 07be817..5ff09b2 100644 --- a/modules/enterprise/server/plugins/pom.xml +++ b/modules/enterprise/server/plugins/pom.xml @@ -83,6 +83,7 @@ <module>filetemplate-bundle</module> <module>ant-bundle</module> <module>validate-all-serverplugins</module> + <module>groovy-script</module> </modules>
</project>
commit 876398c1751c450495a23d3d6e88810cf6553f37 Merge: 81667f2... 51dd587... Author: John Sanda jsanda@redhat.com Date: Sat Aug 21 08:34:42 2010 -0400
Merge branch 'master' of ssh://git.fedorahosted.org/git/rhq/rhq
commit 81667f27c16d39d1b1b49c8350b8413b049b5186 Author: John Sanda jsanda@redhat.com Date: Sat Aug 21 00:38:35 2010 -0400
Re-enabling test
diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy index 877f5b0..0924ab7 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy @@ -16,6 +16,7 @@ import org.testng.annotations.BeforeMethod import org.testng.annotations.Test import static org.testng.Assert.assertEquals import static org.testng.Assert.assertTrue +import org.rhq.core.domain.test.TestEntity
class ScriptRunnerTest {
@@ -58,8 +59,14 @@ class ScriptRunnerTest { executeScript('access_nonexistent_mgr.groovy') }
- @Test(enabled = false) + @Test void createCriteriaAccordingToSpec() { + scriptRunner.entityMap << [TestEntity: TestEntity.class] + + def testMgr = {} + def lookupUtil = new MockFor(LookupUtil) + lookupUtil.demand.getTestEntityManager { testMgr } + def expectedCriteria = new TestEntityCriteria() expectedCriteria.id = 1 expectedCriteria.name = 'Test' @@ -69,9 +76,11 @@ class ScriptRunnerTest { expectedCriteria.addSortId(PageOrdering.DESC) expectedCriteria.addSortName(PageOrdering.DESC)
- def result = executeScript('create_criteria.groovy') + lookupUtil.use { + def result = executeScript('create_criteria.groovy')
- assertScriptResultEquals(result, expectedCriteria.toString(), 'Failed to generate criteria correctly') + assertScriptResultEquals(result, expectedCriteria.toString(), 'Failed to generate criteria correctly') + } }
def executeScript(String script) {
commit 29f040e5b56ff2dee9533816fc755707c71c2b11 Author: John Sanda jsanda@redhat.com Date: Sat Aug 21 00:33:53 2010 -0400
Adding test to verify that the entity map cache is populated
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy index 922facf..28f2056 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy @@ -16,11 +16,13 @@ import org.rhq.enterprise.server.plugin.pc.ServerPluginContext
class ScriptRunner implements ServerPluginComponent, ControlFacet {
+ String entityPackagePrefix = "org.rhq.core.domain" + Map entityMap = [:]
void initialize(ServerPluginContext context) { def reflections = new Reflections(new ConfigurationBuilder() - .setUrls(ClasspathHelper.getUrlsForPackagePrefix("org.rhq.core.domain")) + .setUrls(ClasspathHelper.getUrlsForPackagePrefix(entityPackagePrefix)) .setScanners(new TypeAnnotationsScanner())); def classes = reflections.getTypesAnnotatedWith(Entity.class)
diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntity.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntity.groovy index 04b21b4..7f02ba7 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntity.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntity.groovy @@ -1,5 +1,8 @@ package org.rhq.core.domain.test
+import javax.persistence.Entity + +@Entity class TestEntity {
Integer id diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy index 312ea47..79703ee 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy @@ -1,4 +1,7 @@ package org.rhq.core.domain.test
+import javax.persistence.Entity + +@Entity class TestEntityWithoutCriteria { } diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy index 24170ed..877f5b0 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy @@ -1,25 +1,21 @@ package org.rhq.enterprise.server.plugins.groovy
-import org.testng.annotations.Test import groovy.mock.interceptor.MockFor -import org.rhq.enterprise.server.util.LookupUtil +import javax.persistence.Entity +import org.reflections.Reflections +import org.reflections.scanners.TypeAnnotationsScanner +import org.reflections.util.ClasspathHelper +import org.reflections.util.ConfigurationBuilder import org.rhq.core.domain.configuration.Configuration import org.rhq.core.domain.configuration.PropertySimple - -import static org.testng.Assert.* -import org.rhq.enterprise.server.plugin.pc.ControlResults import org.rhq.core.domain.criteria.TestEntityCriteria -import org.testng.annotations.BeforeClass -import org.rhq.core.domain.test.TestEntity import org.rhq.core.domain.util.PageOrdering +import org.rhq.enterprise.server.plugin.pc.ControlResults +import org.rhq.enterprise.server.util.LookupUtil import org.testng.annotations.BeforeMethod -import org.reflections.Reflections -import javax.persistence.Entity -import org.reflections.scanners.SubTypesScanner -import org.reflections.scanners.TypeAnnotationsScanner -import org.reflections.scanners.ResourcesScanner -import org.reflections.util.ClasspathHelper -import org.reflections.util.ConfigurationBuilder +import org.testng.annotations.Test +import static org.testng.Assert.assertEquals +import static org.testng.Assert.assertTrue
class ScriptRunnerTest {
@@ -28,7 +24,17 @@ class ScriptRunnerTest { @BeforeMethod void setup() { scriptRunner = new ScriptRunner() - scriptRunner.entityMap << [TestEntity: TestEntity.class] + } + + @Test + void populateEntityMap() { + scriptRunner.entityPackagePrefix = 'org.rhq.core.domain.test' + scriptRunner.initialize(null) + + assertEquals(scriptRunner.entityMap.size(), 2, "Expected to entityMap to contain two entries") + assertTrue(scriptRunner.entityMap.containsKey('TestEntity'), "Expected to find <TestEntity> in entity map") + assertTrue(scriptRunner.entityMap.containsKey('TestEntityWithoutCriteria'), + "Expected to find <TestEntityWithoutCriteria> in entity map") }
@Test @@ -68,17 +74,6 @@ class ScriptRunnerTest { assertScriptResultEquals(result, expectedCriteria.toString(), 'Failed to generate criteria correctly') }
- @Test - void scanClasspath() { - Reflections reflections = new Reflections(new ConfigurationBuilder() - .setUrls(ClasspathHelper.getUrlsForPackagePrefix("org.rhq.core.domain")) - .setScanners(new TypeAnnotationsScanner())); - def classes = reflections.getTypesAnnotatedWith(Entity.class) - - println "Found ${classes.size()} entities" - assertTrue(classes.size() > 5, "Found ${classes.size()} entities") - } - def executeScript(String script) { def params = new Configuration() params.put(new PropertySimple('script', getScriptPath(script)))
commit 47ade1fdd82c7d11b64a48db422d8ba9055f188a Author: John Sanda jsanda@redhat.com Date: Sat Aug 21 00:07:11 2010 -0400
Adding logic to dynamically generate entity map
diff --git a/modules/enterprise/server/plugins/groovy-script/pom.xml b/modules/enterprise/server/plugins/groovy-script/pom.xml index 22b86e0..1abb9b3 100644 --- a/modules/enterprise/server/plugins/groovy-script/pom.xml +++ b/modules/enterprise/server/plugins/groovy-script/pom.xml @@ -54,6 +54,11 @@ <version>4.2.3.GA</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.reflections</groupId> + <artifactId>reflections</artifactId> + <version>0.9.5-RC2</version> + </dependency> </dependencies>
<build> @@ -74,8 +79,32 @@ <artifactItem> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> - <version>1.7.1</version> + <version>1.7.3</version> + </artifactItem> + <artifactItem> + <groupId>org.reflections</groupId> + <artifactId>reflections</artifactId> + </artifactItem> + <artifactItem> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.5.6</version> </artifactItem> + <artifactItem> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>1.5.6</version> + </artifactItem> + <artifactItem> + <groupId>com.google.collections</groupId> + <artifactId>google-collections</artifactId> + <version>1.0</version> + </artifactItem> + <artifactItem> + <groupId>javassist</groupId> + <artifactId>javassist</artifactId> + <version>3.8.0.GA</version> + </artifactItem> </artifactItems> <outputDirectory>${project.build.outputDirectory}/lib</outputDirectory> </configuration> @@ -189,4 +218,12 @@ </profile>
</profiles> + + <repositories> + <repository> + <id>reflections-repo</id> + <name>Reflections Maven2 Repository</name> + <url>http://reflections.googlecode.com/svn/repo</url> + </repository> + </repositories> </project> diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy index 5245756..922facf 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy @@ -1,25 +1,30 @@ package org.rhq.enterprise.server.plugins.groovy
+import javax.persistence.Entity import org.codehaus.groovy.control.CompilerConfiguration +import org.reflections.Reflections +import org.reflections.scanners.TypeAnnotationsScanner +import org.reflections.util.ClasspathHelper +import org.reflections.util.ConfigurationBuilder import org.rhq.core.domain.configuration.Configuration import org.rhq.core.domain.configuration.PropertySimple import org.rhq.enterprise.server.plugin.pc.ControlFacet import org.rhq.enterprise.server.plugin.pc.ControlResults +import org.rhq.enterprise.server.plugin.pc.ScheduledJobInvocationContext import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent import org.rhq.enterprise.server.plugin.pc.ServerPluginContext -import org.rhq.core.domain.resource.Resource -import org.rhq.core.domain.resource.ResourceType -import org.rhq.enterprise.server.plugin.pc.ScheduledJobInvocationContext
class ScriptRunner implements ServerPluginComponent, ControlFacet {
- Map entityMap = [ - Resource: Resource.class, - ResourceType: ResourceType.class - ] + Map entityMap = [:]
void initialize(ServerPluginContext context) { + def reflections = new Reflections(new ConfigurationBuilder() + .setUrls(ClasspathHelper.getUrlsForPackagePrefix("org.rhq.core.domain")) + .setScanners(new TypeAnnotationsScanner())); + def classes = reflections.getTypesAnnotatedWith(Entity.class)
+ classes.each { entityMap << [(it.simpleName.toString()): it] } }
void start() { diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy index c8a00d6..24170ed 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy @@ -13,6 +13,13 @@ import org.testng.annotations.BeforeClass import org.rhq.core.domain.test.TestEntity import org.rhq.core.domain.util.PageOrdering import org.testng.annotations.BeforeMethod +import org.reflections.Reflections +import javax.persistence.Entity +import org.reflections.scanners.SubTypesScanner +import org.reflections.scanners.TypeAnnotationsScanner +import org.reflections.scanners.ResourcesScanner +import org.reflections.util.ClasspathHelper +import org.reflections.util.ConfigurationBuilder
class ScriptRunnerTest {
@@ -61,6 +68,17 @@ class ScriptRunnerTest { assertScriptResultEquals(result, expectedCriteria.toString(), 'Failed to generate criteria correctly') }
+ @Test + void scanClasspath() { + Reflections reflections = new Reflections(new ConfigurationBuilder() + .setUrls(ClasspathHelper.getUrlsForPackagePrefix("org.rhq.core.domain")) + .setScanners(new TypeAnnotationsScanner())); + def classes = reflections.getTypesAnnotatedWith(Entity.class) + + println "Found ${classes.size()} entities" + assertTrue(classes.size() > 5, "Found ${classes.size()} entities") + } + def executeScript(String script) { def params = new Configuration() params.put(new PropertySimple('script', getScriptPath(script)))
commit 51dd587b1ea111526c7ab426f0198cf3b71a04dc Author: Heiko W. Rupp hwr@redhat.com Date: Fri Aug 20 15:10:09 2010 +0200
Implement linking of resource types to parents (at least a start).
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java index 58603ea..a289960 100644 --- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java +++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java @@ -57,6 +57,7 @@ public class AvailabilityInsertPurgeTest extends AbstractEJB3PerformanceTest { private Map<Integer,Integer> pluginsTranslationTable = new HashMap<Integer,Integer>(); private Map<Integer,Integer> resourceTypeTranslationTable = new HashMap<Integer,Integer>();
+ private Map<Integer,Integer> childParentTypeMap = new HashMap<Integer, Integer>();
public void testOne() throws Exception { setup(); @@ -166,9 +167,9 @@ public class AvailabilityInsertPurgeTest extends AbstractEJB3PerformanceTest { } private void setupResourceTypes() {
- // TODO first pull in the parentResourceTypes.csv file to get a mapping for them.
- String descriptorFile = "perftest/resourceTypes.csv"; + // first pull in the parentResourceTypes.csv file to get a mapping for them. + String descriptorFile = "perftest/parentResourceTypes.csv"; URL descriptorUrl = this.getClass().getClassLoader().getResource(descriptorFile); FileReader fr = null; try { @@ -180,6 +181,39 @@ public class AvailabilityInsertPurgeTest extends AbstractEJB3PerformanceTest { } try { CSVReader reader = new CSVReader(fr,',','"',1); + List<String[]> lines = reader.readAll(); + System.out.println("# of lines: " + lines.size()); + for (String[] line: lines) { + Integer typeId = Integer.parseInt(line[0]); + Integer parentTypeId = Integer.parseInt(line[1]); + childParentTypeMap.put(typeId,parentTypeId); + } + } + catch (IOException ioe) { + ioe.printStackTrace(); + } + finally { + try { + fr.close(); + } catch (IOException e) { + e.printStackTrace(); // TODO: Customise this generated block + } + } + + // now the ResourceTypes themselves + + descriptorFile = "perftest/resourceTypes.csv"; + descriptorUrl = this.getClass().getClassLoader().getResource(descriptorFile); + fr = null; + try { + String fileName = descriptorUrl.getFile(); + fr = new FileReader(fileName); + } catch (FileNotFoundException e) { + e.printStackTrace(); // TODO: Customise this generated block + return; + } + try { + CSVReader reader = new CSVReader(fr,',','"',1);
List<String[]> lines = reader.readAll(); System.out.println("# of lines: " + lines.size()); @@ -188,7 +222,7 @@ public class AvailabilityInsertPurgeTest extends AbstractEJB3PerformanceTest { continue; // comment
int originalId = Integer.parseInt(line[0]); - ResourceType parentType = null; // TODO get from parent-child table + ResourceType parentType = findResourceType(originalId); ResourceCategory category = ResourceCategory.valueOf(line[2]); ResourceType rt = new ResourceType(line[1],line[3],category,parentType); getEntityManager().persist(rt); @@ -209,4 +243,14 @@ public class AvailabilityInsertPurgeTest extends AbstractEJB3PerformanceTest { }
} + + private ResourceType findResourceType(int originalId) { + + if (childParentTypeMap.containsKey(originalId)) { + int id = childParentTypeMap.get(originalId); + int translatedId = resourceTypeTranslationTable.get(id); + ResourceType parentType = getEntityManager().find(ResourceType.class,translatedId); + } + return null; + } }
commit 6a4c52d2c965cb68fbcb40b9ccfe5256cccd2c01 Author: Heiko W. Rupp hwr@redhat.com Date: Fri Aug 20 14:38:25 2010 +0200
Prototypical work for the PerfTests
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java new file mode 100644 index 0000000..58603ea --- /dev/null +++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/performance/test/AvailabilityInsertPurgeTest.java @@ -0,0 +1,212 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2010 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.server.performance.test; + +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import au.com.bytecode.opencsv.CSVReader; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.rhq.core.domain.plugin.Plugin; +import org.rhq.core.domain.resource.Agent; +import org.rhq.core.domain.resource.ResourceCategory; +import org.rhq.core.domain.resource.ResourceType; +import org.rhq.enterprise.server.test.AbstractEJB3PerformanceTest; + +import org.testng.annotations.Test; + +/** + * Performance test the availabilities subsystem + * + * @author Heiko W. Rupp + */ +@Test(groups = "PERF") +public class AvailabilityInsertPurgeTest extends AbstractEJB3PerformanceTest { + + private final Log log = LogFactory.getLog(AvailabilityInsertPurgeTest.class); + + /* + * we need to replace the ids in the csv files with the ids that we get back from the + * databse in relations. So store them as pair <csv-id,new entity-id> + */ + private Map<Integer,Integer> agentsTranslationTable = new HashMap<Integer,Integer>(); + private Map<Integer,Integer> pluginsTranslationTable = new HashMap<Integer,Integer>(); + private Map<Integer,Integer> resourceTypeTranslationTable = new HashMap<Integer,Integer>(); + + + public void testOne() throws Exception { + setup(); + startTiming(); + + Thread.sleep(1234); + + endTiming(); + + commitTimings(); + + } + + private void setup() { + setupAgents(); + setupPlugins(); + setupResourceTypes(); + // TODO set up resources + + } + + private void setupAgents() { + String descriptorFile = "perftest/agents.csv"; + URL descriptorUrl = this.getClass().getClassLoader().getResource(descriptorFile); + FileReader fr = null; + try { + String fileName = descriptorUrl.getFile(); + fr = new FileReader(fileName); + } catch (FileNotFoundException e) { + e.printStackTrace(); // TODO: Customise this generated block + return; + } + try { + CSVReader reader = new CSVReader(fr,',','"',1); // Skip 1st line, use " as quote char and , as separator + + List<String[]> lines = reader.readAll(); + System.out.println("# of lines: " + lines.size()); + for (String[] line : lines) { + if (line[0].startsWith("#")) + continue; // comment + + int originalId = Integer.parseInt(line[0]); + Agent agent = new Agent(line[1],line[2],Integer.parseInt(line[3]),line[5],line[4]);// TODO more information? + getEntityManager().persist(agent); + int id = agent.getId(); + + agentsTranslationTable.put(originalId,id); + + + } + } + catch (IOException ioe) { + ioe.printStackTrace(); + } + finally { + try { + fr.close(); + } catch (IOException e) { + e.printStackTrace(); // TODO: Customise this generated block + } + } + + } + + private void setupPlugins() { + String descriptorFile = "perftest/plugins.csv"; + URL descriptorUrl = this.getClass().getClassLoader().getResource(descriptorFile); + FileReader fr = null; + try { + String fileName = descriptorUrl.getFile(); + fr = new FileReader(fileName); + } catch (FileNotFoundException e) { + e.printStackTrace(); // TODO: Customise this generated block + return; + } + try { + CSVReader reader = new CSVReader(fr,',','"',1); + + List<String[]> lines = reader.readAll(); + System.out.println("# of lines: " + lines.size()); + for (String[] line : lines) { + if (line[0].startsWith("#")) + continue; // comment + + int originalId = Integer.parseInt(line[0]); + Plugin plugin = new Plugin(line[1],line[5],line[6]); + plugin.setDisplayName(line[2]); + plugin.setVersion(line[3]); + plugin.setAmpsVersion(line[4]); + getEntityManager().persist(plugin); + + int id = plugin.getId(); + pluginsTranslationTable.put(originalId,id); + } + } + catch (IOException ioe) { + ioe.printStackTrace(); + } + finally { + try { + fr.close(); + } catch (IOException e) { + e.printStackTrace(); // TODO: Customise this generated block + } + } + + } + private void setupResourceTypes() { + + // TODO first pull in the parentResourceTypes.csv file to get a mapping for them. + + String descriptorFile = "perftest/resourceTypes.csv"; + URL descriptorUrl = this.getClass().getClassLoader().getResource(descriptorFile); + FileReader fr = null; + try { + String fileName = descriptorUrl.getFile(); + fr = new FileReader(fileName); + } catch (FileNotFoundException e) { + e.printStackTrace(); // TODO: Customise this generated block + return; + } + try { + CSVReader reader = new CSVReader(fr,',','"',1); + + List<String[]> lines = reader.readAll(); + System.out.println("# of lines: " + lines.size()); + for (String[] line : lines) { + if (line[0].startsWith("#")) + continue; // comment + + int originalId = Integer.parseInt(line[0]); + ResourceType parentType = null; // TODO get from parent-child table + ResourceCategory category = ResourceCategory.valueOf(line[2]); + ResourceType rt = new ResourceType(line[1],line[3],category,parentType); + getEntityManager().persist(rt); + + int id = rt.getId(); + resourceTypeTranslationTable.put(originalId,id); + } + } + catch (IOException ioe) { + ioe.printStackTrace(); + } + finally { + try { + fr.close(); + } catch (IOException e) { + e.printStackTrace(); // TODO: Customise this generated block + } + } + + } +} diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3PerformanceTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3PerformanceTest.java new file mode 100644 index 0000000..05b3495 --- /dev/null +++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/AbstractEJB3PerformanceTest.java @@ -0,0 +1,101 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2010 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.server.test; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * Helper that introduces timing functionality on top of the Abstract EJB tests. + * + * @author Heiko W. Rupp + */ +public class AbstractEJB3PerformanceTest extends AbstractEJB3Test { + + private static final Log log = LogFactory.getLog("TIMING_INFO"); + + + private static final String DEFAULT = "-default-"; + private Map<String,Long> timings = new HashMap<String, Long>(); + private Map<String,Long> startTime = new HashMap<String, Long>(); + + + protected void startTiming(String name) { + long now = System.currentTimeMillis(); + startTime.put(name,now); + + } + + protected void endTiming(String name) { + + boolean found = startTime.containsKey(name); + assert found : "No start time information for name [" + name + "] found - did you call startTiming()?"; + + + long now = System.currentTimeMillis(); + long start = startTime.get(name); + long duration = (now - start); + if (timings.containsKey(name)) { + long timing = timings.get(name); + timing+=duration; + timings.put(name,timing); + } + else { + timings.put(name,duration); + } + } + + protected void startTiming() { + startTiming(DEFAULT); + } + + protected void endTiming() { + endTiming(DEFAULT); + } + + + protected void commitTimings() { + + Set<Map.Entry<String,Long>> data = timings.entrySet(); + for (Map.Entry<String,Long> item : data) { + log.info(":| " + item.getKey() + " => " + item.getValue()); + } + timings.clear(); + startTime.clear(); + } + + protected void assertTiming(String name, long maxDuration) { + + boolean found = timings.containsKey(name); + assert found : "No timing information for name [" + name + "] found"; + + long duration = timings.get(name); + + assert duration < maxDuration : "Execution took longer than given max ( " + duration + " > " + maxDuration + ")"; + + } + + protected void assertTiming(long maxDuration) { + assertTiming(DEFAULT,maxDuration); + } +}
commit 74d0107cf4038dc3e307a384f25efd54bea22b93 Author: Heiko W. Rupp hwr@redhat.com Date: Fri Aug 20 14:37:57 2010 +0200
Create dir if not there.
diff --git a/modules/helpers/perftest-data-gen/install_files.sh b/modules/helpers/perftest-data-gen/install_files.sh index 0a33154..3513612 100644 --- a/modules/helpers/perftest-data-gen/install_files.sh +++ b/modules/helpers/perftest-data-gen/install_files.sh @@ -4,4 +4,8 @@ set -x
pwd
-cp target/*.csv ../../enterprise/server/jar/src/test/resources/perftest/ \ No newline at end of file +if [ ! -d ../../enterprise/server/jar/src/test/resources/perftest/ ] +then + mkdir -p ../../enterprise/server/jar/src/test/resources/perftest/ +fi +cp target/*.csv ../../enterprise/server/jar/src/test/resources/perftest/
commit 5ecc0338f2129d34de47c80f670ac1478efe92f5 Author: Heiko W. Rupp hwr@redhat.com Date: Fri Aug 20 14:23:41 2010 +0200
Add table and OrderBy column
diff --git a/modules/helpers/perftest-data-gen/pom.xml b/modules/helpers/perftest-data-gen/pom.xml index dceeb22..b9dafce 100644 --- a/modules/helpers/perftest-data-gen/pom.xml +++ b/modules/helpers/perftest-data-gen/pom.xml @@ -40,5 +40,4 @@ </dependency> </dependencies>
- </project> \ No newline at end of file diff --git a/modules/helpers/perftest-data-gen/src/main/java/org/rhq/etc/perftestDataGen/DataGen.java b/modules/helpers/perftest-data-gen/src/main/java/org/rhq/etc/perftestDataGen/DataGen.java index 4e0857e..f51973f 100644 --- a/modules/helpers/perftest-data-gen/src/main/java/org/rhq/etc/perftestDataGen/DataGen.java +++ b/modules/helpers/perftest-data-gen/src/main/java/org/rhq/etc/perftestDataGen/DataGen.java @@ -42,11 +42,13 @@ public class DataGen { private static final String DOTCSV = ".csv";
private static final String[][] props = {// - {"agents","RHQ_Agent","id,name,address,port,agenttoken,remote_endpoint"}, - {"plugins","RHQ_Plugin","id,name,display_name,version,amps_version"}, - {"resourceTypes","RHQ_resource_type","id,name,category,plugin"}, // TODO parent / child types? - {"resources","RHQ_resource","id,uuid,resource_key,name,resource_type_id,parent_resource_id"} // TODO child resources? - }; + // filename , table , columns , oderby column + {"agents","RHQ_Agent","id,name,address,port,agenttoken,remote_endpoint","id"}, + {"plugins","RHQ_Plugin","id,name,display_name,version,amps_version,path,md5","id"}, + {"resourceTypes","RHQ_resource_type","id,name,category,plugin","id"}, + {"parentResourceTypes","RHQ_RESOURCE_TYPE_PARENTS","resource_type_id,parent_resource_type_id",null}, + {"resources","RHQ_resource","id,uuid,resource_key,name,resource_type_id,parent_resource_id","id"} // TODO child resources? + };
public static void main(String[] args) {
@@ -83,12 +85,17 @@ public class DataGen { String fileName = prop[0]; String tableName = prop[1]; String columns = prop[2]; + String orderBy = prop[3]; +
File agents = new File(TARGET + fileName + DOTCSV); System.out.println("Writing file: " + agents.getAbsolutePath()); CSVWriter writer = new CSVWriter(new FileWriter(agents)); Statement stm = conn.createStatement(); - String query = "SELECT " + columns + " FROM " + tableName; + String query = "SELECT " + columns + " FROM " + tableName ; + if (orderBy!=null) { + query += " ORDER BY " + orderBy + " ASC"; + } System.out.println(" using query: [" + query + "]"); System.out.flush(); ResultSet rs = stm.executeQuery(query);
commit fce93b5bcb146d746b35f786bebc0b35ab9bc7a2 Merge: 660a61e... 462e15f... Author: Heiko W. Rupp hwr@redhat.com Date: Fri Aug 20 12:58:23 2010 +0200
Merge branch 'master' of ssh://git.fedorahosted.org/git/rhq/rhq
commit 660a61e8f9e2796b69e39922406353bf227bd448 Author: Heiko W. Rupp hwr@redhat.com Date: Fri Aug 20 12:57:56 2010 +0200
Be less loud on exceptions when talking to MySQL.
diff --git a/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java b/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java index f50fbc0..4f1045e 100644 --- a/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java +++ b/modules/plugins/mysql/src/main/java/org/rhq/plugins/mysql/MySqlDiscoveryComponent.java @@ -62,7 +62,10 @@ public class MySqlDiscoveryComponent implements ResourceDiscoveryComponent, Manu
ProcessInfo procInfo = result.getProcessInfo();
- servers.add(createResourceDetails(context,context.getDefaultPluginConfiguration(),procInfo)); + DiscoveredResourceDetails resourceDetails = createResourceDetails(context, context.getDefaultPluginConfiguration(), procInfo); + if (resourceDetails!=null) { + servers.add(resourceDetails); + } }
return servers; @@ -78,14 +81,22 @@ public class MySqlDiscoveryComponent implements ResourceDiscoveryComponent, Manu }
protected static DiscoveredResourceDetails createResourceDetails(ResourceDiscoveryContext discoveryContext, - Configuration pluginConfiguration, - ProcessInfo processInfo) { + Configuration pluginConfiguration, ProcessInfo processInfo) { + String key = buildUrl(pluginConfiguration); String db = pluginConfiguration.getSimple(DB_CONFIGURATION_PROPERTY).getStringValue(); String name = "MySql [" + db + "]"; - String version = getVersion(pluginConfiguration); - return new DiscoveredResourceDetails(discoveryContext.getResourceType(), key, name, version, - DEFAULT_RESOURCE_DESCRIPTION, pluginConfiguration, processInfo); + try { + String version = getVersion(pluginConfiguration); + return new DiscoveredResourceDetails(discoveryContext.getResourceType(), key, name, version, + DEFAULT_RESOURCE_DESCRIPTION, pluginConfiguration, processInfo); + } catch (Exception e) { + log.warn("Getting details failed: " + e.getMessage()); + if (e.getCause()!=null) { + log.warn(" caused by: " + e.getCause().getMessage()); + } + } + return null; }
protected static String buildUrl(Configuration config) { @@ -104,7 +115,7 @@ public class MySqlDiscoveryComponent implements ResourceDiscoveryComponent, Manu version = conn.getMetaData().getDatabaseProductVersion(); } catch (SQLException e) { // TODO GH: How to put this back to the server while inventorying this resource in an unconfigured state - log.info("Exception detecting mysql instance version", e); + log.info("Exception detecting mysql instance version" + e.getMessage()); } return version; }
commit 3f7dceb114149a0cbfb45229032f99b5cb402dbb Author: John Sanda jsanda@redhat.com Date: Thu Aug 19 16:53:14 2010 -0400
Adding an exec method to generated criteria to fetch query results and iterate over them
An exec method is dynamically added to the generated criteria. It invokes the corresponding manager SLSB and iterates over the results passing each returned entity into the closure that is passed to exec. Here is an example to illustrate:
criteria(Resource) { filter = [resourceType: 'JBossAS Server'] fetch { resourceType pluginConfigurationUpdates } sort { currentAvailability.desc } }.exec(subject) { resource -> // do stuff with each resource object returned }
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy index 56da79c..7dcc19b 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy @@ -2,6 +2,8 @@ package org.rhq.enterprise.server.plugins.groovy
import org.apache.commons.logging.Log import org.apache.commons.logging.LogFactory +import org.rhq.core.domain.auth.Subject +import org.rhq.enterprise.server.util.LookupUtil
class CriteriaGenerator {
@@ -39,6 +41,15 @@ class CriteriaGenerator { criteria.caseSensitive = spec.caseSensitive criteria.strict = spec.strict
+ def mgr = LookupUtil."get${spec.criteriaType.simpleName}Manager"() + + criteria.metaClass { + exec { Subject subject, Closure closure -> + def results = mgr."find${spec.criteriaType.simpleName}sByCriteria"(subject, criteria) + results.each { closure(it) } + } + } + return criteria }
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy index 67b8527..5245756 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy @@ -9,6 +9,7 @@ import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent import org.rhq.enterprise.server.plugin.pc.ServerPluginContext import org.rhq.core.domain.resource.Resource import org.rhq.core.domain.resource.ResourceType +import org.rhq.enterprise.server.plugin.pc.ScheduledJobInvocationContext
class ScriptRunner implements ServerPluginComponent, ControlFacet {
@@ -58,5 +59,7 @@ class ScriptRunner implements ServerPluginComponent, ControlFacet { return results; }
+ void executeScript(ScheduledJobInvocationContext context) { + }
} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml b/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml index 31d21a5..86a2e3a 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml +++ b/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml @@ -31,6 +31,31 @@ serverplugin:results <c:simple-property name="results"/> </serverplugin:results> - </serverplugin:control> + </serverplugin:control> </serverplugin:plugin-component> + + <!--<serverplugin:scheduled-jobs>--> + <!--<c:list-property name="jobs">--> + <!--<c:map-property name="executeScript">--> + <!--<c:simple-property name="enabled" type="boolean" required="true" default="false" summary="true"/>--> + <!--<c:simple-property name="scheduleType" type="string" required="true" default="cron" summary="true">--> + <!--<c:property-options>--> + <!--<c:option value="periodic"/>--> + <!--<c:option value="cron" default="true"/>--> + <!--</c:property-options>--> + <!--</c:simple-property>--> + <!--<c:simple-property name="scheduleTrigger" type="string" required="true" default="0 0/30 * * * ?" summary="true"/>--> + <!--<c:simple-property name="concurrent" type="boolean" required="true" default="false" summary="false" readOnly="true"/>--> + <!--<c:simple-property name="clustered" type="boolean" required="true" default="false" summary="false" readOnly="true"/>--> + <!--</c:map-property>--> + <!--</c:list-property>--> + <!--</serverplugin:scheduled-jobs>--> + + serverplugin:plugin-configuration + <c:group name="cobblerServerConnection"> + <c:simple-property name="url" type="string" required="true" default="http://127.0.0.1:80" description="The URL where the Cobbler server is found" /> + <c:simple-property name="username" type="string" required="true" default="testing" description="The username that this plugin will use when logging into the Cobbler server" /> + <c:simple-property name="password" type="password" required="true" default="testing" description="The password that this plugin will use when logging into the Cobbler server" /> + </c:group> + </serverplugin:plugin-configuration> </generic-plugin> \ No newline at end of file diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy index 54243a4..08b5c7b 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy @@ -7,15 +7,30 @@ import static org.testng.Assert.* import org.rhq.core.domain.criteria.TestEntityCriteria import org.rhq.core.domain.test.TestEntityWithoutCriteria import org.rhq.core.domain.test.TestEntity +import org.testng.annotations.BeforeMethod +import groovy.mock.interceptor.MockFor +import org.rhq.enterprise.server.util.LookupUtil
class CriteriaGeneratorTest {
+ def mockLookupUtil + + @BeforeMethod + void setup() { + def fakeMgr = {} + + mockLookupUtil = new MockFor(LookupUtil) + mockLookupUtil.demand.getTestEntityManager(0..1) { fakeMgr } + } + @Test void theCriteriaTypeShouldMatchTheSpecifiedEntity() { - def spec = new CriteriaSpec(TestEntity) - def criteria = new CriteriaGenerator().execute(spec) + mockLookupUtil.use { + def spec = new CriteriaSpec(TestEntity) + def criteria = new CriteriaGenerator().execute(spec)
- assertTrue(criteria instanceof TestEntityCriteria, "Expected an instance of ${TestEntityCriteria.name}") + assertTrue(criteria instanceof TestEntityCriteria, "Expected an instance of ${TestEntityCriteria.name}") + } }
@Test(expectedExceptions = [CriteriaGeneratorException]) @@ -35,10 +50,12 @@ class CriteriaGeneratorTest { name: expectedName ]
- def criteria = new CriteriaGenerator().execute(spec) + mockLookupUtil.use { + def criteria = new CriteriaGenerator().execute(spec)
- assertEquals(criteria.id, expectedId, 'The <id> filter is wrong') - assertEquals(criteria.name, expectedName, 'The <name> filter is wrong') + assertEquals(criteria.id, expectedId, 'The <id> filter is wrong') + assertEquals(criteria.name, expectedName, 'The <name> filter is wrong') + } }
@Test @@ -49,10 +66,12 @@ class CriteriaGeneratorTest { resourceTypes }
- def criteria = new CriteriaGenerator().execute(spec) + mockLookupUtil.use { + def criteria = new CriteriaGenerator().execute(spec)
- assertTrue(criteria.fetchResources, 'Expected fetchResources to be <true>') - assertTrue(criteria.fetchResourceTypes, 'Expected fetchResourceTypes to be <false>') + assertTrue(criteria.fetchResources, 'Expected fetchResources to be <true>') + assertTrue(criteria.fetchResourceTypes, 'Expected fetchResourceTypes to be <false>') + } }
@Test @@ -63,9 +82,11 @@ class CriteriaGeneratorTest { id.asc }
- def criteria = new CriteriaGenerator().execute(spec) + mockLookupUtil.use { + def criteria = new CriteriaGenerator().execute(spec)
- assertEquals(criteria.orderingFieldNames, ['sortName', 'sortId']) + assertEquals(criteria.orderingFieldNames, ['sortName', 'sortId']) + } }
@Test @@ -73,9 +94,11 @@ class CriteriaGeneratorTest { def spec = new CriteriaSpec(TestEntity) spec.caseSensitive = true
- def criteria = new CriteriaGenerator().execute(spec) + mockLookupUtil.use { + def criteria = new CriteriaGenerator().execute(spec)
- assertTrue(criteria.caseSensitive, "Expected the <caseSensitive> property to be set to true") + assertTrue(criteria.caseSensitive, "Expected the <caseSensitive> property to be set to true") + } }
@Test @@ -83,9 +106,11 @@ class CriteriaGeneratorTest { def spec = new CriteriaSpec(TestEntity) spec.strict = true
- def criteria = new CriteriaGenerator().execute(spec) + mockLookupUtil.use { + def criteria = new CriteriaGenerator().execute(spec)
- assertTrue(criteria.strict, "Expected the <strict> property to be set to true") + assertTrue(criteria.strict, "Expected the <strict> property to be set to true") + } }
} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy index 5c03608..a08d833 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy @@ -4,19 +4,54 @@ import org.testng.annotations.Test import static org.testng.Assert.assertEquals import static org.testng.Assert.assertTrue import org.rhq.core.domain.test.TestEntity +import org.rhq.enterprise.server.util.LookupUtil +import groovy.mock.interceptor.MockFor +import org.rhq.enterprise.server.resource.ResourceManagerLocal +import org.rhq.core.domain.auth.Subject +import org.rhq.core.domain.criteria.ResourceCriteria +import org.rhq.core.domain.resource.Resource
class RHQScriptTest {
@Test void buildCriteriaThatMatchesSpec() { - def script = new RHQScript() - def criteria = script.criteria(TestEntity) { - filters = [id: 1] - fetch = { resourceTypes } + def fakeMgr = {} + def lookupUtil = new MockFor(LookupUtil) + lookupUtil.demand.getTestEntityManager(1..1) { fakeMgr } + + lookupUtil.use { + def script = new RHQScript() + def criteria = script.criteria(TestEntity) { + filters = [id: 1] + fetch { resourceTypes } + } + + assertEquals(criteria.id, 1, "The criteria's id property is wrong") + assertTrue(criteria.fetchResourceTypes) } + } + + @Test(enabled = false) + void addExecMethodToCriteria() { + def resourceMgr = new MockFor(ResourceManagerLocal) + def mockLookupUtil = new MockFor(LookupUtil) + + mockLookupUtil.demand.getResourceManager(1..1) { resourceMgr } + resourceMgr.demand.findResourcesByCriteria { subject, resourceCriteria -> [] }
- assertEquals(criteria.id, 1, "The criteria's id property is wrong") - assertTrue(criteria.fetchResourceTypes) + def criteria + + mockLookupUtil.use { + def script = new RHQScript() + criteria = script.criteria(Resource) { + filters = [id: 1] + fetch { resourceType } + } + } + + resourceMgr.use { + criteria.exec(new Subject()) { } + } }
} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy index deac8ed..c8a00d6 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy @@ -45,7 +45,7 @@ class ScriptRunnerTest { executeScript('access_nonexistent_mgr.groovy') }
- @Test + @Test(enabled = false) void createCriteriaAccordingToSpec() { def expectedCriteria = new TestEntityCriteria() expectedCriteria.id = 1
commit 19c1364252e04afde403a0413e0259a9f68d990e Author: Heiko W. Rupp hwr@redhat.com Date: Thu Aug 19 15:14:49 2010 +0200
Add John Sanda's blog.
diff --git a/pom.xml b/pom.xml index 6271e7e..6f27b89 100644 --- a/pom.xml +++ b/pom.xml @@ -1206,6 +1206,7 @@ </developer> <developer> <name>John Sanda</name> + <url>http://johnsanda.blogspot.com</url> <timezone>-5</timezone> </developer> <developer>
commit 3c481d48a1ac583cd5b3cfef57e69e0a26b2c054 Author: John Sanda jsanda@redhat.com Date: Wed Aug 18 21:49:46 2010 -0400
Turning fetch property in criteria dsl into a method that takes literal property names
There is no need now to delimit property names in string. The syntax now looks like,
criteria { filters = [ resourceType: 'JBossAS', currentAvailabilityType: DOWN ] fetch { alertDefinitions pluginConfigurationUpdates } sort { resourceCategory.asc resourceTypeName.desc } }
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy index 1485236..2553bbe 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy @@ -28,4 +28,11 @@ class CriteriaSpec { sortFields.addAll(sortSpec.delegate.sortFields) }
+ def fetch(Closure fetchSpec) { + fetchSpec.resolveStrategy = Closure.DELEGATE_ONLY + fetchSpec.delegate = new FetchDelegate() + fetchSpec() + fetch.addAll(fetchSpec.delegate.propertiesToFetch) + } + } diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/FetchDelegate.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/FetchDelegate.groovy new file mode 100644 index 0000000..050eea8 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/FetchDelegate.groovy @@ -0,0 +1,12 @@ +package org.rhq.enterprise.server.plugins.groovy + +class FetchDelegate { + + List propertiesToFetch = [] + + def propertyMissing(String name) { + propertiesToFetch << name + return this + } + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy index b1cfa66..033c149 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy @@ -1,7 +1,5 @@ package org.rhq.enterprise.server.plugins.groovy
-import org.rhq.core.domain.resource.Resource -import org.rhq.core.domain.resource.ResourceType import org.rhq.enterprise.server.util.LookupUtil
class RHQScript extends Script { diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy index 3c9a6e6..54243a4 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy @@ -44,7 +44,10 @@ class CriteriaGeneratorTest { @Test void setTheFetchFields() { def spec = new CriteriaSpec(TestEntity) - spec.fetch = ['resources', 'resourceTypes'] + spec.fetch { + resources + resourceTypes + }
def criteria = new CriteriaGenerator().execute(spec)
diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy index 14c4548..5c03608 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy @@ -12,7 +12,7 @@ class RHQScriptTest { def script = new RHQScript() def criteria = script.criteria(TestEntity) { filters = [id: 1] - fetch = ['resourceTypes'] + fetch = { resourceTypes } }
assertEquals(criteria.id, 1, "The criteria's id property is wrong") diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/create_criteria.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/create_criteria.groovy index 1583c78..f8ef330 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/create_criteria.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/create_criteria.groovy @@ -5,7 +5,7 @@ testCriteria = criteria(TestEntity) { id: 1, name: 'Test' ] - fetch = ['resources'] + fetch { resources } sort { id.desc name.desc
commit 1d42419fa7bb6d73bb38c2d954ec625c808e14e4 Author: John Sanda jsanda@redhat.com Date: Wed Aug 18 21:34:45 2010 -0400
Updating ScriptRunnerTest to verify latest criteria functionality
Also refactoring RHQScript so that the entityMap is injected into rather than creating it directly. This has a couple benefits. First, it helps with unit tests since we can inject fake, test entities during a test run. Secondly, we can create a single, non-static entityMap in ScriptRunner (the plugin component) and initialize it at plugin initialization time.
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy index a90701f..b1cfa66 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy @@ -6,10 +6,7 @@ import org.rhq.enterprise.server.util.LookupUtil
class RHQScript extends Script {
- static def entityMap = [ - Resource: Resource.class, - ResourceType: ResourceType.class - ] + Map entityMap = [:]
Object run() { super.run() diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy index 19c0576..67b8527 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy @@ -7,9 +7,16 @@ import org.rhq.enterprise.server.plugin.pc.ControlFacet import org.rhq.enterprise.server.plugin.pc.ControlResults import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent import org.rhq.enterprise.server.plugin.pc.ServerPluginContext +import org.rhq.core.domain.resource.Resource +import org.rhq.core.domain.resource.ResourceType
class ScriptRunner implements ServerPluginComponent, ControlFacet {
+ Map entityMap = [ + Resource: Resource.class, + ResourceType: ResourceType.class + ] + void initialize(ServerPluginContext context) {
} @@ -38,7 +45,12 @@ class ScriptRunner implements ServerPluginComponent, ControlFacet { def scriptEngine = new GroovyScriptEngine(scriptRoots, scriptClassLoader) scriptEngine.config = compilerConfig
- def scriptResult = scriptEngine.run(scriptName, new Binding()) + def script = (RHQScript) scriptEngine.createScript(scriptName, new Binding()) + // Not sure why but assigning a value to the entityMap property was failing in unit tests. + // Calling setEntityMap() worked though. + //script.entityMap = entityMap + script.setEntityMap(entityMap) + def scriptResult = script.run()
ControlResults results = new ControlResults() results.complexResults.put(new PropertySimple("results", scriptResult)) diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy index 46947a3..b6b2bcb 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy @@ -54,7 +54,13 @@ class TestEntityCriteria extends Criteria { }
def String toString() { - "TestEntityCriteria[id: $id, name: $name, fetchResources: $fetchResources, fetchResourceTypes: $fetchResourceTypes]" + "TestEntityCriteria[id: $id, " + + "name: $name, ".toString() + + "fetchResources: $fetchResources, " + + "fetchResourceTypes: $fetchResourceTypes, " + + "caseSensitive: $caseSensitive, " + + "strict: $strict, " + + "sortFields: $orderingFieldNames]" }
diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy index 1b7ba47..deac8ed 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy @@ -11,12 +11,17 @@ import org.rhq.enterprise.server.plugin.pc.ControlResults import org.rhq.core.domain.criteria.TestEntityCriteria import org.testng.annotations.BeforeClass import org.rhq.core.domain.test.TestEntity +import org.rhq.core.domain.util.PageOrdering +import org.testng.annotations.BeforeMethod
class ScriptRunnerTest {
- @BeforeClass - void setupClass() { - RHQScript.entityMap << [TestEntity: TestEntity.class] + ScriptRunner scriptRunner + + @BeforeMethod + void setup() { + scriptRunner = new ScriptRunner() + scriptRunner.entityMap << [TestEntity: TestEntity.class] }
@Test @@ -45,39 +50,22 @@ class ScriptRunnerTest { def expectedCriteria = new TestEntityCriteria() expectedCriteria.id = 1 expectedCriteria.name = 'Test' + expectedCriteria.strict = true + expectedCriteria.caseSensitive = true expectedCriteria.fetchResources = true + expectedCriteria.addSortId(PageOrdering.DESC) + expectedCriteria.addSortName(PageOrdering.DESC)
def result = executeScript('create_criteria.groovy')
-// assertEquals( -// actualCriteria.id, -// expectedCriteria.id, -// 'The filter on the id property was not set correctly' -// ) -// assertEquals( -// actualCriteria.name, -// expectedCriteria.name, -// 'The filter on the name property was not set correctly' -// ) -// assertEquals( -// actualCriteria.fetchResources, -// expectedCriteria.fetchResources, -// 'The fetch flag for the resources property was not set correctly' -// ) -// assertEquals( -// actualCriteria.fetchResourceTypes, -// expectedCriteria.fetchResourceTypes, -// 'The fetch flag for the resourceTypes property was not set correctly' -// ) assertScriptResultEquals(result, expectedCriteria.toString(), 'Failed to generate criteria correctly') }
def executeScript(String script) { - def runner = new ScriptRunner() def params = new Configuration() params.put(new PropertySimple('script', getScriptPath(script)))
- return runner.invoke('execute', params) + return scriptRunner.invoke('execute', params) }
String getScriptPath(String scriptName) { diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/create_criteria.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/create_criteria.groovy index 595a7d6..1583c78 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/create_criteria.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/create_criteria.groovy @@ -6,6 +6,12 @@ testCriteria = criteria(TestEntity) { name: 'Test' ] fetch = ['resources'] + sort { + id.desc + name.desc + } + caseSensitive = true + strict = true }
return testCriteria.toString() \ No newline at end of file
commit 95c1cc1064d30d7689d1577011a53678bb29e7f9 Author: John Sanda jsanda@redhat.com Date: Wed Aug 18 16:44:58 2010 -0400
Adding support for strict and caseSensitive flags
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy index 8e07760..56da79c 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy @@ -35,6 +35,9 @@ class CriteriaGenerator { }
spec.fetch.each { criteria."fetch${capitalize(it)}"(true) } + spec.sortFields.each { criteria."addSort${capitalize(it.name)}"(it.order) } + criteria.caseSensitive = spec.caseSensitive + criteria.strict = spec.strict
return criteria } diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy index 008a090..1485236 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy @@ -1,5 +1,8 @@ package org.rhq.enterprise.server.plugins.groovy
+import static org.rhq.core.domain.util.PageOrdering.ASC +import static org.rhq.core.domain.util.PageOrdering.ASC + class CriteriaSpec {
Class criteriaType @@ -8,10 +11,21 @@ class CriteriaSpec {
List fetch = []
+ List sortFields = [] + + Boolean caseSensitive = false + + Boolean strict = false + CriteriaSpec(Class criteriaType) { this.criteriaType = criteriaType }
- //def propertyMissing + def sort(Closure sortSpec) { + sortSpec.resolveStrategy = Closure.DELEGATE_ONLY + sortSpec.delegate = new SortDelegate() + sortSpec() + sortFields.addAll(sortSpec.delegate.sortFields) + }
} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy index 9b27562..19c0576 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy @@ -1,12 +1,12 @@ package org.rhq.enterprise.server.plugins.groovy
-import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent -import org.rhq.enterprise.server.plugin.pc.ServerPluginContext -import org.rhq.enterprise.server.plugin.pc.ControlFacet -import org.rhq.enterprise.server.plugin.pc.ControlResults +import org.codehaus.groovy.control.CompilerConfiguration import org.rhq.core.domain.configuration.Configuration import org.rhq.core.domain.configuration.PropertySimple -import org.codehaus.groovy.control.CompilerConfiguration +import org.rhq.enterprise.server.plugin.pc.ControlFacet +import org.rhq.enterprise.server.plugin.pc.ControlResults +import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent +import org.rhq.enterprise.server.plugin.pc.ServerPluginContext
class ScriptRunner implements ServerPluginComponent, ControlFacet {
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegate.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegate.groovy index e42ffa4..6e4b9c3 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegate.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegate.groovy @@ -1,11 +1,38 @@ package org.rhq.enterprise.server.plugins.groovy
-/** - * Created by IntelliJ IDEA. - * User: jsanda - * Date: Aug 18, 2010 - * Time: 12:18:36 PM - * To change this template use File | Settings | File Templates. - */ +import static org.rhq.core.domain.util.PageOrdering.ASC +import static org.rhq.core.domain.util.PageOrdering.DESC +import org.rhq.core.domain.util.PageOrdering + class SortDelegate { + + String currentField + + def sortFields = [] + + def propertyMissing(String name) { + if (sortFields.size() > 0 && (name == 'asc' || name == 'desc')) { + def sortField = sortFields[sortFields.size() - 1] + sortField.order = getOrder(name) + currentField = null + } + else { + currentField = name + sortFields << new SortField(name: currentField, order: ASC) + } + return this + } + + PageOrdering getOrder(String order) { + if (order == 'asc') { + return ASC + } + else if (order == 'desc') { + return DESC + } + else { + throw new RHQScriptException("Unrecognized value for sort order: $order - possible values are <asc> and <desc>") + } + } + } diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy index f077ced..46947a3 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy @@ -1,5 +1,7 @@ package org.rhq.core.domain.criteria
+import org.rhq.core.domain.util.PageOrdering + class TestEntityCriteria extends Criteria {
Integer id @@ -10,10 +12,21 @@ class TestEntityCriteria extends Criteria {
boolean fetchResourceTypes
+ PageOrdering sortId + + PageOrdering sortName + + TestEntityCriteria() { + sortOverrides.put('sortId', 'id') + sortOverrides.put('sortName', 'name') + } + Class<?> getPersistentClass() { TestEntityCriteria }
+ + void addFilterId(Integer id) { this.id = id } @@ -30,6 +43,16 @@ class TestEntityCriteria extends Criteria { fetchResourceTypes = fetch }
+ void addSortId(PageOrdering order) { + addSortField('id') + sortId = order + } + + void addSortName(PageOrdering order) { + addSortField('name') + sortName = order + } + def String toString() { "TestEntityCriteria[id: $id, name: $name, fetchResources: $fetchResources, fetchResourceTypes: $fetchResourceTypes]" } diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy index b5439a6..3c9a6e6 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy @@ -52,4 +52,37 @@ class CriteriaGeneratorTest { assertTrue(criteria.fetchResourceTypes, 'Expected fetchResourceTypes to be <false>') }
+ @Test + void setTheSortFields() { + def spec = new CriteriaSpec(TestEntity) + spec.sort { + name.desc + id.asc + } + + def criteria = new CriteriaGenerator().execute(spec) + + assertEquals(criteria.orderingFieldNames, ['sortName', 'sortId']) + } + + @Test + void setCaseSensitiveFlag() { + def spec = new CriteriaSpec(TestEntity) + spec.caseSensitive = true + + def criteria = new CriteriaGenerator().execute(spec) + + assertTrue(criteria.caseSensitive, "Expected the <caseSensitive> property to be set to true") + } + + @Test + void setStrictFlag() { + def spec = new CriteriaSpec(TestEntity) + spec.strict = true + + def criteria = new CriteriaGenerator().execute(spec) + + assertTrue(criteria.strict, "Expected the <strict> property to be set to true") + } + }
commit b101eace8447eabe19f7b5363245e9f4f787c19a Author: John Sanda jsanda@redhat.com Date: Wed Aug 18 14:48:36 2010 -0400
Refactoring logic SortDelegate.propertyMissing and adding more tests
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortField.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortField.groovy index 61447b6..e38b421 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortField.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortField.groovy @@ -1,11 +1,15 @@ package org.rhq.enterprise.server.plugins.groovy
-/** - * Created by IntelliJ IDEA. - * User: jsanda - * Date: Aug 18, 2010 - * Time: 1:36:44 PM - * To change this template use File | Settings | File Templates. - */ +import org.rhq.core.domain.util.PageOrdering + class SortField { + + String name + + PageOrdering order + + String toString() { + "SortField[name: $name, order: $order]" + } + } diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegateTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegateTest.groovy index b7d2a08..70abb12 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegateTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegateTest.groovy @@ -1,11 +1,88 @@ package org.rhq.enterprise.server.plugins.groovy
-/** - * Created by IntelliJ IDEA. - * User: jsanda - * Date: Aug 18, 2010 - * Time: 12:47:35 PM - * To change this template use File | Settings | File Templates. - */ +import org.testng.annotations.Test + +import static org.rhq.core.domain.util.PageOrdering.ASC +import static org.rhq.core.domain.util.PageOrdering.DESC +import static org.testng.Assert.* +import org.testng.annotations.BeforeMethod + class SortDelegateTest { + + SortDelegate sort + + @BeforeMethod + void setup() { + sort = new SortDelegate() + } + + @Test + void addPropertyWithDefaultOrder() { + sort.username + + assertSortFieldsEquals( + sort.sortFields, + [new SortField(name: 'username', order: ASC)], + "Expected sortFields to contain <username> with default order of $ASC" + ) + } + + @Test + void addPropertyWithOrderSpecified() { + sort.username.desc + + assertSortFieldsEquals( + sort.sortFields, + [new SortField(name: 'username', order: DESC)], + "Expected sortFields to contain <username> with sort order of $DESC" + ) + } + + @Test + void addMultipleProperties() { + sort.username + sort.id + + assertSortFieldsEquals( + sort.sortFields, + [new SortField(name: 'username', order: ASC), new SortField(name: 'id', order: ASC)], + "Failed to specify multiple sort fields with implied ordering" + ) + } + + @Test + void addMultiplePropertiesWithOrderSpecified() { + sort.username.desc + sort.id.asc + + assertSortFieldsEquals( + sort.sortFields, + [new SortField(name: 'username', order: DESC), new SortField(name: 'id', order: ASC)], + "Failed to specify multiple sort fields with order specified for each field" + ) + } + + @Test + void addMultiplePropertiesWithOrderSpecifiedForSome() { + sort.username.desc + sort.id + + assertSortFieldsEquals( + sort.sortFields, + [new SortField(name: 'username', order: DESC), new SortField(name: 'id', order: ASC)], + "Failed to specify multiple sort fields with order specified for some of them" + ) + } + + def assertSortFieldsEquals(List actual, List expected, String msg) { + assertEquals(actual.size(), expected.size(), "$msg -- Lists do not have the same number of elements") + + def index = 0 + expected.each { expectedSortField -> + def actualSortField = actual[index++] + assertEquals(actualSortField.name, expectedSortField.name, "$msg -- sort fields differ, actual: $actual, expected: $expected") + assertEquals(actualSortField.order, expectedSortField.order, "$msg -- sort fields differ, actual: $actual, expected: $expected") + } + } + }
commit c334492346f6938e2877444a7dae1d11b5e0f2a3 Author: John Sanda jsanda@redhat.com Date: Wed Aug 18 14:26:45 2010 -0400
Initial commit for sort-related classes
The sort delegate allows for a syntax like,
sort { username.asc password.desc }
where the order of sort fields is determined by the order in which the property names are listed. An order can optionally be specified with 'asc' or 'desc' using the dot operator as illustrated above.
diff --git a/modules/enterprise/server/plugins/groovy-script/pom.xml b/modules/enterprise/server/plugins/groovy-script/pom.xml index 4691ce7..22b86e0 100644 --- a/modules/enterprise/server/plugins/groovy-script/pom.xml +++ b/modules/enterprise/server/plugins/groovy-script/pom.xml @@ -24,7 +24,7 @@ <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> - <version>1.7.1</version> + <version>1.7.3</version> </dependency> <dependency> <groupId>org.apache.ant</groupId> diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegate.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegate.groovy new file mode 100644 index 0000000..e42ffa4 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegate.groovy @@ -0,0 +1,11 @@ +package org.rhq.enterprise.server.plugins.groovy + +/** + * Created by IntelliJ IDEA. + * User: jsanda + * Date: Aug 18, 2010 + * Time: 12:18:36 PM + * To change this template use File | Settings | File Templates. + */ +class SortDelegate { +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortField.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortField.groovy new file mode 100644 index 0000000..61447b6 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/SortField.groovy @@ -0,0 +1,11 @@ +package org.rhq.enterprise.server.plugins.groovy + +/** + * Created by IntelliJ IDEA. + * User: jsanda + * Date: Aug 18, 2010 + * Time: 1:36:44 PM + * To change this template use File | Settings | File Templates. + */ +class SortField { +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegateTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegateTest.groovy new file mode 100644 index 0000000..b7d2a08 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/SortDelegateTest.groovy @@ -0,0 +1,11 @@ +package org.rhq.enterprise.server.plugins.groovy + +/** + * Created by IntelliJ IDEA. + * User: jsanda + * Date: Aug 18, 2010 + * Time: 12:47:35 PM + * To change this template use File | Settings | File Templates. + */ +class SortDelegateTest { +}
commit deb3350d933143dbf5e5c6f76fb330f046a8aec5 Author: John Sanda jsanda@redhat.com Date: Tue Aug 17 23:58:38 2010 -0400
Adding test in ScriptRunnerTest to verify criteria dsl
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy index 3d47f1e..a90701f 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy @@ -1,12 +1,12 @@ package org.rhq.enterprise.server.plugins.groovy
-import org.rhq.enterprise.server.util.LookupUtil import org.rhq.core.domain.resource.Resource import org.rhq.core.domain.resource.ResourceType +import org.rhq.enterprise.server.util.LookupUtil
class RHQScript extends Script {
- def entityMap = [ + static def entityMap = [ Resource: Resource.class, ResourceType: ResourceType.class ] diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy index 9c83185..f077ced 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy @@ -30,4 +30,9 @@ class TestEntityCriteria extends Criteria { fetchResourceTypes = fetch }
+ def String toString() { + "TestEntityCriteria[id: $id, name: $name, fetchResources: $fetchResources, fetchResourceTypes: $fetchResourceTypes]" + } + + } diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntity.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntity.groovy new file mode 100644 index 0000000..04b21b4 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntity.groovy @@ -0,0 +1,9 @@ +package org.rhq.core.domain.test + +class TestEntity { + + Integer id + + String name + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy new file mode 100644 index 0000000..312ea47 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy @@ -0,0 +1,4 @@ +package org.rhq.core.domain.test + +class TestEntityWithoutCriteria { +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy index 07d450d..b5439a6 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy @@ -5,8 +5,8 @@ import org.testng.annotations.Test import static org.testng.Assert.*
import org.rhq.core.domain.criteria.TestEntityCriteria -import org.rhq.org.rhq.core.domain.test.TestEntity -import org.rhq.org.rhq.core.domain.test.TestEntityWithoutCriteria +import org.rhq.core.domain.test.TestEntityWithoutCriteria +import org.rhq.core.domain.test.TestEntity
class CriteriaGeneratorTest {
diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy index 84c7806..14c4548 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy @@ -1,9 +1,9 @@ package org.rhq.enterprise.server.plugins.groovy
import org.testng.annotations.Test -import org.rhq.org.rhq.core.domain.test.TestEntity - -import static org.testng.Assert.* +import static org.testng.Assert.assertEquals +import static org.testng.Assert.assertTrue +import org.rhq.core.domain.test.TestEntity
class RHQScriptTest {
diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy index 1991b25..1b7ba47 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy @@ -8,9 +8,17 @@ import org.rhq.core.domain.configuration.PropertySimple
import static org.testng.Assert.* import org.rhq.enterprise.server.plugin.pc.ControlResults +import org.rhq.core.domain.criteria.TestEntityCriteria +import org.testng.annotations.BeforeClass +import org.rhq.core.domain.test.TestEntity
class ScriptRunnerTest {
+ @BeforeClass + void setupClass() { + RHQScript.entityMap << [TestEntity: TestEntity.class] + } + @Test void lookupManagerWhenADynamicManagerPropertyIsAccessed() { def fakeMgr = {} @@ -32,6 +40,38 @@ class ScriptRunnerTest { executeScript('access_nonexistent_mgr.groovy') }
+ @Test + void createCriteriaAccordingToSpec() { + def expectedCriteria = new TestEntityCriteria() + expectedCriteria.id = 1 + expectedCriteria.name = 'Test' + expectedCriteria.fetchResources = true + + def result = executeScript('create_criteria.groovy') + +// assertEquals( +// actualCriteria.id, +// expectedCriteria.id, +// 'The filter on the id property was not set correctly' +// ) +// assertEquals( +// actualCriteria.name, +// expectedCriteria.name, +// 'The filter on the name property was not set correctly' +// ) +// assertEquals( +// actualCriteria.fetchResources, +// expectedCriteria.fetchResources, +// 'The fetch flag for the resources property was not set correctly' +// ) +// assertEquals( +// actualCriteria.fetchResourceTypes, +// expectedCriteria.fetchResourceTypes, +// 'The fetch flag for the resourceTypes property was not set correctly' +// ) + assertScriptResultEquals(result, expectedCriteria.toString(), 'Failed to generate criteria correctly') + } + def executeScript(String script) { def runner = new ScriptRunner() def params = new Configuration() diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/org/rhq/core/domain/test/TestEntity.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/org/rhq/core/domain/test/TestEntity.groovy deleted file mode 100644 index 12ee6df..0000000 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/org/rhq/core/domain/test/TestEntity.groovy +++ /dev/null @@ -1,9 +0,0 @@ -package org.rhq.org.rhq.core.domain.test - -class TestEntity { - - Integer id - - String name - -} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy deleted file mode 100644 index 1ddcea2..0000000 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy +++ /dev/null @@ -1,4 +0,0 @@ -package org.rhq.org.rhq.core.domain.test - -class TestEntityWithoutCriteria { -} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/create_criteria.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/create_criteria.groovy new file mode 100644 index 0000000..595a7d6 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/create_criteria.groovy @@ -0,0 +1,11 @@ +package org.rhq.enterprise.server.plugins.groovy + +testCriteria = criteria(TestEntity) { + filters = [ + id: 1, + name: 'Test' + ] + fetch = ['resources'] +} + +return testCriteria.toString() \ No newline at end of file
commit 25735a3547c396ebc7fae2a8b9db7a58bf9fe9d7 Author: John Sanda jsanda@redhat.com Date: Tue Aug 17 00:26:22 2010 -0400
Adding logic to throw exception if script accesses nonexistent manager SLSB
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy index a1f131d..3d47f1e 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy @@ -18,7 +18,12 @@ class RHQScript extends Script { def propertyMissing(String name) { if (name.endsWith("Manager")) { def method = "get$name" - return LookupUtil."$method"() + try { + return LookupUtil."$method"() + } + catch (MissingMethodException e) { + throw new RHQScriptException("Unable to locate $name", e) + } }
if (entityMap.containsKey(name)) { diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptException.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptException.groovy new file mode 100644 index 0000000..930a358 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptException.groovy @@ -0,0 +1,22 @@ +package org.rhq.enterprise.server.plugins.groovy + +class RHQScriptException extends Exception { + + def RHQScriptException() { + super(); + } + + def RHQScriptException(String message) { + super(message); + } + + def RHQScriptException(String message, Throwable cause) { + super(message, cause); + } + + def RHQScriptException(Throwable cause) { + super(cause); + } + + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy index e45656f..1991b25 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy @@ -17,12 +17,8 @@ class ScriptRunnerTest { def lookupMock = new MockFor(LookupUtil) lookupMock.demand.getSubjectManager { fakeMgr }
- def runner = new ScriptRunner() - def params = new Configuration() - params.put(new PropertySimple('script', getScriptPath('access_mgr.groovy'))) - lookupMock.use { - def result = runner.invoke('execute', params) + def result = executeScript('access_mgr.groovy') assertScriptResultEquals( result, fakeMgr.class.name, @@ -31,6 +27,19 @@ class ScriptRunnerTest { } }
+ @Test(expectedExceptions = [RHQScriptException]) + void throwExceptionWhenManagerAccessedDoesNotExist() { + executeScript('access_nonexistent_mgr.groovy') + } + + def executeScript(String script) { + def runner = new ScriptRunner() + def params = new Configuration() + params.put(new PropertySimple('script', getScriptPath(script))) + + return runner.invoke('execute', params) + } + String getScriptPath(String scriptName) { this.class.getResource(scriptName).toURI().path } diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/access_nonexistent_mgr.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/access_nonexistent_mgr.groovy new file mode 100644 index 0000000..75fc7ca --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/access_nonexistent_mgr.groovy @@ -0,0 +1,3 @@ +package org.rhq.enterprise.server.plugins.groovy + +return NonexistentManager.class.name
commit dd07dc1e3cf123a4d034a54a8cc4fdc93cf11cdc Author: John Sanda jsanda@redhat.com Date: Tue Aug 17 00:03:50 2010 -0400
Renaming GroovyScriptPluginComponent to ScriptRunner and adding unit test for it
diff --git a/modules/enterprise/server/plugins/groovy-script/pom.xml b/modules/enterprise/server/plugins/groovy-script/pom.xml index a8a98b2..4691ce7 100644 --- a/modules/enterprise/server/plugins/groovy-script/pom.xml +++ b/modules/enterprise/server/plugins/groovy-script/pom.xml @@ -26,12 +26,34 @@ <artifactId>groovy-all</artifactId> <version>1.7.1</version> </dependency> - <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant</artifactId> <version>1.7.1</version> </dependency> + <dependency> + <groupId>quartz</groupId> + <artifactId>quartz</artifactId> + <version>1.5.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>javax.transaction</groupId> + <artifactId>jta</artifactId> + <version>1.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.javaee</groupId> + <artifactId>jboss-jms-api</artifactId> + <version>1.1.0.GA</version> + </dependency> + <dependency> + <groupId>jboss</groupId> + <artifactId>jboss-system</artifactId> + <version>4.2.3.GA</version> + <scope>test</scope> + </dependency> </dependencies>
<build> diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy index 4e73145..8e07760 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy @@ -16,7 +16,7 @@ class CriteriaGenerator { clazz = Class.forName(className) } catch (Exception e) { - def msg = "Failed to load criteria class $classname" + def msg = "Failed to load criteria class $className" log.warn msg, e throw new CriteriaGeneratorException(msg, e) } diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy index c46892d..008a090 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy @@ -12,6 +12,6 @@ class CriteriaSpec { this.criteriaType = criteriaType }
- def propertyMissing + //def propertyMissing
} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/GroovyScriptPluginComponent.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/GroovyScriptPluginComponent.groovy deleted file mode 100644 index de0184c..0000000 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/GroovyScriptPluginComponent.groovy +++ /dev/null @@ -1,50 +0,0 @@ -package org.rhq.enterprise.server.plugins.groovy - -import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent -import org.rhq.enterprise.server.plugin.pc.ServerPluginContext -import org.rhq.enterprise.server.plugin.pc.ControlFacet -import org.rhq.enterprise.server.plugin.pc.ControlResults -import org.rhq.core.domain.configuration.Configuration -import org.rhq.core.domain.configuration.PropertySimple -import org.codehaus.groovy.control.CompilerConfiguration - -class GroovyScriptPluginComponent implements ServerPluginComponent, ControlFacet { - - void initialize(ServerPluginContext context) { - - } - - void start() { - - } - - void stop() { - - } - - void shutdown() { - - } - - ControlResults invoke(String name, Configuration parameters) { - def compilerConfig = new CompilerConfiguration() - compilerConfig.scriptBaseClass = RHQScript.class.name - - def scriptName = parameters.getSimpleValue("script", null) - - def scriptClassLoader = new GroovyClassLoader(Thread.currentThread().contextClassLoader, compilerConfig) - def scriptRoots = new URL[1] - scriptRoots[0] = new File(scriptName).toURI().toURL() - def scriptEngine = new GroovyScriptEngine(scriptRoots, scriptClassLoader) - scriptEngine.config = compilerConfig - - def scriptResult = scriptEngine.run(scriptName, new Binding()) - - ControlResults results = new ControlResults() - results.complexResults.put(new PropertySimple("results", scriptResult)) - - return results; - } - - -} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy index b87e863..a1f131d 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy @@ -30,10 +30,11 @@ class RHQScript extends Script {
def criteria(Class entityClass, Closure specifyCriteria) { def criteriaSpec = new CriteriaSpec(entityClass) + specifyCriteria.resolveStrategy = Closure.DELEGATE_FIRST specifyCriteria.delegate = criteriaSpec specifyCriteria()
- return new CriteriaGenerator().execute(criteriaSpec) + return new CriteriaGenerator().execute(specifyCriteria.delegate)
}
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy new file mode 100644 index 0000000..9b27562 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunner.groovy @@ -0,0 +1,50 @@ +package org.rhq.enterprise.server.plugins.groovy + +import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent +import org.rhq.enterprise.server.plugin.pc.ServerPluginContext +import org.rhq.enterprise.server.plugin.pc.ControlFacet +import org.rhq.enterprise.server.plugin.pc.ControlResults +import org.rhq.core.domain.configuration.Configuration +import org.rhq.core.domain.configuration.PropertySimple +import org.codehaus.groovy.control.CompilerConfiguration + +class ScriptRunner implements ServerPluginComponent, ControlFacet { + + void initialize(ServerPluginContext context) { + + } + + void start() { + + } + + void stop() { + + } + + void shutdown() { + + } + + ControlResults invoke(String name, Configuration parameters) { + def compilerConfig = new CompilerConfiguration() + compilerConfig.scriptBaseClass = RHQScript.class.name + + def scriptName = parameters.getSimpleValue("script", null) + + def scriptClassLoader = new GroovyClassLoader(Thread.currentThread().contextClassLoader, compilerConfig) + def scriptRoots = new URL[1] + scriptRoots[0] = new File(scriptName).toURI().toURL() + def scriptEngine = new GroovyScriptEngine(scriptRoots, scriptClassLoader) + scriptEngine.config = compilerConfig + + def scriptResult = scriptEngine.run(scriptName, new Binding()) + + ControlResults results = new ControlResults() + results.complexResults.put(new PropertySimple("results", scriptResult)) + + return results; + } + + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml b/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml index c4c6678..31d21a5 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml +++ b/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml @@ -7,7 +7,7 @@ xmlns="urn:xmlns:rhq-serverplugin.generic" xmlns:serverplugin="urn:xmlns:rhq-serverplugin" xmlns:c="urn:xmlns:rhq-configuration"> - <serverplugin:plugin-component class="GroovyScriptPluginComponent"> + <serverplugin:plugin-component class="ScriptRunner"> <serverplugin:control name="execute" description="Executes a Groovy script"> serverplugin:parameters <c:simple-property name="script" diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy new file mode 100644 index 0000000..e45656f --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/ScriptRunnerTest.groovy @@ -0,0 +1,46 @@ +package org.rhq.enterprise.server.plugins.groovy + +import org.testng.annotations.Test +import groovy.mock.interceptor.MockFor +import org.rhq.enterprise.server.util.LookupUtil +import org.rhq.core.domain.configuration.Configuration +import org.rhq.core.domain.configuration.PropertySimple + +import static org.testng.Assert.* +import org.rhq.enterprise.server.plugin.pc.ControlResults + +class ScriptRunnerTest { + + @Test + void lookupManagerWhenADynamicManagerPropertyIsAccessed() { + def fakeMgr = {} + def lookupMock = new MockFor(LookupUtil) + lookupMock.demand.getSubjectManager { fakeMgr } + + def runner = new ScriptRunner() + def params = new Configuration() + params.put(new PropertySimple('script', getScriptPath('access_mgr.groovy'))) + + lookupMock.use { + def result = runner.invoke('execute', params) + assertScriptResultEquals( + result, + fakeMgr.class.name, + "Expected the script to return the object it received from accessing a dynamic manager property" + ) + } + } + + String getScriptPath(String scriptName) { + this.class.getResource(scriptName).toURI().path + } + + def assertScriptResultEquals(controlResults, expected, msg) { + assertEquals(getScriptResult(controlResults), expected, msg) + } + + def getScriptResult(ControlResults results) { + results.complexResults.getSimpleValue("results", null) + } + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/access_mgr.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/access_mgr.groovy new file mode 100644 index 0000000..1f060f5 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/resources/org/rhq/enterprise/server/plugins/groovy/access_mgr.groovy @@ -0,0 +1,4 @@ +package org.rhq.enterprise.server.plugins.groovy + +return SubjectManager.class.name +
commit 225c0357d027d6e46269eec7ab723a692cf46813 Merge: 986a88c... 7677e9f... Author: John Sanda jsanda@redhat.com Date: Mon Aug 16 17:03:52 2010 -0400
Merge branch 'master' into groovy-server-plugin
commit 986a88c1e229f182ae1aa78de4f15fb3ecb9985c Author: John Sanda jsanda@redhat.com Date: Mon Aug 16 16:41:34 2010 -0400
Adding error handling logic in CriteriaGenerator
Initial commit for RHQScriptTest.groovy which includes a test for the criteria dsl.
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy index 3595114..4e73145 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy @@ -1,10 +1,33 @@ package org.rhq.enterprise.server.plugins.groovy
+import org.apache.commons.logging.Log +import org.apache.commons.logging.LogFactory + class CriteriaGenerator {
+ static Log log = LogFactory.getLog(CriteriaGenerator) + def execute(CriteriaSpec spec) { - def clazz = Class.forName("org.rhq.core.domain.criteria.${spec.criteriaType.simpleName}Criteria") - def criteria = clazz.newInstance() + def className = "org.rhq.core.domain.criteria.${spec.criteriaType.simpleName}Criteria" + def clazz + def criteria + + try { + clazz = Class.forName(className) + } + catch (Exception e) { + def msg = "Failed to load criteria class $classname" + log.warn msg, e + throw new CriteriaGeneratorException(msg, e) + } + try { + criteria = clazz.newInstance() + } + catch (Exception e) { + def msg = "Failed to create instance of criteria class $className" + log.warn msg, e + throw new CriteriaGeneratorException(msg, e) + }
spec.filters.each { key, value -> def filterName = "addFilter${capitalize(key)}" diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorException.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorException.groovy new file mode 100644 index 0000000..9040a51 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorException.groovy @@ -0,0 +1,22 @@ +package org.rhq.enterprise.server.plugins.groovy + +class CriteriaGeneratorException extends Exception { + + def CriteriaGeneratorException() { + super(); + } + + def CriteriaGeneratorException(String message) { + super(message); + } + + def CriteriaGeneratorException(String message, Throwable cause) { + super(message, cause); + } + + def CriteriaGeneratorException(Throwable cause) { + super(cause); + } + + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy index caed55c..07d450d 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy @@ -6,6 +6,7 @@ import static org.testng.Assert.*
import org.rhq.core.domain.criteria.TestEntityCriteria import org.rhq.org.rhq.core.domain.test.TestEntity +import org.rhq.org.rhq.core.domain.test.TestEntityWithoutCriteria
class CriteriaGeneratorTest {
@@ -17,10 +18,11 @@ class CriteriaGeneratorTest { assertTrue(criteria instanceof TestEntityCriteria, "Expected an instance of ${TestEntityCriteria.name}") }
-// @Test -// void throwExceptionWhenEntityTypeDoesNotExist() { -// def spec = new CriteriaSpec() -// } + @Test(expectedExceptions = [CriteriaGeneratorException]) + void throwExceptionWhenCriteriaTypeDoesNotExist() { + def spec = new CriteriaSpec(TestEntityWithoutCriteria) + def criteria = new CriteriaGenerator().execute(spec) + }
@Test void setTheFilterFields() { diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy new file mode 100644 index 0000000..84c7806 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScriptTest.groovy @@ -0,0 +1,22 @@ +package org.rhq.enterprise.server.plugins.groovy + +import org.testng.annotations.Test +import org.rhq.org.rhq.core.domain.test.TestEntity + +import static org.testng.Assert.* + +class RHQScriptTest { + + @Test + void buildCriteriaThatMatchesSpec() { + def script = new RHQScript() + def criteria = script.criteria(TestEntity) { + filters = [id: 1] + fetch = ['resourceTypes'] + } + + assertEquals(criteria.id, 1, "The criteria's id property is wrong") + assertTrue(criteria.fetchResourceTypes) + } + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy new file mode 100644 index 0000000..1ddcea2 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/org/rhq/core/domain/test/TestEntityWithoutCriteria.groovy @@ -0,0 +1,4 @@ +package org.rhq.org.rhq.core.domain.test + +class TestEntityWithoutCriteria { +}
commit d7f2b2f0aad74e96b29c256c654bacd4262b8286 Merge: 0d54848... 02a6eaf... Author: John Sanda jsanda@redhat.com Date: Mon Aug 16 07:38:27 2010 -0400
Merge branch 'master' into groovy-server-plugin
commit 0d5484847d4e9f995ec7e83bc851d4e5d721110f Author: John Sanda jsanda@redhat.com Date: Mon Aug 16 07:31:18 2010 -0400
Adding support for fetch fields in criteria dsl, adding criteria() method in RHQScript
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaDelegate.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaDelegate.groovy deleted file mode 100644 index 742dded..0000000 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaDelegate.groovy +++ /dev/null @@ -1,13 +0,0 @@ -package org.rhq.enterprise.server.plugins.groovy - -class CriteriaDelegate { - - Map filters = [:] - - Class criteriaType - - CriteriaDelegate(Class criteriaType) { - this.criteriaType = criteriaType - } - -} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy index c966dee..3595114 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy @@ -2,15 +2,17 @@ package org.rhq.enterprise.server.plugins.groovy
class CriteriaGenerator {
- def execute(CriteriaDelegate details) { - def clazz = Class.forName("org.rhq.core.domain.criteria.${details.criteriaType.simpleName}Criteria") + def execute(CriteriaSpec spec) { + def clazz = Class.forName("org.rhq.core.domain.criteria.${spec.criteriaType.simpleName}Criteria") def criteria = clazz.newInstance()
- details.filters.each { key, value -> + spec.filters.each { key, value -> def filterName = "addFilter${capitalize(key)}" criteria."$filterName"(value) }
+ spec.fetch.each { criteria."fetch${capitalize(it)}"(true) } + return criteria }
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy new file mode 100644 index 0000000..c46892d --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaSpec.groovy @@ -0,0 +1,17 @@ +package org.rhq.enterprise.server.plugins.groovy + +class CriteriaSpec { + + Class criteriaType + + Map filters = [:] + + List fetch = [] + + CriteriaSpec(Class criteriaType) { + this.criteriaType = criteriaType + } + + def propertyMissing + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy index 6259473..b87e863 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy @@ -28,4 +28,13 @@ class RHQScript extends Script { return null // TODO Should we instead some sort of property not found exception }
+ def criteria(Class entityClass, Closure specifyCriteria) { + def criteriaSpec = new CriteriaSpec(entityClass) + specifyCriteria.delegate = criteriaSpec + specifyCriteria() + + return new CriteriaGenerator().execute(criteriaSpec) + + } + } diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy index fe1395a..9c83185 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy @@ -6,6 +6,10 @@ class TestEntityCriteria extends Criteria {
String name
+ boolean fetchResources + + boolean fetchResourceTypes + Class<?> getPersistentClass() { TestEntityCriteria } @@ -18,4 +22,12 @@ class TestEntityCriteria extends Criteria { this.name = name }
+ void fetchResources(boolean fetch) { + fetchResources = fetch + } + + void fetchResourceTypes(boolean fetch) { + fetchResourceTypes = fetch + } + } diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy index 9ec9fbf..caed55c 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy @@ -11,28 +11,43 @@ class CriteriaGeneratorTest {
@Test void theCriteriaTypeShouldMatchTheSpecifiedEntity() { -// def details = new CriteriaDelegate(Resource.class) - def details = new CriteriaDelegate(TestEntity) - def criteria = new CriteriaGenerator().execute(details) + def spec = new CriteriaSpec(TestEntity) + def criteria = new CriteriaGenerator().execute(spec)
assertTrue(criteria instanceof TestEntityCriteria, "Expected an instance of ${TestEntityCriteria.name}") }
+// @Test +// void throwExceptionWhenEntityTypeDoesNotExist() { +// def spec = new CriteriaSpec() +// } + @Test - void setTheCriteriaFilters() { + void setTheFilterFields() { def expectedId = 1 def expectedName = 'Test Entity'
- def details = new CriteriaDelegate(TestEntity) - details.filters = [ + def spec = new CriteriaSpec(TestEntity) + spec.filters = [ id: expectedId, name: expectedName ]
- def criteria = new CriteriaGenerator().execute(details) + def criteria = new CriteriaGenerator().execute(spec)
assertEquals(criteria.id, expectedId, 'The <id> filter is wrong') assertEquals(criteria.name, expectedName, 'The <name> filter is wrong') }
+ @Test + void setTheFetchFields() { + def spec = new CriteriaSpec(TestEntity) + spec.fetch = ['resources', 'resourceTypes'] + + def criteria = new CriteriaGenerator().execute(spec) + + assertTrue(criteria.fetchResources, 'Expected fetchResources to be <true>') + assertTrue(criteria.fetchResourceTypes, 'Expected fetchResourceTypes to be <false>') + } + }
commit 4200f06280fbe7b900e76ee03883f0fe3e7ab585 Author: John Sanda jsanda@redhat.com Date: Sun Aug 15 15:26:48 2010 -0400
Starting to implement criteria dsl.
The purpose of the dsl is to provide a more concise, yet readable syntax for creating and executing criteria queries that are commonly used in the remote apis and in the CLI. The syntax will look something like,
criteria(Resource) { filters = [ id: 1 name: 'My Resource' availability: UP ]
sort = [ name: ASC, pluginName: DESC ] }
This will create a ResourceCriteria object with the id, name, and availability filters set. And it will sort by the name and pluginName properties.
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaDelegate.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaDelegate.groovy new file mode 100644 index 0000000..742dded --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaDelegate.groovy @@ -0,0 +1,13 @@ +package org.rhq.enterprise.server.plugins.groovy + +class CriteriaDelegate { + + Map filters = [:] + + Class criteriaType + + CriteriaDelegate(Class criteriaType) { + this.criteriaType = criteriaType + } + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy new file mode 100644 index 0000000..c966dee --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGenerator.groovy @@ -0,0 +1,24 @@ +package org.rhq.enterprise.server.plugins.groovy + +class CriteriaGenerator { + + def execute(CriteriaDelegate details) { + def clazz = Class.forName("org.rhq.core.domain.criteria.${details.criteriaType.simpleName}Criteria") + def criteria = clazz.newInstance() + + details.filters.each { key, value -> + def filterName = "addFilter${capitalize(key)}" + criteria."$filterName"(value) + } + + return criteria + } + + String capitalize(String string) { + if (string.length() == 1) { + return string.toUpperCase() + } + return string[0].toUpperCase() + string[1..string.length() - 1] + } + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy index 38bcad7..6259473 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy @@ -1,9 +1,16 @@ package org.rhq.enterprise.server.plugins.groovy
import org.rhq.enterprise.server.util.LookupUtil +import org.rhq.core.domain.resource.Resource +import org.rhq.core.domain.resource.ResourceType
class RHQScript extends Script {
+ def entityMap = [ + Resource: Resource.class, + ResourceType: ResourceType.class + ] + Object run() { super.run() } @@ -13,6 +20,11 @@ class RHQScript extends Script { def method = "get$name" return LookupUtil."$method"() } + + if (entityMap.containsKey(name)) { + return entityMap[name] + } + return null // TODO Should we instead some sort of property not found exception }
diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy new file mode 100644 index 0000000..fe1395a --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/core/domain/criteria/TestEntityCriteria.groovy @@ -0,0 +1,21 @@ +package org.rhq.core.domain.criteria + +class TestEntityCriteria extends Criteria { + + Integer id + + String name + + Class<?> getPersistentClass() { + TestEntityCriteria + } + + void addFilterId(Integer id) { + this.id = id + } + + void addFilterName(String name) { + this.name = name + } + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy new file mode 100644 index 0000000..9ec9fbf --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/enterprise/server/plugins/groovy/CriteriaGeneratorTest.groovy @@ -0,0 +1,38 @@ +package org.rhq.enterprise.server.plugins.groovy + +import org.testng.annotations.Test + +import static org.testng.Assert.* + +import org.rhq.core.domain.criteria.TestEntityCriteria +import org.rhq.org.rhq.core.domain.test.TestEntity + +class CriteriaGeneratorTest { + + @Test + void theCriteriaTypeShouldMatchTheSpecifiedEntity() { +// def details = new CriteriaDelegate(Resource.class) + def details = new CriteriaDelegate(TestEntity) + def criteria = new CriteriaGenerator().execute(details) + + assertTrue(criteria instanceof TestEntityCriteria, "Expected an instance of ${TestEntityCriteria.name}") + } + + @Test + void setTheCriteriaFilters() { + def expectedId = 1 + def expectedName = 'Test Entity' + + def details = new CriteriaDelegate(TestEntity) + details.filters = [ + id: expectedId, + name: expectedName + ] + + def criteria = new CriteriaGenerator().execute(details) + + assertEquals(criteria.id, expectedId, 'The <id> filter is wrong') + assertEquals(criteria.name, expectedName, 'The <name> filter is wrong') + } + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/org/rhq/core/domain/test/TestEntity.groovy b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/org/rhq/core/domain/test/TestEntity.groovy new file mode 100644 index 0000000..12ee6df --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/test/groovy/org/rhq/org/rhq/core/domain/test/TestEntity.groovy @@ -0,0 +1,9 @@ +package org.rhq.org.rhq.core.domain.test + +class TestEntity { + + Integer id + + String name + +}
commit 0331a532c08ed27468b827f277ae80b2179c8eb4 Author: John Sanda jsanda@redhat.com Date: Mon Aug 9 23:09:49 2010 -0400
Initial commit for RHQScript.groovy which is the base class for scripts run by the plugin
diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/GroovyScriptPluginComponent.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/GroovyScriptPluginComponent.groovy index 1f12a36..de0184c 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/GroovyScriptPluginComponent.groovy +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/GroovyScriptPluginComponent.groovy @@ -6,6 +6,7 @@ import org.rhq.enterprise.server.plugin.pc.ControlFacet import org.rhq.enterprise.server.plugin.pc.ControlResults import org.rhq.core.domain.configuration.Configuration import org.rhq.core.domain.configuration.PropertySimple +import org.codehaus.groovy.control.CompilerConfiguration
class GroovyScriptPluginComponent implements ServerPluginComponent, ControlFacet {
@@ -26,13 +27,17 @@ class GroovyScriptPluginComponent implements ServerPluginComponent, ControlFacet }
ControlResults invoke(String name, Configuration parameters) { + def compilerConfig = new CompilerConfiguration() + compilerConfig.scriptBaseClass = RHQScript.class.name + def scriptName = parameters.getSimpleValue("script", null)
- def scriptClassLoader = new GroovyClassLoader(Thread.currentThread().contextClassLoader) + def scriptClassLoader = new GroovyClassLoader(Thread.currentThread().contextClassLoader, compilerConfig) def scriptRoots = new URL[1] scriptRoots[0] = new File(scriptName).toURI().toURL() def scriptEngine = new GroovyScriptEngine(scriptRoots, scriptClassLoader) - + scriptEngine.config = compilerConfig + def scriptResult = scriptEngine.run(scriptName, new Binding())
ControlResults results = new ControlResults() diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy new file mode 100644 index 0000000..38bcad7 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/RHQScript.groovy @@ -0,0 +1,19 @@ +package org.rhq.enterprise.server.plugins.groovy + +import org.rhq.enterprise.server.util.LookupUtil + +class RHQScript extends Script { + + Object run() { + super.run() + } + + def propertyMissing(String name) { + if (name.endsWith("Manager")) { + def method = "get$name" + return LookupUtil."$method"() + } + return null // TODO Should we instead some sort of property not found exception + } + +}
commit fe85bc399b56ef1e904280bede87baac4927133a Author: John Sanda jsanda@localhost.localdomain Date: Mon Aug 9 22:08:15 2010 -0400
Commenting out classpath parameter for now due to BZ 622996
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-add-map.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-add-map.xhtml new file mode 100644 index 0000000..ea074f8 --- /dev/null +++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-add-map.xhtml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> + +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:h="http://java.sun.com/jsf/html" + xmlns:f="http://java.sun.com/jsf/core" + xmlns:ui="http://java.sun.com/jsf/facelets" + xmlns:c="http://java.sun.com/jstl/core" + xmlns:onc="http://jboss.org/on/component%22%3E + +<ui:composition template="/rhq/admin/plugin/plugin-details-map.xhtml"> + <ui:param name="actionVerb" value="Add to" /> + <ui:param name="editBreadCrumb" value="true" /> + + <ui:define name="mapConfig"> + <onc:config configurationDefinition="#{editPluginConfigurationUIBean.currentConfigurationDefinition}" + configuration="#{editPluginConfigurationUIBean.currentConfiguration}" + listName="#{param.listName}" /> + + <h:panelGrid columns="2" styleClass="buttons-table" columnClasses="button-cell"> + <h:commandButton value="OK" type="submit" action="#{editPluginConfigurationUIBean.finishMap}" + alt="Click to Add Map" styleClass="buttonmed"/> + <h:commandButton value="RESET" type="reset" immediate="true" + alt="Click to Reset Fields" styleClass="buttonmed"/> + </h:panelGrid> + </ui:define> +</ui:composition> + +</html> diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-edit-map.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-edit-map.xhtml new file mode 100644 index 0000000..e69de29 diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml b/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml index c952fa7..c4c6678 100644 --- a/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml +++ b/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml @@ -13,19 +13,20 @@ <c:simple-property name="script" required="true" description="The pat of the script to execute. Can be relative or absolute." /> - <c:list-property name="classpathList" displayName="classpath" required="false"> - <c:map-property name="classpathMap"> - <c:simple-property name="path" - description="A file system path that can refer to a classes directory, a - single JAR file, or a directory containing multiple JAR files."/> - <c:simple-property name="libDir" displayName="JAR Directory" default="no"> - <c:property-options> - <c:option value="yes" name="Yes"/> - <c:option value="no" name="No"/> - </c:property-options> - </c:simple-property> - </c:map-property> - </c:list-property> + <!--<c:list-property name="classpathList" displayName="classpath" required="false">--> + <!--<c:map-property name="classpathMap">--> + <!--<c:simple-property name="path"--> + <!--required="true"--> + <!--description="A file system path that can refer to a classes directory, a--> + <!--single JAR file, or a directory containing multiple JAR files."/>--> + <!--<c:simple-property name="libDir" displayName="JAR Directory" default="no" required="false">--> + <!--<c:property-options>--> + <!--<c:option value="yes" name="Yes"/>--> + <!--<c:option value="no" name="No"/>--> + <!--</c:property-options>--> + <!--</c:simple-property>--> + <!--</c:map-property>--> + <!--</c:list-property>--> </serverplugin:parameters> serverplugin:results <c:simple-property name="results"/>
commit 0efa7953b22a7877ab594bba2f4ebc2382875ef0 Author: John Sanda jsanda@localhost.localdomain Date: Sun Aug 8 22:23:01 2010 -0400
Initial commit for groovy-script server plugin
With this commit there is initial support for running a specified script. The plugin descriptor has meta data in place for specifying a classpath, but support for an additional classpath has not been implemented yet.
diff --git a/modules/enterprise/server/plugins/groovy-script/pom.xml b/modules/enterprise/server/plugins/groovy-script/pom.xml new file mode 100644 index 0000000..a8a98b2 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/pom.xml @@ -0,0 +1,170 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <parent> + <groupId>org.rhq</groupId> + <artifactId>rhq-enterprise-server-plugins-parent</artifactId> + <version>4.0.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + + <groupId>org.rhq</groupId> + <artifactId>groovy-script-server-plugin</artifactId> + <version>4.0.0-SNAPSHOT</version> + + <name>RHQ Enterprise Server Groovy Script Plugin</name> + + <scm> + <connection>scm:git:ssh://git.fedorahosted.org/git/rhq.git/modules/enterprise/server/plugins/groovy-script/</connection> + <developerConnection>scm:git:ssh://git.fedorahosted.org/git/rhq.git/modules/enterprise/server/plugins/groovy-script/</developerConnection> + </scm> + + <dependencies> + <dependency> + <groupId>org.codehaus.groovy</groupId> + <artifactId>groovy-all</artifactId> + <version>1.7.1</version> + </dependency> + + <dependency> + <groupId>org.apache.ant</groupId> + <artifactId>ant</artifactId> + <version>1.7.1</version> + </dependency> + </dependencies> + + <build> + <plugins> + + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <version>2.0</version> + <executions> + <execution> + <id>copy-libs</id> + <phase>process-resources</phase> + <goals> + <goal>copy</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>org.codehaus.groovy</groupId> + <artifactId>groovy-all</artifactId> + <version>1.7.1</version> + </artifactItem> + </artifactItems> + <outputDirectory>${project.build.outputDirectory}/lib</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.codehaus.groovy.maven</groupId> + <artifactId>gmaven-plugin</artifactId> + <version>1.0</version> + <executions> + <execution> + <goals> + <goal>compile</goal> + <goal>testCompile</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <excludedGroups>${rhq.testng.excludedGroups}</excludedGroups> + <!-- + <argLine>-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y</argLine> + --> + </configuration> + </plugin> + + </plugins> + </build> + + <profiles> + + <profile> + <id>dev</id> + + <properties> + <rhq.rootDir>../../../../..</rhq.rootDir> + <rhq.containerDir>${rhq.rootDir}/${rhq.defaultDevContainerPath}</rhq.containerDir> + <rhq.deploymentDir>${rhq.containerDir}/jbossas/server/default/deploy/${rhq.earName}/rhq-serverplugins</rhq.deploymentDir> + </properties> + + <build> + <plugins> + + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <version>1.1</version> + <executions> + + <execution> + <id>deploy</id> + <phase>package</phase> + <configuration> + <tasks> + <mkdir dir="${rhq.deploymentDir}" /> + <property name="deployment.file" location="${rhq.deploymentDir}/${project.build.finalName}.jar" /> + <echo>*** Updating ${deployment.file}...</echo> + <jar destfile="${deployment.file}" basedir="${project.build.outputDirectory}" /> + </tasks> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + + <execution> + <id>undeploy</id> + <phase>clean</phase> + <configuration> + <tasks> + <property name="deployment.file" location="${rhq.deploymentDir}/${project.build.finalName}.jar" /> + <echo>*** Deleting ${deployment.file}...</echo> + <delete file="${deployment.file}" /> + </tasks> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + + <execution> + <id>deploy-jar-meta-inf</id> + <phase>package</phase> + <configuration> + <tasks> + <property name="deployment.file" location="${rhq.deploymentDir}/${project.build.finalName}.jar" /> + <echo>*** Updating META-INF dir in ${deployment.file}...</echo> + <unjar src="${project.build.directory}/${project.build.finalName}.jar" dest="${project.build.outputDirectory}"> + <patternset> + <include name="META-INF/**" /> + </patternset> + </unjar> + <jar destfile="${deployment.file}" manifest="${project.build.outputDirectory}/META-INF/MANIFEST.MF" update="true"> + </jar> + </tasks> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + + </executions> + </plugin> + + </plugins> + </build> + </profile> + + </profiles> +</project> diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/GroovyScriptPluginComponent.groovy b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/GroovyScriptPluginComponent.groovy new file mode 100644 index 0000000..1f12a36 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/groovy/org/rhq/enterprise/server/plugins/groovy/GroovyScriptPluginComponent.groovy @@ -0,0 +1,45 @@ +package org.rhq.enterprise.server.plugins.groovy + +import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent +import org.rhq.enterprise.server.plugin.pc.ServerPluginContext +import org.rhq.enterprise.server.plugin.pc.ControlFacet +import org.rhq.enterprise.server.plugin.pc.ControlResults +import org.rhq.core.domain.configuration.Configuration +import org.rhq.core.domain.configuration.PropertySimple + +class GroovyScriptPluginComponent implements ServerPluginComponent, ControlFacet { + + void initialize(ServerPluginContext context) { + + } + + void start() { + + } + + void stop() { + + } + + void shutdown() { + + } + + ControlResults invoke(String name, Configuration parameters) { + def scriptName = parameters.getSimpleValue("script", null) + + def scriptClassLoader = new GroovyClassLoader(Thread.currentThread().contextClassLoader) + def scriptRoots = new URL[1] + scriptRoots[0] = new File(scriptName).toURI().toURL() + def scriptEngine = new GroovyScriptEngine(scriptRoots, scriptClassLoader) + + def scriptResult = scriptEngine.run(scriptName, new Binding()) + + ControlResults results = new ControlResults() + results.complexResults.put(new PropertySimple("results", scriptResult)) + + return results; + } + + +} diff --git a/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml b/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml new file mode 100644 index 0000000..c952fa7 --- /dev/null +++ b/modules/enterprise/server/plugins/groovy-script/src/main/resources/META-INF/rhq-serverplugin.xml @@ -0,0 +1,35 @@ +<generic-plugin name="GroovyScriptServerPlugin" + displayName="Groovy Script Server Plugin" + description="A plugin that executes Groovy scripts on the RHQ server" + package="org.rhq.enterprise.server.plugins.groovy" + disabledOnDiscovery="true" + version="2.0" + xmlns="urn:xmlns:rhq-serverplugin.generic" + xmlns:serverplugin="urn:xmlns:rhq-serverplugin" + xmlns:c="urn:xmlns:rhq-configuration"> + <serverplugin:plugin-component class="GroovyScriptPluginComponent"> + <serverplugin:control name="execute" description="Executes a Groovy script"> + serverplugin:parameters + <c:simple-property name="script" + required="true" + description="The pat of the script to execute. Can be relative or absolute." /> + <c:list-property name="classpathList" displayName="classpath" required="false"> + <c:map-property name="classpathMap"> + <c:simple-property name="path" + description="A file system path that can refer to a classes directory, a + single JAR file, or a directory containing multiple JAR files."/> + <c:simple-property name="libDir" displayName="JAR Directory" default="no"> + <c:property-options> + <c:option value="yes" name="Yes"/> + <c:option value="no" name="No"/> + </c:property-options> + </c:simple-property> + </c:map-property> + </c:list-property> + </serverplugin:parameters> + serverplugin:results + <c:simple-property name="results"/> + </serverplugin:results> + </serverplugin:control> + </serverplugin:plugin-component> +</generic-plugin> \ No newline at end of file