etc/samples/custom-serverplugin/src/main/java/org/custom/MyLifecycleListener.java
| 2
modules/core/dbutils/pom.xml
| 6
modules/core/dbutils/src/main/scripts/dbsetup/alert-schema.xml
| 4
modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml
| 4
modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
| 40
modules/core/domain/src/main/java/org/rhq/core/domain/alert/Alert.java
| 56
modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
| 48
modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/EmailNotification.java
| 3
modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/RoleNotification.java
| 3
modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/SnmpNotification.java
| 3
modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/SubjectNotification.java
| 3
modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
| 401 ++++++
modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
| 510 -------
modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
| 153 ++
modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
| 293 ++++
modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
| 73 -
modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/ServerPluginTest.java
| 650 ++++++++++
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
| 36
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
| 48
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java
| 24
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java
| 124 +
modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
| 12
modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml
| 12
modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
| 7
modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/config/ViewDefinition.jsp
| 5
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml
| 3
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
| 6
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
| 5
modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
| 73 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
| 73 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java
| 14
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
| 69 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
| 20
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServerServiceImpl.java
| 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
| 51
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
| 136 --
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
| 89 -
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java
| 24
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ClassLoaderManager.java
| 34
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
| 91 -
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginEnvironment.java
| 12
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
| 18
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertSenderInfo.java
| 67 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertSenderPluginManager.java
| 84 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertServerPluginContainer.java
| 6
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginManager.java
| 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
| 18
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java
| 209 +--
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java
| 7
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
| 24
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestLifecycleListener.java
| 4
modules/enterprise/server/plugins/alert-email/pom.xml
| 8
modules/enterprise/server/plugins/alert-email/src/main/java/org/rhq/enterprise/server/plugins/alertEmail/EmailSender.java
| 14
modules/enterprise/server/plugins/alert-email/src/main/resources/META-INF/rhq-serverplugin.xml
| 15
modules/enterprise/server/xml-schemas/src/main/java/org/rhq/enterprise/server/xmlschema/ServerPluginDescriptorUtil.java
| 4
55 files changed, 2721 insertions(+), 981 deletions(-)
New commits:
commit ecd12c57abf6fb6b51993882babeb6b69d974583
Author: Heiko W. Rupp <pilhuhn(a)fedorapeople.org>
Date: Mon Nov 30 10:38:29 2009 +0100
Support for alert sender plugins and configuring them. WIP
diff --git a/modules/core/dbutils/pom.xml b/modules/core/dbutils/pom.xml
index 83fa2a2..0ab3e72 100644
--- a/modules/core/dbutils/pom.xml
+++ b/modules/core/dbutils/pom.xml
@@ -22,7 +22,7 @@
<properties>
<scm.module.path>modules/core/dbutils/</scm.module.path>
- <db.schema.version>2.69.3</db.schema.version>
+ <db.schema.version>2.70</db.schema.version>
</properties>
<dependencies>
@@ -48,14 +48,14 @@
<!-- NOTE: The version is defined in the root POM's dependencyManagement
section. -->
<scope>test</scope>
</dependency>
-
+
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<!-- NOTE: The version is defined in the root POM's dependencyManagement
section. -->
<scope>test</scope>
</dependency>
-
+
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/alert-schema.xml
b/modules/core/dbutils/src/main/scripts/dbsetup/alert-schema.xml
index 30d179b..f9560c1 100644
--- a/modules/core/dbutils/src/main/scripts/dbsetup/alert-schema.xml
+++ b/modules/core/dbutils/src/main/scripts/dbsetup/alert-schema.xml
@@ -78,6 +78,8 @@
<column name="RECOVERY_ID" type="INTEGER"
required="true"/>
<!-- required, but 0 effectively means null -->
<column name="WILL_RECOVER" required="true"
default="false" type="BOOLEAN"/>
+ <column name="ACK_TIME" required="false"
type="LONG"/>
+ <column name="ACK_BY_ID" required="false"
type="INTEGER" references="RHQ_SUBJECT(ID)"/>
<index name="RHQ_ALERT_IDX_TIME" unique="false">
<field ref="CTIME"/>
</index>
@@ -127,6 +129,8 @@
<column name="SNMP_HOST" size="100"
type="VARCHAR2"/>
<column name="SNMP_PORT" type="INTEGER"/>
<column name="SNMP_OID" size="250"
type="VARCHAR2"/>
+ <column name="ALERT_CONFIG_ID" required="false"
type="INTEGER" references="RHQ_CONFIG(ID)"/>
+ <column name="ALERT_SENDER_NAME" required="false"
type="VARCHAR2" /> <!-- TODO make required = true -->
</table>
</dbsetup>
diff --git a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
index c28b862..b2532b7 100644
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@ -2199,6 +2199,29 @@
<!-- add the new column that indicates what type of plugin this is (e.g.
alert, generic, content) - for server plugins only -->
<schema-addColumn table="RHQ_PLUGIN" column="PTYPE"
columnType="VARCHAR2" precision="200"/>
</schemaSpec>
+ <schemaSpec version="2.70">
+ <schema-addColumn table="RHQ_ALERT" column="ACK_TIME"
columnType="LONG" />
+ <schema-addColumn table="RHQ_ALERT" column="ACK_BY_ID"
columnType="INTEGER" />
+ <schema-directSQL>
+ <statement>
+ ALTER TABLE RHQ_ALERT
+ ADD CONSTRAINT RHQ_ALERT_SUBJECT_ID_FKEY
+ FOREIGN KEY (ACK_BY_ID)
+ REFERENCES RHQ_SUBJECT(ID)
+ </statement>
+ </schema-directSQL>
+ <schema-addColumn table="RHQ_ALERT_NOTIFICATION"
column="ALERT_SENDER_NAME" type="VARCHAR2"/>
+ <schema-addColumn table="RHQ_ALERT_NOTIFICATION"
column="ALERT_CONFIG_ID" type="INTEGER"/>
+ <schema-directSQL>
+ <statement>
+ ALTER TABLE RHQ_ALERT_NOTIFICATION
+ ADD CONSTRAINT RHQ_ALERT_CONFIG_ID_FKEY
+ FOREIGN KEY (ALERT_CONFIG_ID)
+ REFERENCES RHQ_CONFIG(ID)
+ </statement>
+ </schema-directSQL>
+
+ </schemaSpec>
</dbupgrade>
</target>
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/Alert.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/Alert.java
index 7842e19..9f0f76a 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/Alert.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/Alert.java
@@ -43,6 +43,7 @@ import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.rhq.core.domain.alert.notification.AlertNotificationLog;
+import org.rhq.core.domain.auth.Subject;
/**
* @author Joseph Marques
@@ -66,7 +67,7 @@ import org.rhq.core.domain.alert.notification.AlertNotificationLog;
+ " AND ( :priority = a.alertDefinition.priority OR :priority IS NULL )
"
+ " AND res.id IN ( :resourceIds )"),
@NamedQuery(name = Alert.QUERY_FIND_BY_RESOURCE, //
- query = "SELECT a " //
+ query = "SELECT a " //
+ " FROM Alert AS a "
+ " WHERE a.alertDefinition.resource.id = :id "
+ " AND (a.alertDefinition.id = :alertDefinitionId OR :alertDefinitionId
IS NULL) "
@@ -138,16 +139,16 @@ import org.rhq.core.domain.alert.notification.AlertNotificationLog;
+ " FROM AlertDefinition ad " //
+ " WHERE ad.resource.id IN ( :resourceIds )
)"),
@NamedQuery(name = Alert.QUERY_FIND_ALL_COMPOSITES_ADMIN, query = "" //
- + " SELECT new
org.rhq.core.domain.alert.composite.AlertHistoryComposite" //
+ + " SELECT new
org.rhq.core.domain.alert.composite.AlertHistoryComposite" //
+ " ( a, parent.id, parent.name ) " //
+ " FROM Alert a " //
+ " JOIN a.alertDefinition ad " //
+ " JOIN ad.resource res " //
+ "LEFT JOIN res.parentResource parent " //
- /*
+ /*
* as much as i want to (for efficiency of the query [namely roundtrips to the
db]) i can't use fetching here
- * because, when added, the query parser chokes with "query specified join
fetching, but the owner of the
- * fetched association was not present in the select list"...even though it
clearly is ;/
+ * because, when added, the query parser chokes with "query specified join
fetching, but the owner of the
+ * fetched association was not present in the select list"...even though it
clearly is ;/
*/
//+ " JOIN FETCH a.conditionLogs acl " //
+ " WHERE (UPPER(res.name) LIKE :resourceFilter OR :resourceFilter IS
NULL) " //
@@ -155,21 +156,21 @@ import org.rhq.core.domain.alert.notification.AlertNotificationLog;
+ " AND (a.ctime > :startTime OR :startTime IS NULL) " //
+ " AND (a.ctime < :endTime OR :endTime IS NULL) " //
+ " AND (a.id IN ( SELECT aa.id FROM Alert aa " //
- + " JOIN aa.conditionLogs aacl " //
+ + " JOIN aa.conditionLogs aacl " //
+ " JOIN aacl.condition ac " //
+ " WHERE ac.category = :category ) " //
+ " OR :category IS NULL) "), //
@NamedQuery(name = Alert.QUERY_FIND_ALL_COMPOSITES, query = "" //
- + " SELECT new
org.rhq.core.domain.alert.composite.AlertHistoryComposite" //
+ + " SELECT new
org.rhq.core.domain.alert.composite.AlertHistoryComposite" //
+ " ( a, parent.id, parent.name ) " //
+ " FROM Alert a " //
+ " JOIN a.alertDefinition ad " //
+ " JOIN ad.resource res " //
+ "LEFT JOIN res.parentResource parent " //
- /*
+ /*
* as much as i want to (for efficiency of the query [namely roundtrips to the
db]) i can't use fetching here
- * because, when added, the query parser chokes with "query specified join
fetching, but the owner of the
- * fetched association was not present in the select list"...even though it
clearly is ;/
+ * because, when added, the query parser chokes with "query specified join
fetching, but the owner of the
+ * fetched association was not present in the select list"...even though it
clearly is ;/
*/
//+ " JOIN FETCH a.conditionLogs acl " //
+ " WHERE res.id IN ( SELECT rr.id FROM Resource rr " //
@@ -180,7 +181,7 @@ import org.rhq.core.domain.alert.notification.AlertNotificationLog;
+ " AND (a.ctime > :startTime OR :startTime IS NULL) " //
+ " AND (a.ctime < :endTime OR :endTime IS NULL) " //
+ " AND (a.id IN ( SELECT aa.id FROM Alert aa " //
- + " JOIN aa.conditionLogs aacl " //
+ + " JOIN aa.conditionLogs aacl " //
+ " JOIN aacl.condition ac " //
+ " WHERE ac.category = :category ) " //
+ " OR :category IS NULL) ") })
@@ -233,6 +234,7 @@ public class Alert implements Serializable {
@OneToOne(mappedBy = "alert")
private AlertNotificationLog alertNotificationLog;
+ @Deprecated
@Column(name = "TRIGGERED_OPERATION", nullable = true)
private String triggeredOperation;
@@ -247,6 +249,18 @@ public class Alert implements Serializable {
@Column(name = "WILL_RECOVER", nullable = false)
private boolean willRecover;
+
+
+
+ @Column(name ="ACK_TIME")
+ private long ackTime;
+
+ @JoinColumn(name = "ACK_BY_ID", referencedColumnName = "ID")
+ @ManyToOne
+ private Subject ackBy;
+
+
+
/**
* Creates a new alert. (required by EJB3 spec, but not used)
*/
@@ -265,7 +279,7 @@ public class Alert implements Serializable {
this.willRecover = alertDefinition.getWillRecover();
// Do not load the collection side from a one-to-many, This is very slow to load
all existing alerts
// and unnecessary for creating the link
- // alertDefinition.addAlert(this);
+ // alertDefinition.addAlert(this);
this.ctime = ctime;
if (alertDefinition.getOperationDefinition() != null) {
setTriggeredOperation(alertDefinition.getOperationDefinition().getDisplayName());
@@ -314,6 +328,22 @@ public class Alert implements Serializable {
this.triggeredOperation = triggeredOperation;
}
+ public long getAckTime() {
+ return ackTime;
+ }
+
+ public void setAckTime(long ackTime) {
+ this.ackTime = ackTime;
+ }
+
+ public Subject getAckBy() {
+ return ackBy;
+ }
+
+ public void setAckBy(Subject ackBy) {
+ this.ackBy = ackBy;
+ }
+
public boolean getWillRecover() {
return this.willRecover;
}
@@ -368,4 +398,4 @@ public class Alert implements Serializable {
return "org.rhq.core.domain.alert.Alert[id=" + this.id + ",
alertDefinition=" + this.alertDefinition
+ ", ctime=" + this.ctime + "]";
}
-}
\ No newline at end of file
+}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
index 940b0f1..eec3a6c 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java
@@ -24,10 +24,12 @@ package org.rhq.core.domain.alert.notification;
import java.io.Serializable;
+import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@@ -37,12 +39,14 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.jetbrains.annotations.NotNull;
import org.rhq.core.domain.alert.AlertDefinition;
+import org.rhq.core.domain.configuration.Configuration;
@DiscriminatorColumn(name = "NOTIFICATION_TYPE", discriminatorType =
DiscriminatorType.STRING)
@Entity
@@ -53,7 +57,7 @@ import org.rhq.core.domain.alert.AlertDefinition;
@NamedQuery(name = AlertNotification.QUERY_DELETE_ORPHANED, query = "DELETE FROM
AlertNotification an WHERE an.alertDefinition IS NULL") })
@SequenceGenerator(name = "RHQ_ALERT_NOTIFICATION_ID_SEQ", sequenceName =
"RHQ_ALERT_NOTIFICATION_ID_SEQ")
@Table(name = "RHQ_ALERT_NOTIFICATION")
-public abstract class AlertNotification implements Serializable {
+public class AlertNotification implements Serializable {
private static final long serialVersionUID = 1L;
@@ -70,17 +74,35 @@ public abstract class AlertNotification implements Serializable {
@ManyToOne
private AlertDefinition alertDefinition;
+ @JoinColumn(name = "ALERT_CONFIG_ID", referencedColumnName =
"ID")
+ @OneToOne(cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
+ private Configuration configuration;
+
+ @Column(name = "ALERT_SENDER_NAME")
+ private String senderName;
+
protected AlertNotification() {
} // JPA spec
- public AlertNotification(@NotNull AlertDefinition alertDefinition) {
+ public AlertNotification(AlertDefinition alertDefinition) {
+ if (alertDefinition == null) {
+ throw new IllegalArgumentException("alertDefinition must be
non-null.");
+ }
+
+ this.alertDefinition = alertDefinition;
+ }
+
+ public AlertNotification(AlertDefinition alertDefinition, Configuration config) {
if (alertDefinition == null) {
throw new IllegalArgumentException("alertDefinition must be
non-null.");
}
this.alertDefinition = alertDefinition;
+ this.configuration = config.deepCopy();
}
+
+
public int getId() {
return id;
}
@@ -102,9 +124,27 @@ public abstract class AlertNotification implements Serializable {
return results;
}
- protected abstract AlertNotification copy();
+ protected AlertNotification copy() {
+ return new AlertNotification(this.alertDefinition,this.configuration);
+ }
public void prepareForOrphanDelete() {
this.alertDefinition = null;
}
-}
\ No newline at end of file
+
+ public String getSenderName() {
+ return senderName;
+ }
+
+ public void setSenderName(String senderName) {
+ this.senderName = senderName;
+ }
+
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ }
+}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/EmailNotification.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/EmailNotification.java
index 6e52e92..da713bc 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/EmailNotification.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/EmailNotification.java
@@ -39,6 +39,7 @@ import org.rhq.core.domain.alert.AlertDefinition;
+ " FROM EmailNotification en " + " WHERE en.alertDefinition.id =
:alertDefinitionId "),
@NamedQuery(name = EmailNotification.QUERY_FIND_BY_IDS, query = "SELECT en
" + " FROM EmailNotification en "
+ " WHERE en.id IN ( :ids )") })
+@Deprecated
public class EmailNotification extends AlertNotification {
private static final long serialVersionUID = 1L;
@@ -107,4 +108,4 @@ public class EmailNotification extends AlertNotification {
+ ", " + "]";
}
-}
\ No newline at end of file
+}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/RoleNotification.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/RoleNotification.java
index f234ae2..696895b 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/RoleNotification.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/RoleNotification.java
@@ -43,6 +43,7 @@ import org.rhq.core.domain.authz.Role;
+ " WHERE rn.id IN ( :ids )"),
@NamedQuery(name = RoleNotification.QUERY_FIND_BY_ROLE_IDS, query = "SELECT rn
" + " FROM RoleNotification rn "
+ " WHERE rn.role.id IN ( :ids )") })
+@Deprecated
public class RoleNotification extends AlertNotification {
private static final long serialVersionUID = 1L;
@@ -125,4 +126,4 @@ public class RoleNotification extends AlertNotification {
public String toString() {
return this.getClass().getSimpleName() + "[" + "id=" +
getId() + ", " + "role=" + this.role + ", " +
"]";
}
-}
\ No newline at end of file
+}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/SnmpNotification.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/SnmpNotification.java
index 4775c34..1507cb8 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/SnmpNotification.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/SnmpNotification.java
@@ -42,6 +42,7 @@ import org.rhq.core.domain.alert.AlertDefinition;
@Entity
@NamedQueries( { @NamedQuery(name =
SnmpNotification.QUERY_FIND_ALL_BY_ALERT_DEFINITION_ID, query = "SELECT sn "
+ " FROM SnmpNotification sn " + " WHERE sn.alertDefinition.id =
:alertDefinitionId ") })
+@Deprecated
public class SnmpNotification extends AlertNotification {
private static final long serialVersionUID = 1L;
@@ -141,4 +142,4 @@ public class SnmpNotification extends AlertNotification {
return this.getClass().getSimpleName() + "[" + "id=" +
getId() + ", " + "host=" + this.host + ", " +
"port="
+ this.port + ", " + "oid=" + this.oid + ", " +
"]";
}
-}
\ No newline at end of file
+}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/SubjectNotification.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/SubjectNotification.java
index 1c80727..18a90bc 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/SubjectNotification.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/SubjectNotification.java
@@ -43,6 +43,7 @@ import org.rhq.core.domain.auth.Subject;
+ " WHERE sn.id IN ( :ids )"),
@NamedQuery(name = SubjectNotification.QUERY_FIND_BY_SUBJECT_IDS, query =
"SELECT sn "
+ " FROM SubjectNotification sn " + " WHERE sn.subject.id IN (
:ids )") })
+@Deprecated
public class SubjectNotification extends AlertNotification {
private static final long serialVersionUID = 1L;
@@ -125,4 +126,4 @@ public class SubjectNotification extends AlertNotification {
public String toString() {
return this.getClass().getSimpleName() + "[" + "id=" +
getId() + ", " + "subject=" + this.subject + ", " +
"]";
}
-}
\ No newline at end of file
+}
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java
new file mode 100644
index 0000000..7e79bab
--- /dev/null
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/ListNotificationsUIBean.java
@@ -0,0 +1,124 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 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.alert;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.enterprise.server.alert.AlertNotificationManagerLocal;
+import org.rhq.enterprise.server.util.LookupUtil;
+
+/**
+ * Backing bean for the new AlertNotifications stuff
+ * @author Heiko W. Rupp
+ */
+(a)Scope(ScopeType.PAGE)
+@Name("ListNotificationsUIBean")
+public class ListNotificationsUIBean {
+
+ public static final String MANAGED_BEAN_NAME = "ListNotificationsUIBean";
+ private static final String OUTCOME_SUCCESS = "success";
+
+ private final Log log = LogFactory.getLog(ListNotificationsUIBean.class);
+
+ private String selectedSender;
+
+ private ConfigurationDefinition alertConfigurationDefinition;
+ private Configuration alertProperties;
+ int ad;
+
+
+ public ListNotificationsUIBean() {
+ }
+
+ public Map<String,String> getAllAlertSenders() {
+ AlertNotificationManagerLocal notificationManager =
LookupUtil.getAlertNotificationManager();
+ List<String> senders = notificationManager.listAllAlertSenders();
+ Map<String,String> result = new HashMap<String,String>();
+ for (String sender: senders)
+ result.put(sender,sender);
+
+ return result;
+ }
+
+
+ public ConfigurationDefinition getAlertConfigurationDefinition() {
+
+ if (alertConfigurationDefinition==null) {
+ lookupAlertConfigDefinition();
+ }
+
+ return alertConfigurationDefinition;
+ }
+
+ private void lookupAlertConfigDefinition() {
+ AlertNotificationManagerLocal mgr = LookupUtil.getAlertNotificationManager();
+ alertConfigurationDefinition =
mgr.getConfigurationDefinitionForSender(selectedSender);
+
+ }
+
+ public Configuration getAlertProperties() {
+ AlertNotificationManagerLocal mgr = LookupUtil.getAlertNotificationManager();
+
+ // TODO in case of listing an existing notification get this from the properties
on the notification
+ if (alertProperties==null) {
+ if (alertConfigurationDefinition==null)
+ alertConfigurationDefinition = getAlertConfigurationDefinition();
+ alertProperties =
alertConfigurationDefinition.getDefaultTemplate().getConfiguration();
+ }
+ return alertProperties;
+ }
+
+ public void setAlertProperties(Configuration alertProperties) {
+ this.alertProperties = alertProperties;
+ }
+
+ public String getSelectedSender() {
+ return selectedSender;
+ }
+
+ public void setSelectedSender(String selectedSender) {
+ this.selectedSender = selectedSender;
+ }
+
+ public String mySubmitForm() {
+ System.out.println("In submit Form ");
+ log.info("In submit Form ");
+ return OUTCOME_SUCCESS;
+ }
+
+ public int getAd() {
+ return ad;
+ }
+
+ public void setAd(int ad) {
+ this.ad = ad;
+ }
+}
\ No newline at end of file
diff --git
a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
index 5f93540..d41bd31 100644
---
a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
+++
b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-managed-beans/alert-beans.xml
@@ -10,14 +10,14 @@
<managed-bean-class>org.rhq.enterprise.gui.alert.ListAlertDefinitionsUIBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
-
+
<!-- /rhq/resource/alert/listAlertHistory.xhtml -->
<managed-bean>
<managed-bean-name>ListAlertHistoryUIBean</managed-bean-name>
<managed-bean-class>org.rhq.enterprise.gui.alert.ListAlertHistoryUIBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
-
+
<!-- /rhq/admin/listAlertTemplates.xhtml -->
<managed-bean>
<managed-bean-name>ListAlertTemplatesUIBean</managed-bean-name>
@@ -25,4 +25,12 @@
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
+ <!-- /rhq/resource/alert/notif -->
+ <managed-bean>
+ <description>Handling of alert senders</description>
+ <managed-bean-name>ListNotificationsUIBean</managed-bean-name>
+
<managed-bean-class>org.rhq.enterprise.gui.alert.ListNotificationsUIBean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
+
</faces-config>
\ No newline at end of file
diff --git
a/modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/config/ViewDefinition.jsp
b/modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/config/ViewDefinition.jsp
index 66300cf..c445744 100644
---
a/modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/config/ViewDefinition.jsp
+++
b/modules/enterprise/gui/portal-war/src/main/webapp/resource/common/monitor/alerts/config/ViewDefinition.jsp
@@ -1,10 +1,13 @@
<%@ page language="java" %>
<%@ page errorPage="/common/Error.jsp" %>
<%@ taglib
uri="http://jakarta.apache.org/struts/tags-tiles"
prefix="tiles" %>
+<%@ taglib
uri="http://jakarta.apache.org/struts/tags-html-el"
prefix="html" %>
<tiles:insert definition=".page.title.events">
<tiles:put name="titleKey"
value="alert.config.props.ViewDef.PageTitle"/>
</tiles:insert>
+<tiles:importAttribute name="id" ignore="true"/>
+<tiles:importAttribute name="ad" ignore="true"/>
<tiles:insert definition=".portlet.error"/>
<tiles:insert definition=".portlet.confirm"/>
@@ -23,4 +26,6 @@
<tiles:insert definition=".events.config.view.nav"/>
+<a
href="/rhq/resource/alert/notif/listAlertSender.xhtml?id=${param.id}&ad=${param.ad}">Alert
sender stuff</a> <!-- TODO fix and pass real id + ad-->
+
<tiles:insert definition=".page.footer"/>
diff --git
a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
new file mode 100644
index 0000000..e902b81
--- /dev/null
+++
b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/resource/alert/notif/listAlertSender.xhtml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:c="http://java.sun.com/jstl/core"
+
xmlns:onc="http://jboss.org/on/component"
+
xmlns:a4j="https://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.ajax4jsf.org/rich">
+
+<ui:composition template="/rhq/layout/main.xhtml">
+
+ <ui:param name="pageTitle" value="List Alert Notifications for
Resource"/> <!-- '#{ResourceUIBean.name}'"/> -->
+
+ <ui:define name="breadcrumbs">
+ <h:outputLink value="http://localhost:7080/alerts/Config.do">
+ <f:param name="mode" value="viewRoles"/>
+ <f:param name="id" value="#{param.id}"/>
+ <f:param name="ad" value="#{param.ad}"/>
+ <h:outputText>Alert Definitions</h:outputText>
+ </h:outputLink>
+ <h:outputText> > </h:outputText>
+ <h:outputLink value="listAlertSender.xhtml">
+ Alert Sender stuff
+ </h:outputLink>
+ </ui:define>
+
+ <ui:define name="body">
+ <br/>
+ <h:messages showSummary="true"
+ showDetail="true"
+ infoClass="InfoBlock"
+ warnClass="WarnBlock"
+ errorClass="ErrorBlock"
+ fatalClass="FatalBlock"
+ globalOnly="true"
+ layout="table"
+ width="100%"/>
+
+ <p/>
+ <h:outputText>Hello World</h:outputText>
+ <h:form id="listSenderForm">
+ <input type="hidden" name="id"
value="${param.id}"/>
+ <input type="hidden" name="ad"
value="${param.ad}"/>
+ <h:selectOneMenu id="senderList"
value="#{ListNotificationsUIBean.selectedSender}">
+ <f:selectItems
value="#{ListNotificationsUIBean.allAlertSenders}"/>
+ </h:selectOneMenu>
+ <h:commandButton
+ id="submit"
+ value="go"
+ action="nextPage"/>
+
+ <p/>
+ <rich:panel rendered="#{ListNotificationsUIBean.selectedSender !=
null}">
+ <h:outputText>Properties for:
#{ListNotificationsUIBean.selectedSender}</h:outputText>
+ <h:outputText>Rendered:</h:outputText>
+ <h:outputText
value="#{ListNotificationsUIBean.selectedSender}"/>
+ <onc:config
+
configurationDefinition="#{ListNotificationsUIBean.alertConfigurationDefinition}"
+ configuration="#{ListNotificationsUIBean.alertProperties}"
+ readOnly="false"/>
+ <h:commandButton
+ id="submit2"
+ value="Submit it"
+ type="submit"
+ action="#{ListNotificationsUIBean.mySubmitForm}"
+ />
+ </rich:panel>
+ </h:form>
+ </ui:define>
+</ui:composition>
+</html>
\ No newline at end of file
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
index 78d4342..0c1a1a5 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerBean.java
@@ -61,6 +61,9 @@ import org.rhq.core.domain.alert.notification.SnmpNotification;
import org.rhq.core.domain.alert.notification.SubjectNotification;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.criteria.AlertCriteria;
import org.rhq.core.domain.measurement.MeasurementSchedule;
import org.rhq.core.domain.measurement.MeasurementUnits;
@@ -83,6 +86,11 @@ import org.rhq.enterprise.server.core.EmailManagerLocal;
import org.rhq.enterprise.server.measurement.instrumentation.MeasurementMonitor;
import org.rhq.enterprise.server.measurement.util.MeasurementFormatter;
import org.rhq.enterprise.server.operation.OperationManagerLocal;
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.alert.AlertSender;
+import org.rhq.enterprise.server.plugin.pc.alert.AlertSenderPluginManager;
+import org.rhq.enterprise.server.plugin.pc.alert.AlertServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.alert.SenderResult;
import org.rhq.enterprise.server.resource.ResourceManagerLocal;
import org.rhq.enterprise.server.system.SystemManagerLocal;
import org.rhq.enterprise.server.util.CriteriaQueryGenerator;
@@ -182,7 +190,7 @@ public class AlertManagerBean implements AlertManagerLocal,
AlertManagerRemote {
}
/*
- * Since BULK delete JPQL doesn't enforce cascade options, we need to delete
the logs first and then the
+ * Since BULK delete JPQL doesn't enforce cascade options, we need to delete
the logs first and then the
* corresponding Alerts
*/
long totalTime = 0L;
@@ -533,6 +541,22 @@ public class AlertManagerBean implements AlertManagerLocal,
AlertManagerRemote {
}
}
+ /**
+ * Mark the matching alert as acknowledged by the user
+ * @param alertId Id of the alert to acknowledge
+ * @param user user who acknowledged the alert
+ */
+ public void acknowledgeAlert(int alertId, Subject user) {
+ Alert alert = entityManager.find(Alert.class,alertId);
+ if (alert==null) {
+ log.warn("Alert [ " + alertId + " ] to acknowledge was not
found ");
+ return;
+ }
+ alert.setAckBy(user);
+ alert.setAckTime(System.currentTimeMillis());
+ }
+
+
public void fireAlert(int alertDefinitionId) {
log.debug("Firing an alert for alertDefinition with id=" +
alertDefinitionId + "...");
@@ -640,12 +664,45 @@ public class AlertManagerBean implements AlertManagerLocal,
AlertManagerRemote {
}
}
+ AlertNotification test = new AlertNotification(alert.getAlertDefinition());
+ test.setSenderName("Email");
+ test.setConfiguration(new Configuration());
+ Property prop = new
PropertySimple("emailAddress","hwr(a)redhat.com");
+ test.getConfiguration().getProperties().add(prop);
+ AlertSender sender = getAlertSender(test);
+ if (sender!=null) {
+ try {
+ SenderResult result = sender.send(alert);
+ }
+ catch (Throwable t) {
+ log.error("Sender failed: " + t.getMessage());
+ }
+ }
+
sendAlertNotificationEmails(alert, emailAddresses);
} catch (Exception e) {
log.error("Failed to send all notifications for " +
alert.toSimpleString(), e);
}
}
+ /**
+ * Return the plugin manager that is managing alert sender plugins
+ * @return The alert sender plugin manager
+ */
+ public AlertSenderPluginManager getAlertPluginManager() {
+ MasterServerPluginContainer container =
LookupUtil.getServerPluginService().getMasterPluginContainer();
+ AlertServerPluginContainer pc =
container.getPluginContainerByClass(AlertServerPluginContainer.class);
+ AlertSenderPluginManager manager = (AlertSenderPluginManager)
pc.getPluginManager();
+
+ return manager;
+ }
+
+ AlertSender getAlertSender(AlertNotification notification) {
+ AlertSenderPluginManager manager = getAlertPluginManager();
+ AlertSender sender = manager.getAlertSenderForNotification(notification);
+ return sender;
+ }
+
private void processEmailAddress(Alert alert, String emailAddress, Set<String>
emailAddresses) {
if (emailAddress == null) {
return;
@@ -872,10 +929,10 @@ public class AlertManagerBean implements AlertManagerLocal,
AlertManagerRemote {
}
/*
- * there's no reason to update the cache directly anymore. even though
this direct type of update is safe
+ * there's no reason to update the cache directly anymore. even though
this direct type of update is safe
* (because we know the AlertManager will only be executing on the same
server instance that is processing
- * these recovery alerts now) it's unnecessary because changes made via
the AlertDefinitionManager will
- * update the cache indirectly via the status field on the owning agent and
the periodic job that checks it.
+ * these recovery alerts now) it's unnecessary because changes made via
the AlertDefinitionManager will
+ * update the cache indirectly via the status field on the owning agent and
the periodic job that checks it.
*/
} else if (firedDefinition.getWillRecover()) {
log.debug("Disabling " + firedDefinition + " until recovered
manually or by recovery definition");
@@ -888,10 +945,10 @@ public class AlertManagerBean implements AlertManagerLocal,
AlertManagerRemote {
alertDefinitionManager.disableAlertDefinitions(overlord, new Integer[] {
firedDefinition.getId() });
/*
- * there's no reason to update the cache directly anymore. even though
this direct type of update is safe
+ * there's no reason to update the cache directly anymore. even though
this direct type of update is safe
* (because we know the AlertManager will only be executing on the same
server instance that is processing
- * these recovery alerts now) it's unnecessary because changes made via
the AlertDefinitionManager will
- * update the cache indirectly via the status field on the owning agent and
the periodic job that checks it.
+ * these recovery alerts now) it's unnecessary because changes made via
the AlertDefinitionManager will
+ * update the cache indirectly via the status field on the owning agent and
the periodic job that checks it.
*/
}
}
@@ -911,4 +968,4 @@ public class AlertManagerBean implements AlertManagerLocal,
AlertManagerRemote {
return alerts;
}
-}
\ No newline at end of file
+}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java
index 3fde62d..5b3479c 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertManagerLocal.java
@@ -30,6 +30,7 @@ import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.criteria.AlertCriteria;
import org.rhq.core.domain.util.PageControl;
import org.rhq.core.domain.util.PageList;
+import org.rhq.enterprise.server.plugin.pc.alert.AlertSenderPluginManager;
/**
* @author Joseph Marques
@@ -86,4 +87,17 @@ public interface AlertManagerLocal {
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
PageList<Alert> findAlertsByCriteria(Subject subject, AlertCriteria criteria);
+
+ /**
+ * Mark the matching alert as acknowledged by the user
+ * @param alertId Id of the alert to acknowledge
+ * @param user user who acknowledged the alert
+ */
+ void acknowledgeAlert(int alertId, Subject user);
+
+ /**
+ * Return the plugin manager that is managing alert sender plugins
+ * @return The alert sender plugin manager
+ */
+ AlertSenderPluginManager getAlertPluginManager();
}
\ No newline at end of file
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
index c8d4c54..de7362e 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java
@@ -34,6 +34,8 @@ import javax.persistence.Query;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.rhq.core.clientapi.agent.metadata.ConfigurationMetadataParser;
+import org.rhq.core.clientapi.descriptor.configuration.ConfigurationDescriptor;
import org.rhq.core.domain.alert.AlertDefinition;
import org.rhq.core.domain.alert.AlertDefinitionContext;
import org.rhq.core.domain.alert.notification.AlertNotification;
@@ -44,6 +46,9 @@ import org.rhq.core.domain.alert.notification.SubjectNotification;
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.configuration.Configuration;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.util.PageControl;
import org.rhq.core.domain.util.PageList;
import org.rhq.core.domain.util.PersistenceUtility;
@@ -52,6 +57,12 @@ import org.rhq.enterprise.server.auth.SubjectManagerLocal;
import org.rhq.enterprise.server.authz.AuthorizationManagerLocal;
import org.rhq.enterprise.server.authz.PermissionException;
import org.rhq.enterprise.server.authz.RoleManagerLocal;
+import org.rhq.enterprise.server.configuration.ConfigurationManagerLocal;
+import
org.rhq.enterprise.server.configuration.metadata.ConfigurationMetadataManagerLocal;
+import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
+import org.rhq.enterprise.server.plugin.pc.alert.AlertSenderPluginManager;
+import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
+import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.alert.AlertPluginDescriptorType;
/**
* @author Joseph Marques
@@ -66,6 +77,8 @@ public class AlertNotificationManagerBean implements
AlertNotificationManagerLoc
@EJB
private AlertTemplateManagerLocal alertTemplateManager;
@EJB
+ private AlertManagerLocal alertManager;
+ @EJB
private GroupAlertDefinitionManagerLocal groupAlertDefintionManager;
@EJB
private AuthorizationManagerLocal authorizationManager;
@@ -73,6 +86,12 @@ public class AlertNotificationManagerBean implements
AlertNotificationManagerLoc
private RoleManagerLocal roleManager;
@EJB
private SubjectManagerLocal subjectManager;
+ @EJB
+ private ConfigurationMetadataManagerLocal confMeMan;
+ @EJB
+ private ServerPluginsLocal serverPluginsBean;
+ @EJB
+ private ConfigurationManagerLocal configManager;
@PersistenceContext(unitName = RHQConstants.PERSISTENCE_UNIT_NAME)
private EntityManager entityManager;
@@ -84,7 +103,7 @@ public class AlertNotificationManagerBean implements
AlertNotificationManagerLoc
* into AlertDefinitionManager.updateAlertDefinition() which starts a new
transaction, the work will be
* performed at the AlertTemplate layer twice. This would result in duplicate
notifications (RHQ-629) as
* well as errors during removal (which would be attempted twice for each being
removed).
- *
+ *
* Must, however, return an AlertDefinition with a copy of the ids because the
removeNotifications method
* needs to compare ids to figure out what to remove from the set of notifications.
*/
@@ -430,4 +449,52 @@ public class AlertNotificationManagerBean implements
AlertNotificationManagerLoc
}
}
}
+
+ public void handleAlertConfigurationDefinition(ConfigurationDefinition desc) {
+
+ // TODO
+ }
+
+ public Configuration getAlertPropertiesConfiguration(AlertNotification notification)
{
+ Configuration config = notification.getConfiguration();
+ if (config!=null)
+ config = config.deepCopy();
+
+ return config;
+ }
+
+ public ConfigurationDefinition getConfigurationDefinitionForSender(String shortName)
{
+ AlertSenderPluginManager pluginmanager = alertManager.getAlertPluginManager();
+ String pluginName = pluginmanager.getPluginNameForShortName(shortName);
+ PluginKey key = pluginmanager.getAlertSenderInfo(shortName).getPluginKey();
+ try {
+ AlertPluginDescriptorType descriptor = (AlertPluginDescriptorType)
serverPluginsBean.getServerPluginDescriptor(key);
+ // TODO get alert-propertis, not plugin-configuration
+ //ConfigurationDefinition pluginConfigurationDefinition =
ConfigurationMetadataParser.parse("pc:" + pluginName,
descriptor.getPluginConfiguration());
+ ConfigurationDefinition pluginConfigurationDefinition =
ConfigurationMetadataParser.parse("alerts:" + pluginName,
descriptor.getAlertConfiguration());
+
+
+ return pluginConfigurationDefinition;
+ }
+ catch (Exception e) {
+ LOG.error(e);
+ return null;
+ }
+ }
+
+ public Configuration getDefaultAlertConfiguration(ConfigurationDefinition def) {
+ Configuration config = configManager.getConfigurationFromDefaultTemplate(def);
+
+ return config;
+ }
+
+ /**
+ * Return a list of all available AlertSenders in the system by their shortname.
+ * @return list of senders.
+ */
+ public List<String> listAllAlertSenders() {
+ AlertSenderPluginManager pluginmanager = alertManager.getAlertPluginManager();
+ List<String> senders = pluginmanager.getPluginList();
+ return senders;
+ }
}
\ No newline at end of file
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
index ac42a32..532bd95 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java
@@ -18,13 +18,19 @@
*/
package org.rhq.enterprise.server.alert;
+import java.util.List;
+
import javax.ejb.Local;
+import org.rhq.core.clientapi.descriptor.configuration.ConfigurationDescriptor;
+import org.rhq.core.domain.alert.notification.AlertNotification;
import org.rhq.core.domain.alert.notification.EmailNotification;
import org.rhq.core.domain.alert.notification.RoleNotification;
import org.rhq.core.domain.alert.notification.SnmpNotification;
import org.rhq.core.domain.alert.notification.SubjectNotification;
import org.rhq.core.domain.auth.Subject;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.util.PageControl;
import org.rhq.core.domain.util.PageList;
@@ -63,4 +69,18 @@ public interface AlertNotificationManagerLocal {
int removeNotifications(Subject subject, Integer alertDefinitionId, Integer[]
notificationIds);
int purgeOrphanedAlertNotifications();
+
+ void handleAlertConfigurationDefinition(ConfigurationDefinition desc);
+
+ public Configuration getAlertPropertiesConfiguration(AlertNotification
notification);
+
+ /**
+ * Return a list of all available AlertSenders in the system by their shortname.
+ * @return list of senders.
+ */
+ List<String> listAllAlertSenders();
+
+ ConfigurationDefinition getConfigurationDefinitionForSender(String shortName);
+
+ Configuration getDefaultAlertConfiguration(ConfigurationDefinition def);
}
\ No newline at end of file
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertSenderInfo.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertSenderInfo.java
new file mode 100644
index 0000000..ac03577
--- /dev/null
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertSenderInfo.java
@@ -0,0 +1,67 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 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.plugin.pc.alert;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.rhq.core.domain.plugin.PluginKey;
+
+/**
+ * Information about an {@link AlertSender}
+ * @author Heiko W. Rupp
+ */
+public class AlertSenderInfo {
+
+ private String shortName;
+ private String description;
+ private String pluginName;
+ private PluginKey pluginKey;
+
+ public AlertSenderInfo(String shortName, String description, PluginKey key) {
+ this.shortName = shortName;
+ this.description = description;
+ this.pluginKey = key;
+ this.pluginName = key.getPluginName();
+ }
+
+ public String getShortName() {
+ return shortName;
+ }
+
+ public void setShortName(String shortName) {
+ this.shortName = shortName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getPluginName() {
+ return pluginName;
+ }
+
+ public PluginKey getPluginKey() {
+ return pluginKey;
+ }
+}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertSenderPluginManager.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertSenderPluginManager.java
index bc939bf..cb92a91 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertSenderPluginManager.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertSenderPluginManager.java
@@ -25,17 +25,26 @@ import java.util.Map;
import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Element;
+import org.rhq.core.clientapi.descriptor.configuration.ConfigurationDescriptor;
+import org.rhq.core.domain.alert.notification.AlertNotification;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.PluginKey;
+import org.rhq.core.domain.plugin.ServerPlugin;
+import org.rhq.enterprise.server.alert.AlertNotificationManagerLocal;
+import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginContext;
import org.rhq.enterprise.server.plugin.pc.ServerPluginEnvironment;
import org.rhq.enterprise.server.plugin.pc.ServerPluginManager;
+import org.rhq.enterprise.server.util.LookupUtil;
import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.alert.AlertPluginDescriptorType;
/**
- * TODO
+ * Plugin manager that takes care of loading the plug-ins and instantiating
+ * of {@link AlertSender} etc.
* @author Heiko W. Rupp
*/
public class AlertSenderPluginManager extends ServerPluginManager {
@@ -44,14 +53,24 @@ public class AlertSenderPluginManager extends ServerPluginManager {
private Map<String,String> pluginNameToType = new HashMap<String,
String>();
private Map<String,String> pluginClassByName = new HashMap<String,
String>();
private Map<String,ServerPluginEnvironment> pluginEnvByName = new
HashMap<String, ServerPluginEnvironment>();
+ private Map<String,AlertSenderInfo> senderInfoByName = new HashMap<String,
AlertSenderInfo>();
public AlertSenderPluginManager(AbstractTypeServerPluginContainer pc) {
super(pc);
}
+ /**
+ * Postprocess the loading of the plugin - the actual load is done
+ * in the super class.
+ * Here we verify that the passed <plugin-class> is valid and build
the
+ * list of plugins that can be queried by the UI etc.
+ * @param env the environment of the plugin to be loaded
+ *
+ * @throws Exception
+ */
@Override
public void loadPlugin(ServerPluginEnvironment env) throws Exception {
- super.loadPlugin(env); // TODO: Customise this generated block
+ super.loadPlugin(env);
AlertPluginDescriptorType type = (AlertPluginDescriptorType)
env.getPluginDescriptor();
@@ -64,20 +83,37 @@ public class AlertSenderPluginManager extends ServerPluginManager {
}
catch (Exception e) {
log.warn("Can't find pluginClass " + className + ". Plugin
will be ignored");
+ try {
+ unloadPlugin(env);
+ }
+ catch (Throwable t) {
+ log.warn(" +--> unload failed too " + t.getMessage());
+ }
return;
}
String shortName = ((Element) type.getShortName()).getTextContent();
pluginClassByName.put(shortName,className);
- pluginNameToType.put(shortName,env.getPluginName());
+ senderInfoByName.put(shortName,new
AlertSenderInfo(shortName,"-TODO-",env.getPluginKey()));
+
pluginEnvByName.put(shortName,env);
- }
+ ConfigurationDescriptor desc = type.getAlertConfiguration();
+ AlertNotificationManagerLocal mgr = LookupUtil.getAlertNotificationManager();
+ mgr.handleAlertConfigurationDefinition(null); // TODO
+ }
- public AlertSender getAlertSenderForType(String shortName) {
+ /**
+ * Instantiate an AlertSender for the passed shortName, which is the name you have
provided
+ * in the plugin descriptor in the <shortName> element
+ * @param notification
+ * @return a new AlertSender with preferences set
+ * @see AlertSender
+ */
+ public AlertSender getAlertSenderForNotification(AlertNotification notification) {
- String className = pluginClassByName.get(shortName);
- ServerPluginEnvironment env = pluginEnvByName.get(shortName);
+ String className = pluginClassByName.get(notification.getSenderName());
+ ServerPluginEnvironment env = pluginEnvByName.get(notification.getSenderName());
Class clazz;
try {
clazz = Class.forName(className,true,env.getPluginClassLoader());
@@ -98,8 +134,27 @@ public class AlertSenderPluginManager extends ServerPluginManager {
return null;
}
- sender.alertParameters = new Configuration(); // TODO
- sender.preferences = new Configuration(); // TODO
+ // TODO We have no entityManager lying around here, which means
+ // Configuration is an uninitialized Proxy and we'd get a LazyInit
+ // Exception later.
+ // So lets get a session and attach the stuff... TODO
+ ServerPluginContext ctx = getServerPluginContext(env);
+ AlertNotificationManagerLocal mgr = LookupUtil.getAlertNotificationManager();
+
+
+ sender.alertParameters = mgr.getAlertPropertiesConfiguration(notification);
+ if (sender.alertParameters == null)
+ sender.alertParameters = new Configuration(); // Safety measure
+
+ ServerPluginsLocal pluginsMgr = LookupUtil.getServerPlugins();
+
+ PluginKey key = ctx.getPluginEnvironment().getPluginKey();
+ ServerPlugin plugin = pluginsMgr.getServerPlugin(key);
+ plugin = pluginsMgr.getServerPluginRelationships(plugin);
+
+ sender.preferences = plugin.getPluginConfiguration();
+ if (sender.preferences==null)
+ sender.preferences = new Configuration(); // Safety measure
return sender;
}
@@ -111,4 +166,13 @@ public class AlertSenderPluginManager extends ServerPluginManager {
public List<String> getPluginList() {
return new ArrayList<String>(pluginClassByName.keySet());
}
+
+
+ public String getPluginNameForShortName(String shortName) {
+ return pluginNameToType.get(shortName);
+ }
+
+ public AlertSenderInfo getAlertSenderInfo(String shortName) {
+ return senderInfoByName.get(shortName);
+ }
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertServerPluginContainer.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertServerPluginContainer.java
index d9025a9..3de6d0d 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertServerPluginContainer.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/alert/AlertServerPluginContainer.java
@@ -57,6 +57,12 @@ public class AlertServerPluginContainer extends
AbstractTypeServerPluginContaine
}
@Override
+ public void shutdown() {
+ //getPluginManager().un
+ super.shutdown(); // TODO: Customise this generated block
+ }
+
+ @Override
protected ServerPluginManager createPluginManager() {
return new AlertSenderPluginManager(this);
}
diff --git a/modules/enterprise/server/plugins/alert-email/pom.xml
b/modules/enterprise/server/plugins/alert-email/pom.xml
index d76bdbb..85dbd6d 100644
--- a/modules/enterprise/server/plugins/alert-email/pom.xml
+++ b/modules/enterprise/server/plugins/alert-email/pom.xml
@@ -9,7 +9,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
- <groupId>org.rhq</groupId>
+ <groupId>org.rhq.server</groupId>
<artifactId>alert-email</artifactId>
<version>1.4.0-SNAPSHOT</version>
@@ -21,7 +21,7 @@
</scm>
<properties>
-
<scm.module.path>modules/enterprise/server/plugins/disk/</scm.module.path>
+
<scm.module.path>modules/enterprise/server/plugins/alert-email/</scm.module.path>
</properties>
<dependencies>
@@ -55,7 +55,7 @@
<scope>provided</scope>
<!-- needed for referenced domain entities that use Hibernate annotations
-->
</dependency>
-
+
</dependencies>
<build>
@@ -134,4 +134,4 @@
</profiles>
-</project>
\ No newline at end of file
+</project>
diff --git
a/modules/enterprise/server/plugins/alert-email/src/main/java/org/rhq/enterprise/server/plugins/alertEmail/EmailSender.java
b/modules/enterprise/server/plugins/alert-email/src/main/java/org/rhq/enterprise/server/plugins/alertEmail/EmailSender.java
index 581eb94..ad7f0b4 100644
---
a/modules/enterprise/server/plugins/alert-email/src/main/java/org/rhq/enterprise/server/plugins/alertEmail/EmailSender.java
+++
b/modules/enterprise/server/plugins/alert-email/src/main/java/org/rhq/enterprise/server/plugins/alertEmail/EmailSender.java
@@ -42,18 +42,26 @@ import org.rhq.enterprise.server.plugin.pc.alert.SenderResult;
public class EmailSender extends AlertSender {
private final Log log = LogFactory.getLog(EmailSender.class);
+ private static final String SMTP_HOST = "rhq.server.email.smtp-host";
+ private static final String SMTP_PORT = "rhq.server.email.smtp-port";
+ private static final String EMAIL_FROM = "rhq.server.email.from-address";
@Override
public SenderResult send(Alert alert) {
+ if(preferences!=null)
+ preferences.getProperties().size();
+
String emailAddress =
alertParameters.getSimpleValue("emailAddress",null);
if (emailAddress==null) {
log.warn("Email address was null, should not happen");
return new SenderResult(ResultState.FAILURE,"No email address
given");
}
- String mailserver =
preferences.getSimpleValue("mailserver","localhost"); // TODO get RHQ
default one
- String senderAddress =
preferences.getSimpleValue("senderEmail","rhqadmin@localhost"); //
TODO get RHQ default one
+ String tmp = System.getProperty(SMTP_HOST,"localhost");
+ String mailserver = preferences.getSimpleValue("mailserver",tmp);
+ tmp = System.getProperty(EMAIL_FROM, "rhqadmin@localhost");
+ String senderAddress = preferences.getSimpleValue("senderEmail",tmp);
Properties props = new Properties();
props.put("mail.smtp.host",mailserver);
@@ -61,7 +69,7 @@ public class EmailSender extends AlertSender {
Message message = new SMTPMessage(session);
try {
message.setFrom(new InternetAddress(senderAddress));
- message.setRecipient(Message.RecipientType.TO,new
InternetAddress("hwr(a)redhat.com"));
+ message.setRecipient(Message.RecipientType.TO,new
InternetAddress(emailAddress));
message.setSubject("Alert on " + "Dummy - TODO");
message.setText("Li la lu, nur der Mann im Mond schaut zu");
Transport.send(message);
diff --git
a/modules/enterprise/server/plugins/alert-email/src/main/resources/META-INF/rhq-serverplugin.xml
b/modules/enterprise/server/plugins/alert-email/src/main/resources/META-INF/rhq-serverplugin.xml
index 2590490..663185e 100644
---
a/modules/enterprise/server/plugins/alert-email/src/main/resources/META-INF/rhq-serverplugin.xml
+++
b/modules/enterprise/server/plugins/alert-email/src/main/resources/META-INF/rhq-serverplugin.xml
@@ -23,13 +23,16 @@
<!-- Global preferences for all email alerts -->
<serverplugin:plugin-configuration>
<c:simple-property name="mailserver" displayName="Mail server
address" type="longString"
- description="Address of the mail server to use (if not the default
RHQ one )"/>
+ description="Address of the mail server to use (if not the default
RHQ one )"
+ required="false"/>
<c:simple-property name="senderEmail" displayName="Email of
sender" type="string"
- description="Email of the account from which alert emails should
come from"/>
+ description="Email of the account from which alert emails should
come from"
+ required="false"/>
<c:simple-property name="needsLogin" displayName="Needs
credentials?"
- description="Mark this field if the server needs credentials to send
email and give them below" type="boolean"/>
- <c:simple-property name="user" type="string"/>
- <c:simple-property name="password" type="password" />
+ description="Mark this field if the server needs credentials to send
email and give them below" type="boolean"
+ default="false"/>
+ <c:simple-property name="user" type="string"
required="false"/>
+ <c:simple-property name="password" type="password"
required="false"/>
</serverplugin:plugin-configuration>
@@ -45,4 +48,4 @@
description="Email addresses (separated by comma) used for
notifications."/>
</alert-configuration>
-</alert-plugin>
\ No newline at end of file
+</alert-plugin>
commit aa1bd4318448550ea1418dd82deb373d40de6c8b
Author: Heiko W. Rupp <pilhuhn(a)fedorapeople.org>
Date: Mon Nov 30 08:55:21 2009 +0100
Pull up master/master and fix the conflicts that I had.
diff --git
a/etc/samples/custom-serverplugin/src/main/java/org/custom/MyLifecycleListener.java
b/etc/samples/custom-serverplugin/src/main/java/org/custom/MyLifecycleListener.java
index 699ac49..51397c6 100644
--- a/etc/samples/custom-serverplugin/src/main/java/org/custom/MyLifecycleListener.java
+++ b/etc/samples/custom-serverplugin/src/main/java/org/custom/MyLifecycleListener.java
@@ -66,7 +66,7 @@ public class MyLifecycleListener implements ServerPluginComponent {
}
StringBuilder str = new StringBuilder();
-
str.append("plugin-name=").append(this.context.getPluginEnvironment().getPluginName()).append(",");
+
str.append("plugin-key=").append(this.context.getPluginEnvironment().getPluginKey()).append(",");
str.append("plugin-url=").append(this.context.getPluginEnvironment().getPluginUrl()).append(",");
str.append("plugin-config=[").append(getPluginConfigurationString()).append(']');
// do not append ,
return str.toString();
diff --git a/modules/core/dbutils/pom.xml b/modules/core/dbutils/pom.xml
index 8f466be..83fa2a2 100644
--- a/modules/core/dbutils/pom.xml
+++ b/modules/core/dbutils/pom.xml
@@ -22,7 +22,7 @@
<properties>
<scm.module.path>modules/core/dbutils/</scm.module.path>
- <db.schema.version>2.69.1</db.schema.version>
+ <db.schema.version>2.69.3</db.schema.version>
</properties>
<dependencies>
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml
b/modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml
index dbc4a19..1d111cf 100644
--- a/modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml
+++ b/modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml
@@ -19,12 +19,14 @@
<column name="CTIME" type="LONG"
required="true"/>
<column name="MTIME" type="LONG"
required="true"/>
<column name="DEPLOYMENT" size="8"
type="VARCHAR2" required="true"/>
+ <column name="PTYPE" size="200" type="VARCHAR2"
required="false"/>
<column name="PLUGIN_CONFIG_ID" type="INTEGER"
references="RHQ_CONFIG" required="false"/>
<column name="JOBS_CONFIG_ID" type="INTEGER"
references="RHQ_CONFIG" required="false"/>
<column name="CONTENT" type="BLOB"
required="false"/>
- <index name="RHQ_PLUGIN_NAME_IDX" unique="true">
+ <index name="RHQ_PLUGIN_NAME_DEPLOY_IDX"
unique="true">
<field ref="NAME"/>
+ <field ref="DEPLOYMENT"/>
</index>
</table>
diff --git a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
index 07831eb..c28b862 100644
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@ -2183,6 +2183,23 @@
<schema-alterColumn table="RHQ_PLUGIN" column="STATUS"
nullable="FALSE"/>
</schemaSpec>
+ <schemaSpec version="2.69.2">
+ <!-- plugin names must be unique only if they are deployed on the same side
(agent vs. server) -->
+ <schema-directSQL>
+ <statement desc="Dropping unique index on RHQ_PLUGIN (NAME)">
+ DROP INDEX RHQ_PLUGIN_NAME_IDX
+ </statement>
+ <statement desc="Creating unique index on RHQ_PLUGIN (NAME, DEPLOYMENT)
so server plugin names need not be unique with agent plugins">
+ CREATE UNIQUE INDEX RHQ_PLUGIN_NAME_DEPLOY_IDX ON RHQ_PLUGIN (NAME,
DEPLOYMENT)
+ </statement>
+ </schema-directSQL>
+ </schemaSpec>
+
+ <schemaSpec version="2.69.3">
+ <!-- add the new column that indicates what type of plugin this is (e.g.
alert, generic, content) - for server plugins only -->
+ <schema-addColumn table="RHQ_PLUGIN" column="PTYPE"
columnType="VARCHAR2" precision="200"/>
+ </schemaSpec>
+
</dbupgrade>
</target>
</project>
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
new file mode 100644
index 0000000..6ff9cb5
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
@@ -0,0 +1,401 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 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.plugin;
+
+import java.io.ByteArrayInputStream;
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.PrePersist;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+import org.rhq.core.util.MessageDigestGenerator;
+
+/**
+ * Base plugin implementation that agent and server plugin implementations extend.
+ *
+ * @author John Mazzitelli
+ */
+@DiscriminatorColumn(name = "DEPLOYMENT")
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+@Entity
+@SequenceGenerator(name = "SEQ", sequenceName = "RHQ_PLUGIN_ID_SEQ")
+@Table(name = Plugin.TABLE_NAME)
+public class AbstractPlugin implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ public static final String TABLE_NAME = "RHQ_PLUGIN";
+
+ @Column(name = "ID", nullable = false)
+ @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ")
+ @Id
+ private int id;
+
+ @Column(name = "DEPLOYMENT", nullable = false, insertable = false,
updatable = false)
+ @Enumerated(EnumType.STRING)
+ private PluginDeploymentType deployment;
+
+ @Column(name = "NAME", nullable = false)
+ private String name;
+
+ @Column(name = "DISPLAY_NAME", nullable = false)
+ private String displayName;
+
+ @Column(name = "DESCRIPTION", nullable = true)
+ private String description;
+
+ @Column(name = "ENABLED", nullable = false)
+ private boolean enabled = true;
+
+ @Column(name = "STATUS", nullable = false)
+ @Enumerated(EnumType.STRING)
+ private PluginStatusType status = PluginStatusType.INSTALLED;
+
+ @Column(name = "HELP", nullable = true)
+ private String help;
+
+ @Column(name = "VERSION", nullable = true)
+ private String version;
+
+ @Column(name = "AMPS_VERSION", nullable = true)
+ private String ampsVersion;
+
+ @Column(name = "PATH", nullable = false)
+ private String path;
+
+ @Column(name = "MD5", nullable = false)
+ private String md5;
+
+ @Column(name = "CTIME", nullable = false)
+ private long ctime;
+
+ @Column(name = "MTIME", nullable = false)
+ private long mtime;
+
+ @Column(name = "CONTENT", nullable = true)
+ private byte[] content;
+
+ public AbstractPlugin() {
+ }
+
+ /**
+ * Constructor for {@link Plugin}.
+ *
+ * @param name the logical name of the plugin
+ * @param path the actual filename of the plugin jar (see {@link #getPath()})
+ */
+ public AbstractPlugin(String name, String path) {
+ this.name = name;
+ this.path = path;
+ }
+
+ /**
+ * Constructor for {@link Plugin}.
+ * Note that this allows you to provide an MD5 without providing the plugin's
+ * actual content. If you wish to persist this entity in the database, you should
+ * either provide the {@link #setContent(byte[]) content} or update the entity
+ * later by streaming the file content to the content column.
+ *
+ * @param name the logical name of the plugin
+ * @param path the actual filename of the plugin jar (see {@link #getPath()})
+ * @param md5 the MD5 hash string of the plugin jar contents
+ */
+ public AbstractPlugin(String name, String path, String md5) {
+ this.name = name;
+ this.path = path;
+ this.md5 = md5;
+ }
+
+ /**
+ * Constructor for {@link Plugin}.
+ *
+ * @param name the logical name of the plugin
+ * @param path the actual filename of the plugin jar (see {@link #getPath()})
+ * @param content the actual jar file contents (the MD5 hash string will be generated
from this)
+ */
+ public AbstractPlugin(String name, String path, byte[] content) {
+ this.name = name;
+ this.path = path;
+ this.content = content;
+
+ try {
+ ByteArrayInputStream stream = new ByteArrayInputStream(content);
+ this.md5 = MessageDigestGenerator.getDigestString(stream);
+ } catch (Exception e) {
+ throw new RuntimeException("Cannot determine plugin's MD5!",
e);
+ }
+ }
+
+ /**
+ * Constructor that can build the full object except for the content byte array.
+ * This is used mainly for the named queries that want to return a Plugin object
+ * but does not eagerly load in the content array.
+ */
+ public AbstractPlugin(int id, String name, String path, String displayName, boolean
enabled,
+ PluginStatusType status, String description, String help, String md5, String
version, String ampsVersion,
+ PluginDeploymentType deployment, long ctime, long mtime) {
+ this.id = id;
+ this.name = name;
+ this.path = path;
+ this.displayName = displayName;
+ this.enabled = enabled;
+ this.status = status;
+ this.description = description;
+ this.help = help;
+ this.md5 = md5;
+ this.version = version;
+ this.ampsVersion = ampsVersion;
+ this.deployment = deployment;
+ this.ctime = ctime;
+ this.mtime = mtime;
+ }
+
+ public int getId() {
+ return this.id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * See the javadoc of {@link #getMtime()} for
+ * information about this field and its relationship
+ * with "mtime".
+ *
+ * @return the time when this entity was persisted
+ */
+ public long getCtime() {
+ return this.ctime;
+ }
+
+ public void setCtime(long ctime) {
+ this.ctime = ctime;
+ }
+
+ /**
+ * The "mtime" of the plugin has slightly different semantics
+ * than other "mtime" values found elsewhere. The "mtime"
+ * will typically be the time that the content field was modified,
+ * not necessarily the time when any field was modified. In other
+ * words, look at "mtime" if you want to know when the actual
+ * plugin content was last updated. Note that this "mtime" may in
+ * fact be the last modified time of the plugin file from which
+ * the content came from - this means mtime may actually be earlier
+ * in time than "ctime" (in the case when the plugin jar file was
+ * last touched prior to this entity being created).
+ *
+ * Note that the "ctime" field semantics remains the same as always,
+ * it is the time when this entity was originally created.
+ *
+ * @return mtime of the content
+ */
+ public long getMtime() {
+ return this.mtime;
+ }
+
+ /**
+ * This entity does not automatically update the "mtime" when it
+ * is updated via a PreUpdate annotation, therefore, the owner of
+ * this entity needs to explicitly call this setter in order to
+ * set the "mtime". You normally set this value to the last
+ * modified time of the plugin jar that provided
+ * this plugin entity's {@link #getContent() content}.
+ *
+ * @param mtime
+ */
+ public void setMtime(long mtime) {
+ this.mtime = mtime;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public PluginStatusType getStatus() {
+ return status;
+ }
+
+ public void setStatus(PluginStatusType status) {
+ this.status = status;
+ if (this.status == PluginStatusType.DELETED) {
+ this.enabled = false;
+ }
+ }
+
+ public String getHelp() {
+ return help;
+ }
+
+ public void setHelp(String help) {
+ this.help = help;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getAmpsVersion() {
+ return ampsVersion;
+ }
+
+ public void setAmpsVersion(String ampsVersion) {
+ this.ampsVersion = ampsVersion;
+ }
+
+ public String getMd5() {
+ return md5;
+ }
+
+ public void setMd5(String md5) {
+ this.md5 = md5;
+ }
+
+ public String getMD5() {
+ return getMd5();
+ }
+
+ public void setMD5(String md5) {
+ setMd5(md5);
+ }
+
+ /**
+ * Returns the actual name of the plugin jar. This is not the absolute path, in fact,
it does not include any
+ * directory paths. It is strictly the name of the plugin jar as found on the file
system (aka the filename).
+ *
+ * @return plugin filename
+ */
+ public String getPath() {
+ return this.path;
+ }
+
+ /**
+ * Ensure that the path being set does not include any directory names. The plugin
path is the filename. See
+ * {@link #getPath()}.
+ *
+ * @param path the filename of the plugin, not including directory names
+ */
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ /**
+ * Indicates how the plugin gets deployed (e.g. running in the agent or in the
server).
+ *
+ * @return plugin deployment type
+ */
+ public PluginDeploymentType getDeployment() {
+ return deployment;
+ }
+
+ public void setDeployment(PluginDeploymentType deployment) {
+ this.deployment = deployment;
+ }
+
+ /**
+ * Returns the actual content of the plugin file. Be careful calling this
+ * in an entity context - the entire plugin file content will be loaded in
+ * memory (which may trigger an OutOfMemoryError if the file is very large).
+ *
+ * @return the content of the plugin file
+ */
+ public byte[] getContent() {
+ return this.content;
+ }
+
+ public void setContent(byte[] content) {
+ this.content = content;
+ }
+
+ @PrePersist
+ void onPersist() {
+ this.ctime = System.currentTimeMillis();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if ((obj == null) || !(obj instanceof AbstractPlugin)) {
+ return false;
+ }
+
+ AbstractPlugin that = (AbstractPlugin) obj;
+ return name.equals(that.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "[id=" + id + ", name=" + name + ", md5=" +
md5 + "]";
+ }
+}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
index 4047d10..cdd3254 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/Plugin.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
+ * Copyright (C) 2005-2009 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -22,52 +22,35 @@
*/
package org.rhq.core.domain.plugin;
-import java.io.ByteArrayInputStream;
-import java.io.Serializable;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
-import javax.persistence.OneToOne;
-import javax.persistence.PrePersist;
-import javax.persistence.SequenceGenerator;
-import javax.persistence.Table;
-
-import org.jetbrains.annotations.NotNull;
-
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.util.MessageDigestGenerator;
/**
* An agent plugin.
- *
+ *
* This object contains information about the plugin jar itself (e.g. its name and MD5).
* It may also contain the jar contents ({@link #getContent()}).
*/
-@Entity
+@DiscriminatorValue("AGENT")
@NamedQueries( {
//
- @NamedQuery(name = Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE, query = "" //
+ // helps you determine if a plugin is installed or was deleted
+ @NamedQuery(name = Plugin.QUERY_GET_STATUS_BY_NAME, query = "" //
+ " SELECT p.status " //
+ " FROM Plugin AS p " //
- + " WHERE p.name = :name AND p.deployment = :type "), //
+ + " WHERE p.name = :name)"), //
- @NamedQuery(name = Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE, query = ""
//
+ // helps you determine which installed plugins are enabled or disabled
+ @NamedQuery(name = Plugin.QUERY_GET_NAMES_BY_ENABLED, query = "" //
+ " SELECT p.name " //
+ " FROM Plugin AS p " //
- + " WHERE p.enabled = :enabled AND p.deployment = :type AND p.status =
'INSTALLED' "), //
+ + " WHERE p.enabled = :enabled " //
+ + " AND p.status = 'INSTALLED' "), //
// this query does not load the content blob, but loads everything else
- @NamedQuery(name = Plugin.QUERY_FIND_BY_IDS_AND_TYPE, query = "" //
+ @NamedQuery(name = Plugin.QUERY_FIND_BY_IDS, query = "" //
+ " SELECT new org.rhq.core.domain.plugin.Plugin( " //
+ " p.id, " //
+ " p.name, " //
@@ -80,15 +63,11 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
- + " p.pluginConfiguration, " //
- + " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
+ " p.mtime) " //
- + " FROM Plugin AS p " //
- + " LEFT JOIN p.pluginConfiguration " //
- + " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.id IN (:ids) AND p.deployment = :type AND p.status =
'INSTALLED' "), //
+ + " FROM Plugin AS p " //
+ + " WHERE p.id IN (:ids) " //
+ + " AND p.status = 'INSTALLED' "), //
// this query does not load the content blob, but loads everything else
@NamedQuery(name = Plugin.QUERY_FIND_BY_NAME, query = "" //
@@ -104,43 +83,15 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
- + " p.pluginConfiguration, " //
- + " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
+ " p.mtime) " //
- + " FROM Plugin AS p " //
- + " LEFT JOIN p.pluginConfiguration " //
- + " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.name=:name AND p.status = 'INSTALLED' "), //
+ + " FROM Plugin AS p " //
+ + " WHERE p.name=:name " //
+ + " AND p.status = 'INSTALLED' "), //
// gets the plugin, even if it is deleted
// this query does not load the content blob, but loads everything else
- @NamedQuery(name = Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE, query = "" //
- + " SELECT new org.rhq.core.domain.plugin.Plugin( " //
- + " p.id, " //
- + " p.name, " //
- + " p.path, " //
- + " p.displayName, " //
- + " p.enabled, " //
- + " p.status, " //
- + " p.description, " //
- + " p.help, " //
- + " p.md5, " //
- + " p.version, " //
- + " p.ampsVersion, " //
- + " p.deployment, " //
- + " p.pluginConfiguration, " //
- + " p.scheduledJobsConfiguration, " //
- + " p.ctime, " //
- + " p.mtime) " //
- + " FROM Plugin AS p " //
- + " LEFT JOIN p.pluginConfiguration " //
- + " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.name=:name AND p.deployment = :type "), //
-
- // this query does not load the content blob, but loads everything else
- @NamedQuery(name = Plugin.QUERY_FIND_ALL_AGENT, query = "" //
+ @NamedQuery(name = Plugin.QUERY_FIND_ANY_BY_NAME, query = "" //
+ " SELECT new org.rhq.core.domain.plugin.Plugin( " //
+ " p.id, " //
+ " p.name, " //
@@ -153,18 +104,14 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
- + " p.pluginConfiguration, " //
- + " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM Plugin AS p " //
- + " LEFT JOIN p.pluginConfiguration " //
- + " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.deployment = 'AGENT' AND p.status =
'INSTALLED' "), //
+ + " WHERE p.name=:name "), //
+ // finds all installed - ignores those plugins marked as deleted
// this query does not load the content blob, but loads everything else
- @NamedQuery(name = Plugin.QUERY_FIND_ALL_SERVER, query = "" //
+ @NamedQuery(name = Plugin.QUERY_FIND_ALL_INSTALLED, query = "" //
+ " SELECT new org.rhq.core.domain.plugin.Plugin( " //
+ " p.id, " //
+ " p.name, " //
@@ -177,15 +124,10 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
- + " p.pluginConfiguration, " //
- + " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM Plugin AS p " //
- + " LEFT JOIN p.pluginConfiguration " //
- + " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.deployment = 'SERVER' AND p.status =
'INSTALLED' "), //
+ + " WHERE p.status = 'INSTALLED' "), //
// this query is how you enable and disable plugins
@NamedQuery(name = Plugin.UPDATE_PLUGINS_ENABLED_BY_IDS, query = "" //
@@ -207,408 +149,63 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
- + " p.pluginConfiguration, " //
- + " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM Plugin p " //
- + " LEFT JOIN p.pluginConfiguration " //
- + " LEFT JOIN p.scheduledJobsConfiguration " //
+ " WHERE p.status = 'INSTALLED' AND " //
+ " p.name IN ( SELECT rt.plugin " //
+ " FROM Resource res " //
+ " JOIN res.resourceType rt " //
+ " WHERE ( rt.category = :resourceCategory OR
:resourceCategory IS NULL ) " //
+ " AND ( rt.name = :resourceTypeName OR
:resourceTypeName IS NULL ) ) " //
- + "ORDER BY p.name") })
-@SequenceGenerator(name = "SEQ", sequenceName = "RHQ_PLUGIN_ID_SEQ")
-@Table(name = Plugin.TABLE_NAME)
-public class Plugin implements Serializable {
+ + " ORDER BY p.name") //
+})
+@Entity
+public class Plugin extends AbstractPlugin {
private static final long serialVersionUID = 1L;
- public static final String TABLE_NAME = "RHQ_PLUGIN";
-
- public static final String QUERY_FIND_BY_RESOURCE_TYPE_AND_CATEGORY =
"Plugin.findByResourceType";
- public static final String QUERY_FIND_ALL_AGENT = "Plugin.findAllAgent";
- public static final String QUERY_FIND_ALL_SERVER = "Plugin.findAllServer";
+ public static final String QUERY_GET_STATUS_BY_NAME =
"Plugin.queryGetStatusByName";
+ public static final String QUERY_GET_NAMES_BY_ENABLED =
"Plugin.queryGetNamesByEnabled";
+ public static final String QUERY_FIND_BY_IDS = "Plugin.findByIds";
public static final String QUERY_FIND_BY_NAME = "Plugin.findByName";
- public static final String QUERY_FIND_ANY_BY_NAME_AND_TYPE =
"Plugin.findAnyByNameAndType";
- public static final String QUERY_FIND_BY_IDS_AND_TYPE =
"Plugin.findByIdsAndType";
- public static final String QUERY_GET_NAMES_BY_ENABLED_AND_TYPE =
"Plugin.findByEnabledAndType";
- public static final String QUERY_GET_STATUS_BY_NAME_AND_TYPE =
"Plugin.getStatusByNameAndType";
+ public static final String QUERY_FIND_ANY_BY_NAME =
"Plugin.findAnyByName";
+ public static final String QUERY_FIND_ALL_INSTALLED =
"Plugin.findAllInstalled";
public static final String UPDATE_PLUGINS_ENABLED_BY_IDS =
"Plugin.updatePluginsEnabledByIds";
-
- @Column(name = "ID", nullable = false)
- @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ")
- @Id
- private int id;
-
- @Column(name = "DEPLOYMENT", nullable = false)
- @Enumerated(EnumType.STRING)
- private PluginDeploymentType deployment = PluginDeploymentType.AGENT; // assume
agent
-
- @JoinColumn(name = "JOBS_CONFIG_ID", referencedColumnName =
"ID")
- @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
- private Configuration scheduledJobsConfiguration;
-
- @JoinColumn(name = "PLUGIN_CONFIG_ID", referencedColumnName =
"ID")
- @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
- private Configuration pluginConfiguration;
-
- @Column(name = "NAME", nullable = false)
- private String name;
-
- @Column(name = "DISPLAY_NAME", nullable = false)
- private String displayName;
-
- @Column(name = "DESCRIPTION", nullable = true)
- private String description;
-
- @Column(name = "ENABLED", nullable = false)
- private boolean enabled = true;
-
- @Column(name = "STATUS", nullable = false)
- @Enumerated(EnumType.STRING)
- private PluginStatusType status = PluginStatusType.INSTALLED;
-
- @Column(name = "HELP", nullable = true)
- private String help;
-
- @Column(name = "VERSION", nullable = true)
- private String version;
-
- @Column(name = "AMPS_VERSION", nullable = true)
- private String ampsVersion;
-
- @Column(name = "PATH", nullable = false)
- private String path;
-
- @Column(name = "MD5", nullable = false)
- private String md5;
-
- @Column(name = "CTIME", nullable = false)
- private long ctime;
-
- @Column(name = "MTIME", nullable = false)
- private long mtime;
-
- @Column(name = "CONTENT", nullable = true)
- private byte[] content;
+ public static final String QUERY_FIND_BY_RESOURCE_TYPE_AND_CATEGORY =
"Plugin.findByResourceType";
public Plugin() {
+ super();
+ setDeployment(PluginDeploymentType.AGENT);
}
- /**
- * Constructor for {@link Plugin}.
- *
- * @param name the logical name of the plugin
- * @param path the actual filename of the plugin jar (see {@link #getPath()})
- */
- public Plugin(@NotNull String name, String path) {
- this.name = name;
- this.path = path;
+ public Plugin(String name, String path) {
+ super(name, path);
+ setDeployment(PluginDeploymentType.AGENT);
}
- /**
- * Constructor for {@link Plugin}.
- * Note that this allows you to provide an MD5 without providing the plugin's
- * actual content. If you wish to persist this entity in the database, you should
- * either provide the {@link #setContent(byte[]) content} or update the entity
- * later by streaming the file content to the content column.
- *
- * @param name the logical name of the plugin
- * @param path the actual filename of the plugin jar (see {@link #getPath()})
- * @param md5 the MD5 hash string of the plugin jar contents
- */
public Plugin(String name, String path, String md5) {
- this.name = name;
- this.path = path;
- this.md5 = md5;
+ super(name, path, md5);
+ setDeployment(PluginDeploymentType.AGENT);
}
- /**
- * Constructor for {@link Plugin}.
- *
- * @param name the logical name of the plugin
- * @param path the actual filename of the plugin jar (see {@link #getPath()})
- * @param content the actual jar file contents (the MD5 hash string will be generated
from this)
- */
public Plugin(String name, String path, byte[] content) {
- this.name = name;
- this.path = path;
- this.content = content;
-
- try {
- ByteArrayInputStream stream = new ByteArrayInputStream(content);
- this.md5 = MessageDigestGenerator.getDigestString(stream);
- } catch (Exception e) {
- throw new RuntimeException("Cannot determine plugin's MD5!",
e);
- }
+ super(name, path, content);
+ setDeployment(PluginDeploymentType.AGENT);
}
- /**
- * Constructor that can build the full object except for the content byte array.
- * This is used mainly for the named queries that want to return a Plugin object
- * but does not eagerly load in the content array.
- *
- * @param id
- * @param name
- * @param path
- * @param displayName
- * @param enabled
- * @param status
- * @param description
- * @param help
- * @param md5
- * @param version
- * @param ampsVersion
- * @param deployment
- * @param pluginConfig
- * @param scheduledJobsConfig
- * @param ctime
- * @param mtime
- */
public Plugin(int id, String name, String path, String displayName, boolean enabled,
PluginStatusType status,
- String description, String help, String md5, String version, String ampsVersion,
- PluginDeploymentType deployment, Configuration pluginConfig, Configuration
scheduledJobsConfig, long ctime,
- long mtime) {
- this.id = id;
- this.name = name;
- this.path = path;
- this.displayName = displayName;
- this.enabled = enabled;
- this.status = status;
- this.description = description;
- this.help = help;
- this.md5 = md5;
- this.version = version;
- this.ampsVersion = ampsVersion;
- this.deployment = deployment;
- this.pluginConfiguration = pluginConfig;
- this.scheduledJobsConfiguration = scheduledJobsConfig;
- this.ctime = ctime;
- this.mtime = mtime;
- }
-
- public int getId() {
- return this.id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
- public String getName() {
- return this.name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * See the javadoc of {@link #getMtime()} for
- * information about this field and its relationship
- * with "mtime".
- *
- * @return the time when this entity was persisted
- */
- public long getCtime() {
- return this.ctime;
- }
-
- public void setCtime(long ctime) {
- this.ctime = ctime;
- }
-
- /**
- * The "mtime" of the plugin has slightly different semantics
- * than other "mtime" values found elsewhere. The "mtime"
- * will typically be the time that the content field was modified,
- * not necessarily the time when any field was modified. In other
- * words, look at "mtime" if you want to know when the actual
- * plugin content was last updated. Note that this "mtime" may in
- * fact be the last modified time of the plugin file from which
- * the content came from - this means mtime may actually be earlier
- * in time than "ctime" (in the case when the plugin jar file was
- * last touched prior to this entity being created).
- *
- * Note that the "ctime" field semantics remains the same as always,
- * it is the time when this entity was originally created.
- *
- * @return mtime of the content
- */
- public long getMtime() {
- return this.mtime;
- }
-
- /**
- * This entity does not automatically update the "mtime" when it
- * is updated via a PreUpdate annotation, therefore, the owner of
- * this entity needs to explicitly call this setter in order to
- * set the "mtime". You normally set this value to the last
- * modified time of the plugin jar that provided
- * this plugin entity's {@link #getContent() content}.
- *
- * @param mtime
- */
- public void setMtime(long mtime) {
- this.mtime = mtime;
- }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public void setDisplayName(String displayName) {
- this.displayName = displayName;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public PluginStatusType getStatus() {
- return status;
- }
-
- public void setStatus(PluginStatusType status) {
- this.status = status;
- if (this.status == PluginStatusType.DELETED) {
- this.enabled = false;
- }
- }
-
- public String getHelp() {
- return help;
- }
-
- public void setHelp(String help) {
- this.help = help;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public String getAmpsVersion() {
- return ampsVersion;
- }
+ String description, String help, String md5, String version, String ampsVersion,
long ctime, long mtime) {
- public void setAmpsVersion(String ampsVersion) {
- this.ampsVersion = ampsVersion;
- }
-
- public String getMd5() {
- return md5;
- }
-
- public void setMd5(String md5) {
- this.md5 = md5;
- }
-
- public String getMD5() {
- return getMd5();
- }
-
- public void setMD5(String md5) {
- setMd5(md5);
- }
-
- /**
- * Returns the actual name of the plugin jar. This is not the absolute path, in fact,
it does not include any
- * directory paths. It is strictly the name of the plugin jar as found on the file
system (aka the filename).
- *
- * @return plugin filename
- */
- public String getPath() {
- return this.path;
- }
-
- /**
- * Ensure that the path being set does not include any directory names. The plugin
path is the filename. See
- * {@link #getPath()}.
- *
- * @param path the filename of the plugin, not including directory names
- */
- public void setPath(String path) {
- this.path = path;
- }
-
- /**
- * Indicates how the plugin gets deployed (e.g. running in the agent or in the
server).
- *
- * @return plugin deployment type
- */
- public PluginDeploymentType getDeployment() {
- return deployment;
+ super(id, name, path, displayName, enabled, status, description, help, md5,
version, ampsVersion,
+ PluginDeploymentType.AGENT, ctime, mtime);
}
+ @Override
public void setDeployment(PluginDeploymentType deployment) {
- this.deployment = deployment;
- }
-
- /**
- * If the plugin has jobs associated with it, this is the configuration for those
jobs.
- *
- * @return scheduled job configuration for jobs that the plugin defined.
- */
- public Configuration getScheduledJobsConfiguration() {
- return scheduledJobsConfiguration;
- }
-
- public void setScheduledJobsConfiguration(Configuration scheduledJobsConfiguration)
{
- this.scheduledJobsConfiguration = scheduledJobsConfiguration;
- }
-
- /**
- * If the plugin, itself, has configuration associated with it, this is that
configuration.
- *
- * @return the configuration associated with the plugin itself
- */
- public Configuration getPluginConfiguration() {
- return pluginConfiguration;
- }
-
- public void setPluginConfiguration(Configuration pluginConfiguration) {
- this.pluginConfiguration = pluginConfiguration;
- }
-
- /**
- * Returns the actual content of the plugin file. Be careful calling this
- * in an entity context - the entire plugin file content will be loaded in
- * memory (which may trigger an OutOfMemoryError if the file is very large).
- *
- * @return the content of the plugin file
- */
- public byte[] getContent() {
- return this.content;
- }
-
- public void setContent(byte[] content) {
- this.content = content;
- }
-
- @PrePersist
- void onPersist() {
- this.ctime = System.currentTimeMillis();
+ if (deployment != PluginDeploymentType.AGENT) {
+ throw new IllegalArgumentException("Plugin can only ever have deployment
type of AGENT: " + deployment);
+ }
+ super.setDeployment(deployment);
}
@Override
@@ -621,17 +218,16 @@ public class Plugin implements Serializable {
return false;
}
- Plugin that = (Plugin) obj;
- return name.equals(that.name);
+ return super.equals(obj);
}
@Override
public int hashCode() {
- return name.hashCode();
+ return super.hashCode();
}
@Override
public String toString() {
- return "Plugin[id=" + id + ", name=" + name + ",
md5=" + md5 + "]";
+ return "AgentPlugin " + super.toString();
}
}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
new file mode 100644
index 0000000..5240a65
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
@@ -0,0 +1,153 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 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.core.domain.plugin;
+
+/**
+ * Encapsulates informaton that can uniquely identify a plugin.
+ *
+ * @author John Mazzitelli
+ */
+public class PluginKey {
+ private final PluginDeploymentType deployment;
+ private final String pluginType;
+ private final String pluginName;
+
+ /**
+ * Creates a plugin key that identifies an agent plugin. There is only
+ * one plugin container that runs in the agent, thus there is only
+ * one "type" of an agent plugin. Therefore, {@link #getPluginType()} on
the
+ * returned object will return <code>null</code> to signify this.
+ *
+ * @param pluginName the name of the plugin
+ * @return the plugin key for the agent plugin
+ */
+ public static PluginKey createAgentPluginKey(String pluginName) {
+ return new PluginKey(PluginDeploymentType.AGENT, null, pluginName);
+ }
+
+ /**
+ * Creates a plugin key that identifies a server plugin. All server plugins
+ * must have a type and a name.
+ *
+ * @param pluginType the type of plugin - must not be null or an empty string
+ * @param pluginName the name of the plugin
+ * @return the plugin key for the server plugin
+ */
+ public static PluginKey createServerPluginKey(String pluginType, String pluginName)
{
+ // for server plugins, cannot allow an empty string for plugin type
+ if (pluginType == null || pluginType.length() == 0) {
+ throw new IllegalArgumentException("invalid pluginType: " +
pluginType);
+ }
+ return new PluginKey(PluginDeploymentType.SERVER, pluginType, pluginName);
+ }
+
+ /**
+ * Create a plugin key that identifies the given agent plugin.
+ *
+ * @param plugin agent plugin
+ */
+ public PluginKey(Plugin plugin) {
+ this(plugin.getDeployment(), null, plugin.getName());
+ }
+
+ /**
+ * Create a plugin key that identifies the given server plugin.
+ *
+ * @param plugin server plugin
+ */
+ public PluginKey(ServerPlugin plugin) {
+ this(plugin.getDeployment(), plugin.getType(), plugin.getName());
+ }
+
+ public PluginKey(PluginDeploymentType deployment, String pluginType, String
pluginName) {
+ if (deployment == null) {
+ throw new IllegalArgumentException("deployment==null");
+ }
+ if (pluginType == null && deployment != PluginDeploymentType.AGENT) {
+ throw new IllegalArgumentException("only agent plugins can have null
type");
+ }
+ if (pluginType != null && deployment == PluginDeploymentType.AGENT) {
+ throw new IllegalArgumentException("agent plugins must have null
type");
+ }
+ if (pluginName == null || pluginName.length() == 0) {
+ throw new IllegalArgumentException("invalid pluginName: " +
pluginName);
+ }
+
+ this.deployment = deployment;
+ this.pluginType = pluginType;
+ this.pluginName = pluginName;
+ }
+
+ public PluginDeploymentType getDeployment() {
+ return deployment;
+ }
+
+ public String getPluginName() {
+ return pluginName;
+ }
+
+ public String getPluginType() {
+ return pluginType;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("PluginKey
[deployment=").append(deployment).append(",
pluginType=").append(pluginType).append(
+ ", pluginName=").append(pluginName).append("]");
+ return builder.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + deployment.hashCode();
+ result = prime * result + ((pluginType == null) ? 0 : pluginType.hashCode());
+ result = prime * result + pluginName.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof PluginKey)) {
+ return false;
+ }
+ PluginKey other = (PluginKey) obj;
+ if (!pluginName.equals(other.pluginName)) {
+ return false;
+ }
+ if (pluginType == null) {
+ if (other.pluginType != null) {
+ return false;
+ }
+ } else if (!pluginType.equals(other.pluginType)) {
+ return false;
+
+ }
+ if (deployment != other.deployment) {
+ return false;
+ }
+ return true;
+ }
+}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
new file mode 100644
index 0000000..aa06ea9
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
@@ -0,0 +1,293 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2009 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.plugin;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
+
+import org.rhq.core.domain.configuration.Configuration;
+
+/**
+ * A server plugin.
+ *
+ * This object contains information about the plugin jar itself (e.g. its name and MD5).
+ * It may also contain the jar contents ({@link #getContent()}).
+ */
+@DiscriminatorValue("SERVER")
+@NamedQueries( {
+//
+ // helps you determine if a plugin is installed or was deleted
+ @NamedQuery(name = ServerPlugin.QUERY_GET_STATUS_BY_NAME, query = "" //
+ + " SELECT p.status " //
+ + " FROM ServerPlugin AS p " //
+ + " WHERE p.name = :name)"), //
+
+ // helps you determine which installed plugins are enabled or disabled
+ @NamedQuery(name = ServerPlugin.QUERY_GET_NAMES_BY_ENABLED, query = "" //
+ + " SELECT new org.rhq.core.domain.plugin.PluginKey( " //
+ + " p.deployment, " //
+ + " p.type, " //
+ + " p.name) " //
+ + " FROM ServerPlugin AS p " //
+ + " WHERE p.enabled = :enabled " //
+ + " AND p.status = 'INSTALLED' "), //
+
+ // this query does not load the content blob, but loads everything else
+ @NamedQuery(name = ServerPlugin.QUERY_FIND_BY_IDS, query = "" //
+ + " SELECT new org.rhq.core.domain.plugin.ServerPlugin( " //
+ + " p.id, " //
+ + " p.name, " //
+ + " p.path, " //
+ + " p.displayName, " //
+ + " p.enabled, " //
+ + " p.status, " //
+ + " p.description, " //
+ + " p.help, " //
+ + " p.md5, " //
+ + " p.version, " //
+ + " p.ampsVersion, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ + " p.ctime, " //
+ + " p.mtime) " //
+ + " FROM ServerPlugin AS p " //
+ + " LEFT JOIN p.pluginConfiguration " //
+ + " LEFT JOIN p.scheduledJobsConfiguration " //
+ + " WHERE p.id IN (:ids) " //
+ + " AND p.status = 'INSTALLED' "), //
+
+ // this query does not load the content blob, but loads everything else
+ @NamedQuery(name = ServerPlugin.QUERY_FIND_BY_NAME, query = "" //
+ + " SELECT new org.rhq.core.domain.plugin.ServerPlugin( " //
+ + " p.id, " //
+ + " p.name, " //
+ + " p.path, " //
+ + " p.displayName, " //
+ + " p.enabled, " //
+ + " p.status, " //
+ + " p.description, " //
+ + " p.help, " //
+ + " p.md5, " //
+ + " p.version, " //
+ + " p.ampsVersion, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ + " p.ctime, " //
+ + " p.mtime) " //
+ + " FROM ServerPlugin AS p " //
+ + " LEFT JOIN p.pluginConfiguration " //
+ + " LEFT JOIN p.scheduledJobsConfiguration " //
+ + " WHERE p.name=:name " //
+ + " AND p.status = 'INSTALLED' "), //
+
+ // gets the plugin, even if it is deleted
+ // this query does not load the content blob, but loads everything else
+ @NamedQuery(name = ServerPlugin.QUERY_FIND_ANY_BY_NAME, query = "" //
+ + " SELECT new org.rhq.core.domain.plugin.ServerPlugin( " //
+ + " p.id, " //
+ + " p.name, " //
+ + " p.path, " //
+ + " p.displayName, " //
+ + " p.enabled, " //
+ + " p.status, " //
+ + " p.description, " //
+ + " p.help, " //
+ + " p.md5, " //
+ + " p.version, " //
+ + " p.ampsVersion, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ + " p.ctime, " //
+ + " p.mtime) " //
+ + " FROM ServerPlugin AS p " //
+ + " LEFT JOIN p.pluginConfiguration " //
+ + " LEFT JOIN p.scheduledJobsConfiguration " //
+ + " WHERE p.name=:name "), //
+
+ // finds all installed - ignores those plugins marked as deleted
+ // this query does not load the content blob, but loads everything else
+ @NamedQuery(name = ServerPlugin.QUERY_FIND_ALL_INSTALLED, query = "" //
+ + " SELECT new org.rhq.core.domain.plugin.ServerPlugin( " //
+ + " p.id, " //
+ + " p.name, " //
+ + " p.path, " //
+ + " p.displayName, " //
+ + " p.enabled, " //
+ + " p.status, " //
+ + " p.description, " //
+ + " p.help, " //
+ + " p.md5, " //
+ + " p.version, " //
+ + " p.ampsVersion, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ + " p.ctime, " //
+ + " p.mtime) " //
+ + " FROM ServerPlugin AS p " //
+ + " LEFT JOIN p.pluginConfiguration " //
+ + " LEFT JOIN p.scheduledJobsConfiguration " //
+ + " WHERE p.status = 'INSTALLED' "), //
+
+ // this query is how you enable and disable plugins
+ @NamedQuery(name = ServerPlugin.UPDATE_PLUGINS_ENABLED_BY_IDS, query = ""
//
+ + "UPDATE ServerPlugin p " //
+ + " SET p.enabled = :enabled " //
+ + " WHERE p.id IN (:ids)")
+
+})
+@Entity
+public class ServerPlugin extends AbstractPlugin {
+ private static final long serialVersionUID = 1L;
+
+ public static final String QUERY_GET_STATUS_BY_NAME =
"ServerPlugin.queryGetStatusByName";
+ public static final String QUERY_GET_NAMES_BY_ENABLED =
"ServerPlugin.queryGetNamesByEnabled";
+ public static final String QUERY_FIND_BY_IDS = "ServerPlugin.findByIds";
+ public static final String QUERY_FIND_BY_NAME = "ServerPlugin.findByName";
+ public static final String QUERY_FIND_ANY_BY_NAME =
"ServerPlugin.findAnyByName";
+ public static final String QUERY_FIND_ALL_INSTALLED =
"ServerPlugin.findAllInstalled";
+ public static final String UPDATE_PLUGINS_ENABLED_BY_IDS =
"ServerPlugin.updatePluginsEnabledByIds";
+
+ @JoinColumn(name = "JOBS_CONFIG_ID", referencedColumnName =
"ID")
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
+ private Configuration scheduledJobsConfiguration;
+
+ @JoinColumn(name = "PLUGIN_CONFIG_ID", referencedColumnName =
"ID")
+ @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
+ private Configuration pluginConfiguration;
+
+ @Column(name = "PTYPE")
+ private String type;
+
+ public ServerPlugin() {
+ super();
+ setDeployment(PluginDeploymentType.SERVER);
+ }
+
+ public ServerPlugin(String name, String path) {
+ super(name, path);
+ setDeployment(PluginDeploymentType.SERVER);
+ }
+
+ public ServerPlugin(String name, String path, String md5) {
+ super(name, path, md5);
+ setDeployment(PluginDeploymentType.SERVER);
+ }
+
+ public ServerPlugin(String name, String path, byte[] content) {
+ super(name, path, content);
+ setDeployment(PluginDeploymentType.SERVER);
+ }
+
+ public ServerPlugin(int id, String name, String path, String displayName, boolean
enabled, PluginStatusType status,
+ String description, String help, String md5, String version, String ampsVersion,
Configuration pluginConfig,
+ Configuration scheduledJobsConfig, String type, long ctime, long mtime) {
+
+ super(id, name, path, displayName, enabled, status, description, help, md5,
version, ampsVersion,
+ PluginDeploymentType.SERVER, ctime, mtime);
+ this.pluginConfiguration = pluginConfig;
+ this.scheduledJobsConfiguration = scheduledJobsConfig;
+ this.type = type;
+ }
+
+ @Override
+ public void setDeployment(PluginDeploymentType deployment) {
+ if (deployment != PluginDeploymentType.SERVER) {
+ throw new IllegalArgumentException("ServerPlugin can only ever have
deployment type of SERVER: "
+ + deployment);
+ }
+ super.setDeployment(deployment);
+ }
+
+ /**
+ * If the plugin, itself, has configuration associated with it, this is that
configuration.
+ *
+ * @return the configuration associated with the plugin itself
+ */
+ public Configuration getPluginConfiguration() {
+ return this.pluginConfiguration;
+ }
+
+ public void setPluginConfiguration(Configuration pluginConfiguration) {
+ this.pluginConfiguration = pluginConfiguration;
+ }
+
+ /**
+ * If the plugin has jobs associated with it, this is the configuration for those
jobs.
+ *
+ * @return scheduled job configuration for jobs that the plugin defined.
+ */
+ public Configuration getScheduledJobsConfiguration() {
+ return this.scheduledJobsConfiguration;
+ }
+
+ public void setScheduledJobsConfiguration(Configuration scheduledJobsConfiguration)
{
+ this.scheduledJobsConfiguration = scheduledJobsConfiguration;
+ }
+
+ /**
+ * Plugin type string.
+ *
+ * @return plugin type
+ */
+ public String getType() {
+ return this.type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if ((obj == null) || !(obj instanceof ServerPlugin)) {
+ return false;
+ }
+
+ return super.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "ServerPlugin " + super.toString();
+ }
+}
diff --git
a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
index 729f7c2..c7afe81 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/PluginTest.java
@@ -73,20 +73,16 @@ public class PluginTest extends AbstractEJB3Test {
plugin.setHelp(null);
plugin.setContent(content);
- Query q = em.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ Query q = em.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME);
q.setParameter("name", plugin.getName());
- q.setParameter("type", plugin.getDeployment());
assert q.getResultList().size() == 0; // not in the db yet
em.persist(plugin);
id = plugin.getId();
assert id > 0;
- assert plugin.getPluginConfiguration() == null : "there was no config
that should have been here";
- assert plugin.getScheduledJobsConfiguration() == null : "there was no
config that should have been here";
- q = em.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ q = em.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME);
q.setParameter("name", plugin.getName());
- q.setParameter("type", plugin.getDeployment());
assert ((PluginStatusType) q.getSingleResult()) ==
PluginStatusType.INSTALLED;
plugin = em.find(Plugin.class, id);
@@ -100,9 +96,7 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getMD5().equals(md5);
assert plugin.getVersion() == null;
assert plugin.getDescription() == null;
- assert plugin.getDeployment() == PluginDeploymentType.AGENT; // default is
agent
- assert plugin.getPluginConfiguration() == null;
- assert plugin.getScheduledJobsConfiguration() == null;
+ assert plugin.getDeployment() == PluginDeploymentType.AGENT;
assert plugin.getHelp() == null;
assert new String(plugin.getContent()).equals(new String(content));
@@ -116,33 +110,15 @@ public class PluginTest extends AbstractEJB3Test {
String ampsVersion = "2.1";
String description = "description-UPDATED";
String help = "help-UPDATED";
- PluginDeploymentType deployment = PluginDeploymentType.SERVER;
- Configuration pluginConfig = new Configuration();
- Configuration jobsConfig = new Configuration();
- pluginConfig.put(new PropertySimple("first", "last"));
- jobsConfig.put(new PropertySimple("aaa", "bbb"));
+ PluginDeploymentType deployment = PluginDeploymentType.AGENT;
em.close();
getTransactionManager().commit(); // we will be doing an update - needs to be
in own tx
getTransactionManager().begin();
em = getEntityManager();
- em.persist(pluginConfig);
- em.persist(jobsConfig);
em.flush(); // gotta get those two persists to flush to the DB
- // do what
ServerPluginsBean/ResourceMetadataManagerBean.updateServerPluginExceptContent does
- Configuration config = plugin.getPluginConfiguration();
- if (config != null) {
- config = em.merge(config);
- plugin.setPluginConfiguration(config);
- }
- config = plugin.getScheduledJobsConfiguration();
- if (config != null) {
- config = em.merge(config);
- plugin.setScheduledJobsConfiguration(config);
- }
-
Plugin pluginEntity = em.getReference(Plugin.class, plugin.getId());
pluginEntity.setName(name);
pluginEntity.setPath(path);
@@ -153,8 +129,6 @@ public class PluginTest extends AbstractEJB3Test {
pluginEntity.setVersion(version);
pluginEntity.setAmpsVersion(ampsVersion);
pluginEntity.setDeployment(deployment);
- pluginEntity.setPluginConfiguration(pluginConfig);
- pluginEntity.setScheduledJobsConfiguration(jobsConfig);
pluginEntity.setDescription(description);
pluginEntity.setHelp(help);
pluginEntity.setMtime(System.currentTimeMillis());
@@ -181,9 +155,7 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getVersion().equals(version);
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
- assert plugin.getDeployment() == PluginDeploymentType.SERVER;
- assert plugin.getPluginConfiguration().equals(pluginConfig);
- assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
+ assert plugin.getDeployment() == PluginDeploymentType.AGENT;
assert plugin.getHelp().equals(help);
// and what we really want to test - ensure the content remained intact after
the update
assert new String(plugin.getContent()).equals(new String(content));
@@ -193,9 +165,8 @@ public class PluginTest extends AbstractEJB3Test {
getTransactionManager().commit();
getTransactionManager().begin();
em = getEntityManager();
- q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", plugin.getName());
- q.setParameter("type", plugin.getDeployment());
Plugin doomed = (Plugin) q.getSingleResult();
doomed = em.getReference(Plugin.class, doomed.getId());
em.remove(doomed);
@@ -250,9 +221,7 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getMD5().equals(md5);
assert plugin.getVersion() == null;
assert plugin.getDescription() == null;
- assert plugin.getDeployment() == PluginDeploymentType.AGENT; // default is
agent
- assert plugin.getPluginConfiguration() == null;
- assert plugin.getScheduledJobsConfiguration() == null;
+ assert plugin.getDeployment() == PluginDeploymentType.AGENT;
assert plugin.getHelp() == null;
assert plugin.getContent() == null;
@@ -284,7 +253,7 @@ public class PluginTest extends AbstractEJB3Test {
String help = "the test help string is here";
byte[] content = "this is the test content".getBytes();
String md5 = MessageDigestGenerator.getDigestString(new String(content));
- PluginDeploymentType deployment = PluginDeploymentType.SERVER;
+ PluginDeploymentType deployment = PluginDeploymentType.AGENT;
String ampsVersion = "1.2";
Configuration pluginConfig = new Configuration();
@@ -302,8 +271,6 @@ public class PluginTest extends AbstractEJB3Test {
plugin.setHelp(help);
plugin.setContent(content);
plugin.setDeployment(deployment);
- plugin.setPluginConfiguration(pluginConfig);
- plugin.setScheduledJobsConfiguration(jobsConfig);
em.persist(plugin);
assert plugin.getId() > 0;
@@ -320,8 +287,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == deployment;
- assert plugin.getPluginConfiguration().equals(pluginConfig);
- assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
assert new String(plugin.getContent()).equals(new String(content));
@@ -340,14 +305,11 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == deployment;
- assert plugin.getPluginConfiguration().equals(pluginConfig);
- assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
assert plugin.getContent() == null;
- query = em.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_TYPE);
+ query = em.createNamedQuery(Plugin.QUERY_FIND_BY_IDS);
query.setParameter("ids",
Arrays.asList(Integer.valueOf(plugin.getId())));
- query.setParameter("type", plugin.getDeployment());
plugin = (Plugin) query.getSingleResult();
assert plugin != null;
assert plugin.getId() > 0;
@@ -360,12 +322,10 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == deployment;
- assert plugin.getPluginConfiguration().equals(pluginConfig);
- assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
assert plugin.getContent() == null;
- query = em.createNamedQuery(Plugin.QUERY_FIND_ALL_SERVER);
+ query = em.createNamedQuery(Plugin.QUERY_FIND_ALL_INSTALLED);
List<Plugin> all = query.getResultList();
boolean got_it = false;
for (Plugin p : all) {
@@ -381,8 +341,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getAmpsVersion().equals(ampsVersion);
assert p.getDescription().equals(description);
assert plugin.getDeployment() == deployment;
- assert plugin.getPluginConfiguration().equals(pluginConfig);
- assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert p.getHelp().equals(help);
assert p.getContent() == null;
break;
@@ -399,13 +357,12 @@ public class PluginTest extends AbstractEJB3Test {
List<?> results = query.getResultList();
assert results.size() == 0;
- query = em.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_TYPE);
+ query = em.createNamedQuery(Plugin.QUERY_FIND_BY_IDS);
query.setParameter("ids",
Arrays.asList(Integer.valueOf(plugin.getId())));
- query.setParameter("type", plugin.getDeployment());
results = query.getResultList();
assert results.size() == 0;
- query = em.createNamedQuery(Plugin.QUERY_FIND_ALL_SERVER);
+ query = em.createNamedQuery(Plugin.QUERY_FIND_ALL_INSTALLED);
results = query.getResultList();
assert results.size() == 0;
@@ -513,9 +470,8 @@ public class PluginTest extends AbstractEJB3Test {
getTransactionManager().commit();
getTransactionManager().begin();
em = getEntityManager();
- Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", plugin.getName());
- q.setParameter("type", plugin.getDeployment());
Plugin doomed = (Plugin) q.getSingleResult();
doomed = em.getReference(Plugin.class, doomed.getId());
em.remove(doomed);
@@ -628,9 +584,8 @@ public class PluginTest extends AbstractEJB3Test {
getTransactionManager().commit();
getTransactionManager().begin();
em = getEntityManager();
- Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", plugin.getName());
- q.setParameter("type", plugin.getDeployment());
Plugin doomed = (Plugin) q.getSingleResult();
doomed = em.getReference(Plugin.class, doomed.getId());
em.remove(doomed);
diff --git
a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/ServerPluginTest.java
b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/ServerPluginTest.java
new file mode 100644
index 0000000..c8acf79
--- /dev/null
+++
b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/test/ServerPluginTest.java
@@ -0,0 +1,650 @@
+/*
+ * 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.resource.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.naming.InitialContext;
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import javax.sql.DataSource;
+
+import org.testng.annotations.Test;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
+import org.rhq.core.domain.test.AbstractEJB3Test;
+import org.rhq.core.util.MessageDigestGenerator;
+import org.rhq.core.util.stream.StreamUtil;
+
+@Test
+public class ServerPluginTest extends AbstractEJB3Test {
+ public void testUpdate() throws Throwable {
+ boolean done = false;
+ getTransactionManager().begin();
+ EntityManager em = getEntityManager();
+ try {
+ int id;
+
+ String name = "ServerPluginTest-testUpdate";
+ String path = "/test/Update";
+ String displayName = "Server Plugin Test - testUpdate";
+ boolean enabled = true;
+ PluginStatusType status = PluginStatusType.INSTALLED;
+ String md5 = "abcdef";
+ byte[] content = "the content is here".getBytes();
+
+ ServerPlugin plugin = new ServerPlugin(name, path);
+ plugin.setDisplayName(displayName);
+ plugin.setEnabled(enabled);
+ plugin.setStatus(status);
+ plugin.setMD5(md5);
+ plugin.setVersion(null);
+ plugin.setDescription(null);
+ plugin.setHelp(null);
+ plugin.setContent(content);
+
+ Query q = em.createNamedQuery(ServerPlugin.QUERY_GET_STATUS_BY_NAME);
+ q.setParameter("name", plugin.getName());
+ assert q.getResultList().size() == 0; // not in the db yet
+
+ em.persist(plugin);
+ id = plugin.getId();
+ assert id > 0;
+ assert plugin.getPluginConfiguration() == null : "there was no config
that should have been here";
+ assert plugin.getScheduledJobsConfiguration() == null : "there was no
config that should have been here";
+
+ q = em.createNamedQuery(ServerPlugin.QUERY_GET_STATUS_BY_NAME);
+ q.setParameter("name", plugin.getName());
+ assert ((PluginStatusType) q.getSingleResult()) ==
PluginStatusType.INSTALLED;
+
+ plugin = em.find(ServerPlugin.class, id);
+ assert plugin != null;
+ assert plugin.getId() == id;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getStatus() == PluginStatusType.INSTALLED;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion() == null;
+ assert plugin.getDescription() == null;
+ assert plugin.getDeployment() == PluginDeploymentType.SERVER;
+ assert plugin.getPluginConfiguration() == null;
+ assert plugin.getScheduledJobsConfiguration() == null;
+ assert plugin.getHelp() == null;
+ assert new String(plugin.getContent()).equals(new String(content));
+
+ // everything persisted fine, let's update it and see the content is left
alone
+ name = name + "-UPDATED";
+ path = path + "-UPDATED";
+ displayName = displayName + "-UPDATED";
+ enabled = !enabled;
+ md5 = md5 + "00000";
+ String version = "version-UPDATED";
+ String ampsVersion = "2.1";
+ String description = "description-UPDATED";
+ String help = "help-UPDATED";
+ PluginDeploymentType deployment = PluginDeploymentType.SERVER;
+ Configuration pluginConfig = new Configuration();
+ Configuration jobsConfig = new Configuration();
+ pluginConfig.put(new PropertySimple("first", "last"));
+ jobsConfig.put(new PropertySimple("aaa", "bbb"));
+
+ em.close();
+ getTransactionManager().commit(); // we will be doing an update - needs to be
in own tx
+ getTransactionManager().begin();
+ em = getEntityManager();
+
+ em.persist(pluginConfig);
+ em.persist(jobsConfig);
+ em.flush(); // gotta get those two persists to flush to the DB
+
+ // do what ServerPluginsBean.updateServerPluginExceptContent does
+ Configuration config = plugin.getPluginConfiguration();
+ if (config != null) {
+ config = em.merge(config);
+ plugin.setPluginConfiguration(config);
+ }
+ config = plugin.getScheduledJobsConfiguration();
+ if (config != null) {
+ config = em.merge(config);
+ plugin.setScheduledJobsConfiguration(config);
+ }
+
+ ServerPlugin pluginEntity = em.getReference(ServerPlugin.class,
plugin.getId());
+ pluginEntity.setName(name);
+ pluginEntity.setPath(path);
+ pluginEntity.setDisplayName(displayName);
+ pluginEntity.setEnabled(enabled);
+ pluginEntity.setStatus(status);
+ pluginEntity.setMd5(md5);
+ pluginEntity.setVersion(version);
+ pluginEntity.setAmpsVersion(ampsVersion);
+ pluginEntity.setDeployment(deployment);
+ pluginEntity.setPluginConfiguration(pluginConfig);
+ pluginEntity.setScheduledJobsConfiguration(jobsConfig);
+ pluginEntity.setDescription(description);
+ pluginEntity.setHelp(help);
+ pluginEntity.setMtime(System.currentTimeMillis());
+
+ try {
+ em.flush(); // make sure we push this out to the DB now
+ } catch (Exception e) {
+ throw new Exception("Failed to update a plugin that matches ["
+ plugin + "]", e);
+ }
+
+ em.close();
+ getTransactionManager().commit(); // must commit now
+ getTransactionManager().begin();
+ em = getEntityManager();
+
+ plugin = em.find(ServerPlugin.class, id);
+ assert plugin != null;
+ assert plugin.getId() == id;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion().equals(version);
+ assert plugin.getAmpsVersion().equals(ampsVersion);
+ assert plugin.getDescription().equals(description);
+ assert plugin.getDeployment() == PluginDeploymentType.SERVER;
+ assert plugin.getPluginConfiguration().equals(pluginConfig);
+ assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
+ assert plugin.getHelp().equals(help);
+ // and what we really want to test - ensure the content remained intact after
the update
+ assert new String(plugin.getContent()).equals(new String(content));
+
+ // clean up - delete our test plugin
+ em.close();
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+ em = getEntityManager();
+ q = em.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
+ q.setParameter("name", plugin.getName());
+ ServerPlugin doomed = (ServerPlugin) q.getSingleResult();
+ doomed = em.getReference(ServerPlugin.class, doomed.getId());
+ em.remove(doomed);
+ assert q.getResultList().size() == 0 : "didn't remove the
plugin";
+ em.close();
+ getTransactionManager().commit();
+ done = true;
+ } catch (Throwable t) {
+ t.printStackTrace();
+ throw t;
+ } finally {
+ if (!done) {
+ getTransactionManager().rollback();
+ }
+ }
+ }
+
+ public void testPersistMinimal() throws Exception {
+ getTransactionManager().begin();
+ EntityManager em = getEntityManager();
+ try {
+ String name = "ServerPluginTest-testPersist";
+ String path = "/test/Persist";
+ String displayName = "Server Plugin Test - testPersist";
+ boolean enabled = true;
+ PluginStatusType status = PluginStatusType.INSTALLED;
+ String md5 = "abcdef";
+
+ ServerPlugin plugin = new ServerPlugin(name, path);
+ plugin.setDisplayName(displayName);
+ plugin.setEnabled(enabled);
+ plugin.setStatus(status);
+ plugin.setMD5(md5);
+
+ // the following are the only nullable fields
+ plugin.setVersion(null);
+ plugin.setDescription(null);
+ plugin.setHelp(null);
+ plugin.setContent(null);
+
+ em.persist(plugin);
+ assert plugin.getId() > 0;
+
+ plugin = em.find(ServerPlugin.class, plugin.getId());
+ assert plugin != null;
+ assert plugin.getId() > 0;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getStatus() == PluginStatusType.INSTALLED;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion() == null;
+ assert plugin.getDescription() == null;
+ assert plugin.getDeployment() == PluginDeploymentType.SERVER;
+ assert plugin.getPluginConfiguration() == null;
+ assert plugin.getScheduledJobsConfiguration() == null;
+ assert plugin.getHelp() == null;
+ assert plugin.getContent() == null;
+
+ // side check - see that "deleting" a plugin also sets enabled to
false
+ assert plugin.isEnabled() == true;
+ assert plugin.getStatus() == PluginStatusType.INSTALLED;
+ plugin.setStatus(PluginStatusType.DELETED);
+ assert plugin.getStatus() == PluginStatusType.DELETED;
+ assert plugin.isEnabled() == false;
+ plugin = em.merge(plugin);
+ assert plugin.getStatus() == PluginStatusType.DELETED;
+ assert plugin.isEnabled() == false;
+
+ } finally {
+ getTransactionManager().rollback();
+ }
+ }
+
+ public void testPersistFull() throws Exception {
+ getTransactionManager().begin();
+ EntityManager em = getEntityManager();
+ try {
+ String name = "ServerPluginTest-testPersist";
+ String path = "/test/Persist";
+ String displayName = "Server Plugin Test - testPersist";
+ boolean enabled = true;
+ String version = "1.0";
+ String description = "the test description is here";
+ String help = "the test help string is here";
+ byte[] content = "this is the test content".getBytes();
+ String md5 = MessageDigestGenerator.getDigestString(new String(content));
+ PluginDeploymentType deployment = PluginDeploymentType.SERVER;
+ String ampsVersion = "1.2";
+
+ Configuration pluginConfig = new Configuration();
+ Configuration jobsConfig = new Configuration();
+ pluginConfig.put(new PropertySimple("first", "last"));
+ jobsConfig.put(new PropertySimple("aaa", "bbb"));
+
+ ServerPlugin plugin = new ServerPlugin(name, path);
+ plugin.setDisplayName(displayName);
+ plugin.setEnabled(enabled);
+ plugin.setMD5(md5);
+ plugin.setVersion(version);
+ plugin.setAmpsVersion(ampsVersion);
+ plugin.setDescription(description);
+ plugin.setHelp(help);
+ plugin.setContent(content);
+ plugin.setDeployment(deployment);
+ plugin.setPluginConfiguration(pluginConfig);
+ plugin.setScheduledJobsConfiguration(jobsConfig);
+
+ em.persist(plugin);
+ assert plugin.getId() > 0;
+
+ plugin = em.find(ServerPlugin.class, plugin.getId());
+ assert plugin != null;
+ assert plugin.getId() > 0;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion().equals(version);
+ assert plugin.getAmpsVersion().equals(ampsVersion);
+ assert plugin.getDescription().equals(description);
+ assert plugin.getDeployment() == deployment;
+ assert plugin.getPluginConfiguration().equals(pluginConfig);
+ assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
+ assert plugin.getHelp().equals(help);
+ assert new String(plugin.getContent()).equals(new String(content));
+
+ // test our queries that purposefully do not load in the content blob
+ Query query = em.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", name);
+ plugin = (ServerPlugin) query.getSingleResult();
+ assert plugin != null;
+ assert plugin.getId() > 0;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion().equals(version);
+ assert plugin.getAmpsVersion().equals(ampsVersion);
+ assert plugin.getDescription().equals(description);
+ assert plugin.getDeployment() == deployment;
+ assert plugin.getPluginConfiguration().equals(pluginConfig);
+ assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
+ assert plugin.getHelp().equals(help);
+ assert plugin.getContent() == null;
+
+ query = em.createNamedQuery(ServerPlugin.QUERY_FIND_BY_IDS);
+ query.setParameter("ids",
Arrays.asList(Integer.valueOf(plugin.getId())));
+ plugin = (ServerPlugin) query.getSingleResult();
+ assert plugin != null;
+ assert plugin.getId() > 0;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion().equals(version);
+ assert plugin.getAmpsVersion().equals(ampsVersion);
+ assert plugin.getDescription().equals(description);
+ assert plugin.getDeployment() == deployment;
+ assert plugin.getPluginConfiguration().equals(pluginConfig);
+ assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
+ assert plugin.getHelp().equals(help);
+ assert plugin.getContent() == null;
+
+ query = em.createNamedQuery(ServerPlugin.QUERY_FIND_ALL_INSTALLED);
+ List<ServerPlugin> all = query.getResultList();
+ boolean got_it = false;
+ for (ServerPlugin p : all) {
+ if (p.getName().equals(name)) {
+ got_it = true;
+ assert p.getId() > 0;
+ assert p.getName().equals(name);
+ assert p.getPath().equals(path);
+ assert p.getDisplayName().equals(displayName);
+ assert p.isEnabled() == enabled;
+ assert p.getMD5().equals(md5);
+ assert p.getVersion().equals(version);
+ assert plugin.getAmpsVersion().equals(ampsVersion);
+ assert p.getDescription().equals(description);
+ assert plugin.getDeployment() == deployment;
+ assert plugin.getPluginConfiguration().equals(pluginConfig);
+ assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
+ assert p.getHelp().equals(help);
+ assert p.getContent() == null;
+ break;
+ }
+ }
+ assert got_it : "findAll query failed to get our plugin";
+
+ // mark a plugin deleted - all of our queries should then never see it
+ plugin.setStatus(PluginStatusType.DELETED);
+ em.merge(plugin);
+
+ query = em.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", name);
+ List<?> results = query.getResultList();
+ assert results.size() == 0;
+
+ query = em.createNamedQuery(ServerPlugin.QUERY_FIND_BY_IDS);
+ query.setParameter("ids",
Arrays.asList(Integer.valueOf(plugin.getId())));
+ results = query.getResultList();
+ assert results.size() == 0;
+
+ query = em.createNamedQuery(ServerPlugin.QUERY_FIND_ALL_INSTALLED);
+ results = query.getResultList();
+ assert results.size() == 0;
+
+ } finally {
+ getTransactionManager().rollback();
+ }
+ }
+
+ public void testPersistStreamContent() throws Exception {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ boolean done = false;
+
+ getTransactionManager().begin();
+ EntityManager em = getEntityManager();
+ try {
+ String name = "ServerPluginTest-testPersist";
+ String path = "/test/Persist";
+ String displayName = "Server Plugin Test - testPersist";
+ boolean enabled = true;
+ String version = "1.0";
+ String description = "the test description is here";
+ String help = "the test help string is here";
+ byte[] content = "this is the test content".getBytes();
+ String md5 = MessageDigestGenerator.getDigestString(new String(content));
+
+ // persist the plugin, but without any content
+ ServerPlugin plugin = new ServerPlugin(name, path);
+ plugin.setDisplayName(displayName);
+ plugin.setEnabled(enabled);
+ plugin.setMD5(md5);
+ plugin.setVersion(version);
+ plugin.setDescription(description);
+ plugin.setHelp(help);
+
+ em.persist(plugin);
+ assert plugin.getId() > 0;
+
+ // verify we have a content-less plugin in the db
+ plugin = em.find(ServerPlugin.class, plugin.getId());
+ assert plugin != null;
+ assert plugin.getId() > 0;
+ assert plugin.getName().equals(name);
+ assert plugin.getPath().equals(path);
+ assert plugin.getDisplayName().equals(displayName);
+ assert plugin.isEnabled() == enabled;
+ assert plugin.getMD5().equals(md5);
+ assert plugin.getVersion().equals(version);
+ assert plugin.getDescription().equals(description);
+ assert plugin.getHelp().equals(help);
+ assert plugin.getContent() == null;
+
+ em.close();
+ getTransactionManager().commit(); // must commit since we are going to use a
second connection now
+ getTransactionManager().begin();
+
+ // now stream the content into the plugin's table
+ InitialContext context = getInitialContext();
+ DataSource ds = (DataSource) context.lookup("java:/RHQDS");
+ assert ds != null : "Could not get the data source!";
+ conn = ds.getConnection();
+ ps = conn.prepareStatement("UPDATE " + ServerPlugin.TABLE_NAME +
" SET CONTENT = ? WHERE ID = ?");
+ ps.setBinaryStream(1, new ByteArrayInputStream(content), content.length);
+ ps.setInt(2, plugin.getId());
+ int updateResults = ps.executeUpdate();
+ assert updateResults == 1 : "Failed to stream the content blob: " +
updateResults;
+ ps.close();
+ ps = null;
+ conn.close();
+ conn = null;
+
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+ em = getEntityManager();
+
+ // verify the content made it into the database via hibernate
+ plugin = em.find(ServerPlugin.class, plugin.getId());
+ assert new String(plugin.getContent()).equals(new String(content));
+
+ em.close();
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+
+ // verify the content made it into the database via jdbc streaming
+ conn = ds.getConnection();
+ ps = conn.prepareStatement("SELECT CONTENT FROM " +
ServerPlugin.TABLE_NAME + " WHERE ID = ?");
+ ps.setInt(1, plugin.getId());
+ rs = ps.executeQuery();
+ rs.next();
+ InputStream dbStream = rs.getBinaryStream(1);
+ assert dbStream != null : "Could not read the plugin content stream from
the db";
+ byte[] contentFromDb = StreamUtil.slurp(dbStream);
+ assert contentFromDb.length == content.length;
+ assert new String(contentFromDb).equals(new String(content));
+ assert MessageDigestGenerator.getDigestString(new
String(contentFromDb)).equals(md5);
+ rs.close();
+ rs = null;
+ ps.close();
+ ps = null;
+ conn.close();
+ conn = null;
+
+ // clean up - delete our test plugin
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+ em = getEntityManager();
+ Query q = em.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
+ q.setParameter("name", plugin.getName());
+ ServerPlugin doomed = (ServerPlugin) q.getSingleResult();
+ doomed = em.getReference(ServerPlugin.class, doomed.getId());
+ em.remove(doomed);
+ assert q.getResultList().size() == 0 : "didn't remove the
plugin";
+ em.close();
+ getTransactionManager().commit();
+ done = true;
+
+ } finally {
+ if (rs != null) {
+ rs.close();
+ }
+ if (ps != null) {
+ ps.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ if (!done) {
+ getTransactionManager().rollback();
+ }
+ }
+ }
+
+ public void testPersistStreamContent2() throws Exception {
+ Connection conn = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ boolean done = false;
+
+ getTransactionManager().begin();
+ EntityManager em = getEntityManager();
+ try {
+ byte[] content = "this is the test content".getBytes();
+ String path = "/test/Persist";
+
+ // persist a content-less plugin
+ ServerPlugin plugin = new
ServerPlugin("ServerPluginTest-testPersist", path);
+ plugin.setDisplayName("Server Plugin Test - testPersist");
+ plugin.setEnabled(true);
+ plugin.setMD5(MessageDigestGenerator.getDigestString(new String(content)));
+ em.persist(plugin);
+ assert plugin.getId() > 0;
+
+ em.close();
+ getTransactionManager().commit(); // must commit since we are going to use a
second connection now
+ getTransactionManager().begin();
+
+ // test that we can get a null content stream
+ InitialContext context = getInitialContext();
+ DataSource ds = (DataSource) context.lookup("java:/RHQDS");
+ assert ds != null : "Could not get the data source!";
+ conn = ds.getConnection();
+ ps = conn.prepareStatement("SELECT PATH, CONTENT FROM " +
ServerPlugin.TABLE_NAME + " WHERE ID = ?");
+ ps.setInt(1, plugin.getId());
+ rs = ps.executeQuery();
+ rs.next();
+ String dbPath = rs.getString(1);
+ assert dbPath.equals(path);
+ InputStream dbStream = rs.getBinaryStream(2);
+ assert dbStream == null : "Was expecting a null stream but got a
non-null stream from db";
+ rs.close();
+ ps.close();
+ conn.close();
+ rs = null;
+ ps = null;
+ conn = null;
+
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+
+ // now stream the content into the plugin's table
+ conn = ds.getConnection();
+ ps = conn.prepareStatement("UPDATE " + ServerPlugin.TABLE_NAME +
" SET CONTENT = ? WHERE ID = ?");
+ ps.setBinaryStream(1, new ByteArrayInputStream(content), content.length);
+ ps.setInt(2, plugin.getId());
+ int updateResults = ps.executeUpdate();
+ assert updateResults == 1 : "Failed to stream the content blob: " +
updateResults;
+ ps.close();
+ ps = null;
+ conn.close();
+ conn = null;
+
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+
+ // verify we can get the content stream along with another column in the same
query
+ conn = ds.getConnection();
+ ps = conn.prepareStatement("SELECT PATH, CONTENT FROM " +
ServerPlugin.TABLE_NAME + " WHERE ID = ?");
+ ps.setInt(1, plugin.getId());
+ rs = ps.executeQuery();
+ rs.next();
+ dbPath = rs.getString(1);
+ assert dbPath.equals(path);
+ dbStream = rs.getBinaryStream(2);
+ assert dbStream != null : "Could not read the plugin content stream from
the db";
+ byte[] contentFromDb = StreamUtil.slurp(dbStream);
+ assert contentFromDb.length == content.length;
+ assert new String(contentFromDb).equals(new String(content));
+ assert MessageDigestGenerator.getDigestString(new
String(contentFromDb)).equals(
+ MessageDigestGenerator.getDigestString(new String(content)));
+ rs.close();
+ rs = null;
+ ps.close();
+ ps = null;
+ conn.close();
+ conn = null;
+
+ // clean up - delete our test plugin
+ getTransactionManager().commit();
+ getTransactionManager().begin();
+ em = getEntityManager();
+ Query q = em.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
+ q.setParameter("name", plugin.getName());
+ ServerPlugin doomed = (ServerPlugin) q.getSingleResult();
+ doomed = em.getReference(ServerPlugin.class, doomed.getId());
+ em.remove(doomed);
+ assert q.getResultList().size() == 0 : "didn't remove the
plugin";
+ getTransactionManager().commit();
+ done = true;
+
+ } finally {
+ if (rs != null) {
+ rs.close();
+ }
+ if (ps != null) {
+ ps.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ if (!done) {
+ getTransactionManager().rollback();
+ }
+ }
+ }
+
+}
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
index 0bb87bd..a1400ac 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java
@@ -19,12 +19,15 @@
package org.rhq.enterprise.gui.admin.plugin;
import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.web.RequestParameter;
+
+import org.rhq.core.domain.plugin.AbstractPlugin;
import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -39,8 +42,10 @@ public class InstalledPluginComponent {
@RequestParameter("plugin")
private String name;
+ @RequestParameter("deployment")
+ private PluginDeploymentType deployment;
@RequestParameter("pluginType")
- private PluginDeploymentType type;
+ private String pluginType;
public String getName() {
return this.name;
@@ -50,21 +55,30 @@ public class InstalledPluginComponent {
this.name = name;
}
- public PluginDeploymentType getType() {
- return this.type;
+ public PluginDeploymentType getDeployment() {
+ return this.deployment;
+ }
+
+ public void setType(PluginDeploymentType deployment) {
+ this.deployment = deployment;
+ }
+
+ public String getPluginType() {
+ return this.pluginType;
}
- public void setType(PluginDeploymentType type) {
- this.type = type;
+ public void setPluginType(String pluginType) {
+ this.pluginType = pluginType;
}
- @Factory(value="plugin", autoCreate=true, scope=ScopeType.PAGE)
- public Plugin lookupPlugin() {
- if (this.type == PluginDeploymentType.AGENT) {
+ @Factory(value = "plugin", autoCreate = true, scope = ScopeType.PAGE)
+ public AbstractPlugin lookupPlugin() {
+ if (this.deployment == PluginDeploymentType.AGENT) {
return LookupUtil.getResourceMetadataManager().getPlugin(this.name);
- } else if (this.type == PluginDeploymentType.SERVER) {
+ } else if (this.deployment == PluginDeploymentType.SERVER) {
+ PluginKey pluginKey = new PluginKey(this.deployment, this.pluginType,
this.name);
ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
- Plugin plugin = serverPluginsBean.getServerPlugin(this.name);
+ ServerPlugin plugin = serverPluginsBean.getServerPlugin(pluginKey);
return serverPluginsBean.getServerPluginRelationships(plugin);
}
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
index 3fe6988..192d933 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java
@@ -21,19 +21,22 @@ package org.rhq.enterprise.gui.admin.plugin;
import javax.faces.application.FacesMessage;
import org.apache.commons.logging.Log;
-
import org.apache.commons.logging.LogFactory;
+
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+
import org.rhq.core.clientapi.agent.metadata.ConfigurationMetadataParser;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.AbstractPlugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.gui.util.FacesContextUtility;
import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
import org.rhq.enterprise.server.authz.PermissionException;
@@ -49,19 +52,27 @@ import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDe
@Name("InstalledPluginUIBean")
public class InstalledPluginUIBean {
- private static final String OUTCOME_SUCCESS = "success";
+ private static final String OUTCOME_SUCCESS_SERVER_PLUGIN =
"successServerPlugin";
public static final String MANAGED_BEAN_NAME =
InstalledPluginUIBean.class.getSimpleName();
private final Log log = LogFactory.getLog(InstalledPluginUIBean.class);
@In
- private Plugin plugin;
+ private AbstractPlugin plugin;
private ConfigurationDefinition pluginConfigurationDefinition;
private ConfigurationDefinition scheduledJobsDefinition;
- public Plugin getPlugin() {
+ public AbstractPlugin getPlugin() {
return plugin;
}
- public void setPlugin(Plugin plugin) {
+ public void setPlugin(AbstractPlugin plugin) {
+ this.plugin = plugin;
+ }
+
+ public ServerPlugin getServerPlugin() {
+ return (ServerPlugin) this.plugin;
+ }
+
+ public void setServerPlugin(ServerPlugin plugin) {
this.plugin = plugin;
}
@@ -78,18 +89,18 @@ public class InstalledPluginUIBean {
}
public String updatePlugin() {
- ServerPluginsLocal serverPlugins = LookupUtil.getServerPlugins();
-
+ // note we assume we are editing a server plugin - we don't support editing
agent plugins yet
try {
-
serverPlugins.updateServerPluginExceptContent(EnterpriseFacesContextUtility.getSubject(),
plugin);
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO,
- "Configuration settings saved.");
+ ServerPluginsLocal serverPlugins = LookupUtil.getServerPlugins();
+ Subject subject = EnterpriseFacesContextUtility.getSubject();
+ serverPlugins.updateServerPluginExceptContent(subject, getServerPlugin());
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO,
"Configuration settings saved.");
- return OUTCOME_SUCCESS;
+ return OUTCOME_SUCCESS_SERVER_PLUGIN;
} catch (Exception e) {
log.error("Error updating the plugin configurations.", e);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
- "There was an error changing the configuration settings.",
e);
+ "There was an error changing the configuration settings.", e);
return null;
}
@@ -103,9 +114,12 @@ public class InstalledPluginUIBean {
if (this.plugin.getDeployment() == PluginDeploymentType.SERVER) {
try {
ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
- ServerPluginDescriptorType descriptor =
serverPluginsBean.getServerPluginDescriptor(pluginName);
- this.pluginConfigurationDefinition =
ConfigurationMetadataParser.parse("pc:" + pluginName,
descriptor.getPluginConfiguration());
- this.scheduledJobsDefinition =
ConfigurationMetadataParser.parse("jobs:" + pluginName,
descriptor.getScheduledJobs());
+ PluginKey pluginKey = new PluginKey((ServerPlugin) plugin);
+ ServerPluginDescriptorType descriptor =
serverPluginsBean.getServerPluginDescriptor(pluginKey);
+ this.pluginConfigurationDefinition =
ConfigurationMetadataParser.parse("pc:" + pluginName, descriptor
+ .getPluginConfiguration());
+ this.scheduledJobsDefinition =
ConfigurationMetadataParser.parse("jobs:" + pluginName, descriptor
+ .getScheduledJobs());
} catch (Exception e) {
String err = "Cannot determine what the plugin configuration or
scheduled jobs configuration looks like";
log.error(err + " - Cause: " + e);
@@ -116,7 +130,7 @@ public class InstalledPluginUIBean {
}
/**
- * Throws a permission exception if the user is not allowed to access this
functionality.
+ * Throws a permission exception if the user is not allowed to access this
functionality.
*/
private void hasPermission() {
Subject subject = EnterpriseFacesContextUtility.getSubject();
diff --git
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java
index cfc99cf..6fac7a3 100644
---
a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java
+++
b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java
@@ -35,7 +35,9 @@ import org.richfaces.event.UploadEvent;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
+import org.rhq.core.domain.plugin.AbstractPlugin;
import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.gui.util.FacesContextUtility;
import org.rhq.core.gui.util.StringUtility;
import org.rhq.core.util.exception.ThrowableUtil;
@@ -66,7 +68,7 @@ public class InstalledPluginsUIBean {
return resourceMetadataManagerBean.getPlugins();
}
- public Collection<Plugin> getInstalledServerPlugins() {
+ public Collection<ServerPlugin> getInstalledServerPlugins() {
hasPermission();
return serverPluginsBean.getServerPlugins();
@@ -124,9 +126,9 @@ public class InstalledPluginsUIBean {
}
public void enableServerPlugins() {
- List<Plugin> selectedPlugins = getSelectedServerPlugins();
+ List<ServerPlugin> selectedPlugins = getSelectedServerPlugins();
List<String> selectedPluginNames = new ArrayList<String>();
- for (Plugin selectedPlugin : selectedPlugins) {
+ for (ServerPlugin selectedPlugin : selectedPlugins) {
selectedPluginNames.add(selectedPlugin.getName());
}
@@ -142,9 +144,9 @@ public class InstalledPluginsUIBean {
}
public void disableServerPlugins() {
- List<Plugin> selectedPlugins = getSelectedServerPlugins();
+ List<ServerPlugin> selectedPlugins = getSelectedServerPlugins();
List<String> selectedPluginNames = new ArrayList<String>();
- for (Plugin selectedPlugin : selectedPlugins) {
+ for (ServerPlugin selectedPlugin : selectedPlugins) {
selectedPluginNames.add(selectedPlugin.getName());
}
@@ -160,9 +162,9 @@ public class InstalledPluginsUIBean {
}
public void undeployServerPlugins() {
- List<Plugin> selectedPlugins = getSelectedServerPlugins();
+ List<? extends AbstractPlugin> selectedPlugins =
getSelectedServerPlugins();
List<String> selectedPluginNames = new ArrayList<String>();
- for (Plugin selectedPlugin : selectedPlugins) {
+ for (AbstractPlugin selectedPlugin : selectedPlugins) {
selectedPluginNames.add(selectedPlugin.getName());
}
@@ -177,18 +179,18 @@ public class InstalledPluginsUIBean {
return;
}
- private List<Integer> getIds(List<Plugin> plugins) {
+ private List<Integer> getIds(List<? extends AbstractPlugin> plugins) {
ArrayList<Integer> ids = new ArrayList<Integer>(plugins.size());
- for (Plugin plugin : plugins) {
+ for (AbstractPlugin plugin : plugins) {
ids.add(plugin.getId());
}
return ids;
}
- private List<Plugin> getSelectedServerPlugins() {
+ private List<ServerPlugin> getSelectedServerPlugins() {
Integer[] integerItems = getSelectedPluginIds();
List<Integer> ids = Arrays.asList(integerItems);
- List<Plugin> plugins = serverPluginsBean.getServerPluginsById(ids);
+ List<ServerPlugin> plugins = serverPluginsBean.getServerPluginsById(ids);
return plugins;
}
diff --git
a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml
b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml
index 7f19f4d..377523c 100644
---
a/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml
+++
b/modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml
@@ -13,7 +13,7 @@
<to-view-id>/rhq/admin/largeenv.xhtml</to-view-id>
<redirect/>
</navigation-case>
-
+
</navigation-rule>
<navigation-rule>
@@ -26,20 +26,20 @@
<to-view-id>/rhq/admin/plugin/plugin-list.xhtml</to-view-id>
<redirect/>
</navigation-case>
-
+
</navigation-rule>
<navigation-rule>
<from-view-id>/rhq/admin/plugin/plugin-details-edit.xhtml</from-view-id>
<navigation-case>
- <from-outcome>success</from-outcome>
-
<to-view-id>/rhq/admin/plugin/plugin-details-view.xhtml?plugin=#{plugin.name}&pluginType=#{plugin.deployment}</to-view-id>
+ <from-outcome>successServerPlugin</from-outcome>
+
<to-view-id>/rhq/admin/plugin/plugin-details-view.xhtml?plugin=#{plugin.name}&deployment=#{plugin.deployment}&pluginType=#{serverPlugin.type}</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
-
+
<navigation-rule>
<navigation-case>
<from-outcome>sessionExpired</from-outcome>
@@ -47,5 +47,5 @@
<redirect/>
</navigation-case>
</navigation-rule>
-
+
</faces-config>
\ No newline at end of file
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
b/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
index 2c47b0a..25f3e25 100644
--- a/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
+++ b/modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp
@@ -24,7 +24,9 @@
<%@ page import="org.rhq.enterprise.server.system.SystemManagerLocal" %>
<%@ page import="org.rhq.enterprise.server.auth.SubjectManagerLocal" %>
<%@ page import="org.rhq.enterprise.server.support.SupportManagerLocal"
%>
-<%@page
import="org.rhq.enterprise.server.plugin.ServerPluginsLocal"%><html>
+<%@page import="org.rhq.enterprise.server.plugin.ServerPluginsLocal"%>
+<%@page import="org.rhq.core.domain.plugin.PluginKey"%>
+<%@page
import="org.rhq.core.domain.plugin.PluginDeploymentType"%><html>
<%@ page import="org.rhq.enterprise.server.util.LookupUtil" %>
<%@ page
import="org.rhq.enterprise.server.scheduler.jobs.DataPurgeJob"%>
@@ -203,7 +205,8 @@
else if ("purgeServerPlugin".equals(mode))
{
String serverPluginName = request.getParameter("serverPluginName");
- serverPlugins.purgeServerPlugin(subjectManager.getOverlord(),
serverPluginName);
+ PluginKey key = new PluginKey(PluginDeploymentType.SERVER,
"not-needed", serverPluginName);
+ serverPlugins.purgeServerPlugin(subjectManager.getOverlord(), key);
result = "OK - you can now try to re-register a plugin with the name
[" + serverPluginName + "]";
}
else if ("typeManagerRemote".equals(mode))
diff --git
a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml
b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml
index 389923a..92d36f3 100644
---
a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml
+++
b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details-view.xhtml
@@ -17,7 +17,8 @@
<h:outputLink value="/rhq/admin/plugin/plugin-details-edit.xhtml"
styleClass="buttonmed">
<f:param name="plugin"
value="#{installedPlugin.name}"/>
- <f:param name="pluginType"
value="#{installedPlugin.type}"/>
+ <f:param name="deployment"
value="#{installedPlugin.deployment}"/>
+ <f:param name="pluginType"
value="#{installedPlugin.pluginType}"/>
<h:outputText value="EDIT"/>
</h:outputLink>
</h:panelGrid>
diff --git
a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
index cc11203..6b29013 100644
---
a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
+++
b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-details.xhtml
@@ -15,7 +15,7 @@
<h:outputLink value="plugin-list.xhtml" >
<h:outputText value="Installed Plugins"/>
</h:outputLink>
- >
+ >
<h:outputLink value="#" >
<h:outputText
value="#{InstalledPluginUIBean.plugin.displayName}"/>
</h:outputLink>
@@ -75,7 +75,7 @@
<ui:insert name="pre-config" />
- <rich:panel
rendered="#{InstalledPluginUIBean.plugin.pluginConfiguration != null}">
+ <rich:panel
rendered="#{InstalledPluginUIBean.pluginConfigurationDefinition != null}">
<f:facet name="header">
<h:outputText value="Plugin Configuration"/>
</f:facet>
@@ -85,7 +85,7 @@
readOnly="#{not editMode}" />
</rich:panel>
- <rich:panel
rendered="#{InstalledPluginUIBean.plugin.scheduledJobsConfiguration !=
null}">
+ <rich:panel
rendered="#{InstalledPluginUIBean.scheduledJobsDefinition != null}">
<f:facet name="header">
<h:outputText value="Scheduled Jobs"/>
</f:facet>
diff --git
a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
index 5654368..ba128c1 100644
---
a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
+++
b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml
@@ -77,7 +77,7 @@
<h:outputLink
value="/rhq/admin/plugin/plugin-details-view.xhtml">
<f:param name="plugin"
value="#{agentPlugin.name}"/>
- <f:param name="pluginType" value="AGENT"/>
+ <f:param name="deployment" value="AGENT"/>
<h:outputText value="#{agentPlugin.displayName}"/>
</h:outputLink>
@@ -162,7 +162,8 @@
<h:outputLink
value="/rhq/admin/plugin/plugin-details-view.xhtml">
<f:param name="plugin"
value="#{serverPlugin.name}"/>
- <f:param name="pluginType" value="SERVER"/>
+ <f:param name="deployment" value="SERVER"/>
+ <f:param name="pluginType"
value="#{serverPlugin.type}"/>
<h:outputText value="#{serverPlugin.displayName}"/>
</h:outputLink>
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServerServiceImpl.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServerServiceImpl.java
index 8695d35..4eeb177 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServerServiceImpl.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/CoreServerServiceImpl.java
@@ -259,7 +259,7 @@ public class CoreServerServiceImpl implements CoreServerService {
try {
em = LookupUtil.getEntityManager();
- Query q = em.createNamedQuery(Plugin.QUERY_FIND_ALL_AGENT);
+ Query q = em.createNamedQuery(Plugin.QUERY_FIND_ALL_INSTALLED);
List<Plugin> resultList = q.getResultList();
for (Plugin potentialPlugin : resultList) {
if (potentialPlugin.isEnabled()) {
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
index 6bd8c0f..853ce9c 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
@@ -51,14 +51,15 @@ import org.rhq.core.db.PostgresqlDatabaseType;
import org.rhq.core.db.SQLServerDatabaseType;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.plugin.Plugin;
-import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.core.util.jdbc.JDBCUtil;
import org.rhq.core.util.stream.StreamUtil;
import org.rhq.enterprise.server.auth.SubjectManagerLocal;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.util.LookupUtil;
import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorMetadataParser;
import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorUtil;
@@ -159,8 +160,7 @@ public class ServerPluginScanner {
log.info("Registering RHQ server plugin [" + pluginName + "],
version " + version);
- Plugin plugin = new Plugin(pluginName, pluginFile.getName());
- plugin.setDeployment(PluginDeploymentType.SERVER);
+ ServerPlugin plugin = new ServerPlugin(pluginName, pluginFile.getName());
plugin.setDisplayName((displayName != null) ? displayName : pluginName);
plugin.setEnabled(!descriptor.isDisabledOnDiscovery());
plugin.setDescription(descriptor.getDescription());
@@ -170,6 +170,7 @@ public class ServerPluginScanner {
plugin.setMD5(MessageDigestGenerator.getDigestString(pluginFile));
plugin.setPluginConfiguration(getDefaultPluginConfiguration(descriptor));
plugin.setScheduledJobsConfiguration(getDefaultScheduledJobsConfiguration(descriptor));
+ plugin.setType(new ServerPluginType(descriptor).stringify());
if (descriptor.getHelp() != null &&
!descriptor.getHelp().getContent().isEmpty()) {
plugin.setHelp(String.valueOf(descriptor.getHelp().getContent().get(0)));
@@ -178,7 +179,7 @@ public class ServerPluginScanner {
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
// see if this plugin has been deleted previously; if so, don't register
and delete the file
- PluginStatusType status =
serverPluginsManager.getServerPluginStatus(pluginName);
+ PluginStatusType status = serverPluginsManager.getServerPluginStatus(new
PluginKey(plugin));
if (PluginStatusType.DELETED == status) {
log.warn("Plugin file [" + pluginFile + "] has been
detected but that plugin with name [" + pluginName
+ "] was previously undeployed. Will not re-register that plugin
and the file will be deleted.");
@@ -251,7 +252,7 @@ public class ServerPluginScanner {
String md5 = null;
PluginWithDescriptor pluginWithDescriptor =
this.serverPluginsOnFilesystem.get(pluginJar);
- Plugin plugin = null;
+ ServerPlugin plugin = null;
if (pluginWithDescriptor != null) {
plugin = pluginWithDescriptor.plugin;
}
@@ -283,15 +284,16 @@ public class ServerPluginScanner {
// Let's check to see if there are any obsolete plugins that need to be
deleted.
// This is needed if plugin-A-1.0.jar exists and someone deployed
plugin-A-1.1.jar but fails to delete plugin-A-1.0.jar.
doomedPluginFiles.clear();
- HashMap<String, Plugin> pluginsByName = new HashMap<String,
Plugin>();
+ HashMap<String, ServerPlugin> pluginsByName = new HashMap<String,
ServerPlugin>();
for (Entry<File, PluginWithDescriptor> currentPluginFileEntry :
this.serverPluginsOnFilesystem.entrySet()) {
- Plugin currentPlugin = currentPluginFileEntry.getValue().plugin;
- Plugin existingPlugin = pluginsByName.get(currentPlugin.getName());
+ ServerPlugin currentPlugin = currentPluginFileEntry.getValue().plugin;
+ ServerPlugin existingPlugin = pluginsByName.get(currentPlugin.getName());
if (existingPlugin == null) {
// this is the usual case - this is the only plugin with the given name
we've seen
pluginsByName.put(currentPlugin.getName(), currentPlugin);
} else {
- Plugin obsolete =
ServerPluginDescriptorUtil.determineObsoletePlugin(currentPlugin, existingPlugin);
+ ServerPlugin obsolete =
ServerPluginDescriptorUtil.determineObsoletePlugin(currentPlugin,
+ existingPlugin);
if (obsolete == null) {
obsolete = currentPlugin; // both were identical, but we only want
one file so pick one to get rid of
}
@@ -317,13 +319,13 @@ public class ServerPluginScanner {
}
/**
- * Creates a {@link Plugin} object for the given plugin jar and caches it.
+ * Creates a {@link ServerPlugin} object for the given plugin jar and caches it.
* @param pluginJar information about this plugin jar will be cached
* @param md5 if known, this is the plugin jar's MD5,
<code>null</code> if not known
* @return the plugin jar files's information that has been cached
* @throws Exception if failed to get information about the plugin
*/
- private Plugin cacheFilesystemServerPluginJar(File pluginJar, String md5) throws
Exception {
+ private ServerPlugin cacheFilesystemServerPluginJar(File pluginJar, String md5)
throws Exception {
if (md5 == null) { // don't calculate the MD5 is we've already done it
before
md5 = MessageDigestGenerator.getDigestString(pluginJar);
}
@@ -331,11 +333,10 @@ public class ServerPluginScanner {
ServerPluginDescriptorType descriptor =
ServerPluginDescriptorUtil.loadPluginDescriptorFromUrl(pluginUrl);
String version = ServerPluginDescriptorUtil.getPluginVersion(pluginJar,
descriptor).toString();
String name = descriptor.getName();
- Plugin plugin = new Plugin(name, pluginJar.getName());
+ ServerPlugin plugin = new ServerPlugin(name, pluginJar.getName());
plugin.setMd5(md5);
plugin.setVersion(version);
plugin.setMtime(pluginJar.lastModified());
- plugin.setDeployment(PluginDeploymentType.SERVER);
this.serverPluginsOnFilesystem.put(pluginJar, new PluginWithDescriptor(plugin,
descriptor));
return plugin;
}
@@ -352,7 +353,7 @@ public class ServerPluginScanner {
ResultSet rs = null;
// these are plugins (name/path/md5/mtime) that have changed in the DB but are
missing from the file system
- List<Plugin> updatedPlugins = new ArrayList<Plugin>();
+ List<ServerPlugin> updatedPlugins = new ArrayList<ServerPlugin>();
// the same list as above, only they are the files that are written to the
filesystem and no longer missing
List<File> updatedFiles = new ArrayList<File>();
@@ -362,7 +363,7 @@ public class ServerPluginScanner {
conn = ds.getConnection();
// get all the plugins
- ps = conn.prepareStatement("SELECT NAME, PATH, MD5, MTIME, VERSION FROM
" + Plugin.TABLE_NAME
+ ps = conn.prepareStatement("SELECT NAME, PATH, MD5, MTIME, VERSION FROM
" + ServerPlugin.TABLE_NAME
+ " WHERE DEPLOYMENT = 'SERVER' AND STATUS =
'INSTALLED' ");
rs = ps.executeQuery();
while (rs.next()) {
@@ -402,13 +403,12 @@ public class ServerPluginScanner {
}
if (pluginWithDescriptor != null && currentFile != null
&& currentFile.exists()) {
- Plugin dbPlugin = new Plugin(name, path);
+ ServerPlugin dbPlugin = new ServerPlugin(name, path);
dbPlugin.setMd5(md5);
dbPlugin.setVersion(version);
dbPlugin.setMtime(mtime);
- dbPlugin.setDeployment(PluginDeploymentType.SERVER);
- Plugin obsoletePlugin =
ServerPluginDescriptorUtil.determineObsoletePlugin(dbPlugin,
+ ServerPlugin obsoletePlugin =
ServerPluginDescriptorUtil.determineObsoletePlugin(dbPlugin,
pluginWithDescriptor.plugin);
if (obsoletePlugin == pluginWithDescriptor.plugin) { // yes use ==
for reference equality!
@@ -449,10 +449,9 @@ public class ServerPluginScanner {
}
} else {
log.info("Found server plugin in the DB that we do not yet have:
" + name);
- Plugin plugin = new Plugin(name, path, md5);
+ ServerPlugin plugin = new ServerPlugin(name, path, md5);
plugin.setMtime(mtime);
plugin.setVersion(version);
- plugin.setDeployment(PluginDeploymentType.SERVER);
updatedPlugins.add(plugin);
this.serverPluginsOnFilesystem.remove(expectedFile); // paranoia,
make sure the cache doesn't have this
}
@@ -460,9 +459,9 @@ public class ServerPluginScanner {
JDBCUtil.safeClose(ps, rs);
// write all our updated plugins to the file system
- ps = conn.prepareStatement("SELECT CONTENT FROM " +
Plugin.TABLE_NAME
+ ps = conn.prepareStatement("SELECT CONTENT FROM " +
ServerPlugin.TABLE_NAME
+ " WHERE DEPLOYMENT = 'SERVER' AND STATUS =
'INSTALLED' AND NAME = ?");
- for (Plugin plugin : updatedPlugins) {
+ for (ServerPlugin plugin : updatedPlugins) {
File file = new File(this.getServerPluginDir(), plugin.getPath());
ps.setString(1, plugin.getName());
@@ -527,7 +526,7 @@ public class ServerPluginScanner {
TransactionManager tm = null;
String sql = "UPDATE "
- + Plugin.TABLE_NAME
+ + ServerPlugin.TABLE_NAME
+ " SET CONTENT = ?, MD5 = ?, MTIME = ?, PATH = ? WHERE DEPLOYMENT =
'SERVER' AND STATUS = 'INSTALLED' AND NAME = ?";
// if 'different' is true, give bogus data so the plugin deployer will
think the plugin on the file system is new
@@ -573,12 +572,12 @@ public class ServerPluginScanner {
}
private class PluginWithDescriptor {
- public PluginWithDescriptor(Plugin plugin, ServerPluginDescriptorType descriptor)
{
+ public PluginWithDescriptor(ServerPlugin plugin, ServerPluginDescriptorType
descriptor) {
this.plugin = plugin;
this.descriptor = descriptor;
}
- public Plugin plugin;
+ public ServerPlugin plugin;
public ServerPluginDescriptorType descriptor;
}
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
index 49d6e53..eec126a 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
@@ -46,9 +46,10 @@ import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.util.exception.ThrowableUtil;
import org.rhq.core.util.jdbc.JDBCUtil;
import org.rhq.enterprise.server.RHQConstants;
@@ -63,7 +64,7 @@ import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDe
/**
* A server API into the server plugin infrastructure.
- *
+ *
* @author John Mazzitelli
*/
@Stateless
@@ -78,23 +79,22 @@ public class ServerPluginsBean implements ServerPluginsLocal {
@EJB
private ServerPluginsLocal serverPluginsBean; //self
- public List<Plugin> getServerPlugins() {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_FIND_ALL_SERVER);
+ public List<ServerPlugin> getServerPlugins() {
+ Query q = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_ALL_INSTALLED);
return q.getResultList();
}
- public Plugin getServerPlugin(String name) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
- query.setParameter("name", name);
- Plugin plugin = (Plugin) query.getSingleResult();
- if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin named [" + name +
"] is not a server plugin");
- }
+ public ServerPlugin getServerPlugin(PluginKey key) {
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", key.getPluginName());
+ ServerPlugin plugin = (ServerPlugin) query.getSingleResult();
return plugin;
}
- public Plugin getServerPluginRelationships(Plugin plugin) {
- plugin = getServerPlugin(plugin.getName()); // refresh all but the content field
+ public ServerPlugin getServerPluginRelationships(ServerPlugin plugin) {
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", plugin.getName());
+ plugin = (ServerPlugin) query.getSingleResult();
Configuration config = plugin.getPluginConfiguration();
if (config != null) {
@@ -111,18 +111,17 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return plugin;
}
- public List<Plugin> getServerPluginsById(List<Integer> pluginIds) {
+ public List<ServerPlugin> getServerPluginsById(List<Integer> pluginIds)
{
if (pluginIds == null || pluginIds.size() == 0) {
- return new ArrayList<Plugin>(); // nothing to do
+ return new ArrayList<ServerPlugin>(); // nothing to do
}
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_TYPE);
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_IDS);
query.setParameter("ids", pluginIds);
- query.setParameter("type", PluginDeploymentType.SERVER);
return query.getResultList();
}
- public ServerPluginDescriptorType getServerPluginDescriptor(String pluginName) throws
Exception {
- Plugin plugin = getServerPlugin(pluginName);
+ public ServerPluginDescriptorType getServerPluginDescriptor(PluginKey pluginKey)
throws Exception {
+ ServerPlugin plugin = getServerPlugin(pluginKey);
File pluginsDir =
LookupUtil.getServerPluginService().getServerPluginsDirectory();
File pluginJar = new File(pluginsDir, plugin.getPath());
URL url = pluginJar.toURI().toURL();
@@ -130,10 +129,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return descriptor;
}
- public List<String> getServerPluginNamesByEnabled(boolean enabled) {
- Query query =
entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE);
+ public List<PluginKey> getServerPluginKeysByEnabled(boolean enabled) {
+ Query query =
entityManager.createNamedQuery(ServerPlugin.QUERY_GET_NAMES_BY_ENABLED);
query.setParameter("enabled", Boolean.valueOf(enabled));
- query.setParameter("type", PluginDeploymentType.SERVER);
return query.getResultList();
}
@@ -154,9 +152,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public List<String> disableServerPlugins(Subject subject, List<Integer>
pluginIds) throws Exception {
+ public List<PluginKey> disableServerPlugins(Subject subject,
List<Integer> pluginIds) throws Exception {
if (pluginIds == null || pluginIds.size() == 0) {
- return new ArrayList<String>(); // nothing to do
+ return new ArrayList<PluginKey>(); // nothing to do
}
serverPluginsBean.setServerPluginEnabledFlag(subject, pluginIds, false);
@@ -164,24 +162,24 @@ public class ServerPluginsBean implements ServerPluginsLocal {
ServerPluginServiceManagement serverPluginService =
LookupUtil.getServerPluginService();
MasterServerPluginContainer master =
serverPluginService.getMasterPluginContainer();
- List<String> doomedPlugins = new ArrayList<String>();
+ List<PluginKey> doomedPlugins = new ArrayList<PluginKey>();
for (Integer pluginId : pluginIds) {
- Plugin doomedPlugin = null;
+ ServerPlugin doomedPlugin = null;
try {
- doomedPlugin = entityManager.getReference(Plugin.class, pluginId);
+ doomedPlugin = entityManager.getReference(ServerPlugin.class, pluginId);
} catch (Exception ignore) {
}
if (doomedPlugin != null) {
- String pluginName = doomedPlugin.getName();
- doomedPlugins.add(pluginName);
+ PluginKey pluginKey = new PluginKey(doomedPlugin);
+ doomedPlugins.add(pluginKey);
if (master != null) {
- AbstractTypeServerPluginContainer pc =
master.getPluginContainerByPlugin(pluginName);
+ AbstractTypeServerPluginContainer pc =
master.getPluginContainerByPlugin(pluginKey);
if (pc != null) {
try {
- pc.unschedulePluginJobs(pluginName);
+ pc.unschedulePluginJobs(pluginKey);
} catch (Exception e) {
- log.warn("Failed to unschedule jobs for plugin [" +
pluginName + "]", e);
+ log.warn("Failed to unschedule jobs for plugin [" +
pluginKey + "]", e);
}
}
}
@@ -197,9 +195,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public List<String> undeployServerPlugins(Subject subject, List<Integer>
pluginIds) throws Exception {
+ public List<PluginKey> undeployServerPlugins(Subject subject,
List<Integer> pluginIds) throws Exception {
if (pluginIds == null || pluginIds.size() == 0) {
- return new ArrayList<String>(); // nothing to do
+ return new ArrayList<PluginKey>(); // nothing to do
}
serverPluginsBean.setServerPluginEnabledFlag(subject, pluginIds, false);
@@ -207,24 +205,24 @@ public class ServerPluginsBean implements ServerPluginsLocal {
ServerPluginServiceManagement serverPluginService =
LookupUtil.getServerPluginService();
MasterServerPluginContainer master =
serverPluginService.getMasterPluginContainer();
- List<String> doomedPlugins = new ArrayList<String>();
+ List<PluginKey> doomedPlugins = new ArrayList<PluginKey>();
for (Integer pluginId : pluginIds) {
- Plugin doomedPlugin = null;
+ ServerPlugin doomedPlugin = null;
try {
- doomedPlugin = entityManager.getReference(Plugin.class, pluginId);
+ doomedPlugin = entityManager.getReference(ServerPlugin.class, pluginId);
} catch (Exception ignore) {
}
if (doomedPlugin != null) {
- String pluginName = doomedPlugin.getName();
- doomedPlugins.add(pluginName);
+ PluginKey pluginKey = new PluginKey(doomedPlugin);
+ doomedPlugins.add(pluginKey);
if (master != null) {
- AbstractTypeServerPluginContainer pc =
master.getPluginContainerByPlugin(pluginName);
+ AbstractTypeServerPluginContainer pc =
master.getPluginContainerByPlugin(pluginKey);
if (pc != null) {
try {
- pc.unschedulePluginJobs(pluginName);
+ pc.unschedulePluginJobs(pluginKey);
} catch (Exception e) {
- log.warn("Failed to unschedule jobs for plugin [" +
pluginName + "]", e);
+ log.warn("Failed to unschedule jobs for plugin [" +
pluginKey + "]", e);
}
}
}
@@ -269,7 +267,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (pluginIds == null || pluginIds.size() == 0) {
return; // nothing to do
}
- Query q = entityManager.createNamedQuery(Plugin.UPDATE_PLUGINS_ENABLED_BY_IDS);
+ Query q =
entityManager.createNamedQuery(ServerPlugin.UPDATE_PLUGINS_ENABLED_BY_IDS);
q.setParameter("ids", pluginIds);
q.setParameter("enabled", Boolean.valueOf(enabled));
int count = q.executeUpdate();
@@ -288,8 +286,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (pluginIds == null || pluginIds.size() == 0) {
return; // nothing to do
}
- List<Plugin> plugins = getServerPluginsById(pluginIds);
- for (Plugin plugin : plugins) {
+ List<ServerPlugin> plugins = getServerPluginsById(pluginIds);
+ for (ServerPlugin plugin : plugins) {
plugin.setStatus(status);
updateServerPluginExceptContent(subject, plugin);
}
@@ -297,17 +295,17 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public Plugin registerServerPlugin(Subject subject, Plugin plugin, File pluginFile)
throws Exception {
+ public ServerPlugin registerServerPlugin(Subject subject, ServerPlugin plugin, File
pluginFile) throws Exception {
if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
throw new IllegalArgumentException("Plugin [" + plugin.getName()
+ "] must be a server plugin to be registered");
}
- Plugin existingPlugin = null;
+ ServerPlugin existingPlugin = null;
boolean newOrUpdated = false;
try {
- existingPlugin = getServerPlugin(plugin.getName());
+ existingPlugin = getServerPlugin(new PluginKey(plugin));
} catch (NoResultException nre) {
newOrUpdated = true; // this is expected for new plugins
}
@@ -317,7 +315,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
throw new IllegalArgumentException("Cannot register plugin [" +
plugin.getName()
+ "], it has been marked as deleted");
}
- Plugin obsolete = ServerPluginDescriptorUtil.determineObsoletePlugin(plugin,
existingPlugin);
+ ServerPlugin obsolete =
ServerPluginDescriptorUtil.determineObsoletePlugin(plugin, existingPlugin);
if (obsolete == existingPlugin) { // yes use == for reference equality
newOrUpdated = true;
}
@@ -331,7 +329,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
if (plugin.getId() == 0) {
- PluginStatusType status = getServerPluginStatus(plugin.getName());
+ PluginStatusType status = getServerPluginStatus(new PluginKey(plugin));
if (PluginStatusType.DELETED == status) {
throw new IllegalArgumentException("Cannot register plugin
[" + plugin.getName()
+ "], it has been previously marked as deleted.");
@@ -353,33 +351,27 @@ public class ServerPluginsBean implements ServerPluginsLocal {
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void purgeServerPlugin(Subject subject, String pluginName) {
- Query q =
this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
- q.setParameter("name", pluginName);
- q.setParameter("type", PluginDeploymentType.SERVER);
- Plugin doomed = (Plugin) q.getSingleResult();
+ public void purgeServerPlugin(Subject subject, PluginKey pluginKey) {
+ Query q =
this.entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
+ q.setParameter("name", pluginKey.getPluginName());
+ ServerPlugin doomed = (ServerPlugin) q.getSingleResult();
// get the reference to attach to em and use the em.remove. this cascade deletes
too.
- doomed = this.entityManager.getReference(Plugin.class, doomed.getId());
+ doomed = this.entityManager.getReference(ServerPlugin.class, doomed.getId());
this.entityManager.remove(doomed);
- log.debug("Server plugin [" + pluginName + "] has been purged from
the db");
+ log.debug("Server plugin [" + pluginKey + "] has been purged from
the db");
return;
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
- public Plugin updateServerPluginExceptContent(Subject subject, Plugin plugin) throws
Exception {
+ public ServerPlugin updateServerPluginExceptContent(Subject subject, ServerPlugin
plugin) throws Exception {
// this method is here because we need a way to update the plugin's
information
// without blowing away the content data. Because we do not want to load the
// content blob in memory, the plugin's content field will be null - if we
were
// to entityManager.merge that plugin POJO, it would null out that blob column.
- if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin [" + plugin.getName()
- + "] must be a server plugin to be updated");
- }
-
if (plugin.getId() == 0) {
throw new IllegalArgumentException("Plugin must already exist to update
it");
} else {
@@ -395,7 +387,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
plugin.setScheduledJobsConfiguration(config);
}
- Plugin pluginEntity = entityManager.getReference(Plugin.class,
plugin.getId());
+ ServerPlugin pluginEntity = entityManager.getReference(ServerPlugin.class,
plugin.getId());
pluginEntity.setName(plugin.getName());
pluginEntity.setPath(plugin.getPath());
pluginEntity.setDisplayName(plugin.getDisplayName());
@@ -407,6 +399,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
pluginEntity.setDeployment(plugin.getDeployment());
pluginEntity.setPluginConfiguration(plugin.getPluginConfiguration());
pluginEntity.setScheduledJobsConfiguration(plugin.getScheduledJobsConfiguration());
+ pluginEntity.setType(plugin.getType());
pluginEntity.setDescription(plugin.getDescription());
pluginEntity.setHelp(plugin.getHelp());
pluginEntity.setMtime(plugin.getMtime());
@@ -420,10 +413,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return plugin;
}
- public PluginStatusType getServerPluginStatus(String pluginName) {
- Query q =
entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
- q.setParameter("name", pluginName);
- q.setParameter("type", PluginDeploymentType.SERVER);
+ public PluginStatusType getServerPluginStatus(PluginKey pluginKey) {
+ Query q = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_STATUS_BY_NAME);
+ q.setParameter("name", pluginKey.getPluginName());
PluginStatusType status;
try {
status = (PluginStatusType) q.getSingleResult();
@@ -439,14 +431,14 @@ public class ServerPluginsBean implements ServerPluginsLocal {
// if of type "alert plugin" or "generic plugin". That is only
known when the plugin descriptor
// is parsed, which happens when the master plugin container is initialized.
Therefore, this
// needs to get plugin info from the master plugin container while the master is
running.
- public Map<ServerPluginType, List<String>> getAllPluginsGroupedByType()
{
- Map<ServerPluginType, List<String>> allPlugins = new
HashMap<ServerPluginType, List<String>>();
+ public Map<ServerPluginType, List<PluginKey>>
getAllPluginsGroupedByType() {
+ Map<ServerPluginType, List<PluginKey>> allPlugins = new
HashMap<ServerPluginType, List<PluginKey>>();
MasterServerPluginContainer master =
LookupUtil.getServerPluginService().getMasterPluginContainer();
if (master != null) {
List<ServerPluginType> types = master.getServerPluginTypes();
for (ServerPluginType type : types) {
- List<String> plugins = master.getAllPluginsByPluginType(type);
+ List<PluginKey> plugins = master.getAllPluginsByPluginType(type);
allPlugins.put(type, plugins);
}
}
@@ -474,7 +466,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
try {
conn = this.dataSource.getConnection();
- ps = conn.prepareStatement("UPDATE " + Plugin.TABLE_NAME + "
SET CONTENT = ? WHERE ID = ?");
+ ps = conn.prepareStatement("UPDATE " + ServerPlugin.TABLE_NAME +
" SET CONTENT = ? WHERE ID = ?");
ps.setBinaryStream(1, new BufferedInputStream(fis), (int) file.length());
ps.setInt(2, id);
int updateResults = ps.executeUpdate();
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
index a6a09bf..1820fcc 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
@@ -8,72 +8,73 @@ import javax.ejb.Local;
import javax.persistence.NoResultException;
import org.rhq.core.domain.auth.Subject;
-import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
/**
* Interface to the methods that interact with the serve-side plugin infrastructure.
- *
+ *
* @author John Mazzitelli
*/
@Local
public interface ServerPluginsLocal {
/**
* Returns a list of all the server plugins in the database.
- *
+ *
* @return all plugins found in the DB
*/
- List<Plugin> getServerPlugins();
+ List<ServerPlugin> getServerPlugins();
/**
- * Returns a plugin with the given name.
- * @param name name of plugin to find
+ * Returns a plugin with the given key.
+ * @param key identifies the plugin to find
* @return the named plugin
* @throws NoResultException when no plugin with that name exists
*/
- Plugin getServerPlugin(String name);
+ ServerPlugin getServerPlugin(PluginKey key);
/**
* Methods in this object that return plugins normally do not include
* the data from relationships with the plugin (for example, the
* plugin configuration and scheduled jobs related to the plugin).
- *
+ *
* Call this method to fill in that data that wasn't originally loaded.
- *
+ *
* @param plugin
* @return the same plugin, with the relationship data loaded
* @throws NoResultException when no plugin with that name exists
*/
- Plugin getServerPluginRelationships(Plugin plugin);
+ ServerPlugin getServerPluginRelationships(ServerPlugin plugin);
/**
* Get a list of plugins from their IDs.
- *
+ *
* @param pluginIds the IDs of the plugins to load.
* @return plugins matching the given IDs
*/
- List<Plugin> getServerPluginsById(List<Integer> pluginIds);
+ List<ServerPlugin> getServerPluginsById(List<Integer> pluginIds);
/**
- * Given a plugin name, returns the descriptor for that plugin.
- *
- * @param pluginName
+ * Given a plugin key, returns the descriptor for that plugin.
+ *
+ * @param pluginKey
* @return descriptor parsed from the file in the plugin jar
* @throws Exception if the descriptor could not be retrieved or parsed for the given
plugin
*/
- ServerPluginDescriptorType getServerPluginDescriptor(String pluginName) throws
Exception;
+ ServerPluginDescriptorType getServerPluginDescriptor(PluginKey pluginKey) throws
Exception;
/**
- * Returns a list of plugin names for only those server plugins whose
+ * Returns a list of plugin keys for only those server plugins whose
* enabled flag is equal to the given parameter.
- *
- * @param enabled if <code>true</code>, return only the names of plugins
that are enabled;
- * if <code>false</code>, return only the names of plugins
that are disabled.
- * @return list of plugin names that match the enabled criteria
+ *
+ * @param enabled if <code>true</code>, return only the keys of plugins
that are enabled;
+ * if <code>false</code>, return only the keys of plugins
that are disabled.
+ * @return list of plugin keys that match the enabled criteria
*/
- List<String> getServerPluginNamesByEnabled(boolean enabled);
+ List<PluginKey> getServerPluginKeysByEnabled(boolean enabled);
/**
* Enables the plugins and restarts the server plugin container.
@@ -89,25 +90,25 @@ public interface ServerPluginsLocal {
*
* @param subject user making the request
* @param pluginIds the plugins to be disabled
- * @return the list of names of the plugins that were disabled
+ * @return the list of keys of the plugins that were disabled
* @throws Exception if failed to disable a plugin
*/
- List<String> disableServerPlugins(Subject subject, List<Integer>
pluginIds) throws Exception;
+ List<PluginKey> disableServerPlugins(Subject subject, List<Integer>
pluginIds) throws Exception;
/**
* Removes the plugin from the system and restarts the server plugin container.
*
* @param subject user making the request
* @param pluginIds
- * @return the list of names of plugins that were undeployed
+ * @return the list of keys of plugins that were undeployed
* @throws Exception if failed to undeploy a plugin
*/
- List<String> undeployServerPlugins(Subject subject, List<Integer>
pluginIds) throws Exception;
+ List<PluginKey> undeployServerPlugins(Subject subject, List<Integer>
pluginIds) throws Exception;
/**
* Turns on or off the enabled flag in the database but does NOT restart the server
plugin container.
* This has "requires new" semantics, so the results are committed
immediately upon return.
- *
+ *
* @param subject user making the request
* @param pluginIds the plugins to be enabled
* @param enabled the value of the enabled flag for the plugins
@@ -120,7 +121,7 @@ public interface ServerPluginsLocal {
* If the status is {@link PluginStatusType#DELETED}, the enabled flag is also
flipped to <code>false</code>.
*
* This has "requires new" semantics, so the results are committed
immediately upon return.
- *
+ *
* @param subject user making the request
* @param pluginIds the plugins to be enabled
* @param enabled the value of the enabled flag for the plugins
@@ -131,14 +132,14 @@ public interface ServerPluginsLocal {
/**
* Registers the given plugin to the database. This does nothing with the master
plugin container,
* all it does is ensure the database is up-to-date with this new plugin.
- *
+ *
* @param subject the user that needs to have permissions to add a plugin to the
system
* @param plugin the plugin definition
* @param pluginFile the actual plugin file itself
* @return the plugin after being persisted
- * @throws Exception if failed to fully register the plugin
+ * @throws Exception if failed to fully register the plugin
*/
- Plugin registerServerPlugin(Subject subject, Plugin plugin, File pluginFile) throws
Exception;
+ ServerPlugin registerServerPlugin(Subject subject, ServerPlugin plugin, File
pluginFile) throws Exception;
/**
* Given a plugin that already exists, this will update that plugin's data in the
database,
@@ -150,38 +151,38 @@ public interface ServerPluginsLocal {
* @return the updated plugin
* @throws Exception if the plugin did not already exist or an error occurred that
caused the update to fail
*/
- Plugin updateServerPluginExceptContent(Subject subject, Plugin plugin) throws
Exception;
+ ServerPlugin updateServerPluginExceptContent(Subject subject, ServerPlugin plugin)
throws Exception;
/**
* Purges the server plugin from the database. This ensures that, after this method
returns,
* the given plugin will be unknown. The plugin can be installed again later.
- *
+ *
* This has "requires new" semantics, so the results are committed
immediately upon return.
- * This is really a supporting method for {@link #reRegisterServerPlugin(Subject,
Plugin, File)} - you'll
+ * This is really a supporting method for {@link #reRegisterServerPlugin(Subject,
ServerPlugin, File)} - you'll
* probably want to use that instead. Do not blindly purge server plugins using this
method unless you
* know what you are doing.
- *
+ *
* @param subject user making the request
- * @param pluginName the name of the server plugin to delete
+ * @param pluginKey the key of the server plugin to delete
*/
- void purgeServerPlugin(Subject subject, String pluginName);
+ void purgeServerPlugin(Subject subject, PluginKey pluginKey);
/**
- * Given the name of a server plugin, this will return the status of that plugin.
+ * Given the key of a server plugin, this will return the status of that plugin.
* Use this to determine if a plugin has been deleted or not.
- *
- * @param pluginName the name of the plugin whose status is to be returned.
+ *
+ * @param pluginKey the key of the plugin whose status is to be returned.
* @return the status of the plugin, to indicate if the plugin has been deleted or is
installed.
* <code>null</code> indicates an unknown plugin.
*/
- PluginStatusType getServerPluginStatus(String pluginName);
+ PluginStatusType getServerPluginStatus(PluginKey pluginKey);
/**
* This will return a map containing all plugins currently known to the master plugin
container.
* This will return installed plugins that are both enabled and disabled.
* Note that if the master plugin container is not running, an empty map is
returned.
- *
- * @return names of all enabled and disabled plugins, keyed on their types
+ *
+ * @return keys of all enabled and disabled plugins, keyed on their types
*/
- Map<ServerPluginType, List<String>> getAllPluginsGroupedByType();
+ Map<ServerPluginType, List<PluginKey>> getAllPluginsGroupedByType();
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java
index e88e5fd..3301dcc 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/AbstractTypeServerPluginContainer.java
@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobDataMap;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.enterprise.server.scheduler.SchedulerLocal;
import org.rhq.enterprise.server.util.LookupUtil;
import org.rhq.enterprise.server.xmlschema.CronScheduleType;
@@ -131,7 +132,7 @@ public abstract class AbstractTypeServerPluginContainer {
try {
unloadPlugin(env);
} catch (Exception e) {
- this.log.warn("Failed to unload plugin [" +
env.getPluginName() + "].", e);
+ this.log.warn("Failed to unload plugin [" +
env.getPluginKey().getPluginName() + "].", e);
}
}
@@ -195,14 +196,14 @@ public abstract class AbstractTypeServerPluginContainer {
// process all known plugins and schedule their jobs
List<ScheduledJobDefinition> jobs;
for (ServerPluginEnvironment pluginEnv :
this.pluginManager.getPluginEnvironments()) {
- String pluginName = pluginEnv.getPluginName();
+ String pluginName = pluginEnv.getPluginKey().getPluginName();
try {
jobs =
this.pluginManager.getServerPluginContext(pluginEnv).getSchedules();
if (jobs != null) {
for (ScheduledJobDefinition job : jobs) {
try {
- scheduleJob(job, pluginName);
+ scheduleJob(job, pluginEnv.getPluginKey());
} catch (Throwable t) {
log.warn("Failed to schedule job [" + job +
"] for plugin [" + pluginName + "]", t);
}
@@ -231,13 +232,14 @@ public abstract class AbstractTypeServerPluginContainer {
* and able to process the jobs. This method should only be called when a plugin
* is being disabled or removed.
*
+ * @param pluginKey
* @throws Exception if failed to unschedule jobs
*/
- public void unschedulePluginJobs(String pluginName) throws Exception {
+ public void unschedulePluginJobs(PluginKey pluginKey) throws Exception {
SchedulerLocal scheduler = LookupUtil.getSchedulerBean();
// note: all jobs for a plugin are placed in the same group, where the group name
is the plugin name
- String groupName = pluginName;
+ String groupName = pluginKey.getPluginName();
scheduler.pauseJobGroup(groupName);
String[] jobNames = scheduler.getJobNames(groupName);
@@ -245,7 +247,7 @@ public abstract class AbstractTypeServerPluginContainer {
for (String jobName : jobNames) {
boolean deleted = scheduler.deleteJob(jobName, groupName);
if (!deleted) {
- log.warn("Plugin [" + pluginName + "] failed to get
its job [" + jobName + "] unscheduled!");
+ log.warn("Plugin [" + pluginKey + "] failed to get its
job [" + jobName + "] unscheduled!");
}
}
}
@@ -278,17 +280,17 @@ public abstract class AbstractTypeServerPluginContainer {
* job is not enabled, this method returns immediately as a no-op.
*
* @param schedule instructs how the job should be scheduled
- * @param pluginName the name of the plugin scheduling the job
+ * @param pluginKey the key of the plugin scheduling the job
*
* @throws Exception if failed to schedule the job
*/
- protected void scheduleJob(ScheduledJobDefinition schedule, String pluginName) throws
Exception {
+ protected void scheduleJob(ScheduledJobDefinition schedule, PluginKey pluginKey)
throws Exception {
if (!schedule.isEnabled()) {
return;
}
- String groupName = pluginName;
+ String groupName = pluginKey.getPluginName();
boolean rescheduleIfExists = true; // just in case the parameters change,
we'll always want to reschedule it if it exists
boolean isVolatile = true; // if plugin is removed, this allows for the schedule
to go away upon restart automatically
@@ -302,8 +304,8 @@ public abstract class AbstractTypeServerPluginContainer {
// build the data map for the job, setting some values we need, plus adding the
callback data for the plugin itself
JobDataMap jobData = new JobDataMap();
- jobData.put(AbstractJobWrapper.DATAMAP_PLUGIN_NAME, pluginName);
- jobData.put(AbstractJobWrapper.DATAMAP_PLUGIN_TYPE,
getSupportedServerPluginType().stringify());
+ jobData.put(AbstractJobWrapper.DATAMAP_PLUGIN_NAME, pluginKey.getPluginName());
+ jobData.put(AbstractJobWrapper.DATAMAP_PLUGIN_TYPE,
pluginKey.getPluginType().toString());
jobData.put(AbstractJobWrapper.DATAMAP_JOB_ID, schedule.getJobId());
jobData.put(AbstractJobWrapper.DATAMAP_SCHEDULE_TYPE,
schedule.getScheduleType().getTypeName());
jobData.put(AbstractJobWrapper.DATAMAP_SCHEDULE_TRIGGER,
schedule.getScheduleType().getScheduleTrigger());
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ClassLoaderManager.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ClassLoaderManager.java
index 0a9b61c..ae3bbe4 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ClassLoaderManager.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ClassLoaderManager.java
@@ -34,6 +34,7 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.plugin.PluginKey;
import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
/**
@@ -50,9 +51,9 @@ public class ClassLoaderManager {
private final File tmpDir;
/**
- * Provides a map keyed on plugin name whose values are the URLs to those plugin
jars.
+ * Provides a map keyed on plugin keys whose values are the URLs to those plugin
jars.
*/
- private final Map<String, URL> pluginNamesUrls;
+ private final Map<PluginKey, URL> pluginKeysUrls;
/**
* The parent classloader for those classloaders at the top of the classloader
hierarchy.
@@ -61,11 +62,10 @@ public class ClassLoaderManager {
/**
* These are the classloaders that are built for each plugin.
- * This map is keyed on plugin name.
*
* @see #obtainServerPluginClassLoader(String)
*/
- private final Map<String, ClassLoader> serverPluginClassLoaders;
+ private final Map<PluginKey, ClassLoader> serverPluginClassLoaders;
/**
* Creates the object that will manage all classloaders for the plugins deployed in
the server.
@@ -79,11 +79,13 @@ public class ClassLoaderManager {
this.rootClassLoader = rootClassLoader;
this.tmpDir = tmpDir;
- this.serverPluginClassLoaders = new HashMap<String, ClassLoader>();
+ this.serverPluginClassLoaders = new HashMap<PluginKey, ClassLoader>();
- this.pluginNamesUrls = new HashMap<String, URL>(plugins.size());
+ this.pluginKeysUrls = new HashMap<PluginKey, URL>(plugins.size());
for (Map.Entry<URL, ? extends ServerPluginDescriptorType> entry :
plugins.entrySet()) {
- this.pluginNamesUrls.put(entry.getValue().getName(), entry.getKey());
+ ServerPluginType pluginType = new ServerPluginType(entry.getValue());
+ PluginKey pluginKey = PluginKey.createServerPluginKey(pluginType.stringify(),
entry.getValue().getName());
+ this.pluginKeysUrls.put(pluginKey, entry.getKey());
}
return;
@@ -133,24 +135,24 @@ public class ClassLoaderManager {
/**
* Returns a plugin classloader (creating it if necessary).
*
- * @param pluginName the plugin whose classloader is to be created
+ * @param pluginKey the plugin whose classloader is to be created
* @return the plugin classloader
* @throws Exception
*/
- public synchronized ClassLoader obtainServerPluginClassLoader(String pluginName)
throws Exception {
+ public synchronized ClassLoader obtainServerPluginClassLoader(PluginKey pluginKey)
throws Exception {
- ClassLoader cl = this.serverPluginClassLoaders.get(pluginName);
+ ClassLoader cl = this.serverPluginClassLoaders.get(pluginKey);
if (cl == null) {
- URL pluginJarUrl = this.pluginNamesUrls.get(pluginName);
+ URL pluginJarUrl = this.pluginKeysUrls.get(pluginKey);
if (log.isDebugEnabled()) {
- log.debug("Creating classloader for plugin [" + pluginName +
"] from URL [" + pluginJarUrl + ']');
+ log.debug("Creating classloader for plugin [" + pluginKey +
"] from URL [" + pluginJarUrl + ']');
}
ClassLoader parentClassLoader = this.rootClassLoader;
cl = createClassLoader(pluginJarUrl, null, parentClassLoader);
- this.serverPluginClassLoaders.put(pluginName, cl);
+ this.serverPluginClassLoaders.put(pluginKey, cl);
}
return cl;
@@ -167,7 +169,7 @@ public class ClassLoaderManager {
}
/**
- * Returns a shallow copy of the plugin classloaders keyed on plugin name. This
method is here
+ * Returns a shallow copy of the plugin classloaders keyed on plugin key. This method
is here
* just to support a plugin container management MBean.
*
* Do not use this method to obtain a plugin's classloader, instead, you want to
use
@@ -175,8 +177,8 @@ public class ClassLoaderManager {
*
* @return all plugin classloaders currently assigned to plugins (will never be
<code>null</code>)
*/
- public synchronized Map<String, ClassLoader> getServerPluginClassLoaders() {
- return new HashMap<String, ClassLoader>(this.serverPluginClassLoaders);
+ public synchronized Map<PluginKey, ClassLoader> getServerPluginClassLoaders()
{
+ return new HashMap<PluginKey, ClassLoader>(this.serverPluginClassLoaders);
}
private synchronized Set<ClassLoader> getUniqueServerPluginClassLoaders() {
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
index 4ab3fb2..fc54bb2 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/MasterServerPluginContainer.java
@@ -30,6 +30,7 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.enterprise.server.plugin.pc.alert.AlertServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.content.ContentServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.generic.GenericServerPluginContainer;
@@ -60,7 +61,7 @@ public class MasterServerPluginContainer {
* Because the individual plugin containers are only managing enabled plugins (they
are never told about plugins that disabled).
* this map contains the lists of plugins that are disabled so others can find out
what plugins are registered but not running.
*/
- private Map<ServerPluginType, List<String>> disabledPlugins = new
HashMap<ServerPluginType, List<String>>();
+ private Map<ServerPluginType, List<PluginKey>> disabledPlugins = new
HashMap<ServerPluginType, List<PluginKey>>();
/**
* Starts the master plugin container, which will load all plugins and begin managing
them.
@@ -115,7 +116,9 @@ public class MasterServerPluginContainer {
URL pluginUrl = entry.getKey();
ServerPluginDescriptorType descriptor = entry.getValue();
String pluginName = descriptor.getName();
- ClassLoader classLoader =
this.classLoaderManager.obtainServerPluginClassLoader(pluginName);
+ ServerPluginType pluginType = new ServerPluginType(descriptor);
+ PluginKey pluginKey =
PluginKey.createServerPluginKey(pluginType.stringify(), pluginName);
+ ClassLoader classLoader =
this.classLoaderManager.obtainServerPluginClassLoader(pluginKey);
AbstractTypeServerPluginContainer pc =
getPluginContainerByDescriptor(descriptor);
if (pc != null) {
log.debug("Loading server plugin [" + pluginUrl + "]
into its plugin container");
@@ -243,7 +246,7 @@ public class MasterServerPluginContainer {
/**
* Returns the manager that is responsible for created classloaders for plugins.
- *
+ *
* @return classloader manager
*/
public ClassLoaderManager getClassLoaderManager() {
@@ -251,18 +254,18 @@ public class MasterServerPluginContainer {
}
/**
- * Given a plugin type, this will return the names of all known plugins of that
type.
+ * Given a plugin type, this will return the keys of all known plugins of that type.
* This includes all types that are currently started as well as plugins
* that have been disabled.
- *
+ *
* If the master plugin container has not been started, this returns an empty list.
- *
+ *
* @param pluginType
*
* @return list of both enabled and disabled plugins of the given type
*/
- public List<String> getAllPluginsByPluginType(ServerPluginType pluginType) {
- List<String> allPlugins = new ArrayList<String>();
+ public List<PluginKey> getAllPluginsByPluginType(ServerPluginType pluginType)
{
+ List<PluginKey> allPlugins = new ArrayList<PluginKey>();
AbstractTypeServerPluginContainer pc =
getPluginContainerByPluginType(pluginType);
if (pc != null) {
@@ -272,13 +275,13 @@ public class MasterServerPluginContainer {
Collection<ServerPluginEnvironment> envs =
pluginManager.getPluginEnvironments();
if (envs != null) {
for (ServerPluginEnvironment env : envs) {
- allPlugins.add(env.getPluginName());
+ allPlugins.add(env.getPluginKey());
}
}
}
// add the disabled plugins
- List<String> disabled = this.disabledPlugins.get(pluginType);
+ List<PluginKey> disabled = this.disabledPlugins.get(pluginType);
if (disabled != null) {
allPlugins.addAll(disabled);
}
@@ -292,7 +295,7 @@ public class MasterServerPluginContainer {
* that are supported by a server plugin container. You can obtain the server
* plugin container that manages a particular server plugin type via
* {@link #getPluginContainerByPluginType(ServerPluginType)}.
- *
+ *
* @return all known server plugin types
*/
public synchronized List<ServerPluginType> getServerPluginTypes() {
@@ -302,7 +305,7 @@ public class MasterServerPluginContainer {
/**
* Get the plugin container of the given class. This method provides a strongly typed
return value,
* based on the type of plugin container the caller wants returned.
- *
+ *
* @param clazz the class name of the plugin container that the caller wants
* @return the plugin container of the given class (<code>null</code> if
none found)
*/
@@ -317,17 +320,24 @@ public class MasterServerPluginContainer {
}
/**
- * Given the name of a deployed plugin, this returns the plugin container that is
hosting
- * that plugin. If there is no plugin with the given name or that plugin is not
+ * Given the key of a deployed plugin, this returns the plugin container that is
hosting
+ * that plugin. If there is no plugin with the given key or that plugin is not
* loaded in any plugin container (e.g. when it is disabled), then
<code>null</code> is returned.
- *
- * @param pluginName
- * @return the plugin container that is managing the named plugin of
<code>null</code>
+ *
+ * @param pluginKey
+ * @return the plugin container that is managing the named plugin or
<code>null</code>
*/
- public synchronized <T extends AbstractTypeServerPluginContainer> T
getPluginContainerByPlugin(String pluginName) {
+ public synchronized <T extends AbstractTypeServerPluginContainer> T
getPluginContainerByPlugin(PluginKey pluginKey) {
for (AbstractTypeServerPluginContainer pc : this.pluginContainers.values()) {
- if (null != pc.getPluginManager().getPluginEnvironment(pluginName)) {
- return (T) pc;
+ try {
+ if (pc.getSupportedServerPluginType().equals(new
ServerPluginType(pluginKey.getPluginType()))) {
+ if (null !=
pc.getPluginManager().getPluginEnvironment(pluginKey.getPluginName())) {
+ return (T) pc;
+ }
+ }
+ } catch (Exception skip) {
+ // should never really happen
+ log.error("Bad plugin key: " + pluginKey);
}
}
return null;
@@ -335,7 +345,7 @@ public class MasterServerPluginContainer {
/**
* Given a plugin's descriptor, this will return the plugin container that can
manage the plugin.
- *
+ *
* @param descriptor descriptor to identify a plugin whose container is to be
returned
* @return a plugin container that can handle the plugin with the given descriptor
*/
@@ -346,7 +356,7 @@ public class MasterServerPluginContainer {
/**
* Given a plugin's descriptor, this will return the plugin container that can
manage the plugin.
- *
+ *
* @param descriptor descriptor to identify a plugin whose container is to be
returned
* @return a plugin container that can handle the plugin with the given descriptor
*/
@@ -361,9 +371,9 @@ public class MasterServerPluginContainer {
/**
* Finds all plugins and parses their descriptors. This is only called during
* this master plugin container's {@link
#initialize(MasterServerPluginContainerConfiguration) initialization}.
- *
+ *
* If a plugin fails to load, it will be ignored - other plugins will still load.
- *
+ *
* @return a map of plugins, keyed on the plugin jar URL whose values are the parsed
descriptors
*
* @throws Exception on catastrophic failure. Note that if a plugin failed to load,
@@ -381,7 +391,7 @@ public class MasterServerPluginContainer {
if (pluginFiles != null) {
- List<String> allDisabledPlugins = getDisabledPluginNames();
+ List<PluginKey> allDisabledPlugins = getDisabledPluginNames();
for (File pluginFile : pluginFiles) {
if (pluginFile.getName().endsWith(".jar")) {
@@ -391,19 +401,22 @@ public class MasterServerPluginContainer {
ServerPluginDescriptorType descriptor;
descriptor =
ServerPluginDescriptorUtil.loadPluginDescriptorFromUrl(pluginUrl);
if (descriptor != null) {
- if (!allDisabledPlugins.contains(descriptor.getName()))
{
+ PluginKey pluginKey = PluginKey.createServerPluginKey(new
ServerPluginType(descriptor)
+ .stringify(), descriptor.getName());
+
+ if (!allDisabledPlugins.contains(pluginKey)) {
log.debug("pre-loaded server plugin from URL:
" + pluginUrl);
plugins.put(pluginUrl, descriptor);
} else {
log.info("Server plugin [" +
descriptor.getName()
+ "] is disabled and will not be
initialized");
ServerPluginType pluginType = new
ServerPluginType(descriptor);
- List<String> disabledByType =
this.disabledPlugins.get(pluginType);
+ List<PluginKey> disabledByType =
this.disabledPlugins.get(pluginType);
if (disabledByType == null) {
- disabledByType = new ArrayList<String>(1);
+ disabledByType = new
ArrayList<PluginKey>(1);
this.disabledPlugins.put(pluginType,
disabledByType);
}
- disabledByType.add(descriptor.getName());
+ disabledByType.add(pluginKey);
}
}
} catch (Throwable t) {
@@ -419,22 +432,22 @@ public class MasterServerPluginContainer {
}
/**
- * This will return a list of plugin names that represent all the plugins that are to
be
- * disabled. If a plugin jar is found on the filesystem, its plugin name should be
checked with
- * this "blacklist" if it its name is found, that plugin should not be
loaded.
- *
+ * This will return a list of plugin keys that represent all the plugins that are to
be
+ * disabled. If a plugin jar is found on the filesystem, its plugin key should be
checked with
+ * this "blacklist" - if its key is found, that plugin should not be
loaded.
+ *
* @return names of "blacklisted" plugins that should not be loaded
*/
- protected List<String> getDisabledPluginNames() {
- List<String> disabledPlugins =
LookupUtil.getServerPlugins().getServerPluginNamesByEnabled(false);
+ protected List<PluginKey> getDisabledPluginNames() {
+ List<PluginKey> disabledPlugins =
LookupUtil.getServerPlugins().getServerPluginKeysByEnabled(false);
return disabledPlugins;
}
/**
* Creates the individual plugin containers that can be used to deploy different
plugin types.
- *
+ *
* <p>This is protected to allow subclasses to override the PCs that are
created by this service (mainly to support tests).</p>
- *
+ *
* @return the new plugin containers created by this method
*/
protected List<AbstractTypeServerPluginContainer> createPluginContainers() {
@@ -448,7 +461,7 @@ public class MasterServerPluginContainer {
/**
* Create the root classloader that will be the ancester to all plugin classloaders.
- *
+ *
* @return the root server plugin classloader
*/
protected ClassLoader createRootServerPluginClassLoader() {
@@ -463,7 +476,7 @@ public class MasterServerPluginContainer {
* @param plugins maps plugin URLs with their parsed descriptors
* @param rootClassLoader the classloader at the top of the classloader hierarchy
* @param tmpDir where the classloaders can write out the jars that are embedded in
the plugin jars
- *
+ *
* @return the classloader manager instance
*/
protected ClassLoaderManager createClassLoaderManager(Map<URL, ? extends
ServerPluginDescriptorType> plugins,
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginEnvironment.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginEnvironment.java
index e0809a6..5a7dc61 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginEnvironment.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginEnvironment.java
@@ -20,6 +20,7 @@ package org.rhq.enterprise.server.plugin.pc;
import java.net.URL;
+import org.rhq.core.domain.plugin.PluginKey;
import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
/**
@@ -29,7 +30,7 @@ import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDe
*/
public class ServerPluginEnvironment {
private final URL pluginUrl;
- private final String pluginName;
+ private final PluginKey pluginKey;
private final ClassLoader pluginClassLoader;
private final ServerPluginDescriptorType pluginDescriptor;
@@ -47,11 +48,12 @@ public class ServerPluginEnvironment {
this.pluginUrl = pluginUrl;
this.pluginClassLoader = classLoader;
this.pluginDescriptor = descriptor;
- this.pluginName = this.pluginDescriptor.getName();
+ String pluginTypeStr = new ServerPluginType(descriptor).stringify();
+ this.pluginKey = PluginKey.createServerPluginKey(pluginTypeStr,
this.pluginDescriptor.getName());
}
- public String getPluginName() {
- return this.pluginName;
+ public PluginKey getPluginKey() {
+ return this.pluginKey;
}
public URL getPluginUrl() {
@@ -68,6 +70,6 @@ public class ServerPluginEnvironment {
@Override
public String toString() {
- return this.pluginName + ": url=[" + this.pluginUrl + "]";
+ return this.pluginKey + ": url=[" + this.pluginUrl + "]";
}
}
\ No newline at end of file
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
index 36fa5bd..87f2575 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
@@ -30,7 +30,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
import org.rhq.enterprise.server.util.LookupUtil;
import org.rhq.enterprise.server.xmlschema.ScheduledJobDefinition;
@@ -117,7 +117,7 @@ public class ServerPluginManager {
* @throws Exception if the plugin manager cannot load the plugin or deems the plugin
invalid
*/
public void loadPlugin(ServerPluginEnvironment env) throws Exception {
- String pluginName = env.getPluginName();
+ String pluginName = env.getPluginKey().getPluginName();
log.debug("Loading server plugin [" + pluginName + "] from: "
+ env.getPluginUrl());
// tell the plugin we are loading it
@@ -198,7 +198,7 @@ public class ServerPluginManager {
* @throws Exception if the plugin manager cannot unload the plugin
*/
public void unloadPlugin(ServerPluginEnvironment env) throws Exception {
- String pluginName = env.getPluginName();
+ String pluginName = env.getPluginKey().getPluginName();
log.debug("Unloading server plugin [" + pluginName + "]");
try {
@@ -271,7 +271,7 @@ public class ServerPluginManager {
protected ServerPluginContext getServerPluginContext(ServerPluginEnvironment env) {
- String pluginName = env.getPluginName();
+ String pluginName = env.getPluginKey().getPluginName();
ServerPluginContext context = this.pluginContextCache.get(pluginName);
// if we already created it, return it immediately and don't create another
@@ -288,7 +288,7 @@ public class ServerPluginManager {
List<ScheduledJobDefinition> schedules;
try {
- Plugin plugin = getPlugin(env);
+ ServerPlugin plugin = getPlugin(env);
plugnConfig = plugin.getPluginConfiguration();
Configuration scheduledJobsConfig = plugin.getScheduledJobsConfiguration();
schedules =
ServerPluginDescriptorMetadataParser.getScheduledJobs(scheduledJobsConfig);
@@ -306,12 +306,12 @@ public class ServerPluginManager {
* the plugin configuration and scheduled jobs configuration.
*
* @param pluginEnv
- * @return the Plugin object for the given plugin
+ * @return the ServerPlugin object for the given plugin
*/
- protected Plugin getPlugin(ServerPluginEnvironment pluginEnv) {
+ protected ServerPlugin getPlugin(ServerPluginEnvironment pluginEnv) {
// get the plugin data from the database
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
- Plugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginName());
+ ServerPlugin plugin =
serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey());
return plugin;
}
@@ -332,7 +332,7 @@ public class ServerPluginManager {
*/
protected ServerPluginComponent createServerPluginComponent(ServerPluginEnvironment
environment) throws Exception {
- String pluginName = environment.getPluginName();
+ String pluginName = environment.getPluginKey().getPluginName();
ServerPluginComponent instance = null;
ServerPluginComponentType componentXml =
environment.getPluginDescriptor().getPluginComponent();
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginManager.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginManager.java
index 6f42c5e..8d690f9 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginManager.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginManager.java
@@ -112,7 +112,7 @@ public class ContentServerPluginManager extends ServerPluginManager {
@Override
public void unloadPlugin(ServerPluginEnvironment env) throws Exception {
- metadataManager.unloadPlugin(env.getPluginName());
+ metadataManager.unloadPlugin(env.getPluginKey().getPluginName());
super.unloadPlugin(env);
};
}
\ No newline at end of file
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
index d502f4e..a72c8c3 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
@@ -50,7 +50,6 @@ import org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil;
import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
-import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.content.PackageType;
import org.rhq.core.domain.event.EventDefinition;
@@ -125,7 +124,7 @@ public class ResourceMetadataManagerBean implements
ResourceMetadataManagerLocal
*/
@SuppressWarnings("unchecked")
public List<Plugin> getPlugins() {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_FIND_ALL_AGENT);
+ Query q = entityManager.createNamedQuery(Plugin.QUERY_FIND_ALL_INSTALLED);
return q.getResultList();
}
@@ -197,19 +196,6 @@ public class ResourceMetadataManagerBean implements
ResourceMetadataManagerLocal
if (plugin.getId() == 0) {
entityManager.persist(plugin);
} else {
- // agent plugins don't support these configs, but if/when they do in the
future, this will support it
- // make sure we create (if necessary) and attach the configs
- Configuration config = plugin.getPluginConfiguration();
- if (config != null) {
- config = entityManager.merge(config);
- plugin.setPluginConfiguration(config);
- }
- config = plugin.getScheduledJobsConfiguration();
- if (config != null) {
- config = entityManager.merge(config);
- plugin.setScheduledJobsConfiguration(config);
- }
-
// update all the fields except content
Plugin pluginEntity = entityManager.getReference(Plugin.class,
plugin.getId());
pluginEntity.setName(plugin.getName());
@@ -221,8 +207,6 @@ public class ResourceMetadataManagerBean implements
ResourceMetadataManagerLocal
pluginEntity.setVersion(plugin.getVersion());
pluginEntity.setAmpsVersion(plugin.getAmpsVersion());
pluginEntity.setDeployment(plugin.getDeployment());
- pluginEntity.setPluginConfiguration(plugin.getPluginConfiguration());
-
pluginEntity.setScheduledJobsConfiguration(plugin.getScheduledJobsConfiguration());
pluginEntity.setDescription(plugin.getDescription());
pluginEntity.setHelp(plugin.getHelp());
pluginEntity.setMtime(plugin.getMtime());
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java
index d1a6aba..63f2e1d 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java
@@ -34,12 +34,15 @@ import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.plugin.Plugin;
import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.plugin.pc.generic.TestGenericServerPluginService;
import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.util.LookupUtil;
+import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.generic.GenericPluginDescriptorType;
/**
* @author John Mazzitelli
@@ -75,10 +78,10 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
em = getEntityManager();
Query q = em
- .createQuery("SELECT p FROM Plugin p LEFT JOIN FETCH
p.pluginConfiguration LEFT JOIN FETCH p.scheduledJobsConfiguration WHERE p.name LIKE
'serverplugintest%'");
- List<Plugin> doomed = q.getResultList();
- for (Plugin plugin : doomed) {
- em.remove(em.getReference(Plugin.class, plugin.getId()));
+ .createQuery("SELECT p FROM ServerPlugin p LEFT JOIN FETCH
p.pluginConfiguration LEFT JOIN FETCH p.scheduledJobsConfiguration WHERE p.name LIKE
'serverplugintest%'");
+ List<ServerPlugin> doomed = q.getResultList();
+ for (ServerPlugin plugin : doomed) {
+ em.remove(em.getReference(ServerPlugin.class, plugin.getId()));
}
getTransactionManager().commit();
@@ -98,16 +101,18 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
}
public void testGetPlugins() throws Exception {
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
- List<String> pluginNames =
this.serverPluginsBean.getServerPluginNamesByEnabled(true);
- assert pluginNames.contains(p1.getName()) : pluginNames;
- assert pluginNames.contains(p2.getName()) : pluginNames;
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
- assert !pluginNames.contains(p1.getName()) : pluginNames;
- assert !pluginNames.contains(p2.getName()) : pluginNames;
-
- Plugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
+ PluginKey p1key = new PluginKey(p1);
+ PluginKey p2key = new PluginKey(p2);
+ List<PluginKey> pluginKeys =
this.serverPluginsBean.getServerPluginKeysByEnabled(true);
+ assert pluginKeys.contains(p1key) : pluginKeys;
+ assert pluginKeys.contains(p2key) : pluginKeys;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(false);
+ assert !pluginKeys.contains(p1key) : pluginKeys;
+ assert !pluginKeys.contains(p2key) : pluginKeys;
+
+ ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1key);
assert plugin.getId() == p1.getId() : plugin;
assert plugin.getName().equals(p1.getName()) : plugin;
assetLazyInitializationException(plugin);
@@ -118,7 +123,7 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert plugin.getPluginConfiguration().equals(p1.getPluginConfiguration());
assert
plugin.getScheduledJobsConfiguration().equals(p1.getScheduledJobsConfiguration());
- List<Plugin> plugins = this.serverPluginsBean.getServerPlugins();
+ List<ServerPlugin> plugins = this.serverPluginsBean.getServerPlugins();
assert plugins.contains(p1) : plugins;
assert plugins.contains(p2) : plugins;
assetLazyInitializationException(plugins.get(0));
@@ -136,11 +141,13 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
}
public void testUpdatePlugins() throws Exception {
- Plugin p1 = registerPlugin(1);
- p1 = this.serverPluginsBean.getServerPlugin(p1.getName());
+ ServerPlugin p1 = registerPlugin(1);
+ PluginKey p1key = new PluginKey(p1);
+
+ p1 = this.serverPluginsBean.getServerPlugin(p1key);
p1 = this.serverPluginsBean.getServerPluginRelationships(p1);
- Plugin p1update =
this.serverPluginsBean.updateServerPluginExceptContent(getOverlord(), p1);
+ ServerPlugin p1update =
this.serverPluginsBean.updateServerPluginExceptContent(getOverlord(), p1);
p1update = this.serverPluginsBean.getServerPluginRelationships(p1update);
assert p1update.getId() == p1.getId() : p1update;
@@ -154,41 +161,43 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
}
public void testDisableEnablePlugins() throws Exception {
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
+ PluginKey p1key = new PluginKey(p1);
+ PluginKey p2key = new PluginKey(p2);
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
- List<String> disabled =
this.serverPluginsBean.disableServerPlugins(getOverlord(), ids);
+ List<PluginKey> disabled =
this.serverPluginsBean.disableServerPlugins(getOverlord(), ids);
assert disabled.size() == 2 : disabled;
- assert disabled.contains(p1.getName()) : disabled;
- assert disabled.contains(p2.getName()) : disabled;
+ assert disabled.contains(p1key) : disabled;
+ assert disabled.contains(p2key) : disabled;
;
- assert this.serverPluginsBean.getServerPlugin(p1.getName()).getStatus() ==
PluginStatusType.INSTALLED; // still installed
- assert this.serverPluginsBean.getServerPlugin(p2.getName()).getStatus() ==
PluginStatusType.INSTALLED; // still installed
- List<String> pluginNames =
this.serverPluginsBean.getServerPluginNamesByEnabled(false);
- assert pluginNames.contains(p1.getName()) : pluginNames;
- assert pluginNames.contains(p2.getName()) : pluginNames;
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
- assert !pluginNames.contains(p1.getName()) : pluginNames;
- assert !pluginNames.contains(p2.getName()) : pluginNames;
+ assert this.serverPluginsBean.getServerPlugin(p1key).getStatus() ==
PluginStatusType.INSTALLED; // still installed
+ assert this.serverPluginsBean.getServerPlugin(p2key).getStatus() ==
PluginStatusType.INSTALLED; // still installed
+ List<PluginKey> pluginKeys =
this.serverPluginsBean.getServerPluginKeysByEnabled(false);
+ assert pluginKeys.contains(p1key) : pluginKeys;
+ assert pluginKeys.contains(p2key) : pluginKeys;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
+ assert !pluginKeys.contains(p1key) : pluginKeys;
+ assert !pluginKeys.contains(p2key) : pluginKeys;
// re-enable them
this.serverPluginsBean.enableServerPlugins(getOverlord(), ids);
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
- assert pluginNames.contains(p1.getName()) : pluginNames;
- assert pluginNames.contains(p2.getName()) : pluginNames;
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
- assert !pluginNames.contains(p1.getName()) : pluginNames;
- assert !pluginNames.contains(p2.getName()) : pluginNames;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
+ assert pluginKeys.contains(p1key) : pluginKeys;
+ assert pluginKeys.contains(p2key) : pluginKeys;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(false);
+ assert !pluginKeys.contains(p1key) : pluginKeys;
+ assert !pluginKeys.contains(p2key) : pluginKeys;
// make sure none of these enable/disable settings lost our config
- Plugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1key);
plugin = this.serverPluginsBean.getServerPluginRelationships(plugin);
assert plugin.getPluginConfiguration() != null; // no LazyInitException should be
thrown!
assert plugin.getPluginConfiguration().equals(p1.getPluginConfiguration());
- plugin = this.serverPluginsBean.getServerPlugin(p2.getName());
+ plugin = this.serverPluginsBean.getServerPlugin(p2key);
plugin = this.serverPluginsBean.getServerPluginRelationships(plugin);
assert plugin.getPluginConfiguration() != null; // no LazyInitException should be
thrown!
assert plugin.getPluginConfiguration().equals(p1.getPluginConfiguration());
@@ -198,82 +207,96 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
PluginStatusType status;
- status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX +
"1");
+ PluginKey missingKey;
+ missingKey = new PluginKey(PluginDeploymentType.SERVER, new
ServerPluginType(GenericPluginDescriptorType.class)
+ .stringify(), TEST_PLUGIN_NAME_PREFIX + "1");
+ status = this.serverPluginsBean.getServerPluginStatus(missingKey);
assert status == null;
- status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX +
"2");
+ missingKey = new PluginKey(PluginDeploymentType.SERVER, new
ServerPluginType(GenericPluginDescriptorType.class)
+ .stringify(), TEST_PLUGIN_NAME_PREFIX + "2");
+ status = this.serverPluginsBean.getServerPluginStatus(missingKey);
assert status == null;
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
+ PluginKey p1key = new PluginKey(p1);
+ PluginKey p2key = new PluginKey(p2);
- status = this.serverPluginsBean.getServerPluginStatus(p1.getName());
+ status = this.serverPluginsBean.getServerPluginStatus(p1key);
assert status == PluginStatusType.INSTALLED;
- status = this.serverPluginsBean.getServerPluginStatus(p2.getName());
+ status = this.serverPluginsBean.getServerPluginStatus(p2key);
assert status == PluginStatusType.INSTALLED;
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
- List<String> undeployed =
this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
+ List<PluginKey> undeployed =
this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
assert undeployed.size() == 2 : undeployed;
- assert undeployed.contains(p1.getName()) : undeployed;
- assert undeployed.contains(p2.getName()) : undeployed;
- Plugin p1deleted = getDeletedPluginInTx(p1.getName());
- Plugin p2deleted = getDeletedPluginInTx(p2.getName());
+ assert undeployed.contains(p1key) : undeployed;
+ assert undeployed.contains(p2key) : undeployed;
+ ServerPlugin p1deleted = getDeletedPluginInTx(p1.getName());
+ ServerPlugin p2deleted = getDeletedPluginInTx(p2.getName());
assert p1deleted.getStatus() == PluginStatusType.DELETED;
assert p2deleted.getStatus() == PluginStatusType.DELETED;
- List<String> pluginNames =
this.serverPluginsBean.getServerPluginNamesByEnabled(false);
- assert !pluginNames.contains(p1.getName()) : "deleted plugins should not be
returned even here" + pluginNames;
- assert !pluginNames.contains(p2.getName()) : "deleted plugins should not be
returned even here" + pluginNames;
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
- assert !pluginNames.contains(p1.getName()) : pluginNames;
- assert !pluginNames.contains(p2.getName()) : pluginNames;
+ List<PluginKey> pluginKeys =
this.serverPluginsBean.getServerPluginKeysByEnabled(false);
+ assert !pluginKeys.contains(p1key) : "deleted plugins should not be returned
even here" + pluginKeys;
+ assert !pluginKeys.contains(p2key) : "deleted plugins should not be returned
even here" + pluginKeys;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
+ assert !pluginKeys.contains(p1.getName()) : pluginKeys;
+ assert !pluginKeys.contains(p2.getName()) : pluginKeys;
}
public void testReRegisterPlugins() throws Exception {
PluginStatusType status;
- status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX +
"1");
+ PluginKey missingKey;
+ missingKey = new PluginKey(PluginDeploymentType.SERVER, new
ServerPluginType(GenericPluginDescriptorType.class)
+ .stringify(), TEST_PLUGIN_NAME_PREFIX + "1");
+ status = this.serverPluginsBean.getServerPluginStatus(missingKey);
assert status == null;
- status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX +
"2");
+ missingKey = new PluginKey(PluginDeploymentType.SERVER, new
ServerPluginType(GenericPluginDescriptorType.class)
+ .stringify(), TEST_PLUGIN_NAME_PREFIX + "2");
+ status = this.serverPluginsBean.getServerPluginStatus(missingKey);
assert status == null;
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
+ PluginKey p1key = new PluginKey(p1);
+ PluginKey p2key = new PluginKey(p2);
- status = this.serverPluginsBean.getServerPluginStatus(p1.getName());
+ status = this.serverPluginsBean.getServerPluginStatus(p1key);
assert status == PluginStatusType.INSTALLED;
- status = this.serverPluginsBean.getServerPluginStatus(p2.getName());
+ status = this.serverPluginsBean.getServerPluginStatus(p2key);
assert status == PluginStatusType.INSTALLED;
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
- List<String> undeployed =
this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
+ List<PluginKey> undeployed =
this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
assert undeployed.size() == 2 : undeployed;
- assert undeployed.contains(p1.getName()) : undeployed;
- assert undeployed.contains(p2.getName()) : undeployed;
- Plugin p1deleted = getDeletedPluginInTx(p1.getName());
+ assert undeployed.contains(p1key) : undeployed;
+ assert undeployed.contains(p2key) : undeployed;
+ ServerPlugin p1deleted = getDeletedPluginInTx(p1.getName());
assert p1deleted.getStatus() == PluginStatusType.DELETED;
assert p1deleted.getPluginConfiguration() == null; // undeploy should have
removed this
assert p1deleted.getScheduledJobsConfiguration() == null; // undeploy should have
removed this
- Plugin p2deleted = getDeletedPluginInTx(p1.getName());
+ ServerPlugin p2deleted = getDeletedPluginInTx(p1.getName());
assert p2deleted.getStatus() == PluginStatusType.DELETED;
assert p2deleted.getPluginConfiguration() == null; // undeploy should have
removed this
assert p2deleted.getScheduledJobsConfiguration() == null; // undeploy should have
removed this
- List<String> pluginNames =
this.serverPluginsBean.getServerPluginNamesByEnabled(false);
- assert !pluginNames.contains(p1.getName()) : "deleted plugins should not be
returned even here" + pluginNames;
- assert !pluginNames.contains(p2.getName()) : "deleted plugins should not be
returned even here" + pluginNames;
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
- assert !pluginNames.contains(p1.getName()) : pluginNames;
- assert !pluginNames.contains(p2.getName()) : pluginNames;
+ List<PluginKey> pluginKeys =
this.serverPluginsBean.getServerPluginKeysByEnabled(false);
+ assert !pluginKeys.contains(p1key) : "deleted plugins should not be returned
even here" + pluginKeys;
+ assert !pluginKeys.contains(p2key) : "deleted plugins should not be returned
even here" + pluginKeys;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
+ assert !pluginKeys.contains(p1key) : pluginKeys;
+ assert !pluginKeys.contains(p2key) : pluginKeys;
// purge them completely from the DB to prepare to re-register them
- this.serverPluginsBean.purgeServerPlugin(getOverlord(), p1.getName());
- this.serverPluginsBean.purgeServerPlugin(getOverlord(), p2.getName());
+ this.serverPluginsBean.purgeServerPlugin(getOverlord(), p1key);
+ this.serverPluginsBean.purgeServerPlugin(getOverlord(), p2key);
// we just purged the database, make sure our entity ID's are all zero, since
the original IDs are gone
p1.setId(0);
@@ -284,24 +307,24 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
p2.setScheduledJobsConfiguration(p2.getScheduledJobsConfiguration().deepCopy(false));
// re-register them now
- Plugin p1again = this.serverPluginsBean.registerServerPlugin(getOverlord(), p1,
null);
- Plugin p2again = this.serverPluginsBean.registerServerPlugin(getOverlord(), p2,
null);
+ ServerPlugin p1again = this.serverPluginsBean.registerServerPlugin(getOverlord(),
p1, null);
+ ServerPlugin p2again = this.serverPluginsBean.registerServerPlugin(getOverlord(),
p2, null);
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
- assert pluginNames.contains(p1.getName()) : pluginNames;
- assert pluginNames.contains(p2.getName()) : pluginNames;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
+ assert pluginKeys.contains(p1key) : pluginKeys;
+ assert pluginKeys.contains(p2key) : pluginKeys;
assert p1again.getStatus() == PluginStatusType.INSTALLED;
assert p2again.getStatus() == PluginStatusType.INSTALLED;
- pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(false);
- assert !pluginNames.contains(p1.getName()) : pluginNames;
- assert !pluginNames.contains(p2.getName()) : pluginNames;
+ pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(false);
+ assert !pluginKeys.contains(p1key) : pluginKeys;
+ assert !pluginKeys.contains(p2key) : pluginKeys;
}
- private Plugin registerPlugin(int index) throws Exception {
- Plugin plugin = new Plugin(0, TEST_PLUGIN_NAME_PREFIX + index, "path",
"displayName", true,
+ private ServerPlugin registerPlugin(int index) throws Exception {
+ ServerPlugin plugin = new ServerPlugin(0, TEST_PLUGIN_NAME_PREFIX + index,
"path", "displayName", true,
PluginStatusType.INSTALLED, "description", "help",
"md5", "version", "ampsVersion",
- PluginDeploymentType.SERVER, createPluginConfiguration(),
createScheduledJobsConfiguration(), System
- .currentTimeMillis(), System.currentTimeMillis());
+ createPluginConfiguration(), createScheduledJobsConfiguration(), new
ServerPluginType(
+ GenericPluginDescriptorType.class).stringify(),
System.currentTimeMillis(), System.currentTimeMillis());
plugin = this.serverPluginsBean.registerServerPlugin(getOverlord(), plugin,
null);
assert plugin.getId() > 0;
@@ -310,10 +333,11 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert plugin.getStatus() == PluginStatusType.INSTALLED;
assert plugin.getPluginConfiguration() != null;
assert plugin.getScheduledJobsConfiguration() != null;
+ assert plugin.getType().equals(new
ServerPluginType(GenericPluginDescriptorType.class).stringify());
return plugin;
}
- private void assetLazyInitializationException(Plugin plugin) {
+ private void assetLazyInitializationException(ServerPlugin plugin) {
try {
plugin.getPluginConfiguration().toString();
assert false : "Should have thrown a lazy-initialization exception - we
didn't load config";
@@ -344,14 +368,13 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
return LookupUtil.getSubjectManager().getOverlord();
}
- private Plugin getDeletedPluginInTx(String pluginName) throws Exception {
+ private ServerPlugin getDeletedPluginInTx(String pluginName) throws Exception {
EntityManager em = getEntityManager();
getTransactionManager().begin();
try {
- Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ Query q = em.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", pluginName);
- q.setParameter("type", PluginDeploymentType.SERVER);
- return (Plugin) q.getSingleResult();
+ return (ServerPlugin) q.getSingleResult();
} finally {
getTransactionManager().rollback();
}
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java
index 9f0026b..48a5db7 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java
@@ -32,6 +32,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.util.stream.StreamUtil;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
@@ -82,11 +83,11 @@ public class GenericServerPluginTest extends AbstractEJB3Test {
assert schedules == null;
ServerPluginsLocal serverPluginsLocal = LookupUtil.getServerPlugins();
- Map<ServerPluginType, List<String>> map =
serverPluginsLocal.getAllPluginsGroupedByType();
+ Map<ServerPluginType, List<PluginKey>> map =
serverPluginsLocal.getAllPluginsGroupedByType();
assert map.size() == 1;
- List<String> pluginNames = map.get(new
ServerPluginType(GenericPluginDescriptorType.class));
+ List<PluginKey> pluginNames = map.get(new
ServerPluginType(GenericPluginDescriptorType.class));
assert pluginNames.size() == 1;
- assert pluginNames.get(0).equals("TestSimpleGenericPlugin");
+ assert
pluginNames.get(0).getPluginName().equals("TestSimpleGenericPlugin");
// make sure everything is shutdown
this.pluginService.stopMasterPluginContainer();
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
index 592a3d9..1b577fe 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
@@ -27,9 +27,9 @@ import java.util.Map;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.plugin.Plugin;
-import org.rhq.core.domain.plugin.PluginDeploymentType;
+import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
@@ -38,6 +38,7 @@ import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
import org.rhq.enterprise.server.plugin.pc.ServerPluginEnvironment;
import org.rhq.enterprise.server.plugin.pc.ServerPluginManager;
import org.rhq.enterprise.server.plugin.pc.ServerPluginService;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorMetadataParser;
import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
@@ -96,9 +97,9 @@ public class TestGenericServerPluginService extends ServerPluginService
implemen
}
@Override
- protected List<String> getDisabledPluginNames() {
+ protected List<PluginKey> getDisabledPluginNames() {
// in the real world, the db is checked for enable flag, here we say all
plugins are enabled
- return new ArrayList<String>();
+ return new ArrayList<PluginKey>();
}
}
@@ -175,7 +176,7 @@ public class TestGenericServerPluginService extends
ServerPluginService implemen
}
@Override
- protected Plugin getPlugin(ServerPluginEnvironment env) {
+ protected ServerPlugin getPlugin(ServerPluginEnvironment env) {
try {
Configuration pluginConfig = null;
@@ -195,11 +196,12 @@ public class TestGenericServerPluginService extends
ServerPluginService implemen
}
File pluginFile = new File(env.getPluginUrl().toURI());
- Plugin plugin = new Plugin(0, env.getPluginName(), pluginFile.getName(),
pluginDescriptor
- .getDisplayName(), true, PluginStatusType.INSTALLED,
pluginDescriptor.getDescription(), "",
- MessageDigestGenerator.getDigestString(pluginFile),
pluginDescriptor.getVersion(), pluginDescriptor
- .getVersion(), PluginDeploymentType.SERVER, pluginConfig,
scheduledJobsConfig, System
- .currentTimeMillis(), System.currentTimeMillis());
+ ServerPlugin plugin = new ServerPlugin(0,
env.getPluginKey().getPluginName(), pluginFile.getName(),
+ pluginDescriptor.getDisplayName(), true, PluginStatusType.INSTALLED,
pluginDescriptor
+ .getDescription(), "",
MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor
+ .getVersion(), pluginDescriptor.getVersion(), pluginConfig,
scheduledJobsConfig,
+ new ServerPluginType(pluginDescriptor).stringify(),
System.currentTimeMillis(), System
+ .currentTimeMillis());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
@@ -210,7 +212,7 @@ public class TestGenericServerPluginService extends
ServerPluginService implemen
protected ServerPluginComponent
createServerPluginComponent(ServerPluginEnvironment environment)
throws Exception {
ServerPluginComponent component =
super.createServerPluginComponent(environment);
- components.put(environment.getPluginName(), component);
+ components.put(environment.getPluginKey().getPluginName(), component);
return component;
}
}
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestLifecycleListener.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestLifecycleListener.java
index 0b095e5..9b84ddd 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestLifecycleListener.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestLifecycleListener.java
@@ -18,8 +18,8 @@
*/
package org.rhq.enterprise.server.plugin.pc.generic;
-import org.rhq.enterprise.server.plugin.pc.ServerPluginContext;
import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginContext;
/**
* A sample lifecycle listener for the sample generic plugin. This listener will be
@@ -82,7 +82,7 @@ public class TestLifecycleListener implements ServerPluginComponent {
}
StringBuilder str = new StringBuilder();
-
str.append("plugin-name=").append(this.context.getPluginEnvironment().getPluginName()).append(",");
+
str.append("plugin-key=").append(this.context.getPluginEnvironment().getPluginKey()).append(",");
str.append("plugin-url=").append(this.context.getPluginEnvironment().getPluginUrl()).append(",");
str.append("data-dir=").append(this.context.getDataDirectory()).append(",");
str.append("tmp-dir=").append(this.context.getTemporaryDirectory()); //
do not append ,
diff --git
a/modules/enterprise/server/xml-schemas/src/main/java/org/rhq/enterprise/server/xmlschema/ServerPluginDescriptorUtil.java
b/modules/enterprise/server/xml-schemas/src/main/java/org/rhq/enterprise/server/xmlschema/ServerPluginDescriptorUtil.java
index ac89223..0487d19 100644
---
a/modules/enterprise/server/xml-schemas/src/main/java/org/rhq/enterprise/server/xmlschema/ServerPluginDescriptorUtil.java
+++
b/modules/enterprise/server/xml-schemas/src/main/java/org/rhq/enterprise/server/xmlschema/ServerPluginDescriptorUtil.java
@@ -48,7 +48,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.maven.artifact.versioning.ComparableVersion;
-import org.rhq.core.domain.plugin.Plugin;
+import org.rhq.core.domain.plugin.ServerPlugin;
import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
/**
@@ -103,7 +103,7 @@ public abstract class ServerPluginDescriptorUtil {
* <code>null</code> is returned if they are the same (i.e. they
have the same MD5)
* @throws IllegalArgumentException if the two plugins have different logical names
*/
- public static Plugin determineObsoletePlugin(Plugin plugin1, Plugin plugin2) {
+ public static ServerPlugin determineObsoletePlugin(ServerPlugin plugin1, ServerPlugin
plugin2) {
if (!plugin1.getName().equals(plugin2.getName())) {
throw new IllegalArgumentException("The two plugins don't have the
same name:" + plugin1 + ":" + plugin2);
}