Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Merge branch 'bug/1076104' of https://github.com/metlos/rhq into metl…
Browse files Browse the repository at this point in the history
…os-bug/1076104
  • Loading branch information
jmazzitelli committed Apr 22, 2014
2 parents 659c7bd + 8eaa888 commit a637f1e
Show file tree
Hide file tree
Showing 28 changed files with 401 additions and 364 deletions.
2 changes: 1 addition & 1 deletion modules/core/dbutils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<description>Database schema setup, upgrade and other utilities</description>

<properties>
<db.schema.version>2.145</db.schema.version>
<db.schema.version>2.146</db.schema.version>
<rhq.ds.type-mapping>${rhq.test.ds.type-mapping}</rhq.ds.type-mapping>
<rhq.ds.server-name>${rhq.test.ds.server-name}</rhq.ds.server-name>
<rhq.ds.db-name>${rhq.test.ds.db-name}</rhq.ds.db-name>
Expand Down
11 changes: 11 additions & 0 deletions modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@
</index>
</table>

<table name="RHQ_PLUGIN_SERVER_ACK_DELETE">
<column name="PLUGIN_ID" type="INTEGER" required="true" references="RHQ_PLUGIN"/>
<column name="SERVER_ID" type="INTEGER" required="true" references="RHQ_SERVER"/>

<constraint name="RHQ_PLUGIN_SERVER_ACK_DELETE_PK">
<primaryKey>
<field ref="PLUGIN_ID"/>
<field ref="SERVER_ID"/>
</primaryKey>
</constraint>
</table>
</dbsetup>
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
<xs:enumeration value="DOUBLE"/>
<xs:enumeration value="TIMESTAMP"/>
<xs:enumeration value="LONGVARCHAR"/>
<xs:enumeration value="BLOB"/>
<xs:enumeration value="CLOB"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
Expand Down Expand Up @@ -129,4 +131,4 @@
</xs:complexType>
</xs:element>

</xs:schema>
</xs:schema>
13 changes: 12 additions & 1 deletion modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2289,7 +2289,7 @@
<schemaSpec version="2.143">
<schema-alterColumn table="RHQ_RAW_CONFIG" column="config_ID" nullable="true"/>
</schemaSpec>

<schemaSpec version="2.144">
<!-- RHQ_AGENT_INSTALL -->
<schema-createSequence name="RHQ_AGENT_INSTALL_SEQ" initial="10001" />
Expand All @@ -2314,6 +2314,17 @@
<schema-alterColumn table="RHQ_GROUP_DEF" column="CANNED_EXPRESSION" nullable="true"/>
</schemaSpec>

<schemaSpec version="2.146">
<schema-directSQL>
<statement desc="Create new RHQ_PLUGIN_SERVER_ACK_DELETE table">
CREATE TABLE RHQ_PLUGIN_SERVER_ACK_DELETE (
PLUGIN_ID INTEGER NOT NULL REFERENCES RHQ_PLUGIN,
SERVER_ID INTEGER NOT NULL REFERENCES RHQ_SERVER,
CONSTRAINT RHQ_PLUGIN_SERVER_ACK_DELETE_PK PRIMARY KEY (PLUGIN_ID, SERVER_ID)
)
</statement>
</schema-directSQL>
</schemaSpec>
</dbupgrade>
</target>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,30 @@
package org.rhq.core.domain.plugin;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
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.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.PrePersist;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.rhq.core.domain.cloud.Server;

/**
* Base plugin implementation that agent and server plugin implementations extend.
*
Expand Down Expand Up @@ -107,6 +115,11 @@ public class AbstractPlugin implements Serializable {
@Column(name = "CONTENT", nullable = true)
private byte[] content;

@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "RHQ_PLUGIN_SERVER_ACK_DELETE", joinColumns = @JoinColumn(name = "PLUGIN_ID"),
inverseJoinColumns = @JoinColumn(name = "SERVER_ID"))
private Set<Server> serversAcknowledgedDelete;

public AbstractPlugin() {
}

Expand Down Expand Up @@ -357,6 +370,17 @@ public void setDeployment(PluginDeploymentType deployment) {
this.deployment = deployment;
}

/**
* The list of the servers that acknowledged that this plugin is deleted.
* Used to determine whether it is safe to purge the plugin from the database.
*/
public Set<Server> getServersAcknowledgedDelete() {
if (serversAcknowledgedDelete == null) {
serversAcknowledgedDelete = new HashSet<Server>();
}
return serversAcknowledgedDelete;
}

