[rhq] Branch 'iptables' - modules/plugins
by fdrabek
modules/plugins/iptables/src/main/java/org/rhq/augeas/AugeasComponent.java | 211 +++--
modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfiguration.java | 37
modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java | 129 ++-
modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasModuleConfig.java | 170 ++--
modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNode.java | 76 +-
modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeLazy.java | 219 +++--
modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeParent.java | 123 +--
modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeReal.java | 267 +++----
modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasRootNode.java | 131 ++-
modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java | 235 +++---
modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTree.java | 54 +
modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeException.java | 35
modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeLazy.java | 335 ++++----
modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeReal.java | 380 +++++-----
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/AugeasRHQComponent.java | 31
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainComponent.java | 133 ++-
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainDiscoveryComponent.java | 68 +
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesComponent.java | 166 ++--
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesConfigTransform.java | 316 ++++----
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesDiscoveryComponent.java | 52 +
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableComponent.java | 104 +-
modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableDiscoveryComponent.java | 58 +
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasRhqException.java | 38 -
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasToConfiguration.java | 118 ---
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/ConfigurationToAugeas.java | 170 ----
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/NameMap.java | 36
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqAugeasMapping.java | 40 +
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqConfig.java | 109 +-
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqTransform.java | 25
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/AugeasToConfigurationSimple.java | 123 +++
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java | 197 +++++
modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/RhqAugeasMappingSimple.java | 76 ++
32 files changed, 2585 insertions(+), 1677 deletions(-)
New commits:
commit 930a72f007d665f731f41587a1f740a6674e31c4
Author: Filip Drabek <fdrabek(a)dhcp-lab-136.englab.brq.redhat.com>
Date: Mon Nov 30 13:28:25 2009 +0100
update
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/AugeasComponent.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/AugeasComponent.java
index 68464d2..d3a7d15 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/AugeasComponent.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/AugeasComponent.java
@@ -1,3 +1,25 @@
+/*
+ * 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.augeas;
import java.io.File;
@@ -14,26 +36,31 @@ import org.rhq.augeas.tree.AugeasTreeLazy;
import org.rhq.augeas.tree.AugeasTreeReal;
import org.rhq.augeas.util.Glob;
+/**
+ *
+ * @author Filip Drabek
+ * @author Ian Springer
+ *
+ */
public class AugeasComponent {
- private AugeasConfiguration config;
- private Augeas augeas;
- private List<String> modules;
+ private AugeasConfiguration config;
+ private Augeas augeas;
+ private List<String> modules;
- public AugeasComponent(AugeasConfiguration config){
- this.config = config;
- modules = new ArrayList<String>();
- }
-
- public void load() throws Exception
- {
+ public AugeasComponent(AugeasConfiguration config){
+ this.config = config;
+ modules = new ArrayList<String>();
+ }
+
+ public void load() throws Exception
+ {
augeas = new Augeas(config.getRootPath(), config.getLoadPath(), config.getMode());
for (AugeasModuleConfig module : config.getModules()){
-
- checkModule(module);
- modules.add(module.getModuletName());
- augeas.set("/augeas/load/" + module.getModuletName() + "/lens", module.getLensPath());
+ checkModule(module);
+ modules.add(module.getModuletName());
+ augeas.set("/augeas/load/" + module.getModuletName() + "/lens", module.getLensPath());
int idx = 1;
for (String incl : module.getIncludedGlobs()) {
@@ -45,88 +72,88 @@ public class AugeasComponent {
for (String excl : module.getExcludedGlobs()) {
augeas.set("/augeas/load/" + module.getModuletName() + "/excl[" + (idx++) + "]", excl);
}
-
+
}
- augeas.load();
- }
-
-
- private void checkModule(AugeasModuleConfig module) {
- File root = new File(config.getRootPath());
+ augeas.load();
+ }
+
- List<String> includeGlobs = module.getIncludedGlobs();
+ private void checkModule(AugeasModuleConfig module) {
+ File root = new File(config.getRootPath());
- if (includeGlobs.size()<=0) {
- throw new IllegalStateException("Expecting at least once inclusion pattern for configuration files.");
- }
+ List<String> includeGlobs = module.getIncludedGlobs();
- List<File> files = Glob.matchAll(root, includeGlobs);
+ if (includeGlobs.size()<=0) {
+ throw new IllegalStateException("Expecting at least once inclusion pattern for configuration files.");
+ }
- if (module.getExcludedGlobs()!=null)
- {
- List<String> excludeGlobs = module.getExcludedGlobs();
- Glob.excludeAll(files, excludeGlobs);
- }
-
- for (File configFile : files) {
- if (!configFile.isAbsolute()) {
- throw new IllegalStateException("Configuration files inclusion patterns contain a non-absolute file.");
- }
- if (!configFile.exists()) {
- throw new IllegalStateException("Configuration files inclusion patterns refer to a non-existent file.");
- }
- if (configFile.isDirectory()) {
- throw new IllegalStateException("Configuration files inclusion patterns refer to a directory.");
- }
- }
- }
-
- public AugeasTree getAugeasTree(String name,boolean lazy) throws AugeasTreeException
- {
- if (!modules.contains(name))
- throw new AugeasTreeException("Augeas Module "+ name +" not found.");
-
- try {
- if (augeas == null)
- load();
- }catch(Exception e){
- throw new AugeasTreeException("Loading of augeas failed");
- }
-
- AugeasModuleConfig module = null;
-
- for (AugeasModuleConfig conf : config.getModules())
- {
- if (conf.getModuletName().equals(name))
- {
- module = conf;
- break;
- }
- }
- AugeasTree tree;
-
- if (lazy==true)
- tree = new AugeasTreeLazy(augeas,module);
- else
- tree = new AugeasTreeReal(augeas,module);
+ List<File> files = Glob.matchAll(root, includeGlobs);
- return tree;
- }
-
- public String printTree(String path){
- StringBuilder builder = new StringBuilder();
- builder.append(path + " "+ augeas.get(path)+'\n');
- List<String> list = augeas.match(path+File.separatorChar+"*");
- for (String tempStr : list)
- {
- builder.append(printTree(tempStr));
- }
-
- return builder.toString();
- }
-
- public Augeas getAugeas()
- {
- return augeas;
- }
+ if (module.getExcludedGlobs()!=null)
+ {
+ List<String> excludeGlobs = module.getExcludedGlobs();
+ Glob.excludeAll(files, excludeGlobs);
+ }
+
+ for (File configFile : files) {
+ if (!configFile.isAbsolute()) {
+ throw new IllegalStateException("Configuration files inclusion patterns contain a non-absolute file.");
+ }
+ if (!configFile.exists()) {
+ throw new IllegalStateException("Configuration files inclusion patterns refer to a non-existent file.");
+ }
+ if (configFile.isDirectory()) {
+ throw new IllegalStateException("Configuration files inclusion patterns refer to a directory.");
+ }
+ }
+ }
+
+ public AugeasTree getAugeasTree(String name,boolean lazy) throws AugeasTreeException
+ {
+ if (!modules.contains(name))
+ throw new AugeasTreeException("Augeas Module "+ name +" not found.");
+
+ try {
+ if (augeas == null)
+ load();
+ }catch(Exception e){
+ throw new AugeasTreeException("Loading of augeas failed");
+ }
+
+ AugeasModuleConfig module = null;
+
+ for (AugeasModuleConfig conf : config.getModules())
+ {
+ if (conf.getModuletName().equals(name))
+ {
+ module = conf;
+ break;
+ }
+ }
+ AugeasTree tree;
+
+ if (lazy==true)
+ tree = new AugeasTreeLazy(augeas,module);
+ else
+ tree = new AugeasTreeReal(augeas,module);
+
+ return tree;
+ }
+
+ public String printTree(String path){
+ StringBuilder builder = new StringBuilder();
+ builder.append(path + " "+ augeas.get(path)+'\n');
+ List<String> list = augeas.match(path+File.separatorChar+"*");
+ for (String tempStr : list)
+ {
+ builder.append(printTree(tempStr));
+ }
+
+ return builder.toString();
+ }
+
+ public Augeas getAugeas()
+ {
+ return augeas;
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfiguration.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfiguration.java
index f3fd636..0bb7334 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfiguration.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfiguration.java
@@ -1,11 +1,38 @@
+/*
+ * 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.augeas.config;
import java.util.List;
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public interface AugeasConfiguration {
-
- public List<AugeasModuleConfig> getModules();
- public String getRootPath();
- public String getLoadPath();
- public int getMode();
+
+ public List<AugeasModuleConfig> getModules();
+ public String getRootPath();
+ public String getLoadPath();
+ public int getMode();
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java
index 1c487db..48bf732 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasConfigurationSimple.java
@@ -1,58 +1,85 @@
+/*
+ * 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.augeas.config;
import java.util.ArrayList;
import java.util.List;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasConfigurationSimple implements AugeasConfiguration{
+
+ private String loadPath;
+ private int mode;
+ private String rootPath;
+ private List<AugeasModuleConfig> modules;
+
+ public void setLoadPath(String loadPath) {
+ this.loadPath = loadPath;
+ }
+
+ public void setMode(int mode) {
+ this.mode = mode;
+ }
+
+ public void setRootPath(String rootPath) {
+ this.rootPath = rootPath;
+ }
+
+ public void setModules(List<AugeasModuleConfig> modules) {
+ this.modules = modules;
+ }
+
+ public AugeasConfigurationSimple()
+ {
+ modules = new ArrayList<AugeasModuleConfig>();
+ }
+
+ public String getLoadPath() {
+ return loadPath;
+ }
+
+
+ public int getMode() {
+ return mode;
+ }
+
+ public List<AugeasModuleConfig> getModules() {
+ return modules;
+ }
+
+
+ public String getRootPath() {
+ return rootPath;
+ }
- private String loadPath;
- private int mode;
- private String rootPath;
- private List<AugeasModuleConfig> modules;
-
- public void setLoadPath(String loadPath) {
- this.loadPath = loadPath;
- }
-
- public void setMode(int mode) {
- this.mode = mode;
- }
-
- public void setRootPath(String rootPath) {
- this.rootPath = rootPath;
- }
-
- public void setModules(List<AugeasModuleConfig> modules) {
- this.modules = modules;
- }
-
- public AugeasConfigurationSimple()
- {
- modules = new ArrayList<AugeasModuleConfig>();
- }
-
- public String getLoadPath() {
- return loadPath;
- }
-
-
- public int getMode() {
- return mode;
- }
-
- public List<AugeasModuleConfig> getModules() {
- return modules;
- }
-
-
- public String getRootPath() {
- return rootPath;
- }
-
- public void addModuleConfig(AugeasModuleConfig config)
- {
- if (modules.contains(config))
- return;
- modules.add(config);
- }
+ public void addModuleConfig(AugeasModuleConfig config)
+ {
+ if (modules.contains(config))
+ return;
+ modules.add(config);
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasModuleConfig.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasModuleConfig.java
index bdf0192..42be1a0 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasModuleConfig.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/config/AugeasModuleConfig.java
@@ -1,78 +1,102 @@
+/*
+ * 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.augeas.config;
import java.util.ArrayList;
import java.util.List;
-public class AugeasModuleConfig {
-
- private String moduletName;
- private String lensPath;
- private List<String> excludedGlobs;
- private List<String> includedGlobs;
-
- public AugeasModuleConfig(){
- excludedGlobs = new ArrayList<String>();
- includedGlobs = new ArrayList<String>();
- }
-
- public String getModuletName() {
- return moduletName;
- }
-
- public void setModuletName(String moduletName) {
- this.moduletName = moduletName;
- }
-
- public String getLensPath() {
- return lensPath;
- }
-
- public void setLensPath(String lensPath) {
- this.lensPath = lensPath;
- }
-
- public List<String> getExcludedGlobs() {
- return excludedGlobs;
- }
-
- public void setExcludedGlobs(List<String> excludedGlobs) {
- this.excludedGlobs = excludedGlobs;
- }
-
- public List<String> getIncludedGlobs() {
- return includedGlobs;
- }
-
- public void setIncludedGlobs(List<String> includedGlobs) {
- this.includedGlobs = includedGlobs;
- }
-
- public void addIncludedGlob(String name){
- if (!includedGlobs.contains(name))
- this.includedGlobs.add(name);
- }
-
- public void addExcludedGlob(String name){
- if (!excludedGlobs.contains(name))
- this.excludedGlobs.add(name);
- }
-
-
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null || getClass() != obj.getClass())
- return false;
-
- AugeasModuleConfig that = (AugeasModuleConfig) obj;
-
- if (!this.moduletName.equals(that.getModuletName()))
- return false;
-
- if (!this.lensPath.equals(that.getLensPath()))
- return false;
-
- return true;
- }
-
-}
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
+public class AugeasModuleConfig {
+
+ private String moduletName;
+ private String lensPath;
+ private List<String> excludedGlobs;
+ private List<String> includedGlobs;
+
+ public AugeasModuleConfig(){
+ excludedGlobs = new ArrayList<String>();
+ includedGlobs = new ArrayList<String>();
+ }
+
+ public String getModuletName() {
+ return moduletName;
+ }
+
+ public void setModuletName(String moduletName) {
+ this.moduletName = moduletName;
+ }
+
+ public String getLensPath() {
+ return lensPath;
+ }
+
+ public void setLensPath(String lensPath) {
+ this.lensPath = lensPath;
+ }
+
+ public List<String> getExcludedGlobs() {
+ return excludedGlobs;
+ }
+
+ public void setExcludedGlobs(List<String> excludedGlobs) {
+ this.excludedGlobs = excludedGlobs;
+ }
+
+ public List<String> getIncludedGlobs() {
+ return includedGlobs;
+ }
+
+ public void setIncludedGlobs(List<String> includedGlobs) {
+ this.includedGlobs = includedGlobs;
+ }
+
+ public void addIncludedGlob(String name){
+ if (!includedGlobs.contains(name))
+ this.includedGlobs.add(name);
+ }
+
+ public void addExcludedGlob(String name){
+ if (!excludedGlobs.contains(name))
+ this.excludedGlobs.add(name);
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null || getClass() != obj.getClass())
+ return false;
+ AugeasModuleConfig that = (AugeasModuleConfig) obj;
+ if (!this.moduletName.equals(that.getModuletName()))
+ return false;
+ if (!this.lensPath.equals(that.getLensPath()))
+ return false;
+
+ return true;
+ }
+
+}
\ No newline at end of file
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNode.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNode.java
index e620447..6ad60f7 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNode.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNode.java
@@ -1,40 +1,64 @@
+/*
+ * 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.augeas.node;
import java.util.List;
-
-import org.rhq.augeas.tree.AugeasTreeException;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public interface AugeasNode {
- public String getPath();
+ public String getPath();
- public void setPath(String path) throws Exception;
-
- public String getLabel() ;
+ public void setPath(String path) throws Exception;
+
+ public String getLabel() ;
- public void setLabel(String label);
+ public void setLabel(String label);
- public String getValue();
+ public String getValue();
- public void setValue(String value) ;
+ public void setValue(String value) ;
- public int getSeq();
+ public int getSeq();
- public void setSeq(int seq);
+ public void setSeq(int seq);
- public AugeasNode getParentNode();
+ public AugeasNode getParentNode();
- public List<AugeasNode> getChildNodes() ;
-
- public boolean equals(Object obj);
-
- public String getFullPath();
-
- public void addChildNode(AugeasNode node);
-
- public List<AugeasNode> getChildByLabel(String labelName);
-
- public void remove(boolean updateSeq) throws Exception;
-
- public void updateFromParent();
+ public List<AugeasNode> getChildNodes() ;
+
+ public boolean equals(Object obj);
+
+ public String getFullPath();
+
+ public void addChildNode(AugeasNode node);
+
+ public List<AugeasNode> getChildByLabel(String labelName);
+
+ public void remove(boolean updateSeq) throws Exception;
+
+ public void updateFromParent();
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeLazy.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeLazy.java
index 8a8dfc5..21b4941 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeLazy.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeLazy.java
@@ -1,3 +1,26 @@
+/*
+ * 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.augeas.node;
import java.io.File;
@@ -6,63 +29,67 @@ import java.util.List;
import org.rhq.augeas.tree.AugeasTree;
import org.rhq.augeas.tree.AugeasTreeException;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasNodeLazy extends AugeasNodeParent implements AugeasNode {
- public AugeasNodeLazy(String FullPath,AugeasTree ag)
- {
- super();
-
- this.ag = ag;
- this.path = FullPath.substring(0,FullPath.lastIndexOf(File.separatorChar)+1);
- String val = FullPath.substring(FullPath.lastIndexOf(File.separatorChar)+1,FullPath.length());
-
- int firstB = val.indexOf("[");
- if (firstB != -1){
- seq = Integer.valueOf(val.substring(firstB+1,val.indexOf(']')));
- label = val.substring(0,firstB);
- }
- else{
- seq = 0;
- label = FullPath.substring(FullPath.lastIndexOf(File.separatorChar)+1);
- }
- }
-
- public List<AugeasNode> getChildNodes() {
- List <AugeasNode> nodes = null;
- try {
-
- nodes = ag.match(getFullPath()+File.separatorChar+"*");
-
- }catch(AugeasTreeException e)
- {
- //TODO loggin
- e.printStackTrace();
- }
- return nodes;
- }
-
-
- public AugeasNode getParentNode(){
- String parentNodePath = path.substring(0,path.length()-1);
- if (parentNodePath.equals(ag.getRootNode().getFullPath()))
- return ag.getRootNode();
- try {
- parentNode = ag.getNode(parentNodePath);
- }catch(Exception e)
- {
- return null;
- }
-
- return parentNode;
- }
-
- public String getValue() {
- if (value == null)
- value = ag.get(getFullPath());
-
- return value;
- }
+ public AugeasNodeLazy(String FullPath,AugeasTree ag)
+ {
+ super();
+
+ this.ag = ag;
+ this.path = FullPath.substring(0,FullPath.lastIndexOf(File.separatorChar)+1);
+ String val = FullPath.substring(FullPath.lastIndexOf(File.separatorChar)+1,FullPath.length());
+
+ int firstB = val.indexOf("[");
+ if (firstB != -1){
+ seq = Integer.valueOf(val.substring(firstB+1,val.indexOf(']')));
+ label = val.substring(0,firstB);
+ }
+ else{
+ seq = 0;
+ label = FullPath.substring(FullPath.lastIndexOf(File.separatorChar)+1);
+ }
+ }
+
+ public List<AugeasNode> getChildNodes() {
+ List <AugeasNode> nodes = null;
+ try {
+
+ nodes = ag.match(getFullPath()+File.separatorChar+"*");
+
+ }catch(AugeasTreeException e)
+ {
+ //TODO loggin
+ e.printStackTrace();
+ }
+ return nodes;
+ }
+
+
+ public AugeasNode getParentNode(){
+ String parentNodePath = path.substring(0,path.length()-1);
+ if (parentNodePath.equals(ag.getRootNode().getFullPath()))
+ return ag.getRootNode();
+ try {
+ parentNode = ag.getNode(parentNodePath);
+ }catch(Exception e)
+ {
+ return null;
+ }
+
+ return parentNode;
+ }
+
+ public String getValue() {
+ if (value == null)
+ value = ag.get(getFullPath());
+
+ return value;
+ }
public boolean equals(Object obj) {
if (this == obj)
@@ -73,51 +100,51 @@ public class AugeasNodeLazy extends AugeasNodeParent implements AugeasNode {
AugeasNode that = (AugeasNode) obj;
if (!this.getFullPath().equals(that.getFullPath()))
- return false;
+ return false;
return true;
}
public void setValue(String value){
- ag.setValue(this, value);
+ ag.setValue(this, value);
}
-
- public String getFullPath() {
- return path + label + (seq !=0 ? "["+String.valueOf(seq)+"]" : "" );
- }
-
-
- public void addChildNode(AugeasNode node) {
- //TODO kontrola jestli sem patri
- childNodes.add(node);
- }
-
-
- public List<AugeasNode> getChildByLabel(String labelName){
- List<AugeasNode> nodes = getChildNodes();
- List<AugeasNode> tempNode = new ArrayList<AugeasNode>();
-
- for (AugeasNode node : nodes){
- if (node.getLabel().equals(labelName))
- tempNode.add(node);
- }
- return tempNode;
- }
-
- public void remove(boolean updateSeq) throws Exception
- {
- ag.removeNode(this,updateSeq);
- }
-
- public void setPath(String path) throws Exception{
- this.path = path;
-
- }
-
- public void updateFromParent() {
- AugeasNode node = this.getParentNode();
- if (!this.path.equals(node.getFullPath())){
- this.path = node.getFullPath();
- }
- }
+
+ public String getFullPath() {
+ return path + label + (seq !=0 ? "["+String.valueOf(seq)+"]" : "" );
+ }
+
+
+ public void addChildNode(AugeasNode node) {
+ //TODO kontrola jestli sem patri
+ childNodes.add(node);
+ }
+
+
+ public List<AugeasNode> getChildByLabel(String labelName){
+ List<AugeasNode> nodes = getChildNodes();
+ List<AugeasNode> tempNode = new ArrayList<AugeasNode>();
+
+ for (AugeasNode node : nodes){
+ if (node.getLabel().equals(labelName))
+ tempNode.add(node);
+ }
+ return tempNode;
+ }
+
+ public void remove(boolean updateSeq) throws Exception
+ {
+ ag.removeNode(this,updateSeq);
+ }
+
+ public void setPath(String path) throws Exception{
+ this.path = path;
+
+ }
+
+ public void updateFromParent() {
+ AugeasNode node = this.getParentNode();
+ if (!this.path.equals(node.getFullPath())){
+ this.path = node.getFullPath();
+ }
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeParent.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeParent.java
index 4016a28..ed6e646 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeParent.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeParent.java
@@ -1,56 +1,83 @@
+/*
+ * 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.augeas.node;
import java.util.ArrayList;
import java.util.List;
import org.rhq.augeas.tree.AugeasTree;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasNodeParent {
-
- protected String path;
- protected String label;
- protected String value;
- protected AugeasTree ag;
- protected int seq;
- protected AugeasNode parentNode;
- protected List<AugeasNode> childNodes;
-
- public AugeasNodeParent(){
- childNodes = new ArrayList<AugeasNode>();
- }
- public String getPath() {
- return path;
- }
-
- public String getLabel() {
- return label;
- }
-
- public void setLabel(String label) {
- this.label = label;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public int getSeq() {
- return seq;
- }
-
- public void setSeq(int seq) {
- this.seq = seq;
- }
-
- public AugeasNode getParentNode() {
- return parentNode;
- }
-
- public List<AugeasNode> getChildNodes() {
- return childNodes;
- }
+
+ protected String path;
+ protected String label;
+ protected String value;
+ protected AugeasTree ag;
+ protected int seq;
+ protected AugeasNode parentNode;
+ protected List<AugeasNode> childNodes;
+
+ public AugeasNodeParent(){
+ childNodes = new ArrayList<AugeasNode>();
+ }
+ public String getPath() {
+ return path;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public int getSeq() {
+ return seq;
+ }
+
+ public void setSeq(int seq) {
+ this.seq = seq;
+ }
+
+ public AugeasNode getParentNode() {
+ return parentNode;
+ }
+
+ public List<AugeasNode> getChildNodes() {
+ return childNodes;
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeReal.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeReal.java
index 7ccc56c..68eb968 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeReal.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasNodeReal.java
@@ -1,137 +1,164 @@
+/*
+ * 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.augeas.node;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.rhq.augeas.tree.AugeasTree;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasNodeReal extends AugeasNodeParent implements AugeasNode{
- public AugeasNodeReal()
- {
- super();
- }
-
- public AugeasNodeReal(AugeasNode parentNode,AugeasTree tree,String label,int seq)
- {
- super();
- ag = tree;
- this.parentNode = parentNode;
- path = parentNode.getPath()+ File.separatorChar + parentNode.getLabel() + File.separatorChar;
- this.seq = seq;
- }
-
- public AugeasNodeReal(AugeasNode parentNode,AugeasTree ag,String fullPath)
- {
- super();
- this.parentNode = parentNode;
- if (fullPath == null)
- return ;
-
- this.path = fullPath.substring(0,fullPath.lastIndexOf(File.separatorChar)+1);
- String val = fullPath.substring(fullPath.lastIndexOf(File.separatorChar)+1,fullPath.length());
-
- int firstB = val.indexOf("[");
-
- if (firstB != -1){
- seq = Integer.valueOf(val.substring(firstB+1,val.indexOf(']')));
- label = val.substring(0,firstB);
- }
- else{
- seq = 0;
- label = fullPath.substring(fullPath.lastIndexOf(File.separatorChar)+1);
- }
- }
-
- public AugeasNodeReal(String path,String label,int seq,String value)
- {
- childNodes = new ArrayList<AugeasNode>();
-
- if (path == null)
- return ;
-
- this.path = path;
- this.value = value;
- this.label = label;
- this.seq = seq;
- }
+ public AugeasNodeReal()
+ {
+ super();
+ }
+
+ public AugeasNodeReal(AugeasNode parentNode,AugeasTree tree,String label,int seq)
+ {
+ super();
+ ag = tree;
+ this.parentNode = parentNode;
+ path = parentNode.getPath()+ File.separatorChar + parentNode.getLabel() + File.separatorChar;
+ this.seq = seq;
+ }
+
+ public AugeasNodeReal(AugeasNode parentNode,AugeasTree ag,String fullPath)
+ {
+ super();
+ this.parentNode = parentNode;
+ if (fullPath == null)
+ return ;
+
+ this.path = fullPath.substring(0,fullPath.lastIndexOf(File.separatorChar)+1);
+ String val = fullPath.substring(fullPath.lastIndexOf(File.separatorChar)+1,fullPath.length());
+
+ int firstB = val.indexOf("[");
+
+ if (firstB != -1){
+ seq = Integer.valueOf(val.substring(firstB+1,val.indexOf(']')));
+ label = val.substring(0,firstB);
+ }
+ else{
+ seq = 0;
+ label = fullPath.substring(fullPath.lastIndexOf(File.separatorChar)+1);
+ }
+ }
+
+ public AugeasNodeReal(String path,String label,int seq,String value)
+ {
+ childNodes = new ArrayList<AugeasNode>();
+
+ if (path == null)
+ return ;
+
+ this.path = path;
+ this.value = value;
+ this.label = label;
+ this.seq = seq;
+ }
-
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null || getClass() != obj.getClass())
- return false;
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null || getClass() != obj.getClass())
+ return false;
- AugeasNode that = (AugeasNode) obj;
+ AugeasNode that = (AugeasNode) obj;
- if (!this.getFullPath().equals(that.getFullPath()))
- return false;
+ if (!this.getFullPath().equals(that.getFullPath()))
+ return false;
- return true;
- }
+ return true;
+ }
-
- public String getFullPath() {
- return path + label + (seq !=0 ? "["+String.valueOf(seq)+"]" : "" );
- }
-
- public void addChildNode(AugeasNode node) {
- //TODO kontrola jestli sem patri
- childNodes.add(node);
- }
-
- public List<AugeasNode> getChildByLabel(String labelName){
- List<AugeasNode> nodes = getChildNodes();
- List<AugeasNode> tempNode = new ArrayList<AugeasNode>();
+
+ public String getFullPath() {
+ return path + label + (seq !=0 ? "["+String.valueOf(seq)+"]" : "" );
+ }
+
+ public void addChildNode(AugeasNode node) {
+ //TODO kontrola jestli sem patri
+ childNodes.add(node);
+ }
+
+ public List<AugeasNode> getChildByLabel(String labelName){
+ List<AugeasNode> nodes = getChildNodes();
+ List<AugeasNode> tempNode = new ArrayList<AugeasNode>();
- for (AugeasNode node : nodes){
- if (node.getLabel().equals(labelName))
- tempNode.add(node);
- }
- return tempNode;
- }
-
- public void remove(boolean updateSeq) throws Exception
- {
- ag.removeNode(this,updateSeq);
- }
+ for (AugeasNode node : nodes){
+ if (node.getLabel().equals(labelName))
+ tempNode.add(node);
+ }
+ return tempNode;
+ }
+
+ public void remove(boolean updateSeq) throws Exception
+ {
+ ag.removeNode(this,updateSeq);
+ }
- public void setPath(String path) throws Exception{
- int end;
- if (path.lastIndexOf(File.separatorChar) == path.length())
- {
- end = path.length()-1;
- this.path = path.substring(0,path.length()-1);
- }
- else
- {
- end = path.length();
- this.path = path;
- }
-
- AugeasNode parentNode = ag.getNode(path.substring(0,end));
- List<AugeasNode> nodes = parentNode.getChildByLabel(this.label);
- if (!nodes.isEmpty()){
- int indexes = nodes.size();
- this.setSeq(indexes+1);
- }
- parentNode.addChildNode(this);
- for (AugeasNode nd : this.getChildNodes())
- {
- nd.updateFromParent();
- }
- }
+ public void setPath(String path) throws Exception{
+ int end;
+ if (path.lastIndexOf(File.separatorChar) == path.length())
+ {
+ end = path.length()-1;
+ this.path = path.substring(0,path.length()-1);
+ }
+ else
+ {
+ end = path.length();
+ this.path = path;
+ }
+
+ AugeasNode parentNode = ag.getNode(path.substring(0,end));
+ List<AugeasNode> nodes = parentNode.getChildByLabel(this.label);
+ if (!nodes.isEmpty()){
+ int indexes = nodes.size();
+ this.setSeq(indexes+1);
+ }
+ parentNode.addChildNode(this);
+ for (AugeasNode nd : this.getChildNodes())
+ {
+ nd.updateFromParent();
+ }
+ }
- public void updateFromParent() {
- AugeasNode node = this.getParentNode();
- if (!this.path.equals(node.getFullPath())){
- this.path = node.getFullPath();
- }
-
- for (AugeasNode nd : this.getChildNodes())
- {
- nd.updateFromParent();
- }
- }
+ public void updateFromParent() {
+ AugeasNode node = this.getParentNode();
+ if (!this.path.equals(node.getFullPath())){
+ this.path = node.getFullPath();
+ }
+
+ for (AugeasNode nd : this.getChildNodes())
+ {
+ nd.updateFromParent();
+ }
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasRootNode.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasRootNode.java
index 908bdf5..f7d5a70 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasRootNode.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/node/AugeasRootNode.java
@@ -1,72 +1,99 @@
+/*
+ * 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.augeas.node;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasRootNode extends AugeasNodeParent implements AugeasNode{
-
- public AugeasRootNode(List<AugeasNode> nodes){
- super();
- childNodes=nodes;
- }
-
- public AugeasRootNode(){
- super();
- }
-
- public void addChildNode(AugeasNode node) {
- childNodes.add(node);
- }
+
+ public AugeasRootNode(List<AugeasNode> nodes){
+ super();
+ childNodes=nodes;
+ }
+
+ public AugeasRootNode(){
+ super();
+ }
+
+ public void addChildNode(AugeasNode node) {
+ childNodes.add(node);
+ }
-
- public List<AugeasNode> getChildNodes() {
- return childNodes;
- }
+
+ public List<AugeasNode> getChildNodes() {
+ return childNodes;
+ }
- public String getFullPath() {
- return ""+File.pathSeparatorChar;
- }
+ public String getFullPath() {
+ return ""+File.pathSeparatorChar;
+ }
- public String getLabel() {
- return null;
- }
+ public String getLabel() {
+ return null;
+ }
- public AugeasNode getParentNode() {
- return null;
- }
+ public AugeasNode getParentNode() {
+ return null;
+ }
- public String getPath() {
- return File.separator;
- }
-
- public List<AugeasNode> getChildByLabel(String labelName) {
- List<AugeasNode> nodes = getChildNodes();
- List<AugeasNode> tempNode = new ArrayList<AugeasNode>();
+ public String getPath() {
+ return File.separator;
+ }
+
+ public List<AugeasNode> getChildByLabel(String labelName) {
+ List<AugeasNode> nodes = getChildNodes();
+ List<AugeasNode> tempNode = new ArrayList<AugeasNode>();
- for (AugeasNode node : nodes){
- if (node.getLabel().equals(labelName))
- tempNode.add(node);
- }
- return tempNode;
+ for (AugeasNode node : nodes){
+ if (node.getLabel().equals(labelName))
+ tempNode.add(node);
+ }
+ return tempNode;
}
-
- public void remove(boolean updateSeq) throws Exception
- {
- throw new Exception("Root node is virtual and can not be removed. If you want to remove data remove all child nodes.");
- }
+
+ public void remove(boolean updateSeq) throws Exception
+ {
+ throw new Exception("Root node is virtual and can not be removed. If you want to remove data remove all child nodes.");
+ }
- public void setPath(String path) throws Exception{
- // TODO Auto-generated method stub
-
- }
+ public void setPath(String path) throws Exception{
+ // TODO Auto-generated method stub
+
+ }
- public void updateFromParent() {
- // TODO Auto-generated method stub
-
- }
+ public void updateFromParent() {
+ // TODO Auto-generated method stub
+
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
index b96bf70..d2aeb44 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasNodeBuffer.java
@@ -1,3 +1,26 @@
+/*
+ * 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.augeas.tree;
import java.io.File;
@@ -7,113 +30,117 @@ import java.util.List;
import java.util.Map;
import org.rhq.augeas.node.AugeasNode;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasNodeBuffer {
- private Map<String,AugeasNode> buffer;
-
- public AugeasNodeBuffer()
- {
- buffer = new HashMap<String,AugeasNode>();
- }
-
- public boolean isNodeLoaded(String name){
- return buffer.containsKey(name);
- }
-
- public AugeasNode getNode(String name){
- return buffer.get(name);
- }
-
- public void addNode(AugeasNode node){
- if (!isNodeLoaded(node.getFullPath()))
- buffer.put(node.getFullPath(), node);
- }
-
- public void removeNode(AugeasNode node,boolean updateSeq,boolean lazy)
- {
- if (buffer.containsKey(node.getFullPath()))
- buffer.remove(node.getFullPath());
-
- if (updateSeq)
- if (lazy)
- reloadLazy(node);
- else
- reload(node);
- }
-
- public void reload(AugeasNode nodes)
- {
- for (String key : buffer.keySet()){
- AugeasNode nd = buffer.get(key);
- if (!key.equals(nd.getFullPath()))
- {
- buffer.remove(key);
- buffer.put(nd.getFullPath(), nd);
- }
- }
+ private Map<String,AugeasNode> buffer;
+
+ public AugeasNodeBuffer()
+ {
+ buffer = new HashMap<String,AugeasNode>();
+ }
+
+ public boolean isNodeLoaded(String name){
+ return buffer.containsKey(name);
+ }
+
+ public AugeasNode getNode(String name){
+ return buffer.get(name);
+ }
+
+ public void addNode(AugeasNode node){
+ if (!isNodeLoaded(node.getFullPath()))
+ buffer.put(node.getFullPath(), node);
+ }
+
+ public void removeNode(AugeasNode node,boolean updateSeq,boolean lazy)
+ {
+ if (buffer.containsKey(node.getFullPath()))
+ buffer.remove(node.getFullPath());
+
+ if (updateSeq)
+ if (lazy)
+ reloadLazy(node);
+ else
+ reload(node);
+ }
+
+ public void reload(AugeasNode nodes)
+ {
+ for (String key : buffer.keySet()){
+ AugeasNode nd = buffer.get(key);
+ if (!key.equals(nd.getFullPath()))
+ {
+ buffer.remove(key);
+ buffer.put(nd.getFullPath(), nd);
+ }
+ }
}
-
- public void reloadLazy(AugeasNode node){
- Map<String,String> nodesToChange = new HashMap<String,String>();
- List<String> nodesToChangeSeq = new ArrayList<String>();
-
- AugeasNode parentNode = node.getParentNode();
- for (String key : buffer.keySet()){
-
- int index = key.indexOf(parentNode.getFullPath());
- if ((index==0) & (key.length()>parentNode.getFullPath().length())){
- String localPath = key.substring(parentNode.getFullPath().length());
- int endOfLabel = localPath.indexOf(File.separatorChar);
- String label;
+
+ public void reloadLazy(AugeasNode node){
+ Map<String,String> nodesToChange = new HashMap<String,String>();
+ List<String> nodesToChangeSeq = new ArrayList<String>();
+
+ AugeasNode parentNode = node.getParentNode();
+ for (String key : buffer.keySet()){
+
+ int index = key.indexOf(parentNode.getFullPath());
+ if ((index==0) & (key.length()>parentNode.getFullPath().length())){
+ String localPath = key.substring(parentNode.getFullPath().length());
+ int endOfLabel = localPath.indexOf(File.separatorChar);
+ String label;
String restOfPath;
- if (endOfLabel!=-1){
- label = localPath.substring(0,endOfLabel);
- restOfPath = localPath.substring(endOfLabel+1,localPath.length()-1);
- }
- else{
- label = localPath.substring(0,localPath.length()-1);
- restOfPath = "";
- }
- int startOfSeq = label.indexOf('[');
- if (startOfSeq !=-1){
- String labelName = label.substring(0,startOfSeq);
- if (labelName.equals(node.getLabel())){
- int endOfSeq = label.indexOf(']');
- String seqNr = label.substring(startOfSeq,endOfSeq-1);
- int seq = Integer.valueOf(seqNr).intValue();
- if (seq>node.getSeq())
- {
- if (restOfPath.equals(""))
- nodesToChangeSeq.add(key);
- else{
- String newPath = parentNode.getFullPath()+File.separator + labelName+
- "[" + String.valueOf(seq-1)+"]"+(restOfPath.equals("") ? File.separator+ restOfPath : "");
-
- nodesToChange.put(key, newPath);}
- }
- }
- }
- }
-
- }
-
- try {
-
- for (String key : nodesToChange.keySet()){
- AugeasNode nd = buffer.get(key);
- nd.setPath((String)nodesToChange.get(key));
- }
-
- for (String key : nodesToChangeSeq){
- AugeasNode nd = buffer.get(key);
- nd.setSeq(nd.getSeq()-1);
- }
-
- }catch(Exception e){
- //Exception is not thrown here because this method is called only for AugeasNodeLazy
- }
- }
-
+ if (endOfLabel!=-1){
+ label = localPath.substring(0,endOfLabel);
+ restOfPath = localPath.substring(endOfLabel+1,localPath.length()-1);
+ }
+ else{
+ label = localPath.substring(0,localPath.length()-1);
+ restOfPath = "";
+ }
+ int startOfSeq = label.indexOf('[');
+ if (startOfSeq !=-1){
+ String labelName = label.substring(0,startOfSeq);
+ if (labelName.equals(node.getLabel())){
+ int endOfSeq = label.indexOf(']');
+ String seqNr = label.substring(startOfSeq,endOfSeq-1);
+ int seq = Integer.valueOf(seqNr).intValue();
+ if (seq>node.getSeq())
+ {
+ if (restOfPath.equals(""))
+ nodesToChangeSeq.add(key);
+ else{
+ String newPath = parentNode.getFullPath()+File.separator + labelName+
+ "[" + String.valueOf(seq-1)+"]"+(restOfPath.equals("") ? File.separator+ restOfPath : "");
+
+ nodesToChange.put(key, newPath);}
+ }
+ }
+ }
+ }
+
+ }
+
+ try {
+
+ for (String key : nodesToChange.keySet()){
+ AugeasNode nd = buffer.get(key);
+ nd.setPath((String)nodesToChange.get(key));
+ }
+
+ for (String key : nodesToChangeSeq){
+ AugeasNode nd = buffer.get(key);
+ nd.setSeq(nd.getSeq()-1);
+ }
+
+ }catch(Exception e){
+ //Exception is not thrown here because this method is called only for AugeasNodeLazy
+ }
+ }
+
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTree.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTree.java
index ad89c3a..e7f7a3f 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTree.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTree.java
@@ -1,20 +1,48 @@
+/*
+ * 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.augeas.tree;
import java.util.List;
import org.rhq.augeas.node.AugeasNode;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public interface AugeasTree {
- public void load() throws AugeasTreeException;
- public void update();
- public void save();
- public AugeasNode getNode(String path) throws AugeasTreeException;
- public List<AugeasNode> match(String expression) throws AugeasTreeException;
- public List<AugeasNode> matchRelative(AugeasNode node,String expression) throws AugeasTreeException;
- public AugeasNode createNode(String fullPath) throws AugeasTreeException;
- public AugeasNode createNode(AugeasNode parentNode,String value,int seq);
- public String get(String expr);
- public AugeasNode getRootNode();
- public void removeNode(AugeasNode node,boolean updateSeq) throws Exception;
- public void setValue(AugeasNode node,String value);
+ public void load() throws AugeasTreeException;
+ public void update();
+ public void save();
+ public AugeasNode getNode(String path) throws AugeasTreeException;
+ public List<AugeasNode> match(String expression) throws AugeasTreeException;
+ public List<AugeasNode> matchRelative(AugeasNode node,String expression) throws AugeasTreeException;
+ public AugeasNode createNode(String fullPath) throws AugeasTreeException;
+ public AugeasNode createNode(AugeasNode parentNode,String name ,String value,int seq)throws AugeasTreeException;
+ public String get(String expr);
+ public AugeasNode getRootNode();
+ public void removeNode(AugeasNode node,boolean updateSeq) throws Exception;
+ public void setValue(AugeasNode node,String value);
+ public String summarizeAugeasError();
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeException.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeException.java
index 82cd4e5..978103a 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeException.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeException.java
@@ -1,8 +1,35 @@
-package org.rhq.augeas.tree;
+/*
+ * 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.augeas.tree;
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasTreeException extends Exception{
- public AugeasTreeException(String msg){
- super(msg);
- }
+ public AugeasTreeException(String msg){
+ super(msg);
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeLazy.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeLazy.java
index 903fd48..283d8b7 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeLazy.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeLazy.java
@@ -1,3 +1,26 @@
+/*
+ * 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.augeas.tree;
import java.io.File;
@@ -10,158 +33,170 @@ import org.rhq.augeas.config.AugeasModuleConfig;
import org.rhq.augeas.node.AugeasNode;
import org.rhq.augeas.node.AugeasNodeLazy;
import org.rhq.augeas.node.AugeasRootNode;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasTreeLazy implements AugeasTree{
- private AugeasModuleConfig moduleConfig;
- private Augeas ag;
- private AugeasNode rootNode;
- private AugeasNode rootConfigNode;
- private AugeasNodeBuffer nodeBuffer;
-
- private static String AUGEAS_DATA_PATH=File.separatorChar+"files";
-
- public AugeasTreeLazy(Augeas ag ,AugeasModuleConfig moduleConfig)
- {
- rootNode = new AugeasRootNode();
- nodeBuffer = new AugeasNodeBuffer();
- this.moduleConfig = moduleConfig;
- this.ag = ag;
- }
-
- public void load() throws AugeasTreeException
- {
- buildTree();
- }
-
- public void update()
- {
-
- }
-
- public void save()
- {
- ag.save();
- }
-
-
- private AugeasNode getLoadedNode(String path) throws AugeasTreeException
- {
- if (nodeBuffer.isNodeLoaded(path))
- return nodeBuffer.getNode(path);
-
- throw new AugeasTreeException("Node not found.");
- }
-
- public AugeasNode getNode(String path) throws AugeasTreeException
- {
- AugeasNode node;
- try {
- node = getLoadedNode(path);
- }catch(AugeasTreeException e)
- {
- node = createNode(path);
- }
-
- return node;
- }
-
- public List<AugeasNode> match(String expression) throws AugeasTreeException
- {
- List<String> res = ag.match(expression);
+ private AugeasModuleConfig moduleConfig;
+ private Augeas ag;
+ private AugeasNode rootNode;
+ private AugeasNode rootConfigNode;
+ private AugeasNodeBuffer nodeBuffer;
+ private String [] errorNodes = {"pos","line","char","lens","message"};
+ private static String AUGEAS_DATA_PATH=File.separatorChar+"files";
+
+ public AugeasTreeLazy(Augeas ag ,AugeasModuleConfig moduleConfig)
+ {
+ rootNode = new AugeasRootNode();
+ nodeBuffer = new AugeasNodeBuffer();
+ this.moduleConfig = moduleConfig;
+ this.ag = ag;
+ }
+
+ public void load() throws AugeasTreeException
+ {
+ buildTree();
+ }
+
+ public void update()
+ {
+
+ }
+
+ public void save()
+ {
+ ag.save();
+ }
+
+
+ private AugeasNode getLoadedNode(String path) throws AugeasTreeException
+ {
+ if (nodeBuffer.isNodeLoaded(path))
+ return nodeBuffer.getNode(path);
+
+ throw new AugeasTreeException("Node not found.");
+ }
+
+ public AugeasNode getNode(String path) throws AugeasTreeException
+ {
+ AugeasNode node;
+ try {
+ node = getLoadedNode(path);
+ }catch(AugeasTreeException e)
+ {
+ node = createNode(path);
+ }
+
+ return node;
+ }
+
+ public List<AugeasNode> match(String expression) throws AugeasTreeException
+ {
+ List<String> res = ag.match(expression);
- List<AugeasNode> nodes = new ArrayList<AugeasNode>();
-
- for (String name:res){
- nodes.add(getNode(name));
- }
-
- return nodes;
- }
-
- public List<AugeasNode> matchRelative(AugeasNode node,String expression) throws AugeasTreeException
- {
- if (rootNode.getChildNodes().isEmpty())
- throw new AugeasTreeException("Root node has not childs.");
-
- if (node.equals(rootNode)){
- List<AugeasNode> nodes = rootNode.getChildNodes();
- List<AugeasNode> returnNodes = new ArrayList<AugeasNode>();
- for (AugeasNode nd :nodes)
- {
- String tempName = nd.getFullPath()+expression;
- List<AugeasNode> temp = match(tempName);
- returnNodes.addAll(temp);
- }
- return returnNodes;
- }
-
- return match(node.getFullPath()+File.separatorChar+expression);
- }
-
- public AugeasNode createNode(String fullPath) throws AugeasTreeException
- {
- AugeasNode node=null;
-
- ag.set(fullPath, null);
- node = new AugeasNodeLazy(fullPath,this);
- nodeBuffer.addNode(node);
- return node;
- }
-
- public AugeasNode createNode(AugeasNode parentNode,String value,int seq)
- {
- return null;
- }
-
- public String get(String expr)
- {
- return ag.get(expr);
- }
-
- public AugeasNode getRootNode(){
- return rootNode;
- }
-
- private void buildTree() throws AugeasTreeException
- {
- rootConfigNode = createNode("/augeas");
-
- for (String name : moduleConfig.getIncludedGlobs())
- {
- rootNode.addChildNode(createNode(AUGEAS_DATA_PATH+File.separatorChar+name));
- }
- }
-
- public void removeNode(AugeasNode node,boolean updateSeq) throws Exception
- {
- int res = ag.remove(node.getFullPath());
- nodeBuffer.removeNode(node,updateSeq,true);
-
+ List<AugeasNode> nodes = new ArrayList<AugeasNode>();
+
+ for (String name:res){
+ nodes.add(getNode(name));
+ }
+
+ return nodes;
+ }
+
+ public List<AugeasNode> matchRelative(AugeasNode node,String expression) throws AugeasTreeException
+ {
+ if (rootNode.getChildNodes().isEmpty())
+ throw new AugeasTreeException("Root node has not childs.");
+
+ if (node.equals(rootNode)){
+ List<AugeasNode> nodes = rootNode.getChildNodes();
+ List<AugeasNode> returnNodes = new ArrayList<AugeasNode>();
+ for (AugeasNode nd :nodes)
+ {
+ String tempName = nd.getFullPath()+expression;
+ List<AugeasNode> temp = match(tempName);
+ returnNodes.addAll(temp);
+ }
+ return returnNodes;
+ }
+
+ return match(node.getFullPath()+File.separatorChar+expression);
+ }
+
+ public AugeasNode createNode(String fullPath) throws AugeasTreeException
+ {
+ AugeasNode node=null;
+
+ ag.set(fullPath, null);
+ node = new AugeasNodeLazy(fullPath,this);
+ nodeBuffer.addNode(node);
+ return node;
+ }
+
+ public AugeasNode createNode(AugeasNode parentNode,String name,String value,int seq) throws AugeasTreeException
+ {
+ AugeasNode nd = createNode(parentNode.getFullPath()+File.separatorChar+name+"["+String.valueOf(seq)+"]");
+ nd.setValue(value);
+
+ return nd;
+ }
+
+ public String get(String expr)
+ {
+ return ag.get(expr);
+ }
+
+ public AugeasNode getRootNode(){
+ return rootNode;
+ }
+
+ private void buildTree() throws AugeasTreeException
+ {
+ rootConfigNode = createNode("/augeas");
+
+ for (String name : moduleConfig.getIncludedGlobs())
+ {
+ rootNode.addChildNode(createNode(AUGEAS_DATA_PATH+File.separatorChar+name));
+ }
+ }
+
+ public void removeNode(AugeasNode node,boolean updateSeq) throws Exception
+ {
+ int res = ag.remove(node.getFullPath());
+ nodeBuffer.removeNode(node,updateSeq,true);
+
}
-
- public void setValue(AugeasNode node,String value)
- {
- ag.set(node.getFullPath(), value);
- }
- /*
- protected String summarizeAugeasError(Augeas augeas) {
- StringBuilder summary = new StringBuilder();
- String metadataNodePrefix = "/augeas/files";
- for (String glob : moduleConfig.getIncludedGlobs()) {
- if (glob.startsWith(""+File.separatorChar)) {
- glob = glob.substring(1);
- }
- AugeasNode metadataNode = new AugeasNodeLazy();
- AugeasNode errorNode = new AugeasNode(metadataNode, "error");
- List<String> nodePaths = augeas.match(errorNode.getPath() + "/*");
- for (String path : nodePaths) {
- String error = augeas.get(path);
- summary.append("File \"").append(path.substring(metadataNodePrefix.length(), path.length())).append(
- "\":\n").append(error).append("\n");
- }
- }
+
+ public void setValue(AugeasNode node,String value)
+ {
+ ag.set(node.getFullPath(), value);
+ }
+
+ public String summarizeAugeasError() {
+
+ String nodePrefix = "/augeas/files";
+ List<String> str = moduleConfig.getIncludedGlobs();
+ StringBuilder builder = new StringBuilder();
+
+ for (String path : str) {
+ String name = nodePrefix + path+File.separatorChar+"error";
+ if (ag.exists(name))
+ {
+ builder.append("Error "+ag.get(name)+'\n');
+ for (String errNd : errorNodes)
+ {
+ String pathToMessage = name+File.separatorChar+errNd;
+ if (ag.exists(pathToMessage))
+ {
+ builder.append(errNd + " "+ag.get(pathToMessage)+'\n');
+ }
+ }
+ }
+ }
+
+ return builder.toString();
+ }
- return summary.toString();
- }
-*/
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeReal.java b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeReal.java
index 7ad4783..02da23c 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeReal.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/augeas/tree/AugeasTreeReal.java
@@ -1,3 +1,25 @@
+/*
+ * 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.augeas.tree;
import java.io.File;
@@ -10,180 +32,194 @@ import org.rhq.augeas.config.AugeasModuleConfig;
import org.rhq.augeas.node.AugeasNode;
import org.rhq.augeas.node.AugeasNodeReal;
import org.rhq.augeas.node.AugeasRootNode;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasTreeReal implements AugeasTree{
- private AugeasModuleConfig moduleConfig;
- private Augeas ag;
- private AugeasNode rootNode;
- private AugeasNode rootConfigNode;
- private AugeasNodeBuffer nodeBuffer;
-
- private static String AUGEAS_DATA_PATH=File.separatorChar+"files";
-
- public AugeasTreeReal(Augeas ag ,AugeasModuleConfig moduleConfig)
- {
- rootNode = new AugeasRootNode();
- nodeBuffer = new AugeasNodeBuffer();
- this.moduleConfig = moduleConfig;
- this.ag = ag;
- }
-
- public void load() throws AugeasTreeException
- {
- buildTree();
- }
-
- public void update()
- {
-
- }
-
- public void save()
- {
- ag.save();
- }
-
-
- private AugeasNode getLoadedNode(String path) throws AugeasTreeException
- {
- if (nodeBuffer.isNodeLoaded(path))
- return nodeBuffer.getNode(path);
-
- throw new AugeasTreeException("Node not found.");
- }
-
- public AugeasNode getNode(String path) throws AugeasTreeException
- {
- AugeasNode node;
- try {
- node = getLoadedNode(path);
- }catch(AugeasTreeException e)
- {
- node = createNode(path);
- }
-
- return node;
- }
-
- public List<AugeasNode> match(String expression) throws AugeasTreeException
- {
- List<String> res = ag.match(expression);
+ private AugeasModuleConfig moduleConfig;
+ private Augeas ag;
+ private AugeasNode rootNode;
+ private AugeasNode rootConfigNode;
+ private AugeasNodeBuffer nodeBuffer;
+ private String [] errorNodes = {"pos","line","char","lens","message"};
+
+ private static String AUGEAS_DATA_PATH=File.separatorChar+"files";
+
+ public AugeasTreeReal(Augeas ag ,AugeasModuleConfig moduleConfig)
+ {
+ rootNode = new AugeasRootNode();
+ nodeBuffer = new AugeasNodeBuffer();
+ this.moduleConfig = moduleConfig;
+ this.ag = ag;
+ }
+
+ public void load() throws AugeasTreeException
+ {
+ buildTree();
+ }
+
+ public void update()
+ {
+
+ }
+
+ public void save()
+ {
+ ag.save();
+ }
+
+
+ private AugeasNode getLoadedNode(String path) throws AugeasTreeException
+ {
+ if (nodeBuffer.isNodeLoaded(path))
+ return nodeBuffer.getNode(path);
+
+ throw new AugeasTreeException("Node not found.");
+ }
+
+ public AugeasNode getNode(String path) throws AugeasTreeException
+ {
+ AugeasNode node;
+ try {
+ node = getLoadedNode(path);
+ }catch(AugeasTreeException e)
+ {
+ node = createNode(path);
+ }
+
+ return node;
+ }
+
+ public List<AugeasNode> match(String expression) throws AugeasTreeException
+ {
+ List<String> res = ag.match(expression);
- List<AugeasNode> nodes = new ArrayList<AugeasNode>();
-
- for (String name:res){
- nodes.add(getNode(name));
- }
-
- return nodes;
- }
-
- public List<AugeasNode> matchRelative(AugeasNode node,String expression) throws AugeasTreeException
- {
- if (rootNode.getChildNodes().isEmpty())
- throw new AugeasTreeException("Root node has not childs.");
-
- if (node.equals(rootNode)){
- List<AugeasNode> nodes = rootNode.getChildNodes();
- List<AugeasNode> returnNodes = new ArrayList<AugeasNode>();
- for (AugeasNode nd :nodes)
- {
- String tempName = nd.getFullPath()+expression;
- List<AugeasNode> temp = match(tempName);
- returnNodes.addAll(temp);
- }
- return returnNodes;
- }
-
- return match(node.getFullPath()+File.separatorChar+expression);
- }
-
- public AugeasNode createNode(String fullPath) throws AugeasTreeException
- {
- AugeasNode node=null;
-
- int index = fullPath.lastIndexOf(File.separatorChar);
- if (index!=-1){
- String parentPath = fullPath.substring(0,index);
- AugeasNode parentNode = getNode(parentPath);
- node= new AugeasNodeReal(parentNode,this,fullPath);
- } else
- throw new AugeasTreeException("Node can not be created. Parent node does not exist.");
-
- node.setValue(get(fullPath));
-
- List<AugeasNode> childs = match(fullPath + File.separatorChar+"*");
-
- for (AugeasNode chd : childs){
- node.addChildNode(chd);
- }
- nodeBuffer.addNode(node);
- return node;
-
- }
-
- public AugeasNode createNode(AugeasNode parentNode,String value,int seq)
- {
- return null;
- }
-
- public String get(String expr)
- {
- return ag.get(expr);
- }
-
- public AugeasNode getRootNode(){
- return rootNode;
- }
-
- private void buildTree() throws AugeasTreeException
- {
- rootConfigNode = createNode("/augeas");
-
- for (String name : moduleConfig.getIncludedGlobs())
- {
- rootNode.addChildNode(createNode(AUGEAS_DATA_PATH+File.separatorChar+name));
- }
- }
-
- public void removeNode(AugeasNode node,boolean updateSeq) throws Exception
- {
- int seq = node.getSeq();
-
- List<AugeasNode> nodes = matchRelative(node.getParentNode(), File.separatorChar+node.getLabel()+"[position() > "+String.valueOf(seq)+"]");
-
- for (AugeasNode nds : nodes){
- nds.setSeq(nds.getSeq()-1);
- nds.updateFromParent();
- }
-
- int res = ag.remove(node.getFullPath());
- nodeBuffer.removeNode(node,updateSeq,false);
+ List<AugeasNode> nodes = new ArrayList<AugeasNode>();
+
+ for (String name:res){
+ nodes.add(getNode(name));
+ }
+
+ return nodes;
+ }
+
+ public List<AugeasNode> matchRelative(AugeasNode node,String expression) throws AugeasTreeException
+ {
+ if (rootNode.getChildNodes().isEmpty())
+ throw new AugeasTreeException("Root node has not childs.");
+
+ if (node.equals(rootNode)){
+ List<AugeasNode> nodes = rootNode.getChildNodes();
+ List<AugeasNode> returnNodes = new ArrayList<AugeasNode>();
+ for (AugeasNode nd :nodes)
+ {
+ String tempName = nd.getFullPath()+expression;
+ List<AugeasNode> temp = match(tempName);
+ returnNodes.addAll(temp);
+ }
+ return returnNodes;
+ }
+
+ return match(node.getFullPath()+File.separatorChar+expression);
+ }
+
+ public AugeasNode createNode(String fullPath) throws AugeasTreeException
+ {
+ AugeasNode node=null;
+
+ int index = fullPath.lastIndexOf(File.separatorChar);
+ if (index!=-1){
+ String parentPath = fullPath.substring(0,index);
+ AugeasNode parentNode = getNode(parentPath);
+ node= new AugeasNodeReal(parentNode,this,fullPath);
+ } else
+ throw new AugeasTreeException("Node can not be created. Parent node does not exist.");
+
+ node.setValue(get(fullPath));
+
+ List<AugeasNode> childs = match(fullPath + File.separatorChar+"*");
+
+ for (AugeasNode chd : childs){
+ node.addChildNode(chd);
+ }
+ nodeBuffer.addNode(node);
+ return node;
+
+ }
+
+ public AugeasNode createNode(AugeasNode parentNode,String name,String value,int seq) throws AugeasTreeException
+ {
+ AugeasNode nd = createNode(parentNode.getFullPath()+File.separatorChar+name+"["+String.valueOf(seq)+"]");
+ nd.setValue(value);
+
+ return nd;
+ }
+
+ public String get(String expr)
+ {
+ return ag.get(expr);
+ }
+
+ public AugeasNode getRootNode(){
+ return rootNode;
+ }
+
+ private void buildTree() throws AugeasTreeException
+ {
+ rootConfigNode = createNode("/augeas");
+
+ for (String name : moduleConfig.getIncludedGlobs())
+ {
+ rootNode.addChildNode(createNode(AUGEAS_DATA_PATH+File.separatorChar+name));
+ }
+ }
+
+ public void removeNode(AugeasNode node,boolean updateSeq) throws Exception
+ {
+ int seq = node.getSeq();
+
+ List<AugeasNode> nodes = matchRelative(node.getParentNode(), File.separatorChar+node.getLabel()+"[position() > "+String.valueOf(seq)+"]");
+
+ for (AugeasNode nds : nodes){
+ nds.setSeq(nds.getSeq()-1);
+ nds.updateFromParent();
+ }
+
+ int res = ag.remove(node.getFullPath());
+ nodeBuffer.removeNode(node,updateSeq,false);
}
-
- public void setValue(AugeasNode node,String value)
- {
- ag.set(node.getFullPath(), value);
- }
- /*
- protected String summarizeAugeasError(Augeas augeas) {
- StringBuilder summary = new StringBuilder();
- String metadataNodePrefix = "/augeas/files";
- for (String glob : moduleConfig.getIncludedGlobs()) {
- if (glob.startsWith(""+File.separatorChar)) {
- glob = glob.substring(1);
- }
- AugeasNode metadataNode = new AugeasNodeLazy();
- AugeasNode errorNode = new AugeasNode(metadataNode, "error");
- List<String> nodePaths = augeas.match(errorNode.getPath() + "/*");
- for (String path : nodePaths) {
- String error = augeas.get(path);
- summary.append("File \"").append(path.substring(metadataNodePrefix.length(), path.length())).append(
- "\":\n").append(error).append("\n");
- }
- }
+
+ public void setValue(AugeasNode node,String value)
+ {
+ ag.set(node.getFullPath(), value);
+ }
+
+
+
+ public String summarizeAugeasError() {
+
+ String nodePrefix = "/augeas/files";
+ List<String> str = moduleConfig.getIncludedGlobs();
+ StringBuilder builder = new StringBuilder();
+
+ for (String path : str) {
+ String name = nodePrefix + path+File.separatorChar+"error";
+ if (ag.exists(name))
+ {
+ builder.append("Error "+ag.get(name)+'\n');
+ for (String errNd : errorNodes)
+ {
+ String pathToMessage = name+File.separatorChar+errNd;
+ if (ag.exists(pathToMessage))
+ {
+ builder.append(errNd + " "+ag.get(pathToMessage)+'\n');
+ }
+ }
+ }
+ }
- return summary.toString();
- }
-*/
+ return builder.toString();
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/AugeasRHQComponent.java b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/AugeasRHQComponent.java
index 6b8ddf4..dbdf10a 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/AugeasRHQComponent.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/AugeasRHQComponent.java
@@ -1,12 +1,39 @@
+/*
+ * 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.plugins.iptables;
import org.rhq.augeas.AugeasComponent;
import org.rhq.augeas.tree.AugeasTree;
import org.rhq.core.pluginapi.inventory.ResourceComponent;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public interface AugeasRHQComponent <T extends ResourceComponent> extends ResourceComponent<T>{
- public AugeasTree getAugeasTree() throws Exception;
+ public AugeasTree getAugeasTree() throws Exception;
public AugeasComponent getAugeasComponent() throws Exception;
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainComponent.java b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainComponent.java
index e3bbec1..d7f194d 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainComponent.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainComponent.java
@@ -1,3 +1,26 @@
+/*
+ * 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.plugins.iptables;
import java.io.File;
@@ -16,68 +39,72 @@ import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceContext;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesChainComponent implements AugeasRHQComponent<IptablesTableComponent>, ConfigurationFacet{
- private String tableName;
- private String chainName;
- private AugeasTree augeasTree;
- private ResourceContext<IptablesTableComponent> context;
- private IptablesTableComponent parentComponent;
- private final Log log = LogFactory.getLog(this.getClass());
-
- public void start(ResourceContext<IptablesTableComponent> context)
- throws InvalidPluginConfigurationException, Exception {
- this.context = context;
- this.parentComponent = context.getParentResourceComponent();
- this.chainName = context.getResourceKey();
- this.tableName= context.getParentResourceComponent().getTableName();
- }
+ private String tableName;
+ private String chainName;
+ private AugeasTree augeasTree;
+ private ResourceContext<IptablesTableComponent> context;
+ private IptablesTableComponent parentComponent;
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ public void start(ResourceContext<IptablesTableComponent> context)
+ throws InvalidPluginConfigurationException, Exception {
+ this.context = context;
+ this.parentComponent = context.getParentResourceComponent();
+ this.chainName = context.getResourceKey();
+ this.tableName= context.getParentResourceComponent().getTableName();
+ }
- public void stop() {
-
- }
+ public void stop() {
+
+ }
- public AvailabilityType getAvailability() {
- return AvailabilityType.UP;
- }
+ public AvailabilityType getAvailability() {
+ return AvailabilityType.UP;
+ }
- public Configuration loadResourceConfiguration() throws Exception {
- augeasTree = getAugeasTree();
-
- ConfigurationDefinition resourceConfigDef = this.context.getResourceType()
+ public Configuration loadResourceConfiguration() throws Exception {
+ augeasTree = getAugeasTree();
+
+ ConfigurationDefinition resourceConfigDef = this.context.getResourceType()
.getResourceConfigurationDefinition();
- IptablesConfigTransform trans = new IptablesConfigTransform(augeasTree);
- List<AugeasNode> nodes = getIptablesChainNode(chainName);
- Configuration config= null;
- if (!nodes.isEmpty())
- config = trans.transform(nodes, resourceConfigDef);
+ IptablesConfigTransform trans = new IptablesConfigTransform(augeasTree);
+ List<AugeasNode> nodes = getIptablesChainNode(chainName);
+ Configuration config= null;
+ if (!nodes.isEmpty())
+ config = trans.transform(nodes, resourceConfigDef);
- return config;
- }
+ return config;
+ }
- public void updateResourceConfiguration(ConfigurationUpdateReport config) {
- IptablesConfigTransform trans = new IptablesConfigTransform(augeasTree);
- trans.updateAugeas(config.getConfiguration(), new ArrayList<AugeasNode>());
- }
-
- public AugeasComponent getAugeasComponent() throws Exception {
- return parentComponent.getAugeasComponent();
- }
+ public void updateResourceConfiguration(ConfigurationUpdateReport config) {
+ IptablesConfigTransform trans = new IptablesConfigTransform(augeasTree);
+ trans.updateAugeas(config.getConfiguration(), new ArrayList<AugeasNode>());
+ }
+
+ public AugeasComponent getAugeasComponent() throws Exception {
+ return parentComponent.getAugeasComponent();
+ }
- public AugeasTree getAugeasTree() throws Exception {
- return parentComponent.getAugeasTree();
- }
-
- private List<AugeasNode> getIptablesChainNode(String chainName) throws Exception{
- if (augeasTree == null)
- return null;
- String expr = File.separatorChar+tableName+File.separatorChar+chainName;
-
- List<AugeasNode> nodes = augeasTree.matchRelative(augeasTree.getRootNode(), expr);
-
- return nodes;
- }
+ public AugeasTree getAugeasTree() throws Exception {
+ return parentComponent.getAugeasTree();
+ }
+
+ private List<AugeasNode> getIptablesChainNode(String chainName) throws Exception{
+ if (augeasTree == null)
+ return null;
+ String expr = File.separatorChar+tableName+File.separatorChar+chainName;
+
+ List<AugeasNode> nodes = augeasTree.matchRelative(augeasTree.getRootNode(), expr);
+
+ return nodes;
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainDiscoveryComponent.java b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainDiscoveryComponent.java
index 44e8cc0..8c4a1ce 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainDiscoveryComponent.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesChainDiscoveryComponent.java
@@ -1,3 +1,25 @@
+/*
+ * 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.plugins.iptables;
import java.io.File;
@@ -14,27 +36,31 @@ import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesChainDiscoveryComponent implements ResourceDiscoveryComponent<IptablesTableComponent>{
- private final Log log = LogFactory.getLog(this.getClass());
-
- public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<IptablesTableComponent> context)
- throws InvalidPluginConfigurationException, Exception {
-
- AugeasTree tree = context.getParentResourceComponent().getAugeasTree();
- String tableName = context.getParentResourceComponent().getTableName();
-
- List<AugeasNode> nodes = tree.matchRelative(tree.getRootNode(), File.separatorChar+tableName+File.separatorChar+"settings"+File.separatorChar+"chain");
- ResourceType resourceType = context.getResourceType();
-
- Set<DiscoveredResourceDetails> resources = new HashSet<DiscoveredResourceDetails>();
-
- for (AugeasNode nd : nodes){
- String value = nd.getValue();
- resources.add(new DiscoveredResourceDetails(resourceType,value, value, "", "Chain", null, null));
- }
-
- return resources;
- }
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<IptablesTableComponent> context)
+ throws InvalidPluginConfigurationException, Exception {
+
+ AugeasTree tree = context.getParentResourceComponent().getAugeasTree();
+ String tableName = context.getParentResourceComponent().getTableName();
+
+ List<AugeasNode> nodes = tree.matchRelative(tree.getRootNode(), File.separatorChar+tableName+File.separatorChar+"settings"+File.separatorChar+"chain");
+ ResourceType resourceType = context.getResourceType();
+
+ Set<DiscoveredResourceDetails> resources = new HashSet<DiscoveredResourceDetails>();
+
+ for (AugeasNode nd : nodes){
+ String value = nd.getValue();
+ resources.add(new DiscoveredResourceDetails(resourceType,value, value, "", "Chain", null, null));
+ }
+
+ return resources;
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesComponent.java b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesComponent.java
index 7861ef1..e95c2a6 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesComponent.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesComponent.java
@@ -1,3 +1,25 @@
+/*
+ * 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.plugins.iptables;
import org.apache.commons.logging.Log;
@@ -11,86 +33,90 @@ import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceContext;
import org.rhq.rhqtransform.RhqConfig;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesComponent implements AugeasRHQComponent, ConfigurationFacet{
- private ResourceContext context;
- private final Log log = LogFactory.getLog(this.getClass());
- private AugeasTree augeasTree;
- private AugeasComponent augeasComponent;
-
- public void start(ResourceContext context)
- throws InvalidPluginConfigurationException, Exception {
- this.context = context;
- }
+ private ResourceContext context;
+ private final Log log = LogFactory.getLog(this.getClass());
+ private AugeasTree augeasTree;
+ private AugeasComponent augeasComponent;
+
+ public void start(ResourceContext context)
+ throws InvalidPluginConfigurationException, Exception {
+ this.context = context;
+ }
- public void stop() {
-
- }
+ public void stop() {
+
+ }
- public AvailabilityType getAvailability() {
- return AvailabilityType.UP;
- }
+ public AvailabilityType getAvailability() {
+ return AvailabilityType.UP;
+ }
- public Configuration loadResourceConfiguration() throws Exception {
- Configuration pluginConfiguration = new Configuration();
-
- AugeasTree tree=null;
- AugeasComponent augeas =null;
- try {
- RhqConfig config = new RhqConfig(context.getPluginConfiguration());
- augeas = new AugeasComponent(config);
- augeas.load();
- tree = augeas.getAugeasTree("Iptables", true);
- tree.load();
-
- }catch(Exception e)
- {
- log.error(e.getMessage());
-
- }
- return pluginConfiguration;
- }
-
+ public Configuration loadResourceConfiguration() throws Exception {
+ Configuration pluginConfiguration = new Configuration();
+
+ AugeasTree tree=null;
+ AugeasComponent augeas =null;
+ try {
+ RhqConfig config = new RhqConfig(context.getPluginConfiguration());
+ augeas = new AugeasComponent(config);
+ augeas.load();
+ tree = augeas.getAugeasTree("Iptables", true);
+ tree.load();
+
+ }catch(Exception e)
+ {
+ log.error(e.getMessage());
+
+ }
+ return pluginConfiguration;
+ }
+
- public void updateResourceConfiguration(ConfigurationUpdateReport report) {
- Configuration pluginConfiguration = new Configuration();
- AugeasTree tree=null;
- AugeasComponent augeas =null;
- try {
- RhqConfig config = new RhqConfig(context.getPluginConfiguration());
- augeas = new AugeasComponent(config);
-
- tree = augeas.getAugeasTree("Iptables", false);
-
-
- }catch(Exception e)
- {
- log.error(e);
- }
-
- }
+ public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+ Configuration pluginConfiguration = new Configuration();
+ AugeasTree tree=null;
+ AugeasComponent augeas =null;
+ try {
+ RhqConfig config = new RhqConfig(context.getPluginConfiguration());
+ augeas = new AugeasComponent(config);
+
+ tree = augeas.getAugeasTree("Iptables", false);
+
+
+ }catch(Exception e)
+ {
+ log.error(e);
+ }
+
+ }
- public void loadAugeas() throws Exception{
- RhqConfig config = new RhqConfig(context.getPluginConfiguration());
- augeasComponent = new AugeasComponent(config);
- augeasComponent.load();
- augeasTree = augeasComponent.getAugeasTree("Iptables", true);
- augeasTree.load();
-
- }
- public AugeasComponent getAugeasComponent() throws Exception{
+ public void loadAugeas() throws Exception{
+ RhqConfig config = new RhqConfig(context.getPluginConfiguration());
+ augeasComponent = new AugeasComponent(config);
+ augeasComponent.load();
+ augeasTree = augeasComponent.getAugeasTree("Iptables", true);
+ augeasTree.load();
+
+ }
+ public AugeasComponent getAugeasComponent() throws Exception{
if (augeasComponent == null)
- loadAugeas();
+ loadAugeas();
return augeasComponent;
- }
+ }
- public AugeasTree getAugeasTree() throws Exception {
- if (augeasTree == null)
- loadAugeas();
-
- return augeasTree;
- }
+ public AugeasTree getAugeasTree() throws Exception {
+ if (augeasTree == null)
+ loadAugeas();
+
+ return augeasTree;
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesConfigTransform.java b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesConfigTransform.java
index 7002800..31b661a 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesConfigTransform.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesConfigTransform.java
@@ -1,3 +1,25 @@
+/*
+ * 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.plugins.iptables;
import java.io.File;
@@ -13,173 +35,143 @@ import org.rhq.core.domain.configuration.PropertyList;
import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.configuration.definition.PropertyDefinition;
-import org.rhq.rhqtransform.RhqTransform;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesConfigTransform {
- private AugeasTree tree;
- private RhqTransform transf;
-
- public IptablesConfigTransform(AugeasTree tree){
- this.tree = tree;
- this.transf = new RhqTransform(tree);
- }
- /*
- public Configuration transform(List<AugeasNode> startNodes,ConfigurationDefinition resourceConfigDef) throws Exception
- {
-
- Configuration resourceConfig = new Configuration();
- Collection<PropertyDefinition> propDefs = resourceConfigDef.getPropertyDefinitions().values();
+ private AugeasTree tree;
- if (propDefs.size()!=1)
- throw new Exception("Error in mapping.");
-
- PropertyList propList = new PropertyList("chains");
-
- for (PropertyDefinition propDef : propDefs) {
- if (propDef.getName().equals("chain")){
- PropertyDefinition definition = ((PropertyDefinitionList)propDef).getMemberDefinition();
- for (AugeasNode node : startNodes){
- //for (AugeasNode nd : node.getChildNodes())
- propList.add(transf.loadProperty(definition,node));
- }
- }
- }
-
- resourceConfig.put(propList);
- return resourceConfig;
- }*/
-
- public Configuration transform(List<AugeasNode> startNodes,ConfigurationDefinition resourceConfigDef) throws Exception
- {
- Configuration resourceConfig = new Configuration();
+
+ public IptablesConfigTransform(AugeasTree tree){
+ this.tree = tree;
- if (startNodes.isEmpty())
- {
- PropertyList propList = new PropertyList("chains");
- PropertyMap mp = new PropertyMap("rule");
- propList.add(mp);
- resourceConfig.put(propList);
- return resourceConfig;
- }
-
- Collection<PropertyDefinition> propDefs = resourceConfigDef.getPropertyDefinitions().values();
+ }
+
+ public Configuration transform(List<AugeasNode> startNodes,ConfigurationDefinition resourceConfigDef) throws Exception
+ {
+ Configuration resourceConfig = new Configuration();
- if (propDefs.size()!=1)
- throw new Exception("Error in mapping.");
-
- PropertyList propList = new PropertyList("chains");
-
- for (AugeasNode node : startNodes){
- //for (AugeasNode nd : node.getChildNodes())
- PropertyMap mp = new PropertyMap("rule");
- for (AugeasNode nd : node.getChildByLabel("rule"))
- {//rules
-
- String rule = "";
-
- for (AugeasNode tempNode : nd.getChildByLabel("parameters"))
- {
- rule += buildRule(tempNode);
- }
-
- PropertySimple ruleProp = new PropertySimple("param",rule);
- mp.put(ruleProp);
- }
- propList.add(mp);
- }
-
- resourceConfig.put(propList);
- return resourceConfig;
- }
-
- private String buildRule(AugeasNode nd) throws Exception{
- String paramName = getValue(nd,"/param/paramName");
- String negation = getValue(nd, "/param/negation");
- String value = getValue(nd, "/param/value");
-
- return (((paramName.length()> 1) ?"--" : "-") + paramName + " " + negation + " " +value);
- }
-
- private String getValue(AugeasNode nd,String nm) throws Exception{
- List<AugeasNode> nds = tree.matchRelative(nd, nm);
- if (!nds.isEmpty())
- return nds.get(0).getValue();
- else
- return "";
- }
-
-
- public void updateAugeas(Configuration config,List<AugeasNode> nodes)
- {
- List<String> values = new ArrayList<String>();
-
- Collection<Property> props = config.getAllProperties().values();
-
- for (Property prop : props)
- {
- if (prop.getName().equals("chains")){
- PropertyList propList = (PropertyList) prop;
- for (Property property : propList.getList())
- {
- if (property.getName().equals("rule"))
- {
- PropertyMap propMap = (PropertyMap) property;
- for (Property propVal : propMap.getMap().values()){
- if (propVal.getName().equals("param")){
- values.add(((PropertySimple)propVal).getStringValue());
- }
- }
- }
- }
- }
- }
- String name;
- }
-
-
- public void buildTree(List<AugeasNode> nodes) throws Exception
- {
- List<String> values = new ArrayList<String>();
+ if (startNodes.isEmpty())
+ {
+ PropertyList propList = new PropertyList("chains");
+ PropertyMap mp = new PropertyMap("rule");
+ propList.add(mp);
+ resourceConfig.put(propList);
+ return resourceConfig;
+ }
+
+ PropertyList propList = new PropertyList("chains");
+
+ for (AugeasNode node : startNodes){
+ //for (AugeasNode nd : node.getChildNodes())
+ PropertyMap mp = new PropertyMap("rule");
+ for (AugeasNode nd : node.getChildByLabel("rule"))
+ {//rules
+
+ String rule = "";
+
+ for (AugeasNode tempNode : nd.getChildByLabel("parameters"))
+ {
+ rule += buildRule(tempNode);
+ }
+
+ PropertySimple ruleProp = new PropertySimple("param",rule);
+ mp.put(ruleProp);
+ }
+ propList.add(mp);
+ }
+
+ resourceConfig.put(propList);
+ return resourceConfig;
+ }
+
+ private String buildRule(AugeasNode nd) throws Exception{
+ String paramName = getValue(nd,"/param/paramName");
+ String negation = getValue(nd, "/param/negation");
+ String value = getValue(nd, "/param/value");
+
+ return (((paramName.length()> 1) ?"--" : "-") + paramName + " " + negation + " " +value);
+ }
+
+ private String getValue(AugeasNode nd,String nm) throws Exception{
+ List<AugeasNode> nds = tree.matchRelative(nd, nm);
+ if (!nds.isEmpty())
+ return nds.get(0).getValue();
+ else
+ return "";
+ }
+
+
+ public void updateAugeas(Configuration config,List<AugeasNode> nodes)
+ {
+ List<String> values = new ArrayList<String>();
+
+ Collection<Property> props = config.getAllProperties().values();
+
+ for (Property prop : props)
+ {
+ if (prop.getName().equals("chains")){
+ PropertyList propList = (PropertyList) prop;
+ for (Property property : propList.getList())
+ {
+ if (property.getName().equals("rule"))
+ {
+ PropertyMap propMap = (PropertyMap) property;
+ for (Property propVal : propMap.getMap().values()){
+ if (propVal.getName().equals("param")){
+ values.add(((PropertySimple)propVal).getStringValue());
+ }
+ }
+ }
+ }
+ }
+ }
+ String name;
+ }
+
+
+ public void buildTree(List<AugeasNode> nodes) throws Exception
+ {
+ List<String> values = new ArrayList<String>();
- for (AugeasNode node : nodes){
- PropertyMap mp = new PropertyMap("rule");
- for (AugeasNode nd : node.getChildByLabel("rule"))
- {
- String rule = "";
- for (AugeasNode tempNode : nd.getChildByLabel("parameters"))
- {
- rule += buildRule(tempNode);
- }
-
- values.add(rule);
- }
+ for (AugeasNode node : nodes){
+ PropertyMap mp = new PropertyMap("rule");
+ for (AugeasNode nd : node.getChildByLabel("rule"))
+ {
+ String rule = "";
+ for (AugeasNode tempNode : nd.getChildByLabel("parameters"))
+ {
+ rule += buildRule(tempNode);
+ }
+
+ values.add(rule);
+ }
}
- }
-
- public void compare(List<String> values,AugeasTree tree,String chainName,String tableName) throws Exception
- {
- String expr = File.separatorChar+tableName+File.separatorChar+chainName;
-
- List<AugeasNode> nodes = tree.matchRelative(tree.getRootNode(), expr);
-
- for (AugeasNode node : nodes)
- {
- node.remove(false);
- }
- int i =1;
- for (String val : values){
-
- i = i + 1;
- String temp = File.separatorChar+tableName+File.separatorChar+chainName+"["+String.valueOf(i) +"]"+File.separatorChar+"rule";
-
-
- }
- }
-
- public void addToAugeas(String parent,String param){
-
- }
-
+ }
+
+ public void compare(List<String> values,AugeasTree tree,String chainName,String tableName) throws Exception
+ {
+ String expr = File.separatorChar+tableName+File.separatorChar+chainName;
+
+ List<AugeasNode> nodes = tree.matchRelative(tree.getRootNode(), expr);
+
+ for (AugeasNode node : nodes)
+ {
+ node.remove(false);
+ }
+ int i =1;
+ for (String val : values){
+ i = i + 1;
+ String temp = File.separatorChar+tableName+File.separatorChar+chainName+"["+String.valueOf(i) +"]"+File.separatorChar+"rule";
+
+ }
+ }
+
+ public void addToAugeas(String parent,String param){
+
+ }
+
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesDiscoveryComponent.java b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesDiscoveryComponent.java
index c99bc70..3c0f25d 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesDiscoveryComponent.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesDiscoveryComponent.java
@@ -1,3 +1,25 @@
+/*
+ * 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.plugins.iptables;
import java.util.HashSet;
@@ -9,26 +31,30 @@ import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
import org.rhq.rhqtransform.RhqConfig;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesDiscoveryComponent implements ResourceDiscoveryComponent {
- public Set discoverResources(ResourceDiscoveryContext discoveryContext)
- throws InvalidPluginConfigurationException, Exception {
-
- Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>(1);
-
- Configuration pluginConfiguration = discoveryContext.getDefaultPluginConfiguration();
-
- RhqConfig config = new RhqConfig(pluginConfiguration);
-
- Set<DiscoveredResourceDetails> details = new HashSet<DiscoveredResourceDetails>();
- DiscoveredResourceDetails resource =
+ public Set discoverResources(ResourceDiscoveryContext discoveryContext)
+ throws InvalidPluginConfigurationException, Exception {
+
+ Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>(1);
+
+ Configuration pluginConfiguration = discoveryContext.getDefaultPluginConfiguration();
+
+ RhqConfig config = new RhqConfig(pluginConfiguration);
+
+ Set<DiscoveredResourceDetails> details = new HashSet<DiscoveredResourceDetails>();
+ DiscoveredResourceDetails resource =
new DiscoveredResourceDetails(discoveryContext.getResourceType(), "iptables", "IPTABLES",
"", "IPTABLES.", pluginConfiguration, null);
details.add(resource);
return details;
- }
+ }
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableComponent.java b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableComponent.java
index 032c41c..f88ab1a 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableComponent.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableComponent.java
@@ -1,3 +1,25 @@
+/*
+ * 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.plugins.iptables;
import org.rhq.augeas.AugeasComponent;
@@ -8,46 +30,50 @@ import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceContext;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesTableComponent implements AugeasRHQComponent<AugeasRHQComponent>, ConfigurationFacet{
- private String tableName;
- private AugeasRHQComponent parentComponent;
-
- public void start(ResourceContext<AugeasRHQComponent> context)
- throws InvalidPluginConfigurationException, Exception {
-
- tableName = context.getResourceKey();
- parentComponent = context.getParentResourceComponent();
- }
-
- public void stop() {
-
- }
-
- public AvailabilityType getAvailability() {
- return AvailabilityType.UP;
- }
-
- public Configuration loadResourceConfiguration() throws Exception {
-
- return null;
- }
-
- public void updateResourceConfiguration(ConfigurationUpdateReport arg0) {
-
- }
-
- public String getTableName(){
- return tableName;
- }
-
- public AugeasComponent getAugeasComponent() throws Exception {
- return parentComponent.getAugeasComponent();
- }
-
- public AugeasTree getAugeasTree() throws Exception {
- return parentComponent.getAugeasTree();
- }
+ private String tableName;
+ private AugeasRHQComponent parentComponent;
+
+ public void start(ResourceContext<AugeasRHQComponent> context)
+ throws InvalidPluginConfigurationException, Exception {
+
+ tableName = context.getResourceKey();
+ parentComponent = context.getParentResourceComponent();
+ }
+
+ public void stop() {
+
+ }
+
+ public AvailabilityType getAvailability() {
+ return AvailabilityType.UP;
+ }
+
+ public Configuration loadResourceConfiguration() throws Exception {
+
+ return null;
+ }
+
+ public void updateResourceConfiguration(ConfigurationUpdateReport arg0) {
+
+ }
+
+ public String getTableName(){
+ return tableName;
+ }
+
+ public AugeasComponent getAugeasComponent() throws Exception {
+ return parentComponent.getAugeasComponent();
+ }
+
+ public AugeasTree getAugeasTree() throws Exception {
+ return parentComponent.getAugeasTree();
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableDiscoveryComponent.java b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableDiscoveryComponent.java
index cd4c20f..fd7c6e1 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableDiscoveryComponent.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/plugins/iptables/IptablesTableDiscoveryComponent.java
@@ -1,3 +1,25 @@
+/*
+ * 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.plugins.iptables;
import java.util.HashSet;
@@ -8,25 +30,29 @@ import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class IptablesTableDiscoveryComponent implements ResourceDiscoveryComponent<IptablesComponent>{
- public String [] tables = {"filter","nat","mangle"};
-
- public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<IptablesComponent> context)
- throws InvalidPluginConfigurationException, Exception {
-
- ResourceType resourceType = context.getResourceType();
- Set<DiscoveredResourceDetails> resources = new HashSet<DiscoveredResourceDetails>();
-
- for (String tableName : tables)
- {
- resources.add(new DiscoveredResourceDetails(resourceType,
+ public String [] tables = {"filter","nat","mangle"};
+
+ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<IptablesComponent> context)
+ throws InvalidPluginConfigurationException, Exception {
+
+ ResourceType resourceType = context.getResourceType();
+ Set<DiscoveredResourceDetails> resources = new HashSet<DiscoveredResourceDetails>();
+
+ for (String tableName : tables)
+ {
+ resources.add(new DiscoveredResourceDetails(resourceType,
tableName, tableName, "", "Table",
null, null));
- }
-
- return resources;
- }
+ }
+
+ return resources;
+ }
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasRhqException.java b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasRhqException.java
index 5ba2447..4176445 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasRhqException.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasRhqException.java
@@ -1,10 +1,36 @@
+/*
+ * 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.rhqtransform;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public class AugeasRhqException extends Exception{
- public AugeasRhqException(String text)
- {
- super(text);
- }
-
+ public AugeasRhqException(String text)
+ {
+ super(text);
+ }
+
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasToConfiguration.java b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasToConfiguration.java
index 5bf4694..ac24860 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasToConfiguration.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/AugeasToConfiguration.java
@@ -1,95 +1,49 @@
+/*
+ * 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.rhqtransform;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.rhq.augeas.node.AugeasNode;
import org.rhq.augeas.tree.AugeasTree;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.Property;
-import org.rhq.core.domain.configuration.PropertyList;
import org.rhq.core.domain.configuration.PropertyMap;
-import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
-
-public class AugeasToConfiguration {
-
- private final Log log = LogFactory.getLog(this.getClass());
- private AugeasTree tree;
- private NameMap nameMap;
-
- public AugeasToConfiguration(){
-
- }
-
- public void setTree(AugeasTree tree)
- {
- this.tree = tree;
- }
-
- public void setNameMap(NameMap nameMap){
- this.nameMap = nameMap;
- }
-
- public Configuration loadResourceConfiguration(AugeasNode startNode,ConfigurationDefinition resourceConfigDef) throws Exception {
-
- Configuration resourceConfig = new Configuration();
-
- Collection<PropertyDefinition> propDefs = resourceConfigDef.getPropertyDefinitions().values();
-
- for (PropertyDefinition propDef : propDefs) {
- resourceConfig.put(loadProperty(propDef,startNode));
- }
-
- return resourceConfig;
- }
-
- public Property loadProperty(PropertyDefinition propDef, AugeasNode parentNode) throws Exception{
-
- Property prop;
- if (propDef instanceof PropertyDefinitionSimple) {
- prop = createPropertySimple((PropertyDefinitionSimple) propDef, parentNode);
- } else if (propDef instanceof PropertyDefinitionMap) {
- prop = createPropertyMap((PropertyDefinitionMap) propDef, parentNode);
- } else if (propDef instanceof PropertyDefinitionList) {
- prop = createPropertyList((PropertyDefinitionList) propDef, parentNode);
- } else {
- throw new IllegalStateException("Unsupported PropertyDefinition subclass: " + propDef.getClass().getName());
- }
- return prop;
- }
-
- public Property createPropertySimple(PropertyDefinitionSimple propDefSimple, AugeasNode node) throws Exception{
- Object value;
- value = node.getValue();
- return new PropertySimple(propDefSimple.getName(), value);
- }
-
- public PropertyMap createPropertyMap(PropertyDefinitionMap propDefMap, AugeasNode node) throws Exception {
- PropertyMap propMap = new PropertyMap(propDefMap.getName());
- for (PropertyDefinition mapEntryPropDef : propDefMap.getPropertyDefinitions().values()) {
- propMap.put(loadProperty(mapEntryPropDef, node));
- }
- return propMap;
- }
-
- public Property createPropertyList(PropertyDefinitionList propDefList, AugeasNode node) throws Exception{
-
- PropertyList propList = new PropertyList(propDefList.getName());
-
- List<AugeasNode> nodes = tree.matchRelative(node, propDefList.getName());
- PropertyDefinition listMemberPropDef = propDefList.getMemberDefinition();
-
- for (AugeasNode listMemberNode : nodes){
- propList.add(loadProperty(listMemberPropDef,listMemberNode));
- }
-
- return propList;
- }
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
+public interface AugeasToConfiguration {
+
+ public void setTree(AugeasTree tree);
+ public void setNameMap(NameMap nameMap);
+ public Configuration loadResourceConfiguration(AugeasNode startNode,ConfigurationDefinition resourceConfigDef)throws Exception;
+ public Property loadProperty(PropertyDefinition propDef, AugeasNode parentNode) throws Exception;
+ public Property createPropertySimple(PropertyDefinitionSimple propDefSimple, AugeasNode node) throws Exception;
+ public PropertyMap createPropertyMap(PropertyDefinitionMap propDefMap, AugeasNode node) throws Exception;
+ public Property createPropertyList(PropertyDefinitionList propDefList, AugeasNode node) throws Exception;
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/ConfigurationToAugeas.java b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/ConfigurationToAugeas.java
index 93d711f..1aea026 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/ConfigurationToAugeas.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/ConfigurationToAugeas.java
@@ -1,147 +1,47 @@
+/*
+ * 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.rhqtransform;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
import org.rhq.augeas.node.AugeasNode;
import org.rhq.augeas.tree.AugeasTree;
-import org.rhq.core.domain.configuration.AbstractPropertyMap;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.Property;
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.configuration.PropertyMap;
-import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
-import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
-
-public class ConfigurationToAugeas {
-
- private AugeasTree tree;
-
- public void updateResourceConfiguration(ConfigurationDefinition resourceConfigDef,Configuration resourceConfig) throws Exception{
-
- Collection<PropertyDefinition> propDefs = resourceConfigDef.getPropertyDefinitions().values();
- for (PropertyDefinition propDef : propDefs) {
- setNode(propDef, resourceConfig, tree.getRootNode());
- }
- }
-
- protected void setNode(PropertyDefinition propDef, AbstractPropertyMap parentPropMap,
- AugeasNode parentNode) throws Exception{
-
- String propName = propDef.getName();
-
- AugeasNode node;
-
- if (propName.equals("."))
- node = parentNode;
- else
- {
- List<AugeasNode> nodes = tree.matchRelative(parentNode, propName);
- if (nodes.isEmpty())
- throw new Exception("Error in mapping");
- node = nodes.get(0);
- }
-
- if (isPropertyDefined(propDef, parentPropMap)) {
- // The property *is* defined, which means we either need to add or update the corresponding node in the
- // Augeas tree.
- if (propDef instanceof PropertyDefinitionSimple) {
- PropertyDefinitionSimple propDefSimple = (PropertyDefinitionSimple) propDef;
- PropertySimple propSimple = parentPropMap.getSimple(propDefSimple.getName());
- setNodeFromPropertySimple( node, propDefSimple, propSimple);
- } else if (propDef instanceof PropertyDefinitionMap) {
- PropertyDefinitionMap propDefMap = (PropertyDefinitionMap) propDef;
- PropertyMap propMap = parentPropMap.getMap(propDefMap.getName());
- setNodeFromPropertyMap(propDefMap, propMap, node);
- } else if (propDef instanceof PropertyDefinitionList) {
- PropertyDefinitionList propDefList = (PropertyDefinitionList) propDef;
- PropertyList propList = parentPropMap.getList(propDefList.getName());
- setNodeFromPropertyList(propDefList, propList, node);
- } else {
- throw new IllegalStateException("Unsupported PropertyDefinition subclass: "
- + propDef.getClass().getName());
- }
- } else {
- // The property *is not* defined - remove the corresponding node from the Augeas tree if it exists.
- node.remove();
- }
- }
-
- protected void setNodeFromPropertySimple(AugeasNode node, PropertyDefinitionSimple propDefSimple,
- PropertySimple propSimple) {
- String value = propSimple.getStringValue();
-
- // Update the value of the existing node.
- node.setValue(value);
- }
-
- protected void setNodeFromPropertyMap(PropertyDefinitionMap propDefMap, PropertyMap propMap,
- AugeasNode mapNode) throws Exception{
- for (PropertyDefinition mapEntryPropDef : propDefMap.getPropertyDefinitions().values()) {
- setNode(mapEntryPropDef, propMap, mapNode);
- }
- }
-
- protected void setNodeFromPropertyList(PropertyDefinitionList propDefList, PropertyList propList,
- AugeasNode listNode) {
- PropertyDefinition listMemberPropDef = propDefList.getMemberDefinition();
-
- PropertyDefinitionMap listMemberPropDefMap = (PropertyDefinitionMap) listMemberPropDef;
-
- int listIndex = 0;
- String listMemberPropDefMapPath = listMemberPropDefMap.getName();
- List<AugeasNode> existingListMemberNodes = listNode.getChildByLabel(listMemberPropDefMapPath);
-
- Set<AugeasNode> updatedListMemberNodes = new HashSet<AugeasNode>();
- for (Property listMemberProp : propList.getList()) {
- PropertyMap listMemberPropMap = (PropertyMap) listMemberProp;
- AugeasNode memberNodeToUpdate = getExistingChildNodeForListMemberPropertyMap(listNode, propDefList,
- listMemberPropMap);
- if (memberNodeToUpdate != null) {
- // Keep track of the existing nodes that we'll be updating, so that we can remove all other existing
- // nodes.
- updatedListMemberNodes.add(memberNodeToUpdate);
- } else {
- // The maps in the list are non-keyed, or there is no map in the list with the same key as the map
- // being added, so create a new node for the map to add to the list.
- AugeasNode basePathNode = getNewListMemberNode(listNode, listMemberPropDefMap, listIndex);
- String var = "prop" + listIndex;
- augeas.defineNode(var, basePathNode.getPath(), null);
- memberNodeToUpdate = new AugeasNode("$" + var);
- listIndex++;
- }
-
- // Update the node's children.
- setNodeFromPropertyMap(listMemberPropDefMap, listMemberPropMap, augeas, memberNodeToUpdate);
- }
-
- // Now remove any existing nodes that we did not update in the previous loop.
- for (AugeasNode existingListMemberNode : existingListMemberNodes) {
- if (!updatedListMemberNodes.contains(existingListMemberNode)) {
- augeas.remove(existingListMemberNode.getPath());
- }
- }
- }
-
- protected AugeasNode getNewListMemberNode(AugeasNode listNode, PropertyDefinitionMap listMemberPropDefMap,
- int listIndex) {
- return new AugeasNode(listNode, getAugeasPathRelativeToParent(listMemberPropDefMap, listNode, getAugeas())
- + "[" + listIndex + "]");
- }
-
- private boolean isPropertyDefined(PropertyDefinition propDef, AbstractPropertyMap parentPropMap) {
- Property prop = parentPropMap.get(propDef.getName());
- if (prop == null) {
- return false;
- } else {
- return (!(prop instanceof PropertySimple) || ((PropertySimple) prop).getStringValue() != null);
- }
- }
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
+public interface ConfigurationToAugeas {
+
+ public void setTree(AugeasTree tree);
+ public void updateResourceConfiguration(AugeasNode node,ConfigurationDefinition resourceConfigDef,Configuration resourceConfig) throws Exception;
+ public void updateMap(PropertyDefinitionMap propDefMap, Property prop,AugeasNode mapNode,int seq) throws Exception;
+ public void updateList(PropertyDefinitionList propDef, Property prop,AugeasNode listNode,int seq) throws Exception;
+ public void updateSimple(AugeasNode parentNode, PropertyDefinitionSimple propDef,Property prop,int seq) throws Exception;
+ public void updateProperty(PropertyDefinition propDef, Property parentProp,AugeasNode parentNode,int seq) throws Exception;
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/NameMap.java b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/NameMap.java
index afe74aa..0f18027 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/NameMap.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/NameMap.java
@@ -1,9 +1,35 @@
+/*
+ * 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.rhqtransform;
-
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
public interface NameMap {
- public String getSimplePropertyName();
- public String getMapPropertyName();
- public String getListPropertyName();
-
+ public String getSimplePropertyName();
+ public String getMapPropertyName();
+ public String getListPropertyName();
+
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqAugeasMapping.java b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqAugeasMapping.java
new file mode 100644
index 0000000..043368d
--- /dev/null
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqAugeasMapping.java
@@ -0,0 +1,40 @@
+/*
+ * 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.rhqtransform;
+
+import org.rhq.augeas.AugeasComponent;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
+public interface RhqAugeasMapping {
+
+ public void updateAugeas(AugeasComponent augeasComponent,Configuration config,
+ ConfigurationDefinition configDef) throws Exception;
+ public Configuration updateConfiguration(AugeasComponent augeasComponent,ConfigurationDefinition configDef) throws Exception;
+
+}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqConfig.java b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqConfig.java
index 91f6618..9f03a06 100644
--- a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqConfig.java
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqConfig.java
@@ -1,3 +1,26 @@
+/*
+ * 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.rhqtransform;
import java.io.File;
@@ -5,53 +28,55 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-
import net.augeas.Augeas;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.rhq.augeas.config.AugeasConfiguration;
import org.rhq.augeas.config.AugeasModuleConfig;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
-
-
+/**
+ *
+ * @author Filip Drabek
+ * @author Ian Springer
+ *
+ */
public class RhqConfig implements AugeasConfiguration{
- public static final String INCLUDE_GLOBS_PROP = "configurationFilesInclusionPatterns";
- public static final String EXCLUDE_GLOBS_PROP = "configurationFilesExclusionPatterns";
- public static final String AUGEAS_MODULE_NAME_PROP = "augeasModuleName";
- private static final String AUGEAS_LOAD_PATH = "augeasLoadPath";
-
- public static final String DEFAULT_AUGEAS_ROOT_PATH = File.listRoots()[0].getPath();
-
- private final Log log = LogFactory.getLog(this.getClass());
- private List<AugeasModuleConfig> modules;
- private String loadPath;
-
- public RhqConfig(Configuration configuration) throws AugeasRhqException{
- List<String> includes = determineGlobs(configuration,INCLUDE_GLOBS_PROP);
- List<String> excludes = determineGlobs(configuration,EXCLUDE_GLOBS_PROP);
- modules = new ArrayList<AugeasModuleConfig>();
- if (includes.isEmpty())
- throw new AugeasRhqException("At least one Include glob must be defined.");
+ public static final String INCLUDE_GLOBS_PROP = "configurationFilesInclusionPatterns";
+ public static final String EXCLUDE_GLOBS_PROP = "configurationFilesExclusionPatterns";
+ public static final String AUGEAS_MODULE_NAME_PROP = "augeasModuleName";
+ private static final String AUGEAS_LOAD_PATH = "augeasLoadPath";
+
+ public static final String DEFAULT_AUGEAS_ROOT_PATH = File.listRoots()[0].getPath();
+
+ private final Log log = LogFactory.getLog(this.getClass());
+ private List<AugeasModuleConfig> modules;
+ private String loadPath;
+
+ public RhqConfig(Configuration configuration) throws AugeasRhqException{
+ List<String> includes = determineGlobs(configuration,INCLUDE_GLOBS_PROP);
+ List<String> excludes = determineGlobs(configuration,EXCLUDE_GLOBS_PROP);
+ modules = new ArrayList<AugeasModuleConfig>();
+ if (includes.isEmpty())
+ throw new AugeasRhqException("At least one Include glob must be defined.");
- AugeasModuleConfig config = new AugeasModuleConfig();
- config.setIncludedGlobs(includes);
- config.setExcludedGlobs(excludes);
- config.setLensPath(getAugeasModuleName(configuration)+".lns");
- config.setModuletName(getAugeasModuleName(configuration));
- modules.add(config);
-
- loadPath = configuration.getSimpleValue(AUGEAS_LOAD_PATH, null);
- }
-
-
+ AugeasModuleConfig config = new AugeasModuleConfig();
+ config.setIncludedGlobs(includes);
+ config.setExcludedGlobs(excludes);
+ config.setLensPath(getAugeasModuleName(configuration)+".lns");
+ config.setModuletName(getAugeasModuleName(configuration));
+ modules.add(config);
+
+ loadPath = configuration.getSimpleValue(AUGEAS_LOAD_PATH, null);
+ }
+
+
protected List<String> determineGlobs(Configuration configuration,String name) {
PropertySimple includeGlobsProp = configuration.getSimple(name);
if (includeGlobsProp== null)
- return null;
+ return null;
List<String> ret = new ArrayList<String>();
ret.addAll(getGlobList(includeGlobsProp));
@@ -60,7 +85,7 @@ public class RhqConfig implements AugeasConfiguration{
}
protected String getAugeasModuleName(Configuration configuration){
- return (configuration.getSimpleValue(AUGEAS_MODULE_NAME_PROP, null));
+ return (configuration.getSimpleValue(AUGEAS_MODULE_NAME_PROP, null));
}
public static PropertySimple getGlobList(String name, List<String> simples) {
@@ -85,10 +110,10 @@ public class RhqConfig implements AugeasConfiguration{
}
public Configuration updateConfiguration(Configuration configuration) throws AugeasRhqException{
- if (modules.isEmpty())
- throw new AugeasRhqException("Error in augeas Configuration.");
- AugeasModuleConfig tempModule = modules.get(0);
-
+ if (modules.isEmpty())
+ throw new AugeasRhqException("Error in augeas Configuration.");
+ AugeasModuleConfig tempModule = modules.get(0);
+
PropertySimple includeProps = getGlobList(INCLUDE_GLOBS_PROP, tempModule.getIncludedGlobs());
PropertySimple excludeProps = getGlobList(EXCLUDE_GLOBS_PROP, tempModule.getExcludedGlobs());
configuration.put(includeProps);
@@ -98,18 +123,18 @@ public class RhqConfig implements AugeasConfiguration{
}
public String getLoadPath() {
- return loadPath;
+ return loadPath;
}
public int getMode() {
- return Augeas.NO_MODL_AUTOLOAD;
+ return Augeas.NO_MODL_AUTOLOAD;
}
public List<AugeasModuleConfig> getModules() {
- return modules;
+ return modules;
}
public String getRootPath() {
- return DEFAULT_AUGEAS_ROOT_PATH;
+ return DEFAULT_AUGEAS_ROOT_PATH;
}
}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqTransform.java b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqTransform.java
deleted file mode 100644
index b284aa0..0000000
--- a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/RhqTransform.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.rhq.rhqtransform;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.rhq.augeas.tree.AugeasTree;
-import org.rhq.core.domain.configuration.Configuration;
-
-public class RhqTransform {
-
- private final Log log = LogFactory.getLog(this.getClass());
- private AugeasTree tree;
-
- public RhqTransform(AugeasTree tree){
- this.tree = tree;
- }
-
-
- public Configuration updateConfiguration(){
- return null;
- }
-
- public AugeasTree updateAugeas(){
- return null;
- }
-}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/AugeasToConfigurationSimple.java b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/AugeasToConfigurationSimple.java
new file mode 100644
index 0000000..51fbafd
--- /dev/null
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/AugeasToConfigurationSimple.java
@@ -0,0 +1,123 @@
+/*
+ * 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.rhqtransform.impl;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.augeas.node.AugeasNode;
+import org.rhq.augeas.tree.AugeasTree;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.rhq.rhqtransform.AugeasToConfiguration;
+import org.rhq.rhqtransform.NameMap;
+/**
+ *
+ * @author Filip Drabek
+ * @author Ian Springer
+ */
+public class AugeasToConfigurationSimple implements AugeasToConfiguration {
+ private final Log log = LogFactory.getLog(this.getClass());
+ private AugeasTree tree;
+ private NameMap nameMap;
+
+ public AugeasToConfigurationSimple(){
+
+ }
+
+ public void setTree(AugeasTree tree)
+ {
+ this.tree = tree;
+ }
+
+ public void setNameMap(NameMap nameMap){
+ this.nameMap = nameMap;
+ }
+
+ public Configuration loadResourceConfiguration(AugeasNode startNode,ConfigurationDefinition resourceConfigDef) throws Exception {
+
+ Configuration resourceConfig = new Configuration();
+
+ Collection<PropertyDefinition> propDefs = resourceConfigDef.getPropertyDefinitions().values();
+
+ for (PropertyDefinition propDef : propDefs) {
+ resourceConfig.put(loadProperty(propDef,startNode));
+ }
+
+ return resourceConfig;
+ }
+
+ public Property loadProperty(PropertyDefinition propDef, AugeasNode parentNode) throws Exception{
+
+ Property prop;
+ if (propDef instanceof PropertyDefinitionSimple) {
+ prop = createPropertySimple((PropertyDefinitionSimple) propDef, parentNode);
+ } else if (propDef instanceof PropertyDefinitionMap) {
+ prop = createPropertyMap((PropertyDefinitionMap) propDef, parentNode);
+ } else if (propDef instanceof PropertyDefinitionList) {
+ prop = createPropertyList((PropertyDefinitionList) propDef, parentNode);
+ } else {
+ throw new IllegalStateException("Unsupported PropertyDefinition subclass: " + propDef.getClass().getName());
+ }
+ return prop;
+ }
+
+ public Property createPropertySimple(PropertyDefinitionSimple propDefSimple, AugeasNode node) throws Exception{
+ Object value;
+ value = node.getValue();
+ return new PropertySimple(propDefSimple.getName(), value);
+ }
+
+ public PropertyMap createPropertyMap(PropertyDefinitionMap propDefMap, AugeasNode node) throws Exception {
+ PropertyMap propMap = new PropertyMap(propDefMap.getName());
+ for (PropertyDefinition mapEntryPropDef : propDefMap.getPropertyDefinitions().values()) {
+ propMap.put(loadProperty(mapEntryPropDef, node));
+ }
+ return propMap;
+ }
+
+ public Property createPropertyList(PropertyDefinitionList propDefList, AugeasNode node) throws Exception{
+
+ PropertyList propList = new PropertyList(propDefList.getName());
+
+ List<AugeasNode> nodes = tree.matchRelative(node, propDefList.getName());
+ PropertyDefinition listMemberPropDef = propDefList.getMemberDefinition();
+
+ for (AugeasNode listMemberNode : nodes){
+ propList.add(loadProperty(listMemberPropDef,listMemberNode));
+ }
+
+ return propList;
+ }
+}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java
new file mode 100644
index 0000000..2a23b33
--- /dev/null
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/ConfigurationToAugeasSimple.java
@@ -0,0 +1,197 @@
+/*
+ * 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.rhqtransform.impl;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.rhq.augeas.node.AugeasNode;
+import org.rhq.augeas.tree.AugeasTree;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.rhq.rhqtransform.ConfigurationToAugeas;
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
+public class ConfigurationToAugeasSimple implements ConfigurationToAugeas{
+
+ private AugeasTree tree;
+
+ public ConfigurationToAugeasSimple(){
+
+ }
+
+ public void setTree(AugeasTree tree){
+ this.tree = tree;
+ }
+
+ public void updateResourceConfiguration(AugeasNode node,ConfigurationDefinition resourceConfigDef,Configuration resourceConfig) throws Exception{
+
+ Collection<PropertyDefinition> propDefs = resourceConfigDef.getPropertyDefinitions().values();
+ PropertyMap startProp = new PropertyMap();
+
+ for (Property property : resourceConfig.getProperties())
+ startProp.put(property);
+
+ for (PropertyDefinition propDef : propDefs) {
+ updateProperty(propDef, startProp, node,0);
+ }
+ }
+
+
+ public void updateMap(PropertyDefinitionMap propDefMap, Property prop,
+ AugeasNode mapNode,int seq) throws Exception{
+
+ PropertyMap map=null;
+
+ if (prop instanceof PropertyList){
+ PropertyList lst = (PropertyList) prop;
+ List<Property> props = lst.getList();
+ map = (PropertyMap) props.get(seq-1);
+ }
+
+ if (prop instanceof PropertyMap){
+ PropertyMap mp = (PropertyMap) prop;
+ map = (PropertyMap) mp.get(propDefMap.getName());
+ }
+
+ List<AugeasNode> nodes = tree.matchRelative(mapNode, propDefMap.getName());
+
+ AugeasNode node;
+ int i=0;
+ if (nodes.isEmpty() | nodes.size()<seq)
+ {
+ node = tree.createNode(mapNode,propDefMap.getName(), null, seq);
+ nodes.add(node);
+ i = ((seq == 0)? 0 : seq-1);
+ }else
+ if (seq==0){
+ node = nodes.get(0);
+ i=0;
+ }
+ else{
+ node = nodes.get(seq-1);
+ i=seq-1;
+ }
+
+ for (PropertyDefinition mapEntryPropDef : propDefMap.getPropertyDefinitions().values()) {
+ updateProperty(mapEntryPropDef, map, nodes.get(i),0);
+ }
+
+ }
+
+
+
+ public void updateList(PropertyDefinitionList propDef, Property prop,
+ AugeasNode listNode,int seq) throws Exception{
+
+ PropertyList listProperty = null;
+ PropertyDefinition childDefinition = propDef.getMemberDefinition();
+
+ if (prop instanceof PropertyList){
+ PropertyList lst = (PropertyList) prop;
+ listProperty = (PropertyList) lst.getList().get(seq-1);
+ }
+
+ if (prop instanceof PropertyMap){
+ PropertyMap map = (PropertyMap) prop;
+ listProperty = (PropertyList) map.get(propDef.getName());
+ }
+
+ List<AugeasNode> nodes = tree.matchRelative(listNode, propDef.getName());
+ AugeasNode node = null;
+
+ if (nodes.isEmpty() | nodes.size()<seq)
+ {
+ node = tree.createNode(listNode,propDef.getName(), null, seq);
+ nodes.add(node);
+ }else
+ node = nodes.get(seq);
+
+ int i=1;
+ for (Property prp : listProperty.getList()){
+ System.out.println(prp.getName());
+ updateProperty(childDefinition, listProperty, node,i);
+ i= i+1;
+ }
+ }
+
+ public void updateSimple(AugeasNode parentNode, PropertyDefinitionSimple propDef,
+ Property prop,int seq) throws Exception{
+
+ PropertySimple simpleProp=null;
+ AugeasNode node = null;
+ if (prop instanceof PropertyList){
+ PropertyList lst = (PropertyList) prop;
+ List<Property> props = lst.getList();
+ simpleProp = (PropertySimple)props.get(seq-1);
+ }
+
+ if (prop instanceof PropertyMap){
+ PropertyMap map = (PropertyMap) prop;
+ simpleProp = (PropertySimple) map.get(propDef.getName());
+ }
+
+ List<AugeasNode> nodes = tree.matchRelative(parentNode, propDef.getName());
+
+ if (nodes.isEmpty())
+ {
+ node = tree.createNode(parentNode,propDef.getName(), null, 1);
+ }else
+ node = nodes.get(0);
+
+ node.setValue(simpleProp.getStringValue());
+
+ }
+
+
+ public void updateProperty(PropertyDefinition propDef, Property parentProp,
+ AugeasNode parentNode,int seq) throws Exception{
+
+ if (propDef instanceof PropertyDefinitionSimple) {
+ PropertyDefinitionSimple propDefSimple = (PropertyDefinitionSimple) propDef;
+ updateSimple(parentNode, propDefSimple, parentProp,seq);
+ } else if (propDef instanceof PropertyDefinitionMap) {
+ PropertyDefinitionMap propDefMap = (PropertyDefinitionMap) propDef;
+ updateMap(propDefMap, parentProp, parentNode,seq);
+ } else if (propDef instanceof PropertyDefinitionList) {
+ PropertyDefinitionList propDefList = (PropertyDefinitionList) propDef;
+ updateList(propDefList, parentProp, parentNode,seq);
+ } else {
+ throw new IllegalStateException("Unsupported PropertyDefinition subclass: "
+ + propDef.getClass().getName());
+ }
+
+ }
+}
diff --git a/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/RhqAugeasMappingSimple.java b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/RhqAugeasMappingSimple.java
new file mode 100644
index 0000000..b88ffe2
--- /dev/null
+++ b/modules/plugins/iptables/src/main/java/org/rhq/rhqtransform/impl/RhqAugeasMappingSimple.java
@@ -0,0 +1,76 @@
+/*
+ * 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.rhqtransform.impl;
+
+import org.rhq.augeas.AugeasComponent;
+import org.rhq.augeas.node.AugeasNode;
+import org.rhq.augeas.tree.AugeasTree;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.rhqtransform.AugeasToConfiguration;
+import org.rhq.rhqtransform.ConfigurationToAugeas;
+import org.rhq.rhqtransform.RhqAugeasMapping;
+/**
+ *
+ * @author Filip Drabek
+ *
+ */
+public class RhqAugeasMappingSimple implements RhqAugeasMapping{
+
+ private AugeasToConfiguration augeasToConfiguration;
+ private ConfigurationToAugeas configurationToAugeas;
+ private String moduleName;
+
+
+ public RhqAugeasMappingSimple(String moduleName){
+ this.augeasToConfiguration = new AugeasToConfigurationSimple();
+ this.configurationToAugeas = new ConfigurationToAugeasSimple();
+ this.moduleName = moduleName;
+ }
+
+ public RhqAugeasMappingSimple(AugeasToConfiguration toConfig,ConfigurationToAugeas toAugeas,String moduleName){
+ this.augeasToConfiguration = toConfig;
+ this.configurationToAugeas = toAugeas;
+ this.moduleName = moduleName;
+ }
+
+
+ public void updateAugeas(AugeasComponent component, Configuration config,
+ ConfigurationDefinition configDef) throws Exception{
+ AugeasTree tree = component.getAugeasTree(moduleName, true);
+ AugeasNode startNode = getStartNode(tree);
+ configurationToAugeas.updateResourceConfiguration(startNode, configDef, config);
+ }
+
+ public Configuration updateConfiguration(AugeasComponent augeasComponent,ConfigurationDefinition configDef) throws Exception{
+ AugeasTree tree = augeasComponent.getAugeasTree(moduleName, true);
+ AugeasNode startNode = getStartNode(tree);
+ return augeasToConfiguration.loadResourceConfiguration(startNode, configDef);
+ }
+
+ protected AugeasNode getStartNode(AugeasTree tree) throws Exception{
+ return tree.getRootNode();
+ }
+
+}
14 years, 5 months
[rhq] Branch 'alertPlugin' - modules/enterprise
by Heiko W. Rupp
modules/enterprise/server/plugins/pom.xml | 2 ++
1 file changed, 2 insertions(+)
New commits:
commit a7a472991d9fcf6adcbb7a198c1ec8d287ee0abf
Author: Heiko W. Rupp <pilhuhn(a)fedorapeople.org>
Date: Mon Nov 30 10:57:53 2009 +0100
Enable building of the alert-email sender.
diff --git a/modules/enterprise/server/plugins/pom.xml b/modules/enterprise/server/plugins/pom.xml
index 960616b..b3717bb 100644
--- a/modules/enterprise/server/plugins/pom.xml
+++ b/modules/enterprise/server/plugins/pom.xml
@@ -39,6 +39,8 @@
<module>yum</module>
<module>url</module>
<module>rhnhosted</module>
+ <module>alert-email</module>
+ <!-- <module>alert-mobicents</module> -->
</modules>
</project>
14 years, 5 months
[rhq] Branch 'alertPlugin' - 2 commits - etc/samples modules/core modules/enterprise
by Heiko W. Rupp
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);
}
14 years, 5 months
[rhq] Branch 'content' - modules/enterprise
by John Matthews
modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/PrimaryXML.java | 113 ++++++----
modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/PrimaryXMLTest.java | 43 +--
2 files changed, 93 insertions(+), 63 deletions(-)
New commits:
commit 9e728071aa9bd751aa4f1d53380d7e5032914be9
Author: John Matthews <jmatthew(a)redhat.com>
Date: Sun Nov 29 18:44:02 2009 -0500
Fixing rhnhosted package metadata for dependencies and obsoletes
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/PrimaryXML.java b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/PrimaryXML.java
index ee94f40..8638c59 100644
--- a/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/PrimaryXML.java
+++ b/modules/enterprise/server/plugins/rhnhosted/src/main/java/org/rhq/enterprise/server/plugins/rhnhosted/PrimaryXML.java
@@ -25,8 +25,10 @@ import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom.Element;
+import org.jdom.Namespace;
import org.jdom.output.XMLOutputter;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageObsoletesEntryType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageObsoletesType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageProvidesEntryType;
import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageProvidesType;
@@ -88,6 +90,8 @@ public class PrimaryXML {
final static int RPM_SENSE_GREATER = 4;
final static int RPM_SENSE_EQUAL = 8;
+ final static String RHNHOSTED_URI = "http://rhq-project.org/rhnhosted";
+
static private final Log log = LogFactory.getLog(PrimaryXML.class);
static public String getFlags(String sense) {
@@ -109,17 +113,26 @@ public class PrimaryXML {
return "";
}
+ /**
+ * Will return the 'epoch'. If the epoch is empty, then a "0" is returned
+ * to comply with yum's expectations for package metadata
+ * @param version string containing epoch:version-release
+ * @return
+ */
static public String getEpoch(String version) {
int end = version.indexOf("-");
if (end < 0) {
- return "";
+ return "0";
}
String tmp = version.substring(0, end);
int index = tmp.indexOf(":");
if (index < 0) {
- return "";
+ return "0";
}
String epoch = tmp.substring(0, index);
+ if (StringUtils.isBlank(epoch)) {
+ return "0";
+ }
return epoch;
}
@@ -154,18 +167,20 @@ public class PrimaryXML {
* @return string snippet of xml data
*/
static public String createPackageXML(RhnPackageType pkg) {
- Element top = new Element("package");
+ Namespace packageNS = Namespace.getNamespace(RHNHOSTED_URI);
+
+ Element top = new Element("package", packageNS);
top.setAttribute("type", "rpm");
- Element name = new Element("name");
+ Element name = new Element("name", packageNS);
name.setText(pkg.getName());
top.addContent(name);
- Element arch = new Element("arch");
+ Element arch = new Element("arch", packageNS);
arch.setText(pkg.getPackageArch());
top.addContent(arch);
- Element version = new Element("version");
+ Element version = new Element("version", packageNS);
version.setText(pkg.getVersion());
version.setAttribute("ver", pkg.getVersion());
version.setAttribute("rel", pkg.getRelease());
@@ -177,44 +192,44 @@ public class PrimaryXML {
version.setAttribute("epoch", epoch);
top.addContent(version);
- Element checksum = new Element("checksum");
+ Element checksum = new Element("checksum", packageNS);
checksum.setAttribute("type", "md5");
checksum.setAttribute("pkgid", "YES");
checksum.setText(pkg.getMd5Sum());
top.addContent(checksum);
- Element summary = new Element("summary");
+ Element summary = new Element("summary", packageNS);
summary.setText(pkg.getRhnPackageSummary());
top.addContent(summary);
- Element description = new Element("description");
+ Element description = new Element("description", packageNS);
description.setText(pkg.getRhnPackageDescription());
top.addContent(description);
- Element packager = new Element("packager");
+ Element packager = new Element("packager", packageNS);
//TODO: Not sure if we get 'packager' info from RHN.
packager.setText("");
top.addContent(packager);
- Element url = new Element("url");
+ Element url = new Element("url", packageNS);
//TODO: Not sure what to put for url value, don't think it applies to RHN
url.setText("");
top.addContent(url);
- Element time = new Element("time");
+ Element time = new Element("time", packageNS);
//TODO: Verify below, guessing for file/build times.
time.setAttribute("file", pkg.getLastModified());
time.setAttribute("build", pkg.getBuildTime());
top.addContent(time);
- Element size = new Element("size");
+ Element size = new Element("size", packageNS);
size.setAttribute("package", pkg.getPackageSize());
size.setAttribute("archive", pkg.getPayloadSize());
//TODO: Unsure about installed, does this need to change on server side when package is installed on a client?
size.setAttribute("installed", "");
top.addContent(size);
- Element location = new Element("location");
+ Element location = new Element("location", packageNS);
//This value can not be empty and can not contain a "?".
//It's value is ignored by the RHQ processing for yum.
//RHQ will append a series of request parameters to download the file.
@@ -223,76 +238,98 @@ public class PrimaryXML {
location.setAttribute("href", rpmName);
top.addContent(location);
- Element format = new Element("format");
+ Element format = new Element("format", packageNS);
- Element rpmLicense = new Element("license", "rpm");
+ Namespace rpmNS = Namespace.getNamespace("rpm", "http://rhq-project.org/rhnhosted");
+ Element rpmLicense = new Element("license", rpmNS);
rpmLicense.setText(pkg.getRhnPackageCopyright());
format.addContent(rpmLicense);
- Element rpmVendor = new Element("vendor", "rpm");
+ Element rpmVendor = new Element("vendor", rpmNS);
rpmVendor.setText(pkg.getRhnPackageVendor());
format.addContent(rpmVendor);
- Element rpmGroup = new Element("group", "rpm");
+ Element rpmGroup = new Element("group", rpmNS);
rpmGroup.setText(pkg.getPackageGroup());
format.addContent(rpmGroup);
- Element rpmBuildHost = new Element("buildhost", "rpm");
+ Element rpmBuildHost = new Element("buildhost", rpmNS);
rpmBuildHost.setText(pkg.getBuildHost());
format.addContent(rpmBuildHost);
- Element rpmSourceRPM = new Element("sourcerpm", "rpm");
+ Element rpmSourceRPM = new Element("sourcerpm", rpmNS);
rpmSourceRPM.setText(pkg.getSourceRpm());
format.addContent(rpmSourceRPM);
- Element rpmHeaderRange = new Element("header-range", "rpm");
+ Element rpmHeaderRange = new Element("header-range", rpmNS);
rpmHeaderRange.setAttribute("start", pkg.getRhnPackageHeaderStart());
rpmHeaderRange.setAttribute("end", pkg.getRhnPackageHeaderEnd());
format.addContent(rpmHeaderRange);
- Element rpmProvides = new Element("provides", "rpm");
+ Element rpmProvides = new Element("provides", rpmNS);
RhnPackageProvidesType provides_type = pkg.getRhnPackageProvides();
if (provides_type != null) {
List<RhnPackageProvidesEntryType> provides = provides_type.getRhnPackageProvidesEntry();
for (RhnPackageProvidesEntryType provEntry : provides) {
- Element entry = new Element("entry", "rpm");
+ Element entry = new Element("entry", rpmNS);
entry.setAttribute("name", provEntry.getName());
- entry.setAttribute("flags", getFlags(provEntry.getSense()));
- entry.setAttribute("epoch", getEpoch(provEntry.getVersion()));
- entry.setAttribute("ver", getVersion(provEntry.getVersion()));
- entry.setAttribute("rel", getRelease(provEntry.getVersion()));
+ String flags = getFlags(provEntry.getSense());
+ if (!StringUtils.isBlank(flags)) {
+ entry.setAttribute("flags", flags);
+ String provEpoch = getEpoch(provEntry.getVersion());
+ entry.setAttribute("epoch", provEpoch);
+ String provVer = getVersion(provEntry.getVersion());
+ entry.setAttribute("ver", provVer);
+ String provRel = getRelease(provEntry.getVersion());
+ entry.setAttribute("rel", getRelease(provEntry.getVersion()));
+ }
rpmProvides.addContent(entry);
}
}
format.addContent(rpmProvides);
- Element rpmRequires = new Element("requires", "rpm");
+ Element rpmRequires = new Element("requires", rpmNS);
RhnPackageRequiresType requires_type = pkg.getRhnPackageRequires();
if (requires_type != null) {
List<RhnPackageRequiresEntryType> requires = requires_type.getRhnPackageRequiresEntry();
for (RhnPackageRequiresEntryType reqEntry : requires) {
- Element entry = new Element("entry", "rpm");
+ Element entry = new Element("entry", rpmNS);
entry.setAttribute("name", reqEntry.getName());
- entry.setAttribute("flags", getFlags(reqEntry.getSense()));
- entry.setAttribute("epoch", getEpoch(reqEntry.getVersion()));
- entry.setAttribute("ver", getVersion(reqEntry.getVersion()));
- entry.setAttribute("rel", getRelease(reqEntry.getVersion()));
+ String flags = getFlags(reqEntry.getSense());
+ if (!StringUtils.isBlank(flags)) {
+ entry.setAttribute("flags", flags);
+ String reqEpoch = getEpoch(reqEntry.getVersion());
+ entry.setAttribute("epoch", reqEpoch);
+ String reqVer = getVersion(reqEntry.getVersion());
+ entry.setAttribute("ver", reqVer);
+ String reqRel = getRelease(reqEntry.getVersion());
+ entry.setAttribute("rel", getRelease(reqEntry.getVersion()));
+ }
rpmRequires.addContent(entry);
}
}
format.addContent(rpmRequires);
- Element rpmConflicts = new Element("conflicts", "rpm");
+ Element rpmConflicts = new Element("conflicts", rpmNS);
rpmConflicts.setText(pkg.getRhnPackageConflicts());
format.addContent(rpmConflicts);
- Element rpmObsoletes = new Element("obsoletes", "rpm");
+ Element rpmObsoletes = new Element("obsoletes", rpmNS);
RhnPackageObsoletesType obs_type = pkg.getRhnPackageObsoletes();
if (obs_type != null) {
List<Serializable> obsoletes = obs_type.getContent();
- for (Serializable obsEntry : obsoletes) {
- Element entry = new Element("entry", "rpm");
- entry.setAttribute("name", obsEntry.toString());
+ for (Serializable s : obsoletes) {
+ RhnPackageObsoletesEntryType obsEntry = (RhnPackageObsoletesEntryType) s;
+ Element entry = new Element("entry", rpmNS);
+ entry.setAttribute("name", obsEntry.getName());
+ String obsVer = obsEntry.getVersion();
+ if (!StringUtils.isBlank(obsVer)) {
+ entry.setAttribute("version", obsVer);
+ }
+ String obsFlags = getFlags(obsEntry.getSense());
+ if (!StringUtils.isBlank(obsFlags)) {
+ entry.setAttribute("flags", obsFlags);
+ }
rpmObsoletes.addContent(entry);
}
}
diff --git a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/PrimaryXMLTest.java b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/PrimaryXMLTest.java
index dd6acab..e979545 100644
--- a/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/PrimaryXMLTest.java
+++ b/modules/enterprise/server/plugins/rhnhosted/src/test/java/org/rhq/enterprise/server/plugins/rhnhosted/PrimaryXMLTest.java
@@ -18,26 +18,26 @@
*/
package org.rhq.enterprise.server.plugins.rhnhosted;
-import java.util.List;
import java.io.ByteArrayInputStream;
+import java.util.List;
import junit.framework.TestCase;
-import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageType;
-import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageProvidesEntryType;
-import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageProvidesType;
-import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageRequiresType;
-import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageRequiresEntryType;
import org.apache.commons.lang.StringUtils;
-import org.jdom.input.SAXBuilder;
import org.jdom.Document;
import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageProvidesEntryType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageProvidesType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageRequiresEntryType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageRequiresType;
+import org.rhq.enterprise.server.plugins.rhnhosted.xml.RhnPackageType;
/**
* @author John Matthews
*/
-public class PrimaryXMLTest extends TestCase
-{
+public class PrimaryXMLTest extends TestCase {
protected RhnPackageType getTestRhnPackage() {
RhnPackageType pkg = new RhnPackageType();
pkg.setName("gnome-user-docs");
@@ -60,7 +60,6 @@ public class PrimaryXMLTest extends TestCase
pkg.setRhnPackageHeaderStart("440");
pkg.setRhnPackageHeaderEnd("97656");
-
RhnPackageProvidesType provides_type = new RhnPackageProvidesType();
List<RhnPackageProvidesEntryType> provides = provides_type.getRhnPackageProvidesEntry();
RhnPackageProvidesEntryType prov = new RhnPackageProvidesEntryType();
@@ -83,8 +82,7 @@ public class PrimaryXMLTest extends TestCase
return pkg;
}
- public void testGetFlags()
- {
+ public void testGetFlags() {
String value = PrimaryXML.getFlags("8");
assert StringUtils.equals(value, "EQ");
@@ -102,24 +100,21 @@ public class PrimaryXMLTest extends TestCase
}
- public void testGetEpoch()
- {
+ public void testGetEpoch() {
String value = PrimaryXML.getEpoch("4:98.9-4");
assert StringUtils.equals(value, "4");
value = PrimaryXML.getEpoch("98.9-4");
- assert StringUtils.equals(value, "");
+ assert StringUtils.equals(value, "0");
value = PrimaryXML.getEpoch("");
- assert StringUtils.equals(value, "");
+ assert StringUtils.equals(value, "0");
value = PrimaryXML.getEpoch("98.9-45:3.f");
- assert StringUtils.equals(value, "");
+ assert StringUtils.equals(value, "0");
}
-
- public void testGetVersion()
- {
+ public void testGetVersion() {
String value = PrimaryXML.getVersion("4:98.9-4");
assert StringUtils.equals(value, "98.9");
@@ -131,8 +126,7 @@ public class PrimaryXMLTest extends TestCase
}
- public void testGetRelease()
- {
+ public void testGetRelease() {
String value = PrimaryXML.getRelease("4:98.9-4");
assert StringUtils.equals(value, "4");
@@ -145,9 +139,8 @@ public class PrimaryXMLTest extends TestCase
value = PrimaryXML.getRelease("98.9");
assert StringUtils.equals(value, "");
}
-
- public void testCreatePackageXML() throws Exception
- {
+
+ public void testCreatePackageXML() throws Exception {
RhnPackageType pkg = getTestRhnPackage();
String xml = PrimaryXML.createPackageXML(pkg);
System.out.println(xml);
14 years, 5 months
[rhq] Branch 'pc' - modules/core modules/enterprise
by mazz
modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java | 15 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java | 31 ++--
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java | 6
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/GenericServerPluginTest.java | 76 ++++++++--
4 files changed, 97 insertions(+), 31 deletions(-)
New commits:
commit fff2771d008518f57516efb2607e9b1704973fb3
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 13:13:48 2009 -0500
now that we have the type in the data model, we can get all installed plugins grouped by their type
this was needed for the UI
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
index aa06ea9..426b62e 100644
--- 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
@@ -50,7 +50,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " WHERE p.name = :name)"), //
// helps you determine which installed plugins are enabled or disabled
- @NamedQuery(name = ServerPlugin.QUERY_GET_NAMES_BY_ENABLED, query = "" //
+ @NamedQuery(name = ServerPlugin.QUERY_GET_KEYS_BY_ENABLED, query = "" //
+ " SELECT new org.rhq.core.domain.plugin.PluginKey( " //
+ " p.deployment, " //
+ " p.type, " //
@@ -159,6 +159,16 @@ import org.rhq.core.domain.configuration.Configuration;
+ " LEFT JOIN p.scheduledJobsConfiguration " //
+ " WHERE p.status = 'INSTALLED' "), //
+ // 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 = "" //
+ + " SELECT new org.rhq.core.domain.plugin.PluginKey( " //
+ + " p.deployment, " //
+ + " p.type, " //
+ + " p.name) " //
+ + " FROM ServerPlugin AS p " //
+ + " 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 " //
@@ -171,11 +181,12 @@ 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_GET_KEYS_BY_ENABLED = "ServerPlugin.queryGetKeysByEnabled";
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 QUERY_FIND_ALL_INSTALLED_KEYS = "ServerPlugin.findAllInstalledKeys";
public static final String UPDATE_PLUGINS_ENABLED_BY_IDS = "ServerPlugin.updatePluginsEnabledByIds";
@JoinColumn(name = "JOBS_CONFIG_ID", referencedColumnName = "ID")
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 b3808ab..5de2a0d 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
@@ -130,7 +130,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public List<PluginKey> getServerPluginKeysByEnabled(boolean enabled) {
- Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_NAMES_BY_ENABLED);
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_KEYS_BY_ENABLED);
query.setParameter("enabled", Boolean.valueOf(enabled));
return query.getResultList();
}
@@ -425,24 +425,25 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return status;
}
- // we need this method to talk to the master plugin container because the plugin data model
- // does not contain information as to what type a plugin is. It only has information about
- // where the plugin is deployed (agent or server) but it doesn't indicate if a plugin
- // 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<PluginKey>> getAllPluginsGroupedByType() {
+ public Map<ServerPluginType, List<PluginKey>> getInstalledServerPluginsGroupedByType() {
+ Query q = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_ALL_INSTALLED_KEYS);
+ List<PluginKey> keys = q.getResultList(); // all installed plugins, both enabled and disabled
+
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<PluginKey> plugins = master.getAllPluginsByPluginType(type);
- allPlugins.put(type, plugins);
+ for (PluginKey key : keys) {
+ try {
+ ServerPluginType type = new ServerPluginType(key.getPluginType());
+ List<PluginKey> knownPluginsForType = allPlugins.get(type);
+ if (knownPluginsForType == null) {
+ knownPluginsForType = new ArrayList<PluginKey>();
+ allPlugins.put(type, knownPluginsForType);
+ }
+ knownPluginsForType.add(key);
+ } catch (Exception e) {
+ log.warn("Invalid plugin key found [" + key + "]", e);
}
}
-
return allPlugins;
}
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 a1e0a40..98957d8 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
@@ -178,11 +178,9 @@ public interface ServerPluginsLocal {
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.
+ * This will return a map containing all installed plugins that are both enabled and disabled.
*
* @return keys of all enabled and disabled plugins, keyed on their types
*/
- Map<ServerPluginType, List<PluginKey>> getAllPluginsGroupedByType();
+ Map<ServerPluginType, List<PluginKey>> getInstalledServerPluginsGroupedByType();
}
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 48a5db7..450f4db 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
@@ -33,6 +33,9 @@ import org.testng.annotations.Test;
import org.rhq.core.domain.configuration.Configuration;
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.stream.StreamUtil;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
import org.rhq.enterprise.server.plugin.pc.ServerPluginType;
@@ -43,6 +46,8 @@ import org.rhq.enterprise.server.plugin.pc.generic.TestLifecycleListener.Lifecyc
import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.util.LookupUtil;
import org.rhq.enterprise.server.xmlschema.ScheduledJobDefinition;
+import org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorUtil;
+import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.generic.GenericPluginDescriptorType;
@Test
@@ -82,21 +87,72 @@ public class GenericServerPluginTest extends AbstractEJB3Test {
List<ScheduledJobDefinition> schedules = component.context.getSchedules();
assert schedules == null;
- ServerPluginsLocal serverPluginsLocal = LookupUtil.getServerPlugins();
- Map<ServerPluginType, List<PluginKey>> map = serverPluginsLocal.getAllPluginsGroupedByType();
- assert map.size() == 1;
- List<PluginKey> pluginNames = map.get(new ServerPluginType(GenericPluginDescriptorType.class));
- assert pluginNames.size() == 1;
- assert pluginNames.get(0).getPluginName().equals("TestSimpleGenericPlugin");
-
// make sure everything is shutdown
this.pluginService.stopMasterPluginContainer();
assert pc.state == State.UNINITIALIZED;
assert component.state == LifecycleState.UNINITIALIZED;
+ }
+
+ public void testGetInstalledPlugins() throws Exception {
+ File jar = createPluginJar("testSimpleGenericPlugin.jar", "serverplugins/simple-generic-serverplugin.xml");
+ ServerPluginType type = new ServerPluginType(GenericPluginDescriptorType.class);
+
+ ServerPluginDescriptorType descriptor = ServerPluginDescriptorUtil.loadPluginDescriptorFromUrl(jar.toURI()
+ .toURL());
+
+ ServerPlugin plugin = new ServerPlugin(0, descriptor.getName(), jar.getName(), descriptor.getDisplayName(),
+ true, PluginStatusType.INSTALLED, descriptor.getDescription(), null, MessageDigestGenerator
+ .getDigestString(jar), descriptor.getVersion(), descriptor.getApiVersion(), null, null, type
+ .stringify(), System.currentTimeMillis(), System.currentTimeMillis());
+
+ ServerPluginsLocal serverPluginsLocal = LookupUtil.getServerPlugins();
+ Map<ServerPluginType, List<PluginKey>> original = serverPluginsLocal.getInstalledServerPluginsGroupedByType();
+ serverPluginsLocal.registerServerPlugin(LookupUtil.getSubjectManager().getOverlord(), plugin, jar);
+
+ try {
+ Map<ServerPluginType, List<PluginKey>> map = serverPluginsLocal.getInstalledServerPluginsGroupedByType();
+ List<PluginKey> pluginKeys = map.get(type);
+
+ if (original.containsKey(type)) {
+ assert map.size() == original.size();
+ assert pluginKeys.size() == original.get(type).size() + 1;
+ } else {
+ assert map.size() == original.size() + 1;
+ assert pluginKeys.size() == 1;
+ }
+ boolean got_it = false;
+ for (PluginKey pluginKey : pluginKeys) {
+ if (pluginKey.getPluginName().equals("TestSimpleGenericPlugin")) {
+ got_it = true;
+ break;
+ }
+ }
+ assert got_it == true;
+ } finally {
+ // make sure we clean this up, even on error
+ serverPluginsLocal.purgeServerPlugin(LookupUtil.getSubjectManager().getOverlord(), new PluginKey(plugin));
+ }
- // with the master down, this method should return an empty map
- map = serverPluginsLocal.getAllPluginsGroupedByType();
- assert map.size() == 0;
+ // test that purge really deleted it
+ Map<ServerPluginType, List<PluginKey>> map = serverPluginsLocal.getInstalledServerPluginsGroupedByType();
+ List<PluginKey> pluginKeys = map.get(type);
+
+ assert map.size() == original.size();
+ if (pluginKeys == null) {
+ assert !original.containsKey(type) : "we dont have any plugins of this type, neither should original";
+ } else {
+ assert pluginKeys.size() == original.get(type).size();
+ boolean got_it = false;
+ for (PluginKey pluginKey : pluginKeys) {
+ if (pluginKey.getPluginName().equals("TestSimpleGenericPlugin")) {
+ got_it = true;
+ break;
+ }
+ }
+ assert got_it == false : "we still have the plugin, but it should have been purged";
+ }
+
+ return;
}
private File createPluginJar(String jarName, String descriptorXmlFilename) throws Exception {
14 years, 5 months
[rhq] modules/enterprise
by mazz
modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
New commits:
commit fa1d59755426ed42ac85b2a36a874dc12aeeed75
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 12:05:47 2009 -0500
opps... forgot to fix the control.jsp to call the new API
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))
14 years, 5 months
[rhq] Branch 'pc' - modules/enterprise
by mazz
modules/enterprise/gui/portal-war/src/main/webapp/admin/test/control.jsp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
New commits:
commit fa1d59755426ed42ac85b2a36a874dc12aeeed75
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 12:05:47 2009 -0500
opps... forgot to fix the control.jsp to call the new API
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))
14 years, 5 months
[rhq] 8 commits - etc/samples modules/core modules/enterprise
by mazz
etc/samples/custom-serverplugin/src/main/java/org/custom/MyLifecycleListener.java | 2
modules/core/dbutils/pom.xml | 2
modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml | 4
modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml | 17
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 | 504 -------
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 | 49
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java | 24
modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml | 4
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 | 4
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml | 5
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 | 134 --
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java | 59
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 | 61
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/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/xml-schemas/src/main/java/org/rhq/enterprise/server/xmlschema/ServerPluginDescriptorUtil.java | 4
33 files changed, 2004 insertions(+), 883 deletions(-)
New commits:
commit 46b2dc39e618652087bbd0c3b6b8f4cddefb4df2
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 11:19:32 2009 -0500
use != to check for deployment type inequality
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
index 0d28937..5240a65 100644
--- 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
@@ -145,7 +145,7 @@ public class PluginKey {
return false;
}
- if (!deployment.equals(other.deployment)) {
+ if (deployment != other.deployment) {
return false;
}
return true;
commit 2838e6492a4db53a5cb066d599d7176f86138303
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 11:04:56 2009 -0500
plugin configs are now only valid for server plugins. do the check on the UI bean def, since that will be null for agent plugins
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..5e32efa 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
@@ -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>
commit d2e2d1e98759c5fb5d2fd678c3d01b829e315270
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 02:17:25 2009 -0500
first attempt to see what this looks like if i use plugin key vs. just plugin name in API
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/PluginKey.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
index 4f7809d..0d28937 100644
--- 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
@@ -33,13 +33,13 @@ public class PluginKey {
* 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 an empty string to signify this.
+ * 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, "", pluginName);
+ return new PluginKey(PluginDeploymentType.AGENT, null, pluginName);
}
/**
@@ -58,12 +58,33 @@ public class PluginKey {
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) {
- throw new IllegalArgumentException("pluginType==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);
@@ -99,7 +120,7 @@ public class PluginKey {
final int prime = 31;
int result = 1;
result = prime * result + deployment.hashCode();
- result = prime * result + pluginType.hashCode();
+ result = prime * result + ((pluginType == null) ? 0 : pluginType.hashCode());
result = prime * result + pluginName.hashCode();
return result;
}
@@ -116,8 +137,13 @@ public class PluginKey {
if (!pluginName.equals(other.pluginName)) {
return false;
}
- if (!pluginType.equals(other.pluginType)) {
+ if (pluginType == null) {
+ if (other.pluginType != null) {
+ return false;
+ }
+ } else if (!pluginType.equals(other.pluginType)) {
return false;
+
}
if (!deployment.equals(other.deployment)) {
return false;
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
index d233365..aa06ea9 100644
--- 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
@@ -23,6 +23,7 @@
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;
@@ -50,7 +51,10 @@ import org.rhq.core.domain.configuration.Configuration;
// helps you determine which installed plugins are enabled or disabled
@NamedQuery(name = ServerPlugin.QUERY_GET_NAMES_BY_ENABLED, query = "" //
- + " SELECT p.name " //
+ + " 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' "), //
@@ -71,6 +75,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.ampsVersion, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM ServerPlugin AS p " //
@@ -95,6 +100,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.ampsVersion, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM ServerPlugin AS p " //
@@ -120,6 +126,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.ampsVersion, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM ServerPlugin AS p " //
@@ -144,6 +151,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.ampsVersion, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM ServerPlugin AS p " //
@@ -178,6 +186,9 @@ public class ServerPlugin extends AbstractPlugin {
@OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
private Configuration pluginConfiguration;
+ @Column(name = "PTYPE")
+ private String type;
+
public ServerPlugin() {
super();
setDeployment(PluginDeploymentType.SERVER);
@@ -200,12 +211,13 @@ public class ServerPlugin extends AbstractPlugin {
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, long ctime, long mtime) {
+ 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
@@ -223,7 +235,7 @@ public class ServerPlugin extends AbstractPlugin {
* @return the configuration associated with the plugin itself
*/
public Configuration getPluginConfiguration() {
- return pluginConfiguration;
+ return this.pluginConfiguration;
}
public void setPluginConfiguration(Configuration pluginConfiguration) {
@@ -236,13 +248,26 @@ public class ServerPlugin extends AbstractPlugin {
* @return scheduled job configuration for jobs that the plugin defined.
*/
public Configuration getScheduledJobsConfiguration() {
- return scheduledJobsConfiguration;
+ 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) {
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 31d4188..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
@@ -26,6 +26,7 @@ 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;
@@ -41,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;
@@ -52,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 type) {
- this.type = type;
+ public void setType(PluginDeploymentType deployment) {
+ this.deployment = deployment;
+ }
+
+ public String getPluginType() {
+ return this.pluginType;
+ }
+
+ public void setPluginType(String pluginType) {
+ this.pluginType = pluginType;
}
@Factory(value = "plugin", autoCreate = true, scope = ScopeType.PAGE)
public AbstractPlugin lookupPlugin() {
- if (this.type == PluginDeploymentType.AGENT) {
+ 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();
- ServerPlugin 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 2f7d73a..9351385 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
@@ -35,6 +35,7 @@ import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
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;
@@ -51,7 +52,7 @@ 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
@@ -67,6 +68,14 @@ public class InstalledPluginUIBean {
this.plugin = plugin;
}
+ public ServerPlugin getServerPlugin() {
+ return (ServerPlugin) this.plugin;
+ }
+
+ public void setServerPlugin(ServerPlugin plugin) {
+ this.plugin = plugin;
+ }
+
public ConfigurationDefinition getPluginConfigurationDefinition() {
return this.pluginConfigurationDefinition;
}
@@ -80,14 +89,14 @@ 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(),
- (ServerPlugin) plugin);
+ 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,
@@ -105,7 +114,8 @@ public class InstalledPluginUIBean {
if (this.plugin.getDeployment() == PluginDeploymentType.SERVER) {
try {
ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
- ServerPluginDescriptorType descriptor = serverPluginsBean.getServerPluginDescriptor(pluginName);
+ 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
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..37b3bad 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
@@ -33,8 +33,8 @@
<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>
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-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/plugin/ServerPluginScanner.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
index de8857b..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,7 +51,7 @@ 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.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;
@@ -59,6 +59,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.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;
@@ -160,7 +161,6 @@ public class ServerPluginScanner {
log.info("Registering RHQ server plugin [" + pluginName + "], version " + version);
ServerPlugin plugin = new ServerPlugin(pluginName, pluginFile.getName());
- plugin.setDeployment(PluginDeploymentType.SERVER);
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.");
@@ -451,7 +452,6 @@ public class ServerPluginScanner {
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
}
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 6839cfc..b3808ab 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
@@ -132,7 +132,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
public List<PluginKey> getServerPluginKeysByEnabled(boolean enabled) {
Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_NAMES_BY_ENABLED);
query.setParameter("enabled", Boolean.valueOf(enabled));
- return xquery.getResultList(); // TODO this is a list of strings, not plugin keys!!!
+ return query.getResultList();
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
@@ -171,8 +171,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
} catch (Exception ignore) {
}
if (doomedPlugin != null) {
- String pluginName = doomedPlugin.getName();
- PluginKey pluginKey = ;
+ PluginKey pluginKey = new PluginKey(doomedPlugin);
doomedPlugins.add(pluginKey);
if (master != null) {
AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginKey);
@@ -215,8 +214,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
} catch (Exception ignore) {
}
if (doomedPlugin != null) {
- String pluginName = doomedPlugin.getName();
- PluginKey pluginKey = ;
+ PluginKey pluginKey = new PluginKey(doomedPlugin);
doomedPlugins.add(pluginKey);
if (master != null) {
AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginKey);
@@ -307,7 +305,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
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
}
@@ -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.");
@@ -401,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());
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 a4bd9b1..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
@@ -311,7 +311,7 @@ public class ServerPluginManager {
protected ServerPlugin getPlugin(ServerPluginEnvironment pluginEnv) {
// get the plugin data from the database
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
- ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey().getPluginName());
+ ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey());
return plugin;
}
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 cd1921b..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
@@ -35,11 +35,14 @@ 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.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
@@ -100,14 +103,16 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
public void testGetPlugins() throws Exception {
ServerPlugin p1 = registerPlugin(1);
ServerPlugin 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;
-
- ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ 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);
@@ -137,7 +142,9 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
public void testUpdatePlugins() throws Exception {
ServerPlugin p1 = registerPlugin(1);
- p1 = this.serverPluginsBean.getServerPlugin(p1.getName());
+ PluginKey p1key = new PluginKey(p1);
+
+ p1 = this.serverPluginsBean.getServerPlugin(p1key);
p1 = this.serverPluginsBean.getServerPluginRelationships(p1);
ServerPlugin p1update = this.serverPluginsBean.updateServerPluginExceptContent(getOverlord(), p1);
@@ -156,39 +163,41 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
public void testDisableEnablePlugins() throws Exception {
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
- ServerPlugin 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,63 +207,77 @@ 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;
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;
+ 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;
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;
+ 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
@@ -264,16 +287,16 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
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);
@@ -287,21 +310,21 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
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 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",
- 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,6 +333,7 @@ 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;
}
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 cd95053..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
@@ -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;
@@ -198,8 +199,9 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
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, System.currentTimeMillis(), System.currentTimeMillis());
+ .getVersion(), pluginDescriptor.getVersion(), pluginConfig, scheduledJobsConfig,
+ new ServerPluginType(pluginDescriptor).stringify(), System.currentTimeMillis(), System
+ .currentTimeMillis());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
commit 2bb5e6e39a106fe9a3f023b0216651954d50f3a6
Merge: b038b80... 3e3f767...
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 00:21:30 2009 -0500
Merge branch 'plugin-name-refactor' into pc2
Conflicts:
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
diff --cc modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
index 5bee8c0,aa75432..6839cfc
--- 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 +46,10 @@@ import org.apache.commons.logging.LogFa
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;
@@@ -83,15 -84,23 +84,17 @@@ public class ServerPluginsBean implemen
return q.getResultList();
}
- public ServerPlugin getServerPlugin(String name) {
- public Plugin getServerPlugin(PluginKey key) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
++ public ServerPlugin getServerPlugin(PluginKey key) {
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
- query.setParameter("name", name);
+ query.setParameter("name", key.getPluginName());
- Plugin plugin = (Plugin) query.getSingleResult();
- if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin [" + key + "] is not a server plugin");
- }
+ ServerPlugin plugin = (ServerPlugin) query.getSingleResult();
return plugin;
}
- public Plugin getServerPluginRelationships(Plugin plugin) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
+ public ServerPlugin getServerPluginRelationships(ServerPlugin plugin) {
- plugin = getServerPlugin(plugin.getName()); // refresh all but the content field
++ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", plugin.getName());
- plugin = (Plugin) query.getSingleResult();
- if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin [" + plugin.getName() + "] is not a server plugin");
- }
++ plugin = (ServerPlugin) query.getSingleResult();
Configuration config = plugin.getPluginConfiguration();
if (config != null) {
@@@ -117,8 -126,9 +120,8 @@@
- query.setParameter("type", PluginDeploymentType.SERVER);
return query.getResultList();
}
- public ServerPluginDescriptorType getServerPluginDescriptor(String pluginName) throws Exception {
- ServerPlugin plugin = getServerPlugin(pluginName);
+ public ServerPluginDescriptorType getServerPluginDescriptor(PluginKey pluginKey) throws Exception {
- Plugin plugin = getServerPlugin(pluginKey);
++ ServerPlugin plugin = getServerPlugin(pluginKey);
File pluginsDir = LookupUtil.getServerPluginService().getServerPluginsDirectory();
File pluginJar = new File(pluginsDir, plugin.getPath());
URL url = pluginJar.toURI().toURL();
@@@ -126,10 -136,11 +129,10 @@@
return descriptor;
}
- public List<String> getServerPluginNamesByEnabled(boolean enabled) {
+ public List<PluginKey> getServerPluginKeysByEnabled(boolean enabled) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE);
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_NAMES_BY_ENABLED);
query.setParameter("enabled", Boolean.valueOf(enabled));
- return query.getResultList();
- query.setParameter("type", PluginDeploymentType.SERVER);
+ return xquery.getResultList(); // TODO this is a list of strings, not plugin keys!!!
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
@@@ -159,12 -170,12 +162,12 @@@
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) {
@@@ -202,12 -214,12 +206,12 @@@
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) {
@@@ -348,16 -361,17 +353,16 @@@
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void purgeServerPlugin(Subject subject, String pluginName) {
+ public void purgeServerPlugin(Subject subject, PluginKey pluginKey) {
- Query q = this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ Query q = this.entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
- q.setParameter("name", pluginName);
+ q.setParameter("name", pluginKey.getPluginName());
- q.setParameter("type", PluginDeploymentType.SERVER);
- Plugin doomed = (Plugin) q.getSingleResult();
+ 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;
}
@@@ -409,9 -428,10 +414,9 @@@
return plugin;
}
- public PluginStatusType getServerPluginStatus(String pluginName) {
+ public PluginStatusType getServerPluginStatus(PluginKey pluginKey) {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ Query q = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_STATUS_BY_NAME);
- q.setParameter("name", pluginName);
+ q.setParameter("name", pluginKey.getPluginName());
- q.setParameter("type", PluginDeploymentType.SERVER);
PluginStatusType status;
try {
status = (PluginStatusType) q.getSingleResult();
diff --cc modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
index e5375c4,2f84337..a1e0a40
--- 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,8 -8,9 +8,9 @@@ 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;
@@@ -25,15 -26,15 +26,15 @@@ public interface ServerPluginsLocal
*
* @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
*/
- ServerPlugin getServerPlugin(String name);
- Plugin getServerPlugin(PluginKey key);
++ ServerPlugin getServerPlugin(PluginKey key);
/**
* Methods in this object that return plugins normally do not include
@@@ -54,12 -55,12 +55,12 @@@
* @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.
+ * Given a plugin key, returns the descriptor for that plugin.
*
- * @param pluginName
+ * @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
*/
diff --cc modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
index 43e07fc,350ca61..a4bd9b1
--- 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
@@@ -306,12 -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();
- ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginName());
- Plugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey().getPluginName());
++ ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey().getPluginName());
return plugin;
}
diff --cc modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
index 44d03c3,e80ed1f..cd95053
--- 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,8 -27,10 +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;
@@@ -194,11 -196,11 +195,11 @@@ public class TestGenericServerPluginSer
}
File pluginFile = new File(env.getPluginUrl().toURI());
- ServerPlugin plugin = new ServerPlugin(0, env.getPluginName(), pluginFile.getName(), pluginDescriptor
- .getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor.getDescription(), "",
- MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor.getVersion(), pluginDescriptor
- .getVersion(), pluginConfig, scheduledJobsConfig, System.currentTimeMillis(), System
- .currentTimeMillis());
- Plugin plugin = new Plugin(0, env.getPluginKey().getPluginName(), pluginFile.getName(),
++ ServerPlugin plugin = new ServerPlugin(0, env.getPluginKey().getPluginName(), pluginFile.getName(),
+ pluginDescriptor.getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor
+ .getDescription(), "", MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor
- .getVersion(), pluginDescriptor.getVersion(), PluginDeploymentType.SERVER, pluginConfig,
++ .getVersion(), pluginDescriptor.getVersion(), pluginConfig,
+ scheduledJobsConfig, System.currentTimeMillis(), System.currentTimeMillis());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
commit b038b80610293eb628ea5f8c34eb14fce7e2edd5
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 27 23:42:16 2009 -0500
fix copyright
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
index ff68860..6ff9cb5 100644
--- 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
@@ -4,17 +4,21 @@
* 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.
+ * 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 for more details.
+ * 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
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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;
@@ -36,8 +40,6 @@ import javax.persistence.PrePersist;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
-import org.jetbrains.annotations.NotNull;
-
import org.rhq.core.util.MessageDigestGenerator;
/**
@@ -113,7 +115,7 @@ public class AbstractPlugin implements Serializable {
* @param name the logical name of the plugin
* @param path the actual filename of the plugin jar (see {@link #getPath()})
*/
- public AbstractPlugin(@NotNull String name, String path) {
+ public AbstractPlugin(String name, String path) {
this.name = name;
this.path = path;
}
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 bf1b438..b3c370d 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
@@ -27,8 +27,6 @@ import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
-import org.jetbrains.annotations.NotNull;
-
/**
* An agent plugin.
*
@@ -180,7 +178,7 @@ public class Plugin extends AbstractPlugin {
setDeployment(PluginDeploymentType.AGENT);
}
- public Plugin(@NotNull String name, String path) {
+ public Plugin(String name, String path) {
super(name, path);
setDeployment(PluginDeploymentType.AGENT);
}
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
index bb897b1..d233365 100644
--- 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
@@ -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
@@ -31,8 +31,6 @@ import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
-import org.jetbrains.annotations.NotNull;
-
import org.rhq.core.domain.configuration.Configuration;
/**
@@ -185,7 +183,7 @@ public class ServerPlugin extends AbstractPlugin {
setDeployment(PluginDeploymentType.SERVER);
}
- public ServerPlugin(@NotNull String name, String path) {
+ public ServerPlugin(String name, String path) {
super(name, path);
setDeployment(PluginDeploymentType.SERVER);
}
commit 816db190b25e5b1b8169fdae865f9e60ce371a3f
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 27 19:54:33 2009 -0500
finish JPA discriminator refactoring so there is now ServerPlugin entity (Plugin entity is now only for agent plugins)
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
index 757fa6a..ff68860 100644
--- 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
@@ -22,27 +22,22 @@ 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.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.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;
/**
@@ -69,14 +64,6 @@ public class AbstractPlugin implements Serializable {
@Enumerated(EnumType.STRING)
private PluginDeploymentType deployment;
- @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;
@@ -172,28 +159,10 @@ public class AbstractPlugin implements Serializable {
* 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 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, Configuration pluginConfig, Configuration scheduledJobsConfig, long ctime,
- long mtime) {
+ PluginDeploymentType deployment, long ctime, long mtime) {
this.id = id;
this.name = name;
this.path = path;
@@ -206,8 +175,6 @@ public class AbstractPlugin implements Serializable {
this.version = version;
this.ampsVersion = ampsVersion;
this.deployment = deployment;
- this.pluginConfiguration = pluginConfig;
- this.scheduledJobsConfiguration = scheduledJobsConfig;
this.ctime = ctime;
this.mtime = mtime;
}
@@ -387,32 +354,6 @@ public class AbstractPlugin implements Serializable {
}
/**
- * 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).
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 1b4c693..bf1b438 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
@@ -29,8 +29,6 @@ import javax.persistence.NamedQuery;
import org.jetbrains.annotations.NotNull;
-import org.rhq.core.domain.configuration.Configuration;
-
/**
* An agent plugin.
*
@@ -67,14 +65,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " 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.status = 'INSTALLED' "), //
@@ -92,14 +85,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " 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' "), //
@@ -118,14 +106,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " 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 "), //
// finds all installed - ignores those plugins marked as deleted
@@ -143,14 +126,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " 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.status = 'INSTALLED' "), //
// this query is how you enable and disable plugins
@@ -173,14 +151,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " 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 " //
@@ -223,16 +196,10 @@ public class Plugin extends AbstractPlugin {
}
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) {
-
- super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion, deployment,
- pluginConfig, scheduledJobsConfig, ctime, mtime);
+ String description, String help, String md5, String version, String ampsVersion, long ctime, long mtime) {
- if (deployment != PluginDeploymentType.AGENT) {
- throw new IllegalArgumentException("Plugin must only ever be of deployment type == AGENT: " + deployment);
- }
+ super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion,
+ PluginDeploymentType.AGENT, ctime, mtime);
}
@Override
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
index 0c406c3..bb897b1 100644
--- 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
@@ -22,10 +22,14 @@
*/
package org.rhq.core.domain.plugin;
+import javax.persistence.CascadeType;
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.jetbrains.annotations.NotNull;
@@ -67,7 +71,6 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
@@ -92,7 +95,6 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
@@ -118,7 +120,6 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
@@ -143,7 +144,6 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
@@ -172,6 +172,14 @@ public class ServerPlugin extends AbstractPlugin {
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;
+
public ServerPlugin() {
super();
setDeployment(PluginDeploymentType.SERVER);
@@ -193,17 +201,13 @@ public class ServerPlugin extends AbstractPlugin {
}
public ServerPlugin(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) {
+ String description, String help, String md5, String version, String ampsVersion, Configuration pluginConfig,
+ Configuration scheduledJobsConfig, long ctime, long mtime) {
- super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion, deployment,
- pluginConfig, scheduledJobsConfig, ctime, mtime);
-
- if (deployment != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("ServerPlugin must only ever be of deployment type == SERVER: "
- + deployment);
- }
+ super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion,
+ PluginDeploymentType.SERVER, ctime, mtime);
+ this.pluginConfiguration = pluginConfig;
+ this.scheduledJobsConfiguration = scheduledJobsConfig;
}
@Override
@@ -215,6 +219,32 @@ public class ServerPlugin extends AbstractPlugin {
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 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 scheduledJobsConfiguration;
+ }
+
+ public void setScheduledJobsConfiguration(Configuration scheduledJobsConfiguration) {
+ this.scheduledJobsConfiguration = scheduledJobsConfiguration;
+ }
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
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 be2deb3..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
@@ -80,8 +80,6 @@ public class PluginTest extends AbstractEJB3Test {
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);
q.setParameter("name", plugin.getName());
@@ -99,8 +97,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getVersion() == null;
assert plugin.getDescription() == null;
assert plugin.getDeployment() == PluginDeploymentType.AGENT;
- assert plugin.getPluginConfiguration() == null;
- assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
assert new String(plugin.getContent()).equals(new String(content));
@@ -115,32 +111,14 @@ public class PluginTest extends AbstractEJB3Test {
String description = "description-UPDATED";
String help = "help-UPDATED";
PluginDeploymentType deployment = PluginDeploymentType.AGENT;
- 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/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);
@@ -151,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());
@@ -180,8 +156,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == PluginDeploymentType.AGENT;
- 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));
@@ -248,8 +222,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getVersion() == null;
assert plugin.getDescription() == null;
assert plugin.getDeployment() == PluginDeploymentType.AGENT;
- assert plugin.getPluginConfiguration() == null;
- assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
assert plugin.getContent() == null;
@@ -299,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;
@@ -317,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));
@@ -337,8 +305,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 plugin.getContent() == null;
@@ -356,8 +322,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 plugin.getContent() == null;
@@ -377,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;
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..31d4188 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,14 @@
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.ServerPlugin;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -58,13 +60,13 @@ public class InstalledPluginComponent {
this.type = type;
}
- @Factory(value="plugin", autoCreate=true, scope=ScopeType.PAGE)
- public Plugin lookupPlugin() {
+ @Factory(value = "plugin", autoCreate = true, scope = ScopeType.PAGE)
+ public AbstractPlugin lookupPlugin() {
if (this.type == PluginDeploymentType.AGENT) {
return LookupUtil.getResourceMetadataManager().getPlugin(this.name);
} else if (this.type == PluginDeploymentType.SERVER) {
ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
- Plugin plugin = serverPluginsBean.getServerPlugin(this.name);
+ ServerPlugin plugin = serverPluginsBean.getServerPlugin(this.name);
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..2f7d73a 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,21 @@ 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.ServerPlugin;
import org.rhq.core.gui.util.FacesContextUtility;
import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
import org.rhq.enterprise.server.authz.PermissionException;
@@ -53,15 +55,15 @@ public class InstalledPluginUIBean {
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;
}
@@ -81,15 +83,15 @@ public class InstalledPluginUIBean {
ServerPluginsLocal serverPlugins = LookupUtil.getServerPlugins();
try {
- serverPlugins.updateServerPluginExceptContent(EnterpriseFacesContextUtility.getSubject(), plugin);
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO,
- "Configuration settings saved.");
+ serverPlugins.updateServerPluginExceptContent(EnterpriseFacesContextUtility.getSubject(),
+ (ServerPlugin) plugin);
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Configuration settings saved.");
return OUTCOME_SUCCESS;
} 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;
}
@@ -104,8 +106,10 @@ public class InstalledPluginUIBean {
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());
+ 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);
@@ -121,7 +125,8 @@ public class InstalledPluginUIBean {
private void hasPermission() {
Subject subject = EnterpriseFacesContextUtility.getSubject();
if (!LookupUtil.getAuthorizationManager().hasGlobalPermission(subject, Permission.MANAGE_SETTINGS)) {
- throw new PermissionException("User [" + subject.getName() + "] does not have the proper permissions to view or manage plugins");
+ throw new PermissionException("User [" + subject.getName()
+ + "] does not have the proper permissions to view or manage plugins");
}
}
}
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/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..de8857b 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,9 +51,9 @@ 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.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;
@@ -159,7 +159,7 @@ public class ServerPluginScanner {
log.info("Registering RHQ server plugin [" + pluginName + "], version " + version);
- Plugin plugin = new Plugin(pluginName, pluginFile.getName());
+ ServerPlugin plugin = new ServerPlugin(pluginName, pluginFile.getName());
plugin.setDeployment(PluginDeploymentType.SERVER);
plugin.setDisplayName((displayName != null) ? displayName : pluginName);
plugin.setEnabled(!descriptor.isDisabledOnDiscovery());
@@ -251,7 +251,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 +283,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 +318,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 +332,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 +352,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 +362,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 +402,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,7 +448,7 @@ 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);
@@ -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 e139241..5bee8c0 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,9 @@ 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.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;
@@ -78,22 +78,19 @@ 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);
+ public ServerPlugin getServerPlugin(String name) {
+ Query query = entityManager.createNamedQuery(ServerPlugin.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");
- }
+ ServerPlugin plugin = (ServerPlugin) query.getSingleResult();
return plugin;
}
- public Plugin getServerPluginRelationships(Plugin plugin) {
+ public ServerPlugin getServerPluginRelationships(ServerPlugin plugin) {
plugin = getServerPlugin(plugin.getName()); // refresh all but the content field
Configuration config = plugin.getPluginConfiguration();
@@ -111,18 +108,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_DEPLOYMENT);
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_IDS);
query.setParameter("ids", pluginIds);
- query.setParameter("deployment", PluginDeploymentType.SERVER);
return query.getResultList();
}
public ServerPluginDescriptorType getServerPluginDescriptor(String pluginName) throws Exception {
- Plugin plugin = getServerPlugin(pluginName);
+ ServerPlugin plugin = getServerPlugin(pluginName);
File pluginsDir = LookupUtil.getServerPluginService().getServerPluginsDirectory();
File pluginJar = new File(pluginsDir, plugin.getPath());
URL url = pluginJar.toURI().toURL();
@@ -131,9 +127,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public List<String> getServerPluginNamesByEnabled(boolean enabled) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_DEPLOYMENT);
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_NAMES_BY_ENABLED);
query.setParameter("enabled", Boolean.valueOf(enabled));
- query.setParameter("deployment", PluginDeploymentType.SERVER);
return query.getResultList();
}
@@ -167,9 +162,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
List<String> doomedPlugins = new ArrayList<String>();
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) {
@@ -210,9 +205,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
List<String> doomedPlugins = new ArrayList<String>();
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) {
@@ -269,7 +264,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 +283,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,14 +292,14 @@ 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());
@@ -317,7 +312,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;
}
@@ -354,13 +349,12 @@ 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_DEPLOYMENT);
+ Query q = this.entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", pluginName);
- q.setParameter("deployment", PluginDeploymentType.SERVER);
- Plugin doomed = (Plugin) q.getSingleResult();
+ 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");
@@ -368,18 +362,13 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@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 +384,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());
@@ -421,9 +410,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public PluginStatusType getServerPluginStatus(String pluginName) {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_DEPLOYMENT);
+ Query q = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_STATUS_BY_NAME);
q.setParameter("name", pluginName);
- q.setParameter("deployment", PluginDeploymentType.SERVER);
PluginStatusType status;
try {
status = (PluginStatusType) q.getSingleResult();
@@ -474,7 +462,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..e5375c4 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,8 +8,8 @@ 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.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;
@@ -25,7 +25,7 @@ public interface ServerPluginsLocal {
*
* @return all plugins found in the DB
*/
- List<Plugin> getServerPlugins();
+ List<ServerPlugin> getServerPlugins();
/**
* Returns a plugin with the given name.
@@ -33,7 +33,7 @@ public interface ServerPluginsLocal {
* @return the named plugin
* @throws NoResultException when no plugin with that name exists
*/
- Plugin getServerPlugin(String name);
+ ServerPlugin getServerPlugin(String name);
/**
* Methods in this object that return plugins normally do not include
@@ -46,7 +46,7 @@ public interface ServerPluginsLocal {
* @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.
@@ -54,7 +54,7 @@ public interface ServerPluginsLocal {
* @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.
@@ -138,7 +138,7 @@ public interface ServerPluginsLocal {
* @return the plugin after being persisted
* @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,14 +150,14 @@ 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.
*
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..43e07fc 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;
@@ -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.getPluginName());
return plugin;
}
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 e39f570..cd1921b 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,9 +34,9 @@ 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.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.enterprise.server.plugin.pc.generic.TestGenericServerPluginService;
import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -75,10 +75,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,8 +98,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
}
public void testGetPlugins() throws Exception {
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
List<String> pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
assert pluginNames.contains(p1.getName()) : pluginNames;
assert pluginNames.contains(p2.getName()) : pluginNames;
@@ -107,7 +107,7 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert !pluginNames.contains(p1.getName()) : pluginNames;
assert !pluginNames.contains(p2.getName()) : pluginNames;
- Plugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
assert plugin.getId() == p1.getId() : plugin;
assert plugin.getName().equals(p1.getName()) : plugin;
assetLazyInitializationException(plugin);
@@ -118,7 +118,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 +136,11 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
}
public void testUpdatePlugins() throws Exception {
- Plugin p1 = registerPlugin(1);
+ ServerPlugin p1 = registerPlugin(1);
p1 = this.serverPluginsBean.getServerPlugin(p1.getName());
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,8 +154,8 @@ 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);
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
@@ -184,7 +184,7 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert !pluginNames.contains(p2.getName()) : pluginNames;
// make sure none of these enable/disable settings lost our config
- Plugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
plugin = this.serverPluginsBean.getServerPluginRelationships(plugin);
assert plugin.getPluginConfiguration() != null; // no LazyInitException should be thrown!
assert plugin.getPluginConfiguration().equals(p1.getPluginConfiguration());
@@ -203,8 +203,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "2");
assert status == null;
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
status = this.serverPluginsBean.getServerPluginStatus(p1.getName());
assert status == PluginStatusType.INSTALLED;
@@ -218,8 +218,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
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());
+ ServerPlugin p1deleted = getDeletedPluginInTx(p1.getName());
+ ServerPlugin p2deleted = getDeletedPluginInTx(p2.getName());
assert p1deleted.getStatus() == PluginStatusType.DELETED;
assert p2deleted.getStatus() == PluginStatusType.DELETED;
@@ -240,8 +240,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "2");
assert status == null;
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
status = this.serverPluginsBean.getServerPluginStatus(p1.getName());
assert status == PluginStatusType.INSTALLED;
@@ -255,11 +255,11 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert undeployed.size() == 2 : undeployed;
assert undeployed.contains(p1.getName()) : undeployed;
assert undeployed.contains(p2.getName()) : undeployed;
- Plugin p1deleted = getDeletedPluginInTx(p1.getName());
+ 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
@@ -284,8 +284,8 @@ 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;
@@ -297,11 +297,11 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert !pluginNames.contains(p2.getName()) : pluginNames;
}
- 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(), System.currentTimeMillis(), System
+ .currentTimeMillis());
plugin = this.serverPluginsBean.registerServerPlugin(getOverlord(), plugin, null);
assert plugin.getId() > 0;
@@ -313,7 +313,7 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
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 +344,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_DEPLOYMENT);
+ Query q = em.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", pluginName);
- q.setParameter("deployment", 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/TestGenericServerPluginService.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
index 592a3d9..44d03c3 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,8 @@ 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.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;
@@ -175,7 +174,7 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
}
@Override
- protected Plugin getPlugin(ServerPluginEnvironment env) {
+ protected ServerPlugin getPlugin(ServerPluginEnvironment env) {
try {
Configuration pluginConfig = null;
@@ -195,11 +194,11 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
}
File pluginFile = new File(env.getPluginUrl().toURI());
- Plugin plugin = new Plugin(0, env.getPluginName(), pluginFile.getName(), pluginDescriptor
+ ServerPlugin plugin = new ServerPlugin(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());
+ .getVersion(), pluginConfig, scheduledJobsConfig, System.currentTimeMillis(), System
+ .currentTimeMillis());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
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);
}
commit 00d502f86cea6a401c172316e395b6ff76c41d98
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 27 16:44:26 2009 -0500
start to adding JPA discriminators to plugin entities
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..757fa6a
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
@@ -0,0 +1,458 @@
+/*
+ * 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;
+
+import java.io.ByteArrayInputStream;
+import java.io.Serializable;
+
+import javax.persistence.CascadeType;
+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.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;
+
+/**
+ * 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;
+
+ @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 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(@NotNull 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.
+ *
+ * @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 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, 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;
+ }
+
+ 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;
+ }
+
+ /**
+ * 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();
+ }
+
+ @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..1b4c693 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
@@ -22,30 +22,14 @@
*/
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.
@@ -53,21 +37,24 @@ import org.rhq.core.util.MessageDigestGenerator;
* 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, " //
@@ -88,7 +75,8 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " 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' "), //
+ + " 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 = "" //
@@ -112,11 +100,12 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " FROM Plugin AS p " //
+ " LEFT JOIN p.pluginConfiguration " //
+ " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.name=:name AND p.status = 'INSTALLED' "), //
+ + " 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 = "" //
+ @NamedQuery(name = Plugin.QUERY_FIND_ANY_BY_NAME, query = "" //
+ " SELECT new org.rhq.core.domain.plugin.Plugin( " //
+ " p.id, " //
+ " p.name, " //
@@ -137,34 +126,11 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " 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 = "" //
- + " 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.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, " //
@@ -185,7 +151,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " 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 = "" //
@@ -221,394 +187,60 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " 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;
+ 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;
- }
+ super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion, deployment,
+ pluginConfig, scheduledJobsConfig, ctime, mtime);
- 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;
+ if (deployment != PluginDeploymentType.AGENT) {
+ throw new IllegalArgumentException("Plugin must only ever be of deployment type == AGENT: " + deployment);
}
}
- 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;
- }
-
+ @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 +253,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/ServerPlugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
new file mode 100644
index 0000000..0c406c3
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
@@ -0,0 +1,240 @@
+/*
+ * 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.plugin;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+
+import org.jetbrains.annotations.NotNull;
+
+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 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.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " 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.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " 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.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " 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.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " 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";
+
+ public ServerPlugin() {
+ super();
+ setDeployment(PluginDeploymentType.SERVER);
+ }
+
+ public ServerPlugin(@NotNull 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,
+ PluginDeploymentType deployment, Configuration pluginConfig, Configuration scheduledJobsConfig, long ctime,
+ long mtime) {
+
+ super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion, deployment,
+ pluginConfig, scheduledJobsConfig, ctime, mtime);
+
+ if (deployment != PluginDeploymentType.SERVER) {
+ throw new IllegalArgumentException("ServerPlugin must only ever be of deployment type == SERVER: "
+ + deployment);
+ }
+ }
+
+ @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);
+ }
+
+ @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..be2deb3 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,9 +73,8 @@ 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);
@@ -84,9 +83,8 @@ public class PluginTest extends AbstractEJB3Test {
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,7 +98,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.getDeployment() == PluginDeploymentType.AGENT;
assert plugin.getPluginConfiguration() == null;
assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
@@ -116,7 +114,7 @@ public class PluginTest extends AbstractEJB3Test {
String ampsVersion = "2.1";
String description = "description-UPDATED";
String help = "help-UPDATED";
- PluginDeploymentType deployment = PluginDeploymentType.SERVER;
+ PluginDeploymentType deployment = PluginDeploymentType.AGENT;
Configuration pluginConfig = new Configuration();
Configuration jobsConfig = new Configuration();
pluginConfig.put(new PropertySimple("first", "last"));
@@ -181,7 +179,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.getDeployment() == PluginDeploymentType.AGENT;
assert plugin.getPluginConfiguration().equals(pluginConfig);
assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
@@ -193,9 +191,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,7 +247,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.getDeployment() == PluginDeploymentType.AGENT;
assert plugin.getPluginConfiguration() == null;
assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
@@ -284,7 +281,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();
@@ -345,9 +342,8 @@ public class PluginTest extends AbstractEJB3Test {
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;
@@ -365,7 +361,7 @@ public class PluginTest extends AbstractEJB3Test {
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) {
@@ -399,13 +395,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 +508,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 +622,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/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..e139241 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
@@ -115,9 +115,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (pluginIds == null || pluginIds.size() == 0) {
return new ArrayList<Plugin>(); // nothing to do
}
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_TYPE);
+ Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_DEPLOYMENT);
query.setParameter("ids", pluginIds);
- query.setParameter("type", PluginDeploymentType.SERVER);
+ query.setParameter("deployment", PluginDeploymentType.SERVER);
return query.getResultList();
}
@@ -131,9 +131,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public List<String> getServerPluginNamesByEnabled(boolean enabled) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE);
+ Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_DEPLOYMENT);
query.setParameter("enabled", Boolean.valueOf(enabled));
- query.setParameter("type", PluginDeploymentType.SERVER);
+ query.setParameter("deployment", PluginDeploymentType.SERVER);
return query.getResultList();
}
@@ -354,9 +354,9 @@ 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);
+ Query q = this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_DEPLOYMENT);
q.setParameter("name", pluginName);
- q.setParameter("type", PluginDeploymentType.SERVER);
+ q.setParameter("deployment", PluginDeploymentType.SERVER);
Plugin doomed = (Plugin) q.getSingleResult();
// get the reference to attach to em and use the em.remove. this cascade deletes too.
@@ -421,9 +421,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public PluginStatusType getServerPluginStatus(String pluginName) {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_DEPLOYMENT);
q.setParameter("name", pluginName);
- q.setParameter("type", PluginDeploymentType.SERVER);
+ q.setParameter("deployment", PluginDeploymentType.SERVER);
PluginStatusType status;
try {
status = (PluginStatusType) q.getSingleResult();
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..e39f570 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
@@ -348,9 +348,9 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
EntityManager em = getEntityManager();
getTransactionManager().begin();
try {
- Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_DEPLOYMENT);
q.setParameter("name", pluginName);
- q.setParameter("type", PluginDeploymentType.SERVER);
+ q.setParameter("deployment", PluginDeploymentType.SERVER);
return (Plugin) q.getSingleResult();
} finally {
getTransactionManager().rollback();
commit 3e3f767e11d3fc680d6ad846d7f745d39a39a8fc
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 27 11:22:43 2009 -0500
start with plugin key impl
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/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..4f7809d
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
@@ -0,0 +1,127 @@
+/*
+ * 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 an empty string 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, "", 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);
+ }
+
+ public PluginKey(PluginDeploymentType deployment, String pluginType, String pluginName) {
+ if (deployment == null) {
+ throw new IllegalArgumentException("deployment==null");
+ }
+ if (pluginType == null) {
+ throw new IllegalArgumentException("pluginType==null");
+ }
+ 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.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.equals(other.pluginType)) {
+ return false;
+ }
+ if (!deployment.equals(other.deployment)) {
+ return false;
+ }
+ return true;
+ }
+}
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..aa75432 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
@@ -48,6 +48,7 @@ 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.util.exception.ThrowableUtil;
import org.rhq.core.util.jdbc.JDBCUtil;
@@ -83,18 +84,23 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return q.getResultList();
}
- public Plugin getServerPlugin(String name) {
+ public Plugin getServerPlugin(PluginKey key) {
Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
- query.setParameter("name", name);
+ query.setParameter("name", key.getPluginName());
Plugin plugin = (Plugin) query.getSingleResult();
if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin named [" + name + "] is not a server plugin");
+ throw new IllegalArgumentException("Plugin [" + key + "] is not a server plugin");
}
return plugin;
}
public Plugin getServerPluginRelationships(Plugin plugin) {
- plugin = getServerPlugin(plugin.getName()); // refresh all but the content field
+ Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", plugin.getName());
+ plugin = (Plugin) query.getSingleResult();
+ if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
+ throw new IllegalArgumentException("Plugin [" + plugin.getName() + "] is not a server plugin");
+ }
Configuration config = plugin.getPluginConfiguration();
if (config != null) {
@@ -121,8 +127,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return query.getResultList();
}
- public ServerPluginDescriptorType getServerPluginDescriptor(String pluginName) throws Exception {
- Plugin plugin = getServerPlugin(pluginName);
+ public ServerPluginDescriptorType getServerPluginDescriptor(PluginKey pluginKey) throws Exception {
+ Plugin plugin = getServerPlugin(pluginKey);
File pluginsDir = LookupUtil.getServerPluginService().getServerPluginsDirectory();
File pluginJar = new File(pluginsDir, plugin.getPath());
URL url = pluginJar.toURI().toURL();
@@ -130,11 +136,11 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return descriptor;
}
- public List<String> getServerPluginNamesByEnabled(boolean enabled) {
+ public List<PluginKey> getServerPluginKeysByEnabled(boolean enabled) {
Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE);
query.setParameter("enabled", Boolean.valueOf(enabled));
query.setParameter("type", PluginDeploymentType.SERVER);
- return query.getResultList();
+ return xquery.getResultList(); // TODO this is a list of strings, not plugin keys!!!
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
@@ -154,9 +160,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,7 +170,7 @@ 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;
@@ -174,14 +180,15 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
if (doomedPlugin != null) {
String pluginName = doomedPlugin.getName();
- doomedPlugins.add(pluginName);
+ PluginKey pluginKey = ;
+ 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 +204,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,7 +214,7 @@ 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;
@@ -217,14 +224,15 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
if (doomedPlugin != null) {
String pluginName = doomedPlugin.getName();
- doomedPlugins.add(pluginName);
+ PluginKey pluginKey = ;
+ 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);
}
}
}
@@ -353,9 +361,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void purgeServerPlugin(Subject subject, String pluginName) {
+ public void purgeServerPlugin(Subject subject, PluginKey pluginKey) {
Query q = this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
- q.setParameter("name", pluginName);
+ q.setParameter("name", pluginKey.getPluginName());
q.setParameter("type", PluginDeploymentType.SERVER);
Plugin doomed = (Plugin) q.getSingleResult();
@@ -363,7 +371,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
doomed = this.entityManager.getReference(Plugin.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;
}
@@ -420,9 +428,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return plugin;
}
- public PluginStatusType getServerPluginStatus(String pluginName) {
+ public PluginStatusType getServerPluginStatus(PluginKey pluginKey) {
Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
- q.setParameter("name", pluginName);
+ q.setParameter("name", pluginKey.getPluginName());
q.setParameter("type", PluginDeploymentType.SERVER);
PluginStatusType status;
try {
@@ -439,14 +447,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);
}
}
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..2f84337 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
@@ -9,6 +9,7 @@ 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.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
@@ -28,12 +29,12 @@ public interface ServerPluginsLocal {
List<Plugin> 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);
+ Plugin getServerPlugin(PluginKey key);
/**
* Methods in this object that return plugins normally do not include
@@ -57,23 +58,23 @@ public interface ServerPluginsLocal {
List<Plugin> getServerPluginsById(List<Integer> pluginIds);
/**
- * Given a plugin name, returns the descriptor for that plugin.
+ * Given a plugin key, returns the descriptor for that plugin.
*
- * @param pluginName
+ * @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,20 +90,20 @@ 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.
@@ -162,26 +163,26 @@ public interface ServerPluginsLocal {
* 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..2d2eea7 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");
@@ -251,7 +254,7 @@ 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.
*
@@ -261,8 +264,8 @@ public class MasterServerPluginContainer {
*
* @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);
}
@@ -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;
@@ -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,14 +432,14 @@ 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;
}
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..350ca61 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
@@ -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
@@ -311,7 +311,7 @@ public class ServerPluginManager {
protected Plugin getPlugin(ServerPluginEnvironment pluginEnv) {
// get the plugin data from the database
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
- Plugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginName());
+ Plugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey().getPluginName());
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/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..e80ed1f 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
@@ -29,6 +29,7 @@ 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.util.MessageDigestGenerator;
import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
@@ -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>();
}
}
@@ -195,11 +196,11 @@ 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());
+ Plugin plugin = new Plugin(0, env.getPluginKey().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());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
@@ -210,7 +211,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 ,
14 years, 5 months
[rhq] Branch 'pc' - 5 commits - etc/samples modules/core modules/enterprise
by mazz
etc/samples/custom-serverplugin/src/main/java/org/custom/MyLifecycleListener.java | 2
modules/core/dbutils/pom.xml | 2
modules/core/dbutils/src/main/scripts/dbsetup/amps-schema.xml | 4
modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml | 17 +
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 | 33 +-
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginComponent.java | 28 +
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java | 24 +
modules/enterprise/gui/portal-war/src/main/webapp/WEB-INF/jsf-navigation/admin-navigation.xml | 4
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 | 4
modules/enterprise/gui/portal-war/src/main/webapp/rhq/admin/plugin/plugin-list.xhtml | 5
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java | 8
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java | 68 ++--
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java | 45 +-
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 | 61 ++-
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 | 10
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/content/ContentServerPluginManager.java | 2
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/ServerPluginsBeanTest.java | 152 +++++----
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 | 17 -
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestLifecycleListener.java | 4
25 files changed, 498 insertions(+), 225 deletions(-)
New commits:
commit 46b2dc39e618652087bbd0c3b6b8f4cddefb4df2
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 11:19:32 2009 -0500
use != to check for deployment type inequality
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
index 0d28937..5240a65 100644
--- 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
@@ -145,7 +145,7 @@ public class PluginKey {
return false;
}
- if (!deployment.equals(other.deployment)) {
+ if (deployment != other.deployment) {
return false;
}
return true;
commit 2838e6492a4db53a5cb066d599d7176f86138303
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 11:04:56 2009 -0500
plugin configs are now only valid for server plugins. do the check on the UI bean def, since that will be null for agent plugins
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..5e32efa 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
@@ -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>
commit d2e2d1e98759c5fb5d2fd678c3d01b829e315270
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 02:17:25 2009 -0500
first attempt to see what this looks like if i use plugin key vs. just plugin name in API
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/PluginKey.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
index 4f7809d..0d28937 100644
--- 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
@@ -33,13 +33,13 @@ public class PluginKey {
* 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 an empty string to signify this.
+ * 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, "", pluginName);
+ return new PluginKey(PluginDeploymentType.AGENT, null, pluginName);
}
/**
@@ -58,12 +58,33 @@ public class PluginKey {
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) {
- throw new IllegalArgumentException("pluginType==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);
@@ -99,7 +120,7 @@ public class PluginKey {
final int prime = 31;
int result = 1;
result = prime * result + deployment.hashCode();
- result = prime * result + pluginType.hashCode();
+ result = prime * result + ((pluginType == null) ? 0 : pluginType.hashCode());
result = prime * result + pluginName.hashCode();
return result;
}
@@ -116,8 +137,13 @@ public class PluginKey {
if (!pluginName.equals(other.pluginName)) {
return false;
}
- if (!pluginType.equals(other.pluginType)) {
+ if (pluginType == null) {
+ if (other.pluginType != null) {
+ return false;
+ }
+ } else if (!pluginType.equals(other.pluginType)) {
return false;
+
}
if (!deployment.equals(other.deployment)) {
return false;
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
index d233365..aa06ea9 100644
--- 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
@@ -23,6 +23,7 @@
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;
@@ -50,7 +51,10 @@ import org.rhq.core.domain.configuration.Configuration;
// helps you determine which installed plugins are enabled or disabled
@NamedQuery(name = ServerPlugin.QUERY_GET_NAMES_BY_ENABLED, query = "" //
- + " SELECT p.name " //
+ + " 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' "), //
@@ -71,6 +75,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.ampsVersion, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM ServerPlugin AS p " //
@@ -95,6 +100,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.ampsVersion, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM ServerPlugin AS p " //
@@ -120,6 +126,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.ampsVersion, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM ServerPlugin AS p " //
@@ -144,6 +151,7 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.ampsVersion, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ + " p.type, " //
+ " p.ctime, " //
+ " p.mtime) " //
+ " FROM ServerPlugin AS p " //
@@ -178,6 +186,9 @@ public class ServerPlugin extends AbstractPlugin {
@OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
private Configuration pluginConfiguration;
+ @Column(name = "PTYPE")
+ private String type;
+
public ServerPlugin() {
super();
setDeployment(PluginDeploymentType.SERVER);
@@ -200,12 +211,13 @@ public class ServerPlugin extends AbstractPlugin {
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, long ctime, long mtime) {
+ 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
@@ -223,7 +235,7 @@ public class ServerPlugin extends AbstractPlugin {
* @return the configuration associated with the plugin itself
*/
public Configuration getPluginConfiguration() {
- return pluginConfiguration;
+ return this.pluginConfiguration;
}
public void setPluginConfiguration(Configuration pluginConfiguration) {
@@ -236,13 +248,26 @@ public class ServerPlugin extends AbstractPlugin {
* @return scheduled job configuration for jobs that the plugin defined.
*/
public Configuration getScheduledJobsConfiguration() {
- return scheduledJobsConfiguration;
+ 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) {
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 31d4188..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
@@ -26,6 +26,7 @@ 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;
@@ -41,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;
@@ -52,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 type) {
- this.type = type;
+ public void setType(PluginDeploymentType deployment) {
+ this.deployment = deployment;
+ }
+
+ public String getPluginType() {
+ return this.pluginType;
+ }
+
+ public void setPluginType(String pluginType) {
+ this.pluginType = pluginType;
}
@Factory(value = "plugin", autoCreate = true, scope = ScopeType.PAGE)
public AbstractPlugin lookupPlugin() {
- if (this.type == PluginDeploymentType.AGENT) {
+ 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();
- ServerPlugin 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 2f7d73a..9351385 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
@@ -35,6 +35,7 @@ import org.rhq.core.domain.authz.Permission;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
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;
@@ -51,7 +52,7 @@ 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
@@ -67,6 +68,14 @@ public class InstalledPluginUIBean {
this.plugin = plugin;
}
+ public ServerPlugin getServerPlugin() {
+ return (ServerPlugin) this.plugin;
+ }
+
+ public void setServerPlugin(ServerPlugin plugin) {
+ this.plugin = plugin;
+ }
+
public ConfigurationDefinition getPluginConfigurationDefinition() {
return this.pluginConfigurationDefinition;
}
@@ -80,14 +89,14 @@ 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(),
- (ServerPlugin) plugin);
+ 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,
@@ -105,7 +114,8 @@ public class InstalledPluginUIBean {
if (this.plugin.getDeployment() == PluginDeploymentType.SERVER) {
try {
ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
- ServerPluginDescriptorType descriptor = serverPluginsBean.getServerPluginDescriptor(pluginName);
+ 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
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..37b3bad 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
@@ -33,8 +33,8 @@
<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>
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-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/plugin/ServerPluginScanner.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/core/plugin/ServerPluginScanner.java
index de8857b..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,7 +51,7 @@ 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.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;
@@ -59,6 +59,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.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;
@@ -160,7 +161,6 @@ public class ServerPluginScanner {
log.info("Registering RHQ server plugin [" + pluginName + "], version " + version);
ServerPlugin plugin = new ServerPlugin(pluginName, pluginFile.getName());
- plugin.setDeployment(PluginDeploymentType.SERVER);
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.");
@@ -451,7 +452,6 @@ public class ServerPluginScanner {
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
}
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 6839cfc..b3808ab 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
@@ -132,7 +132,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
public List<PluginKey> getServerPluginKeysByEnabled(boolean enabled) {
Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_NAMES_BY_ENABLED);
query.setParameter("enabled", Boolean.valueOf(enabled));
- return xquery.getResultList(); // TODO this is a list of strings, not plugin keys!!!
+ return query.getResultList();
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
@@ -171,8 +171,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
} catch (Exception ignore) {
}
if (doomedPlugin != null) {
- String pluginName = doomedPlugin.getName();
- PluginKey pluginKey = ;
+ PluginKey pluginKey = new PluginKey(doomedPlugin);
doomedPlugins.add(pluginKey);
if (master != null) {
AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginKey);
@@ -215,8 +214,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
} catch (Exception ignore) {
}
if (doomedPlugin != null) {
- String pluginName = doomedPlugin.getName();
- PluginKey pluginKey = ;
+ PluginKey pluginKey = new PluginKey(doomedPlugin);
doomedPlugins.add(pluginKey);
if (master != null) {
AbstractTypeServerPluginContainer pc = master.getPluginContainerByPlugin(pluginKey);
@@ -307,7 +305,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
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
}
@@ -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.");
@@ -401,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());
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 a4bd9b1..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
@@ -311,7 +311,7 @@ public class ServerPluginManager {
protected ServerPlugin getPlugin(ServerPluginEnvironment pluginEnv) {
// get the plugin data from the database
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
- ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey().getPluginName());
+ ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey());
return plugin;
}
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 cd1921b..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
@@ -35,11 +35,14 @@ 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.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
@@ -100,14 +103,16 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
public void testGetPlugins() throws Exception {
ServerPlugin p1 = registerPlugin(1);
ServerPlugin 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;
-
- ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ 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);
@@ -137,7 +142,9 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
public void testUpdatePlugins() throws Exception {
ServerPlugin p1 = registerPlugin(1);
- p1 = this.serverPluginsBean.getServerPlugin(p1.getName());
+ PluginKey p1key = new PluginKey(p1);
+
+ p1 = this.serverPluginsBean.getServerPlugin(p1key);
p1 = this.serverPluginsBean.getServerPluginRelationships(p1);
ServerPlugin p1update = this.serverPluginsBean.updateServerPluginExceptContent(getOverlord(), p1);
@@ -156,39 +163,41 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
public void testDisableEnablePlugins() throws Exception {
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
- ServerPlugin 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,63 +207,77 @@ 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;
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;
+ 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;
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;
+ 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
@@ -264,16 +287,16 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
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);
@@ -287,21 +310,21 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
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 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",
- 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,6 +333,7 @@ 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;
}
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 cd95053..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
@@ -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;
@@ -198,8 +199,9 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
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, System.currentTimeMillis(), System.currentTimeMillis());
+ .getVersion(), pluginDescriptor.getVersion(), pluginConfig, scheduledJobsConfig,
+ new ServerPluginType(pluginDescriptor).stringify(), System.currentTimeMillis(), System
+ .currentTimeMillis());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
commit 2bb5e6e39a106fe9a3f023b0216651954d50f3a6
Merge: b038b80... 3e3f767...
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Sat Nov 28 00:21:30 2009 -0500
Merge branch 'plugin-name-refactor' into pc2
Conflicts:
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
diff --cc modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java
index 5bee8c0,aa75432..6839cfc
--- 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 +46,10 @@@ import org.apache.commons.logging.LogFa
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;
@@@ -83,15 -84,23 +84,17 @@@ public class ServerPluginsBean implemen
return q.getResultList();
}
- public ServerPlugin getServerPlugin(String name) {
- public Plugin getServerPlugin(PluginKey key) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
++ public ServerPlugin getServerPlugin(PluginKey key) {
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
- query.setParameter("name", name);
+ query.setParameter("name", key.getPluginName());
- Plugin plugin = (Plugin) query.getSingleResult();
- if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin [" + key + "] is not a server plugin");
- }
+ ServerPlugin plugin = (ServerPlugin) query.getSingleResult();
return plugin;
}
- public Plugin getServerPluginRelationships(Plugin plugin) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
+ public ServerPlugin getServerPluginRelationships(ServerPlugin plugin) {
- plugin = getServerPlugin(plugin.getName()); // refresh all but the content field
++ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", plugin.getName());
- plugin = (Plugin) query.getSingleResult();
- if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin [" + plugin.getName() + "] is not a server plugin");
- }
++ plugin = (ServerPlugin) query.getSingleResult();
Configuration config = plugin.getPluginConfiguration();
if (config != null) {
@@@ -117,8 -126,9 +120,8 @@@
- query.setParameter("type", PluginDeploymentType.SERVER);
return query.getResultList();
}
- public ServerPluginDescriptorType getServerPluginDescriptor(String pluginName) throws Exception {
- ServerPlugin plugin = getServerPlugin(pluginName);
+ public ServerPluginDescriptorType getServerPluginDescriptor(PluginKey pluginKey) throws Exception {
- Plugin plugin = getServerPlugin(pluginKey);
++ ServerPlugin plugin = getServerPlugin(pluginKey);
File pluginsDir = LookupUtil.getServerPluginService().getServerPluginsDirectory();
File pluginJar = new File(pluginsDir, plugin.getPath());
URL url = pluginJar.toURI().toURL();
@@@ -126,10 -136,11 +129,10 @@@
return descriptor;
}
- public List<String> getServerPluginNamesByEnabled(boolean enabled) {
+ public List<PluginKey> getServerPluginKeysByEnabled(boolean enabled) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE);
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_NAMES_BY_ENABLED);
query.setParameter("enabled", Boolean.valueOf(enabled));
- return query.getResultList();
- query.setParameter("type", PluginDeploymentType.SERVER);
+ return xquery.getResultList(); // TODO this is a list of strings, not plugin keys!!!
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
@@@ -159,12 -170,12 +162,12 @@@
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) {
@@@ -202,12 -214,12 +206,12 @@@
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) {
@@@ -348,16 -361,17 +353,16 @@@
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void purgeServerPlugin(Subject subject, String pluginName) {
+ public void purgeServerPlugin(Subject subject, PluginKey pluginKey) {
- Query q = this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ Query q = this.entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
- q.setParameter("name", pluginName);
+ q.setParameter("name", pluginKey.getPluginName());
- q.setParameter("type", PluginDeploymentType.SERVER);
- Plugin doomed = (Plugin) q.getSingleResult();
+ 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;
}
@@@ -409,9 -428,10 +414,9 @@@
return plugin;
}
- public PluginStatusType getServerPluginStatus(String pluginName) {
+ public PluginStatusType getServerPluginStatus(PluginKey pluginKey) {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ Query q = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_STATUS_BY_NAME);
- q.setParameter("name", pluginName);
+ q.setParameter("name", pluginKey.getPluginName());
- q.setParameter("type", PluginDeploymentType.SERVER);
PluginStatusType status;
try {
status = (PluginStatusType) q.getSingleResult();
diff --cc modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java
index e5375c4,2f84337..a1e0a40
--- 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,8 -8,9 +8,9 @@@ 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;
@@@ -25,15 -26,15 +26,15 @@@ public interface ServerPluginsLocal
*
* @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
*/
- ServerPlugin getServerPlugin(String name);
- Plugin getServerPlugin(PluginKey key);
++ ServerPlugin getServerPlugin(PluginKey key);
/**
* Methods in this object that return plugins normally do not include
@@@ -54,12 -55,12 +55,12 @@@
* @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.
+ * Given a plugin key, returns the descriptor for that plugin.
*
- * @param pluginName
+ * @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
*/
diff --cc modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java
index 43e07fc,350ca61..a4bd9b1
--- 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
@@@ -306,12 -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();
- ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginName());
- Plugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey().getPluginName());
++ ServerPlugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey().getPluginName());
return plugin;
}
diff --cc modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
index 44d03c3,e80ed1f..cd95053
--- 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,8 -27,10 +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;
@@@ -194,11 -196,11 +195,11 @@@ public class TestGenericServerPluginSer
}
File pluginFile = new File(env.getPluginUrl().toURI());
- ServerPlugin plugin = new ServerPlugin(0, env.getPluginName(), pluginFile.getName(), pluginDescriptor
- .getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor.getDescription(), "",
- MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor.getVersion(), pluginDescriptor
- .getVersion(), pluginConfig, scheduledJobsConfig, System.currentTimeMillis(), System
- .currentTimeMillis());
- Plugin plugin = new Plugin(0, env.getPluginKey().getPluginName(), pluginFile.getName(),
++ ServerPlugin plugin = new ServerPlugin(0, env.getPluginKey().getPluginName(), pluginFile.getName(),
+ pluginDescriptor.getDisplayName(), true, PluginStatusType.INSTALLED, pluginDescriptor
+ .getDescription(), "", MessageDigestGenerator.getDigestString(pluginFile), pluginDescriptor
- .getVersion(), pluginDescriptor.getVersion(), PluginDeploymentType.SERVER, pluginConfig,
++ .getVersion(), pluginDescriptor.getVersion(), pluginConfig,
+ scheduledJobsConfig, System.currentTimeMillis(), System.currentTimeMillis());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
commit 3e3f767e11d3fc680d6ad846d7f745d39a39a8fc
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 27 11:22:43 2009 -0500
start with plugin key impl
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/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..4f7809d
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/PluginKey.java
@@ -0,0 +1,127 @@
+/*
+ * 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 an empty string 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, "", 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);
+ }
+
+ public PluginKey(PluginDeploymentType deployment, String pluginType, String pluginName) {
+ if (deployment == null) {
+ throw new IllegalArgumentException("deployment==null");
+ }
+ if (pluginType == null) {
+ throw new IllegalArgumentException("pluginType==null");
+ }
+ 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.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.equals(other.pluginType)) {
+ return false;
+ }
+ if (!deployment.equals(other.deployment)) {
+ return false;
+ }
+ return true;
+ }
+}
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..aa75432 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
@@ -48,6 +48,7 @@ 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.util.exception.ThrowableUtil;
import org.rhq.core.util.jdbc.JDBCUtil;
@@ -83,18 +84,23 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return q.getResultList();
}
- public Plugin getServerPlugin(String name) {
+ public Plugin getServerPlugin(PluginKey key) {
Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
- query.setParameter("name", name);
+ query.setParameter("name", key.getPluginName());
Plugin plugin = (Plugin) query.getSingleResult();
if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("Plugin named [" + name + "] is not a server plugin");
+ throw new IllegalArgumentException("Plugin [" + key + "] is not a server plugin");
}
return plugin;
}
public Plugin getServerPluginRelationships(Plugin plugin) {
- plugin = getServerPlugin(plugin.getName()); // refresh all but the content field
+ Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_NAME);
+ query.setParameter("name", plugin.getName());
+ plugin = (Plugin) query.getSingleResult();
+ if (plugin.getDeployment() != PluginDeploymentType.SERVER) {
+ throw new IllegalArgumentException("Plugin [" + plugin.getName() + "] is not a server plugin");
+ }
Configuration config = plugin.getPluginConfiguration();
if (config != null) {
@@ -121,8 +127,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return query.getResultList();
}
- public ServerPluginDescriptorType getServerPluginDescriptor(String pluginName) throws Exception {
- Plugin plugin = getServerPlugin(pluginName);
+ public ServerPluginDescriptorType getServerPluginDescriptor(PluginKey pluginKey) throws Exception {
+ Plugin plugin = getServerPlugin(pluginKey);
File pluginsDir = LookupUtil.getServerPluginService().getServerPluginsDirectory();
File pluginJar = new File(pluginsDir, plugin.getPath());
URL url = pluginJar.toURI().toURL();
@@ -130,11 +136,11 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return descriptor;
}
- public List<String> getServerPluginNamesByEnabled(boolean enabled) {
+ public List<PluginKey> getServerPluginKeysByEnabled(boolean enabled) {
Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE);
query.setParameter("enabled", Boolean.valueOf(enabled));
query.setParameter("type", PluginDeploymentType.SERVER);
- return query.getResultList();
+ return xquery.getResultList(); // TODO this is a list of strings, not plugin keys!!!
}
@RequiredPermission(Permission.MANAGE_SETTINGS)
@@ -154,9 +160,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,7 +170,7 @@ 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;
@@ -174,14 +180,15 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
if (doomedPlugin != null) {
String pluginName = doomedPlugin.getName();
- doomedPlugins.add(pluginName);
+ PluginKey pluginKey = ;
+ 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 +204,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,7 +214,7 @@ 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;
@@ -217,14 +224,15 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
if (doomedPlugin != null) {
String pluginName = doomedPlugin.getName();
- doomedPlugins.add(pluginName);
+ PluginKey pluginKey = ;
+ 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);
}
}
}
@@ -353,9 +361,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
@RequiredPermission(Permission.MANAGE_SETTINGS)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void purgeServerPlugin(Subject subject, String pluginName) {
+ public void purgeServerPlugin(Subject subject, PluginKey pluginKey) {
Query q = this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
- q.setParameter("name", pluginName);
+ q.setParameter("name", pluginKey.getPluginName());
q.setParameter("type", PluginDeploymentType.SERVER);
Plugin doomed = (Plugin) q.getSingleResult();
@@ -363,7 +371,7 @@ public class ServerPluginsBean implements ServerPluginsLocal {
doomed = this.entityManager.getReference(Plugin.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;
}
@@ -420,9 +428,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
return plugin;
}
- public PluginStatusType getServerPluginStatus(String pluginName) {
+ public PluginStatusType getServerPluginStatus(PluginKey pluginKey) {
Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
- q.setParameter("name", pluginName);
+ q.setParameter("name", pluginKey.getPluginName());
q.setParameter("type", PluginDeploymentType.SERVER);
PluginStatusType status;
try {
@@ -439,14 +447,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);
}
}
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..2f84337 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
@@ -9,6 +9,7 @@ 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.enterprise.server.plugin.pc.ServerPluginType;
import org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
@@ -28,12 +29,12 @@ public interface ServerPluginsLocal {
List<Plugin> 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);
+ Plugin getServerPlugin(PluginKey key);
/**
* Methods in this object that return plugins normally do not include
@@ -57,23 +58,23 @@ public interface ServerPluginsLocal {
List<Plugin> getServerPluginsById(List<Integer> pluginIds);
/**
- * Given a plugin name, returns the descriptor for that plugin.
+ * Given a plugin key, returns the descriptor for that plugin.
*
- * @param pluginName
+ * @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,20 +90,20 @@ 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.
@@ -162,26 +163,26 @@ public interface ServerPluginsLocal {
* 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..2d2eea7 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");
@@ -251,7 +254,7 @@ 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.
*
@@ -261,8 +264,8 @@ public class MasterServerPluginContainer {
*
* @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);
}
@@ -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;
@@ -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,14 +432,14 @@ 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;
}
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..350ca61 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
@@ -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
@@ -311,7 +311,7 @@ public class ServerPluginManager {
protected Plugin getPlugin(ServerPluginEnvironment pluginEnv) {
// get the plugin data from the database
ServerPluginsLocal serverPluginsManager = LookupUtil.getServerPlugins();
- Plugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginName());
+ Plugin plugin = serverPluginsManager.getServerPlugin(pluginEnv.getPluginKey().getPluginName());
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/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..e80ed1f 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
@@ -29,6 +29,7 @@ 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.util.MessageDigestGenerator;
import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
@@ -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>();
}
}
@@ -195,11 +196,11 @@ 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());
+ Plugin plugin = new Plugin(0, env.getPluginKey().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());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
@@ -210,7 +211,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 ,
14 years, 5 months
[rhq] Branch 'pc' - 3 commits - modules/core modules/enterprise
by mazz
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 | 504 -------
modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java | 268 ++++
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 | 10
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginUIBean.java | 29
modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/admin/plugin/InstalledPluginsUIBean.java | 24
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 | 43
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsBean.java | 70 -
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/ServerPluginsLocal.java | 16
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/ServerPluginManager.java | 10
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 | 65 -
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java | 11
modules/enterprise/server/xml-schemas/src/main/java/org/rhq/enterprise/server/xmlschema/ServerPluginDescriptorUtil.java | 4
17 files changed, 1523 insertions(+), 675 deletions(-)
New commits:
commit b038b80610293eb628ea5f8c34eb14fce7e2edd5
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 27 23:42:16 2009 -0500
fix copyright
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
index ff68860..6ff9cb5 100644
--- 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
@@ -4,17 +4,21 @@
* 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.
+ * 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 for more details.
+ * 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
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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;
@@ -36,8 +40,6 @@ import javax.persistence.PrePersist;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
-import org.jetbrains.annotations.NotNull;
-
import org.rhq.core.util.MessageDigestGenerator;
/**
@@ -113,7 +115,7 @@ public class AbstractPlugin implements Serializable {
* @param name the logical name of the plugin
* @param path the actual filename of the plugin jar (see {@link #getPath()})
*/
- public AbstractPlugin(@NotNull String name, String path) {
+ public AbstractPlugin(String name, String path) {
this.name = name;
this.path = path;
}
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 bf1b438..b3c370d 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
@@ -27,8 +27,6 @@ import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
-import org.jetbrains.annotations.NotNull;
-
/**
* An agent plugin.
*
@@ -180,7 +178,7 @@ public class Plugin extends AbstractPlugin {
setDeployment(PluginDeploymentType.AGENT);
}
- public Plugin(@NotNull String name, String path) {
+ public Plugin(String name, String path) {
super(name, path);
setDeployment(PluginDeploymentType.AGENT);
}
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
index bb897b1..d233365 100644
--- 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
@@ -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
@@ -31,8 +31,6 @@ import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
-import org.jetbrains.annotations.NotNull;
-
import org.rhq.core.domain.configuration.Configuration;
/**
@@ -185,7 +183,7 @@ public class ServerPlugin extends AbstractPlugin {
setDeployment(PluginDeploymentType.SERVER);
}
- public ServerPlugin(@NotNull String name, String path) {
+ public ServerPlugin(String name, String path) {
super(name, path);
setDeployment(PluginDeploymentType.SERVER);
}
commit 816db190b25e5b1b8169fdae865f9e60ce371a3f
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 27 19:54:33 2009 -0500
finish JPA discriminator refactoring so there is now ServerPlugin entity (Plugin entity is now only for agent plugins)
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
index 757fa6a..ff68860 100644
--- 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
@@ -22,27 +22,22 @@ 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.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.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;
/**
@@ -69,14 +64,6 @@ public class AbstractPlugin implements Serializable {
@Enumerated(EnumType.STRING)
private PluginDeploymentType deployment;
- @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;
@@ -172,28 +159,10 @@ public class AbstractPlugin implements Serializable {
* 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 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, Configuration pluginConfig, Configuration scheduledJobsConfig, long ctime,
- long mtime) {
+ PluginDeploymentType deployment, long ctime, long mtime) {
this.id = id;
this.name = name;
this.path = path;
@@ -206,8 +175,6 @@ public class AbstractPlugin implements Serializable {
this.version = version;
this.ampsVersion = ampsVersion;
this.deployment = deployment;
- this.pluginConfiguration = pluginConfig;
- this.scheduledJobsConfiguration = scheduledJobsConfig;
this.ctime = ctime;
this.mtime = mtime;
}
@@ -387,32 +354,6 @@ public class AbstractPlugin implements Serializable {
}
/**
- * 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).
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 1b4c693..bf1b438 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
@@ -29,8 +29,6 @@ import javax.persistence.NamedQuery;
import org.jetbrains.annotations.NotNull;
-import org.rhq.core.domain.configuration.Configuration;
-
/**
* An agent plugin.
*
@@ -67,14 +65,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " 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.status = 'INSTALLED' "), //
@@ -92,14 +85,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " 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' "), //
@@ -118,14 +106,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " 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 "), //
// finds all installed - ignores those plugins marked as deleted
@@ -143,14 +126,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " 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.status = 'INSTALLED' "), //
// this query is how you enable and disable plugins
@@ -173,14 +151,9 @@ import org.rhq.core.domain.configuration.Configuration;
+ " 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 " //
@@ -223,16 +196,10 @@ public class Plugin extends AbstractPlugin {
}
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) {
-
- super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion, deployment,
- pluginConfig, scheduledJobsConfig, ctime, mtime);
+ String description, String help, String md5, String version, String ampsVersion, long ctime, long mtime) {
- if (deployment != PluginDeploymentType.AGENT) {
- throw new IllegalArgumentException("Plugin must only ever be of deployment type == AGENT: " + deployment);
- }
+ super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion,
+ PluginDeploymentType.AGENT, ctime, mtime);
}
@Override
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
index 0c406c3..bb897b1 100644
--- 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
@@ -22,10 +22,14 @@
*/
package org.rhq.core.domain.plugin;
+import javax.persistence.CascadeType;
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.jetbrains.annotations.NotNull;
@@ -67,7 +71,6 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
@@ -92,7 +95,6 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
@@ -118,7 +120,6 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
@@ -143,7 +144,6 @@ import org.rhq.core.domain.configuration.Configuration;
+ " p.md5, " //
+ " p.version, " //
+ " p.ampsVersion, " //
- + " p.deployment, " //
+ " p.pluginConfiguration, " //
+ " p.scheduledJobsConfiguration, " //
+ " p.ctime, " //
@@ -172,6 +172,14 @@ public class ServerPlugin extends AbstractPlugin {
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;
+
public ServerPlugin() {
super();
setDeployment(PluginDeploymentType.SERVER);
@@ -193,17 +201,13 @@ public class ServerPlugin extends AbstractPlugin {
}
public ServerPlugin(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) {
+ String description, String help, String md5, String version, String ampsVersion, Configuration pluginConfig,
+ Configuration scheduledJobsConfig, long ctime, long mtime) {
- super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion, deployment,
- pluginConfig, scheduledJobsConfig, ctime, mtime);
-
- if (deployment != PluginDeploymentType.SERVER) {
- throw new IllegalArgumentException("ServerPlugin must only ever be of deployment type == SERVER: "
- + deployment);
- }
+ super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion,
+ PluginDeploymentType.SERVER, ctime, mtime);
+ this.pluginConfiguration = pluginConfig;
+ this.scheduledJobsConfiguration = scheduledJobsConfig;
}
@Override
@@ -215,6 +219,32 @@ public class ServerPlugin extends AbstractPlugin {
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 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 scheduledJobsConfiguration;
+ }
+
+ public void setScheduledJobsConfiguration(Configuration scheduledJobsConfiguration) {
+ this.scheduledJobsConfiguration = scheduledJobsConfiguration;
+ }
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
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 be2deb3..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
@@ -80,8 +80,6 @@ public class PluginTest extends AbstractEJB3Test {
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);
q.setParameter("name", plugin.getName());
@@ -99,8 +97,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getVersion() == null;
assert plugin.getDescription() == null;
assert plugin.getDeployment() == PluginDeploymentType.AGENT;
- assert plugin.getPluginConfiguration() == null;
- assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
assert new String(plugin.getContent()).equals(new String(content));
@@ -115,32 +111,14 @@ public class PluginTest extends AbstractEJB3Test {
String description = "description-UPDATED";
String help = "help-UPDATED";
PluginDeploymentType deployment = PluginDeploymentType.AGENT;
- 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/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);
@@ -151,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());
@@ -180,8 +156,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getAmpsVersion().equals(ampsVersion);
assert plugin.getDescription().equals(description);
assert plugin.getDeployment() == PluginDeploymentType.AGENT;
- 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));
@@ -248,8 +222,6 @@ public class PluginTest extends AbstractEJB3Test {
assert plugin.getVersion() == null;
assert plugin.getDescription() == null;
assert plugin.getDeployment() == PluginDeploymentType.AGENT;
- assert plugin.getPluginConfiguration() == null;
- assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
assert plugin.getContent() == null;
@@ -299,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;
@@ -317,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));
@@ -337,8 +305,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 plugin.getContent() == null;
@@ -356,8 +322,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 plugin.getContent() == null;
@@ -377,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;
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..31d4188 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,14 @@
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.ServerPlugin;
import org.rhq.enterprise.server.plugin.ServerPluginsLocal;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -58,13 +60,13 @@ public class InstalledPluginComponent {
this.type = type;
}
- @Factory(value="plugin", autoCreate=true, scope=ScopeType.PAGE)
- public Plugin lookupPlugin() {
+ @Factory(value = "plugin", autoCreate = true, scope = ScopeType.PAGE)
+ public AbstractPlugin lookupPlugin() {
if (this.type == PluginDeploymentType.AGENT) {
return LookupUtil.getResourceMetadataManager().getPlugin(this.name);
} else if (this.type == PluginDeploymentType.SERVER) {
ServerPluginsLocal serverPluginsBean = LookupUtil.getServerPlugins();
- Plugin plugin = serverPluginsBean.getServerPlugin(this.name);
+ ServerPlugin plugin = serverPluginsBean.getServerPlugin(this.name);
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..2f7d73a 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,21 @@ 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.ServerPlugin;
import org.rhq.core.gui.util.FacesContextUtility;
import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility;
import org.rhq.enterprise.server.authz.PermissionException;
@@ -53,15 +55,15 @@ public class InstalledPluginUIBean {
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;
}
@@ -81,15 +83,15 @@ public class InstalledPluginUIBean {
ServerPluginsLocal serverPlugins = LookupUtil.getServerPlugins();
try {
- serverPlugins.updateServerPluginExceptContent(EnterpriseFacesContextUtility.getSubject(), plugin);
- FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO,
- "Configuration settings saved.");
+ serverPlugins.updateServerPluginExceptContent(EnterpriseFacesContextUtility.getSubject(),
+ (ServerPlugin) plugin);
+ FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Configuration settings saved.");
return OUTCOME_SUCCESS;
} 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;
}
@@ -104,8 +106,10 @@ public class InstalledPluginUIBean {
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());
+ 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);
@@ -121,7 +125,8 @@ public class InstalledPluginUIBean {
private void hasPermission() {
Subject subject = EnterpriseFacesContextUtility.getSubject();
if (!LookupUtil.getAuthorizationManager().hasGlobalPermission(subject, Permission.MANAGE_SETTINGS)) {
- throw new PermissionException("User [" + subject.getName() + "] does not have the proper permissions to view or manage plugins");
+ throw new PermissionException("User [" + subject.getName()
+ + "] does not have the proper permissions to view or manage plugins");
}
}
}
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/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..de8857b 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,9 +51,9 @@ 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.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;
@@ -159,7 +159,7 @@ public class ServerPluginScanner {
log.info("Registering RHQ server plugin [" + pluginName + "], version " + version);
- Plugin plugin = new Plugin(pluginName, pluginFile.getName());
+ ServerPlugin plugin = new ServerPlugin(pluginName, pluginFile.getName());
plugin.setDeployment(PluginDeploymentType.SERVER);
plugin.setDisplayName((displayName != null) ? displayName : pluginName);
plugin.setEnabled(!descriptor.isDisabledOnDiscovery());
@@ -251,7 +251,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 +283,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 +318,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 +332,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 +352,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 +362,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 +402,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,7 +448,7 @@ 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);
@@ -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 e139241..5bee8c0 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,9 @@ 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.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;
@@ -78,22 +78,19 @@ 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);
+ public ServerPlugin getServerPlugin(String name) {
+ Query query = entityManager.createNamedQuery(ServerPlugin.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");
- }
+ ServerPlugin plugin = (ServerPlugin) query.getSingleResult();
return plugin;
}
- public Plugin getServerPluginRelationships(Plugin plugin) {
+ public ServerPlugin getServerPluginRelationships(ServerPlugin plugin) {
plugin = getServerPlugin(plugin.getName()); // refresh all but the content field
Configuration config = plugin.getPluginConfiguration();
@@ -111,18 +108,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_DEPLOYMENT);
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_BY_IDS);
query.setParameter("ids", pluginIds);
- query.setParameter("deployment", PluginDeploymentType.SERVER);
return query.getResultList();
}
public ServerPluginDescriptorType getServerPluginDescriptor(String pluginName) throws Exception {
- Plugin plugin = getServerPlugin(pluginName);
+ ServerPlugin plugin = getServerPlugin(pluginName);
File pluginsDir = LookupUtil.getServerPluginService().getServerPluginsDirectory();
File pluginJar = new File(pluginsDir, plugin.getPath());
URL url = pluginJar.toURI().toURL();
@@ -131,9 +127,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public List<String> getServerPluginNamesByEnabled(boolean enabled) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_DEPLOYMENT);
+ Query query = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_NAMES_BY_ENABLED);
query.setParameter("enabled", Boolean.valueOf(enabled));
- query.setParameter("deployment", PluginDeploymentType.SERVER);
return query.getResultList();
}
@@ -167,9 +162,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
List<String> doomedPlugins = new ArrayList<String>();
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) {
@@ -210,9 +205,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
List<String> doomedPlugins = new ArrayList<String>();
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) {
@@ -269,7 +264,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 +283,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,14 +292,14 @@ 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());
@@ -317,7 +312,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;
}
@@ -354,13 +349,12 @@ 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_DEPLOYMENT);
+ Query q = this.entityManager.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", pluginName);
- q.setParameter("deployment", PluginDeploymentType.SERVER);
- Plugin doomed = (Plugin) q.getSingleResult();
+ 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");
@@ -368,18 +362,13 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
@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 +384,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());
@@ -421,9 +410,8 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public PluginStatusType getServerPluginStatus(String pluginName) {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_DEPLOYMENT);
+ Query q = entityManager.createNamedQuery(ServerPlugin.QUERY_GET_STATUS_BY_NAME);
q.setParameter("name", pluginName);
- q.setParameter("deployment", PluginDeploymentType.SERVER);
PluginStatusType status;
try {
status = (PluginStatusType) q.getSingleResult();
@@ -474,7 +462,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..e5375c4 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,8 +8,8 @@ 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.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;
@@ -25,7 +25,7 @@ public interface ServerPluginsLocal {
*
* @return all plugins found in the DB
*/
- List<Plugin> getServerPlugins();
+ List<ServerPlugin> getServerPlugins();
/**
* Returns a plugin with the given name.
@@ -33,7 +33,7 @@ public interface ServerPluginsLocal {
* @return the named plugin
* @throws NoResultException when no plugin with that name exists
*/
- Plugin getServerPlugin(String name);
+ ServerPlugin getServerPlugin(String name);
/**
* Methods in this object that return plugins normally do not include
@@ -46,7 +46,7 @@ public interface ServerPluginsLocal {
* @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.
@@ -54,7 +54,7 @@ public interface ServerPluginsLocal {
* @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.
@@ -138,7 +138,7 @@ public interface ServerPluginsLocal {
* @return the plugin after being persisted
* @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,14 +150,14 @@ 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.
*
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..43e07fc 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;
@@ -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.getPluginName());
return plugin;
}
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 e39f570..cd1921b 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,9 +34,9 @@ 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.PluginStatusType;
+import org.rhq.core.domain.plugin.ServerPlugin;
import org.rhq.enterprise.server.plugin.pc.generic.TestGenericServerPluginService;
import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.util.LookupUtil;
@@ -75,10 +75,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,8 +98,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
}
public void testGetPlugins() throws Exception {
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
List<String> pluginNames = this.serverPluginsBean.getServerPluginNamesByEnabled(true);
assert pluginNames.contains(p1.getName()) : pluginNames;
assert pluginNames.contains(p2.getName()) : pluginNames;
@@ -107,7 +107,7 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert !pluginNames.contains(p1.getName()) : pluginNames;
assert !pluginNames.contains(p2.getName()) : pluginNames;
- Plugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
assert plugin.getId() == p1.getId() : plugin;
assert plugin.getName().equals(p1.getName()) : plugin;
assetLazyInitializationException(plugin);
@@ -118,7 +118,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 +136,11 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
}
public void testUpdatePlugins() throws Exception {
- Plugin p1 = registerPlugin(1);
+ ServerPlugin p1 = registerPlugin(1);
p1 = this.serverPluginsBean.getServerPlugin(p1.getName());
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,8 +154,8 @@ 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);
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
@@ -184,7 +184,7 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert !pluginNames.contains(p2.getName()) : pluginNames;
// make sure none of these enable/disable settings lost our config
- Plugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
+ ServerPlugin plugin = this.serverPluginsBean.getServerPlugin(p1.getName());
plugin = this.serverPluginsBean.getServerPluginRelationships(plugin);
assert plugin.getPluginConfiguration() != null; // no LazyInitException should be thrown!
assert plugin.getPluginConfiguration().equals(p1.getPluginConfiguration());
@@ -203,8 +203,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "2");
assert status == null;
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
status = this.serverPluginsBean.getServerPluginStatus(p1.getName());
assert status == PluginStatusType.INSTALLED;
@@ -218,8 +218,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
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());
+ ServerPlugin p1deleted = getDeletedPluginInTx(p1.getName());
+ ServerPlugin p2deleted = getDeletedPluginInTx(p2.getName());
assert p1deleted.getStatus() == PluginStatusType.DELETED;
assert p2deleted.getStatus() == PluginStatusType.DELETED;
@@ -240,8 +240,8 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
status = this.serverPluginsBean.getServerPluginStatus(TEST_PLUGIN_NAME_PREFIX + "2");
assert status == null;
- Plugin p1 = registerPlugin(1);
- Plugin p2 = registerPlugin(2);
+ ServerPlugin p1 = registerPlugin(1);
+ ServerPlugin p2 = registerPlugin(2);
status = this.serverPluginsBean.getServerPluginStatus(p1.getName());
assert status == PluginStatusType.INSTALLED;
@@ -255,11 +255,11 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert undeployed.size() == 2 : undeployed;
assert undeployed.contains(p1.getName()) : undeployed;
assert undeployed.contains(p2.getName()) : undeployed;
- Plugin p1deleted = getDeletedPluginInTx(p1.getName());
+ 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
@@ -284,8 +284,8 @@ 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;
@@ -297,11 +297,11 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
assert !pluginNames.contains(p2.getName()) : pluginNames;
}
- 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(), System.currentTimeMillis(), System
+ .currentTimeMillis());
plugin = this.serverPluginsBean.registerServerPlugin(getOverlord(), plugin, null);
assert plugin.getId() > 0;
@@ -313,7 +313,7 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
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 +344,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_DEPLOYMENT);
+ Query q = em.createNamedQuery(ServerPlugin.QUERY_FIND_ANY_BY_NAME);
q.setParameter("name", pluginName);
- q.setParameter("deployment", 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/TestGenericServerPluginService.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/plugin/pc/generic/TestGenericServerPluginService.java
index 592a3d9..44d03c3 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,8 @@ 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.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;
@@ -175,7 +174,7 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
}
@Override
- protected Plugin getPlugin(ServerPluginEnvironment env) {
+ protected ServerPlugin getPlugin(ServerPluginEnvironment env) {
try {
Configuration pluginConfig = null;
@@ -195,11 +194,11 @@ public class TestGenericServerPluginService extends ServerPluginService implemen
}
File pluginFile = new File(env.getPluginUrl().toURI());
- Plugin plugin = new Plugin(0, env.getPluginName(), pluginFile.getName(), pluginDescriptor
+ ServerPlugin plugin = new ServerPlugin(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());
+ .getVersion(), pluginConfig, scheduledJobsConfig, System.currentTimeMillis(), System
+ .currentTimeMillis());
return plugin;
} catch (Exception e) {
throw new RuntimeException(e);
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);
}
commit 00d502f86cea6a401c172316e395b6ff76c41d98
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Fri Nov 27 16:44:26 2009 -0500
start to adding JPA discriminators to plugin entities
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..757fa6a
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java
@@ -0,0 +1,458 @@
+/*
+ * 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;
+
+import java.io.ByteArrayInputStream;
+import java.io.Serializable;
+
+import javax.persistence.CascadeType;
+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.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;
+
+/**
+ * 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;
+
+ @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 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(@NotNull 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.
+ *
+ * @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 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, 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;
+ }
+
+ 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;
+ }
+
+ /**
+ * 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();
+ }
+
+ @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..1b4c693 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
@@ -22,30 +22,14 @@
*/
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.
@@ -53,21 +37,24 @@ import org.rhq.core.util.MessageDigestGenerator;
* 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, " //
@@ -88,7 +75,8 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " 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' "), //
+ + " 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 = "" //
@@ -112,11 +100,12 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " FROM Plugin AS p " //
+ " LEFT JOIN p.pluginConfiguration " //
+ " LEFT JOIN p.scheduledJobsConfiguration " //
- + " WHERE p.name=:name AND p.status = 'INSTALLED' "), //
+ + " 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 = "" //
+ @NamedQuery(name = Plugin.QUERY_FIND_ANY_BY_NAME, query = "" //
+ " SELECT new org.rhq.core.domain.plugin.Plugin( " //
+ " p.id, " //
+ " p.name, " //
@@ -137,34 +126,11 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " 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 = "" //
- + " 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.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, " //
@@ -185,7 +151,7 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " 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 = "" //
@@ -221,394 +187,60 @@ import org.rhq.core.util.MessageDigestGenerator;
+ " 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;
+ 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;
- }
+ super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion, deployment,
+ pluginConfig, scheduledJobsConfig, ctime, mtime);
- 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;
+ if (deployment != PluginDeploymentType.AGENT) {
+ throw new IllegalArgumentException("Plugin must only ever be of deployment type == AGENT: " + deployment);
}
}
- 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;
- }
-
+ @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 +253,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/ServerPlugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
new file mode 100644
index 0000000..0c406c3
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/ServerPlugin.java
@@ -0,0 +1,240 @@
+/*
+ * 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.plugin;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+
+import org.jetbrains.annotations.NotNull;
+
+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 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.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " 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.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " 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.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " 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.deployment, " //
+ + " p.pluginConfiguration, " //
+ + " p.scheduledJobsConfiguration, " //
+ + " 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";
+
+ public ServerPlugin() {
+ super();
+ setDeployment(PluginDeploymentType.SERVER);
+ }
+
+ public ServerPlugin(@NotNull 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,
+ PluginDeploymentType deployment, Configuration pluginConfig, Configuration scheduledJobsConfig, long ctime,
+ long mtime) {
+
+ super(id, name, path, displayName, enabled, status, description, help, md5, version, ampsVersion, deployment,
+ pluginConfig, scheduledJobsConfig, ctime, mtime);
+
+ if (deployment != PluginDeploymentType.SERVER) {
+ throw new IllegalArgumentException("ServerPlugin must only ever be of deployment type == SERVER: "
+ + deployment);
+ }
+ }
+
+ @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);
+ }
+
+ @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..be2deb3 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,9 +73,8 @@ 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);
@@ -84,9 +83,8 @@ public class PluginTest extends AbstractEJB3Test {
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,7 +98,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.getDeployment() == PluginDeploymentType.AGENT;
assert plugin.getPluginConfiguration() == null;
assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
@@ -116,7 +114,7 @@ public class PluginTest extends AbstractEJB3Test {
String ampsVersion = "2.1";
String description = "description-UPDATED";
String help = "help-UPDATED";
- PluginDeploymentType deployment = PluginDeploymentType.SERVER;
+ PluginDeploymentType deployment = PluginDeploymentType.AGENT;
Configuration pluginConfig = new Configuration();
Configuration jobsConfig = new Configuration();
pluginConfig.put(new PropertySimple("first", "last"));
@@ -181,7 +179,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.getDeployment() == PluginDeploymentType.AGENT;
assert plugin.getPluginConfiguration().equals(pluginConfig);
assert plugin.getScheduledJobsConfiguration().equals(jobsConfig);
assert plugin.getHelp().equals(help);
@@ -193,9 +191,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,7 +247,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.getDeployment() == PluginDeploymentType.AGENT;
assert plugin.getPluginConfiguration() == null;
assert plugin.getScheduledJobsConfiguration() == null;
assert plugin.getHelp() == null;
@@ -284,7 +281,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();
@@ -345,9 +342,8 @@ public class PluginTest extends AbstractEJB3Test {
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;
@@ -365,7 +361,7 @@ public class PluginTest extends AbstractEJB3Test {
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) {
@@ -399,13 +395,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 +508,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 +622,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/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..e139241 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
@@ -115,9 +115,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
if (pluginIds == null || pluginIds.size() == 0) {
return new ArrayList<Plugin>(); // nothing to do
}
- Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_TYPE);
+ Query query = entityManager.createNamedQuery(Plugin.QUERY_FIND_BY_IDS_AND_DEPLOYMENT);
query.setParameter("ids", pluginIds);
- query.setParameter("type", PluginDeploymentType.SERVER);
+ query.setParameter("deployment", PluginDeploymentType.SERVER);
return query.getResultList();
}
@@ -131,9 +131,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public List<String> getServerPluginNamesByEnabled(boolean enabled) {
- Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_TYPE);
+ Query query = entityManager.createNamedQuery(Plugin.QUERY_GET_NAMES_BY_ENABLED_AND_DEPLOYMENT);
query.setParameter("enabled", Boolean.valueOf(enabled));
- query.setParameter("type", PluginDeploymentType.SERVER);
+ query.setParameter("deployment", PluginDeploymentType.SERVER);
return query.getResultList();
}
@@ -354,9 +354,9 @@ 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);
+ Query q = this.entityManager.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_DEPLOYMENT);
q.setParameter("name", pluginName);
- q.setParameter("type", PluginDeploymentType.SERVER);
+ q.setParameter("deployment", PluginDeploymentType.SERVER);
Plugin doomed = (Plugin) q.getSingleResult();
// get the reference to attach to em and use the em.remove. this cascade deletes too.
@@ -421,9 +421,9 @@ public class ServerPluginsBean implements ServerPluginsLocal {
}
public PluginStatusType getServerPluginStatus(String pluginName) {
- Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_TYPE);
+ Query q = entityManager.createNamedQuery(Plugin.QUERY_GET_STATUS_BY_NAME_AND_DEPLOYMENT);
q.setParameter("name", pluginName);
- q.setParameter("type", PluginDeploymentType.SERVER);
+ q.setParameter("deployment", PluginDeploymentType.SERVER);
PluginStatusType status;
try {
status = (PluginStatusType) q.getSingleResult();
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..e39f570 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
@@ -348,9 +348,9 @@ public class ServerPluginsBeanTest extends AbstractEJB3Test {
EntityManager em = getEntityManager();
getTransactionManager().begin();
try {
- Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_TYPE);
+ Query q = em.createNamedQuery(Plugin.QUERY_FIND_ANY_BY_NAME_AND_DEPLOYMENT);
q.setParameter("name", pluginName);
- q.setParameter("type", PluginDeploymentType.SERVER);
+ q.setParameter("deployment", PluginDeploymentType.SERVER);
return (Plugin) q.getSingleResult();
} finally {
getTransactionManager().rollback();
14 years, 5 months