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

Commit

Permalink
[BZ 1076104] Server plugins don't require explicit purge do disappear.
Browse files Browse the repository at this point in the history
  • Loading branch information
metlos committed Mar 27, 2014
1 parent 742bf8d commit 38941df
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 158 deletions.
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 ServerPluginTableView extends TableSection<ServerPluginDataSource>
private static final String FIELD_DEPLOYED = "deployed";
private static final String FIELD_VERSION = "version";

private boolean showUndeployed = false;

public ServerPluginTableView() {
super(null);
setHeight100();
Expand Down Expand Up @@ -116,7 +114,8 @@ public void onFailure(Throwable caught) {
caught);
refreshTableInfo();
}
});
}
);
}
});

Expand All @@ -143,10 +142,12 @@ public void onSuccess(ArrayList<String> result) {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(
MSG.view_admin_plugins_disabledServerPluginsFailure() + " "
+ caught.getMessage(), caught);
+ caught.getMessage(), caught
);
refreshTableInfo();
}
});
}
);
} else {
refreshTableInfo();
}
Expand All @@ -155,7 +156,7 @@ public void onFailure(Throwable caught) {
}
});

addTableAction(MSG.view_admin_plugins_undeploy(), new AuthorizedTableAction(this, TableActionEnablement.ANY,
addTableAction(MSG.common_button_delete(), new AuthorizedTableAction(this, TableActionEnablement.ANY,
Permission.MANAGE_SETTINGS) {
public void executeAction(final ListGridRecord[] selections, Object actionValue) {
ArrayList<String> selectedNames = getSelectedNames(selections);
Expand All @@ -164,7 +165,7 @@ public void executeAction(final ListGridRecord[] selections, Object actionValue)
public void execute(Boolean confirmed) {
if (confirmed) {
int[] selectedIds = getSelectedIds(selections);
GWTServiceLookup.getPluginService().undeployServerPlugins(selectedIds,
GWTServiceLookup.getPluginService().deleteServerPlugins(selectedIds,
new AsyncCallback<ArrayList<String>>() {
@Override
public void onSuccess(ArrayList<String> result) {
Expand All @@ -178,10 +179,12 @@ public void onSuccess(ArrayList<String> result) {
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(
MSG.view_admin_plugins_undeployedServerPluginsFailure() + " "
+ caught.getMessage(), caught);
+ caught.getMessage(), caught
);
refreshTableInfo();
}
});
}
);
} else {
refreshTableInfo();
}
Expand All @@ -190,40 +193,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 (showUndeployed) {
return super.isEnabled(selection);
} else {
return false; // we aren't showing undeployed 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().purgeServerPlugins(selectedIds,
new AsyncCallback<ArrayList<String>>() {
@Override
public void onSuccess(ArrayList<String> result) {
Message msg = new Message(MSG.view_admin_plugins_purgedServerPlugins(result.toString()),
Severity.Info);
CoreGUI.getMessageCenter().notify(msg);
refresh();
}

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

IButton scanForUpdatesButton = new EnhancedIButton(MSG.view_admin_plugins_scan());
scanForUpdatesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Expand Down Expand Up @@ -269,26 +238,10 @@ public void onFailure(Throwable caught) {
}
});

final IButton showUndeployedButton = new EnhancedIButton(MSG.view_admin_plugins_showUndeployed());
showUndeployedButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
showUndeployed = !showUndeployed;
if (showUndeployed) {
showUndeployedButton.setTitle(MSG.view_admin_plugins_hideUndeployed());
getListGrid().showField(FIELD_DEPLOYED);
} else {
showUndeployedButton.setTitle(MSG.view_admin_plugins_showUndeployed());
getListGrid().hideField(FIELD_DEPLOYED);
}
refresh();
}
});

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

addExtraWidget(scanForUpdatesButton, true);
addExtraWidget(restartMasterPCButton, true);
addExtraWidget(showUndeployedButton, true);
addExtraWidget(pluginUploadForm, true);

super.configureTable();
Expand Down Expand Up @@ -362,12 +315,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 @@ -377,15 +324,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().getServerPlugins(showUndeployed,
GWTServiceLookup.getPluginService().getServerPlugins(false,
new AsyncCallback<ArrayList<ServerPlugin>>() {
public void onSuccess(ArrayList<ServerPlugin> result) {
response.setData(buildRecords(result));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,8 @@ public interface PluginGWTService extends RemoteService {
* @param selectedPluginIds the IDs of the server plugins that are to be undeployed
* @return list of names of those server plugins that were undeployed
*/
ArrayList<String> undeployServerPlugins(int[] selectedPluginIds) throws RuntimeException;
ArrayList<String> deleteServerPlugins(int[] selectedPluginIds) throws RuntimeException;

/**
* Purges the undeployed server plugins from the system so there is no record of them to have
* ever existed. This deletes all remnants of the plugin from the database.
*
* @param selectedPluginIds the IDs of the undeployed server plugins that are to be purged
* @return list of names of those server plugins that were purged
*/
ArrayList<String> purgeServerPlugins(int[] selectedPluginIds) throws RuntimeException;

/**
* Returns the definition for the given plugin's global plugin configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public ArrayList<String> disableServerPlugins(int[] selectedPluginIds) throws Ru
}

@Override
public ArrayList<String> undeployServerPlugins(int[] selectedPluginIds) throws RuntimeException {
public ArrayList<String> deleteServerPlugins(int[] selectedPluginIds) throws RuntimeException {
try {
List<ServerPlugin> allSelectedPlugins = getSelectedServerPlugins(selectedPluginIds);
ArrayList<String> selectedPluginNames = new ArrayList<String>();
Expand All @@ -307,37 +307,14 @@ public ArrayList<String> undeployServerPlugins(int[] selectedPluginIds) throws R
return selectedPluginNames;
}

serverPluginManager.undeployServerPlugins(getSessionSubject(), getIds(pluginsToUndeploy));
serverPluginManager.deleteServerPlugins(getSessionSubject(), getIds(pluginsToUndeploy));
log.info("Undeployed server plugins: " + selectedPluginNames);
return selectedPluginNames;
} catch (Throwable t) {
throw getExceptionToThrowToClient(t);
}
}

@Override
public ArrayList<String> purgeServerPlugins(int[] selectedPluginIds) throws RuntimeException {
try {
List<ServerPlugin> allSelectedPlugins = getSelectedServerPlugins(selectedPluginIds);
ArrayList<String> selectedPluginNames = new ArrayList<String>();

for (ServerPlugin selectedPlugin : allSelectedPlugins) {
selectedPluginNames.add(selectedPlugin.getDisplayName());
}

if (selectedPluginNames.isEmpty()) {
log.debug("No server plugins were selected. Nothing to purge");
return selectedPluginNames;
}

serverPluginManager.purgeServerPlugins(getSessionSubject(), getIds(allSelectedPlugins));
log.info("Purged server plugins: " + selectedPluginNames);
return selectedPluginNames;
} catch (Throwable t) {
throw getExceptionToThrowToClient(t);
}
}

@Override
public ConfigurationDefinition getServerPluginConfigurationDefinition(PluginKey pluginKey) throws RuntimeException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public void undeployServerPlugins() {

try {
Subject subject = EnterpriseFacesContextUtility.getSubject();
serverPluginsBean.undeployServerPlugins(subject, getIds(pluginsToUndeploy));
serverPluginsBean.deleteServerPlugins(subject, getIds(pluginsToUndeploy));
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Undeployed server plugins: "
+ selectedPluginNames);
} catch (Exception e) {
Expand All @@ -351,8 +351,10 @@ public void purgeServerPlugins() {
}

try {
Subject subject = EnterpriseFacesContextUtility.getSubject();
serverPluginsBean.purgeServerPlugins(subject, getIds(allSelectedPlugins));
//The JSF UI is no longer used for server plugins, so I'm just commenting out the code
//that would not compile anymore...
//Subject subject = EnterpriseFacesContextUtility.getSubject();
//serverPluginsBean.purgeServerPlugins(subject, getIds(allSelectedPlugins));
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Purged server plugins: " + selectedPluginNames);
} catch (Exception e) {
processException("Failed to undeploy server plugins", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void testUndeployPlugins() throws Exception {
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
List<PluginKey> undeployed = this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
List<PluginKey> undeployed = this.serverPluginsBean.deleteServerPlugins(getOverlord(), ids);
assert undeployed.size() == 2 : undeployed;
assert undeployed.contains(p1key) : undeployed;
assert undeployed.contains(p2key) : undeployed;
Expand Down Expand Up @@ -284,7 +284,7 @@ public void testReRegisterPlugins() throws Exception {
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
List<PluginKey> undeployed = this.serverPluginsBean.undeployServerPlugins(getOverlord(), ids);
List<PluginKey> undeployed = this.serverPluginsBean.deleteServerPlugins(getOverlord(), ids);
assert undeployed.size() == 2 : undeployed;
assert undeployed.contains(p1key) : undeployed;
assert undeployed.contains(p2key) : undeployed;
Expand All @@ -305,8 +305,8 @@ public void testReRegisterPlugins() throws Exception {
assert !pluginKeys.contains(p2key) : pluginKeys;

// purge them completely from the DB to prepare to re-register them
this.serverPluginsBean.purgeServerPlugin(getOverlord(), p1key);
this.serverPluginsBean.purgeServerPlugin(getOverlord(), p2key);
this.serverPluginsBean.purgeServerPlugin(p1.getId());
this.serverPluginsBean.purgeServerPlugin(p2.getId());

// we just purged the database, make sure our entity ID's are all zero, since the original IDs are gone
p1.setId(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void testGetInstalledPlugins() throws Exception {
assert got_it == true;
} finally {
// make sure we clean this up, even on error
serverPluginsLocal.purgeServerPlugin(LookupUtil.getSubjectManager().getOverlord(), new PluginKey(plugin));
serverPluginsLocal.purgeServerPlugin(plugin.getId());
}

// test that purge really deleted it
Expand Down Expand Up @@ -210,4 +210,4 @@ private void deleteAllTestPluginJars() {
return;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.jetbrains.annotations.Nullable;

import org.rhq.core.domain.cloud.Server;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
Expand All @@ -51,6 +52,7 @@
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.cloud.instance.ServerManagerLocal;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
Expand Down Expand Up @@ -124,7 +126,7 @@ void registerServerPlugins() throws Exception {
try {
log.info("Plugin file [" + undeployedFile + "] has been undeployed. It will be deleted.");
List<Integer> id = Arrays.asList(undeployedPlugin.getId());
serverPluginsManager.undeployServerPlugins(LookupUtil.getSubjectManager().getOverlord(), id);
serverPluginsManager.deleteServerPlugins(LookupUtil.getSubjectManager().getOverlord(), id);
} finally {
this.serverPluginsOnFilesystem.remove(undeployedFile);
}
Expand Down Expand Up @@ -195,7 +197,12 @@ void serverPluginScan() throws Exception {
log.debug("Scan detected server plugin [" + updatedFile + "]...");
this.scanned.add(updatedFile);
}
return;

ServerPluginsLocal pluginMgr = LookupUtil.getServerPlugins();
ServerManagerLocal serverMgr = LookupUtil.getServerManager();
Server thisServer = serverMgr.getServer();

pluginMgr.acknowledgeDeletedPluginsBy(thisServer.getId());
}

/**
Expand Down

0 comments on commit 38941df

Please sign in to comment.