/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,11 @@
+ " WHERE p.ctime = -1 AND p.status = 'DELETED'"
),

@NamedQuery(name = Plugin.PURGE_PLUGINS, query = ""
+ " DELETE FROM Plugin p WHERE p IN (:plugins)")
@NamedQuery(
name = Plugin.QUERY_UNACKED_DELETED_PLUGINS,
query = "SELECT p FROM Plugin p WHERE p.status = 'DELETED' AND :serverId NOT MEMBER OF p.serversAcknowledgedDelete"
)

})
@Entity
public class Plugin extends AbstractPlugin {
Expand All @@ -259,8 +262,18 @@ public class Plugin extends AbstractPlugin {
public static final String UPDATE_PLUGINS_ENABLED_BY_IDS = "Plugin.updatePluginsEnabledByIds";
public static final String QUERY_FIND_BY_RESOURCE_TYPE_AND_CATEGORY = "Plugin.findByResourceType";
public static final String UPDATE_PLUGIN_ENABLED_BY_ID = "Plugin.updatePluginEnabledById";
public static final String QUERY_UNACKED_DELETED_PLUGINS = "Plugin.unackedDeletedPlugins";

/**
* @deprecated This used to identify a named query that no longer exist. Do not use this for anything.
*/
@Deprecated
public static final String PURGE_PLUGINS = "Plugin.purgePlugins";

/**
* @deprecated This is no longer used and means nothing now.
*/
@Deprecated
public static final long PURGED = -1;

public Plugin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@
+ " LEFT JOIN p.scheduledJobsConfiguration AS jobsConfig " //
+ " WHERE p.status = 'INSTALLED' "), //

// finds all installed - ignores those plugins marked as deleted
// this query does not load the content blob or plugin or schedule configurations
@NamedQuery(name = ServerPlugin.QUERY_FIND_DELETED, query = "" //
+ " SELECT p " //
+ " FROM ServerPlugin AS p " //
+ " WHERE p.status = 'DELETED' "), //

// returns all installed plugins, both enabled and disabled
// this is faster than QUERY_FIND_ALL_INSTALLED because it doesn't join configs
@NamedQuery(name = ServerPlugin.QUERY_FIND_ALL_INSTALLED_KEYS, query = "" //
Expand Down Expand Up @@ -242,7 +249,13 @@
@NamedQuery(name = ServerPlugin.UPDATE_PLUGIN_ENABLED_BY_ID, query = "" //
+ "UPDATE ServerPlugin p " //
+ " SET p.enabled = :enabled " //
+ " WHERE p.id = :id)")
+ " WHERE p.id = :id)"),

@NamedQuery(
name = ServerPlugin.QUERY_UNACKED_DELETED_PLUGINS,
query = "SELECT p FROM ServerPlugin p WHERE p.status = 'DELETED' AND :serverId NOT MEMBER OF p.serversAcknowledgedDelete"
)


})
@Entity
Expand All @@ -257,10 +270,12 @@ public class ServerPlugin extends AbstractPlugin {
public static final String QUERY_FIND_ANY_BY_NAME = "ServerPlugin.findAnyByName";
public static final String QUERY_FIND_ALL = "ServerPlugin.findAll";
public static final String QUERY_FIND_ALL_INSTALLED = "ServerPlugin.findAllInstalled";
public static final String QUERY_FIND_DELETED = "ServerPlugin.findDeleted";
public static final String QUERY_FIND_ALL_INSTALLED_KEYS = "ServerPlugin.findAllInstalledKeys";
public static final String QUERY_FIND_KEYS_BY_IDS = "ServerPlugin.findKeysByIds";
public static final String QUERY_GET_CONFIG_MTIMES = "ServerPlugin.getConfigMTimes";
public static final String UPDATE_PLUGIN_ENABLED_BY_ID = "ServerPlugin.updatePluginEnabledById";
public static final String QUERY_UNACKED_DELETED_PLUGINS = "ServerPlugin.unackedDeletedPlugins";

@JoinColumn(name = "JOBS_CONFIG_ID", referencedColumnName = "ID", nullable = true)
@OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, optional = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ public class AgentPluginTableView extends TableSection<AgentPluginDataSource> {
private static final String FIELD_DEPLOYED = "deployed";
private static final String FIELD_VERSION = "version";

private boolean showDeleted = false;

public AgentPluginTableView() {
super(null);
setHeight100();
Expand Down Expand Up @@ -191,38 +189,6 @@ public void onFailure(Throwable caught) {
}
});

addTableAction(MSG.common_button_purge(), MSG.common_msg_areYouSure(), new AuthorizedTableAction(this,
TableActionEnablement.ANY, Permission.MANAGE_SETTINGS) {
public boolean isEnabled(ListGridRecord[] selection) {
if (showDeleted) {
return super.isEnabled(selection);
} else {
return false; // we aren't showing deleted plugins, so there is no plugin shown that can be purged anyway
}
}

public void executeAction(ListGridRecord[] selections, Object actionValue) {
int[] selectedIds = getSelectedIds(selections);
GWTServiceLookup.getPluginService().purgeAgentPlugins(selectedIds,
new AsyncCallback<ArrayList<String>>() {
@Override
public void onSuccess(ArrayList<String> result) {
Message msg = new Message(MSG.view_admin_plugins_purgedAgentPlugins(result.toString()),
Severity.Info);
CoreGUI.getMessageCenter().notify(msg);
refresh();
}

@Override
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(
MSG.view_admin_plugins_purgedAgentPluginsFailure() + " " + caught.getMessage(), caught);
refreshTableInfo();
}
});
}
});

