Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Frost2011-05-23 08:48:08 -0400
committerChristopher Frost2011-05-23 08:48:08 -0400
commit7326de3d853d7db48d6f6398393ad00f12271f20 (patch)
tree6eb4d791cd5d1648940141c6daf44eedf232a053
parentbf1122c74bba6941fbfeb609c4f5d7ae3cab7035 (diff)
downloadorg.eclipse.virgo.kernel-7326de3d853d7db48d6f6398393ad00f12271f20.tar.gz
org.eclipse.virgo.kernel-7326de3d853d7db48d6f6398393ad00f12271f20.tar.xz
org.eclipse.virgo.kernel-7326de3d853d7db48d6f6398393ad00f12271f20.zip
Moving all use of model mbeans to artifact model mbeans only and enforcing the use of regions
-rw-r--r--org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/model/helper/RamAccessorHelper.java19
-rw-r--r--org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/model/helper/StandardRamAccessorHelper.java71
-rw-r--r--org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/model/helper/DummyManagableArtifact.java7
-rw-r--r--org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/model/helper/StandardRamAccessorHelperTests.java30
4 files changed, 40 insertions, 87 deletions
diff --git a/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/model/helper/RamAccessorHelper.java b/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/model/helper/RamAccessorHelper.java
index df206493..a8d06230 100644
--- a/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/model/helper/RamAccessorHelper.java
+++ b/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/model/helper/RamAccessorHelper.java
@@ -33,7 +33,7 @@ public interface RamAccessorHelper {
* @param version
* @return a response string indicating success or failure
*/
- public String start(String type, String name, String version);
+ public String start(String type, String name, String version, String region);
/**
* Stop the Artifact with the given type, name and version.
@@ -42,7 +42,7 @@ public interface RamAccessorHelper {
* @param version
* @return a response string indicating success or failure
*/
- public String stop(String type, String name, String version);
+ public String stop(String type, String name, String version, String region);
/**
* Uninstall the Artifact with the given type, name and version.
@@ -51,7 +51,7 @@ public interface RamAccessorHelper {
* @param version
* @return a response string indicating success or failure
*/
- public String uninstall(String type, String name, String version);
+ public String uninstall(String type, String name, String version, String region);
/**
* Refresh the Artifact with the given type, name and version.
@@ -60,7 +60,7 @@ public interface RamAccessorHelper {
* @param version
* @return a response string indicating success or failure
*/
- public String refresh(String type, String name, String version);
+ public String refresh(String type, String name, String version, String region);
/**
* Return a list of all the types of the user installed artifacts in the system.
@@ -94,17 +94,6 @@ public interface RamAccessorHelper {
* @param type of {@link org.eclipse.virgo.kernel.model.Artifact artifact}
* @param name of {@link org.eclipse.virgo.kernel.model.Artifact artifact}
* @param version of {@link org.eclipse.virgo.kernel.model.Artifact artifact}
- * @return an {@link ArtifactAccessor} for the identified artifact, or <code>null</code> if there isn't one
- */
- public ArtifactAccessor getArtifact(String type, String name, String version);
-
- /**
- * Return a representation of the requested artifact as an {@link ArtifactAccessor}. If no such artifact exists null
- * may be returned.
- *
- * @param type of {@link org.eclipse.virgo.kernel.model.Artifact artifact}
- * @param name of {@link org.eclipse.virgo.kernel.model.Artifact artifact}
- * @param version of {@link org.eclipse.virgo.kernel.model.Artifact artifact}
* @param region of {@link org.eclipse.virgo.kernel.model.Artifact artifact}
* @return an {@link ArtifactAccessor} for the identified artifact, or <code>null</code> if there isn't one
*/
diff --git a/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/model/helper/StandardRamAccessorHelper.java b/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/model/helper/StandardRamAccessorHelper.java
index f65f14e6..84b35d3f 100644
--- a/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/model/helper/StandardRamAccessorHelper.java
+++ b/org.eclipse.virgo.kernel.shell/src/main/java/org/eclipse/virgo/kernel/shell/model/helper/StandardRamAccessorHelper.java
@@ -64,9 +64,7 @@ final public class StandardRamAccessorHelper implements RamAccessorHelper {
private static final String OPERATION_FAIL = "An error occurred during the %s operation";
- private static final String ARTIFACT_MBEAN_QUERY = "org.eclipse.virgo.kernel:type=Model,artifact-type=%s,name=%s,version=%s";
-
- private static final String REGION_ARTIFACT_MBEAN_QUERY = "org.eclipse.virgo.kernel:type=ArtifactModel,artifact-type=%s,name=%s,version=%s,region=%s";
+ private static final String ARTIFACT_MODEL_MBEAN_QUERY = "org.eclipse.virgo.kernel:type=ArtifactModel,artifact-type=%s,name=%s,version=%s,region=%s";
public StandardRamAccessorHelper() {
}
@@ -74,35 +72,35 @@ final public class StandardRamAccessorHelper implements RamAccessorHelper {
/**
* {@inheritDoc}
*/
- public String start(String type, String name, String version) {
- return performOperation(type, name, version, "start");
+ public String start(String type, String name, String version, String region) {
+ return performOperation(type, name, version, region, "start");
}
/**
* {@inheritDoc}
*/
- public String stop(String type, String name, String version) {
- return performOperation(type, name, version, "stop");
+ public String stop(String type, String name, String version, String region) {
+ return performOperation(type, name, version, region, "stop");
}
/**
* {@inheritDoc}
*/
- public String uninstall(String type, String name, String version) {
- return performOperation(type, name, version, "uninstall");
+ public String uninstall(String type, String name, String version, String region) {
+ return performOperation(type, name, version, region, "uninstall");
}
/**
* {@inheritDoc}
*/
- public String refresh(String type, String name, String version) {
- return performOperation(type, name, version, "refresh");
+ public String refresh(String type, String name, String version, String region) {
+ return performOperation(type, name, version, region, "refresh");
}
- private String performOperation(String type, String name, String version, String operationName) {
+ private String performOperation(String type, String name, String version, String region, String operationName) {
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
try {
- ObjectName objectName = new ObjectName(String.format(ARTIFACT_MBEAN_QUERY, type, name, version));
+ ObjectName objectName = new ObjectName(String.format(ARTIFACT_MODEL_MBEAN_QUERY, type, name, version, region));
mBeanServer.invoke(objectName, operationName, new Object[0], new String[0]);
return String.format(OPERATION_SUCSESS, operationName);
} catch (Exception e) {
@@ -119,7 +117,7 @@ final public class StandardRamAccessorHelper implements RamAccessorHelper {
List<String> types = new ArrayList<String>();
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
try {
- Set<ObjectName> objectNames = mBeanServer.queryNames(new ObjectName("org.eclipse.virgo.kernel:type=Model,*"), null);
+ Set<ObjectName> objectNames = mBeanServer.queryNames(new ObjectName("org.eclipse.virgo.kernel:type=ArtifactModel,*"), null);
for (ObjectName objectName : objectNames) {
String type = objectName.getKeyProperty("artifact-type");
if (!(type == null || types.contains(type))) {
@@ -153,7 +151,7 @@ final public class StandardRamAccessorHelper implements RamAccessorHelper {
List<ArtifactAccessorPointer> artifacts = new ArrayList<ArtifactAccessorPointer>();
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
try {
- Set<ObjectName> objectNames = mBeanServer.queryNames(new ObjectName(String.format("org.eclipse.virgo.kernel:type=Model,artifact-type=%s,*", type)), null);
+ Set<ObjectName> objectNames = mBeanServer.queryNames(new ObjectName(String.format("org.eclipse.virgo.kernel:type=ArtifactModel,artifact-type=%s,*", type)), null);
for (ObjectName objectName : objectNames) {
ArtifactAccessorPointer pointer = buildArtifactAccessorPointer(objectName);
if (pointer != null) {
@@ -171,56 +169,15 @@ final public class StandardRamAccessorHelper implements RamAccessorHelper {
}
return artifacts;
}
-
- /*
- * Partial temporary workaround for bug 342458. Need to add the region to the dojo tree so it can be passed
- * in as a parameter. Meanwhile if the artifact isn't found in the user region portion of JMX, try the
- * kernel portion. This is not a proper fix as some artifacts appear in both user region and kernel and this
- * algorithm will sometimes wrongly return the user region artifact rather than the kernel artifacts.
- * Perhaps this is worse than a NPE, but it's only temporary and at least it proves the underlying JMX
- * structure.
- */
-
- /**
- * {@inheritDoc}
- */
- public ArtifactAccessor getArtifact(String type, String name, String version) {
- String kernelRegion = "org.eclipse.equinox.region.kernel";
- // should be a parameter, but note there is no region
- // in the user region mbeans (for backward compatibility)
- ArtifactAccessorPointer pointer = null;
- ObjectName objectName = null;
- try {
- objectName = new ObjectName(String.format(ARTIFACT_MBEAN_QUERY, type, name, version));
- pointer = buildArtifactAccessorPointer(objectName);
- if(pointer == null){
- objectName = new ObjectName(String.format(REGION_ARTIFACT_MBEAN_QUERY, type, name, version, kernelRegion));
- pointer = buildArtifactAccessorPointer(objectName);
- }
- } catch (MalformedObjectNameException e) {
- LOGGER.warn("Unexpected error while trying to read the Runtime Artifact Model MBeans", e);
- } catch (NullPointerException e) {
- LOGGER.warn("Unexpected error while trying to read the Runtime Artifact Model MBeans", e);
- }
- return getArtifact(pointer, objectName);
- }
/**
* {@inheritDoc}
*/
public ArtifactAccessor getArtifact(String type, String name, String version, String region) {
- String kernelRegion = "org.eclipse.equinox.region.kernel";
- // should be a parameter, but note there is no region
- // in the user region mbeans (for backward compatibility)
-
ArtifactAccessorPointer pointer = null;
ObjectName objectName = null;
try {
- if(kernelRegion.equals(region)){
- objectName = new ObjectName(String.format(REGION_ARTIFACT_MBEAN_QUERY, type, name, version, region));
- } else {
- objectName = new ObjectName(String.format(ARTIFACT_MBEAN_QUERY, type, name, version));
- }
+ objectName = new ObjectName(String.format(ARTIFACT_MODEL_MBEAN_QUERY, type, name, version, region));
pointer = buildArtifactAccessorPointer(objectName);
} catch (MalformedObjectNameException e) {
LOGGER.warn("Unexpected error while trying to read the Runtime Artifact Model MBeans", e);
diff --git a/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/model/helper/DummyManagableArtifact.java b/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/model/helper/DummyManagableArtifact.java
index 89af2d4f..15ad4a39 100644
--- a/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/model/helper/DummyManagableArtifact.java
+++ b/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/model/helper/DummyManagableArtifact.java
@@ -29,10 +29,13 @@ public final class DummyManagableArtifact implements ManageableArtifact {
private final String name;
- public DummyManagableArtifact(String type, String name, String version) {
+ private final String region;
+
+ public DummyManagableArtifact(String type, String name, String version, String region) {
this.type = type;
this.name = name;
this.version = version;
+ this.region = region;
}
public void start() {
@@ -78,7 +81,7 @@ public final class DummyManagableArtifact implements ManageableArtifact {
}
public String getRegion() {
- return "testRegion";
+ return region;
}
}
diff --git a/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/model/helper/StandardRamAccessorHelperTests.java b/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/model/helper/StandardRamAccessorHelperTests.java
index c9a19a21..9124f080 100644
--- a/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/model/helper/StandardRamAccessorHelperTests.java
+++ b/org.eclipse.virgo.kernel.shell/src/test/java/org/eclipse/virgo/kernel/shell/model/helper/StandardRamAccessorHelperTests.java
@@ -42,13 +42,17 @@ public class StandardRamAccessorHelperTests {
private static final String VERSION = "test.version";
+ private static final String REGION = "test.region";
+
private static final String TYPE_EXISTS = "test.type.exists";
private static final String NAME_EXISTS = "test.name.exists";
private static final String VERSION_EXISTS = "test.version.exists";
- private static final String ARTIFACT_MBEAN_FORMAT = "org.eclipse.virgo.kernel:type=Model,artifact-type=%s,name=%s,version=%s";
+ private static final String REGION_EXISTS = "test.region.exists";
+
+ private static final String ARTIFACT_MBEAN_FORMAT = "org.eclipse.virgo.kernel:type=ArtifactModel,artifact-type=%s,name=%s,version=%s,region=%s";
private RamAccessorHelper ramAccessorHelper;
@@ -58,9 +62,9 @@ public class StandardRamAccessorHelperTests {
@Before
public void setUp() throws Exception {
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
- ObjectName objectName = new ObjectName(String.format(ARTIFACT_MBEAN_FORMAT, TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS));
+ ObjectName objectName = new ObjectName(String.format(ARTIFACT_MBEAN_FORMAT, TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS, REGION_EXISTS));
if(!mBeanServer.isRegistered(objectName)) {
- DummyManagableArtifact dummyManagableArtifact = new DummyManagableArtifact(TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS);
+ DummyManagableArtifact dummyManagableArtifact = new DummyManagableArtifact(TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS, REGION_EXISTS);
mBeanServer.registerMBean(dummyManagableArtifact, objectName);
AttributeList attributeList = new AttributeList();
attributeList.add(new Attribute("type", TYPE_EXISTS));
@@ -76,7 +80,7 @@ public class StandardRamAccessorHelperTests {
*/
@Test
public void testStart() {
- String message = this.ramAccessorHelper.start(TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS);
+ String message = this.ramAccessorHelper.start(TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS, REGION_EXISTS);
assertNotNull(message);
assertTrue(message.contains("successful"));
assertTrue(message.contains("start"));
@@ -87,7 +91,7 @@ public class StandardRamAccessorHelperTests {
*/
@Test
public void testStop() {
- String message = this.ramAccessorHelper.stop(TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS);
+ String message = this.ramAccessorHelper.stop(TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS, REGION_EXISTS);
assertNotNull(message);
assertTrue(message.contains("successful"));
assertTrue(message.contains("stop"));
@@ -98,7 +102,7 @@ public class StandardRamAccessorHelperTests {
*/
@Test
public void testUninstall() {
- String message = this.ramAccessorHelper.uninstall(TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS);
+ String message = this.ramAccessorHelper.uninstall(TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS, REGION_EXISTS);
assertNotNull(message);
assertTrue(message.contains("successful"));
assertTrue(message.contains("uninstall"));
@@ -109,7 +113,7 @@ public class StandardRamAccessorHelperTests {
*/
@Test
public void testUpdateAndRefresh() {
- String message = this.ramAccessorHelper.refresh(TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS);
+ String message = this.ramAccessorHelper.refresh(TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS, REGION_EXISTS);
assertNotNull(message);
assertTrue(message.contains("successful"));
assertTrue(message.contains("refresh"));
@@ -120,7 +124,7 @@ public class StandardRamAccessorHelperTests {
*/
@Test
public void testStartFail() {
- String message = this.ramAccessorHelper.start(TYPE, NAME, VERSION);
+ String message = this.ramAccessorHelper.start(TYPE, NAME, VERSION, REGION);
assertNotNull(message);
assertTrue(message.contains("error"));
assertTrue(message.contains("start"));
@@ -131,7 +135,7 @@ public class StandardRamAccessorHelperTests {
*/
@Test
public void testStopFail() {
- String message = this.ramAccessorHelper.stop(TYPE, NAME, VERSION);
+ String message = this.ramAccessorHelper.stop(TYPE, NAME, VERSION, REGION);
assertNotNull(message);
assertTrue(message.contains("error"));
assertTrue(message.contains("stop"));
@@ -142,7 +146,7 @@ public class StandardRamAccessorHelperTests {
*/
@Test
public void testUninstallFail() {
- String message = this.ramAccessorHelper.uninstall(TYPE, NAME, VERSION);
+ String message = this.ramAccessorHelper.uninstall(TYPE, NAME, VERSION, REGION);
assertNotNull(message);
assertTrue(message.contains("error"));
assertTrue(message.contains("uninstall"));
@@ -153,7 +157,7 @@ public class StandardRamAccessorHelperTests {
*/
@Test
public void testUpdateAndRefreshFail() {
- String message = this.ramAccessorHelper.refresh(TYPE, NAME, VERSION);
+ String message = this.ramAccessorHelper.refresh(TYPE, NAME, VERSION, REGION);
assertNotNull(message);
assertTrue(message.contains("error"));
assertTrue(message.contains("refresh"));
@@ -184,7 +188,7 @@ public class StandardRamAccessorHelperTests {
@Test
public void testGetArtifactExist() {
- ArtifactAccessor artifact = this.ramAccessorHelper.getArtifact(TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS);
+ ArtifactAccessor artifact = this.ramAccessorHelper.getArtifact(TYPE_EXISTS, NAME_EXISTS, VERSION_EXISTS, REGION_EXISTS);
assertNotNull(artifact);
assertEquals(TYPE_EXISTS, artifact.getType());
assertEquals(NAME_EXISTS, artifact.getName());
@@ -193,7 +197,7 @@ public class StandardRamAccessorHelperTests {
@Test
public void testGetArtifactNotExist() {
- ArtifactAccessor artifact = this.ramAccessorHelper.getArtifact(TYPE, NAME, VERSION);
+ ArtifactAccessor artifact = this.ramAccessorHelper.getArtifact(TYPE, NAME, VERSION, REGION);
assertNull(artifact);
}

Back to the top