modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/DownloadsView.java
| 61 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/SystemGWTService.java
| 11
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
| 29
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
| 4
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
| 4
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
| 4
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
| 4
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
| 4
modules/enterprise/server/container/src/main/downloadable-resources/cli-alert-scripts/fix-bundle-deployment.js
| 467 ++++++++++
modules/enterprise/server/container/src/main/scripts/rhq-container.build.xml
| 13
10 files changed, 597 insertions(+), 4 deletions(-)
New commits:
commit 4ef245611000d6b7f72d2e6ed27b8211315d427b
Author: Lukas Krejci <lkrejci(a)redhat.com>
Date: Thu Dec 1 14:50:06 2011 +0100
[BZ 751248] - Make the sample CLI alert scripts downloadable from the server's
/download/cli-alert-scripts location and from the Downloads section of the GUI.
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/DownloadsView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/DownloadsView.java
index 122ccb6..114f335 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/DownloadsView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/admin/DownloadsView.java
@@ -60,6 +60,7 @@ public class DownloadsView extends LocatableVLayout {
private SectionStackSection cliSection;
private SectionStackSection bundleSection;
private SectionStackSection connectorsSection;
+ private SectionStackSection cliAlertScriptsSection;
private ProductInfo productInfo;
public DownloadsView(String locatorId) {
@@ -83,17 +84,20 @@ public class DownloadsView extends LocatableVLayout {
cliSection = new SectionStackSection(MSG.view_admin_downloads_cliDownload());
bundleSection = new
SectionStackSection(MSG.view_admin_downloads_bundleDownload());
connectorsSection = new
SectionStackSection(MSG.view_admin_downloads_connectorsDownload());
-
+ cliAlertScriptsSection = new
SectionStackSection(MSG.view_admin_downloads_cliAlertScriptsDownload());
+
agentSection.setExpanded(false);
cliSection.setExpanded(false);
bundleSection.setExpanded(false);
connectorsSection.setExpanded(false);
-
+ cliAlertScriptsSection.setExpanded(false);
+
sectionStack.addSection(agentSection);
sectionStack.addSection(cliSection);
sectionStack.addSection(bundleSection);
sectionStack.addSection(connectorsSection);
-
+ sectionStack.addSection(cliAlertScriptsSection);
+
addMember(sectionStack);
}
@@ -105,6 +109,7 @@ public class DownloadsView extends LocatableVLayout {
prepareCLISection();
prepareBundleSection();
prepareConnectorsSection();
+ prepareCliAlertScriptsSection();
}
private void prepareAgentSection() {
@@ -299,4 +304,54 @@ public class DownloadsView extends LocatableVLayout {
}
});
}
+
+ private void prepareCliAlertScriptsSection() {
+ systemManager.getCliAlertScriptDownloads(new AsyncCallback<HashMap<String,
String>>() {
+
+ @Override
+ public void onSuccess(HashMap<String, String> result) {
+ LocatableDynamicForm form = new
LocatableDynamicForm(extendLocatorId("cliAlertScripts"));
+ form.setMargin(10);
+ form.setWidth100();
+
+ if (result != null && !result.isEmpty()) {
+ int i = 0;
+ FormItem[] items = new FormItem[result.size() + 1];
+
+ StaticTextItem helpText = new
StaticTextItem("cliAlertScriptsHelp");
+ helpText.setColSpan(2);
+ helpText.setShowTitle(false);
+ helpText.setValue(MSG.view_admin_downloads_cliAlertScripts_help());
+ items[i] = helpText;
+ i++;
+
+ for (Map.Entry<String, String> entry : result.entrySet()) {
+ LinkItem linkItem = new LinkItem("cliAlertScriptLink" +
i);
+ linkItem.setColSpan(2);
+ linkItem.setShowTitle(false);
+ linkItem.setLinkTitle(entry.getKey());
+ linkItem.setValue(entry.getValue());
+ items[i] = linkItem;
+ i++;
+ }
+ form.setItems(items);
+ } else {
+ StaticTextItem item = new
StaticTextItem("noCliAlertScripts");
+ item.setColSpan(2);
+ item.setShowTitle(false);
+ item.setValue(MSG.view_admin_downloads_cliAlertScripts_none());
+ form.setItems(item);
+ }
+
+ cliAlertScriptsSection.setItems(form);
+ cliAlertScriptsSection.setExpanded(true);
+ sectionStack.markForRedraw();
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+
CoreGUI.getErrorHandler().handleError(MSG.view_admin_downloads_cliAlertScripts_loadError(),
caught);
+ }
+ });
+ }
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/SystemGWTService.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/SystemGWTService.java
index 33573d1..a9fd575 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/SystemGWTService.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/SystemGWTService.java
@@ -57,6 +57,17 @@ public interface SystemGWTService extends RemoteService {
HashMap<String, String> getConnectorDownloads() throws RuntimeException;
/**
+ * Returns the name and download URL (key and value respectively) of all CLI alert
scripts
+ * that are available on the server for download. These are just scripts that users
can
+ * then use to create actual cli scripts for alert notifications. These scripts will
usually
+ * require some tweaking to be usable as alert scripts.
+ *
+ * @return info about the available CLI alert scripts
+ * @throws RuntimeException
+ */
+ HashMap<String, String> getCliAlertScriptDownloads() throws RuntimeException;
+
+ /**
* @return metadata properties about the CLI download available on the server.
*/
HashMap<String, String> getClientVersionProperties() throws RuntimeException;
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
index cf3848e..d4624ef 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/SystemGWTServiceImpl.java
@@ -130,6 +130,26 @@ public class SystemGWTServiceImpl extends AbstractGWTServiceImpl
implements Syst
}
@Override
+ public HashMap<String, String> getCliAlertScriptDownloads() throws
RuntimeException {
+ try {
+ File downloadsDir = getCliAlertScriptDownloadsDir();
+ List<File> files = getFiles(downloadsDir);
+ if (files == null) {
+ return new HashMap<String, String>(0);
+ } else {
+ HashMap<String, String> ret = new HashMap<String,
String>(files.size());
+
+ for(File file : files) {
+ ret.put(file.getName(), "/downloads/cli-alert-scripts/" +
file.getName());
+ }
+ return ret;
+ }
+ } catch (Throwable t) {
+ throw getExceptionToThrowToClient(t);
+ }
+ }
+
+ @Override
public HashMap<String, String> getClientVersionProperties() throws
RuntimeException {
File versionFile = new File(getClientDownloadDir(),
"rhq-client-version.properties");
try {
@@ -182,6 +202,15 @@ public class SystemGWTServiceImpl extends AbstractGWTServiceImpl
implements Syst
return downloadDir;
}
+ private File getCliAlertScriptDownloadsDir() {
+ File serverHomeDir = getServerHomeDir();
+ File downloadDir = new File(serverHomeDir,
"deploy/rhq.ear/rhq-downloads/cli-alert-scripts");
+ if (!downloadDir.exists()) {
+ throw new RuntimeException("Server is missing connectors download
directory at [" + downloadDir + "]");
+ }
+ return downloadDir;
+ }
+
private File getClientDownloadDir() {
File serverHomeDir = getServerHomeDir();
File downloadDir = new File(serverHomeDir,
"deploy/rhq.ear/rhq-downloads/rhq-client");
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
index c8df668..e96c012 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
@@ -506,6 +506,10 @@ view_admin_downloads_bundle_help = <p> This is the Bundle
Deployer tool. It is f
view_admin_downloads_bundle_link_label = Link
view_admin_downloads_bundle_link_value = Download Bundle Deployer {0}
view_admin_downloads_bundle_loadError = Cannot get bundle deployer info
+view_admin_downloads_cliAlertScriptsDownload = CLI Alert Scripts Download
+view_admin_downloads_cliAlertScripts_help = CLI alert scripts are pre-canned scripts that
can be used for creating scripted alert notifications. The scripts will usually require
some tweaking before they can be used as a notification on a particular alert definition.
+view_admin_downloads_cliAlertScripts_loadError = Cannot get info on available CLI alert
scripts for download
+view_admin_downloads_cliAlertScripts_none = No CLI alert scripts are available for
download
view_admin_downloads_cliDownload = Command Line Client Download
view_admin_downloads_cli_buildNumber = CLI Build
view_admin_downloads_cli_help = <p> This is the Command Line Client tool, otherwise
known as the CLI. It is a standalone tool that runs from within a console and provides a
command line interface to the {0} Server. You can invoke commands via the CLI as well as
run scripts to perform automated tasks. See the documentation for more information on how
to install and use the CLI. </p>
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
index 76bbf6a..a42707d 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
@@ -466,6 +466,10 @@ view_admin_content = Inhalte
view_admin_downloads_agent_buildNumber = Build-Nummer des Agents
view_admin_downloads_agent_md5 = MD5 Prüfsumme des Agents
view_admin_downloads_agent_version = Version des Agents
+##view_admin_downloads_cliAlertScriptsDownload = CLI Alert Scripts Download
+##view_admin_downloads_cliAlertScripts_help = CLI alert scripts are pre-canned scripts
that can be used as templates for creating actual scripted alert notifications. The
scripts will usually require some tweaking before they can be used as a notification on a
particular alert definition.
+##view_admin_downloads_cliAlertScripts_loadError = Cannot get info on available CLI alert
scripts for download
+##view_admin_downloads_cliAlertScripts_none = No CLI alert scripts are available for
download
view_admin_downloads_cli_md5 = MD5 Prüfsumme des CLI
view_admin_downloads_cli_version = Version des CLI
##view_admin_landing = In dieser Sektion können die globalen Einstellungen für RHQ
verwaltet werden. Dies schließt Sicherheitseinstellungen und Plugins ein, sowie die
Verwaltung der RHQ Server- und Agentplugins.
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
index 1242729..71e3530 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
@@ -505,6 +505,10 @@ view_admin_downloads_bundleDownload = バンドルデプロイヤのダウンロ
view_admin_downloads_bundle_link_label = リンク
view_admin_downloads_bundle_link_value = バンドルデプロイヤー {0} をダウンロード
view_admin_downloads_bundle_loadError = バンドルデプロイヤー情報が取得できません
+##view_admin_downloads_cliAlertScriptsDownload = CLI Alert Scripts Download
+##view_admin_downloads_cliAlertScripts_help = CLI alert scripts are pre-canned scripts
that can be used for creating scripted alert notifications. The scripts will usually
require some tweaking before they can be used as a notification on a particular alert
definition.
+##view_admin_downloads_cliAlertScripts_loadError = Cannot get info on available CLI alert
scripts for download
+##view_admin_downloads_cliAlertScripts_none = No CLI alert scripts are available for
download
view_admin_downloads_cliDownload = コマンドラインクライアントのダウンロード
view_admin_downloads_cli_buildNumber = CLIビルド
##view_admin_downloads_cli_help = <p>
これはコマンドラインツールで、CLIとして知られているものです。コンソールから実行するスタンドアロンツールで、RHQサーバーに対してコマンドラインインタフェースを提供します。自動化されたタスクを実行するためにCLIやrunスクリプトを介してコマンドを呼び出すことが可能です。CLIのインストール方法と使い方についての詳細情報はドキュメントをご覧ください。</p>
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
index 6acfd8a..3a60da7 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
@@ -514,6 +514,10 @@ view_admin_downloads_bundleDownload = Bundle Deployer Download
##view_admin_downloads_bundle_help = <p> view_admin_downloads_bundle_link_label =
Link
view_admin_downloads_bundle_link_value = Download Bundle Deployer {0}
view_admin_downloads_bundle_loadError = Cannot get bundle deployer info
+##view_admin_downloads_cliAlertScriptsDownload = CLI Alert Scripts Download
+##view_admin_downloads_cliAlertScripts_help = CLI alert scripts are pre-canned scripts
that can be used for creating scripted alert notifications. The scripts will usually
require some tweaking before they can be used as a notification on a particular alert
definition.
+##view_admin_downloads_cliAlertScripts_loadError = Cannot get info on available CLI alert
scripts for download
+##view_admin_downloads_cliAlertScripts_none = No CLI alert scripts are available for
download
view_admin_downloads_cliDownload = Command Line Client Download
view_admin_downloads_cli_buildNumber = CLI Build
##view_admin_downloads_cli_help = <p> view_admin_downloads_cli_link_label = Link
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
index 89b23e8..7e4da98 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
@@ -503,6 +503,10 @@ view_admin_downloads_bundleDownload =
Bundle\u90e8\u7f72\u5668\u4e0b\u8f7d
view_admin_downloads_bundle_link_label = \u94fe\u63a5
view_admin_downloads_bundle_link_value = Download Bundle Deployer {0}
view_admin_downloads_bundle_loadError = Cannot get bundle deployer info
+##view_admin_downloads_cliAlertScriptsDownload = CLI Alert Scripts Download
+##view_admin_downloads_cliAlertScripts_help = CLI alert scripts are pre-canned scripts
that can be used for creating scripted alert notifications. The scripts will usually
require some tweaking before they can be used as a notification on a particular alert
definition.
+##view_admin_downloads_cliAlertScripts_loadError = Cannot get info on available CLI alert
scripts for download
+##view_admin_downloads_cliAlertScripts_none = No CLI alert scripts are available for
download
view_admin_downloads_cliDownload = \u547d\u4ee4\u884c\u5ba2\u6237\u7aef\u4e0b\u8f7d
view_admin_downloads_cli_buildNumber = CLI Build
##view_admin_downloads_cli_help = <p> This is the Command Line Client tool,
otherwise known as the CLI. It is a standalone tool that runs from within a console and
provides a command line interface to the RHQ Server. You can invoke commands via the CLI
as well as run scripts to perform automated tasks. See the documentation for more
information on how to install and use the CLI. </p>
diff --git
a/modules/enterprise/server/container/src/main/downloadable-resources/cli-alert-scripts/fix-bundle-deployment.js
b/modules/enterprise/server/container/src/main/downloadable-resources/cli-alert-scripts/fix-bundle-deployment.js
new file mode 100644
index 0000000..bc38983
--- /dev/null
+++
b/modules/enterprise/server/container/src/main/downloadable-resources/cli-alert-scripts/fix-bundle-deployment.js
@@ -0,0 +1,467 @@
+/**
+ * Using this script one can automatically reset a bundle deployment to a specified
version.
+ *
+ * This script consists of several utility methods originally included in standalone
files
+ * in the samples of the CLI distribution, which have been included in this file so that
it
+ * is usable on its own even in the server environment.
+ *
+ * The configuration of the bundle and its version to reset to is located at the top of
this file.
+ * Please provide the values to the variables as instructed to make this script work in
+ * a concrete situation.
+ */
+
+//----------------------------- script configuration
+
+/**
+ * Replace the "null" with the ID of the bundle destination you want to reset.
+ *
+ * The ID of the destination can be determined from the URL. If you navigate to
+ * some destination of a bundle, the destination ID is the number at the very
+ * end of the URL in the address bar of your browser.
+ *
+ * It can also be determined programmatically using the remote API of the RHQ
+ * server but that is beyond the scope of this comment.
+ */
+var destinationId = null;
+
+/**
+ * Replace the "null" with the ID of the bundle version the deployment should
be reset to.
+ *
+ * As with the destinations, the ID of a bundle version can be determined in the GUI by
+ * examining the URL. If you navigate to some version of a bundle, the bundle version ID
is
+ * the very last number in the URL in the address bar of the browser.
+ */
+var bundleVersionId = null;
+
+/**
+ * A deployment of the bundle version may require configuration. Normally, this can be
+ * provided as a simple javascript object (using the curly braces notation). Please see
+ * the documentation of the <code>asConfiguration</code> function further
down to understand
+ * the limitations of this approach. Should the simple format using the javascript
object
+ * be not possible, you have to build up a full
org.rhq.core.domain.configuration.Configuration
+ * object.
+ */
+var deploymentConfig = null;
+
+/**
+ * The description of the deployment that will be performed.
+ */
+var description = "redeploy due to drift";
+
+// DO NOT TOUCH THIS UNLESS YOU FULLY UNDERSTAND WHAT YOU ARE DOING.
+// NOTE: It's essential that isCleanDeployment=true, otherwise files that have
drifted will not be replaced with their
+// original versions from the bundle.
+var isCleanDeployment = true;
+
+//-------------------- util.js
+
+/**
+ * If obj is a JS array or a java.util.Collection, each element is passed to
+ * the callback function. If obj is a java.util.Map, each map entry is passed
+ * to the callback function as a key/value pair. If obj is none of the
+ * aforementioned types, it is treated as a generic object and each of its
+ * properties is passed to the callback function as a name/value pair.
+ */
+function foreach(obj, fn) {
+ if (obj instanceof Array) {
+ for (i in obj) {
+ fn(obj[i]);
+ }
+ }
+ else if (obj instanceof java.util.Collection) {
+ var iterator = obj.iterator();
+ while (iterator.hasNext()) {
+ fn(iterator.next());
+ }
+ }
+ else if (obj instanceof java.util.Map) {
+ var iterator = obj.entrySet().iterator()
+ while (iterator.hasNext()) {
+ var entry = iterator.next();
+ fn(entry.key, entry.value);
+ }
+ }
+ else { // assume we have a generic object
+ for (i in obj) {
+ fn(i, obj[i]);
+ }
+ }
+}
+
+/**
+ * Iterates over obj similar to foreach. fn should be a predicate that evaluates
+ * to true or false. The first match that is found is returned.
+ */
+function find(obj, fn) {
+ if (obj instanceof Array) {
+ for (i in obj) {
+ if (fn(obj[i])) {
+ return obj[i]
+ }
+ }
+ }
+ else if (obj instanceof java.util.Collection) {
+ var iterator = obj.iterator();
+ while (iterator.hasNext()) {
+ var next = iterator.next();
+ if (fn(next)) {
+ return next;
+ }
+ }
+ }
+ else if (obj instanceof java.util.Map) {
+ var iterator = obj.entrySet().iterator();
+ while (iterator.hasNext()) {
+ var entry = iterator.next();
+ if (fn(entry.key, entry.value)) {
+ return {key: entry.key, value: entry.value};
+ }
+ }
+ }
+ else {
+ for (i in obj) {
+ if (fn(i, obj[i])) {
+ return {key: i, value: obj[i]};
+ }
+ }
+ }
+ return null;
+}
+
+/**
+ * Iterates over obj similar to foreach. fn should be a predicate that evaluates
+ * to true or false. All of the matches are returned in a java.util.List.
+ */
+function findAll(obj, fn) {
+ var matches = java.util.ArrayList();
+ if ((obj instanceof Array) || (obj instanceof java.util.Collection)) {
+ foreach(obj, function(element) {
+ if (fn(element)) {
+ matches.add(element);
+ }
+ });
+ }
+ else {
+ foreach(obj, function(key, value) {
+ if (fn(theKey, theValue)) {
+ matches.add({key: theKey, value: theValue});
+ }
+ });
+ }
+ return matches;
+}
+
+/**
+ * A convenience function to convert javascript hashes into RHQ's configuration
+ * objects.
+ * <p>
+ * The conversion of individual keys in the hash follows these rules:
+ * <ol>
+ * <li> if a value of a key is a javascript array, it is interpreted as
PropertyList
+ * <li> if a value is a hash, it is interpreted as a PropertyMap
+ * <li> otherwise it is interpreted as a PropertySimple
+ * <li> a null or undefined value is ignored
+ * </ol>
+ * <p>
+ * Note that the conversion isn't perfect, because the hash does not contain enough
+ * information to restore the names of the list members.
+ * <p>
+ * Example: <br/>
+ * <pre><code>
+ * {
+ * simple : "value",
+ * list : [ "value1", "value2"],
+ * listOfMaps : [ { k1 : "value", k2 : "value" }, { k1 :
"value2", k2 : "value2" } ]
+ * }
+ * </code></pre>
+ * gets converted to a configuration object:
+ * Configuration:
+ * <ul>
+ * <li> PropertySimple(name = "simple", value = "value")
+ * <li> PropertyList(name = "list")
+ * <ol>
+ * <li>PropertySimple(name = "list", value = "value1")
+ * <li>PropertySimple(name = "list", value = "value2")
+ * </ol>
+ * <li> PropertyList(name = "listOfMaps")
+ * <ol>
+ * <li> PropertyMap(name = "listOfMaps")
+ * <ul>
+ * <li>PropertySimple(name = "k1", value = "value")
+ * <li>PropertySimple(name = "k2", value = "value")
+ * </ul>
+ * <li> PropertyMap(name = "listOfMaps")
+ * <ul>
+ * <li>PropertySimple(name = "k1", value = "value2")
+ * <li>PropertySimple(name = "k2", value = "value2")
+ * </ul>
+ * </ol>
+ * </ul>
+ * Notice that the members of the list have the same name as the list itself
+ * which generally is not the case.
+ */
+function asConfiguration(hash) {
+
+ config = new Configuration;
+
+ for(key in hash) {
+ value = hash[key];
+
+ if (value == null) {
+ continue;
+ }
+
+ (function(parent, key, value) {
+ function isArray(obj) {
+ return typeof(obj) == 'object' && (obj instanceof Array);
+ }
+
+ function isHash(obj) {
+ return typeof(obj) == 'object' && !(obj instanceof Array);
+ }
+
+ function isPrimitive(obj) {
+ return typeof(obj) != 'object';
+ }
+
+ //this is an anonymous function, so the only way it can call itself
+ //is by getting its reference via argument.callee. Let's just assign
+ //a shorter name for it.
+ var me = arguments.callee;
+
+ var prop = null;
+
+ if (isPrimitive(value)) {
+ prop = new PropertySimple(key, new java.lang.String(value));
+ } else if (isArray(value)) {
+ prop = new PropertyList(key);
+ for(var i = 0; i < value.length; ++i) {
+ var v = value[i];
+ if (v != null) {
+ me(prop, key, v);
+ }
+ }
+ } else if (isHash(value)) {
+ prop = new PropertyMap(key);
+ for(var i in value) {
+ var v = value[i];
+ if (value != null) {
+ me(prop, i, v);
+ }
+ }
+ }
+
+ if (parent instanceof PropertyList) {
+ parent.add(prop);
+ } else {
+ parent.put(prop);
+ }
+ })(config, key, value);
+ }
+
+ return config;
+}
+
+/**
+ * Opposite of <code>asConfiguration</code>. Converts an RHQ's
configuration object
+ * into a javascript hash.
+ *
+ * @param configuration
+ */
+function asHash(configuration) {
+ ret = {}
+
+ iterator = configuration.getMap().values().iterator();
+ while(iterator.hasNext()) {
+ prop = iterator.next();
+
+ (function(parent, prop) {
+ function isArray(obj) {
+ return typeof(obj) == 'object' && (obj instanceof Array);
+ }
+
+ function isHash(obj) {
+ return typeof(obj) == 'object' && !(obj instanceof Array);
+ }
+
+ var me = arguments.callee;
+
+ var representation = null;
+
+ if (prop instanceof PropertySimple) {
+ representation = prop.stringValue;
+ } else if (prop instanceof PropertyList) {
+ representation = [];
+
+ for(var i = 0; i < prop.list.size(); ++i) {
+ var child = prop.list.get(i);
+ me(representation, child);
+ }
+ } else if (prop instanceof PropertyMap) {
+ representation = {};
+
+ var childIterator = prop.getMap().values().iterator();
+ while(childIterator.hasNext()) {
+ var child = childIterator.next();
+
+ me(representation, child);
+ }
+ }
+
+ if (isArray(parent)) {
+ parent.push(representation);
+ } else if (isHash(parent)) {
+ parent[prop.name] = representation;
+ }
+ })(ret, prop);
+ }
+ (function(parent) {
+
+ })(configuration);
+
+ return ret;
+}
+
+//------------------------------ bundles.js
+
+/**
+ * A simple function to create a new bundle version from a zip file containing
+ * the bundle.
+ *
+ * @param pathToBundleZipFile the path to the bundle on the local file system
+ *
+ * @return an instance of BundleVersion class describing what's been created on
+ * the RHQ server.
+ */
+function createBundleVersion(pathToBundleZipFile) {
+ var bytes = getFileBytes(pathToBundleZipFile)
+ return BundleManager.createBundleVersionViaByteArray(bytes)
+}
+
+/**
+ * This is a helper function that one can use to find out what base directories
+ * given resource type defines.
+ * <p>
+ * These base directories then can be used when specifying bundle destinations.
+ *
+ * @param resourceTypeId
+ * @returns a java.util.Set of ResourceTypeBundleConfiguration objects
+ */
+function getAllBaseDirectories(resourceTypeId) {
+ var crit = new ResourceTypeCriteria;
+ crit.addFilterId(resourceTypeId);
+ crit.fetchBundleConfiguration(true);
+
+ var types = ResourceTypeManager.findResourceTypesByCriteria(crit);
+
+ if (types.size() == 0) {
+ throw "Could not find a resource type with id " + resourceTypeId;
+ } else if (types.size() > 1) {
+ throw "More than one resource type found with id " + resourceTypeId + "!
How did that happen!";
+ }
+
+ var type = types.get(0);
+
+ return type.getResourceTypeBundleConfiguration().getBundleDestinationBaseDirectories();
+}
+
+/**
+ * Creates a new destination for given bundle. Once a destination exists,
+ * actual bundle versions can be deployed to it.
+ * <p>
+ * Note that this only differs from the
<code>BundleManager.createBundleDestination</code>
+ * method in the fact that one can provide bundle and resource group names instead of
their
+ * ids.
+ *
+ * @param destinationName the name of the destination to be created
+ * @param description the description for the destination
+ * @param bundleName the name of the bundle to create the destination for
+ * @param groupName name of a group of resources that the destination will handle
+ * @param baseDirName the name of the basedir definition that represents where inside the
+ * deployment of the individual resources the bundle will get
deployed
+ * @param deployDir the specific sub directory of the base dir where the bundles will get
deployed
+ *
+ * @return BundleDestination object
+ */
+function createBundleDestination(destinationName, description, bundleName, groupName,
baseDirName, deployDir) {
+ var groupCrit = new ResourceGroupCriteria;
+ groupCrit.addFilterName(groupName);
+ var groups = ResourceGroupManager.findResourceGroupsByCriteria(groupCrit);
+
+ if (groups.empty) {
+ throw "No group called '" + groupName + "' found.";
+ }
+
+ var group = groups.get(0);
+
+ var bundleCrit = new BundleCriteria;
+ bundleCrit.addFilterName(bundleName);
+ var bundles = BundleManager.findBundlesByCriteria(bundleCrit);
+
+ if (bundles.empty) {
+ throw "No bundle called '" + bundleName + "' found.";
+ }
+
+ var bundle = bundles.get(0);
+
+ return BundleManager.createBundleDestination(bundle.id, destinationName, description,
baseDirName, deployDir, group.id);
+}
+
+/**
+ * Tries to deploy given bundle version to provided destination using given
configuration.
+ * <p>
+ * This method blocks while waiting for the deployment to complete or fail.
+ *
+ * @param destination the bundle destination (or id thereof)
+ * @param bundleVersion the bundle version to deploy (or id thereof)
+ * @param deploymentConfiguration the deployment configuration. This can be an ordinary
+ * javascript object (hash) or an instance of RHQ's Configuration. If it is the
former,
+ * it is converted to a Configuration instance using the
<code>asConfiguration</code>
+ * function from <code>util.js</code>. Please consult the documentation of
that method
+ * to understand the limitations of that approach.
+ * @param description the deployment description
+ * @param isCleanDeployment if true, perform a wipe of the deploy directory prior to the
deployment; if false,
+ * perform as an upgrade to the existing deployment, if any
+ *
+ * @return the BundleDeployment instance describing the deployment
+ */
+function deployBundle(destination, bundleVersion, deploymentConfiguration, description,
isCleanDeployment) {
+ var destinationId = destination;
+ if (typeof(destination) == 'object') {
+ destinationId = destination.id;
+ }
+
+ var bundleVersionId = bundleVersion;
+ if (typeof(bundleVersion) == 'object') {
+ bundleVersionId = bundleVersion.id;
+ }
+
+ var deploymentConfig = deploymentConfiguration;
+ if (!(deploymentConfiguration instanceof Configuration)) {
+ deploymentConfig = asConfiguration(deploymentConfiguration);
+ }
+
+ var deployment = BundleManager.createBundleDeployment(bundleVersionId, destinationId,
description, deploymentConfig);
+
+ deployment = BundleManager.scheduleBundleDeployment(deployment.id, isCleanDeployment);
+
+ var crit = new BundleDeploymentCriteria;
+ crit.addFilterId(deployment.id);
+
+ while (deployment.status == BundleDeploymentStatus.PENDING || deployment.status ==
BundleDeploymentStatus.IN_PROGRESS) {
+ java.lang.Thread.currentThread().sleep(1000);
+ var dps = BundleManager.findBundleDeploymentsByCriteria(crit);
+ if (dps.empty) {
+ throw "The deployment disappeared while we were waiting for it to
complete.";
+ }
+
+ deployment = dps.get(0);
+ }
+
+ return deployment;
+}
+
+//------------------- script body
+
+deployBundle(destinationId, bundleVersionId, deploymentConfig, description,
isCleanDeployment);
+
diff --git a/modules/enterprise/server/container/src/main/scripts/rhq-container.build.xml
b/modules/enterprise/server/container/src/main/scripts/rhq-container.build.xml
index d920ff9..9416b30 100644
--- a/modules/enterprise/server/container/src/main/scripts/rhq-container.build.xml
+++ b/modules/enterprise/server/container/src/main/scripts/rhq-container.build.xml
@@ -360,7 +360,18 @@
<fileset dir="${jboss.home}" includes="*.*" />
</delete>
- <!-- make sure our downloads directories exist -->
+ <!-- make sure the top level downloads directory exists -->
+ <mkdir dir="${jboss.deploy.dir}/${rhq.earName}/rhq-downloads" />
+
+ <!-- deploy all the static downloadable content -->
+ <echo>Deploying static downloadable content</echo>
+ <copy todir="${jboss.deploy.dir}/${rhq.earName}/rhq-downloads"
+ verbose="true"
+ failonerror="false">
+ <fileset dir="${basedir}/src/main/downloadable-resources" />
+ </copy>
+
+ <!-- make sure our downloads directories exist -->
<mkdir
dir="${jboss.deploy.dir}/${rhq.earName}/rhq-downloads/rhq-agent" />
<mkdir
dir="${jboss.deploy.dir}/${rhq.earName}/rhq-downloads/rhq-client" />
<mkdir
dir="${jboss.deploy.dir}/${rhq.earName}/rhq-downloads/rhq-plugins" />