IButton scanForUpdatesButton = new EnhancedIButton(MSG.view_admin_plugins_scan());
scanForUpdatesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Expand All @@ -244,25 +210,9 @@ public void onFailure(Throwable caught) {
}
});

final IButton showDeletedButton = new EnhancedIButton(MSG.view_admin_plugins_showDeleted());
showDeletedButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
showDeleted = !showDeleted;
if (showDeleted) {
showDeletedButton.setTitle(MSG.view_admin_plugins_hideDeleted());
getListGrid().showField(FIELD_DEPLOYED);
} else {
showDeletedButton.setTitle(MSG.view_admin_plugins_showDeleted());
getListGrid().hideField(FIELD_DEPLOYED);
}
refresh();
}
});

PluginFileUploadForm pluginUploadForm = new PluginFileUploadForm(MSG.view_admin_plugins_upload(), true);

addExtraWidget(scanForUpdatesButton, true);
addExtraWidget(showDeletedButton, true);
addExtraWidget(pluginUploadForm, true);

super.configureTable();
Expand Down Expand Up @@ -336,12 +286,6 @@ public List<ListGridField> getListGridFields() {
enabledField.setAlign(Alignment.CENTER);
fields.add(enabledField);

ListGridField deployedField = new ListGridField(FIELD_DEPLOYED, MSG.view_admin_plugins_deployed());
deployedField.setType(ListGridFieldType.IMAGE);
deployedField.setAlign(Alignment.CENTER);
deployedField.setHidden(true);
fields.add(deployedField);

ListGridField versionField = new ListGridField(FIELD_VERSION, MSG.common_title_version());
versionField.setHidden(true);
fields.add(versionField);
Expand All @@ -351,15 +295,14 @@ public List<ListGridField> getListGridFields() {
descriptionField.setWidth("*");
lastUpdateField.setWidth("20%");
enabledField.setWidth(65);
deployedField.setWidth(75);
versionField.setWidth(100);

return fields;
}

@Override
protected void executeFetch(final DSRequest request, final DSResponse response, Criteria criteria) {
GWTServiceLookup.getPluginService().getAgentPlugins(showDeleted, new AsyncCallback<ArrayList<Plugin>>() {
GWTServiceLookup.getPluginService().getAgentPlugins(false, new AsyncCallback<ArrayList<Plugin>>() {
public void onSuccess(ArrayList<Plugin> result) {
response.setData(buildRecords(result));
response.setTotalRows(result.size());
Expand Down

0 comments on commit a637f1e

Please sign in to comment.