[rhq] Branch 'mazz/test-rhq-on-as7' - modules/enterprise
by mazz
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java | 292 ++++++----
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/ServerPropertyRecordList.java | 62 ++
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java | 43 -
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/shared/ServerDetails.java | 115 +++
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java | 61 +-
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerDetails.java | 120 ----
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java | 7
modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties | 3
8 files changed, 446 insertions(+), 257 deletions(-)
New commits:
commit c7c754d3c5b9cc4911af5d617b809f0287887b26
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Jul 20 02:52:14 2012 -0400
the workflow in the gui is mostly done i think. just a matter of getting the server-side code to install everything that the user asked for.
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
index 12d5885..f93b823 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
@@ -40,6 +40,8 @@ import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
+import com.smartgwt.client.widgets.form.fields.FormItem;
+import com.smartgwt.client.widgets.form.fields.FormItemIcon;
import com.smartgwt.client.widgets.form.fields.PasswordItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.SpacerItem;
@@ -47,9 +49,10 @@ import com.smartgwt.client.widgets.form.fields.SpinnerItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
+import com.smartgwt.client.widgets.form.fields.events.IconClickEvent;
+import com.smartgwt.client.widgets.form.fields.events.IconClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.grid.events.EditCompleteEvent;
import com.smartgwt.client.widgets.grid.events.EditCompleteHandler;
import com.smartgwt.client.widgets.layout.VLayout;
@@ -58,6 +61,7 @@ import com.smartgwt.client.widgets.tab.TabSet;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
import org.rhq.enterprise.gui.installer.client.gwt.InstallerGWTServiceAsync;
+import org.rhq.enterprise.gui.installer.client.shared.ServerDetails;
import org.rhq.enterprise.gui.installer.client.shared.ServerProperties;
/**
@@ -71,12 +75,12 @@ public class Installer implements EntryPoint {
public static final Messages MSG = GWT.create(Messages.class);
public static final ServerPropertiesMessages PROPS_MSG = GWT.create(ServerPropertiesMessages.class);
- private static final String PROPERTY_NAME = "propertyName";
- private static final String PROPERTY_VALUE = "propertyValue";
+ private static final String NEW_SERVER_TO_REGISTER = "*new*";
- private InstallerGWTServiceAsync installerService = InstallerGWTServiceAsync.Util.getInstance();
- private HashMap<String, String> serverProperties = new HashMap<String, String>();
- private HashMap<String, String> originalProperties = new HashMap<String, String>();
+ private final InstallerGWTServiceAsync installerService = InstallerGWTServiceAsync.Util.getInstance();
+ private final ServerPropertyRecordList serverProperties = new ServerPropertyRecordList();
+ private final HashMap<String, String> originalProperties = new HashMap<String, String>();
+ private final LinkedHashMap<String, String> registeredServerNames = new LinkedHashMap<String, String>();
private ListGrid advancedPropertyItemGrid;
private Button mainInstallButton;
@@ -120,7 +124,7 @@ public class Installer implements EntryPoint {
}
private void updateServerProperty(String name, Object value) {
- serverProperties.put(name, value == null ? "" : value.toString());
+ serverProperties.putServerProperty(name, value == null ? "" : value.toString());
refreshAdvancedView();
}
@@ -131,8 +135,7 @@ public class Installer implements EntryPoint {
if (result.size() == 0) {
SC.say("Initial server properties are missing.");
}
- serverProperties.clear();
- serverProperties.putAll(result);
+ serverProperties.replaceServerProperties(result);
// remember these original properties in case the user wants to reset them back
originalProperties.clear();
@@ -152,34 +155,26 @@ public class Installer implements EntryPoint {
}
private void refreshSimpleView() {
+ Map<String, String> props = serverProperties.getMap();
+
// DB SETTINGS
- dbType.setValue(serverProperties.get(ServerProperties.PROP_DATABASE_TYPE));
- dbConnectionUrl.setValue(serverProperties.get(ServerProperties.PROP_DATABASE_CONNECTION_URL));
- dbUsername.setValue(serverProperties.get(ServerProperties.PROP_DATABASE_USERNAME));
+ dbType.setValue(props.get(ServerProperties.PROP_DATABASE_TYPE));
+ dbConnectionUrl.setValue(props.get(ServerProperties.PROP_DATABASE_CONNECTION_URL));
+ dbUsername.setValue(props.get(ServerProperties.PROP_DATABASE_USERNAME));
// do not prefill the database password - force the user to know it and type it in for security purposes
// SERVER SETTINGS
- serverSettingServerName.setValue(serverProperties.get(ServerProperties.PROP_HIGH_AVAILABILITY_NAME));
- serverSettingWebHttpPort.setValue(serverProperties.get(ServerProperties.PROP_WEB_HTTP_PORT));
- serverSettingWebSecureHttpPort.setValue(serverProperties.get(ServerProperties.PROP_WEB_HTTPS_PORT));
- serverSettingEmailSMTPHostname.setValue(serverProperties.get(ServerProperties.PROP_EMAIL_SMTP_HOST));
- serverSettingEmailFromAddress.setValue(serverProperties.get(ServerProperties.PROP_EMAIL_FROM_ADDRESS));
+ serverSettingServerName.setValue(props.get(ServerProperties.PROP_HIGH_AVAILABILITY_NAME));
+ serverSettingWebHttpPort.setValue(props.get(ServerProperties.PROP_WEB_HTTP_PORT));
+ serverSettingWebSecureHttpPort.setValue(props.get(ServerProperties.PROP_WEB_HTTPS_PORT));
+ serverSettingEmailSMTPHostname.setValue(props.get(ServerProperties.PROP_EMAIL_SMTP_HOST));
+ serverSettingEmailFromAddress.setValue(props.get(ServerProperties.PROP_EMAIL_FROM_ADDRESS));
- dbExistingSchemaOption.hide();
- testConnectionButton.setIcon(null);
+ forceAnotherTestConnection();
}
private void refreshAdvancedView() {
- ArrayList<ListGridRecord> records = new ArrayList<ListGridRecord>();
- for (Map.Entry<String, String> entry : serverProperties.entrySet()) {
- ListGridRecord record = new ListGridRecord();
- record.setAttribute(PROPERTY_NAME, entry.getKey());
- record.setAttribute(PROPERTY_VALUE, entry.getValue());
- records.add(record);
- }
- advancedPropertyItemGrid.setData(records.toArray(new ListGridRecord[records.size()]));
advancedPropertyItemGrid.markForRedraw();
- return;
}
private Canvas createHeader() {
@@ -216,23 +211,22 @@ public class Installer implements EntryPoint {
final TabSet topTabSet = new TabSet();
topTabSet.setTabBarPosition(Side.TOP);
topTabSet.setTabBarAlign(Side.LEFT);
- topTabSet.setWidth("80%");
- topTabSet.setHeight("75%");
+ topTabSet.setWidth("90%");
final Tab welcomeTab = new Tab(MSG.tab_welcome());
Label welcomeLabel = new Label(MSG.tab_welcome_content());
welcomeTab.setPane(welcomeLabel);
- final Tab databaseTab = new Tab(MSG.tab_simpleView());
- Canvas databaseForm = createSimpleForm();
- databaseTab.setPane(databaseForm);
+ final Tab simpleViewTab = new Tab(MSG.tab_simpleView());
+ Canvas simpleForm = createSimpleForm();
+ simpleViewTab.setPane(simpleForm);
final Tab advancedViewTab = new Tab(MSG.tab_advancedView());
Canvas advancedView = createAdvancedView();
advancedViewTab.setPane(advancedView);
topTabSet.addTab(welcomeTab);
- topTabSet.addTab(databaseTab);
+ topTabSet.addTab(simpleViewTab);
topTabSet.addTab(advancedViewTab);
return topTabSet;
@@ -247,10 +241,10 @@ public class Installer implements EntryPoint {
IButton saveButton = new IButton(MSG.button_save());
saveButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
- installerService.saveServerProperties(serverProperties, new AsyncCallback<Void>() {
+ installerService.saveServerProperties(serverProperties.getMap(), new AsyncCallback<Void>() {
public void onSuccess(Void result) {
originalProperties.clear();
- originalProperties.putAll(serverProperties);
+ originalProperties.putAll(serverProperties.getMap());
SC.say("Properties saved to server");
}
@@ -263,8 +257,7 @@ public class Installer implements EntryPoint {
IButton resetButton = new IButton(MSG.button_reset());
resetButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
- serverProperties.clear();
- serverProperties.putAll(originalProperties);
+ serverProperties.replaceServerProperties(originalProperties);
refreshAdvancedView();
}
});
@@ -275,22 +268,23 @@ public class Installer implements EntryPoint {
advancedPropertyItemGrid = new ListGrid();
advancedPropertyItemGrid.setWidth100();
advancedPropertyItemGrid.setHeight100();
- advancedPropertyItemGrid.setData(new ListGridRecord[0]);
+ advancedPropertyItemGrid.setData(serverProperties);
- ListGridField nameField = new ListGridField(PROPERTY_NAME, MSG.property_name_label());
+ ListGridField nameField = new ListGridField(ServerPropertyRecordList.PROPERTY_NAME, MSG.property_name_label());
nameField.setCanEdit(false);
- ListGridField valueField = new ListGridField(PROPERTY_VALUE, MSG.property_value_label());
+ ListGridField valueField = new ListGridField(ServerPropertyRecordList.PROPERTY_VALUE,
+ MSG.property_value_label());
valueField.setCanEdit(true);
advancedPropertyItemGrid.setFields(nameField, valueField);
- advancedPropertyItemGrid.setSortField(PROPERTY_NAME);
+ advancedPropertyItemGrid.setSortField(ServerPropertyRecordList.PROPERTY_NAME);
advancedPropertyItemGrid.addEditCompleteHandler(new EditCompleteHandler() {
public void onEditComplete(EditCompleteEvent event) {
String newValue = (String) event.getNewValues().values().iterator().next().toString();
- String changedProperty = event.getOldRecord().getAttribute(PROPERTY_NAME);
- serverProperties.put(changedProperty, newValue);
+ String changedProperty = event.getOldRecord().getAttribute(ServerPropertyRecordList.PROPERTY_NAME);
+ serverProperties.getMap().put(changedProperty, newValue); // we need this to be reflected in the internal map
refreshSimpleView();
}
});
@@ -302,7 +296,7 @@ public class Installer implements EntryPoint {
private Canvas createSimpleForm() {
- final int fieldWidth = 250;
+ final int fieldWidth = 300;
////////////////////////////////////////////////////////
// The Database form
@@ -322,6 +316,7 @@ public class Installer implements EntryPoint {
dbConnectionUrl.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
updateServerProperty(ServerProperties.PROP_DATABASE_CONNECTION_URL, String.valueOf(event.getValue()));
+ forceAnotherTestConnection();
}
});
@@ -331,6 +326,7 @@ public class Installer implements EntryPoint {
dbUsername.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
updateServerProperty(ServerProperties.PROP_DATABASE_USERNAME, String.valueOf(event.getValue()));
+ forceAnotherTestConnection();
}
});
@@ -340,6 +336,7 @@ public class Installer implements EntryPoint {
dbPassword.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
updateServerProperty(ServerProperties.PROP_DATABASE_PASSWORD, String.valueOf(event.getValue()));
+ forceAnotherTestConnection();
}
});
@@ -353,48 +350,42 @@ public class Installer implements EntryPoint {
dbExistingSchemaOption.setVisible(false);
dbExistingSchemaOption.setWidth(fieldWidth);
dbExistingSchemaOption.setWrapTitle(true);
+ dbExistingSchemaOption.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ if (registeredServersSelection != null) {
+ String selected = event.getValue().toString();
+ if ("overwrite".equals(selected)) {
+ registeredServersSelection.setValue((String) null);
+ registeredServersSelection.disable();
+ } else {
+ registeredServersSelection.enable();
+ }
+ }
+ }
+ });
testConnectionButton = new ButtonItem("testConnectionButton", MSG.button_testConnection());
testConnectionButton.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
- final String connectionUrl = dbConnectionUrl.getValueAsString();
- final String username = dbUsername.getValueAsString();
- final String password = dbPassword.getValueAsString();
-
- installerService.testConnection(connectionUrl, username, password, new AsyncCallback<String>() {
- public void onSuccess(String result) {
- if (result != null) {
- SC.say("Could not connect to the database: " + result);
- testConnectionButton.setIcon("[SKIN]/actions/exclamation.png");
- mainInstallButton.disable();
- dbExistingSchemaOption.hide();
- } else {
- testConnectionButton.setIcon("[SKIN]/actions/ok.png");
- installerService.isDatabaseSchemaExist(connectionUrl, username, password,
- new AsyncCallback<Boolean>() {
- public void onSuccess(Boolean schemaExists) {
- if (schemaExists) {
- dbExistingSchemaOption.show();
- } else {
- dbExistingSchemaOption.hide();
- }
- mainInstallButton.enable();
- }
-
- public void onFailure(Throwable caught) {
- SC.say("Cannot determine the status of the database schema: " + caught);
- }
- });
+ final Conn conn = new Conn();
+ installerService.testConnection(conn.url(), conn.username(), conn.password(),
+ new AsyncCallback<String>() {
+ public void onSuccess(String result) {
+ if (result != null) {
+ forceAnotherTestConnection();
+ testConnectionButton.setIcon("[SKIN]/actions/exclamation.png");
+ SC.say("Could not connect to the database: " + result);
+ } else {
+ connectedToDatabase();
+ }
}
- }
- public void onFailure(Throwable caught) {
- SC.say("Failed to test connection: " + caught.toString());
- testConnectionButton.setIcon("[SKIN]/actions/exclamation.png");
- mainInstallButton.disable();
- dbExistingSchemaOption.hide();
- }
- });
+ public void onFailure(Throwable caught) {
+ forceAnotherTestConnection();
+ testConnectionButton.setIcon("[SKIN]/actions/exclamation.png");
+ SC.say("Failed to test connection: " + caught.toString());
+ }
+ });
}
});
@@ -408,10 +399,7 @@ public class Installer implements EntryPoint {
dbType.setDefaultToFirstOption(true);
dbType.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
- // force the user to re-test the connection
- mainInstallButton.disable();
- testConnectionButton.setIcon(null);
- dbExistingSchemaOption.setVisible(false);
+ forceAnotherTestConnection();
String newDBType = (String) event.getValue();
String newURL = "";
@@ -431,11 +419,11 @@ public class Installer implements EntryPoint {
}
dbConnectionUrl.setValue(newURL);
- serverProperties.put(ServerProperties.PROP_DATABASE_CONNECTION_URL, newURL);
- serverProperties.put(ServerProperties.PROP_DATABASE_HIBERNATE_DIALECT, dialect);
- serverProperties.put(ServerProperties.PROP_QUARTZ_DRIVER_DELEGATE_CLASS, quartzDriverDelegateClass);
- serverProperties.put(ServerProperties.PROP_QUARTZ_SELECT_WITH_LOCK_SQL, quartzSelectWithLockSQL);
- serverProperties.put(ServerProperties.PROP_QUARTZ_LOCK_HANDLER_CLASS, quartzLockHandlerClass);
+ updateServerProperty(ServerProperties.PROP_DATABASE_CONNECTION_URL, newURL);
+ updateServerProperty(ServerProperties.PROP_DATABASE_HIBERNATE_DIALECT, dialect);
+ updateServerProperty(ServerProperties.PROP_QUARTZ_DRIVER_DELEGATE_CLASS, quartzDriverDelegateClass);
+ updateServerProperty(ServerProperties.PROP_QUARTZ_SELECT_WITH_LOCK_SQL, quartzSelectWithLockSQL);
+ updateServerProperty(ServerProperties.PROP_QUARTZ_LOCK_HANDLER_CLASS, quartzLockHandlerClass);
updateServerProperty(ServerProperties.PROP_DATABASE_TYPE, newDBType); // this refreshes the advanced view, too
}
});
@@ -465,6 +453,9 @@ public class Installer implements EntryPoint {
serverSettingServerName.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
updateServerProperty(ServerProperties.PROP_HIGH_AVAILABILITY_NAME, String.valueOf(event.getValue()));
+ if (registeredServersSelection != null) {
+ registeredServersSelection.setValue((String) null); // flip it back to *new* since the server name changed
+ }
}
});
@@ -496,20 +487,40 @@ public class Installer implements EntryPoint {
registeredServersSelection = new SelectItem("registeredServersSelectItem",
MSG.tab_simpleView_serverSettings_registeredServers());
- final LinkedHashMap<String, String> registeredServers = new LinkedHashMap<String, String>();
- registeredServers.put("*new*", MSG.tab_simpleView_serverSettings_registeredServers_newServer());
- registeredServers.put("blah", "blah");
- registeredServersSelection.setValueMap(registeredServers);
+ registeredServersSelection.setWidth(fieldWidth);
+ addContextualHelp(registeredServersSelection, MSG.help_registeredServers());
+ registeredServerNames.put(NEW_SERVER_TO_REGISTER,
+ MSG.tab_simpleView_serverSettings_registeredServers_newServer());
+ registeredServersSelection.setValueMap(registeredServerNames);
registeredServersSelection.setDefaultToFirstOption(true);
registeredServersSelection.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
- String selectedServerName = String.valueOf(event.getValue());
- boolean newServer = "*new*".equals(selectedServerName);
+ final String selectedServerName = String.valueOf(event.getValue());
+ final boolean newServer = NEW_SERVER_TO_REGISTER.equals(selectedServerName);
if (newServer) {
serverSettingServerName.setValue("");
serverSettingPublicAddress.setValue("");
+ updateServerProperty(ServerProperties.PROP_HIGH_AVAILABILITY_NAME, "");
} else {
- serverSettingServerName.setValue(selectedServerName);
+ final Conn conn = new Conn();
+ installerService.getServerDetails(conn.url(), conn.username(), conn.password(), selectedServerName,
+ new AsyncCallback<ServerDetails>() {
+ public void onSuccess(ServerDetails details) {
+ serverSettingServerName.setValue(details.getName());
+ serverSettingPublicAddress.setValue(details.getEndpointAddress());
+ serverSettingWebHttpPort.setValue(details.getEndpointPortString());
+ serverSettingWebSecureHttpPort.setValue(details.getEndpointSecurePortString());
+ updateServerProperty(ServerProperties.PROP_HIGH_AVAILABILITY_NAME, details.getName());
+ updateServerProperty(ServerProperties.PROP_WEB_HTTP_PORT,
+ details.getEndpointPortString());
+ updateServerProperty(ServerProperties.PROP_WEB_HTTPS_PORT,
+ details.getEndpointSecurePortString());
+ }
+
+ public void onFailure(Throwable caught) {
+ SC.say("Failed to get details on selected server [" + selectedServerName + "]");
+ }
+ });
}
}
});
@@ -550,4 +561,91 @@ public class Installer implements EntryPoint {
return simpleForm;
}
+
+ private void connectedToDatabase() {
+ final Conn conn = new Conn();
+ testConnectionButton.setIcon("[SKIN]/actions/ok.png");
+ installerService.isDatabaseSchemaExist(conn.url(), conn.username(), conn.password(),
+ new AsyncCallback<Boolean>() {
+ public void onSuccess(Boolean schemaExists) {
+ if (schemaExists) {
+ dbExistingSchemaOption.show();
+ registeredServersSelection.enable();
+
+ installerService.getServerNames(conn.url(), conn.username(), conn.password(),
+ new AsyncCallback<ArrayList<String>>() {
+ public void onSuccess(ArrayList<String> servers) {
+ registeredServerNames.clear();
+ registeredServerNames.put(NEW_SERVER_TO_REGISTER,
+ MSG.tab_simpleView_serverSettings_registeredServers_newServer());
+ for (String server : servers) {
+ registeredServerNames.put(server, server);
+ }
+ registeredServersSelection.setValueMap(registeredServerNames);
+ }
+
+ public void onFailure(Throwable caught) {
+ SC.say("Cannot get the registered server names");
+ }
+ });
+ } else {
+ dbExistingSchemaOption.hide();
+ registeredServersSelection.setValue((String) null);
+ registeredServersSelection.disable();
+ }
+ mainInstallButton.enable();
+ }
+
+ public void onFailure(Throwable caught) {
+ SC.say("Cannot determine the status of the database schema: " + caught);
+ }
+ });
+ }
+
+ private void addContextualHelp(final FormItem item, final String helpText) {
+ final FormItemIcon helpIcon = new FormItemIcon();
+ helpIcon.setSrc("[SKIN]/actions/help.png");
+ helpIcon.setNeverDisable(true);
+ item.setIcons(helpIcon);
+
+ item.addIconClickHandler(new IconClickHandler() {
+ public void onIconClick(IconClickEvent event) {
+ if (event.getIcon().equals(helpIcon)) {
+ SC.say(helpText);
+ }
+ }
+ });
+ }
+
+ /**
+ * Call this when the user changed something (like connection URL or password) that renders
+ * the old connection test invalid. This will ensure the user is forced to re-test the connection.
+ */
+ private void forceAnotherTestConnection() {
+ mainInstallButton.disable();
+ testConnectionButton.setIcon(null);
+ dbExistingSchemaOption.hide();
+
+ if (registeredServerNames.size() > 1) {
+ registeredServerNames.clear();
+ registeredServerNames.put(NEW_SERVER_TO_REGISTER, MSG.tab_simpleView_serverSettings_registeredServers_newServer());
+ }
+ registeredServersSelection.setValue((String) null);
+ registeredServersSelection.setValueMap(registeredServerNames);
+ }
+
+ // for convienence, so we can get the conn url, user, pass in one object
+ private class Conn {
+ public String url() {
+ return Installer.this.dbConnectionUrl.getValueAsString();
+ }
+
+ public String username() {
+ return Installer.this.dbUsername.getValueAsString();
+ }
+
+ public String password() {
+ return Installer.this.dbPassword.getValueAsString();
+ }
+ }
}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/ServerPropertyRecordList.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/ServerPropertyRecordList.java
new file mode 100644
index 0000000..654e3cf
--- /dev/null
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/ServerPropertyRecordList.java
@@ -0,0 +1,62 @@
+package org.rhq.enterprise.gui.installer.client;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.smartgwt.client.data.Record;
+import com.smartgwt.client.data.RecordList;
+
+/**
+ * This provides a RecordList that is really a map underneath (each record is nothing more
+ * than a name/value pair; that is, each record has two attributes: name and value).
+ *
+ * We use this because this RecordList will be the list backing the Advanced View grid.
+ * So changing this list will be automatically reflected in that grid.
+ *
+ * @author John Mazzitelli
+ */
+public class ServerPropertyRecordList extends RecordList {
+
+ public static final String PROPERTY_NAME = "n";
+ public static final String PROPERTY_VALUE = "v";
+
+ // this map is kept in sync with the record list
+ private HashMap<String, String> map = new HashMap<String, String>();
+
+ public HashMap<String, String> getMap() {
+ return map;
+ }
+
+ public String getServerProperty(String name) {
+ String value = map.get(name);
+ return (value == null) ? "" : value;
+ }
+
+ public void putServerProperty(String name, String value) {
+ // fill in the internal map
+ map.put(name, value);
+
+ // now update the record list
+ Record found = find(PROPERTY_NAME, name);
+ if (found == null) {
+ Record record = new Record();
+ record.setAttribute(PROPERTY_NAME, name);
+ record.setAttribute(PROPERTY_VALUE, value);
+ add(record);
+ } else {
+ found.setAttribute(PROPERTY_VALUE, value);
+ }
+ }
+
+ public void replaceServerProperties(Map<String, String> newMap) {
+ // first update the internal map
+ map.clear();
+ map.putAll(newMap);
+
+ // now update the record list
+ setLength(0);
+ for (Map.Entry<String, String> entry : newMap.entrySet()) {
+ putServerProperty(entry.getKey(), entry.getValue());
+ }
+ }
+}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
index 2272e9c..c37d923 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
@@ -18,16 +18,43 @@
*/
package org.rhq.enterprise.gui.installer.client.gwt;
+import java.util.ArrayList;
import java.util.HashMap;
import com.google.gwt.user.client.rpc.RemoteService;
+import org.rhq.enterprise.gui.installer.client.shared.ServerDetails;
+
/**
* @author John Mazzitelli
*/
public interface InstallerGWTService extends RemoteService {
/**
+ * Returns a list of all registered servers in the database.
+ *
+ * @param connectionUrl
+ * @param username
+ * @param password
+ * @return list of all existing servers registered in the database.
+ * @throws Exception
+ */
+ ArrayList<String> getServerNames(String connectionUrl, String username, String password) throws Exception;
+
+ /**
+ * Returns details on a specific server that is registered in the database.
+ *
+ * @param connectionUrl
+ * @param username
+ * @param password
+ * @param serverName the name of the server whose details are to be retrieved
+ * @return the details of the server or null if the server does not exist
+ * @throws Exception
+ */
+ ServerDetails getServerDetails(String connectionUrl, String username, String password, String serverName)
+ throws Exception;
+
+ /**
* Tests to see if there is already a schema installed.
*
* @param connectionUrl
@@ -63,22 +90,6 @@ public interface InstallerGWTService extends RemoteService {
void saveServerProperties(HashMap<String, String> serverProperties) throws Exception;
/**
- * Creates a security domain in the app server for use by the datasources.
- * @param username username the security domain will use to connect to the database
- * @param password password the security domain will use to connect to the database
- * @throws Exception
- */
- void createDatasourceSecurityDomain(String username, String password) throws Exception;
-
- /**
- * Returns the directory name where the app server is installed (e.g. the root install directory
- * of the app server).
- * @return app server install dir
- * @throws Exception
- */
- String getAppServerHomeDir() throws Exception;
-
- /**
* Returns the version string for the app server itself (e.g. "7.1.2.Final").
* @return version string of app server
* @throws Exception
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/shared/ServerDetails.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/shared/ServerDetails.java
new file mode 100644
index 0000000..b54e380
--- /dev/null
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/shared/ServerDetails.java
@@ -0,0 +1,115 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.installer.client.shared;
+
+import java.io.Serializable;
+
+public class ServerDetails implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ public static final String DEFAULT_AFFINITY_GROUP = "";
+ public static final int DEFAULT_ENDPOINT_PORT = 7080;
+ public static final int DEFAULT_ENDPOINT_SECURE_PORT = 7443;
+
+ private String name;
+ private String endpointAddress;
+ private int endpointPort;
+ private int endpointSecurePort;
+ private String affinityGroup;
+
+ protected ServerDetails() {
+ // for GWT
+ }
+
+ public ServerDetails(String name, String endpointAddress, int port, int securePort, String affinityGroup) {
+ this.name = name;
+ this.endpointAddress = endpointAddress;
+ this.endpointPort = port;
+ this.endpointSecurePort = securePort;
+ this.affinityGroup = affinityGroup;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ if ((null != name) && (!"".equals(name.trim()))) {
+ this.name = name;
+ }
+ }
+
+ public String getEndpointAddress() {
+ return endpointAddress;
+ }
+
+ public void setEndpointAddress(String endpointAddress) {
+ if ((null != endpointAddress) && (!"".equals(endpointAddress.trim()))) {
+ this.endpointAddress = endpointAddress;
+ }
+ }
+
+ public int getEndpointPort() {
+ return endpointPort;
+ }
+
+ public void setEndpointPort(int endpointPort) {
+ this.endpointPort = endpointPort;
+ }
+
+ public String getEndpointPortString() {
+ return (String.valueOf(endpointPort));
+ }
+
+ public void setEndpointPortString(String endpointPort) {
+ this.endpointPort = Integer.valueOf(endpointPort).intValue();
+ }
+
+ public int getEndpointSecurePort() {
+ return endpointSecurePort;
+ }
+
+ public void setEndpointSecurePort(int endpointSecurePort) {
+ this.endpointSecurePort = endpointSecurePort;
+ }
+
+ public String getEndpointSecurePortString() {
+ return (String.valueOf(endpointSecurePort));
+ }
+
+ public void setEndpointSecurePortString(String endpointSecurePort) {
+ this.endpointSecurePort = Integer.valueOf(endpointSecurePort).intValue();
+ }
+
+ public String getAffinityGroup() {
+ return affinityGroup;
+ }
+
+ public void setAffinityGroup(String affinityGroup) {
+ if ((null != affinityGroup) && (!"".equals(affinityGroup.trim()))) {
+ this.affinityGroup = affinityGroup;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "[name=" + name + " address=" + endpointAddress + " port=" + endpointPort + " secureport="
+ + endpointSecurePort + " affinitygroup=" + affinityGroup + "]";
+ }
+}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
index e023bd1..6247168 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
@@ -19,6 +19,7 @@
package org.rhq.enterprise.gui.installer.server.servlet;
import java.io.File;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -34,6 +35,7 @@ import org.rhq.common.jbossas.client.controller.JBossASClient;
import org.rhq.common.jbossas.client.controller.SecurityDomainJBossASClient;
import org.rhq.core.util.PropertiesFileUpdate;
import org.rhq.enterprise.gui.installer.client.gwt.InstallerGWTService;
+import org.rhq.enterprise.gui.installer.client.shared.ServerDetails;
import org.rhq.enterprise.gui.installer.server.service.ManagementService;
/**
@@ -47,6 +49,27 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
private static final String RHQ_SECURITY_DOMAIN = "RHQDSSecurityDomain";
@Override
+ public ArrayList<String> getServerNames(String connectionUrl, String username, String password) throws Exception {
+ try {
+ return ServerInstallUtil.getServerNames(connectionUrl, username, password);
+ } catch (Exception e) {
+ log("Could not get the list of registered server names", e);
+ return null;
+ }
+ }
+
+ @Override
+ public ServerDetails getServerDetails(String connectionUrl, String username, String password, String serverName)
+ throws Exception {
+ try {
+ return ServerInstallUtil.getServerDetails(connectionUrl, username, password, serverName);
+ } catch (Exception e) {
+ log("Could not get server details for [" + serverName + "]", e);
+ return null;
+ }
+ }
+
+ @Override
public boolean isDatabaseSchemaExist(String connectionUrl, String username, String password) throws Exception {
try {
return ServerInstallUtil.isDatabaseSchemaExist(connectionUrl, username, password);
@@ -93,26 +116,6 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
}
@Override
- public void createDatasourceSecurityDomain(String username, String password) throws Exception {
- final SecurityDomainJBossASClient client = new SecurityDomainJBossASClient(getClient());
- final String securityDomain = RHQ_SECURITY_DOMAIN;
- if (!client.isSecurityDomain(securityDomain)) {
- client.createNewSecureIdentitySecurityDomainRequest(securityDomain, username, password);
- log("Security domain [" + securityDomain + "] created");
- } else {
- log("Security domain [" + securityDomain + "] already exists, skipping the creation request");
- }
- }
-
- @Override
- public String getAppServerHomeDir() throws Exception {
- JBossASClient client = new JBossASClient(getClient());
- String[] address = { "core-service", "server-environment" };
- String dir = client.getStringAttribute(true, "home-dir", Address.root().add(address));
- return dir;
- }
-
- @Override
public String getAppServerVersion() throws Exception {
JBossASClient client = new JBossASClient(getClient());
String version = client.getStringAttribute("release-version", Address.root());
@@ -127,6 +130,13 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
return osName;
}
+ private String getAppServerHomeDir() throws Exception {
+ JBossASClient client = new JBossASClient(getClient());
+ String[] address = { "core-service", "server-environment" };
+ String dir = client.getStringAttribute(true, "home-dir", Address.root().add(address));
+ return dir;
+ }
+
private File getServerPropertiesFile() throws Exception {
File appServerHomeDir = new File(getAppServerHomeDir());
File serverPropertiesFile = new File(appServerHomeDir, "../bin/rhq-server.properties");
@@ -137,4 +147,15 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
ModelControllerClient client = ManagementService.getClient();
return client;
}
+
+ private void createDatasourceSecurityDomain(String username, String password) throws Exception {
+ final SecurityDomainJBossASClient client = new SecurityDomainJBossASClient(getClient());
+ final String securityDomain = RHQ_SECURITY_DOMAIN;
+ if (!client.isSecurityDomain(securityDomain)) {
+ client.createNewSecureIdentitySecurityDomainRequest(securityDomain, username, password);
+ log("Security domain [" + securityDomain + "] created");
+ } else {
+ log("Security domain [" + securityDomain + "] already exists, skipping the creation request");
+ }
+ }
}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerDetails.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerDetails.java
deleted file mode 100644
index e81187d..0000000
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerDetails.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2012 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.installer.server.servlet;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class ServerDetails {
- private final Log LOG = LogFactory.getLog(ServerDetails.class);
-
- public static final String DEFAULT_AFFINITY_GROUP = "";
- public static final int DEFAULT_ENDPOINT_PORT = 7080;
- public static final int DEFAULT_ENDPOINT_SECURE_PORT = 7443;
-
- private String name;
- private String endpointAddress;
- private int endpointPort;
- private int endpointSecurePort;
- private String affinityGroup;
-
- public ServerDetails(String name, String endpointAddress, int port, int securePort, String affinityGroup) {
- this.name = name;
- this.endpointAddress = endpointAddress;
- this.endpointPort = port;
- this.endpointSecurePort = securePort;
- this.affinityGroup = affinityGroup;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- if ((null != name) && (!"".equals(name.trim()))) {
- this.name = name;
- }
- }
-
- public String getEndpointAddress() {
- return endpointAddress;
- }
-
- public void setEndpointAddress(String endpointAddress) {
- if ((null != endpointAddress) && (!"".equals(endpointAddress.trim()))) {
- this.endpointAddress = endpointAddress;
- }
- }
-
- public int getEndpointPort() {
- return endpointPort;
- }
-
- public void setEndpointPort(int endpointPort) {
- this.endpointPort = endpointPort;
- }
-
- public String getEndpointPortString() {
- return (String.valueOf(this.endpointPort));
- }
-
- public void setEndpointPortString(String endpointPort) {
- try {
- this.endpointPort = Integer.valueOf(endpointPort).intValue();
- } catch (NumberFormatException e) {
- LOG.debug("Failed to set port with invalid number: " + endpointPort);
- }
- }
-
- public int getEndpointSecurePort() {
- return endpointSecurePort;
- }
-
- public void setEndpointSecurePort(int endpointSecurePort) {
- this.endpointSecurePort = endpointSecurePort;
- }
-
- public String getEndpointSecurePortString() {
- return (String.valueOf(this.endpointSecurePort));
- }
-
- public void setEndpointSecurePortString(String endpointSecurePort) {
- try {
- this.endpointSecurePort = Integer.valueOf(endpointSecurePort).intValue();
- } catch (NumberFormatException e) {
- LOG.debug("Failed to set secure port with invalid number: " + endpointSecurePort);
- }
- }
-
- public String getAffinityGroup() {
- return affinityGroup;
- }
-
- public void setAffinityGroup(String affinityGroup) {
- if ((null != affinityGroup) && (!"".equals(affinityGroup.trim()))) {
- this.affinityGroup = affinityGroup;
- }
- }
-
- @Override
- public String toString() {
- return "[name=" + name + " address=" + endpointAddress + " port=" + endpointPort + " secureport="
- + endpointSecurePort + " affinitygroup=" + affinityGroup + "]";
- }
-}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java
index c3c8d89..4577789 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java
@@ -24,7 +24,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
-import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -33,6 +32,7 @@ import org.rhq.core.db.DatabaseType;
import org.rhq.core.db.DatabaseTypeFactory;
import org.rhq.core.db.DbUtil;
import org.rhq.core.util.exception.ThrowableUtil;
+import org.rhq.enterprise.gui.installer.client.shared.ServerDetails;
/**
* Provides utility methods necessary to complete the server installation.
@@ -87,12 +87,13 @@ public class ServerInstallUtil {
*
* @throws Exception if failed to communicate with the database
*/
- public List<String> getServerNames(String connectionUrl, String username, String password) throws Exception {
+ public static ArrayList<String> getServerNames(String connectionUrl, String username, String password)
+ throws Exception {
DatabaseType db = null;
Connection conn = null;
Statement stm = null;
ResultSet rs = null;
- List<String> result = new ArrayList<String>();
+ ArrayList<String> result = new ArrayList<String>();
try {
conn = getDatabaseConnection(connectionUrl, username, password);
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties b/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
index 82aeb86..5915f40 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
@@ -2,6 +2,7 @@ button_reset = Reset
button_save = Save
button_startInstallation = Press To Start The Installation Now
button_testConnection = Test Connection
+help_registeredServers = If you are performing an upgrade or a re-installation then you should select a server from this list of registered servers. If you want to install a new server into the system, select the *New Server* option. (Note that if you are going to overwrite your existing schema, you cannot select an existing registered server since they will be deleted when the overwrite is performed.)
property_name_label = Property
property_value_label = Value
schema_update_keep = Keep (Maintain Existing Data)
@@ -14,7 +15,7 @@ tab_simpleView_database = Database Settings
tab_simpleView_serverSettings = Server Settings
tab_simpleView_serverSettings_publicAddress = Server Public Address
tab_simpleView_serverSettings_registeredServers = Registered Server Names
-tab_simpleView_serverSettings_registeredServers_newServer = New Server
+tab_simpleView_serverSettings_registeredServers_newServer = *New Server*
tab_welcome = Welcome
tab_welcome_content = <h1>Welcome to the new GWT Installer</h1>\nThis is the <b>new</b> installer.\nAny HTML can go in here.
welcome_title = Installing the Server
11 years, 10 months
[rhq] Branch 'mazz/test-rhq-on-as7' - modules/enterprise
by mazz
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java | 162 +++++++++-
modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties | 7
modules/enterprise/gui/gwt-installer-war/src/main/webapp/index.html | 2
3 files changed, 156 insertions(+), 15 deletions(-)
New commits:
commit ced0c5ecbffdad1d7ee88b6262600e1e32368be8
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 19 23:39:00 2012 -0400
layout of the system settings
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
index d9fb689..12d5885 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
@@ -42,6 +42,8 @@ import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.PasswordItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
+import com.smartgwt.client.widgets.form.fields.SpacerItem;
+import com.smartgwt.client.widgets.form.fields.SpinnerItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
@@ -84,6 +86,13 @@ public class Installer implements EntryPoint {
private SelectItem dbExistingSchemaOption;
private ButtonItem testConnectionButton;
private SelectItem dbType;
+ private TextItem serverSettingServerName;
+ private TextItem serverSettingPublicAddress;
+ private SpinnerItem serverSettingWebHttpPort;
+ private SpinnerItem serverSettingWebSecureHttpPort;
+ private SelectItem registeredServersSelection;
+ private TextItem serverSettingEmailSMTPHostname;
+ private TextItem serverSettingEmailFromAddress;
public void onModuleLoad() {
Canvas header = createHeader();
@@ -143,10 +152,21 @@ public class Installer implements EntryPoint {
}
private void refreshSimpleView() {
+ // DB SETTINGS
dbType.setValue(serverProperties.get(ServerProperties.PROP_DATABASE_TYPE));
dbConnectionUrl.setValue(serverProperties.get(ServerProperties.PROP_DATABASE_CONNECTION_URL));
dbUsername.setValue(serverProperties.get(ServerProperties.PROP_DATABASE_USERNAME));
// do not prefill the database password - force the user to know it and type it in for security purposes
+
+ // SERVER SETTINGS
+ serverSettingServerName.setValue(serverProperties.get(ServerProperties.PROP_HIGH_AVAILABILITY_NAME));
+ serverSettingWebHttpPort.setValue(serverProperties.get(ServerProperties.PROP_WEB_HTTP_PORT));
+ serverSettingWebSecureHttpPort.setValue(serverProperties.get(ServerProperties.PROP_WEB_HTTPS_PORT));
+ serverSettingEmailSMTPHostname.setValue(serverProperties.get(ServerProperties.PROP_EMAIL_SMTP_HOST));
+ serverSettingEmailFromAddress.setValue(serverProperties.get(ServerProperties.PROP_EMAIL_FROM_ADDRESS));
+
+ dbExistingSchemaOption.hide();
+ testConnectionButton.setIcon(null);
}
private void refreshAdvancedView() {
@@ -203,8 +223,8 @@ public class Installer implements EntryPoint {
Label welcomeLabel = new Label(MSG.tab_welcome_content());
welcomeTab.setPane(welcomeLabel);
- final Tab databaseTab = new Tab(MSG.tab_simple());
- DynamicForm databaseForm = createSimpleForm();
+ final Tab databaseTab = new Tab(MSG.tab_simpleView());
+ Canvas databaseForm = createSimpleForm();
databaseTab.setPane(databaseForm);
final Tab advancedViewTab = new Tab(MSG.tab_advancedView());
@@ -271,6 +291,7 @@ public class Installer implements EntryPoint {
String newValue = (String) event.getNewValues().values().iterator().next().toString();
String changedProperty = event.getOldRecord().getAttribute(PROPERTY_NAME);
serverProperties.put(changedProperty, newValue);
+ refreshSimpleView();
}
});
@@ -279,13 +300,24 @@ public class Installer implements EntryPoint {
return layout;
}
- private DynamicForm createSimpleForm() {
- final DynamicForm simpleForm = new DynamicForm();
+ private Canvas createSimpleForm() {
+
+ final int fieldWidth = 250;
+
+ ////////////////////////////////////////////////////////
+ // The Database form
+
+ final DynamicForm databaseForm = new DynamicForm();
+ databaseForm.setAutoWidth();
+ databaseForm.setPadding(5);
+ databaseForm.setCellPadding(5);
+ databaseForm.setWrapItemTitles(false);
+ databaseForm.setIsGroup(true);
+ databaseForm.setGroupTitle(MSG.tab_simpleView_database());
dbConnectionUrl = new TextItem(ServerProperties.PROP_DATABASE_CONNECTION_URL,
PROPS_MSG.rhq_server_database_connection_url());
- dbConnectionUrl.setWrapTitle(false);
- dbConnectionUrl.setWidth(300);
+ dbConnectionUrl.setWidth(fieldWidth);
dbConnectionUrl.setValue("jdbc:postgresql://127.0.0.1:5432/rhq");
dbConnectionUrl.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
@@ -295,8 +327,7 @@ public class Installer implements EntryPoint {
dbUsername = new TextItem(ServerProperties.PROP_DATABASE_USERNAME,
PROPS_MSG.rhq_server_database_user_name());
- dbUsername.setWrapTitle(false);
- dbUsername.setWidth(200);
+ dbUsername.setWidth(fieldWidth);
dbUsername.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
updateServerProperty(ServerProperties.PROP_DATABASE_USERNAME, String.valueOf(event.getValue()));
@@ -305,8 +336,7 @@ public class Installer implements EntryPoint {
dbPassword = new PasswordItem(ServerProperties.PROP_DATABASE_PASSWORD,
PROPS_MSG.rhq_server_database_password());
- dbPassword.setWrapTitle(false);
- dbPassword.setWidth(200);
+ dbPassword.setWidth(fieldWidth);
dbPassword.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
updateServerProperty(ServerProperties.PROP_DATABASE_PASSWORD, String.valueOf(event.getValue()));
@@ -321,9 +351,10 @@ public class Installer implements EntryPoint {
dbExistingSchemaOption.setValueMap(schemaOpt);
dbExistingSchemaOption.setDefaultToFirstOption(true);
dbExistingSchemaOption.setVisible(false);
- dbExistingSchemaOption.setWidth(200);
+ dbExistingSchemaOption.setWidth(fieldWidth);
+ dbExistingSchemaOption.setWrapTitle(true);
- testConnectionButton = new ButtonItem("testDbConnectionButton", MSG.button_testConnection());
+ testConnectionButton = new ButtonItem("testConnectionButton", MSG.button_testConnection());
testConnectionButton.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
final String connectionUrl = dbConnectionUrl.getValueAsString();
@@ -409,9 +440,114 @@ public class Installer implements EntryPoint {
}
});
- simpleForm.setFields(dbType, dbConnectionUrl, dbUsername, dbPassword, testConnectionButton,
+ // use this to move the button over to the second column - it looks better this way
+ SpacerItem buttonSpacer = new SpacerItem();
+ buttonSpacer.setEndRow(false);
+ testConnectionButton.setStartRow(false);
+
+ databaseForm.setFields(dbType, dbConnectionUrl, dbUsername, dbPassword, buttonSpacer, testConnectionButton,
dbExistingSchemaOption);
+ ////////////////////////////////////////////////////////
+ // The Server Settings form
+
+ final DynamicForm serverSettingsForm = new DynamicForm();
+ serverSettingsForm.setPadding(5);
+ serverSettingsForm.setCellPadding(5);
+ serverSettingsForm.setAutoWidth();
+ serverSettingsForm.setIsGroup(true);
+ serverSettingsForm.setWrapItemTitles(false);
+ serverSettingsForm.setGroupTitle(MSG.tab_simpleView_serverSettings());
+
+ serverSettingServerName = new TextItem(ServerProperties.PROP_HIGH_AVAILABILITY_NAME,
+ PROPS_MSG.rhq_server_high_availability_name());
+ serverSettingServerName.setWidth(fieldWidth);
+ serverSettingServerName.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ updateServerProperty(ServerProperties.PROP_HIGH_AVAILABILITY_NAME, String.valueOf(event.getValue()));
+ }
+ });
+
+ serverSettingPublicAddress = new TextItem("serverPublicAddress",
+ MSG.tab_simpleView_serverSettings_publicAddress());
+ serverSettingPublicAddress.setWidth(fieldWidth);
+
+ serverSettingWebHttpPort = new SpinnerItem(ServerProperties.PROP_WEB_HTTP_PORT,
+ PROPS_MSG.rhq_server_startup_web_http_port());
+ serverSettingWebHttpPort.setWidth(fieldWidth);
+ serverSettingWebHttpPort.setMin(1);
+ serverSettingWebHttpPort.setMax(65535);
+ serverSettingWebHttpPort.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ updateServerProperty(ServerProperties.PROP_WEB_HTTP_PORT, String.valueOf(event.getValue()));
+ }
+ });
+
+ serverSettingWebSecureHttpPort = new SpinnerItem(ServerProperties.PROP_WEB_HTTPS_PORT,
+ PROPS_MSG.rhq_server_startup_web_http_port());
+ serverSettingWebSecureHttpPort.setWidth(fieldWidth);
+ serverSettingWebSecureHttpPort.setMin(1);
+ serverSettingWebSecureHttpPort.setMax(65535);
+ serverSettingWebSecureHttpPort.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ updateServerProperty(ServerProperties.PROP_WEB_HTTPS_PORT, String.valueOf(event.getValue()));
+ }
+ });
+
+ registeredServersSelection = new SelectItem("registeredServersSelectItem",
+ MSG.tab_simpleView_serverSettings_registeredServers());
+ final LinkedHashMap<String, String> registeredServers = new LinkedHashMap<String, String>();
+ registeredServers.put("*new*", MSG.tab_simpleView_serverSettings_registeredServers_newServer());
+ registeredServers.put("blah", "blah");
+ registeredServersSelection.setValueMap(registeredServers);
+ registeredServersSelection.setDefaultToFirstOption(true);
+ registeredServersSelection.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ String selectedServerName = String.valueOf(event.getValue());
+ boolean newServer = "*new*".equals(selectedServerName);
+ if (newServer) {
+ serverSettingServerName.setValue("");
+ serverSettingPublicAddress.setValue("");
+ } else {
+ serverSettingServerName.setValue(selectedServerName);
+ }
+ }
+ });
+
+ serverSettingEmailSMTPHostname = new TextItem(ServerProperties.PROP_EMAIL_SMTP_HOST,
+ PROPS_MSG.rhq_server_email_smtp_host());
+ serverSettingEmailSMTPHostname.setWidth(fieldWidth);
+ serverSettingEmailSMTPHostname.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ updateServerProperty(ServerProperties.PROP_EMAIL_SMTP_HOST, String.valueOf(event.getValue()));
+ }
+ });
+
+ serverSettingEmailFromAddress = new TextItem(ServerProperties.PROP_EMAIL_FROM_ADDRESS,
+ PROPS_MSG.rhq_server_email_from_address());
+ serverSettingEmailFromAddress.setWidth(fieldWidth);
+ serverSettingEmailFromAddress.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ updateServerProperty(ServerProperties.PROP_EMAIL_FROM_ADDRESS, String.valueOf(event.getValue()));
+ }
+ });
+
+ serverSettingsForm.setItems(registeredServersSelection, serverSettingServerName, serverSettingPublicAddress,
+ serverSettingWebHttpPort, serverSettingWebSecureHttpPort, serverSettingEmailSMTPHostname,
+ serverSettingEmailFromAddress);
+
+ ////////////////////////////////////////////////////////
+ // The layout holding the forms in the simple view tab
+
+ VLayout simpleForm = new VLayout();
+ simpleForm.setLayoutMargin(5);
+ simpleForm.setMembersMargin(5);
+ simpleForm.setWidth100();
+ simpleForm.setHeight100();
+ simpleForm.setDefaultLayoutAlign(Alignment.CENTER);
+ simpleForm.addMember(databaseForm);
+ simpleForm.addMember(serverSettingsForm);
+
return simpleForm;
}
}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties b/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
index e6f5fbc..82aeb86 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
@@ -9,7 +9,12 @@ schema_update_overwrite = Overwrite (Lose Existing Data!)
schema_update_question = A database schema already exists. What do you want to do?
schema_update_skip = Skip (Leave Database As-Is)
tab_advancedView = Advanced View
-tab_simple = Simple View
+tab_simpleView = Simple View
+tab_simpleView_database = Database Settings
+tab_simpleView_serverSettings = Server Settings
+tab_simpleView_serverSettings_publicAddress = Server Public Address
+tab_simpleView_serverSettings_registeredServers = Registered Server Names
+tab_simpleView_serverSettings_registeredServers_newServer = New Server
tab_welcome = Welcome
tab_welcome_content = <h1>Welcome to the new GWT Installer</h1>\nThis is the <b>new</b> installer.\nAny HTML can go in here.
welcome_title = Installing the Server
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/webapp/index.html b/modules/enterprise/gui/gwt-installer-war/src/main/webapp/index.html
index 944e61e..cb9016e 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/webapp/index.html
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/webapp/index.html
@@ -35,7 +35,7 @@
<div id="Loading-Panel" style="width: 214px; height: 90px; margin-top: 300px; margin-left: 40%; margin-right: 40%;">
<div style="text-align: center; border: 3px solid lightgray;">
- Loading RHQ Installer...
+ Loading Installer...
</div>
</div>
11 years, 10 months
[rhq] Branch 'mazz/test-rhq-on-as7' - modules/enterprise
by mazz
modules/enterprise/gui/gwt-installer-war/pom.xml | 5
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java | 200 ++++++-
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java | 57 ++
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/shared/ServerProperties.java | 53 +
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java | 42 +
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerDetails.java | 120 ++++
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java | 273 ++++++++++
modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties | 28 -
modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/ServerPropertiesMessages.properties | 23
9 files changed, 746 insertions(+), 55 deletions(-)
New commits:
commit e1dea18942517ff2d7007cedc97316cfc5d78e0f
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 19 21:15:42 2012 -0400
trying to get the database portion of the installer to work. half way there
diff --git a/modules/enterprise/gui/gwt-installer-war/pom.xml b/modules/enterprise/gui/gwt-installer-war/pom.xml
index 01a6915..3b73c6c 100644
--- a/modules/enterprise/gui/gwt-installer-war/pom.xml
+++ b/modules/enterprise/gui/gwt-installer-war/pom.xml
@@ -62,7 +62,7 @@
<dependencies>
<dependency>
<groupId>org.rhq</groupId>
- <artifactId>rhq-core-util</artifactId>
+ <artifactId>rhq-core-dbutils</artifactId>
<version>${project.version}</version>
</dependency>
@@ -189,6 +189,7 @@
<debugSuspend>false</debugSuspend>
<servicePattern>**/gwt/*GWTService.java</servicePattern>
<i18nMessagesBundle>org.rhq.enterprise.gui.installer.client.Messages</i18nMessagesBundle>
+ <i18nConstantsWithLookupBundle>org.rhq.enterprise.gui.installer.client.ServerPropertiesMessages</i18nConstantsWithLookupBundle>
<style>${gwt.style}</style>
<strict>true</strict>
<!-- compiles gwt artifacts like symbolMap outside of war so it doesnt
@@ -359,7 +360,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<includes>
- <include>org/rhq/enterprise/gui/installer/client/Messages*.java</include>
+ <include>org/rhq/enterprise/gui/installer/client/*Messages.java</include>
</includes>
</configuration>
</plugin>
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
index e45bf6d..d9fb689 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
@@ -20,6 +20,7 @@ package org.rhq.enterprise.gui.installer.client;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import com.google.gwt.core.client.EntryPoint;
@@ -38,7 +39,12 @@ import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.ButtonItem;
+import com.smartgwt.client.widgets.form.fields.PasswordItem;
+import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
+import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
+import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
@@ -50,6 +56,7 @@ import com.smartgwt.client.widgets.tab.TabSet;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
import org.rhq.enterprise.gui.installer.client.gwt.InstallerGWTServiceAsync;
+import org.rhq.enterprise.gui.installer.client.shared.ServerProperties;
/**
* The GWT {@link EntryPoint entry point} to the RHQ Installer GUI.
@@ -59,7 +66,8 @@ import org.rhq.enterprise.gui.installer.client.gwt.InstallerGWTServiceAsync;
public class Installer implements EntryPoint {
// This must come first to ensure proper I18N class loading for dev mode
- private static final Messages MSG = GWT.create(Messages.class);
+ public static final Messages MSG = GWT.create(Messages.class);
+ public static final ServerPropertiesMessages PROPS_MSG = GWT.create(ServerPropertiesMessages.class);
private static final String PROPERTY_NAME = "propertyName";
private static final String PROPERTY_VALUE = "propertyValue";
@@ -69,10 +77,17 @@ public class Installer implements EntryPoint {
private HashMap<String, String> originalProperties = new HashMap<String, String>();
private ListGrid advancedPropertyItemGrid;
+ private Button mainInstallButton;
+ private TextItem dbConnectionUrl;
+ private TextItem dbUsername;
+ private PasswordItem dbPassword;
+ private SelectItem dbExistingSchemaOption;
+ private ButtonItem testConnectionButton;
+ private SelectItem dbType;
public void onModuleLoad() {
Canvas header = createHeader();
- Canvas installButton = createMainInstallButton();
+ mainInstallButton = createMainInstallButton();
Canvas tabSet = createTabSet();
VLayout layout = new VLayout();
@@ -82,7 +97,7 @@ public class Installer implements EntryPoint {
layout.setMembersMargin(5);
layout.setDefaultLayoutAlign(Alignment.CENTER);
layout.addMember(header);
- layout.addMember(installButton);
+ layout.addMember(mainInstallButton);
layout.addMember(tabSet);
layout.draw();
@@ -95,6 +110,11 @@ public class Installer implements EntryPoint {
}
+ private void updateServerProperty(String name, Object value) {
+ serverProperties.put(name, value == null ? "" : value.toString());
+ refreshAdvancedView();
+ }
+
private void loadServerProperties() {
// load the initial server properties
installerService.getServerProperties(new AsyncCallback<HashMap<String, String>>() {
@@ -109,6 +129,9 @@ public class Installer implements EntryPoint {
originalProperties.clear();
originalProperties.putAll(result);
+ // refresh the simple view with the new data
+ refreshSimpleView();
+
// refresh the advanced view with the new data
refreshAdvancedView();
}
@@ -119,6 +142,13 @@ public class Installer implements EntryPoint {
});
}
+ private void refreshSimpleView() {
+ dbType.setValue(serverProperties.get(ServerProperties.PROP_DATABASE_TYPE));
+ dbConnectionUrl.setValue(serverProperties.get(ServerProperties.PROP_DATABASE_CONNECTION_URL));
+ dbUsername.setValue(serverProperties.get(ServerProperties.PROP_DATABASE_USERNAME));
+ // do not prefill the database password - force the user to know it and type it in for security purposes
+ }
+
private void refreshAdvancedView() {
ArrayList<ListGridRecord> records = new ArrayList<ListGridRecord>();
for (Map.Entry<String, String> entry : serverProperties.entrySet()) {
@@ -148,10 +178,11 @@ public class Installer implements EntryPoint {
return strip;
}
- private Canvas createMainInstallButton() {
- Button installButton = new Button(MSG.start_installation_label());
+ private Button createMainInstallButton() {
+ Button installButton = new Button(MSG.button_startInstallation());
installButton.setWrap(false);
installButton.setAutoFit(true);
+ installButton.setDisabled(true); // we can't allow the user to install yet
installButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
SC.say("TODO: this should start the install");
@@ -172,21 +203,16 @@ public class Installer implements EntryPoint {
Label welcomeLabel = new Label(MSG.tab_welcome_content());
welcomeTab.setPane(welcomeLabel);
- final Tab databaseTab = new Tab(MSG.tab_database());
- DynamicForm databaseForm = createDatabaseForm();
+ final Tab databaseTab = new Tab(MSG.tab_simple());
+ DynamicForm databaseForm = createSimpleForm();
databaseTab.setPane(databaseForm);
- final Tab systemSettingsTab = new Tab(MSG.tab_systemSettings());
- DynamicForm systemSettingsForm = createSystemSettingsForm();
- systemSettingsTab.setPane(systemSettingsForm);
-
final Tab advancedViewTab = new Tab(MSG.tab_advancedView());
Canvas advancedView = createAdvancedView();
advancedViewTab.setPane(advancedView);
topTabSet.addTab(welcomeTab);
topTabSet.addTab(databaseTab);
- topTabSet.addTab(systemSettingsTab);
topTabSet.addTab(advancedViewTab);
return topTabSet;
@@ -198,7 +224,7 @@ public class Installer implements EntryPoint {
ToolStrip strip = new ToolStrip();
strip.setWidth100();
- IButton saveButton = new IButton(MSG.save_label());
+ IButton saveButton = new IButton(MSG.button_save());
saveButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
installerService.saveServerProperties(serverProperties, new AsyncCallback<Void>() {
@@ -214,7 +240,7 @@ public class Installer implements EntryPoint {
});
}
});
- IButton resetButton = new IButton(MSG.reset_label());
+ IButton resetButton = new IButton(MSG.button_reset());
resetButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
serverProperties.clear();
@@ -253,19 +279,139 @@ public class Installer implements EntryPoint {
return layout;
}
- private DynamicForm createSystemSettingsForm() {
- DynamicForm systemSettingsForm = new DynamicForm();
- TextItem nameTextItem = new TextItem();
- nameTextItem.setTitle("Your Name");
- systemSettingsForm.setFields(nameTextItem);
- return systemSettingsForm;
- }
+ private DynamicForm createSimpleForm() {
+ final DynamicForm simpleForm = new DynamicForm();
+
+ dbConnectionUrl = new TextItem(ServerProperties.PROP_DATABASE_CONNECTION_URL,
+ PROPS_MSG.rhq_server_database_connection_url());
+ dbConnectionUrl.setWrapTitle(false);
+ dbConnectionUrl.setWidth(300);
+ dbConnectionUrl.setValue("jdbc:postgresql://127.0.0.1:5432/rhq");
+ dbConnectionUrl.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ updateServerProperty(ServerProperties.PROP_DATABASE_CONNECTION_URL, String.valueOf(event.getValue()));
+ }
+ });
+
+ dbUsername = new TextItem(ServerProperties.PROP_DATABASE_USERNAME,
+ PROPS_MSG.rhq_server_database_user_name());
+ dbUsername.setWrapTitle(false);
+ dbUsername.setWidth(200);
+ dbUsername.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ updateServerProperty(ServerProperties.PROP_DATABASE_USERNAME, String.valueOf(event.getValue()));
+ }
+ });
+
+ dbPassword = new PasswordItem(ServerProperties.PROP_DATABASE_PASSWORD,
+ PROPS_MSG.rhq_server_database_password());
+ dbPassword.setWrapTitle(false);
+ dbPassword.setWidth(200);
+ dbPassword.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ updateServerProperty(ServerProperties.PROP_DATABASE_PASSWORD, String.valueOf(event.getValue()));
+ }
+ });
+
+ dbExistingSchemaOption = new SelectItem("existingSchemaOption", MSG.schema_update_question());
+ final LinkedHashMap<String, String> schemaOpt = new LinkedHashMap<String, String>();
+ schemaOpt.put("keep", MSG.schema_update_keep());
+ schemaOpt.put("overwrite", MSG.schema_update_overwrite());
+ schemaOpt.put("skip", MSG.schema_update_skip());
+ dbExistingSchemaOption.setValueMap(schemaOpt);
+ dbExistingSchemaOption.setDefaultToFirstOption(true);
+ dbExistingSchemaOption.setVisible(false);
+ dbExistingSchemaOption.setWidth(200);
+
+ testConnectionButton = new ButtonItem("testDbConnectionButton", MSG.button_testConnection());
+ testConnectionButton.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
+ public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
+ final String connectionUrl = dbConnectionUrl.getValueAsString();
+ final String username = dbUsername.getValueAsString();
+ final String password = dbPassword.getValueAsString();
+
+ installerService.testConnection(connectionUrl, username, password, new AsyncCallback<String>() {
+ public void onSuccess(String result) {
+ if (result != null) {
+ SC.say("Could not connect to the database: " + result);
+ testConnectionButton.setIcon("[SKIN]/actions/exclamation.png");
+ mainInstallButton.disable();
+ dbExistingSchemaOption.hide();
+ } else {
+ testConnectionButton.setIcon("[SKIN]/actions/ok.png");
+ installerService.isDatabaseSchemaExist(connectionUrl, username, password,
+ new AsyncCallback<Boolean>() {
+ public void onSuccess(Boolean schemaExists) {
+ if (schemaExists) {
+ dbExistingSchemaOption.show();
+ } else {
+ dbExistingSchemaOption.hide();
+ }
+ mainInstallButton.enable();
+ }
+
+ public void onFailure(Throwable caught) {
+ SC.say("Cannot determine the status of the database schema: " + caught);
+ }
+ });
+ }
+ }
+
+ public void onFailure(Throwable caught) {
+ SC.say("Failed to test connection: " + caught.toString());
+ testConnectionButton.setIcon("[SKIN]/actions/exclamation.png");
+ mainInstallButton.disable();
+ dbExistingSchemaOption.hide();
+ }
+ });
+
+ }
+ });
+
+ dbType = new SelectItem(ServerProperties.PROP_DATABASE_TYPE,
+ PROPS_MSG.rhq_server_database_type_mapping());
+ final LinkedHashMap<String, String> dbs = new LinkedHashMap<String, String>();
+ dbs.put("PostgreSQL", "PostgreSQL");
+ dbs.put("Oracle", "Oracle");
+ dbType.setValueMap(dbs);
+ dbType.setDefaultToFirstOption(true);
+ dbType.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ // force the user to re-test the connection
+ mainInstallButton.disable();
+ testConnectionButton.setIcon(null);
+ dbExistingSchemaOption.setVisible(false);
+
+ String newDBType = (String) event.getValue();
+ String newURL = "";
+ String dialect = "";
+ String quartzDriverDelegateClass = "org.quartz.impl.jdbcjobstore.StdJDBCDelegate";
+ String quartzSelectWithLockSQL = "SELECT * FROM {0}LOCKS ROWLOCK WHERE LOCK_NAME = ? FOR UPDATE";
+ String quartzLockHandlerClass = "org.quartz.impl.jdbcjobstore.StdRowLockSemaphore";
+
+ if ("PostgreSQL".equalsIgnoreCase(newDBType)) {
+ newURL = "jdbc:postgresql://127.0.0.1:5432/rhq";
+ dialect = "org.hibernate.dialect.PostgreSQLDialect";
+ quartzDriverDelegateClass = "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate";
+ } else if ("Oracle".equalsIgnoreCase(newDBType)) {
+ newURL = "jdbc:oracle:thin:@127.0.0.1:1521:rhq";
+ dialect = "org.hibernate.dialect.Oracle10gDialect";
+ quartzDriverDelegateClass = "org.quartz.impl.jdbcjobstore.oracle.OracleDelegate";
+ }
+ dbConnectionUrl.setValue(newURL);
+
+ serverProperties.put(ServerProperties.PROP_DATABASE_CONNECTION_URL, newURL);
+ serverProperties.put(ServerProperties.PROP_DATABASE_HIBERNATE_DIALECT, dialect);
+ serverProperties.put(ServerProperties.PROP_QUARTZ_DRIVER_DELEGATE_CLASS, quartzDriverDelegateClass);
+ serverProperties.put(ServerProperties.PROP_QUARTZ_SELECT_WITH_LOCK_SQL, quartzSelectWithLockSQL);
+ serverProperties.put(ServerProperties.PROP_QUARTZ_LOCK_HANDLER_CLASS, quartzLockHandlerClass);
+ updateServerProperty(ServerProperties.PROP_DATABASE_TYPE, newDBType); // this refreshes the advanced view, too
+ }
+ });
+
+ simpleForm.setFields(dbType, dbConnectionUrl, dbUsername, dbPassword, testConnectionButton,
+ dbExistingSchemaOption);
- private DynamicForm createDatabaseForm() {
- DynamicForm databaseForm = new DynamicForm();
- TextItem dbUsernameTextItem = new TextItem();
- dbUsernameTextItem.setTitle("Database User");
- databaseForm.setFields(dbUsernameTextItem);
- return databaseForm;
+ return simpleForm;
}
}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
index 0184c77..2272e9c 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
@@ -27,15 +27,68 @@ import com.google.gwt.user.client.rpc.RemoteService;
*/
public interface InstallerGWTService extends RemoteService {
+ /**
+ * Tests to see if there is already a schema installed.
+ *
+ * @param connectionUrl
+ * @param username
+ * @param password
+ * @return <code>true</code> if there appears to be a schema installed in the database already.
+ * @throws Exception
+ */
+ boolean isDatabaseSchemaExist(String connectionUrl, String username, String password) throws Exception;
+
+ /**
+ * Tests that the database can be connected to with the given URL and credentials.
+ * @param connectionUrl
+ * @param username
+ * @param password
+ * @return <code>null</code> if the connection succeeded; this will be an error message if failed
+ * @throws Exception
+ */
+ String testConnection(String connectionUrl, String username, String password) throws Exception;
+
+ /**
+ * Returns the rhq-server.properties values in a map.
+ * @return server properties
+ * @throws Exception
+ */
HashMap<String, String> getServerProperties() throws Exception;
+ /**
+ * Saves the rhq-server.properties with the given values.
+ * @param serverProperties
+ * @throws Exception
+ */
void saveServerProperties(HashMap<String, String> serverProperties) throws Exception;
+ /**
+ * Creates a security domain in the app server for use by the datasources.
+ * @param username username the security domain will use to connect to the database
+ * @param password password the security domain will use to connect to the database
+ * @throws Exception
+ */
void createDatasourceSecurityDomain(String username, String password) throws Exception;
- String getAppServerVersion() throws Exception;
-
+ /**
+ * Returns the directory name where the app server is installed (e.g. the root install directory
+ * of the app server).
+ * @return app server install dir
+ * @throws Exception
+ */
String getAppServerHomeDir() throws Exception;
+ /**
+ * Returns the version string for the app server itself (e.g. "7.1.2.Final").
+ * @return version string of app server
+ * @throws Exception
+ */
+ String getAppServerVersion() throws Exception;
+
+ /**
+ * Returns the general type of operating system the server is running on (e.g. "Linux").
+ * @return os type name
+ * @throws Exception
+ */
String getOperatingSystem() throws Exception;
}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/shared/ServerProperties.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/shared/ServerProperties.java
new file mode 100644
index 0000000..d92d4ce
--- /dev/null
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/shared/ServerProperties.java
@@ -0,0 +1,53 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 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.installer.client.shared;
+
+/**
+ * Settings found in the rhq-server.properties file that controls the startup configuration of the server.
+ *
+ * @author John Mazzitelli
+ */
+public class ServerProperties {
+ public static final String PREFIX_PROP_DATABASE = "rhq.server.database.";
+ public static final String PROP_DATABASE_TYPE = PREFIX_PROP_DATABASE + "type-mapping";
+ public static final String PROP_DATABASE_CONNECTION_URL = PREFIX_PROP_DATABASE + "connection-url";
+ public static final String PROP_DATABASE_USERNAME = PREFIX_PROP_DATABASE + "user-name";
+ public static final String PROP_DATABASE_PASSWORD = PREFIX_PROP_DATABASE + "password";
+ public static final String PROP_DATABASE_SERVER_NAME = PREFIX_PROP_DATABASE + "server-name";
+ public static final String PROP_DATABASE_PORT = PREFIX_PROP_DATABASE + "port";
+ public static final String PROP_DATABASE_DB_NAME = PREFIX_PROP_DATABASE + "db-name";
+ public static final String PROP_DATABASE_HIBERNATE_DIALECT = "hibernate.dialect";
+ public static final String PROP_QUARTZ_DRIVER_DELEGATE_CLASS = "rhq.server.quartz.driverDelegateClass";
+ public static final String PROP_QUARTZ_SELECT_WITH_LOCK_SQL = "rhq.server.quartz.selectWithLockSQL";
+ public static final String PROP_QUARTZ_LOCK_HANDLER_CLASS = "rhq.server.quartz.lockHandlerClass";
+
+ public static final String PREFIX_PROP_WEB = "rhq.server.startup.web.";
+ public static final String PROP_WEB_HTTP_PORT = PREFIX_PROP_WEB + "http.port";
+ public static final String PROP_WEB_HTTPS_PORT = PREFIX_PROP_WEB + "https.port";
+
+ public static final String PREFIX_PROP_EMBEDDED_AGENT = "rhq.server.embedded-agent.";
+ public static final String PROP_EMBEDDED_AGENT_ENABLED = PREFIX_PROP_EMBEDDED_AGENT + "enabled";
+
+ public static final String PREFIX_PROP_EMAIL = "rhq.server.email.";
+ public static final String PROP_EMAIL_SMTP_HOST = PREFIX_PROP_EMAIL + "smtp-host";
+ public static final String PROP_EMAIL_FROM_ADDRESS = PREFIX_PROP_EMAIL + "from-address";
+
+ public static final String PROP_HIGH_AVAILABILITY_NAME = "rhq.server.high-availability.name";
+ public static final String PROP_MM_AT_START = "rhq.server.maintenance-mode-at-startup";
+}
\ No newline at end of file
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
index 3890e1b..e023bd1 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
@@ -47,9 +47,24 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
private static final String RHQ_SECURITY_DOMAIN = "RHQDSSecurityDomain";
@Override
+ public boolean isDatabaseSchemaExist(String connectionUrl, String username, String password) throws Exception {
+ try {
+ return ServerInstallUtil.isDatabaseSchemaExist(connectionUrl, username, password);
+ } catch (Exception e) {
+ log("Could not determine database existence", e);
+ return false;
+ }
+ }
+
+ @Override
+ public String testConnection(String connectionUrl, String username, String password) throws Exception {
+ String results = ServerInstallUtil.testConnection(connectionUrl, username, password);
+ return results;
+ }
+
+ @Override
public HashMap<String, String> getServerProperties() throws Exception {
- File appServerHomeDir = new File(getAppServerHomeDir());
- File serverPropertiesFile = new File(appServerHomeDir, "../bin/rhq-server.properties");
+ File serverPropertiesFile = getServerPropertiesFile();
PropertiesFileUpdate propsFile = new PropertiesFileUpdate(serverPropertiesFile.getAbsolutePath());
Properties props = propsFile.loadExistingProperties();
@@ -63,8 +78,7 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
@Override
public void saveServerProperties(HashMap<String, String> serverProperties) throws Exception {
- File appServerHomeDir = new File(getAppServerHomeDir());
- File serverPropertiesFile = new File(appServerHomeDir, "../bin/rhq-server.properties");
+ File serverPropertiesFile = getServerPropertiesFile();
PropertiesFileUpdate propsFile = new PropertiesFileUpdate(serverPropertiesFile.getAbsolutePath());
// GWT can't handle Properties - convert from HashMap
@@ -91,13 +105,6 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
}
@Override
- public String getAppServerVersion() throws Exception {
- JBossASClient client = new JBossASClient(getClient());
- String version = client.getStringAttribute("release-version", Address.root());
- return version;
- }
-
- @Override
public String getAppServerHomeDir() throws Exception {
JBossASClient client = new JBossASClient(getClient());
String[] address = { "core-service", "server-environment" };
@@ -106,6 +113,13 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
}
@Override
+ public String getAppServerVersion() throws Exception {
+ JBossASClient client = new JBossASClient(getClient());
+ String version = client.getStringAttribute("release-version", Address.root());
+ return version;
+ }
+
+ @Override
public String getOperatingSystem() throws Exception {
JBossASClient client = new JBossASClient(getClient());
String[] address = { "core-service", "platform-mbean", "type", "operating-system" };
@@ -113,6 +127,12 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
return osName;
}
+ private File getServerPropertiesFile() throws Exception {
+ File appServerHomeDir = new File(getAppServerHomeDir());
+ File serverPropertiesFile = new File(appServerHomeDir, "../bin/rhq-server.properties");
+ return serverPropertiesFile;
+ }
+
private ModelControllerClient getClient() {
ModelControllerClient client = ManagementService.getClient();
return client;
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerDetails.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerDetails.java
new file mode 100644
index 0000000..e81187d
--- /dev/null
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerDetails.java
@@ -0,0 +1,120 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.installer.server.servlet;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ServerDetails {
+ private final Log LOG = LogFactory.getLog(ServerDetails.class);
+
+ public static final String DEFAULT_AFFINITY_GROUP = "";
+ public static final int DEFAULT_ENDPOINT_PORT = 7080;
+ public static final int DEFAULT_ENDPOINT_SECURE_PORT = 7443;
+
+ private String name;
+ private String endpointAddress;
+ private int endpointPort;
+ private int endpointSecurePort;
+ private String affinityGroup;
+
+ public ServerDetails(String name, String endpointAddress, int port, int securePort, String affinityGroup) {
+ this.name = name;
+ this.endpointAddress = endpointAddress;
+ this.endpointPort = port;
+ this.endpointSecurePort = securePort;
+ this.affinityGroup = affinityGroup;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ if ((null != name) && (!"".equals(name.trim()))) {
+ this.name = name;
+ }
+ }
+
+ public String getEndpointAddress() {
+ return endpointAddress;
+ }
+
+ public void setEndpointAddress(String endpointAddress) {
+ if ((null != endpointAddress) && (!"".equals(endpointAddress.trim()))) {
+ this.endpointAddress = endpointAddress;
+ }
+ }
+
+ public int getEndpointPort() {
+ return endpointPort;
+ }
+
+ public void setEndpointPort(int endpointPort) {
+ this.endpointPort = endpointPort;
+ }
+
+ public String getEndpointPortString() {
+ return (String.valueOf(this.endpointPort));
+ }
+
+ public void setEndpointPortString(String endpointPort) {
+ try {
+ this.endpointPort = Integer.valueOf(endpointPort).intValue();
+ } catch (NumberFormatException e) {
+ LOG.debug("Failed to set port with invalid number: " + endpointPort);
+ }
+ }
+
+ public int getEndpointSecurePort() {
+ return endpointSecurePort;
+ }
+
+ public void setEndpointSecurePort(int endpointSecurePort) {
+ this.endpointSecurePort = endpointSecurePort;
+ }
+
+ public String getEndpointSecurePortString() {
+ return (String.valueOf(this.endpointSecurePort));
+ }
+
+ public void setEndpointSecurePortString(String endpointSecurePort) {
+ try {
+ this.endpointSecurePort = Integer.valueOf(endpointSecurePort).intValue();
+ } catch (NumberFormatException e) {
+ LOG.debug("Failed to set secure port with invalid number: " + endpointSecurePort);
+ }
+ }
+
+ public String getAffinityGroup() {
+ return affinityGroup;
+ }
+
+ public void setAffinityGroup(String affinityGroup) {
+ if ((null != affinityGroup) && (!"".equals(affinityGroup.trim()))) {
+ this.affinityGroup = affinityGroup;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "[name=" + name + " address=" + endpointAddress + " port=" + endpointPort + " secureport="
+ + endpointSecurePort + " affinitygroup=" + affinityGroup + "]";
+ }
+}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java
new file mode 100644
index 0000000..c3c8d89
--- /dev/null
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/ServerInstallUtil.java
@@ -0,0 +1,273 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.installer.server.servlet;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.rhq.core.db.DatabaseType;
+import org.rhq.core.db.DatabaseTypeFactory;
+import org.rhq.core.db.DbUtil;
+import org.rhq.core.util.exception.ThrowableUtil;
+
+/**
+ * Provides utility methods necessary to complete the server installation.
+ *
+ * @author John Mazzitelli
+ */
+public class ServerInstallUtil {
+ private static final Log LOG = LogFactory.getLog(ServerInstallUtil.class);
+
+ public enum ExistingSchemaOption {
+ OVERWRITE, KEEP, SKIP
+ };
+
+ public static boolean isKeepExistingSchema(ExistingSchemaOption existingSchemaOption) {
+ return ExistingSchemaOption.KEEP.name().equals(existingSchemaOption)
+ || ExistingSchemaOption.SKIP.name().equals(existingSchemaOption);
+ }
+
+ /**
+ * Returns <code>true</code> if the database already has the database schema created for it. It will not be known
+ * what version of schema or if its the latest, all this method tells you is that some RHQ database schema exists.
+ *
+ * @param connectionUrl
+ * @param username
+ * @param password
+ * @return <code>true</code> if the database can be connected to
+ *
+ * @throws Exception if failed to communicate with the database
+ */
+ public static boolean isDatabaseSchemaExist(String connectionUrl, String username, String password)
+ throws Exception {
+
+ Connection conn = getDatabaseConnection(connectionUrl, username, password);
+ DatabaseType db = DatabaseTypeFactory.getDatabaseType(conn);
+
+ try {
+ return db.checkTableExists(conn, "RHQ_PRINCIPAL");
+ } catch (IllegalStateException e) {
+ return false;
+ } finally {
+ db.closeConnection(conn);
+ }
+ }
+
+ /**
+ * Get the list of existing servers from an existing schema.
+ *
+ * @param connectionUrl
+ * @param username
+ * @param password
+ * @return List of server names registered in the database. Empty list if the table does not exist or there are no entries in the table.
+ *
+ * @throws Exception if failed to communicate with the database
+ */
+ public List<String> getServerNames(String connectionUrl, String username, String password) throws Exception {
+ DatabaseType db = null;
+ Connection conn = null;
+ Statement stm = null;
+ ResultSet rs = null;
+ List<String> result = new ArrayList<String>();
+
+ try {
+ conn = getDatabaseConnection(connectionUrl, username, password);
+ db = DatabaseTypeFactory.getDatabaseType(conn);
+
+ if (db.checkTableExists(conn, "rhq_server")) {
+
+ stm = conn.createStatement();
+ rs = stm.executeQuery("SELECT name FROM rhq_server ORDER BY name asc");
+
+ while (rs.next()) {
+ result.add(rs.getString(1));
+ }
+ }
+ } catch (IllegalStateException e) {
+ // table does not exist
+ } catch (SQLException e) {
+ LOG.info("Unable to fetch existing server info: " + e.getMessage());
+ } finally {
+ if (null != db) {
+ db.closeJDBCObjects(conn, stm, rs);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns information on the server as found in the database (port numbers, affinity group, etc).
+ *
+ * @param connectionUrl
+ * @param username
+ * @param password
+ * @param serverName the server whose details are to be returned
+ * @return the information on the named server
+ */
+ public static ServerDetails getServerDetails(String connectionUrl, String username, String password,
+ String serverName) {
+
+ DatabaseType db = null;
+ Connection conn = null;
+ ServerDetails result = null;
+
+ try {
+ conn = getDatabaseConnection(connectionUrl, username, password);
+ db = DatabaseTypeFactory.getDatabaseType(conn);
+
+ result = getServerDetails(db, conn, serverName);
+
+ } catch (Exception e) {
+ LOG.info("Unable to get server detail: " + e.getMessage());
+ } finally {
+ if (null != db) {
+ db.closeConnection(conn);
+ }
+ }
+
+ return result;
+ }
+
+ private static ServerDetails getServerDetails(DatabaseType db, Connection conn, String serverName) {
+ PreparedStatement stm = null;
+ ResultSet rs = null;
+ ServerDetails result = null;
+
+ if (null == serverName) {
+ return result;
+ }
+
+ try {
+ stm = conn.prepareStatement("" //
+ + "SELECT s.address, s.port, s.secure_port, ag.name " //
+ + " FROM rhq_server s LEFT JOIN rhq_affinity_group ag ON ag.id = s.affinity_group_id " //
+ + " WHERE s.name = ?");
+ stm.setString(1, serverName.trim());
+
+ rs = stm.executeQuery();
+
+ if (rs.next()) {
+ result = new ServerDetails(serverName, rs.getString(1), rs.getInt(2), rs.getInt(3), rs.getString(4));
+ }
+
+ } catch (SQLException e) {
+ LOG.info("Unable to get affinity group name for server: " + e.getMessage());
+ } finally {
+ if (null != db) {
+ db.closeResultSet(rs);
+ db.closeStatement(stm);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Tests to make sure the server can be connected to with the given settings.
+ * If the test is successful, <code>null</code>. If the test fails, the returned string
+ * will be the error message to indicate the problem.
+ *
+ * @param connectionUrl
+ * @param username
+ * @param password
+ * @return error message if test failed; <code>null</code> if test succeeded
+ */
+ public static String testConnection(String connectionUrl, String username, String password) {
+
+ // its possible the JDBC URL was changed, clear the factory cache in case the DB version is different now
+ DatabaseTypeFactory.clearDatabaseTypeCache();
+
+ try {
+ ensureDatabaseIsSupported(connectionUrl, username, password);
+ return null;
+ } catch (Exception e) {
+ LOG.warn("Installer failed to test connection", e);
+ return ThrowableUtil.getAllMessages(e);
+ }
+ }
+
+ /**
+ * Call this when you need to confirm that the database is supported.
+ *
+ * @param connectionUrl
+ * @param username
+ * @param password
+ *
+ * @throws Exception if the database is not supported
+ */
+ public static void ensureDatabaseIsSupported(String connectionUrl, String username, String password)
+ throws Exception {
+ Connection conn = null;
+ DatabaseType db = null;
+
+ try {
+ conn = getDatabaseConnection(connectionUrl, username, password);
+ db = DatabaseTypeFactory.getDatabaseType(conn);
+
+ String version = db.getVersion();
+
+ if (DatabaseTypeFactory.isPostgres(db)) {
+ if (version.startsWith("7") || version.equals("8") || version.startsWith("8.0")
+ || version.startsWith("8.1")) {
+ throw new Exception("Unsupported PostgreSQL [" + db + "]");
+ }
+ } else if (DatabaseTypeFactory.isOracle(db)) {
+ if (version.startsWith("8") || version.startsWith("9")) {
+ throw new Exception("Unsupported Oracle [" + db + "]");
+ }
+ } else {
+ throw new Exception("Unsupported DB [" + db + "]");
+ }
+
+ LOG.info("Database is supported: " + db);
+ } finally {
+ if (db != null) {
+ db.closeConnection(conn);
+ }
+ }
+
+ return;
+ }
+
+ /**
+ * Returns a database connection with the given set of properties providing the settings that allow for a successful
+ * database connection. If <code>props</code> is <code>null</code>, it will use the server properties from
+ * {@link #getServerProperties()}.
+ *
+ * @param connectionUrl
+ * @param userName
+ * @param password
+ * @return the database connection
+ *
+ * @throws SQLException if cannot successfully connect to the database
+ */
+ public static Connection getDatabaseConnection(String connectionUrl, String userName, String password)
+ throws SQLException {
+ return DbUtil.getConnection(connectionUrl, userName, password);
+ }
+}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties b/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
index 2a99074..e6f5fbc 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
@@ -1,13 +1,15 @@
-welcome.title=Installing the Server
-tab.welcome.content=<h1>Welcome to the new GWT Installer</h1>\n\
-This is the <b>new</b> installer.\n\
-Any HTML can go in here.
-tab.welcome=Welcome
-tab.database=Database
-tab.systemSettings=System Settings
-tab.advancedView=Advanced View
-property.name.label=Property
-property.value.label=Value
-save.label=Save
-reset.label=Reset
-start.installation.label=Press To Start The Installation Now
\ No newline at end of file
+button_reset = Reset
+button_save = Save
+button_startInstallation = Press To Start The Installation Now
+button_testConnection = Test Connection
+property_name_label = Property
+property_value_label = Value
+schema_update_keep = Keep (Maintain Existing Data)
+schema_update_overwrite = Overwrite (Lose Existing Data!)
+schema_update_question = A database schema already exists. What do you want to do?
+schema_update_skip = Skip (Leave Database As-Is)
+tab_advancedView = Advanced View
+tab_simple = Simple View
+tab_welcome = Welcome
+tab_welcome_content = <h1>Welcome to the new GWT Installer</h1>\nThis is the <b>new</b> installer.\nAny HTML can go in here.
+welcome_title = Installing the Server
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/ServerPropertiesMessages.properties b/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/ServerPropertiesMessages.properties
new file mode 100644
index 0000000..6c53445
--- /dev/null
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/ServerPropertiesMessages.properties
@@ -0,0 +1,23 @@
+### RHQ Server Configuration Properties
+### These should match the actual property names in rhq-server.properties.
+
+# Database
+rhq.server.database.connection-url=Database Connection URL
+rhq.server.database.user-name=Database Username
+rhq.server.database.password=Database Password
+rhq.server.database.type-mapping=Database Type
+
+# High Availability (HA)
+rhq.server.high-availability.name=Server Name
+rhq.server.maintenance-mode-at-startup=Maintenance Mode At Startup
+
+# General Properties
+rhq.server.startup.web.http.port=HTTP Port
+rhq.server.startup.web.https.port=Secure HTTP Port
+
+# Embedded RHQ Agent
+rhq.server.embedded-agent.enabled=Embedded Agent Enabled
+
+# Email
+rhq.server.email.smtp-host=Email SMTP Host
+rhq.server.email.from-address=Email From Address
\ No newline at end of file
11 years, 10 months
[rhq] Branch 'mazz/test-rhq-on-as7' - modules/enterprise
by mazz
modules/enterprise/gui/gwt-installer-war/pom.xml | 6
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java | 31 ++
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java | 146 +++++++++-
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java | 8
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java | 46 +++
modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties | 8
6 files changed, 242 insertions(+), 3 deletions(-)
New commits:
commit e0ac8b3964c0cb15cc05c9c390e56a22a208f141
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Jul 18 21:51:41 2012 -0400
It's happening again - I'm building out an installer with no one from UXD
walking me away from the ledge.
Oh well, here's more of the new installer prototype.
I'm sure it will be the foundation of the new installer and people will
hate its UI design. At least it doesn't have a red background.
diff --git a/modules/enterprise/gui/gwt-installer-war/pom.xml b/modules/enterprise/gui/gwt-installer-war/pom.xml
index e32bc78..01a6915 100644
--- a/modules/enterprise/gui/gwt-installer-war/pom.xml
+++ b/modules/enterprise/gui/gwt-installer-war/pom.xml
@@ -61,6 +61,12 @@
<dependencies>
<dependency>
+ <groupId>org.rhq</groupId>
+ <artifactId>rhq-core-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwt.version}</version>
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java
index 20ca4db..c8d040c 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java
@@ -73,7 +73,21 @@ public class JBossASClient {
* @return the request
*/
public static ModelNode createReadAttributeRequest(String attributeName, Address address) {
+ return createReadAttributeRequest(false, attributeName, address);
+ }
+
+ /**
+ * Convienence method that allows you to create request that reads a single attribute
+ * value to a resource.
+ *
+ * @param runtime if <code>true</code>, the attribute is a runtime attribute
+ * @param attributeName the name of the attribute whose value is to be read
+ * @param address identifies the resource
+ * @return the request
+ */
+ public static ModelNode createReadAttributeRequest(boolean runtime, String attributeName, Address address) {
ModelNode op = createRequest(READ_ATTRIBUTE, address);
+ op.get("include-runtime").set(runtime);
op.get(NAME).set(attributeName);
return op;
}
@@ -261,7 +275,22 @@ public class JBossASClient {
* @throws Exception if failed to obtain the attribute value
*/
public String getStringAttribute(String attributeName, Address address) throws Exception {
- ModelNode op = createReadAttributeRequest(attributeName, address);
+ return getStringAttribute(false, attributeName, address);
+ }
+
+ /**
+ * Convienence method that allows you to obtain a single attribute's string value from
+ * a resource.
+ *
+ * @param runtime if <code>true</code>, the attribute to be retrieved is a runtime attribute
+ * @param attributeName the attribute whose value is to be returned
+ * @param address identifies the resource
+ * @return the attribute value
+ *
+ * @throws Exception if failed to obtain the attribute value
+ */
+ public String getStringAttribute(boolean runtime, String attributeName, Address address) throws Exception {
+ ModelNode op = createReadAttributeRequest(runtime, attributeName, address);
ModelNode results = execute(op);
if (isSuccess(results)) {
ModelNode version = getResults(results);
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
index c267d22..e45bf6d 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
@@ -18,17 +18,32 @@
*/
package org.rhq.enterprise.gui.installer.client;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Side;
import com.smartgwt.client.types.VerticalAlignment;
+import com.smartgwt.client.util.SC;
+import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.TextItem;
+import com.smartgwt.client.widgets.grid.ListGrid;
+import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+import com.smartgwt.client.widgets.grid.events.EditCompleteEvent;
+import com.smartgwt.client.widgets.grid.events.EditCompleteHandler;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;
@@ -46,11 +61,19 @@ public class Installer implements EntryPoint {
// This must come first to ensure proper I18N class loading for dev mode
private static final Messages MSG = GWT.create(Messages.class);
+ private static final String PROPERTY_NAME = "propertyName";
+ private static final String PROPERTY_VALUE = "propertyValue";
+
private InstallerGWTServiceAsync installerService = InstallerGWTServiceAsync.Util.getInstance();
+ private HashMap<String, String> serverProperties = new HashMap<String, String>();
+ private HashMap<String, String> originalProperties = new HashMap<String, String>();
+
+ private ListGrid advancedPropertyItemGrid;
public void onModuleLoad() {
Canvas header = createHeader();
- TabSet tabSet = createTabSet();
+ Canvas installButton = createMainInstallButton();
+ Canvas tabSet = createTabSet();
VLayout layout = new VLayout();
layout.setWidth100();
@@ -59,12 +82,54 @@ public class Installer implements EntryPoint {
layout.setMembersMargin(5);
layout.setDefaultLayoutAlign(Alignment.CENTER);
layout.addMember(header);
+ layout.addMember(installButton);
layout.addMember(tabSet);
layout.draw();
// Remove loading image in case we don't completely cover it
Element loadingPanel = DOM.getElementById("Loading-Panel");
loadingPanel.removeFromParent();
+
+ // get the server properties from the server
+ loadServerProperties();
+
+ }
+
+ private void loadServerProperties() {
+ // load the initial server properties
+ installerService.getServerProperties(new AsyncCallback<HashMap<String, String>>() {
+ public void onSuccess(HashMap<String, String> result) {
+ if (result.size() == 0) {
+ SC.say("Initial server properties are missing.");
+ }
+ serverProperties.clear();
+ serverProperties.putAll(result);
+
+ // remember these original properties in case the user wants to reset them back
+ originalProperties.clear();
+ originalProperties.putAll(result);
+
+ // refresh the advanced view with the new data
+ refreshAdvancedView();
+ }
+
+ public void onFailure(Throwable caught) {
+ SC.say("Cannot load properties: " + caught);
+ }
+ });
+ }
+
+ private void refreshAdvancedView() {
+ ArrayList<ListGridRecord> records = new ArrayList<ListGridRecord>();
+ for (Map.Entry<String, String> entry : serverProperties.entrySet()) {
+ ListGridRecord record = new ListGridRecord();
+ record.setAttribute(PROPERTY_NAME, entry.getKey());
+ record.setAttribute(PROPERTY_VALUE, entry.getValue());
+ records.add(record);
+ }
+ advancedPropertyItemGrid.setData(records.toArray(new ListGridRecord[records.size()]));
+ advancedPropertyItemGrid.markForRedraw();
+ return;
}
private Canvas createHeader() {
@@ -83,6 +148,19 @@ public class Installer implements EntryPoint {
return strip;
}
+ private Canvas createMainInstallButton() {
+ Button installButton = new Button(MSG.start_installation_label());
+ installButton.setWrap(false);
+ installButton.setAutoFit(true);
+ installButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent event) {
+ SC.say("TODO: this should start the install");
+ }
+ });
+
+ return installButton;
+ }
+
private TabSet createTabSet() {
final TabSet topTabSet = new TabSet();
topTabSet.setTabBarPosition(Side.TOP);
@@ -102,13 +180,79 @@ public class Installer implements EntryPoint {
DynamicForm systemSettingsForm = createSystemSettingsForm();
systemSettingsTab.setPane(systemSettingsForm);
+ final Tab advancedViewTab = new Tab(MSG.tab_advancedView());
+ Canvas advancedView = createAdvancedView();
+ advancedViewTab.setPane(advancedView);
+
topTabSet.addTab(welcomeTab);
topTabSet.addTab(databaseTab);
topTabSet.addTab(systemSettingsTab);
+ topTabSet.addTab(advancedViewTab);
return topTabSet;
}
+ private Canvas createAdvancedView() {
+ VLayout layout = new VLayout();
+
+ ToolStrip strip = new ToolStrip();
+ strip.setWidth100();
+
+ IButton saveButton = new IButton(MSG.save_label());
+ saveButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent event) {
+ installerService.saveServerProperties(serverProperties, new AsyncCallback<Void>() {
+ public void onSuccess(Void result) {
+ originalProperties.clear();
+ originalProperties.putAll(serverProperties);
+ SC.say("Properties saved to server");
+ }
+
+ public void onFailure(Throwable caught) {
+ SC.say("Failed to save properties to server");
+ }
+ });
+ }
+ });
+ IButton resetButton = new IButton(MSG.reset_label());
+ resetButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent event) {
+ serverProperties.clear();
+ serverProperties.putAll(originalProperties);
+ refreshAdvancedView();
+ }
+ });
+ strip.addMember(saveButton);
+ strip.addMember(resetButton);
+ layout.addMember(strip);
+
+ advancedPropertyItemGrid = new ListGrid();
+ advancedPropertyItemGrid.setWidth100();
+ advancedPropertyItemGrid.setHeight100();
+ advancedPropertyItemGrid.setData(new ListGridRecord[0]);
+
+ ListGridField nameField = new ListGridField(PROPERTY_NAME, MSG.property_name_label());
+ nameField.setCanEdit(false);
+
+ ListGridField valueField = new ListGridField(PROPERTY_VALUE, MSG.property_value_label());
+ valueField.setCanEdit(true);
+
+ advancedPropertyItemGrid.setFields(nameField, valueField);
+ advancedPropertyItemGrid.setSortField(PROPERTY_NAME);
+
+ advancedPropertyItemGrid.addEditCompleteHandler(new EditCompleteHandler() {
+ public void onEditComplete(EditCompleteEvent event) {
+ String newValue = (String) event.getNewValues().values().iterator().next().toString();
+ String changedProperty = event.getOldRecord().getAttribute(PROPERTY_NAME);
+ serverProperties.put(changedProperty, newValue);
+ }
+ });
+
+ layout.addMember(advancedPropertyItemGrid);
+
+ return layout;
+ }
+
private DynamicForm createSystemSettingsForm() {
DynamicForm systemSettingsForm = new DynamicForm();
TextItem nameTextItem = new TextItem();
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
index 64e0d77..0184c77 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
@@ -18,6 +18,8 @@
*/
package org.rhq.enterprise.gui.installer.client.gwt;
+import java.util.HashMap;
+
import com.google.gwt.user.client.rpc.RemoteService;
/**
@@ -25,9 +27,15 @@ import com.google.gwt.user.client.rpc.RemoteService;
*/
public interface InstallerGWTService extends RemoteService {
+ HashMap<String, String> getServerProperties() throws Exception;
+
+ void saveServerProperties(HashMap<String, String> serverProperties) throws Exception;
+
void createDatasourceSecurityDomain(String username, String password) throws Exception;
String getAppServerVersion() throws Exception;
+ String getAppServerHomeDir() throws Exception;
+
String getOperatingSystem() throws Exception;
}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
index 2451b45..3890e1b 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
@@ -18,6 +18,11 @@
*/
package org.rhq.enterprise.gui.installer.server.servlet;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
import javax.servlet.annotation.WebServlet;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@@ -27,6 +32,7 @@ import org.jboss.as.controller.client.ModelControllerClient;
import org.rhq.common.jbossas.client.controller.Address;
import org.rhq.common.jbossas.client.controller.JBossASClient;
import org.rhq.common.jbossas.client.controller.SecurityDomainJBossASClient;
+import org.rhq.core.util.PropertiesFileUpdate;
import org.rhq.enterprise.gui.installer.client.gwt.InstallerGWTService;
import org.rhq.enterprise.gui.installer.server.service.ManagementService;
@@ -41,6 +47,38 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
private static final String RHQ_SECURITY_DOMAIN = "RHQDSSecurityDomain";
@Override
+ public HashMap<String, String> getServerProperties() throws Exception {
+ File appServerHomeDir = new File(getAppServerHomeDir());
+ File serverPropertiesFile = new File(appServerHomeDir, "../bin/rhq-server.properties");
+ PropertiesFileUpdate propsFile = new PropertiesFileUpdate(serverPropertiesFile.getAbsolutePath());
+ Properties props = propsFile.loadExistingProperties();
+
+ // GWT can't handle Properties - convert to HashMap
+ HashMap<String, String> map = new HashMap<String, String>(props.size());
+ for (Object property : props.keySet()) {
+ map.put(property.toString(), props.getProperty(property.toString()));
+ }
+ return map;
+ }
+
+ @Override
+ public void saveServerProperties(HashMap<String, String> serverProperties) throws Exception {
+ File appServerHomeDir = new File(getAppServerHomeDir());
+ File serverPropertiesFile = new File(appServerHomeDir, "../bin/rhq-server.properties");
+ PropertiesFileUpdate propsFile = new PropertiesFileUpdate(serverPropertiesFile.getAbsolutePath());
+
+ // GWT can't handle Properties - convert from HashMap
+ Properties props = new Properties();
+ for (Map.Entry<String, String> entry : serverProperties.entrySet()) {
+ props.setProperty(entry.getKey(), entry.getValue());
+ }
+
+ propsFile.update(props);
+
+ return;
+ }
+
+ @Override
public void createDatasourceSecurityDomain(String username, String password) throws Exception {
final SecurityDomainJBossASClient client = new SecurityDomainJBossASClient(getClient());
final String securityDomain = RHQ_SECURITY_DOMAIN;
@@ -60,6 +98,14 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
}
@Override
+ public String getAppServerHomeDir() throws Exception {
+ JBossASClient client = new JBossASClient(getClient());
+ String[] address = { "core-service", "server-environment" };
+ String dir = client.getStringAttribute(true, "home-dir", Address.root().add(address));
+ return dir;
+ }
+
+ @Override
public String getOperatingSystem() throws Exception {
JBossASClient client = new JBossASClient(getClient());
String[] address = { "core-service", "platform-mbean", "type", "operating-system" };
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties b/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
index fe75532..2a99074 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
@@ -4,4 +4,10 @@ This is the <b>new</b> installer.\n\
Any HTML can go in here.
tab.welcome=Welcome
tab.database=Database
-tab.systemSettings=System Settings
\ No newline at end of file
+tab.systemSettings=System Settings
+tab.advancedView=Advanced View
+property.name.label=Property
+property.value.label=Value
+save.label=Save
+reset.label=Reset
+start.installation.label=Press To Start The Installation Now
\ No newline at end of file
11 years, 10 months
[rhq] Branch 'mazz/test-rhq-on-as7' - modules/enterprise
by mazz
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/Address.java | 14 +
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/DatasourceJBossASClient.java | 34 ++
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/FailureException.java | 77 ++++++
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java | 127 ++++++++--
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/SecurityDomainJBossASClient.java | 110 ++++++++
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java | 127 ++++++----
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java | 2
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java | 35 +-
modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties | 8
9 files changed, 448 insertions(+), 86 deletions(-)
New commits:
commit b942403c15f463123a68afef060ba35991408e58
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Jul 18 19:52:30 2012 -0400
more prototyping - i have code that can deploy the RHQ security domain - which is necessary before we can deploy datasources
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/Address.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/Address.java
index ff28f35..1a54d36 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/Address.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/Address.java
@@ -27,7 +27,7 @@ import org.jboss.dmr.ModelNode;
*
* @author John Mazzitelli
*/
-public class Address {
+public class Address implements Cloneable {
private ModelNode addressNode;
public static Address root() {
@@ -67,4 +67,16 @@ public class Address {
addressNode.add(type, name);
return this;
}
+
+ @Override
+ public Address clone() throws CloneNotSupportedException {
+ Address clone = new Address();
+ clone.addressNode = addressNode.clone();
+ return clone;
+ }
+
+ @Override
+ public String toString() {
+ return addressNode.asString();
+ }
}
\ No newline at end of file
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/DatasourceJBossASClient.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/DatasourceJBossASClient.java
new file mode 100644
index 0000000..fb3135c
--- /dev/null
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/DatasourceJBossASClient.java
@@ -0,0 +1,34 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.common.jbossas.client.controller;
+
+import org.jboss.as.controller.client.ModelControllerClient;
+
+/**
+ * Provides convienence methods associated with datasource management.
+ *
+ * @author John Mazzitelli
+ */
+public class DatasourceJBossASClient extends JBossASClient {
+
+ public DatasourceJBossASClient(ModelControllerClient client) {
+ super(client);
+ }
+
+}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/FailureException.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/FailureException.java
new file mode 100644
index 0000000..6dde289
--- /dev/null
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/FailureException.java
@@ -0,0 +1,77 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.common.jbossas.client.controller;
+
+import org.jboss.dmr.ModelNode;
+
+/**
+ * Indicates a failed client request.
+ *
+ * @author John Mazzitelli
+ */
+public class FailureException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ private static final String GENERIC_ERROR = "Failed request";
+
+ public FailureException(ModelNode failureNode) {
+ super(buildErrorMessage(GENERIC_ERROR, failureNode));
+ }
+
+ public FailureException(ModelNode failureNode, String errMsg) {
+ super(buildErrorMessage(errMsg, failureNode));
+ }
+
+ public FailureException(ModelNode failureNode, Throwable cause) {
+ super(buildErrorMessage(GENERIC_ERROR, failureNode), cause);
+ }
+
+ public FailureException(ModelNode failureNode, String errMsg, Throwable cause) {
+ super(buildErrorMessage(errMsg, failureNode), cause);
+ }
+
+ public FailureException(String errMsg, Throwable cause) {
+ super((errMsg != null) ? errMsg : GENERIC_ERROR, cause);
+ }
+
+ public FailureException(String errMsg) {
+ super((errMsg != null) ? errMsg : GENERIC_ERROR);
+ }
+
+ public FailureException(Throwable cause) {
+ super(GENERIC_ERROR, cause);
+ }
+
+ public FailureException() {
+ super(GENERIC_ERROR);
+ }
+
+ private static final String buildErrorMessage(String errMsg, ModelNode failureNode) {
+ if (errMsg == null) {
+ errMsg = GENERIC_ERROR;
+ }
+
+ String description = JBossASClient.getFailureDescription(failureNode);
+ if (description != null) {
+ errMsg += ": " + description;
+ }
+
+ return errMsg;
+ }
+}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java
index 0f4d3b7..20ca4db 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java
@@ -22,7 +22,11 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.as.controller.client.OperationMessageHandler;
import org.jboss.dmr.ModelNode;
/**
@@ -32,25 +36,62 @@ import org.jboss.dmr.ModelNode;
*/
public class JBossASClient {
- private static final String BATCH = "composite";
- private static final String BATCH_STEPS = "steps";
- private static final String OPERATION = "operation";
- private static final String ADDRESS = "address";
- private static final String RESULT = "result";
- private static final String OUTCOME = "outcome";
- private static final String OUTCOME_SUCCESS = "success";
- private static final String FAILURE_DESCRIPTION = "failure-description";
- private static final String NAME = "name";
- private static final String READ_ATTRIBUTE = "read-attribute";
+ // protected to allow subclasses to have a logger, too, without explicitly declaring one themselves
+ protected final Log log = LogFactory.getLog(this.getClass());
+
+ public static final String BATCH = "composite";
+ public static final String BATCH_STEPS = "steps";
+ public static final String OPERATION = "operation";
+ public static final String ADDRESS = "address";
+ public static final String RESULT = "result";
+ public static final String OUTCOME = "outcome";
+ public static final String OUTCOME_SUCCESS = "success";
+ public static final String SUBSYSTEM = "subsystem";
+ public static final String FAILURE_DESCRIPTION = "failure-description";
+ public static final String NAME = "name";
+ public static final String VALUE = "value";
+ public static final String READ_ATTRIBUTE = "read-attribute";
+ public static final String READ_RESOURCE = "read-resource";
+ public static final String WRITE_ATTRIBUTE = "write-attribute";
+ public static final String ADD = "add";
private ModelControllerClient client;
-
+
public JBossASClient(ModelControllerClient client) {
this.client = client;
}
- public ModelControllerClient getModelControllerClient() {
- return client;
+ /////////////////////////////////////////////////////////////////
+ // Some static methods useful for convienence
+
+ /**
+ * Convienence method that allows you to create request that reads a single attribute
+ * value to a resource.
+ *
+ * @param attributeName the name of the attribute whose value is to be read
+ * @param address identifies the resource
+ * @return the request
+ */
+ public static ModelNode createReadAttributeRequest(String attributeName, Address address) {
+ ModelNode op = createRequest(READ_ATTRIBUTE, address);
+ op.get(NAME).set(attributeName);
+ return op;
+ }
+
+ /**
+ * Convienence method that allows you to create request that writes a single attribute's
+ * string value to a resource.
+ *
+ * @param attributeName the name of the attribute whose value is to be written
+ * @param attributeValue the attribute value that is to be written
+ * @param address identifies the resource
+ * @return the request
+ */
+ public static ModelNode createWriteAttributeRequest(String attributeName, String attributeValue, Address address) {
+ ModelNode op = createRequest(WRITE_ATTRIBUTE, address);
+ op.get(NAME).set(attributeName);
+ op.get(VALUE).set(attributeValue);
+ return op;
}
/**
@@ -60,7 +101,7 @@ public class JBossASClient {
* @param address identifies the target resource
* @return the partial operation request node - caller should fill this in further to complete the node
*/
- public ModelNode createRequest(String operation, Address address) {
+ public static ModelNode createRequest(String operation, Address address) {
final ModelNode request = new ModelNode();
request.get(OPERATION).set(operation);
request.get(ADDRESS).set(address.getAddressNode());
@@ -74,7 +115,7 @@ public class JBossASClient {
*
* @return the batch operation node
*/
- public ModelNode createBatchRequest(ModelNode... steps) {
+ public static ModelNode createBatchRequest(ModelNode... steps) {
final ModelNode composite = new ModelNode();
composite.get(OPERATION).set(BATCH);
composite.get(ADDRESS).setEmptyList();
@@ -92,7 +133,7 @@ public class JBossASClient {
* @param operationResult the node to examine
* @return the result list as Strings if there is a list, empty otherwise
*/
- public List<String> getResultList(ModelNode operationResult) {
+ public static List<String> getResultListAsStrings(ModelNode operationResult) {
if (!operationResult.hasDefined(RESULT)) {
return Collections.emptyList();
}
@@ -111,13 +152,28 @@ public class JBossASClient {
}
/**
+ * If the given node has results, those results are returned in a ModelNode.
+ * Otherwise, an empty node is returned.
+ *
+ * @param operationResult the node to examine
+ * @return the results as a ModelNode
+ */
+ public static ModelNode getResults(ModelNode operationResult) {
+ if (!operationResult.hasDefined(RESULT)) {
+ return new ModelNode();
+ }
+
+ return operationResult.get(RESULT);
+ }
+
+ /**
* Examines the given node's result list and if the item is found, returns true.
*
* @param operationResult the node to examine
* @param item the item to look for in the node's result list
* @return true if the node has a result list and it contains the item; false otherwise
*/
- public boolean listContains(ModelNode operationResult, String item) {
+ public static boolean listContains(ModelNode operationResult, String item) {
if (!operationResult.hasDefined(RESULT)) {
return false;
}
@@ -142,7 +198,7 @@ public class JBossASClient {
* @param operationResult the operation result to test
* @return the success or failure flag of the result
*/
- public boolean isSuccess(ModelNode operationResult) {
+ public static boolean isSuccess(ModelNode operationResult) {
if (operationResult != null) {
return operationResult.hasDefined(OUTCOME)
&& operationResult.get(OUTCOME).asString().equals(OUTCOME_SUCCESS);
@@ -158,7 +214,7 @@ public class JBossASClient {
* @param operationResult the operation whose failure description is to be returned
* @return the failure description of <code>null</code> if the operation was a success
*/
- public String getFailureDescription(ModelNode operationResult) {
+ public static String getFailureDescription(ModelNode operationResult) {
if (isSuccess(operationResult)) {
return null;
}
@@ -171,6 +227,29 @@ public class JBossASClient {
return "Unknown failure";
}
+ /////////////////////////////////////////////////////////////////
+ // Non-static methods that need the client
+
+ public ModelControllerClient getModelControllerClient() {
+ return client;
+ }
+
+ /**
+ * Convienence method that executes the request.
+ *
+ * @param request
+ * @return results
+ * @throws Exception
+ */
+ public ModelNode execute(ModelNode request) throws Exception {
+ try {
+ return getModelControllerClient().execute(request, OperationMessageHandler.logging);
+ } catch (Exception e) {
+ log.error("Failed to execute request", e);
+ throw e;
+ }
+ }
+
/**
* Convienence method that allows you to obtain a single attribute's string value from
* a resource.
@@ -182,15 +261,15 @@ public class JBossASClient {
* @throws Exception if failed to obtain the attribute value
*/
public String getStringAttribute(String attributeName, Address address) throws Exception {
- ModelNode op = createRequest(READ_ATTRIBUTE, address);
- op.get(NAME).set(attributeName);
- ModelNode results = getModelControllerClient().execute(op);
+ ModelNode op = createReadAttributeRequest(attributeName, address);
+ ModelNode results = execute(op);
if (isSuccess(results)) {
- ModelNode version = results.get(RESULT);
+ ModelNode version = getResults(results);
String attributeValue = version.asString();
return attributeValue;
} else {
- throw new RuntimeException(getFailureDescription(results));
+ throw new FailureException(results, "Failed to get attribute [" + attributeName + "] from [" + address
+ + "]");
}
}
}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/SecurityDomainJBossASClient.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/SecurityDomainJBossASClient.java
new file mode 100644
index 0000000..a73ba79
--- /dev/null
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/SecurityDomainJBossASClient.java
@@ -0,0 +1,110 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.common.jbossas.client.controller;
+
+import java.util.List;
+
+import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.dmr.ModelNode;
+
+/**
+ * Provides convienence methods associated with security domain management.
+ *
+ * @author John Mazzitelli
+ */
+public class SecurityDomainJBossASClient extends JBossASClient {
+
+ public static final String SUBSYSTEM_SECURITY = "security";
+ public static final String SECURITY_DOMAIN = "security-domain";
+ public static final String CACHE_TYPE = "cache-type";
+ public static final String AUTHENTICATION = "authentication";
+ public static final String LOGIN_MODULES = "login-modules";
+ public static final String CLASSIC = "classic";
+ public static final String CODE = "code";
+ public static final String FLAG = "flag";
+ public static final String MODULE_OPTIONS = "module-options";
+ public static final String USERNAME = "username";
+ public static final String PASSWORD = "password";
+
+ public SecurityDomainJBossASClient(ModelControllerClient client) {
+ super(client);
+ }
+
+ /**
+ * Checks to see if there is already a security domain with the given name.
+ *
+ * @param securityDomainName the name to check
+ * @return true if there is a security domain with the given name already in existence
+ */
+ public boolean isSecurityDomain(String securityDomainName) throws Exception {
+ Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_SECURITY);
+ ModelNode queryNode = createRequest(READ_RESOURCE, addr);
+ ModelNode results = execute(queryNode);
+ if (isSuccess(results)) {
+ ModelNode domains = getResults(results).get(SECURITY_DOMAIN);
+ List<ModelNode> list = domains.asList();
+ for (ModelNode domain : list) {
+ if (domain.has(securityDomainName)) {
+ return true;
+ }
+ }
+ return false;
+ } else {
+ throw new FailureException(results, "Failed to get security domains");
+ }
+ }
+
+ /**
+ * Convienence method that builds a request which can create a new security-domain
+ * using the SecureIdentity authentication method. This is used when you want
+ * to obfuscate a database password in the configuration.
+ *
+ * @param securityDomainName the name of the new security domain
+ * @param username the username associated with the security domain
+ * @param password the value of the password to store in the configuration (e.g. the obfuscated password itself)
+ *
+ * @throws Exception if failed to create security domain
+ */
+ public void createNewSecureIdentitySecurityDomainRequest(String securityDomainName, String username, String password)
+ throws Exception {
+
+ Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_SECURITY, SECURITY_DOMAIN, securityDomainName);
+ ModelNode addTopNode = createRequest(ADD, addr);
+ addTopNode.get(CACHE_TYPE).set("default");
+
+ ModelNode addAuthNode = createRequest(ADD, addr.clone().add(AUTHENTICATION, CLASSIC));
+ ModelNode loginModulesNode = addAuthNode.get(LOGIN_MODULES);
+ ModelNode loginModule = new ModelNode();
+ loginModule.get(CODE).set("SecureIdentity");
+ loginModule.get(FLAG).set("required");
+ ModelNode moduleOptions = loginModule.get(MODULE_OPTIONS);
+ moduleOptions.setEmptyList();
+ moduleOptions.add(USERNAME, username);
+ moduleOptions.add(PASSWORD, password);
+ loginModulesNode.add(loginModule);
+
+ ModelNode batch = createBatchRequest(addTopNode, addAuthNode);
+ ModelNode results = execute(batch);
+ if (!isSuccess(results)) {
+ throw new FailureException(results, "Failed to create security domain [" + securityDomainName + "]");
+ }
+
+ return;
+ }
+}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
index decd028..c267d22 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/Installer.java
@@ -22,12 +22,17 @@ import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.util.SC;
-import com.smartgwt.client.widgets.IButton;
-import com.smartgwt.client.widgets.events.ClickEvent;
-import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.Side;
+import com.smartgwt.client.types.VerticalAlignment;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.layout.VLayout;
+import com.smartgwt.client.widgets.tab.Tab;
+import com.smartgwt.client.widgets.tab.TabSet;
+import com.smartgwt.client.widgets.toolbar.ToolStrip;
import org.rhq.enterprise.gui.installer.client.gwt.InstallerGWTServiceAsync;
@@ -41,52 +46,82 @@ public class Installer implements EntryPoint {
// This must come first to ensure proper I18N class loading for dev mode
private static final Messages MSG = GWT.create(Messages.class);
+ private InstallerGWTServiceAsync installerService = InstallerGWTServiceAsync.Util.getInstance();
+
public void onModuleLoad() {
- IButton button1 = new IButton(MSG.hello_msg());
- button1.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- InstallerGWTServiceAsync rpc = InstallerGWTServiceAsync.Util.getInstance();
- rpc.getAppServerVersion(new AsyncCallback<String>() {
-
- @Override
- public void onSuccess(String result) {
- SC.say("SUCCESS: " + result);
- }
-
- @Override
- public void onFailure(Throwable caught) {
- SC.say("FAILURE: " + caught);
- }
- });
- }
- });
-
- IButton button2 = new IButton(MSG.hello_msg());
- button2.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- InstallerGWTServiceAsync rpc = InstallerGWTServiceAsync.Util.getInstance();
- rpc.getOperatingSystem(new AsyncCallback<String>() {
-
- @Override
- public void onSuccess(String result) {
- SC.say("SUCCESS: " + result);
- }
-
- @Override
- public void onFailure(Throwable caught) {
- SC.say("FAILURE: " + caught);
- }
- });
- }
- });
-
- VLayout layout = new VLayout(10);
- layout.addMember(button1);
- layout.addMember(button2);
+ Canvas header = createHeader();
+ TabSet tabSet = createTabSet();
+
+ VLayout layout = new VLayout();
+ layout.setWidth100();
+ layout.setHeight100();
+ layout.setLayoutMargin(10);
+ layout.setMembersMargin(5);
+ layout.setDefaultLayoutAlign(Alignment.CENTER);
+ layout.addMember(header);
+ layout.addMember(tabSet);
layout.draw();
// Remove loading image in case we don't completely cover it
Element loadingPanel = DOM.getElementById("Loading-Panel");
loadingPanel.removeFromParent();
}
+
+ private Canvas createHeader() {
+ ToolStrip strip = new ToolStrip();
+ strip.setWidth100();
+ strip.setAlign(Alignment.CENTER);
+
+ Label title = new Label();
+ title.setWidth100();
+ title.setHeight100();
+ title.setWrap(false);
+ title.setValign(VerticalAlignment.CENTER);
+ title.setAlign(Alignment.CENTER);
+ title.setContents("<span style=\"font-size:16pt;font-weight:bold;\">" + MSG.welcome_title() + "</span>");
+ strip.addMember(title);
+ return strip;
+ }
+
+ private TabSet createTabSet() {
+ final TabSet topTabSet = new TabSet();
+ topTabSet.setTabBarPosition(Side.TOP);
+ topTabSet.setTabBarAlign(Side.LEFT);
+ topTabSet.setWidth("80%");
+ topTabSet.setHeight("75%");
+
+ final Tab welcomeTab = new Tab(MSG.tab_welcome());
+ Label welcomeLabel = new Label(MSG.tab_welcome_content());
+ welcomeTab.setPane(welcomeLabel);
+
+ final Tab databaseTab = new Tab(MSG.tab_database());
+ DynamicForm databaseForm = createDatabaseForm();
+ databaseTab.setPane(databaseForm);
+
+ final Tab systemSettingsTab = new Tab(MSG.tab_systemSettings());
+ DynamicForm systemSettingsForm = createSystemSettingsForm();
+ systemSettingsTab.setPane(systemSettingsForm);
+
+ topTabSet.addTab(welcomeTab);
+ topTabSet.addTab(databaseTab);
+ topTabSet.addTab(systemSettingsTab);
+
+ return topTabSet;
+ }
+
+ private DynamicForm createSystemSettingsForm() {
+ DynamicForm systemSettingsForm = new DynamicForm();
+ TextItem nameTextItem = new TextItem();
+ nameTextItem.setTitle("Your Name");
+ systemSettingsForm.setFields(nameTextItem);
+ return systemSettingsForm;
+ }
+
+ private DynamicForm createDatabaseForm() {
+ DynamicForm databaseForm = new DynamicForm();
+ TextItem dbUsernameTextItem = new TextItem();
+ dbUsernameTextItem.setTitle("Database User");
+ databaseForm.setFields(dbUsernameTextItem);
+ return databaseForm;
+ }
}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
index b0f7e23..64e0d77 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
@@ -25,6 +25,8 @@ import com.google.gwt.user.client.rpc.RemoteService;
*/
public interface InstallerGWTService extends RemoteService {
+ void createDatasourceSecurityDomain(String username, String password) throws Exception;
+
String getAppServerVersion() throws Exception;
String getOperatingSystem() throws Exception;
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
index bc5351b..2451b45 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
@@ -26,6 +26,7 @@ import org.jboss.as.controller.client.ModelControllerClient;
import org.rhq.common.jbossas.client.controller.Address;
import org.rhq.common.jbossas.client.controller.JBossASClient;
+import org.rhq.common.jbossas.client.controller.SecurityDomainJBossASClient;
import org.rhq.enterprise.gui.installer.client.gwt.InstallerGWTService;
import org.rhq.enterprise.gui.installer.server.service.ManagementService;
@@ -37,31 +38,37 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
private static final long serialVersionUID = 1L;
+ private static final String RHQ_SECURITY_DOMAIN = "RHQDSSecurityDomain";
+
+ @Override
+ public void createDatasourceSecurityDomain(String username, String password) throws Exception {
+ final SecurityDomainJBossASClient client = new SecurityDomainJBossASClient(getClient());
+ final String securityDomain = RHQ_SECURITY_DOMAIN;
+ if (!client.isSecurityDomain(securityDomain)) {
+ client.createNewSecureIdentitySecurityDomainRequest(securityDomain, username, password);
+ log("Security domain [" + securityDomain + "] created");
+ } else {
+ log("Security domain [" + securityDomain + "] already exists, skipping the creation request");
+ }
+ }
+
@Override
public String getAppServerVersion() throws Exception {
- try {
- String version = getClient().getStringAttribute("release-version", Address.root());
+ JBossASClient client = new JBossASClient(getClient());
+ String version = client.getStringAttribute("release-version", Address.root());
return version;
- } catch (Exception t) {
- t.printStackTrace();
- throw t;
- }
}
@Override
public String getOperatingSystem() throws Exception {
- try {
+ JBossASClient client = new JBossASClient(getClient());
String[] address = { "core-service", "platform-mbean", "type", "operating-system" };
- String osName = getClient().getStringAttribute("name", Address.root().add(address));
+ String osName = client.getStringAttribute("name", Address.root().add(address));
return osName;
- } catch (Exception t) {
- t.printStackTrace();
- throw t;
- }
}
- private JBossASClient getClient() {
+ private ModelControllerClient getClient() {
ModelControllerClient client = ManagementService.getClient();
- return new JBossASClient(client);
+ return client;
}
}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties b/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
index e83bff5..fe75532 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/resources/org/rhq/enterprise/gui/installer/client/Messages.properties
@@ -1 +1,7 @@
-hello.msg=Hello from the installer
+welcome.title=Installing the Server
+tab.welcome.content=<h1>Welcome to the new GWT Installer</h1>\n\
+This is the <b>new</b> installer.\n\
+Any HTML can go in here.
+tab.welcome=Welcome
+tab.database=Database
+tab.systemSettings=System Settings
\ No newline at end of file
11 years, 10 months
[rhq] Branch 'mazz/test-rhq-on-as7' - modules/enterprise
by mazz
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/Address.java | 70 +++
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java | 196 ++++++++++
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java | 4
modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java | 59 ---
4 files changed, 287 insertions(+), 42 deletions(-)
New commits:
commit 817f2209aad09db2ab468ef3ad9bb6121881f52d
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Jul 18 13:05:15 2012 -0400
refactor client stuff so we can more easily move it to common module later
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/Address.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/Address.java
new file mode 100644
index 0000000..ff28f35
--- /dev/null
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/Address.java
@@ -0,0 +1,70 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.common.jbossas.client.controller;
+
+import java.util.Arrays;
+
+import org.jboss.dmr.ModelNode;
+
+/**
+ * Identifies a managed resource.
+ *
+ * @author John Mazzitelli
+ */
+public class Address {
+ private ModelNode addressNode;
+
+ public static Address root() {
+ return new Address();
+ }
+
+ public Address() {
+ addressNode = new ModelNode();
+ }
+
+ public Address(String... addressParts) {
+ this();
+ add(addressParts);
+ }
+
+ public ModelNode getAddressNode() {
+ return addressNode;
+ }
+
+ public Address add(String... addressParts) {
+ if (addressParts != null) {
+ if ((addressParts.length % 2) != 0) {
+ throw new IllegalArgumentException("address is incomplete: " + Arrays.toString(addressParts));
+ }
+
+ if (addressParts.length > 0) {
+ for (int i = 0; i < addressParts.length; i += 2) {
+ addressNode.add(addressParts[i], addressParts[i + 1]);
+ }
+ }
+ }
+
+ return this;
+ }
+
+ public Address add(String type, String name) {
+ addressNode.add(type, name);
+ return this;
+ }
+}
\ No newline at end of file
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java
new file mode 100644
index 0000000..0f4d3b7
--- /dev/null
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/common/jbossas/client/controller/JBossASClient.java
@@ -0,0 +1,196 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2012 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.common.jbossas.client.controller;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.dmr.ModelNode;
+
+/**
+ * A client that can be used to talk to a JBossAS server via the DMR/ModelControllerClient API.
+ *
+ * @author John Mazzitelli
+ */
+public class JBossASClient {
+
+ private static final String BATCH = "composite";
+ private static final String BATCH_STEPS = "steps";
+ private static final String OPERATION = "operation";
+ private static final String ADDRESS = "address";
+ private static final String RESULT = "result";
+ private static final String OUTCOME = "outcome";
+ private static final String OUTCOME_SUCCESS = "success";
+ private static final String FAILURE_DESCRIPTION = "failure-description";
+ private static final String NAME = "name";
+ private static final String READ_ATTRIBUTE = "read-attribute";
+
+ private ModelControllerClient client;
+
+ public JBossASClient(ModelControllerClient client) {
+ this.client = client;
+ }
+
+ public ModelControllerClient getModelControllerClient() {
+ return client;
+ }
+
+ /**
+ * Convienence method that builds a partial operation request node.
+ *
+ * @param operation the operation to be requested
+ * @param address identifies the target resource
+ * @return the partial operation request node - caller should fill this in further to complete the node
+ */
+ public ModelNode createRequest(String operation, Address address) {
+ final ModelNode request = new ModelNode();
+ request.get(OPERATION).set(operation);
+ request.get(ADDRESS).set(address.getAddressNode());
+ return request;
+ }
+
+ /**
+ * Creates a batch of operations that can be atomically invoked.
+ *
+ * @param steps the different operation steps of the batch
+ *
+ * @return the batch operation node
+ */
+ public ModelNode createBatchRequest(ModelNode... steps) {
+ final ModelNode composite = new ModelNode();
+ composite.get(OPERATION).set(BATCH);
+ composite.get(ADDRESS).setEmptyList();
+ final ModelNode stepsNode = composite.get(BATCH_STEPS);
+ for (ModelNode step : steps) {
+ stepsNode.add(step);
+ }
+ return composite;
+ }
+
+ /**
+ * If the given node has a result list, that list will be returned
+ * with the values as Strings. Otherwise, an empty list is returned.
+ *
+ * @param operationResult the node to examine
+ * @return the result list as Strings if there is a list, empty otherwise
+ */
+ public List<String> getResultList(ModelNode operationResult) {
+ if (!operationResult.hasDefined(RESULT)) {
+ return Collections.emptyList();
+ }
+
+ List<ModelNode> nodeList = operationResult.get(RESULT).asList();
+ if (nodeList.isEmpty()) {
+ return Collections.emptyList();
+ }
+
+ List<String> list = new ArrayList<String>(nodeList.size());
+ for (ModelNode node : nodeList) {
+ list.add(node.asString());
+ }
+
+ return list;
+ }
+
+ /**
+ * Examines the given node's result list and if the item is found, returns true.
+ *
+ * @param operationResult the node to examine
+ * @param item the item to look for in the node's result list
+ * @return true if the node has a result list and it contains the item; false otherwise
+ */
+ public boolean listContains(ModelNode operationResult, String item) {
+ if (!operationResult.hasDefined(RESULT)) {
+ return false;
+ }
+
+ List<ModelNode> nodeList = operationResult.get(RESULT).asList();
+ if (nodeList.isEmpty()) {
+ return false;
+ }
+
+ for (ModelNode node : nodeList) {
+ if (node.asString().equals(item)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns <code>true</code> if the operation was a success; <code>false</code> otherwise.
+ *
+ * @param operationResult the operation result to test
+ * @return the success or failure flag of the result
+ */
+ public boolean isSuccess(ModelNode operationResult) {
+ if (operationResult != null) {
+ return operationResult.hasDefined(OUTCOME)
+ && operationResult.get(OUTCOME).asString().equals(OUTCOME_SUCCESS);
+ }
+ return false;
+ }
+
+ /**
+ * If the operation result was a failure, this returns the failure description if there is one.
+ * A generic failure message will be returned if the operation was a failure but has no failure
+ * description. A <code>null</code> is returned if the operation was a success.
+ *
+ * @param operationResult the operation whose failure description is to be returned
+ * @return the failure description of <code>null</code> if the operation was a success
+ */
+ public String getFailureDescription(ModelNode operationResult) {
+ if (isSuccess(operationResult)) {
+ return null;
+ }
+ if (operationResult != null) {
+ ModelNode descr = operationResult.get(FAILURE_DESCRIPTION);
+ if (descr != null) {
+ return descr.asString();
+ }
+ }
+ return "Unknown failure";
+ }
+
+ /**
+ * Convienence method that allows you to obtain a single attribute's string value from
+ * a resource.
+ *
+ * @param attributeName the attribute whose value is to be returned
+ * @param address identifies the resource
+ * @return the attribute value
+ *
+ * @throws Exception if failed to obtain the attribute value
+ */
+ public String getStringAttribute(String attributeName, Address address) throws Exception {
+ ModelNode op = createRequest(READ_ATTRIBUTE, address);
+ op.get(NAME).set(attributeName);
+ ModelNode results = getModelControllerClient().execute(op);
+ if (isSuccess(results)) {
+ ModelNode version = results.get(RESULT);
+ String attributeValue = version.asString();
+ return attributeValue;
+ } else {
+ throw new RuntimeException(getFailureDescription(results));
+ }
+ }
+}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
index 97d38a2..b0f7e23 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/client/gwt/InstallerGWTService.java
@@ -25,7 +25,7 @@ import com.google.gwt.user.client.rpc.RemoteService;
*/
public interface InstallerGWTService extends RemoteService {
- String getAppServerVersion();
+ String getAppServerVersion() throws Exception;
- String getOperatingSystem();
+ String getOperatingSystem() throws Exception;
}
diff --git a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
index 21e489e..bc5351b 100644
--- a/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
+++ b/modules/enterprise/gui/gwt-installer-war/src/main/java/org/rhq/enterprise/gui/installer/server/servlet/InstallerGWTServiceImpl.java
@@ -23,8 +23,9 @@ import javax.servlet.annotation.WebServlet;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.jboss.as.controller.client.ModelControllerClient;
-import org.jboss.dmr.ModelNode;
+import org.rhq.common.jbossas.client.controller.Address;
+import org.rhq.common.jbossas.client.controller.JBossASClient;
import org.rhq.enterprise.gui.installer.client.gwt.InstallerGWTService;
import org.rhq.enterprise.gui.installer.server.service.ManagementService;
@@ -37,52 +38,30 @@ public class InstallerGWTServiceImpl extends RemoteServiceServlet implements Ins
private static final long serialVersionUID = 1L;
@Override
- public String getAppServerVersion() {
- ModelControllerClient client = ManagementService.getClient();
-
- // create the read operation we want to invoke on the root AS resource
- ModelNode op = new ModelNode();
- op.get("operation").set("read-attribute");
- op.get("name").set("release-version");
-
- String versionString;
-
+ public String getAppServerVersion() throws Exception {
try {
- ModelNode results = client.execute(op);
- ModelNode version = results.get("result");
- versionString = version.asString();
- } catch (Exception e) {
- versionString = e.toString();
+ String version = getClient().getStringAttribute("release-version", Address.root());
+ return version;
+ } catch (Exception t) {
+ t.printStackTrace();
+ throw t;
}
-
- return versionString;
}
@Override
- public String getOperatingSystem() {
- ModelControllerClient client = ManagementService.getClient();
-
- // create the read operation we want to invoke on the platform MBean operating system resource
- ModelNode op = new ModelNode();
- op.get("operation").set("read-attribute");
- op.get("name").set("name");
-
- // provide the target address to the platform MBean operating system resource via ModelNode list
- ModelNode address = op.get("address");
- address.add("core-service", "platform-mbean");
- address.add("type", "operating-system");
-
- String osName;
-
+ public String getOperatingSystem() throws Exception {
try {
- ModelNode results = client.execute(op);
- ModelNode version = results.get("result");
- osName = version.asString();
- } catch (Exception e) {
- osName = e.toString();
- }
-
+ String[] address = { "core-service", "platform-mbean", "type", "operating-system" };
+ String osName = getClient().getStringAttribute("name", Address.root().add(address));
return osName;
+ } catch (Exception t) {
+ t.printStackTrace();
+ throw t;
+ }
}
+ private JBossASClient getClient() {
+ ModelControllerClient client = ManagementService.getClient();
+ return new JBossASClient(client);
+ }
}
11 years, 10 months
[rhq] Branch 'release/jon3.1.x' - 5 commits - modules/core modules/enterprise
by mazz
modules/core/domain/src/main/java/org/rhq/core/domain/auth/Subject.java | 2
modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Configuration.java | 4
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceGroupCriteria.java | 12
modules/core/domain/src/main/java/org/rhq/core/domain/measurement/Availability.java | 2
modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java | 13
modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java | 16
modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java | 56 +-
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/cluster/ClusterManagerBean.java | 7
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java | 50 -
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/GroupWithUncommittedTest.java | 280 ++++++++++
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/LargeGroupCriteriaTest.java | 82 ++
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/RecursiveResourceGroupTest.java | 3
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/LargeGroupTestBase.java | 20
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/util/SessionTestHelper.java | 4
14 files changed, 462 insertions(+), 89 deletions(-)
New commits:
commit ee6d6f6f063064f2a0336573c62eb9beb2b334eb
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Mon May 14 11:13:54 2012 -0400
[BZ 820981][BZ 819897] fix unit tests that now must ensure they put new resources in the committed inventory state
(cherry picked from commit 5c02dfbad4a6fc8c9eeaaf15d3519eccfa1fe31f)
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/RecursiveResourceGroupTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/RecursiveResourceGroupTest.java
index 86efd10..597cb26 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/RecursiveResourceGroupTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/RecursiveResourceGroupTest.java
@@ -34,6 +34,7 @@ import org.testng.annotations.Test;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.authz.Role;
+import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.group.ResourceGroup;
import org.rhq.core.domain.util.PageControl;
@@ -105,6 +106,7 @@ public class RecursiveResourceGroupTest extends AbstractEJB3Test {
// test update implicit resources
Resource newChildOfNodeA = new Resource("new nodeOne child", "new nodeOne child", nodeA.getResourceType());
newChildOfNodeA.setUuid("" + new Random().nextInt());
+ newChildOfNodeA.setInventoryStatus(InventoryStatus.COMMITTED);
resourceManager.createResource(subject, newChildOfNodeA, nodeA.getId()); // sets up implicit relationships
@@ -151,6 +153,7 @@ public class RecursiveResourceGroupTest extends AbstractEJB3Test {
// test update implicit resources
Resource gen5 = new Resource("g5", "g5", gen4.getResourceType());
gen5.setUuid("" + new Random().nextInt());
+ gen5.setInventoryStatus(InventoryStatus.COMMITTED);
resourceManager.createResource(subject, gen5, gen4.getId()); // sets up implicit relationships
// confirm results
commit 3d9da7710ed9c3f4857c3427c6e4c69cc8c58b23
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri May 11 16:14:15 2012 -0400
opps.. fix test method name
(cherry picked from commit 3f5f02c489179e81d783b49d8270ae869b74d404)
Conflicts:
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/LargeGroupCriteriaTest.java
commit 81f7ea0d5078c6b470e9cc3342687e88170360e8
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri May 11 16:08:42 2012 -0400
[BZ 820981][BZ 819897] fix some group queries that did not properly filter non-committed resources
(cherry picked from commit 3d1a2e5722043bd70835c88cf448f3a9c1d47711)
Conflicts:
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/LargeGroupCriteriaTest.java
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/auth/Subject.java b/modules/core/domain/src/main/java/org/rhq/core/domain/auth/Subject.java
index 8c76e70..2ed8c6c 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/auth/Subject.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/auth/Subject.java
@@ -185,7 +185,7 @@ import org.rhq.core.domain.resource.group.ResourceGroup;
*/
@NamedQuery(name = Subject.QUERY_GET_RESOURCES_BY_PERMISSION, query = "SELECT distinct res.id "
+ "FROM Subject s, IN (s.roles) r, IN (r.permissions) p, IN (r.resourceGroups) g, IN (g.implicitResources) res "
- + "WHERE s = :subject AND p = :permission"),
+ + "WHERE s = :subject AND p = :permission AND res.inventoryStatus = 'COMMITTED'"),
@NamedQuery(name = Subject.QUERY_FIND_AVAILABLE_SUBJECTS_FOR_ROLE_WITH_EXCLUDES, query = "" //
+ "SELECT DISTINCT s " + " FROM Subject AS s LEFT JOIN s.roles AS r " //
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Configuration.java b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Configuration.java
index 3fd05f7..99426b9 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Configuration.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/Configuration.java
@@ -99,12 +99,12 @@ import org.jetbrains.annotations.Nullable;
+ "SELECT r.id, r.resourceConfiguration " //
+ " FROM ResourceGroup rg " //
+ " JOIN rg.explicitResources r " //
- + " WHERE rg.id = :resourceGroupId"),
+ + " WHERE rg.id = :resourceGroupId AND r.inventoryStatus = 'COMMITTED'"),
@NamedQuery(name = Configuration.QUERY_GET_PLUGIN_CONFIG_MAP_BY_GROUP_ID, query = "" //
+ "SELECT r.id, r.pluginConfiguration " //
+ " FROM ResourceGroup rg " //
+ " JOIN rg.explicitResources r " //
- + " WHERE rg.id = :resourceGroupId"),
+ + " WHERE rg.id = :resourceGroupId AND r.inventoryStatus = 'COMMITTED'"),
@NamedQuery(name = Configuration.QUERY_GET_RESOURCE_CONFIG_MAP_BY_GROUP_UPDATE_ID, query = "" //
+ "SELECT res.id, cu.configuration " //
+ " FROM ResourceConfigurationUpdate cu " //
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/Availability.java b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/Availability.java
index b439e35..6158a74 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/Availability.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/measurement/Availability.java
@@ -104,7 +104,7 @@ import org.rhq.core.domain.resource.Resource;
+ " WHERE av.resource.id IN ( SELECT ires.id " //
+ " FROM ResourceGroup rg " //
+ " JOIN rg.implicitResources ires " //
- + " WHERE rg.id = :groupId ) " //
+ + " WHERE rg.id = :groupId AND ires.inventoryStatus = 'COMMITTED' ) " //
+ " AND ((av.startTime <= :start AND (av.endTime >= :start OR av.endTime IS NULL) ) " /* availability straddles :start */
+ " OR (av.startTime BETWEEN :start AND :end)) " /* interval straddles availability.startTime */
+ "ORDER BY av.startTime ASC"), //
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
index 74b5c17..46383f3 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
@@ -379,11 +379,11 @@ import org.rhq.core.domain.util.Summary;
@NamedQuery(name = Resource.QUERY_FIND_EXPLICIT_IDS_BY_RESOURCE_GROUP_ADMIN, query = "" //
+ "SELECT res.id " //
+ " FROM ResourceGroup rg, IN (rg.explicitResources) res " //
- + " WHERE rg.id = :groupId"),
+ + " WHERE rg.id = :groupId AND res.inventoryStatus = 'COMMITTED' "),
@NamedQuery(name = Resource.QUERY_FIND_IMPLICIT_IDS_BY_RESOURCE_GROUP_ADMIN, query = "" //
+ "SELECT res.id " //
+ " FROM ResourceGroup rg, IN (rg.implicitResources) res " //
- + " WHERE rg.id = :groupId "),
+ + " WHERE rg.id = :groupId AND res.inventoryStatus = 'COMMITTED' "),
@NamedQuery(name = Resource.QUERY_FIND_FLY_WEIGHTS_BY_RESOURCE_IDS, query = "" //
+ "SELECT new org.rhq.core.domain.resource.composite.ResourceIdFlyWeight(res.id, res.uuid) " //
+ " FROM Resource res " //
@@ -392,20 +392,21 @@ import org.rhq.core.domain.util.Summary;
@NamedQuery(name = Resource.QUERY_FIND_BY_EXPLICIT_RESOURCE_GROUP, query = "" //
+ "SELECT DISTINCT res " //
+ " FROM ResourceGroup rg JOIN rg.roles r JOIN r.subjects s JOIN rg.explicitResources res " //
- + " WHERE rg = :group " //
+ + " WHERE rg = :group AND res.inventoryStatus = 'COMMITTED' " //
+ " AND s = :subject"),
@NamedQuery(name = Resource.QUERY_FIND_BY_EXPLICIT_RESOURCE_GROUP_ADMIN, query = "" //
+ "SELECT res " //
- + " FROM ResourceGroup rg, IN (rg.explicitResources) res " + " WHERE rg = :group "),
+ + " FROM ResourceGroup rg, IN (rg.explicitResources) res " //
+ + " WHERE rg = :group AND res.inventoryStatus = 'COMMITTED' "),
@NamedQuery(name = Resource.QUERY_FIND_BY_IMPLICIT_RESOURCE_GROUP, query = "" //
+ "SELECT DISTINCT res " //
+ " FROM ResourceGroup rg JOIN rg.roles r JOIN r.subjects s JOIN rg.implicitResources res " //
- + " WHERE rg = :group " //
+ + " WHERE rg = :group AND res.inventoryStatus = 'COMMITTED'" //
+ " AND s = :subject"),
@NamedQuery(name = Resource.QUERY_FIND_BY_IMPLICIT_RESOURCE_GROUP_ADMIN, query = "" //
+ "SELECT res " //
+ " FROM ResourceGroup rg, IN (rg.implicitResources) res " //
- + " WHERE rg = :group "),
+ + " WHERE rg = :group AND res.inventoryStatus = 'COMMITTED' "),
@NamedQuery(name = Resource.QUERY_FIND_EXPLICIT_RESOURCES_WITH_AVAILABILITY_FOR_RESOURCE_GROUP, query = "" //
+ "SELECT new org.rhq.core.domain.resource.composite.ResourceWithAvailability(res, " //
+ " (SELECT parentRes FROM Resource parentRes WHERE parentRes = res.parentResource), " //
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
index 6934c3a..9d8118d 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
@@ -155,12 +155,16 @@ import org.rhq.core.domain.util.Summary;
+ " FROM ResourceGroup rg " //
+ " JOIN rg.resourceType rt" //
+ " WHERE rt.deleted = false AND ( rt.plugin = :pluginName OR :pluginName is null ) "),
- @NamedQuery(name = ResourceType.QUERY_GET_EXPLICIT_RESOURCE_TYPE_COUNTS_BY_GROUP, query = "SELECT type.id, type.name, COUNT(type.id) "
- + "FROM ResourceGroup rg JOIN rg.explicitResources res JOIN res.resourceType type "
- + "WHERE rg.id = :groupId AND res.resourceType.deleted = false " + "GROUP BY type.id, type.name "),
- @NamedQuery(name = ResourceType.QUERY_GET_IMPLICIT_RESOURCE_TYPE_COUNTS_BY_GROUP, query = "SELECT type.id, type.name, COUNT(type.id) "
- + "FROM ResourceGroup rg JOIN rg.implicitResources res JOIN res.resourceType type "
- + "WHERE rg.id = :groupId AND res.resourceType.deleted = false " + "GROUP BY type.id, type.name "),
+ @NamedQuery(name = ResourceType.QUERY_GET_EXPLICIT_RESOURCE_TYPE_COUNTS_BY_GROUP, query = "" //
+ + "SELECT type.id, type.name, COUNT(type.id) " //
+ + " FROM ResourceGroup rg JOIN rg.explicitResources res JOIN res.resourceType type " //
+ + " WHERE rg.id = :groupId AND res.resourceType.deleted = false AND res.inventoryStatus = 'COMMITTED' " //
+ + " GROUP BY type.id, type.name "),
+ @NamedQuery(name = ResourceType.QUERY_GET_IMPLICIT_RESOURCE_TYPE_COUNTS_BY_GROUP, query = "" //
+ + "SELECT type.id, type.name, COUNT(type.id) " //
+ + " FROM ResourceGroup rg JOIN rg.implicitResources res JOIN res.resourceType type " //
+ + " WHERE rg.id = :groupId AND res.resourceType.deleted = false AND res.inventoryStatus = 'COMMITTED' " //
+ + " GROUP BY type.id, type.name "),
@NamedQuery(name = ResourceType.QUERY_FIND_BY_SUBCATEGORY, query = "SELECT rt " + "FROM ResourceType rt "
+ "WHERE rt.subCategory = :subCategory AND rt.deleted = false"),
@NamedQuery(name = ResourceType.QUERY_FIND_BY_ID_WITH_ALL_OPERATIONS, query = "SELECT DISTINCT rt "
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java
index ba2e49c..7b30aaf 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java
@@ -78,32 +78,33 @@ import org.rhq.core.domain.tagging.Tag;
+ "LEFT JOIN g.resourceType type " //
+ "LEFT JOIN g.implicitResources res " // used for inventory>summary "member in groups" section, authz-related
+ "WHERE s = :subject " //
- + " AND g.visible = true "
- + " AND ( res.id = :resourceId OR :resourceId is null ) "
- + " AND ( g.id = :groupId OR :groupId is null ) "
+ + " AND g.visible = true " //
+ + " AND res.inventoryStatus = 'COMMITTED' " //
+ + " AND ( res.id = :resourceId OR :resourceId is null ) " //
+ + " AND ( g.id = :groupId OR :groupId is null ) " //
+ " AND ( g.groupCategory = :groupCategory OR :groupCategory is null ) " //
+ " AND (UPPER(g.name) LIKE :search " //
+ " OR UPPER(g.description) LIKE :search " //
+ "OR :search is null) " //
+ "AND ( type is null " //
- + " OR ( (type.name = :resourceTypeName OR :resourceTypeName is null) "
- + " AND (type.plugin = :pluginName OR :pluginName is null) "
+ + " OR ( (type.name = :resourceTypeName OR :resourceTypeName is null) " //
+ + " AND (type.plugin = :pluginName OR :pluginName is null) " //
+ " AND (type.category = :category OR :category is null) ) ) "),
@NamedQuery(name = ResourceGroup.QUERY_FIND_ALL_FILTERED_COUNT_ADMIN, query = "SELECT count(DISTINCT g) FROM ResourceGroup g "
+ "LEFT JOIN g.resourceType type "
+ "LEFT JOIN g.implicitResources res " // used for inventory>summary "member in groups" section, authz-related
- + "WHERE ( g.groupCategory = :groupCategory OR :groupCategory is null ) "
- + " AND g.visible = true "
- + " AND ( res.id = :resourceId OR :resourceId is null ) "
- + " AND ( g.id = :groupId OR :groupId is null ) "
- + " AND (UPPER(g.name) LIKE :search "
- + " OR UPPER(g.description) LIKE :search "
- + " OR :search is null) "
+ + "WHERE ( g.groupCategory = :groupCategory OR :groupCategory is null ) " //
+ + " AND g.visible = true " //
+ + " AND ( res.id = :resourceId OR :resourceId is null ) " //
+ + " AND res.inventoryStatus = 'COMMITTED' " //
+ + " AND ( g.id = :groupId OR :groupId is null ) " //
+ + " AND (UPPER(g.name) LIKE :search " //
+ + " OR UPPER(g.description) LIKE :search " //
+ + " OR :search is null) " //
+ "AND ( type is null " //
- + " OR ( (type.name = :resourceTypeName OR :resourceTypeName is null) "
- + " AND (type.plugin = :pluginName OR :pluginName is null) "
+ + " OR ( (type.name = :resourceTypeName OR :resourceTypeName is null) " //
+ + " AND (type.plugin = :pluginName OR :pluginName is null) " //
+ " AND (type.category = :category OR :category is null) ) ) "),
-
@NamedQuery(name = ResourceGroup.QUERY_FIND_RESOURCE_GROUP_SUMMARY, query = "" //
+ "SELECT rg.groupCategory, COUNT(DISTINCT rg) " //
+ " FROM ResourceGroup AS rg JOIN rg.roles r JOIN r.subjects s " //
@@ -181,8 +182,11 @@ import org.rhq.core.domain.tagging.Tag;
+ "FROM Resource res JOIN res.currentAvailability a "
+ "WHERE res.id = :resourceId "
+ "GROUP BY res.resourceType "),
- @NamedQuery(name = ResourceGroup.QUERY_FIND_RESOURCE_NAMES_BY_GROUP_ID, query = "SELECT new org.rhq.core.domain.common.composite.IntegerOptionItem(res.id, res.name) "
- + " FROM ResourceGroup g " + " JOIN g.explicitResources res " + " WHERE g.id = :groupId "),
+ @NamedQuery(name = ResourceGroup.QUERY_FIND_RESOURCE_NAMES_BY_GROUP_ID, query = ""
+ + "SELECT new org.rhq.core.domain.common.composite.IntegerOptionItem(res.id, res.name) " //
+ + " FROM ResourceGroup g " //
+ + " JOIN g.explicitResources res " //
+ + " WHERE g.id = :groupId AND res.inventoryStatus = 'COMMITTED' "),
@NamedQuery(name = ResourceGroup.QUERY_FIND_BY_GROUP_DEFINITION_AND_EXPRESSION, query = "SELECT g "
+ " FROM ResourceGroup g " + " WHERE (g.groupByClause = :groupByClause OR :groupByClause IS NULL) "
+ " AND g.groupDefinition.id = :groupDefinitionId "),
@@ -193,7 +197,7 @@ import org.rhq.core.domain.tagging.Tag;
+ " AND res.id NOT IN ( SELECT explicitRes.id " //
+ " FROM ResourceGroup rg " //
+ " JOIN rg.explicitResources explicitRes " //
- + " WHERE rg.id = :groupId ) ") })
+ + " WHERE rg.id = :groupId AND explicitRes.inventoryStatus = 'COMMITTED') ") })
@SequenceGenerator(name = "id", sequenceName = "RHQ_RESOURCE_GROUP_ID_SEQ")
@Table(name = "RHQ_RESOURCE_GROUP")
@XmlAccessorType(XmlAccessType.FIELD)
@@ -244,7 +248,7 @@ public class ResourceGroup extends Group {
+ " ON eresAvail.resource_id = eres.id "
+ " INNER JOIN rhq_resource_group_res_exp_map expMap "
+ " ON eres.id = expMap.resource_id "
- + " WHERE expMap.resource_group_id = rg.id AND eres.inventoryStatus = 'COMMITTED' "
+ + " WHERE expMap.resource_group_id = rg.id AND eres.inventory_status = 'COMMITTED' "
+ " ) as explicitCount, "
+ "" //
+ " ( SELECT COUNT(eresAvail.ID) " // DOWN explicit members
@@ -253,7 +257,7 @@ public class ResourceGroup extends Group {
+ " ON eresAvail.resource_id = eres.id "
+ " INNER JOIN rhq_resource_group_res_exp_map expMap "
+ " ON eres.id = expMap.resource_id "
- + " WHERE expMap.resource_group_id = rg.id AND eres.inventoryStatus = 'COMMITTED' "
+ + " WHERE expMap.resource_group_id = rg.id AND eres.inventory_status = 'COMMITTED' "
+ " AND eresAvail.availability_type = 0 "
+ " ) as explicitDown, "
+ "" //
@@ -263,7 +267,7 @@ public class ResourceGroup extends Group {
+ " ON eresAvail.resource_id = eres.id "
+ " INNER JOIN rhq_resource_group_res_exp_map expMap "
+ " ON eres.id = expMap.resource_id "
- + " WHERE expMap.resource_group_id = rg.id AND eres.inventoryStatus = 'COMMITTED' "
+ + " WHERE expMap.resource_group_id = rg.id AND eres.inventory_status = 'COMMITTED' "
+ " AND eresAvail.availability_type = 2 "
+ " ) as explicitUnknown, "
+ "" //
@@ -273,7 +277,7 @@ public class ResourceGroup extends Group {
+ " ON eresAvail.resource_id = eres.id "
+ " INNER JOIN rhq_resource_group_res_exp_map expMap "
+ " ON eres.id = expMap.resource_id "
- + " WHERE expMap.resource_group_id = rg.id AND eres.inventoryStatus = 'COMMITTED' "
+ + " WHERE expMap.resource_group_id = rg.id AND eres.inventory_status = 'COMMITTED' "
+ " AND eresAvail.availability_type = 3 "
+ " ) as explicitDisabled, "
+ "" //
@@ -283,7 +287,7 @@ public class ResourceGroup extends Group {
+ " ON iresAvail.resource_id = ires.id "
+ " INNER JOIN rhq_resource_group_res_imp_map impMap "
+ " ON ires.id = impMap.resource_id "
- + " WHERE impMap.resource_group_id = rg.id AND ires.inventoryStatus = 'COMMITTED' "
+ + " WHERE impMap.resource_group_id = rg.id AND ires.inventory_status = 'COMMITTED' "
+ " ) as implicitCount, "
+ "" //
+ " ( SELECT COUNT(iresAvail.ID) " // DOWN implicit members
@@ -292,7 +296,7 @@ public class ResourceGroup extends Group {
+ " ON iresAvail.resource_id = ires.id "
+ " INNER JOIN rhq_resource_group_res_imp_map impMap "
+ " ON ires.id = impMap.resource_id "
- + " WHERE impMap.resource_group_id = rg.id AND ires.inventoryStatus = 'COMMITTED' "
+ + " WHERE impMap.resource_group_id = rg.id AND ires.inventory_status = 'COMMITTED' "
+ " AND iresAvail.availability_type = 0 "
+ " ) as implicitDown, "
+ "" //
@@ -302,7 +306,7 @@ public class ResourceGroup extends Group {
+ " ON iresAvail.resource_id = ires.id "
+ " INNER JOIN rhq_resource_group_res_imp_map impMap "
+ " ON ires.id = impMap.resource_id "
- + " WHERE impMap.resource_group_id = rg.id AND ires.inventoryStatus = 'COMMITTED' "
+ + " WHERE impMap.resource_group_id = rg.id AND ires.inventory_status = 'COMMITTED' "
+ " AND iresAvail.availability_type = 2 "
+ " ) as implicitUnknown, "
+ "" //
@@ -312,7 +316,7 @@ public class ResourceGroup extends Group {
+ " ON iresAvail.resource_id = ires.id "
+ " INNER JOIN rhq_resource_group_res_imp_map impMap "
+ " ON ires.id = impMap.resource_id "
- + " WHERE impMap.resource_group_id = rg.id AND ires.inventoryStatus = 'COMMITTED' "
+ + " WHERE impMap.resource_group_id = rg.id AND ires.inventory_status = 'COMMITTED' "
+ " AND iresAvail.availability_type = 3 "
+ " ) as implicitDisabled, "
+ "" //
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/cluster/ClusterManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/cluster/ClusterManagerBean.java
index 7a86705..4573b9c 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/cluster/ClusterManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/cluster/ClusterManagerBean.java
@@ -357,7 +357,8 @@ public class ClusterManagerBean implements ClusterManagerLocal, ClusterManagerRe
// this is an authorization-related query, so use implicitResource (not explicitResources)
if (1 == size) {
- query.append("SELECT rgir FROM ResourceGroup rg JOIN rg.implicitResources rgir WHERE rg = "
+ query
+ .append("SELECT rgir FROM ResourceGroup rg JOIN rg.implicitResources rgir WHERE rgir.inventoryStatus = 'COMMITTED' AND rg = "
+ clusterKey.getClusterGroupId());
} else {
buildQuery(query, params, clusterKey, nodes.subList(0, size - 1));
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java
index a1d623f..e05b1bb 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java
@@ -1232,7 +1232,7 @@ public class ResourceGroupManagerBean implements ResourceGroupManagerLocal, Reso
List<Integer> groupIds = new ArrayList<Integer>();
for (Object[] row : rawResults) {
- groupIds.add(((Number) row[4]).intValue());
+ groupIds.add(((Number) row[8]).intValue());
}
Map<Integer, ResourceGroup> groupMap = getIdGroupMap(groupIds);
@@ -1403,26 +1403,26 @@ public class ResourceGroupManagerBean implements ResourceGroupManagerLocal, Reso
// all the subselects.
String queryString = "SELECT \n" //
+ " (SELECT count(er) " // Total explicit
- + " FROM ResourceGroup g JOIN g.explicitResources er where g.id = :groupId),\n"
+ + " FROM ResourceGroup g JOIN g.explicitResources er where er.inventoryStatus = 'COMMITTED' and g.id = :groupId),\n"
+ " (SELECT count(er) " // DOWN explicit
- + " FROM ResourceGroup g JOIN g.explicitResources er where g.id = :groupId"
+ + " FROM ResourceGroup g JOIN g.explicitResources er where er.inventoryStatus = 'COMMITTED' and g.id = :groupId"
+ " AND er.currentAvailability.availabilityType = 0 ),\n"
+ " (SELECT count(er) " // UNKNOWN explicit
- + " FROM ResourceGroup g JOIN g.explicitResources er where g.id = :groupId"
+ + " FROM ResourceGroup g JOIN g.explicitResources er where er.inventoryStatus = 'COMMITTED' and g.id = :groupId"
+ " AND er.currentAvailability.availabilityType = 2 ),\n"
+ " (SELECT count(er) " // DISABLED explicit
- + " FROM ResourceGroup g JOIN g.explicitResources er where g.id = :groupId"
+ + " FROM ResourceGroup g JOIN g.explicitResources er where er.inventoryStatus = 'COMMITTED' and g.id = :groupId"
+ " AND er.currentAvailability.availabilityType = 3 ),\n"
+ " (SELECT count(ir) " // Total implicit
- + " FROM ResourceGroup g JOIN g.implicitResources ir where g.id = :groupId),\n"
+ + " FROM ResourceGroup g JOIN g.implicitResources ir where ir.inventoryStatus = 'COMMITTED' and g.id = :groupId),\n"
+ " (SELECT count(ir) " // DOWN implicit
- + " FROM ResourceGroup g JOIN g.implicitResources ir where g.id = :groupId"
+ + " FROM ResourceGroup g JOIN g.implicitResources ir where ir.inventoryStatus = 'COMMITTED' and g.id = :groupId"
+ " AND ir.currentAvailability.availabilityType = 0 ),\n"
+ " (SELECT count(ir) " // UNKNOWN implicit
- + " FROM ResourceGroup g JOIN g.implicitResources ir where g.id = :groupId"
+ + " FROM ResourceGroup g JOIN g.implicitResources ir where ir.inventoryStatus = 'COMMITTED' and g.id = :groupId"
+ " AND ir.currentAvailability.availabilityType = 2 ),\n"
+ " (SELECT count(ir) " // DISABLED implicit
- + " FROM ResourceGroup g JOIN g.implicitResources ir where g.id = :groupId"
+ + " FROM ResourceGroup g JOIN g.implicitResources ir where ir.inventoryStatus = 'COMMITTED' and g.id = :groupId"
+ " AND ir.currentAvailability.availabilityType = 3 )\n,"
+ " g "
+ "FROM ResourceGroup g where g.id = :groupId";
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/GroupWithUncommittedTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/GroupWithUncommittedTest.java
new file mode 100644
index 0000000..8ef992d
--- /dev/null
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/GroupWithUncommittedTest.java
@@ -0,0 +1,280 @@
+/*
+ * 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.resource.group.test;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.persistence.Query;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import org.rhq.core.domain.authz.Permission;
+import org.rhq.core.domain.common.composite.IntegerOptionItem;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.measurement.Availability;
+import org.rhq.core.domain.resource.InventoryStatus;
+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.resource.group.composite.ResourceGroupComposite;
+import org.rhq.core.domain.server.PersistenceUtility;
+import org.rhq.core.domain.util.PageControl;
+import org.rhq.core.domain.util.PageList;
+import org.rhq.enterprise.server.resource.group.ResourceGroupManagerLocal;
+import org.rhq.enterprise.server.test.LargeGroupTestBase;
+import org.rhq.enterprise.server.test.TestServerCommunicationsService;
+import org.rhq.enterprise.server.util.LookupUtil;
+import org.rhq.enterprise.server.util.SessionTestHelper;
+
+@Test
+public class GroupWithUncommittedTest extends LargeGroupTestBase {
+
+ private static final boolean TESTS_ENABLED = true;
+ private ResourceGroupManagerLocal rgMgr;
+ private LargeGroupEnvironment env;
+
+ private class GroupAvailCounts {
+ public final int up;
+ public final int down;
+ public final int unknown;
+ public final int disabled;
+ public final int uncommitted;
+ public final int total;
+ public final int visibleTotal;
+
+ GroupAvailCounts(int up, int down, int unknown, int disabled, int uncommitted) {
+ this.up = up;
+ this.down = down;
+ this.unknown = unknown;
+ this.disabled = disabled;
+ this.uncommitted = uncommitted;
+ this.total = up + down + unknown + disabled + uncommitted;
+ this.visibleTotal = up + down + unknown + disabled; // uncommitted is not included
+ assert this.visibleTotal != this.total : "all of our tests should have at least 1 uncommitted resource";
+ }
+ }
+
+ @Override
+ protected void setupMockAgentServices(TestServerCommunicationsService agentServiceContainer) {
+ }
+
+ @BeforeMethod
+ public void getManagers() {
+ this.rgMgr = LookupUtil.getResourceGroupManager();
+ }
+
+ /**
+ * Remove the group and all its members.
+ */
+ @AfterMethod(alwaysRun = true)
+ public void teardownEnv() throws Exception {
+ if (env != null) {
+ tearDownLargeGroupWithNormalUserRoleAccess(env, false);
+ SessionTestHelper.simulateLogout(env.normalSubject);
+ }
+ env = null;
+ }
+
+ @Test(enabled = TESTS_ENABLED)
+ public void testResourceGroupQueries() throws Exception {
+ GroupAvailCounts gac = new GroupAvailCounts(1, 1, 1, 1, 1);
+ env = createLargeGroupWithNormalUserRoleAccessWithInventoryStatus(null, gac.total, gac.down, gac.unknown,
+ gac.disabled, gac.uncommitted, Permission.CONFIGURE_READ);
+ assert null != pickUncommittedResource(env.platformResource) : "there should have been an uncommitted resource";
+
+ SessionTestHelper.simulateLogin(env.normalSubject);
+
+ // these queries were tweeked to filter uncommitted - see BZ 820981
+ PageList<ResourceGroupComposite> results = rgMgr.findResourceGroupComposites(env.normalSubject, null, null,
+ null, null, null, null, env.compatibleGroup.getId(), new PageControl(0, 50));
+ int count = results.size();
+ assert count == 1 : "results=" + results;
+ ResourceGroupComposite rgc = results.get(0);
+ assert rgc.getExplicitCount() == gac.visibleTotal;
+ assert rgc.getImplicitCount() == gac.visibleTotal;
+ }
+
+ @Test(enabled = TESTS_ENABLED)
+ public void testGetResourceNameOptionItems() {
+ GroupAvailCounts gac = new GroupAvailCounts(1, 1, 1, 1, 1);
+ env = createLargeGroupWithNormalUserRoleAccessWithInventoryStatus(null, gac.total, gac.down, gac.unknown,
+ gac.disabled, gac.uncommitted, Permission.CONFIGURE_READ);
+ assert null != pickUncommittedResource(env.platformResource) : "there should have been an uncommitted resource";
+
+ SessionTestHelper.simulateLogin(env.normalSubject);
+
+ // this uses ResourceGroup.QUERY_FIND_RESOURCE_NAMES_BY_GROUP_ID which was tweeked due to BZ 820981
+ List<IntegerOptionItem> results = LookupUtil.getOperationManager().getResourceNameOptionItems(
+ env.compatibleGroup.getId());
+ int count = results.size();
+ assert count == gac.visibleTotal : "results=" + results;
+ }
+
+ @Test(enabled = TESTS_ENABLED)
+ public void testAnotherResourceGroupQuery() throws Exception {
+ GroupAvailCounts gac = new GroupAvailCounts(1, 1, 1, 1, 1);
+ env = createLargeGroupWithNormalUserRoleAccessWithInventoryStatus(null, gac.total, gac.down, gac.unknown,
+ gac.disabled, gac.uncommitted, Permission.CONFIGURE_READ);
+ assert null != pickUncommittedResource(env.platformResource) : "there should have been an uncommitted resource";
+
+ SessionTestHelper.simulateLogin(env.normalSubject);
+
+ // this query was tweeked to filter uncommitted - see BZ 820981
+ // we aren't really testing recursive groups - so we don't have any resources in implicit list that isn't in explicit
+ // but run this query anyway to make sure it can successfully run - we'll check that we get back 0 rows.
+ Query q = getEntityManager().createNamedQuery(ResourceGroup.QUERY_FIND_RESOURCE_IDS_NOT_IN_GROUP_EXPLICIT);
+ q.setParameter("groupId", env.compatibleGroup.getId());
+ q.setParameter("resourceIds",
+ Collections.singletonList(env.platformResource.getChildResources().iterator().next().getId())); // just pick any ID, it won't match anyway
+ List<?> results = q.getResultList();
+ assert results.isEmpty() : "results should have been empty" + results;
+ }
+
+ @Test(enabled = TESTS_ENABLED)
+ public void testResourceTypeQueries() throws Exception {
+ GroupAvailCounts gac = new GroupAvailCounts(1, 1, 1, 1, 1);
+ env = createLargeGroupWithNormalUserRoleAccessWithInventoryStatus(null, gac.total, gac.down, gac.unknown,
+ gac.disabled, gac.uncommitted, Permission.CONFIGURE_READ);
+ assert null != pickUncommittedResource(env.platformResource) : "there should have been an uncommitted resource";
+
+ SessionTestHelper.simulateLogin(env.normalSubject);
+
+ // these queries were tweeked to filter uncommitted - see BZ 820981
+ Query q = getEntityManager().createNamedQuery(ResourceType.QUERY_GET_EXPLICIT_RESOURCE_TYPE_COUNTS_BY_GROUP);
+ q.setParameter("groupId", env.compatibleGroup.getId());
+ List<?> results = q.getResultList();
+ int count = results.size();
+ assert count == 1 : "results=" + results;
+
+ q = getEntityManager().createNamedQuery(ResourceType.QUERY_GET_IMPLICIT_RESOURCE_TYPE_COUNTS_BY_GROUP);
+ q.setParameter("groupId", env.compatibleGroup.getId());
+ results = q.getResultList();
+ count = results.size();
+ assert count == 1 : "results=" + results;
+ }
+
+ @Test(enabled = TESTS_ENABLED)
+ public void testResourceQueries() throws Exception {
+ GroupAvailCounts gac = new GroupAvailCounts(1, 1, 1, 1, 1);
+ env = createLargeGroupWithNormalUserRoleAccessWithInventoryStatus(null, gac.total, gac.down, gac.unknown,
+ gac.disabled, gac.uncommitted, Permission.CONFIGURE_READ);
+ assert null != pickUncommittedResource(env.platformResource) : "there should have been an uncommitted resource";
+
+ SessionTestHelper.simulateLogin(env.normalSubject);
+
+ // these queries were tweeked to filter uncommitted - see BZ 820981
+ Query q = getEntityManager().createNamedQuery(Resource.QUERY_FIND_EXPLICIT_IDS_BY_RESOURCE_GROUP_ADMIN);
+ q.setParameter("groupId", env.compatibleGroup.getId());
+ List<?> results = q.getResultList();
+ int count = results.size();
+ assert count == gac.visibleTotal : "results=" + results;
+
+ q = getEntityManager().createNamedQuery(Resource.QUERY_FIND_IMPLICIT_IDS_BY_RESOURCE_GROUP_ADMIN);
+ q.setParameter("groupId", env.compatibleGroup.getId());
+ results = q.getResultList();
+ count = results.size();
+ assert count == gac.visibleTotal : "results=" + results;
+
+ q = getEntityManager().createNamedQuery(Resource.QUERY_FIND_BY_EXPLICIT_RESOURCE_GROUP);
+ q.setParameter("group", env.compatibleGroup);
+ q.setParameter("subject", env.normalSubject);
+ results = q.getResultList();
+ count = results.size();
+ assert count == gac.visibleTotal : "results=" + results;
+
+ q = getEntityManager().createNamedQuery(Resource.QUERY_FIND_BY_EXPLICIT_RESOURCE_GROUP_ADMIN);
+ q.setParameter("group", env.compatibleGroup);
+ results = q.getResultList();
+ count = results.size();
+ assert count == gac.visibleTotal : "results=" + results;
+
+ q = getEntityManager().createNamedQuery(Resource.QUERY_FIND_BY_IMPLICIT_RESOURCE_GROUP);
+ q.setParameter("group", env.compatibleGroup);
+ q.setParameter("subject", env.normalSubject);
+ results = q.getResultList();
+ count = results.size();
+ assert count == gac.visibleTotal : "results=" + results;
+
+ q = getEntityManager().createNamedQuery(Resource.QUERY_FIND_BY_IMPLICIT_RESOURCE_GROUP_ADMIN);
+ q.setParameter("group", env.compatibleGroup);
+ results = q.getResultList();
+ count = results.size();
+ assert count == gac.visibleTotal : "results=" + results;
+ }
+
+ @Test(enabled = TESTS_ENABLED)
+ public void testAvailGroupQueries() throws Exception {
+ GroupAvailCounts gac = new GroupAvailCounts(1, 1, 1, 1, 1);
+ env = createLargeGroupWithNormalUserRoleAccessWithInventoryStatus(null, gac.total, gac.down, gac.unknown,
+ gac.disabled, gac.uncommitted, Permission.CONFIGURE_READ);
+ assert null != pickUncommittedResource(env.platformResource) : "there should have been an uncommitted resource";
+
+ SessionTestHelper.simulateLogin(env.normalSubject);
+
+ // this query was tweeked to filter uncommitted - see BZ 820981
+ Query q = getEntityManager().createNamedQuery(Availability.FIND_FOR_RESOURCE_GROUP_WITHIN_INTERVAL);
+ q.setParameter("groupId", env.compatibleGroup.getId());
+ q.setParameter("start", 0L);
+ q.setParameter("end", System.currentTimeMillis());
+ List<?> results = q.getResultList();
+ int availCount = results.size();
+ assert availCount == gac.visibleTotal : "availCount=" + availCount;
+ }
+
+ @Test(enabled = TESTS_ENABLED)
+ public void testConfigGroupQueries() throws Exception {
+ GroupAvailCounts gac = new GroupAvailCounts(5, 4, 3, 2, 1);
+ env = createLargeGroupWithNormalUserRoleAccessWithInventoryStatus(null, gac.total, gac.down, gac.unknown,
+ gac.disabled, gac.uncommitted, Permission.CONFIGURE_READ);
+ assert null != pickUncommittedResource(env.platformResource) : "there should have been an uncommitted resource";
+
+ SessionTestHelper.simulateLogin(env.normalSubject);
+
+ // these queries were tweeked to filter uncommitted - see BZ 820981
+ Query resConfigCountQuery = PersistenceUtility.createCountQuery(getEntityManager(),
+ Configuration.QUERY_GET_RESOURCE_CONFIG_MAP_BY_GROUP_ID);
+ resConfigCountQuery.setParameter("resourceGroupId", env.compatibleGroup.getId());
+ long resConfigCount = (Long) resConfigCountQuery.getSingleResult();
+
+ Query pluginConfigCountQuery = PersistenceUtility.createCountQuery(getEntityManager(),
+ Configuration.QUERY_GET_PLUGIN_CONFIG_MAP_BY_GROUP_ID);
+ pluginConfigCountQuery.setParameter("resourceGroupId", env.compatibleGroup.getId());
+ long pluginConfigCount = (Long) pluginConfigCountQuery.getSingleResult();
+
+ assert resConfigCount == gac.visibleTotal;
+ assert pluginConfigCount == gac.visibleTotal;
+
+ int groupSize = rgMgr.getExplicitGroupMemberCount(env.compatibleGroup.getId());
+ assert resConfigCount == groupSize;
+ assert pluginConfigCount == groupSize;
+
+ }
+
+ private Resource pickUncommittedResource(Resource platformResource) {
+ for (Resource r : platformResource.getChildResources()) {
+ if (r.getInventoryStatus() == InventoryStatus.NEW) {
+ return r;
+ }
+ }
+ return null;
+ }
+}
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/LargeGroupCriteriaTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/LargeGroupCriteriaTest.java
index 0c5d769..0759e72 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/LargeGroupCriteriaTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/group/test/LargeGroupCriteriaTest.java
@@ -19,6 +19,7 @@
package org.rhq.enterprise.server.resource.group.test;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import org.testng.annotations.AfterMethod;
@@ -26,8 +27,11 @@ import org.testng.annotations.Test;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.criteria.ResourceGroupCriteria;
+import org.rhq.core.domain.resource.InventoryStatus;
+import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.group.composite.ResourceGroupComposite;
import org.rhq.core.domain.util.PageList;
+import org.rhq.enterprise.server.authz.AuthorizationManagerLocal;
import org.rhq.enterprise.server.resource.group.ResourceGroupManagerLocal;
import org.rhq.enterprise.server.test.LargeGroupTestBase;
import org.rhq.enterprise.server.test.TestServerCommunicationsService;
@@ -37,21 +41,31 @@ import org.rhq.enterprise.server.util.SessionTestHelper;
@Test
public class LargeGroupCriteriaTest extends LargeGroupTestBase {
+ private static final boolean TEST_ENABLED = true;
+
private ArrayList<LargeGroupEnvironment> env;
private class GroupAvailCounts {
- public int up;
- public int down;
- public int unknown;
- public int disabled;
+ public final int up;
+ public final int down;
+ public final int unknown;
+ public final int disabled;
+ public final int uncommitted;
public final int total;
+ public final int visibleTotal;
GroupAvailCounts(int up, int down, int unknown, int disabled) {
+ this(up, down, unknown, disabled, 0);
+ }
+
+ GroupAvailCounts(int up, int down, int unknown, int disabled, int uncommitted) {
this.up = up;
this.down = down;
this.unknown = unknown;
this.disabled = disabled;
- this.total = up + down + unknown + disabled;
+ this.uncommitted = uncommitted;
+ this.total = up + down + unknown + disabled + uncommitted;
+ this.visibleTotal = up + down + unknown + disabled; // uncommitted is not included
}
}
@@ -76,6 +90,7 @@ public class LargeGroupCriteriaTest extends LargeGroupTestBase {
}
}
+ @Test(enabled = TEST_ENABLED)
public void testSearchBarAvailabilityQueryUP() throws Exception {
GroupAvailCounts gac = new GroupAvailCounts(5, 0, 0, 0);
PageList<ResourceGroupComposite> pageList = testGroupQueriesWithSearchBar(gac, "availability=up");
@@ -86,6 +101,7 @@ public class LargeGroupCriteriaTest extends LargeGroupTestBase {
assert pageList.size() == 0;
}
+ @Test(enabled = TEST_ENABLED)
public void testSearchBarAvailabilityQueryDOWN() throws Exception {
GroupAvailCounts gac = new GroupAvailCounts(0, 5, 0, 0);
PageList<ResourceGroupComposite> pageList = testGroupQueriesWithSearchBar(gac, "availability=down");
@@ -96,6 +112,7 @@ public class LargeGroupCriteriaTest extends LargeGroupTestBase {
assert pageList.size() == 0;
}
+ @Test(enabled = TEST_ENABLED)
public void testSearchBarAvailabilityQueryDISABLED() throws Exception {
GroupAvailCounts gac = new GroupAvailCounts(0, 0, 0, 5);
PageList<ResourceGroupComposite> pageList = testGroupQueriesWithSearchBar(gac, "availability=disabled");
@@ -106,6 +123,7 @@ public class LargeGroupCriteriaTest extends LargeGroupTestBase {
assert pageList.size() == 0;
}
+ @Test(enabled = TEST_ENABLED)
public void testSearchBarAvailabilityQueryMIXED() throws Exception {
// when a group has a mix of up/down/disabled resources, it will not be returned with the avail search expression
GroupAvailCounts gac = new GroupAvailCounts(2, 2, 0, 2);
@@ -121,6 +139,22 @@ public class LargeGroupCriteriaTest extends LargeGroupTestBase {
assert pageList.size() == 0;
}
+ @Test(enabled = TEST_ENABLED)
+ public void testUncommitted() throws Exception {
+ ArrayList<GroupAvailCounts> gacs = new ArrayList<LargeGroupCriteriaTest.GroupAvailCounts>();
+ gacs.add(new GroupAvailCounts(1, 1, 1, 1, 1));
+ testGroupQueries(gacs);
+ }
+
+ @Test(enabled = TEST_ENABLED)
+ public void testSmallGroupsWithUncommitted() throws Exception {
+ ArrayList<GroupAvailCounts> gacs = new ArrayList<LargeGroupCriteriaTest.GroupAvailCounts>();
+ gacs.add(new GroupAvailCounts(8, 4, 2, 1, 1));
+ gacs.add(new GroupAvailCounts(2, 4, 6, 8, 10));
+ testGroupQueries(gacs);
+ }
+
+ @Test(enabled = TEST_ENABLED)
public void testSmallGroups() throws Exception {
ArrayList<GroupAvailCounts> gacs = new ArrayList<LargeGroupCriteriaTest.GroupAvailCounts>();
gacs.add(new GroupAvailCounts(8, 4, 2, 1));
@@ -128,6 +162,7 @@ public class LargeGroupCriteriaTest extends LargeGroupTestBase {
testGroupQueries(gacs);
}
+ @Test(enabled = TEST_ENABLED)
public void testLotsOfSmallGroups() throws Exception {
ArrayList<GroupAvailCounts> gacs = new ArrayList<LargeGroupCriteriaTest.GroupAvailCounts>();
for (int i = 0; i < 50; i++) {
@@ -137,12 +172,14 @@ public class LargeGroupCriteriaTest extends LargeGroupTestBase {
testGroupQueries(gacs);
}
+ @Test(enabled = TEST_ENABLED)
public void testLargeGroup() throws Exception {
ArrayList<GroupAvailCounts> gacs = new ArrayList<LargeGroupCriteriaTest.GroupAvailCounts>();
gacs.add(new GroupAvailCounts(500, 250, 150, 110)); // purposefully over 1,000
testGroupQueries(gacs);
}
+ @Test(enabled = TEST_ENABLED)
public void testLotsOfLargeGroups() throws Exception {
ArrayList<GroupAvailCounts> gacs = new ArrayList<LargeGroupCriteriaTest.GroupAvailCounts>();
for (int i = 0; i < 5; i++) {
@@ -159,8 +196,8 @@ public class LargeGroupCriteriaTest extends LargeGroupTestBase {
env = new ArrayList<LargeGroupEnvironment>(1);
LargeGroupEnvironment lgeWithTypes = null;
- env.add(createLargeGroupWithNormalUserRoleAccess(lgeWithTypes, gac.total, gac.down,
- gac.unknown, gac.disabled, Permission.CONFIGURE_READ));
+ env.add(createLargeGroupWithNormalUserRoleAccessWithInventoryStatus(lgeWithTypes, gac.total, gac.down,
+ gac.unknown, gac.disabled, gac.uncommitted, Permission.CONFIGURE_READ));
ResourceGroupCriteria criteria;
PageList<ResourceGroupComposite> pageList;
@@ -178,13 +215,14 @@ public class LargeGroupCriteriaTest extends LargeGroupTestBase {
private void testGroupQueries(ArrayList<GroupAvailCounts> groupAvailCounts) throws Exception {
ResourceGroupManagerLocal groupManager = LookupUtil.getResourceGroupManager();
+ AuthorizationManagerLocal authManager = LookupUtil.getAuthorizationManager();
env = new ArrayList<LargeGroupEnvironment>(groupAvailCounts.size());
LargeGroupEnvironment lgeWithTypes = null;
for (GroupAvailCounts gac : groupAvailCounts) {
- env.add(createLargeGroupWithNormalUserRoleAccess(lgeWithTypes, gac.total, gac.down, gac.unknown,
- gac.disabled, Permission.CONFIGURE_READ));
+ env.add(createLargeGroupWithNormalUserRoleAccessWithInventoryStatus(lgeWithTypes, gac.total, gac.down,
+ gac.unknown, gac.disabled, gac.uncommitted, Permission.CONFIGURE_READ));
lgeWithTypes = env.get(0);
}
@@ -207,12 +245,24 @@ public class LargeGroupCriteriaTest extends LargeGroupTestBase {
assert pageList.size() == 1 : "the query should only have selected the one group for our user";
groupComp = pageList.get(0);
System.out.println("-->" + groupComp);
- assert groupComp.getExplicitCount() == gac.total;
+ assert groupComp.getExplicitCount() == gac.visibleTotal;
assert groupComp.getExplicitCount() == groupComp.getImplicitCount(); // we aren't testing recursive groups
assert groupComp.getExplicitUp() == gac.up;
assert groupComp.getExplicitDown() == gac.down;
assert groupComp.getExplicitUnknown() == gac.unknown;
assert groupComp.getExplicitDisabled() == gac.disabled;
+
+ // mainly to help test when there are uncommitted resources in the group - see BZ 820981
+ Resource committed = pickAResourceWithInventoryStatus(lge.platformResource, InventoryStatus.COMMITTED);
+ assert true == authManager.hasResourcePermission(lge.normalSubject, Permission.CONFIGURE_READ,
+ Collections.singletonList(committed.getId()));
+ assert false == authManager.hasResourcePermission(lge.normalSubject, Permission.CONTROL,
+ Collections.singletonList(committed.getId())); // we weren't given CONTROL perms on the committed resource
+ Resource uncommitted = pickAResourceWithInventoryStatus(lge.platformResource, InventoryStatus.NEW);
+ if (uncommitted != null) {
+ assert false == authManager.hasResourcePermission(lge.normalSubject, Permission.CONFIGURE_READ,
+ Collections.singletonList(uncommitted.getId())); // no permissions for uncommitted resource
+ }
}
// test getResourceGroupComposite
@@ -225,7 +275,7 @@ public class LargeGroupCriteriaTest extends LargeGroupTestBase {
groupComp = groupManager.getResourceGroupComposite(lge.normalSubject, lge.compatibleGroup.getId());
System.out.println("getResourceGroupComposite #" + i + "==>" + (System.currentTimeMillis() - start) + "ms");
System.out.println("-->" + groupComp);
- assert groupComp.getExplicitCount() == gac.total;
+ assert groupComp.getExplicitCount() == gac.visibleTotal;
assert groupComp.getExplicitCount() == groupComp.getImplicitCount(); // we aren't testing recursive groups
assert groupComp.getExplicitUp() == gac.up;
assert groupComp.getExplicitDown() == gac.down;
@@ -233,4 +283,14 @@ public class LargeGroupCriteriaTest extends LargeGroupTestBase {
assert groupComp.getExplicitDisabled() == gac.disabled;
}
}
+
+ private Resource pickAResourceWithInventoryStatus(Resource platformResource, InventoryStatus status) {
+ for (Resource r : platformResource.getChildResources()) {
+ if (r.getInventoryStatus() == status) {
+ return r;
+ }
+ }
+ return null;
+ }
}
+
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/LargeGroupTestBase.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/LargeGroupTestBase.java
index 089379e..1bf07d7 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/LargeGroupTestBase.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/LargeGroupTestBase.java
@@ -42,6 +42,7 @@ import org.rhq.core.domain.configuration.group.GroupPluginConfigurationUpdate;
import org.rhq.core.domain.configuration.group.GroupResourceConfigurationUpdate;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.resource.Agent;
+import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceCategory;
import org.rhq.core.domain.resource.ResourceType;
@@ -144,6 +145,12 @@ public abstract class LargeGroupTestBase extends AbstractEJB3Test {
return createLargeGroupWithNormalUserRoleAccess(null, groupSize, 0, 0, 0, permissions);
}
+ protected LargeGroupEnvironment createLargeGroupWithNormalUserRoleAccess(LargeGroupEnvironment largeGroupEnv,
+ final int groupSize, final int down, final int unknown, final int disabled, final Permission... permissions) {
+ return createLargeGroupWithNormalUserRoleAccessWithInventoryStatus(largeGroupEnv, groupSize, down, unknown,
+ disabled, 0, permissions);
+ }
+
/**
* Creates a compatible group of the given size. This also creates a normal user and a role
* and makes sure that user can access the group that was created. The role will be assigned the
@@ -156,11 +163,13 @@ public abstract class LargeGroupTestBase extends AbstractEJB3Test {
* @param down number of resources that are to be set as DOWN
* @param unknown number of resources whose availability status is to be marked as UNKNOWN
* @param disabled number of resources that are to be set as DISABLED
+ * @param uncommitted number of resources whose inventory status is not COMMITTED (will be NEW instead)
* @param permissions permissions to grant the new user via the new role.
* @return information about the entities that were created
*/
- protected LargeGroupEnvironment createLargeGroupWithNormalUserRoleAccess(LargeGroupEnvironment largeGroupEnv,
- final int groupSize, final int down, final int unknown, final int disabled, final Permission... permissions) {
+ protected LargeGroupEnvironment createLargeGroupWithNormalUserRoleAccessWithInventoryStatus(
+ LargeGroupEnvironment largeGroupEnv, final int groupSize, final int down, final int unknown,
+ final int disabled, final int uncommitted, final Permission... permissions) {
System.out.println("=====Creating a group with [" + groupSize + "] members");
@@ -224,9 +233,11 @@ public abstract class LargeGroupTestBase extends AbstractEJB3Test {
int downCount = down;
int unknownCount = unknown;
int disabledCount = disabled;
+ int uncommittedCount = uncommitted;
System.out.print("=====> Creating member Resources (this might take some time)...");
for (int i = 1; i <= groupSize; i++) {
AvailabilityType avail;
+ InventoryStatus inventoryStatus = InventoryStatus.COMMITTED;
if (downCount > 0) {
avail = AvailabilityType.DOWN;
downCount--;
@@ -236,6 +247,10 @@ public abstract class LargeGroupTestBase extends AbstractEJB3Test {
} else if (disabledCount > 0) {
avail = AvailabilityType.DISABLED;
disabledCount--;
+ } else if (uncommittedCount > 0) {
+ avail = AvailabilityType.UNKNOWN;
+ inventoryStatus = InventoryStatus.NEW;
+ uncommittedCount--;
} else {
avail = AvailabilityType.UP;
}
@@ -243,6 +258,7 @@ public abstract class LargeGroupTestBase extends AbstractEJB3Test {
Resource res = SessionTestHelper.createNewResourceForGroup(em, lge.compatibleGroup,
"LargeGroupTestServer", lge.serverType, avail, (i % 100) == 0);
res.setAgent(lge.agent);
+ res.setInventoryStatus(inventoryStatus);
lge.platformResource.addChildResource(res);
// give it an initial plugin configuration
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/util/SessionTestHelper.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/util/SessionTestHelper.java
index 7b3c55d..4b51224 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/util/SessionTestHelper.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/util/SessionTestHelper.java
@@ -34,6 +34,7 @@ import org.rhq.core.domain.authz.Role;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
import org.rhq.core.domain.configuration.definition.PropertySimpleType;
+import org.rhq.core.domain.measurement.Availability;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.ResourceAvailability;
import org.rhq.core.domain.resource.Agent;
@@ -212,7 +213,10 @@ public class SessionTestHelper {
Resource resource = new Resource(resourceName, resourceName, type);
resource.setUuid("" + new Random().nextInt());
resource.setInventoryStatus(InventoryStatus.COMMITTED);
+ resource.initCurrentAvailability(); // the only way I can see to intialize the avail list
resource.setCurrentAvailability(new ResourceAvailability(resource, avail));
+ resource.getAvailability().clear();
+ resource.getAvailability().add(new Availability(resource, 0L, avail));
group.addExplicitResource(resource);
resource.getExplicitGroups().add(group);
commit a20fedb416f53d49f89f8b1e32af3eb1ca53413a
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed May 9 16:27:48 2012 -0400
[BZ 819897] fix the left-hand tree on the group page - don't show non-committed resources
(cherry picked from commit 2e47850fbaf10e4203ae372fc74b4a97a41fb11e)
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/cluster/ClusterManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/cluster/ClusterManagerBean.java
index 9280ddf..7a86705 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/cluster/ClusterManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/cluster/ClusterManagerBean.java
@@ -191,9 +191,9 @@ public class ClusterManagerBean implements ClusterManagerLocal, ClusterManagerRe
"SELECT r.id, r.resourceType.id, r.parentResource.id, r.resourceKey, r.name, " //
+ " (SELECT count(r2)" //
+ " FROM Resource r2 JOIN r2.explicitGroups g2 " //
- + " WHERE g2.id = :groupId and r2.id = r.id) " //
+ + " WHERE g2.id = :groupId and r2.id = r.id and r2.inventoryStatus = 'COMMITTED') " //
+ " FROM Resource r join r.implicitGroups g " //
- + " WHERE g.id = :groupId ";
+ + " WHERE g.id = :groupId and r.inventoryStatus = 'COMMITTED' ";
Query query = entityManager.createQuery(queryString);
query.setParameter("groupId", groupId);
commit 65a890fa1f4084d26781aba3da0d06c1f38b6121
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed May 9 15:41:40 2012 -0400
[BZ 819897] filter out all non-committed resources from some group queries
(cherry picked from commit 4e1a3602aeca91102ee6585f87a5bf194693810b)
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceGroupCriteria.java b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceGroupCriteria.java
index 144a71d..dda954f 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceGroupCriteria.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceGroupCriteria.java
@@ -84,37 +84,37 @@ public class ResourceGroupCriteria extends TaggedCriteria {
+ "id IN ( SELECT implicitGroup.id " //
+ " FROM Resource res " //
+ " JOIN res.implicitGroups implicitGroup " //
- + " WHERE res.currentAvailability.availabilityType = 0 " //
+ + " WHERE res.currentAvailability.availabilityType = 0 AND res.inventoryStatus = 'COMMITTED' " //
+ " GROUP BY implicitGroup.id " //
+ " HAVING COUNT(res) >= ? )");
filterOverrides.put("explicitResourceIds", "" //
+ "id IN ( SELECT explicitGroup.id " //
+ " FROM Resource res " //
+ " JOIN res.explicitGroups explicitGroup " //
- + " WHERE res.id IN ( ? ) )");
+ + " WHERE res.id IN ( ? ) AND res.inventoryStatus = 'COMMITTED' )");
filterOverrides.put("implicitResourceIds", "" //
+ "id IN ( SELECT implicitGroup.id " //
+ " FROM Resource res " //
+ " JOIN res.implicitGroups implicitGroup " //
- + " WHERE res.id IN ( ? ) )");
+ + " WHERE res.id IN ( ? ) AND res.inventoryStatus = 'COMMITTED' )");
filterOverrides.put("explicitResourceCategory", "" //
+ "NOT EXISTS " //
+ "( SELECT res " //
+ " FROM Resource res " //
+ " JOIN res.explicitGroups explicitGroup " //
- + " WHERE resourcegroup.id = explicitGroup.id AND NOT res.resourceType.category = ? )");
+ + " WHERE resourcegroup.id = explicitGroup.id AND NOT res.resourceType.category = ? AND res.inventoryStatus = 'COMMITTED' )");
filterOverrides.put("explicitResourceTypeId", "" //
+ "NOT EXISTS " //
+ "( SELECT res " //
+ " FROM Resource res " //
+ " JOIN res.explicitGroups explicitGroup " //
- + " WHERE resourcegroup.id = explicitGroup.id AND NOT res.resourceType.id = ? )");
+ + " WHERE resourcegroup.id = explicitGroup.id AND NOT res.resourceType.id = ? AND res.inventoryStatus = 'COMMITTED' )");
filterOverrides.put("explicitResourceTypeName", "" //
+ "NOT EXISTS " //
+ "( SELECT res " //
+ " FROM Resource res " //
+ " JOIN res.explicitGroups explicitGroup " //
- + " WHERE resourcegroup.id = explicitGroup.id AND NOT res.resourceType.name = ? )");
+ + " WHERE resourcegroup.id = explicitGroup.id AND NOT res.resourceType.name = ? AND res.inventoryStatus = 'COMMITTED' )");
filterOverrides.put("groupDefinitionId", "groupDefinition.id = ?");
filterOverrides.put("ids", "id IN ( ? )");
filterOverrides.put("bundleTargetableOnly", "resourceType.bundleConfiguration IS NOT NULL");
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java
index 2a5c479..ba2e49c 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/group/ResourceGroup.java
@@ -244,7 +244,7 @@ public class ResourceGroup extends Group {
+ " ON eresAvail.resource_id = eres.id "
+ " INNER JOIN rhq_resource_group_res_exp_map expMap "
+ " ON eres.id = expMap.resource_id "
- + " WHERE expMap.resource_group_id = rg.id "
+ + " WHERE expMap.resource_group_id = rg.id AND eres.inventoryStatus = 'COMMITTED' "
+ " ) as explicitCount, "
+ "" //
+ " ( SELECT COUNT(eresAvail.ID) " // DOWN explicit members
@@ -253,7 +253,7 @@ public class ResourceGroup extends Group {
+ " ON eresAvail.resource_id = eres.id "
+ " INNER JOIN rhq_resource_group_res_exp_map expMap "
+ " ON eres.id = expMap.resource_id "
- + " WHERE expMap.resource_group_id = rg.id "
+ + " WHERE expMap.resource_group_id = rg.id AND eres.inventoryStatus = 'COMMITTED' "
+ " AND eresAvail.availability_type = 0 "
+ " ) as explicitDown, "
+ "" //
@@ -263,7 +263,7 @@ public class ResourceGroup extends Group {
+ " ON eresAvail.resource_id = eres.id "
+ " INNER JOIN rhq_resource_group_res_exp_map expMap "
+ " ON eres.id = expMap.resource_id "
- + " WHERE expMap.resource_group_id = rg.id "
+ + " WHERE expMap.resource_group_id = rg.id AND eres.inventoryStatus = 'COMMITTED' "
+ " AND eresAvail.availability_type = 2 "
+ " ) as explicitUnknown, "
+ "" //
@@ -273,7 +273,7 @@ public class ResourceGroup extends Group {
+ " ON eresAvail.resource_id = eres.id "
+ " INNER JOIN rhq_resource_group_res_exp_map expMap "
+ " ON eres.id = expMap.resource_id "
- + " WHERE expMap.resource_group_id = rg.id "
+ + " WHERE expMap.resource_group_id = rg.id AND eres.inventoryStatus = 'COMMITTED' "
+ " AND eresAvail.availability_type = 3 "
+ " ) as explicitDisabled, "
+ "" //
@@ -283,7 +283,7 @@ public class ResourceGroup extends Group {
+ " ON iresAvail.resource_id = ires.id "
+ " INNER JOIN rhq_resource_group_res_imp_map impMap "
+ " ON ires.id = impMap.resource_id "
- + " WHERE impMap.resource_group_id = rg.id "
+ + " WHERE impMap.resource_group_id = rg.id AND ires.inventoryStatus = 'COMMITTED' "
+ " ) as implicitCount, "
+ "" //
+ " ( SELECT COUNT(iresAvail.ID) " // DOWN implicit members
@@ -292,7 +292,7 @@ public class ResourceGroup extends Group {
+ " ON iresAvail.resource_id = ires.id "
+ " INNER JOIN rhq_resource_group_res_imp_map impMap "
+ " ON ires.id = impMap.resource_id "
- + " WHERE impMap.resource_group_id = rg.id "
+ + " WHERE impMap.resource_group_id = rg.id AND ires.inventoryStatus = 'COMMITTED' "
+ " AND iresAvail.availability_type = 0 "
+ " ) as implicitDown, "
+ "" //
@@ -302,7 +302,7 @@ public class ResourceGroup extends Group {
+ " ON iresAvail.resource_id = ires.id "
+ " INNER JOIN rhq_resource_group_res_imp_map impMap "
+ " ON ires.id = impMap.resource_id "
- + " WHERE impMap.resource_group_id = rg.id "
+ + " WHERE impMap.resource_group_id = rg.id AND ires.inventoryStatus = 'COMMITTED' "
+ " AND iresAvail.availability_type = 2 "
+ " ) as implicitUnknown, "
+ "" //
@@ -312,7 +312,7 @@ public class ResourceGroup extends Group {
+ " ON iresAvail.resource_id = ires.id "
+ " INNER JOIN rhq_resource_group_res_imp_map impMap "
+ " ON ires.id = impMap.resource_id "
- + " WHERE impMap.resource_group_id = rg.id "
+ + " WHERE impMap.resource_group_id = rg.id AND ires.inventoryStatus = 'COMMITTED' "
+ " AND iresAvail.availability_type = 3 "
+ " ) as implicitDisabled, "
+ "" //
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java
index b386bcd..a1d623f 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/group/ResourceGroupManagerBean.java
@@ -1553,28 +1553,28 @@ public class ResourceGroupManagerBean implements ResourceGroupManagerLocal, Reso
case SUBJECT_OWNED:
compositeProjection = ""
+ " new org.rhq.core.domain.resource.group.composite.ResourceGroupComposite( "
- + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail ) AS explicitCount," // explicit member count
- + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE avail.availabilityType = 0 ) AS explicitDown," // explicit member count with DOWN avail
- + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE avail.availabilityType = 2 ) AS explicitUnknown," // explicit member count with UNKNOWN avail
- + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE avail.availabilityType = 3 ) AS explicitDisabled," // explicit member count with DISABLED avail
- + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail ) AS implicitCount," // implicit member count
- + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE avail.availabilityType = 0 ) AS implicitDown," // implicit member count with DOWN avail
- + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE avail.availabilityType = 2 ) AS implicitUnknown," // implicit member count with UNKNOWN avail
- + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE avail.availabilityType = 3 ) AS implicitDisabled," // implicit member count with DISABLED avail
+ + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' ) AS explicitCount," // explicit member count
+ + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' AND avail.availabilityType = 0 ) AS explicitDown," // explicit member count with DOWN avail
+ + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' AND avail.availabilityType = 2 ) AS explicitUnknown," // explicit member count with UNKNOWN avail
+ + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' AND avail.availabilityType = 3 ) AS explicitDisabled," // explicit member count with DISABLED avail
+ + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' ) AS implicitCount," // implicit member count
+ + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' AND avail.availabilityType = 0 ) AS implicitDown," // implicit member count with DOWN avail
+ + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' AND avail.availabilityType = 2 ) AS implicitUnknown," // implicit member count with UNKNOWN avail
+ + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' AND avail.availabilityType = 3 ) AS implicitDisabled," // implicit member count with DISABLED avail
+ " %alias% ) "; // ResourceGroup
break;
case ROLE_OWNED:
case AUTO_CLUSTER:
compositeProjection = ""
+ " new org.rhq.core.domain.resource.group.composite.ResourceGroupComposite( "
- + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail ) AS explicitCount," // explicit member count
- + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE avail.availabilityType = 0 ) AS explicitDown," // explicit member count with DOWN avail
- + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE avail.availabilityType = 2 ) AS explicitUnknown," // explicit member count with UNKNOWN avail
- + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE avail.availabilityType = 3 ) AS explicitDisabled," // explicit member count with DISABLED avail
- + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail ) AS implicitCount," // implicit member count
- + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE avail.availabilityType = 0 ) AS implicitDown," // implicit member count with DOWN avail
- + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE avail.availabilityType = 2 ) AS implicitUnknown," // implicit member count with UNKNOWN avail
- + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE avail.availabilityType = 3 ) AS implicitDisabled," // implicit member count with DISABLED avail
+ + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' ) AS explicitCount," // explicit member count
+ + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' AND avail.availabilityType = 0 ) AS explicitDown," // explicit member count with DOWN avail
+ + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' AND avail.availabilityType = 2 ) AS explicitUnknown," // explicit member count with UNKNOWN avail
+ + " ( SELECT COUNT(avail) FROM %alias%.explicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' AND avail.availabilityType = 3 ) AS explicitDisabled," // explicit member count with DISABLED avail
+ + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' ) AS implicitCount," // implicit member count
+ + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' AND avail.availabilityType = 0 ) AS implicitDown," // implicit member count with DOWN avail
+ + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' AND avail.availabilityType = 2 ) AS implicitUnknown," // implicit member count with UNKNOWN avail
+ + " ( SELECT COUNT(avail) FROM %alias%.implicitResources res JOIN res.currentAvailability avail WHERE res.inventoryStatus = 'COMMITTED' AND avail.availabilityType = 3 ) AS implicitDisabled," // implicit member count with DISABLED avail
+ " %alias%, " // ResourceGroup
+ " ( SELECT count(p) FROM %permAlias%.roles r JOIN r.subjects s JOIN r.permissions p WHERE s.id = %subjectId% AND p = 8 ), " // MANAGE_MEASUREMENTS
+ " ( SELECT count(p) FROM %permAlias%.roles r JOIN r.subjects s JOIN r.permissions p WHERE s.id = %subjectId% AND p = 4 ), " // MODIFY_RESOURCE
11 years, 10 months
[rhq] Branch 'release/jon3.1.x' - 2 commits - modules/core modules/enterprise
by mazz
modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/configuration/ConfigurationUtility.java | 244 ------
modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/configuration/ConfigurationUtilityTest.java | 322 --------
modules/core/domain/src/main/java/org/rhq/core/domain/configuration/ConfigurationUtility.java | 334 +++++++++
modules/core/domain/src/test/java/org/rhq/core/domain/configuration/ConfigurationUtilityTest.java | 363 ++++++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/GetDeploymentConfigStep.java | 30
5 files changed, 738 insertions(+), 555 deletions(-)
New commits:
commit cb5116aa5c55f970a46ea81a59c8bdbbce2ccc04
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Jun 20 17:26:41 2012 -0400
[BZ 828843] fix bundle deploy wizard's configuration editor initialization so required properties that didn't exist in the live deployment config are set to their default values
(cherry picked from commit a5ef337f5921c5cc52fd6a96c084925c46b8f4a1)
diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/configuration/ConfigurationUtility.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/configuration/ConfigurationUtility.java
index 85ae0bb..6420978 100644
--- a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/configuration/ConfigurationUtility.java
+++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/configuration/ConfigurationUtility.java
@@ -22,31 +22,20 @@
*/
package org.rhq.core.clientapi.agent.configuration;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.rhq.core.domain.configuration.AbstractPropertyMap;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.Property;
-import org.rhq.core.domain.configuration.PropertyDefinitionDynamic;
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.configuration.PropertyMap;
-import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
-import org.rhq.core.domain.configuration.definition.PropertyDefinition;
-import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
-import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
-import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
/**
* Utility methods for working with {@link Configuration}s.
*
* @author Ian Springer
+ *
+ * @deprecated use the utility found in the domain module -org.rhq.core.domain.configuration.ConfigurationUtility
*/
public abstract class ConfigurationUtility {
@@ -60,21 +49,11 @@ public abstract class ConfigurationUtility {
* for it, this method is a no-op and will return immediately.
*
* @param configDef the configuration definition whose default template is to be created and set
+ *
+ * @deprecated use the utility found in the domain module -org.rhq.core.domain.configuration.ConfigurationUtility
*/
public static void initializeDefaultTemplate(ConfigurationDefinition configDef) {
- ConfigurationTemplate defaultTemplate = configDef.getDefaultTemplate();
- if (defaultTemplate == null) {
- Configuration defaultConfig = createDefaultConfiguration(configDef);
- // not everything should have a default template - only stuff that has default values
- if (!defaultConfig.getProperties().isEmpty()) {
- defaultTemplate = new ConfigurationTemplate(ConfigurationTemplate.DEFAULT_TEMPLATE_NAME,
- ConfigurationTemplate.DEFAULT_TEMPLATE_NAME);
- defaultTemplate.setDefault(true);
- defaultTemplate.setConfiguration(defaultConfig);
- configDef.putTemplate(defaultTemplate);
- }
- }
- return;
+ org.rhq.core.domain.configuration.ConfigurationUtility.initializeDefaultTemplate(configDef);
}
/**
@@ -87,17 +66,12 @@ public abstract class ConfigurationUtility {
*
* @param configurationDefinition the configuration definition whose default configuration is to be created
* @return configuration the default configuration
+ *
+ * @deprecated use the utility found in the domain module -org.rhq.core.domain.configuration.ConfigurationUtility
*/
public static Configuration createDefaultConfiguration(ConfigurationDefinition configurationDefinition) {
- if (configurationDefinition == null) {
- throw new IllegalArgumentException("configurationDefinition == null");
- }
- Configuration defaultConfig = new Configuration();
- Map<String, PropertyDefinition> childPropertyDefinitions = configurationDefinition.getPropertyDefinitions();
- for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) {
- createDefaultProperty(childPropertyDefinition, defaultConfig);
- }
- return defaultConfig;
+ return org.rhq.core.domain.configuration.ConfigurationUtility
+ .createDefaultConfiguration(configurationDefinition);
}
/**
@@ -107,19 +81,13 @@ public abstract class ConfigurationUtility {
*
* @param configuration the configuration to be normalized
* @param configurationDefinition the configuration definition to normalize the configuration against
+ *
+ * @deprecated use the utility found in the domain module -org.rhq.core.domain.configuration.ConfigurationUtility
*/
public static void normalizeConfiguration(@NotNull Configuration configuration,
@Nullable ConfigurationDefinition configurationDefinition) {
- //noinspection ConstantConditions
- if (configuration == null) {
- throw new IllegalArgumentException("Configuration parameter is null.");
- }
- if (configurationDefinition != null) {
- Map<String, PropertyDefinition> childPropertyDefinitions = configurationDefinition.getPropertyDefinitions();
- for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) {
- normalizeProperty(childPropertyDefinition, configuration);
- }
- }
+ org.rhq.core.domain.configuration.ConfigurationUtility.normalizeConfiguration(configuration,
+ configurationDefinition, false, false);
}
/**
@@ -132,191 +100,13 @@ public abstract class ConfigurationUtility {
* @param configurationDefinition the configuration definition to validate the configuration against
*
* @return a list of messages describing any errors that were found
+ *
+ * @deprecated use the utility found in the domain module -org.rhq.core.domain.configuration.ConfigurationUtility
*/
@NotNull
public static List<String> validateConfiguration(@NotNull Configuration configuration,
@Nullable ConfigurationDefinition configurationDefinition) {
- List<String> errorMessages = new ArrayList<String>();
- if (configurationDefinition != null) {
- Map<String, PropertyDefinition> childPropertyDefinitions = configurationDefinition.getPropertyDefinitions();
- for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) {
- validateProperty(childPropertyDefinition, configuration, errorMessages);
- }
- }
- return errorMessages;
- }
-
- private static void createDefaultProperty(PropertyDefinition propertyDefinition,
- AbstractPropertyMap parentPropertyMap) {
-
- Property property = null;
-
- if (propertyDefinition instanceof PropertyDefinitionSimple) {
- String defaultValue = ((PropertyDefinitionSimple) propertyDefinition).getDefaultValue();
- if (defaultValue != null || propertyDefinition.isRequired()) {
- property = new PropertySimple(propertyDefinition.getName(), defaultValue);
- }
- } else if (propertyDefinition.isRequired()) {
- if (propertyDefinition instanceof PropertyDefinitionMap) {
- property = new PropertyMap(propertyDefinition.getName());
- Map<String, PropertyDefinition> childPropertyDefinitions = ((PropertyDefinitionMap) propertyDefinition)
- .getMap();
- for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) {
- createDefaultProperty(childPropertyDefinition, (PropertyMap) property);
- }
- } else if (propertyDefinition instanceof PropertyDefinitionList) {
- property = new PropertyList(propertyDefinition.getName());
- PropertyDefinition listMemberPropertyDefinition = ((PropertyDefinitionList) propertyDefinition)
- .getMemberDefinition();
- if (listMemberPropertyDefinition.isRequired()) {
- if (listMemberPropertyDefinition instanceof PropertyDefinitionMap) {
- // member property is a list-o-maps, create a default child map if appropriate
- PropertyDefinitionMap listMemberDefinitionMap = (PropertyDefinitionMap) listMemberPropertyDefinition;
- PropertyMap listMap = new PropertyMap(listMemberDefinitionMap.getName());
- createDefaultProperty(listMemberDefinitionMap, listMap);
- ((PropertyList) property).add(listMap);
- } else if (listMemberPropertyDefinition instanceof PropertyDefinitionSimple) {
- // member property is a simple, create a single list entry as its default if appropriate
- PropertyDefinitionSimple listMemberDefinitionSimple = (PropertyDefinitionSimple) listMemberPropertyDefinition;
- String defaultValue = listMemberDefinitionSimple.getDefaultValue();
- if (defaultValue != null || listMemberDefinitionSimple.isRequired()) {
- PropertySimple listSimple = new PropertySimple(listMemberDefinitionSimple.getName(),
- defaultValue);
- ((PropertyList) property).add(listSimple);
- }
- }
- }
- } else if (propertyDefinition instanceof PropertyDefinitionDynamic) {
- // Dynamic property values should simply be stored as simple
- property = new PropertySimple(propertyDefinition.getName(), null);
- } else {
- throw new IllegalStateException("Unsupported PropertyDefinition subclass: "
- + propertyDefinition.getClass().getName());
- }
- }
-
- if (property != null) {
- parentPropertyMap.put(property);
- }
- }
-
- private static void normalizeProperty(PropertyDefinition propertyDefinition, AbstractPropertyMap parentPropertyMap) {
- if (parentPropertyMap.getMap().keySet().contains(propertyDefinition.getName())) // property is already set
- {
- if (propertyDefinition instanceof PropertyDefinitionSimple) {
- PropertySimple propertySimple = parentPropertyMap.getSimple(propertyDefinition.getName());
- String value = propertySimple.getStringValue();
- if (value != null) {
- if (value.equals("")) {
- // Normalize "" to null, since Oracle will do the same upon persistence.
- propertySimple.setStringValue(null);
- } else if (value.length() > PropertySimple.MAX_VALUE_LENGTH) {
- // Truncate the value to the max length allowed by the DB schema.
- propertySimple.setStringValue(value.substring(0, PropertySimple.MAX_VALUE_LENGTH));
- }
- }
- }
-
- // If the property is a Map, recurse into it and normalize its child properties.
- else if (propertyDefinition instanceof PropertyDefinitionMap) {
- PropertyMap propertyMap = parentPropertyMap.getMap(propertyDefinition.getName());
- PropertyDefinitionMap propertyDefinitionMap = (PropertyDefinitionMap) propertyDefinition;
- normalizePropertyMap(propertyMap, propertyDefinitionMap);
- } else if (propertyDefinition instanceof PropertyDefinitionList) {
- PropertyDefinitionList propertyDefinitionList = (PropertyDefinitionList) propertyDefinition;
- PropertyDefinition listMemberPropertyDefinition = propertyDefinitionList.getMemberDefinition();
-
- // If the property is a List of Maps, iterate the list, and recurse into each Map and verify its child
- // properties.
- if (listMemberPropertyDefinition instanceof PropertyDefinitionMap) {
- PropertyDefinitionMap propertyDefinitionMap = (PropertyDefinitionMap) listMemberPropertyDefinition;
- PropertyList propertyList = parentPropertyMap.getList(propertyDefinition.getName());
- for (Property property : propertyList.getList()) {
- PropertyMap propertyMap = (PropertyMap) property;
- normalizePropertyMap(propertyMap, propertyDefinitionMap);
- }
- }
- }
- } else // property is not set yet
- {
- Property property;
- if (propertyDefinition instanceof PropertyDefinitionSimple) {
- property = new PropertySimple(propertyDefinition.getName(), null);
- } else if (propertyDefinition instanceof PropertyDefinitionMap) {
- property = new PropertyMap(propertyDefinition.getName());
- } else if (propertyDefinition instanceof PropertyDefinitionList) {
- property = new PropertyList(propertyDefinition.getName());
- } else if (propertyDefinition instanceof PropertyDefinitionDynamic) {
- // Dynamic property values should simply be stored as simple
- property = new PropertySimple(propertyDefinition.getName(), null);
- } else {
- throw new IllegalStateException("Unsupported PropertyDefinition subclass: "
- + propertyDefinition.getClass().getName());
- }
-
- parentPropertyMap.put(property);
- }
- }
-
- private static void normalizePropertyMap(AbstractPropertyMap propertyMap,
- PropertyDefinitionMap propertyDefinitionMap) {
- Map<String, PropertyDefinition> childPropertyDefinitions = propertyDefinitionMap.getMap();
- for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) {
- normalizeProperty(childPropertyDefinition, propertyMap);
- }
- }
-
- private static void validateProperty(PropertyDefinition propertyDefinition, AbstractPropertyMap parentPropertyMap,
- List<String> errorMessages) {
- if (parentPropertyMap.getMap().keySet().contains(propertyDefinition.getName())) // property is already set
- {
- if (propertyDefinition instanceof PropertyDefinitionSimple) {
- PropertySimple propertySimple = parentPropertyMap.getSimple(propertyDefinition.getName());
- if (propertyDefinition.isRequired() && (propertySimple.getStringValue() == null)) {
- errorMessages.add("Required property '" + propertyDefinition.getName() + "' has a null value in "
- + parentPropertyMap + ".");
- propertySimple.setStringValue("");
- }
- }
-
- // If the property is a Map, recurse into it and validate its child properties.
- else if (propertyDefinition instanceof PropertyDefinitionMap) {
- PropertyMap propertyMap = parentPropertyMap.getMap(propertyDefinition.getName());
- PropertyDefinitionMap propertyDefinitionMap = (PropertyDefinitionMap) propertyDefinition;
- validatePropertyMap(propertyMap, propertyDefinitionMap, errorMessages);
- } else if (propertyDefinition instanceof PropertyDefinitionList) {
- PropertyDefinitionList propertyDefinitionList = (PropertyDefinitionList) propertyDefinition;
- PropertyDefinition listMemberPropertyDefinition = propertyDefinitionList.getMemberDefinition();
-
- // If the property is a List of Maps, iterate the list, and recurse into each Map and validate its child
- // properties.
- if (listMemberPropertyDefinition instanceof PropertyDefinitionMap) {
- PropertyDefinitionMap propertyDefinitionMap = (PropertyDefinitionMap) listMemberPropertyDefinition;
- PropertyList propertyList = parentPropertyMap.getList(propertyDefinition.getName());
- for (Property property : propertyList.getList()) {
- PropertyMap propertyMap = (PropertyMap) property;
- validatePropertyMap(propertyMap, propertyDefinitionMap, errorMessages);
- }
- }
- }
- } else // property is not set yet
- {
- if (propertyDefinition.isRequired()) {
- errorMessages.add("Required property '" + propertyDefinition.getName() + "' was not set in "
- + parentPropertyMap + ".");
- if (propertyDefinition instanceof PropertyDefinitionSimple) {
- PropertySimple propertySimple = new PropertySimple(propertyDefinition.getName(), "");
- parentPropertyMap.put(propertySimple);
- }
- }
- }
- }
-
- private static void validatePropertyMap(AbstractPropertyMap propertyMap,
- PropertyDefinitionMap propertyDefinitionMap, List<String> errorMessages) {
- Map<String, PropertyDefinition> childPropertyDefinitions = propertyDefinitionMap.getMap();
- for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) {
- validateProperty(childPropertyDefinition, propertyMap, errorMessages);
- }
+ return org.rhq.core.domain.configuration.ConfigurationUtility.validateConfiguration(configuration,
+ configurationDefinition);
}
}
\ No newline at end of file
diff --git a/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/configuration/ConfigurationUtilityTest.java b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/configuration/ConfigurationUtilityTest.java
deleted file mode 100644
index 3f3dccd..0000000
--- a/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/configuration/ConfigurationUtilityTest.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * 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, 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.clientapi.agent.configuration;
-
-import org.testng.annotations.Test;
-
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.configuration.PropertyMap;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
-import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
-import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
-import org.rhq.core.domain.configuration.definition.PropertySimpleType;
-
-@Test
-public class ConfigurationUtilityTest {
- public void testCreateDefaultNone() {
- // no defaults, no required props - returned config should be empty
- ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
-
- PropertyDefinitionSimple simple = new PropertyDefinitionSimple("simple", null, false, PropertySimpleType.STRING);
- PropertyDefinitionMap map = new PropertyDefinitionMap("map", null, false, simple);
- PropertyDefinitionList list = new PropertyDefinitionList("list", null, false, simple);
-
- configDef.put(simple);
- configDef.put(map);
- configDef.put(list);
-
- Configuration config = ConfigurationUtility.createDefaultConfiguration(configDef);
- assert config != null;
- assert config.getProperties().size() == 0;
- }
-
- public void testCreateDefaultSimple() {
- ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
-
- PropertyDefinitionSimple simple = new PropertyDefinitionSimple("simple", null, false, PropertySimpleType.STRING);
- PropertyDefinitionSimple simpleRequired = new PropertyDefinitionSimple("simpleRequired", null, true,
- PropertySimpleType.STRING);
- PropertyDefinitionSimple simpleDefault = new PropertyDefinitionSimple("simpleDefault", null, false,
- PropertySimpleType.STRING);
- PropertyDefinitionSimple simpleRequiredDefault = new PropertyDefinitionSimple("simpleRequiredDefault", null,
- true, PropertySimpleType.STRING);
-
- simpleDefault.setDefaultValue("!!simpleDefaultValue!!");
- simpleRequiredDefault.setDefaultValue("!!simpleRequiredDefaultValue!!");
-
- configDef.put(simple);
- configDef.put(simpleRequired);
- configDef.put(simpleDefault);
- configDef.put(simpleRequiredDefault);
-
- Configuration config = ConfigurationUtility.createDefaultConfiguration(configDef);
- assert config != null;
- assert config.getProperties().size() == 3; // simple is not required with no default - its not in the config
- assert config.getSimple(simple.getName()) == null;
- assert config.getSimpleValue(simpleRequired.getName(), null) == null;
- assert config.getSimpleValue(simpleDefault.getName(), null).equals("!!simpleDefaultValue!!");
- assert config.getSimpleValue(simpleRequiredDefault.getName(), null).equals("!!simpleRequiredDefaultValue!!");
- }
-
- public void testCreateDefaultMap() {
- ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
-
- // a=not required, no default; c=not required, has default; d=required, has default
- PropertyDefinitionSimple a = new PropertyDefinitionSimple("a", null, false, PropertySimpleType.STRING);
- PropertyDefinitionSimple b = new PropertyDefinitionSimple("b", null, false, PropertySimpleType.STRING);
- PropertyDefinitionSimple c = new PropertyDefinitionSimple("c", null, true, PropertySimpleType.STRING);
- b.setDefaultValue("!!bDefaultValue!!");
- c.setDefaultValue("!!cDefaultValue!!");
-
- PropertyDefinitionMap map1 = new PropertyDefinitionMap("map1", null, false, a, b, c);
- PropertyDefinitionMap mapRequired1 = new PropertyDefinitionMap("mapRequired1", null, true, a, b, c);
- PropertyDefinitionMap mapRequiredDefault1 = new PropertyDefinitionMap("mapRequiredDefault1", null, true, a, b,
- c);
-
- configDef.put(map1);
- configDef.put(mapRequired1);
- configDef.put(mapRequiredDefault1);
-
- Configuration config = ConfigurationUtility.createDefaultConfiguration(configDef);
- assert config != null;
- assert config.getProperties().size() == 2; // map is not required with no default - its not in the config
- assert config.getMap(map1.getName()) == null;
-
- // the two required maps have the same definitions - a,b,c as above. since a isn't required with no default, its not there
- PropertyMap mapProp1 = config.getMap(mapRequired1.getName());
- assert mapProp1 != null;
- assert mapProp1.getSimple(a.getName()) == null;
- assert mapProp1.getSimpleValue(b.getName(), null).equals("!!bDefaultValue!!");
- assert mapProp1.getSimpleValue(c.getName(), null).equals("!!cDefaultValue!!");
-
- mapProp1 = config.getMap(mapRequiredDefault1.getName());
- assert mapProp1 != null;
- assert mapProp1.getSimple(a.getName()) == null;
- assert mapProp1.getSimpleValue(b.getName(), null).equals("!!bDefaultValue!!");
- assert mapProp1.getSimpleValue(c.getName(), null).equals("!!cDefaultValue!!");
- }
-
- public void testCreateDefaultList() {
- ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
-
- // a=not required, no default, b=required, has default
- PropertyDefinitionSimple a = new PropertyDefinitionSimple("a", null, false, PropertySimpleType.STRING);
- PropertyDefinitionSimple c = new PropertyDefinitionSimple("c", null, true, PropertySimpleType.STRING);
- c.setDefaultValue("!!cDefaultValue!!");
-
- PropertyDefinitionList list1 = new PropertyDefinitionList("list1", null, false, a);
- PropertyDefinitionList listRequired1 = new PropertyDefinitionList("listRequired1", null, true, a);
- PropertyDefinitionList listRequiredDefault1 = new PropertyDefinitionList("listRequiredDefault1", null, true, c);
-
- configDef.put(list1);
- configDef.put(listRequired1);
- configDef.put(listRequiredDefault1);
-
- Configuration config = ConfigurationUtility.createDefaultConfiguration(configDef);
- assert config != null;
- assert config.getProperties().size() == 2; // list is not required with no default - its not in the config
- assert config.getList(list1.getName()) == null;
-
- PropertyList listProp1 = config.getList(listRequired1.getName());
- assert listProp1 != null;
- assert listProp1.getList().isEmpty(); // has "a" definition, which is not required and has no default
-
- listProp1 = config.getList(listRequiredDefault1.getName());
- assert listProp1 != null;
- assert listProp1.getList().get(0).getName().equals(c.getName());
- assert ((PropertySimple) listProp1.getList().get(0)).getStringValue().equals("!!cDefaultValue!!");
- }
-
- public void testCreateDefaultListOMaps() {
- ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
-
- // a=not required, no default; c=not required, has default; d=required, has default
- PropertyDefinitionSimple a = new PropertyDefinitionSimple("a", null, false, PropertySimpleType.STRING);
- PropertyDefinitionSimple b = new PropertyDefinitionSimple("b", null, false, PropertySimpleType.STRING);
- PropertyDefinitionSimple c = new PropertyDefinitionSimple("c", null, true, PropertySimpleType.STRING);
- b.setDefaultValue("!!bDefaultValue!!");
- c.setDefaultValue("!!cDefaultValue!!");
-
- PropertyDefinitionMap map2 = new PropertyDefinitionMap("map2", null, false, a, b, c);
- PropertyDefinitionMap mapRequired2 = new PropertyDefinitionMap("mapRequired2", null, true, a, b, c);
- PropertyDefinitionMap mapRequiredDefault2 = new PropertyDefinitionMap("mapRequiredDefault2", null, true, a, b,
- c);
-
- PropertyDefinitionList listX = new PropertyDefinitionList("listX", null, true, map2);
- PropertyDefinitionList listY = new PropertyDefinitionList("listY", null, true, mapRequired2);
- PropertyDefinitionList listZ = new PropertyDefinitionList("listZ", null, true, mapRequiredDefault2);
-
- configDef.put(listX);
- configDef.put(listY);
- configDef.put(listZ);
-
- Configuration config = ConfigurationUtility.createDefaultConfiguration(configDef);
-
- assert config != null;
- assert config.getProperties().size() == 3;
-
- PropertyList listPropTest = config.getList(listX.getName());
- assert listPropTest != null;
- assert listPropTest.getList().isEmpty();
-
- listPropTest = config.getList(listY.getName());
- assert listPropTest != null;
- PropertyMap childMap2 = (PropertyMap) listPropTest.getList().get(0);
-
- listPropTest = config.getList(listZ.getName());
- assert listPropTest != null;
- PropertyMap childMap3 = (PropertyMap) listPropTest.getList().get(0);
-
- assert childMap2.getName().equals(mapRequired2.getName());
- assert childMap3.getName().equals(mapRequiredDefault2.getName());
- }
-
- public void testCreateDefaultAllSimpleMapList() {
- // tests a big config def that has simples, lists, maps - combination of the other individual tests
- ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
-
- // SETUP SIMPLE
-
- PropertyDefinitionSimple simple = new PropertyDefinitionSimple("simple", null, false, PropertySimpleType.STRING);
- PropertyDefinitionSimple simpleRequired = new PropertyDefinitionSimple("simpleRequired", null, true,
- PropertySimpleType.STRING);
- PropertyDefinitionSimple simpleDefault = new PropertyDefinitionSimple("simpleDefault", null, false,
- PropertySimpleType.STRING);
- PropertyDefinitionSimple simpleRequiredDefault = new PropertyDefinitionSimple("simpleRequiredDefault", null,
- true, PropertySimpleType.STRING);
-
- simpleDefault.setDefaultValue("!!simpleDefaultValue!!");
- simpleRequiredDefault.setDefaultValue("!!simpleRequiredDefaultValue!!");
-
- configDef.put(simple);
- configDef.put(simpleRequired);
- configDef.put(simpleDefault);
- configDef.put(simpleRequiredDefault);
-
- // SETUP MAP
-
- // a=not required, no default; c=not required, has default; d=required, has default
- PropertyDefinitionSimple a = new PropertyDefinitionSimple("a", null, false, PropertySimpleType.STRING);
- PropertyDefinitionSimple b = new PropertyDefinitionSimple("b", null, false, PropertySimpleType.STRING);
- PropertyDefinitionSimple c = new PropertyDefinitionSimple("c", null, true, PropertySimpleType.STRING);
- b.setDefaultValue("!!bDefaultValue!!");
- c.setDefaultValue("!!cDefaultValue!!");
-
- PropertyDefinitionMap map1 = new PropertyDefinitionMap("map1", null, false, a, b, c);
- PropertyDefinitionMap mapRequired1 = new PropertyDefinitionMap("mapRequired1", null, true, a, b, c);
- PropertyDefinitionMap mapRequiredDefault1 = new PropertyDefinitionMap("mapRequiredDefault1", null, true, a, b,
- c);
-
- configDef.put(map1);
- configDef.put(mapRequired1);
- configDef.put(mapRequiredDefault1);
-
- // SETUP LIST
-
- PropertyDefinitionList list1 = new PropertyDefinitionList("list1", null, false, a);
- PropertyDefinitionList listRequired1 = new PropertyDefinitionList("listRequired1", null, true, a);
- PropertyDefinitionList listRequiredDefault1 = new PropertyDefinitionList("listRequiredDefault1", null, true, c);
-
- configDef.put(list1);
- configDef.put(listRequired1);
- configDef.put(listRequiredDefault1);
-
- // SETUP LIST-O-MAPS
-
- PropertyDefinitionMap map2 = new PropertyDefinitionMap("map2", null, false, a, b, c);
- PropertyDefinitionMap mapRequired2 = new PropertyDefinitionMap("mapRequired2", null, true, a, b, c);
- PropertyDefinitionMap mapRequiredDefault2 = new PropertyDefinitionMap("mapRequiredDefault2", null, true, a, b,
- c);
-
- PropertyDefinitionList listX = new PropertyDefinitionList("listX", null, true, map2);
- PropertyDefinitionList listY = new PropertyDefinitionList("listY", null, true, mapRequired2);
- PropertyDefinitionList listZ = new PropertyDefinitionList("listZ", null, true, mapRequiredDefault2);
-
- configDef.put(listX);
- configDef.put(listY);
- configDef.put(listZ);
-
- // get the default config
- Configuration config = ConfigurationUtility.createDefaultConfiguration(configDef);
- assert config != null;
- assert config.getProperties().size() == 10;
-
- // ASSERT SIMPLE
-
- assert config.getSimple(simple.getName()) == null;
- assert config.getSimpleValue(simpleRequired.getName(), null) == null;
- assert config.getSimpleValue(simpleDefault.getName(), null).equals("!!simpleDefaultValue!!");
- assert config.getSimpleValue(simpleRequiredDefault.getName(), null).equals("!!simpleRequiredDefaultValue!!");
-
- // ASSERT MAP
-
- assert config.getMap(map1.getName()) == null;
-
- // the two required maps have the same definitions - a,b,c as above. since a isn't required with no default, its not there
- PropertyMap mapProp1 = config.getMap(mapRequired1.getName());
- assert mapProp1 != null;
- assert mapProp1.getSimple(a.getName()) == null;
- assert mapProp1.getSimpleValue(b.getName(), null).equals("!!bDefaultValue!!");
- assert mapProp1.getSimpleValue(c.getName(), null).equals("!!cDefaultValue!!");
-
- mapProp1 = config.getMap(mapRequiredDefault1.getName());
- assert mapProp1 != null;
- assert mapProp1.getSimple(a.getName()) == null;
- assert mapProp1.getSimpleValue(b.getName(), null).equals("!!bDefaultValue!!");
- assert mapProp1.getSimpleValue(c.getName(), null).equals("!!cDefaultValue!!");
-
- // ASSERT LIST
-
- assert config.getList(list1.getName()) == null;
-
- PropertyList listProp1 = config.getList(listRequired1.getName());
- assert listProp1 != null;
- assert listProp1.getList().isEmpty(); // has "a" definition, which is not required and has no default
-
- listProp1 = config.getList(listRequiredDefault1.getName());
- assert listProp1 != null;
- assert listProp1.getList().get(0).getName().equals(c.getName());
- assert ((PropertySimple) listProp1.getList().get(0)).getStringValue().equals("!!cDefaultValue!!");
-
- // ASSERT LIST-O-MAPS
-
- PropertyList listPropTest = config.getList(listX.getName());
- assert listPropTest != null;
- assert listPropTest.getList().isEmpty();
-
- listPropTest = config.getList(listY.getName());
- assert listPropTest != null;
- PropertyMap childMap2 = (PropertyMap) listPropTest.getList().get(0);
-
- listPropTest = config.getList(listZ.getName());
- assert listPropTest != null;
- PropertyMap childMap3 = (PropertyMap) listPropTest.getList().get(0);
-
- assert childMap2.getName().equals(mapRequired2.getName());
- assert childMap3.getName().equals(mapRequiredDefault2.getName());
- }
-}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/ConfigurationUtility.java b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/ConfigurationUtility.java
new file mode 100644
index 0000000..1c32526
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/configuration/ConfigurationUtility.java
@@ -0,0 +1,334 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 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.configuration;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+
+/**
+ * Utility methods for working with {@link Configuration}s.
+ *
+ * @author Ian Springer
+ */
+public abstract class ConfigurationUtility {
+
+ /**
+ * This will populate the given configuration definition with a default template.
+ * A default template will only be created if one or more properties are required
+ * or have default values. If no property definition is required or has a default value,
+ * the default template will remain <code>null</code> in the given config definition.
+ *
+ * Note that if the given configuration definition already has a default template defined
+ * for it, this method is a no-op and will return immediately.
+ *
+ * @param configDef the configuration definition whose default template is to be created and set
+ */
+ public static void initializeDefaultTemplate(ConfigurationDefinition configDef) {
+ ConfigurationTemplate defaultTemplate = configDef.getDefaultTemplate();
+ if (defaultTemplate == null) {
+ Configuration defaultConfig = createDefaultConfiguration(configDef);
+ // not everything should have a default template - only stuff that has default values
+ if (!defaultConfig.getProperties().isEmpty()) {
+ defaultTemplate = new ConfigurationTemplate(ConfigurationTemplate.DEFAULT_TEMPLATE_NAME,
+ ConfigurationTemplate.DEFAULT_TEMPLATE_NAME);
+ defaultTemplate.setDefault(true);
+ defaultTemplate.setConfiguration(defaultConfig);
+ configDef.putTemplate(defaultTemplate);
+ }
+ }
+ return;
+ }
+
+ /**
+ * Given a configuration definition, this will build and return a "default configuration" that
+ * can be validated with the definition. All required properties are set and all properties
+ * that define a default value are also set. If a required property does not have a default
+ * value defined in the definition, the property value will be set to <code>null</code>.
+ *
+ * Use this to help create the definition's default template.
+ *
+ * @param configurationDefinition the configuration definition whose default configuration is to be created
+ * @return configuration the default configuration
+ */
+ public static Configuration createDefaultConfiguration(ConfigurationDefinition configurationDefinition) {
+ if (configurationDefinition == null) {
+ throw new IllegalArgumentException("configurationDefinition == null");
+ }
+ Configuration defaultConfig = new Configuration();
+ Map<String, PropertyDefinition> childPropertyDefinitions = configurationDefinition.getPropertyDefinitions();
+ for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) {
+ createDefaultProperty(childPropertyDefinition, defaultConfig);
+ }
+ return defaultConfig;
+ }
+
+ /**
+ * "Normalize" the given configuration according to the given configuration definition. That is, for any optional
+ * properties that are not defined in the top-level configuration Map or any sub-Maps, set them.
+ * Map properties are set with an empty Map, and List properties with an empty List. By default, simple
+ * properties that are missing will be created and set with a null value. However, if normalizeRequiredDefaults is true,
+ * and a simple property is required with a default, this will set the required property to that default value.
+ * If normalizeOptionalDefaults is true, and a simple property is not required but has a default, this will set the
+ * optional property to that default. If a simple property does not have a default defined, no matter what those
+ * "normalize" booleans are, the simple property will still be set to null since this method won't know what value
+ * to set it to anyway.
+ *
+ * @param configuration the configuration to be normalized (must not be null)
+ * @param configurationDefinition the configuration definition to normalize the configuration against (may be null)
+ * @param normalizeRequiredDefaults if true, and a property is required, its default will be set as that property's value
+ * @param normalizeOptionalDefaults if true, and a property is optional, its default will be set as that property's value
+ */
+ public static void normalizeConfiguration(Configuration configuration,
+ ConfigurationDefinition configurationDefinition, boolean normalizeRequiredDefaults,
+ boolean normalizeOptionalDefaults) {
+ if (configuration == null) {
+ throw new IllegalArgumentException("Configuration parameter is null.");
+ }
+ if (configurationDefinition != null) {
+ Map<String, PropertyDefinition> childPropertyDefinitions = configurationDefinition.getPropertyDefinitions();
+ for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) {
+ normalizeProperty(childPropertyDefinition, configuration, normalizeRequiredDefaults,
+ normalizeOptionalDefaults);
+ }
+ }
+ }
+
+ /**
+ * Validate the given configuration according to the given configuration definition. That is, check that any
+ * required properties in the top-level configuration Map or any sub-Maps, are defined and, in the case of simple
+ * properties, check that they have a non-null value. A list of messages describing any errors that were found is
+ * returned. Additionally, any undefined or null simple properties will be assigned a value of "".
+ *
+ * @param configuration the configuration to be validated (must not be null)
+ * @param configurationDefinition the configuration definition to validate the configuration against (may be null)
+ *
+ * @return a list of messages describing any errors that were found - will be empty if there are no messagse
+ */
+ public static List<String> validateConfiguration(Configuration configuration,
+ ConfigurationDefinition configurationDefinition) {
+ List<String> errorMessages = new ArrayList<String>();
+ if (configurationDefinition != null) {
+ Map<String, PropertyDefinition> childPropertyDefinitions = configurationDefinition.getPropertyDefinitions();
+ for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) {
+ validateProperty(childPropertyDefinition, configuration, errorMessages);
+ }
+ }
+ return errorMessages;
+ }
+
+ private static void createDefaultProperty(PropertyDefinition propertyDefinition,
+ AbstractPropertyMap parentPropertyMap) {
+
+ Property property = null;
+
+ if (propertyDefinition instanceof PropertyDefinitionSimple) {
+ String defaultValue = ((PropertyDefinitionSimple) propertyDefinition).getDefaultValue();
+ if (defaultValue != null || propertyDefinition.isRequired()) {
+ property = new PropertySimple(propertyDefinition.getName(), defaultValue);
+ }
+ } else if (propertyDefinition.isRequired()) {
+ if (propertyDefinition instanceof PropertyDefinitionMap) {
+ property = new PropertyMap(propertyDefinition.getName());
+ Map<String, PropertyDefinition> childPropertyDefinitions = ((PropertyDefinitionMap) propertyDefinition)
+ .getMap();
+ for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) {
+ createDefaultProperty(childPropertyDefinition, (PropertyMap) property);
+ }
+ } else if (propertyDefinition instanceof PropertyDefinitionList) {
+ property = new PropertyList(propertyDefinition.getName());
+ PropertyDefinition listMemberPropertyDefinition = ((PropertyDefinitionList) propertyDefinition)
+ .getMemberDefinition();
+ if (listMemberPropertyDefinition.isRequired()) {
+ if (listMemberPropertyDefinition instanceof PropertyDefinitionMap) {
+ // member property is a list-o-maps, create a default child map if appropriate
+ PropertyDefinitionMap listMemberDefinitionMap = (PropertyDefinitionMap) listMemberPropertyDefinition;
+ PropertyMap listMap = new PropertyMap(listMemberDefinitionMap.getName());
+ createDefaultProperty(listMemberDefinitionMap, listMap);
+ ((PropertyList) property).add(listMap);
+ } else if (listMemberPropertyDefinition instanceof PropertyDefinitionSimple) {
+ // member property is a simple, create a single list entry as its default if appropriate
+ PropertyDefinitionSimple listMemberDefinitionSimple = (PropertyDefinitionSimple) listMemberPropertyDefinition;
+ String defaultValue = listMemberDefinitionSimple.getDefaultValue();
+ if (defaultValue != null || listMemberDefinitionSimple.isRequired()) {
+ PropertySimple listSimple = new PropertySimple(listMemberDefinitionSimple.getName(),
+ defaultValue);
+ ((PropertyList) property).add(listSimple);
+ }
+ }
+ }
+ } else if (propertyDefinition instanceof PropertyDefinitionDynamic) {
+ // Dynamic property values should simply be stored as simple
+ property = new PropertySimple(propertyDefinition.getName(), null);
+ } else {
+ throw new IllegalStateException("Unsupported PropertyDefinition subclass: "
+ + propertyDefinition.getClass().getName());
+ }
+ }
+
+ if (property != null) {
+ parentPropertyMap.put(property);
+ }
+ }
+
+ private static void normalizeProperty(PropertyDefinition propertyDefinition, AbstractPropertyMap parentPropertyMap,
+ boolean normalizeRequiredDefaults, boolean normalizeOptionalDefaults) {
+ if (parentPropertyMap.getMap().keySet().contains(propertyDefinition.getName())) // property is already set
+ {
+ if (propertyDefinition instanceof PropertyDefinitionSimple) {
+ PropertySimple propertySimple = parentPropertyMap.getSimple(propertyDefinition.getName());
+ String value = propertySimple.getStringValue();
+ if (value != null) {
+ if (value.equals("")) {
+ // Normalize "" to null, since Oracle will do the same upon persistence.
+ propertySimple.setStringValue(null);
+ } else if (value.length() > PropertySimple.MAX_VALUE_LENGTH) {
+ // Truncate the value to the max length allowed by the DB schema.
+ propertySimple.setStringValue(value.substring(0, PropertySimple.MAX_VALUE_LENGTH));
+ }
+ }
+ }
+
+ // If property is a Map, recurse into it and normalize its child properties.
+ else if (propertyDefinition instanceof PropertyDefinitionMap) {
+ PropertyMap propertyMap = parentPropertyMap.getMap(propertyDefinition.getName());
+ PropertyDefinitionMap propertyDefinitionMap = (PropertyDefinitionMap) propertyDefinition;
+ normalizePropertyMap(propertyMap, propertyDefinitionMap, false, false); // TODO do we want to pass normalizeRequired/OptionalDefaults?
+ } else if (propertyDefinition instanceof PropertyDefinitionList) {
+ PropertyDefinitionList propertyDefinitionList = (PropertyDefinitionList) propertyDefinition;
+ PropertyDefinition listMemberPropertyDefinition = propertyDefinitionList.getMemberDefinition();
+
+ // If property is a List of Maps, iterate the list and recurse into each Map and normalize its child properties.
+ if (listMemberPropertyDefinition instanceof PropertyDefinitionMap) {
+ PropertyDefinitionMap propertyDefinitionMap = (PropertyDefinitionMap) listMemberPropertyDefinition;
+ PropertyList propertyList = parentPropertyMap.getList(propertyDefinition.getName());
+ for (Property property : propertyList.getList()) {
+ PropertyMap propertyMap = (PropertyMap) property;
+ normalizePropertyMap(propertyMap, propertyDefinitionMap, false, false); // TODO do we want to pass normalizeRequired/OptionalDefaults?
+ }
+ }
+ }
+ } else // property is not set yet
+ {
+ Property property;
+ if (propertyDefinition instanceof PropertyDefinitionSimple) {
+ String value = null;
+ if (normalizeRequiredDefaults || normalizeOptionalDefaults) {
+ if (propertyDefinition.isRequired()) {
+ if (normalizeRequiredDefaults) {
+ value = ((PropertyDefinitionSimple) propertyDefinition).getDefaultValue();
+ }
+ } else {
+ if (normalizeOptionalDefaults) {
+ value = ((PropertyDefinitionSimple) propertyDefinition).getDefaultValue();
+ }
+ }
+ }
+ property = new PropertySimple(propertyDefinition.getName(), value);
+ } else if (propertyDefinition instanceof PropertyDefinitionMap) {
+ property = new PropertyMap(propertyDefinition.getName());
+ } else if (propertyDefinition instanceof PropertyDefinitionList) {
+ property = new PropertyList(propertyDefinition.getName());
+ } else if (propertyDefinition instanceof PropertyDefinitionDynamic) {
+ // Dynamic property values should simply be stored as simple
+ property = new PropertySimple(propertyDefinition.getName(), null);
+ } else {
+ throw new IllegalStateException("Unsupported PropertyDefinition subclass: "
+ + propertyDefinition.getClass().getName());
+ }
+
+ parentPropertyMap.put(property);
+ }
+ }
+
+ private static void normalizePropertyMap(AbstractPropertyMap propertyMap,
+ PropertyDefinitionMap propertyDefinitionMap, boolean normalizeRequiredDefaults,
+ boolean normalizeOptionalDefaults) {
+ Map<String, PropertyDefinition> childPropertyDefinitions = propertyDefinitionMap.getMap();
+ for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) {
+ normalizeProperty(childPropertyDefinition, propertyMap, normalizeRequiredDefaults,
+ normalizeOptionalDefaults);
+ }
+ }
+
+ private static void validateProperty(PropertyDefinition propertyDefinition, AbstractPropertyMap parentPropertyMap,
+ List<String> errorMessages) {
+ if (parentPropertyMap.getMap().keySet().contains(propertyDefinition.getName())) // property is already set
+ {
+ if (propertyDefinition instanceof PropertyDefinitionSimple) {
+ PropertySimple propertySimple = parentPropertyMap.getSimple(propertyDefinition.getName());
+ if (propertyDefinition.isRequired() && (propertySimple.getStringValue() == null)) {
+ errorMessages.add("Required property '" + propertyDefinition.getName() + "' has a null value in "
+ + parentPropertyMap + ".");
+ propertySimple.setStringValue("");
+ }
+ }
+
+ // If the property is a Map, recurse into it and validate its child properties.
+ else if (propertyDefinition instanceof PropertyDefinitionMap) {
+ PropertyMap propertyMap = parentPropertyMap.getMap(propertyDefinition.getName());
+ PropertyDefinitionMap propertyDefinitionMap = (PropertyDefinitionMap) propertyDefinition;
+ validatePropertyMap(propertyMap, propertyDefinitionMap, errorMessages);
+ } else if (propertyDefinition instanceof PropertyDefinitionList) {
+ PropertyDefinitionList propertyDefinitionList = (PropertyDefinitionList) propertyDefinition;
+ PropertyDefinition listMemberPropertyDefinition = propertyDefinitionList.getMemberDefinition();
+
+ // If the property is a List of Maps, iterate the list, and recurse into each Map and validate its child
+ // properties.
+ if (listMemberPropertyDefinition instanceof PropertyDefinitionMap) {
+ PropertyDefinitionMap propertyDefinitionMap = (PropertyDefinitionMap) listMemberPropertyDefinition;
+ PropertyList propertyList = parentPropertyMap.getList(propertyDefinition.getName());
+ for (Property property : propertyList.getList()) {
+ PropertyMap propertyMap = (PropertyMap) property;
+ validatePropertyMap(propertyMap, propertyDefinitionMap, errorMessages);
+ }
+ }
+ }
+ } else // property is not set yet
+ {
+ if (propertyDefinition.isRequired()) {
+ errorMessages.add("Required property '" + propertyDefinition.getName() + "' was not set in "
+ + parentPropertyMap + ".");
+ if (propertyDefinition instanceof PropertyDefinitionSimple) {
+ PropertySimple propertySimple = new PropertySimple(propertyDefinition.getName(), "");
+ parentPropertyMap.put(propertySimple);
+ }
+ }
+ }
+ }
+
+ private static void validatePropertyMap(AbstractPropertyMap propertyMap,
+ PropertyDefinitionMap propertyDefinitionMap, List<String> errorMessages) {
+ Map<String, PropertyDefinition> childPropertyDefinitions = propertyDefinitionMap.getMap();
+ for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) {
+ validateProperty(childPropertyDefinition, propertyMap, errorMessages);
+ }
+ }
+}
\ No newline at end of file
diff --git a/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/ConfigurationUtilityTest.java b/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/ConfigurationUtilityTest.java
new file mode 100644
index 0000000..7c49296
--- /dev/null
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/configuration/ConfigurationUtilityTest.java
@@ -0,0 +1,363 @@
+/*
+ * 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, 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.configuration;
+
+import org.testng.annotations.Test;
+
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.rhq.core.domain.configuration.definition.PropertySimpleType;
+
+@Test
+public class ConfigurationUtilityTest {
+ public void testNormalizeDefaultSimple() {
+ ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
+
+ PropertyDefinitionSimple simple = new PropertyDefinitionSimple("simple", null, false, PropertySimpleType.STRING);
+ PropertyDefinitionSimple simpleRequired = new PropertyDefinitionSimple("simpleRequired", null, true,
+ PropertySimpleType.STRING);
+ PropertyDefinitionSimple simpleDefault = new PropertyDefinitionSimple("simpleDefault", null, false,
+ PropertySimpleType.STRING);
+ PropertyDefinitionSimple simpleRequiredDefault = new PropertyDefinitionSimple("simpleRequiredDefault", null,
+ true, PropertySimpleType.STRING);
+
+ simpleDefault.setDefaultValue("!!simpleDefaultValue!!");
+ simpleRequiredDefault.setDefaultValue("!!simpleRequiredDefaultValue!!");
+
+ configDef.put(simple);
+ configDef.put(simpleRequired);
+ configDef.put(simpleDefault);
+ configDef.put(simpleRequiredDefault);
+
+ // test normalization
+ Configuration config = new Configuration();
+ ConfigurationUtility.normalizeConfiguration(config, configDef, false, false);
+ assert config.getProperties().size() == 4;
+ assert config.getSimpleValue(simple.getName(), null) == null;
+ assert config.getSimpleValue(simpleRequired.getName(), null) == null;
+ assert config.getSimpleValue(simpleDefault.getName(), null) == null;
+ assert config.getSimpleValue(simpleRequiredDefault.getName(), null) == null;
+
+ config = new Configuration();
+ ConfigurationUtility.normalizeConfiguration(config, configDef, true, false);
+ assert config.getProperties().size() == 4;
+ assert config.getSimpleValue(simple.getName(), null) == null;
+ assert config.getSimpleValue(simpleRequired.getName(), null) == null; // there is no default, so nothing to set
+ assert config.getSimpleValue(simpleDefault.getName(), null) == null;
+ assert config.getSimpleValue(simpleRequiredDefault.getName(), null).equals("!!simpleRequiredDefaultValue!!");
+
+ config = new Configuration();
+ ConfigurationUtility.normalizeConfiguration(config, configDef, false, true);
+ assert config.getProperties().size() == 4;
+ assert config.getSimpleValue(simple.getName(), null) == null; // there is no default, so nothing to set
+ assert config.getSimpleValue(simpleRequired.getName(), null) == null;
+ assert config.getSimpleValue(simpleDefault.getName(), null).equals("!!simpleDefaultValue!!");
+ assert config.getSimpleValue(simpleRequiredDefault.getName(), null) == null;
+ }
+
+ public void testCreateDefaultNone() {
+ // no defaults, no required props - returned config should be empty
+ ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
+
+ PropertyDefinitionSimple simple = new PropertyDefinitionSimple("simple", null, false, PropertySimpleType.STRING);
+ PropertyDefinitionMap map = new PropertyDefinitionMap("map", null, false, simple);
+ PropertyDefinitionList list = new PropertyDefinitionList("list", null, false, simple);
+
+ configDef.put(simple);
+ configDef.put(map);
+ configDef.put(list);
+
+ Configuration config = ConfigurationUtility.createDefaultConfiguration(configDef);
+ assert config != null;
+ assert config.getProperties().size() == 0;
+ }
+
+ public void testCreateDefaultSimple() {
+ ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
+
+ PropertyDefinitionSimple simple = new PropertyDefinitionSimple("simple", null, false, PropertySimpleType.STRING);
+ PropertyDefinitionSimple simpleRequired = new PropertyDefinitionSimple("simpleRequired", null, true,
+ PropertySimpleType.STRING);
+ PropertyDefinitionSimple simpleDefault = new PropertyDefinitionSimple("simpleDefault", null, false,
+ PropertySimpleType.STRING);
+ PropertyDefinitionSimple simpleRequiredDefault = new PropertyDefinitionSimple("simpleRequiredDefault", null,
+ true, PropertySimpleType.STRING);
+
+ simpleDefault.setDefaultValue("!!simpleDefaultValue!!");
+ simpleRequiredDefault.setDefaultValue("!!simpleRequiredDefaultValue!!");
+
+ configDef.put(simple);
+ configDef.put(simpleRequired);
+ configDef.put(simpleDefault);
+ configDef.put(simpleRequiredDefault);
+
+ Configuration config = ConfigurationUtility.createDefaultConfiguration(configDef);
+ assert config != null;
+ assert config.getProperties().size() == 3; // simple is not required with no default - its not in the config
+ assert config.getSimple(simple.getName()) == null;
+ assert config.getSimpleValue(simpleRequired.getName(), null) == null;
+ assert config.getSimpleValue(simpleDefault.getName(), null).equals("!!simpleDefaultValue!!");
+ assert config.getSimpleValue(simpleRequiredDefault.getName(), null).equals("!!simpleRequiredDefaultValue!!");
+ }
+
+ public void testCreateDefaultMap() {
+ ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
+
+ // a=not required, no default; c=not required, has default; d=required, has default
+ PropertyDefinitionSimple a = new PropertyDefinitionSimple("a", null, false, PropertySimpleType.STRING);
+ PropertyDefinitionSimple b = new PropertyDefinitionSimple("b", null, false, PropertySimpleType.STRING);
+ PropertyDefinitionSimple c = new PropertyDefinitionSimple("c", null, true, PropertySimpleType.STRING);
+ b.setDefaultValue("!!bDefaultValue!!");
+ c.setDefaultValue("!!cDefaultValue!!");
+
+ PropertyDefinitionMap map1 = new PropertyDefinitionMap("map1", null, false, a, b, c);
+ PropertyDefinitionMap mapRequired1 = new PropertyDefinitionMap("mapRequired1", null, true, a, b, c);
+ PropertyDefinitionMap mapRequiredDefault1 = new PropertyDefinitionMap("mapRequiredDefault1", null, true, a, b,
+ c);
+
+ configDef.put(map1);
+ configDef.put(mapRequired1);
+ configDef.put(mapRequiredDefault1);
+
+ Configuration config = ConfigurationUtility.createDefaultConfiguration(configDef);
+ assert config != null;
+ assert config.getProperties().size() == 2; // map is not required with no default - its not in the config
+ assert config.getMap(map1.getName()) == null;
+
+ // the two required maps have the same definitions - a,b,c as above. since a isn't required with no default, its not there
+ PropertyMap mapProp1 = config.getMap(mapRequired1.getName());
+ assert mapProp1 != null;
+ assert mapProp1.getSimple(a.getName()) == null;
+ assert mapProp1.getSimpleValue(b.getName(), null).equals("!!bDefaultValue!!");
+ assert mapProp1.getSimpleValue(c.getName(), null).equals("!!cDefaultValue!!");
+
+ mapProp1 = config.getMap(mapRequiredDefault1.getName());
+ assert mapProp1 != null;
+ assert mapProp1.getSimple(a.getName()) == null;
+ assert mapProp1.getSimpleValue(b.getName(), null).equals("!!bDefaultValue!!");
+ assert mapProp1.getSimpleValue(c.getName(), null).equals("!!cDefaultValue!!");
+ }
+
+ public void testCreateDefaultList() {
+ ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
+
+ // a=not required, no default, b=required, has default
+ PropertyDefinitionSimple a = new PropertyDefinitionSimple("a", null, false, PropertySimpleType.STRING);
+ PropertyDefinitionSimple c = new PropertyDefinitionSimple("c", null, true, PropertySimpleType.STRING);
+ c.setDefaultValue("!!cDefaultValue!!");
+
+ PropertyDefinitionList list1 = new PropertyDefinitionList("list1", null, false, a);
+ PropertyDefinitionList listRequired1 = new PropertyDefinitionList("listRequired1", null, true, a);
+ PropertyDefinitionList listRequiredDefault1 = new PropertyDefinitionList("listRequiredDefault1", null, true, c);
+
+ configDef.put(list1);
+ configDef.put(listRequired1);
+ configDef.put(listRequiredDefault1);
+
+ Configuration config = ConfigurationUtility.createDefaultConfiguration(configDef);
+ assert config != null;
+ assert config.getProperties().size() == 2; // list is not required with no default - its not in the config
+ assert config.getList(list1.getName()) == null;
+
+ PropertyList listProp1 = config.getList(listRequired1.getName());
+ assert listProp1 != null;
+ assert listProp1.getList().isEmpty(); // has "a" definition, which is not required and has no default
+
+ listProp1 = config.getList(listRequiredDefault1.getName());
+ assert listProp1 != null;
+ assert listProp1.getList().get(0).getName().equals(c.getName());
+ assert ((PropertySimple) listProp1.getList().get(0)).getStringValue().equals("!!cDefaultValue!!");
+ }
+
+ public void testCreateDefaultListOMaps() {
+ ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
+
+ // a=not required, no default; c=not required, has default; d=required, has default
+ PropertyDefinitionSimple a = new PropertyDefinitionSimple("a", null, false, PropertySimpleType.STRING);
+ PropertyDefinitionSimple b = new PropertyDefinitionSimple("b", null, false, PropertySimpleType.STRING);
+ PropertyDefinitionSimple c = new PropertyDefinitionSimple("c", null, true, PropertySimpleType.STRING);
+ b.setDefaultValue("!!bDefaultValue!!");
+ c.setDefaultValue("!!cDefaultValue!!");
+
+ PropertyDefinitionMap map2 = new PropertyDefinitionMap("map2", null, false, a, b, c);
+ PropertyDefinitionMap mapRequired2 = new PropertyDefinitionMap("mapRequired2", null, true, a, b, c);
+ PropertyDefinitionMap mapRequiredDefault2 = new PropertyDefinitionMap("mapRequiredDefault2", null, true, a, b,
+ c);
+
+ PropertyDefinitionList listX = new PropertyDefinitionList("listX", null, true, map2);
+ PropertyDefinitionList listY = new PropertyDefinitionList("listY", null, true, mapRequired2);
+ PropertyDefinitionList listZ = new PropertyDefinitionList("listZ", null, true, mapRequiredDefault2);
+
+ configDef.put(listX);
+ configDef.put(listY);
+ configDef.put(listZ);
+
+ Configuration config = ConfigurationUtility.createDefaultConfiguration(configDef);
+
+ assert config != null;
+ assert config.getProperties().size() == 3;
+
+ PropertyList listPropTest = config.getList(listX.getName());
+ assert listPropTest != null;
+ assert listPropTest.getList().isEmpty();
+
+ listPropTest = config.getList(listY.getName());
+ assert listPropTest != null;
+ PropertyMap childMap2 = (PropertyMap) listPropTest.getList().get(0);
+
+ listPropTest = config.getList(listZ.getName());
+ assert listPropTest != null;
+ PropertyMap childMap3 = (PropertyMap) listPropTest.getList().get(0);
+
+ assert childMap2.getName().equals(mapRequired2.getName());
+ assert childMap3.getName().equals(mapRequiredDefault2.getName());
+ }
+
+ public void testCreateDefaultAllSimpleMapList() {
+ // tests a big config def that has simples, lists, maps - combination of the other individual tests
+ ConfigurationDefinition configDef = new ConfigurationDefinition("foo", null);
+
+ // SETUP SIMPLE
+
+ PropertyDefinitionSimple simple = new PropertyDefinitionSimple("simple", null, false, PropertySimpleType.STRING);
+ PropertyDefinitionSimple simpleRequired = new PropertyDefinitionSimple("simpleRequired", null, true,
+ PropertySimpleType.STRING);
+ PropertyDefinitionSimple simpleDefault = new PropertyDefinitionSimple("simpleDefault", null, false,
+ PropertySimpleType.STRING);
+ PropertyDefinitionSimple simpleRequiredDefault = new PropertyDefinitionSimple("simpleRequiredDefault", null,
+ true, PropertySimpleType.STRING);
+
+ simpleDefault.setDefaultValue("!!simpleDefaultValue!!");
+ simpleRequiredDefault.setDefaultValue("!!simpleRequiredDefaultValue!!");
+
+ configDef.put(simple);
+ configDef.put(simpleRequired);
+ configDef.put(simpleDefault);
+ configDef.put(simpleRequiredDefault);
+
+ // SETUP MAP
+
+ // a=not required, no default; c=not required, has default; d=required, has default
+ PropertyDefinitionSimple a = new PropertyDefinitionSimple("a", null, false, PropertySimpleType.STRING);
+ PropertyDefinitionSimple b = new PropertyDefinitionSimple("b", null, false, PropertySimpleType.STRING);
+ PropertyDefinitionSimple c = new PropertyDefinitionSimple("c", null, true, PropertySimpleType.STRING);
+ b.setDefaultValue("!!bDefaultValue!!");
+ c.setDefaultValue("!!cDefaultValue!!");
+
+ PropertyDefinitionMap map1 = new PropertyDefinitionMap("map1", null, false, a, b, c);
+ PropertyDefinitionMap mapRequired1 = new PropertyDefinitionMap("mapRequired1", null, true, a, b, c);
+ PropertyDefinitionMap mapRequiredDefault1 = new PropertyDefinitionMap("mapRequiredDefault1", null, true, a, b,
+ c);
+
+ configDef.put(map1);
+ configDef.put(mapRequired1);
+ configDef.put(mapRequiredDefault1);
+
+ // SETUP LIST
+
+ PropertyDefinitionList list1 = new PropertyDefinitionList("list1", null, false, a);
+ PropertyDefinitionList listRequired1 = new PropertyDefinitionList("listRequired1", null, true, a);
+ PropertyDefinitionList listRequiredDefault1 = new PropertyDefinitionList("listRequiredDefault1", null, true, c);
+
+ configDef.put(list1);
+ configDef.put(listRequired1);
+ configDef.put(listRequiredDefault1);
+
+ // SETUP LIST-O-MAPS
+
+ PropertyDefinitionMap map2 = new PropertyDefinitionMap("map2", null, false, a, b, c);
+ PropertyDefinitionMap mapRequired2 = new PropertyDefinitionMap("mapRequired2", null, true, a, b, c);
+ PropertyDefinitionMap mapRequiredDefault2 = new PropertyDefinitionMap("mapRequiredDefault2", null, true, a, b,
+ c);
+
+ PropertyDefinitionList listX = new PropertyDefinitionList("listX", null, true, map2);
+ PropertyDefinitionList listY = new PropertyDefinitionList("listY", null, true, mapRequired2);
+ PropertyDefinitionList listZ = new PropertyDefinitionList("listZ", null, true, mapRequiredDefault2);
+
+ configDef.put(listX);
+ configDef.put(listY);
+ configDef.put(listZ);
+
+ // get the default config
+ Configuration config = ConfigurationUtility.createDefaultConfiguration(configDef);
+ assert config != null;
+ assert config.getProperties().size() == 10;
+
+ // ASSERT SIMPLE
+
+ assert config.getSimple(simple.getName()) == null;
+ assert config.getSimpleValue(simpleRequired.getName(), null) == null;
+ assert config.getSimpleValue(simpleDefault.getName(), null).equals("!!simpleDefaultValue!!");
+ assert config.getSimpleValue(simpleRequiredDefault.getName(), null).equals("!!simpleRequiredDefaultValue!!");
+
+ // ASSERT MAP
+
+ assert config.getMap(map1.getName()) == null;
+
+ // the two required maps have the same definitions - a,b,c as above. since a isn't required with no default, its not there
+ PropertyMap mapProp1 = config.getMap(mapRequired1.getName());
+ assert mapProp1 != null;
+ assert mapProp1.getSimple(a.getName()) == null;
+ assert mapProp1.getSimpleValue(b.getName(), null).equals("!!bDefaultValue!!");
+ assert mapProp1.getSimpleValue(c.getName(), null).equals("!!cDefaultValue!!");
+
+ mapProp1 = config.getMap(mapRequiredDefault1.getName());
+ assert mapProp1 != null;
+ assert mapProp1.getSimple(a.getName()) == null;
+ assert mapProp1.getSimpleValue(b.getName(), null).equals("!!bDefaultValue!!");
+ assert mapProp1.getSimpleValue(c.getName(), null).equals("!!cDefaultValue!!");
+
+ // ASSERT LIST
+
+ assert config.getList(list1.getName()) == null;
+
+ PropertyList listProp1 = config.getList(listRequired1.getName());
+ assert listProp1 != null;
+ assert listProp1.getList().isEmpty(); // has "a" definition, which is not required and has no default
+
+ listProp1 = config.getList(listRequiredDefault1.getName());
+ assert listProp1 != null;
+ assert listProp1.getList().get(0).getName().equals(c.getName());
+ assert ((PropertySimple) listProp1.getList().get(0)).getStringValue().equals("!!cDefaultValue!!");
+
+ // ASSERT LIST-O-MAPS
+
+ PropertyList listPropTest = config.getList(listX.getName());
+ assert listPropTest != null;
+ assert listPropTest.getList().isEmpty();
+
+ listPropTest = config.getList(listY.getName());
+ assert listPropTest != null;
+ PropertyMap childMap2 = (PropertyMap) listPropTest.getList().get(0);
+
+ listPropTest = config.getList(listZ.getName());
+ assert listPropTest != null;
+ PropertyMap childMap3 = (PropertyMap) listPropTest.getList().get(0);
+
+ assert childMap2.getName().equals(mapRequired2.getName());
+ assert childMap3.getName().equals(mapRequiredDefault2.getName());
+ }
+}
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/GetDeploymentConfigStep.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/GetDeploymentConfigStep.java
index 7fc0363..c295b74 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/GetDeploymentConfigStep.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/GetDeploymentConfigStep.java
@@ -19,13 +19,14 @@
package org.rhq.enterprise.gui.coregui.client.bundle.deploy;
import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.HTMLFlow;
import com.smartgwt.client.widgets.layout.VLayout;
import org.rhq.core.domain.bundle.BundleDeployment;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.ConfigurationUtility;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
-import org.rhq.enterprise.gui.coregui.client.components.HeaderLabel;
import org.rhq.enterprise.gui.coregui.client.components.configuration.ConfigurationEditor;
import org.rhq.enterprise.gui.coregui.client.components.wizard.AbstractWizardStep;
import org.rhq.enterprise.gui.coregui.client.util.selenium.Locatable;
@@ -58,8 +59,11 @@ public class GetDeploymentConfigStep extends AbstractWizardStep {
// This has started behaving badly. Instead of moving ahead let's give them a message
// and a chance to go back to the previous screen.
// this.wizard.getView().incrementStep();
- HeaderLabel label = new HeaderLabel(MSG.view_bundle_deployWizard_getConfigSkip());
+ HTMLFlow label = new HTMLFlow(MSG.view_bundle_deployWizard_getConfigSkip());
label.setWidth100();
+ label.setHeight(50);
+ label.setStylePrimaryName("HeaderLabel");
+ label.setStyleName("HeaderLabel");
editor = new VLayout();
editor.addMember(label);
} else {
@@ -100,9 +104,7 @@ public class GetDeploymentConfigStep extends AbstractWizardStep {
config = new Configuration();
} else {
config = config.deepCopy(false);
- //TODO: get access to this method, may need to add slsb call
- // also, may need to enhance this drop unnecessary config (maybe it can just stay around)
- //ConfigurationUtility.normalizeConfiguration(config, configDef);
+ ConfigurationUtility.normalizeConfiguration(config, configDef, true, false);
}
return config;
commit 521552eacb1d0ecb0a317d8f593fcc785a56c190
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri May 4 14:38:47 2012 -0400
[BZ 818751] don't use the live config if it was empty - we need to get the default template
(cherry picked from commit 184dabf1f2e443f9925af666409c069584ae9d2a)
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/GetDeploymentConfigStep.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/GetDeploymentConfigStep.java
index 42d1c70..7fc0363 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/GetDeploymentConfigStep.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/deploy/GetDeploymentConfigStep.java
@@ -21,6 +21,7 @@ package org.rhq.enterprise.gui.coregui.client.bundle.deploy;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.layout.VLayout;
+import org.rhq.core.domain.bundle.BundleDeployment;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
@@ -64,7 +65,22 @@ public class GetDeploymentConfigStep extends AbstractWizardStep {
} else {
// otherwise, pop up the config editor to get the needed config
Configuration startingConfig;
- if (wizard.getLiveDeployment() == null) {
+ BundleDeployment liveDeployment = wizard.getLiveDeployment();
+ boolean useLiveConfig = false;
+
+ if (liveDeployment != null) {
+ // If we have a live deployment but it didn't have configuration before
+ // then make sure we don't start with a completely empty config.
+ // In that case, we need to ask for the config from the default template.
+ // But if our live deployment DID have a previous non-empty config, we'll use it
+ // to allow the user to see the previous config values used in the live deployment.
+ Configuration liveConfig = liveDeployment.getConfiguration();
+ if (liveConfig != null) {
+ useLiveConfig = !liveConfig.getMap().isEmpty();
+ }
+ }
+
+ if (useLiveConfig == false) {
ConfigurationTemplate defaultTemplate = configDef.getDefaultTemplate();
startingConfig = (defaultTemplate != null) ? defaultTemplate.createConfiguration() :
new Configuration();
11 years, 10 months
[rhq] Branch 'release/jon3.1.x' - modules/core modules/enterprise
by mazz
modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java | 6 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java | 17 ++-
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java | 51 ++++++++++
3 files changed, 70 insertions(+), 4 deletions(-)
New commits:
commit b42e0606e6c048b36632b40691facfd6b2487390
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Jun 5 14:48:53 2012 -0400
[BZ 828905] fix the version ordering column when deleting a bundle version
(cherry picked from commit f364f5ff907a4fff391579181fee1e2e01a861a7)
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java b/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
index 31fc9ab..b4010bd 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/bundle/BundleVersion.java
@@ -57,6 +57,11 @@ import org.rhq.core.domain.tagging.Tag;
*/
@Entity
@NamedQueries( {
+ @NamedQuery(name = BundleVersion.UPDATE_VERSION_ORDER_BY_BUNDLE_ID_AFTER_DELETE, query = "" //
+ + "UPDATE BundleVersion bv "//
+ + " SET bv.versionOrder = (bv.versionOrder-1) " //
+ + " WHERE bv.bundle.id = :bundleId " //
+ + " AND bv.versionOrder > :versionOrder"), //
@NamedQuery(name = BundleVersion.UPDATE_VERSION_ORDER_BY_BUNDLE_ID, query = "" //
+ "UPDATE BundleVersion bv "//
+ " SET bv.versionOrder = (bv.versionOrder+1) " //
@@ -83,6 +88,7 @@ import org.rhq.core.domain.tagging.Tag;
public class BundleVersion implements Serializable {
private static final long serialVersionUID = 1L;
+ public static final String UPDATE_VERSION_ORDER_BY_BUNDLE_ID_AFTER_DELETE = "BundleVersion.updateVersionOrderByBundleIdAfterDelete";
public static final String UPDATE_VERSION_ORDER_BY_BUNDLE_ID = "BundleVersion.updateVersionOrderByBundleId";
public static final String QUERY_FIND_LATEST_BY_BUNDLE_ID = "BundleVersion.findLatestByBundleId";
public static final String QUERY_FIND_VERSION_INFO_BY_BUNDLE_ID = "BundleVersion.findVersionsByBundleId";
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
index 0e129ee..a6302de 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java
@@ -1646,10 +1646,11 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
return;
}
- int bundleId = 0;
- if (deleteBundleIfEmpty) {
- bundleId = bundleVersion.getBundle().getId(); // note that we lazy load this if we never plan to delete the bundle
- }
+ // After we delete this bundle version, this is the version order value that is being removed.
+ // Later we need to re-order the other bundles that are newer than this so their version orders are readjusted.
+ int doomedBundleVersionOrder = bundleVersion.getVersionOrder();
+
+ int bundleId = bundleVersion.getBundle().getId();
// deployments replace other deployments and have a self-referring FK. The deployments
// need to be removed in a way that will ensure that a replaced deployment is not removed
@@ -1671,9 +1672,17 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot
if (q.getResultList().size() == 0) {
// there are no more bundle versions left, blow away the bundle and all repo/bundle files associated with it
deleteBundle(subject, bundleId);
+ doomedBundleVersionOrder = -1; // just a marker to let us know not to bother with adjusting version orders
}
}
+ if (doomedBundleVersionOrder >= 0) {
+ q = entityManager.createNamedQuery(BundleVersion.UPDATE_VERSION_ORDER_BY_BUNDLE_ID_AFTER_DELETE);
+ q.setParameter("bundleId", bundleId);
+ q.setParameter("versionOrder", doomedBundleVersionOrder);
+ q.executeUpdate();
+ }
+
return;
}
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
index e3b985e..a4d43b8 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/bundle/BundleManagerBeanTest.java
@@ -533,6 +533,12 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
bCriteria.addFilterId(b1.getId());
bResults = bundleManager.findBundlesByCriteria(overlord, bCriteria);
assert bResults.size() == 0 : "Should have deleted bundle since no versions exists anymore";
+
+ // make sure our composite query is OK and can show us 0 bundles, too
+ PageList<BundleWithLatestVersionComposite> composites;
+ bCriteria = new BundleCriteria();
+ composites = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, bCriteria);
+ assert composites.size() == 0;
}
@Test(enabled = TESTS_ENABLED)
@@ -696,6 +702,51 @@ public class BundleManagerBeanTest extends AbstractEJB3Test {
assert results.get(1).getBundleDescription().equals(b2.getDescription());
assert results.get(1).getLatestVersion().equals("9.1");
assert results.get(1).getVersionsCount().longValue() == 1L;
+
+ // now delete one of the older bundle versions and make sure the ordering remains intact
+ bundleManager.deleteBundleVersion(overlord, bv1.getId(), true);
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, criteria);
+ assert results.size() == 2 : results;
+ assert results.get(0).getBundleId().equals(b1.getId());
+ assert results.get(0).getBundleName().equals(b1.getName());
+ assert results.get(0).getBundleDescription().equals(b1.getDescription());
+ assert results.get(0).getLatestVersion().equals("2.0");
+ assert results.get(0).getVersionsCount().longValue() == 3L;
+ assert results.get(1).getBundleId().equals(b2.getId());
+ assert results.get(1).getBundleName().equals(b2.getName());
+ assert results.get(1).getBundleDescription().equals(b2.getDescription());
+ assert results.get(1).getLatestVersion().equals("9.1");
+ assert results.get(1).getVersionsCount().longValue() == 1L;
+
+ // now add another bundle version and make sure the ordering is updated properly [BZ 828905]
+ BundleVersion bv5 = createBundleVersion(b1.getName() + "-5", "5.0", b1);
+ assertNotNull(bv5);
+ assertEquals("5.0", bv5.getVersion());
+ assert 3 == bv5.getVersionOrder();
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, criteria);
+ assert results.get(0).getBundleId().equals(b1.getId());
+ assert results.get(0).getBundleName().equals(b1.getName());
+ assert results.get(0).getBundleDescription().equals(b1.getDescription());
+ assert results.get(0).getLatestVersion().equals("5.0");
+ assert results.get(0).getVersionsCount().longValue() == 4L;
+
+ // delete the latest bundle version and make sure we didn't screw up the order
+ bundleManager.deleteBundleVersion(overlord, bv5.getId(), true);
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, criteria);
+ assert results.get(0).getBundleId().equals(b1.getId());
+ assert results.get(0).getBundleName().equals(b1.getName());
+ assert results.get(0).getBundleDescription().equals(b1.getDescription());
+ assert results.get(0).getLatestVersion().equals("2.0");
+ assert results.get(0).getVersionsCount().longValue() == 3L;
+
+ // delete the oldest bundle version and make sure we didn't screw up the order
+ bundleManager.deleteBundleVersion(overlord, bv4.getId(), true); // deleting version 0.5
+ results = bundleManager.findBundlesWithLatestVersionCompositesByCriteria(overlord, criteria);
+ assert results.get(0).getBundleId().equals(b1.getId());
+ assert results.get(0).getBundleName().equals(b1.getName());
+ assert results.get(0).getBundleDescription().equals(b1.getDescription());
+ assert results.get(0).getLatestVersion().equals("2.0");
+ assert results.get(0).getVersionsCount().longValue() == 2L;
}
@Test(enabled = TESTS_ENABLED)
11 years, 10 months
[rhq] Changes to 'feature/hadoop-plugin'
by Jiri Kremser
New branch 'feature/hadoop-plugin' available with the following commits:
commit f81e53193ced4e5c9d705462d459e9fbc78e6b2c
Author: Jirka Kremser <jkremser(a)redhat.com>
Date: Wed Jul 18 17:09:43 2012 +0200
The plugin descriptor has been restructured, new metrics have been added
11 years, 10 months