Skip to content
Browse files

AS7-4078 - upgrade subsystem example

Archetype upgrade
upgrade to resource definition
upgrade to 7.1.1
  • Loading branch information...
1 parent 4d37388 commit 0361b928256abdffc22b362de2302d0de155c612 @ctomc ctomc committed with kabir Mar 7, 2012
Showing with 495 additions and 917 deletions.
  1. +42 −31 jboss-as-subsystem-archetype/archetype-metadata.xml
  2. +10 −4 jboss-as-subsystem-archetype/archetype-pom.xml
  3. +3 −3 jboss-as-subsystem-archetype/archetype.properties
  4. +3 −1 jboss-as-subsystem-archetype/create-archetype.sh
  5. +2 −2 jboss-as-subsystem-archetype/pom.xml
  6. +31 −0 ...s-as-subsystem-archetype/src/main/java/com/mycompany/subsystem/extension/SubsystemDefinition.java
  7. +40 −53 jboss-as-subsystem-archetype/src/main/java/com/mycompany/subsystem/extension/SubsystemExtension.java
  8. +0 −71 jboss-as-subsystem-archetype/src/main/java/com/mycompany/subsystem/extension/SubsystemProviders.java
  9. +3 −0 ...ystem-archetype/src/main/resources/com/mycompany/subsystem/extension/LocalDescriptions.properties
  10. +6 −120 ...subsystem-archetype/src/test/java/com/mycompany/subsystem/extension/SubsystemParsingTestCase.java
  11. +1 −1 jboss-as-subsystem-example/pom.xml
  12. +1 −3 jboss-as-subsystem-example/src/main/java/com/acme/corp/tracker/extension/SubsystemAdd.java
  13. +0 −214 jboss-as-subsystem-example/src/main/java/com/acme/corp/tracker/extension/SubsystemExtension.java
  14. +0 −103 jboss-as-subsystem-example/src/main/java/com/acme/corp/tracker/extension/SubsystemProviders.java
  15. +173 −0 jboss-as-subsystem-example/src/main/java/com/acme/corp/tracker/extension/TrackerExtension.java
  16. +6 −7 jboss-as-subsystem-example/src/main/java/com/acme/corp/tracker/extension/TrackerService.java
  17. +36 −0 ...s-subsystem-example/src/main/java/com/acme/corp/tracker/extension/TrackerSubsystemDefinition.java
  18. +43 −19 jboss-as-subsystem-example/src/main/java/com/acme/corp/tracker/extension/TrackerTickHandler.java
  19. +8 −23 ...system-example/src/main/java/com/acme/corp/tracker/extension/{TypeAddHandler.java → TypeAdd.java}
  20. +44 −0 jboss-as-subsystem-example/src/main/java/com/acme/corp/tracker/extension/TypeDefinition.java
  21. +3 −11 ...-example/src/main/java/com/acme/corp/tracker/extension/{TypeRemoveHandler.java → TypeRemove.java}
  22. +1 −1 jboss-as-subsystem-example/src/main/resources/META-INF/services/org.jboss.as.controller.Extension
  23. +7 −0 ...subsystem-example/src/main/resources/com/acme/corp/tracker/extension/LocalDescriptions.properties
  24. +20 −0 jboss-as-subsystem-example/src/main/resources/schema/jboss-as-mysubsystem_1_0.xsd
  25. +0 −24 jboss-as-subsystem-example/src/main/resources/schema/mysubsystem.xsd
  26. +7 −226 ...-as-subsystem-example/src/test/java/com/acme/corp/tracker/extension/SubsystemParsingTestCase.java
  27. +5 −0 jboss-as-subsystem-example/src/test/resources/com/acme/corp/tracker/extension/subsystem.xml
View
73 jboss-as-subsystem-archetype/archetype-metadata.xml
@@ -1,33 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
-<archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="jboss-as-subsystem-src"
- xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <requiredProperties>
- <requiredProperty key="name">
- <defaultValue>JBoss AS 7 subsystem project</defaultValue>
- </requiredProperty>
- <requiredProperty key="module"/>
- </requiredProperties>
- <fileSets>
- <fileSet filtered="true" packaged="true" encoding="UTF-8">
- <directory>src/main/java</directory>
- <includes>
- <include>**/*.java</include>
- </includes>
- </fileSet>
- <fileSet filtered="true" encoding="UTF-8">
- <directory>src/main/resources</directory>
- <includes>
- <include>**/*.Extension</include>
- <include>**/module.xml</include>
- <include>schema/*.xsd</include>
- </includes>
- </fileSet>
- <fileSet filtered="true" packaged="true" encoding="UTF-8">
- <directory>src/test/java</directory>
- <includes>
- <include>**/*.java</include>
- </includes>
- </fileSet>
- </fileSets>
+<archetype-descriptor
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
+ name="jboss-as-subsystem-src"
+ xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <requiredProperties>
+ <requiredProperty key="name">
+ <defaultValue>JBoss AS 7 subsystem project</defaultValue>
+ </requiredProperty>
+ <requiredProperty key="module"/>
+ </requiredProperties>
+ <fileSets>
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8" packaged="false">
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.Extension</include>
+ <include>**/module.xml</include>
+ <include>schema/*.xsd</include>
+ </includes>
+ </fileSet>
+ <fileSet filtered="true" encoding="UTF-8" packaged="true">
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.properties</include>
+ </includes>
+ </fileSet>
+
+ <fileSet filtered="true" packaged="true" encoding="UTF-8">
+ <directory>src/test/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileSet>
+
+ </fileSets>
+
</archetype-descriptor>
View
14 jboss-as-subsystem-archetype/archetype-pom.xml
@@ -6,12 +6,12 @@
<parent>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-parent</artifactId>
- <version>7.1.0.Final</version>
+ <version>7.1.1.Final</version>
</parent>
<groupId>org.jboss.as.archetypes</groupId>
<artifactId>jboss-as-subsystem</artifactId>
- <version>7.1.0.Final</version>
+ <version>7.1.1.Final</version>
<packaging>maven-archetype</packaging>
<name>JBoss AS 7 Subsystem</name>
@@ -28,6 +28,12 @@
<organizationUrl>http://redhat.com/jboss</organizationUrl>
<url>http://kabir-khan.blogspot.com/</url>
</developer>
+ <developer>
+ <name>Tomaz Cerar</name>
+ <email>tomaz.cerar@redhat.com</email>
+ <organization>JBoss, by Red Hat</organization>
+ <organizationUrl>http://redhat.com/jboss</organizationUrl>
+ </developer>
</developers>
<repositories>
@@ -50,15 +56,15 @@
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
- <version>2.0-alpha-5</version>
+ <version>2.2</version>
</extension>
</extensions>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
- <version>2.0-alpha-5</version>
+ <version>2.2</version>
<extensions>true</extensions>
</plugin>
</plugins>
View
6 jboss-as-subsystem-archetype/archetype.properties
@@ -1,9 +1,9 @@
archetype.groupId=org.jboss.as.archetypes
archetype.artifactId=jboss-as-subsystem
-archetype.version=7.1.0.Final
+archetype.version=7.1.1.Final
# Java package of the source files; will be replaced with the ${package} expression
archetype.package=com.mycompany.subsystem
-archetype.languages=java
+archetype.languages=java, properties
# value of <artifactId> element in POM is converted to ${artifactId} expression in filtered files
-archetype.filteredExtensions=java,txt,html
+archetype.filteredExtensions=java,txt,html,properties
name=JBoss AS 7 subsystem project
View
4 jboss-as-subsystem-archetype/create-archetype.sh
@@ -37,6 +37,8 @@ cp -f archetype-metadata.xml $ARCHETYPE_DIR/src/main/resources/META-INF/maven/ar
touch $ARCHETYPE_DIR/src/main/resources/META-INF/maven/archetype-metadata.xml
cp archetype-test.properties $ARCHETYPE_DIR/src/test/resources/projects/basic/archetype.properties
+mv $ARCHETYPE_RESOURCES_DIR/src/main/resources/com/mycompany/subsystem $ARCHETYPE_RESOURCES_DIR/src/main/resources/
+
#rsync -az --exclude .svn eclipse-dot-files/ $ARCHETYPE_RESOURCES_DIR/
# fix the archetype plugin being an idiot
find $ARCHETYPE_RESOURCES_DIR -type f -exec sed -i -e 's;packageInPathFormat;package;g' {} \;
@@ -54,6 +56,6 @@ if [ ! -z $1 ] && [ "$1" = "generate" ]; then
echo Generating project from archetype...
cd target
mvn archetype:generate -B -DarchetypeCatalog=local \
- -DarchetypeArtifactId=jboss-javaee6-webapp -DarchetypeGroupId=org.jboss.spec.archetypes -DarchetypeVersion=7.0.1.Final \
+ -DarchetypeArtifactId=jboss-javaee6-webapp -DarchetypeGroupId=org.jboss.spec.archetypes -DarchetypeVersion=7.1.1.Final \
-DartifactId=example-project -DgroupId=com.acme -Dpackage=com.acme.example -Dversion=1.0.0-SNAPSHOT -Dname="Java EE 6 subsystem project"
fi
View
4 jboss-as-subsystem-archetype/pom.xml
@@ -33,14 +33,14 @@
<groupId>org.jboss.as.archetypes</groupId>
<artifactId>jboss-as-subsystem-src</artifactId>
- <version>7.1.0.Final</version>
+ <version>7.1.1.Final</version>
<name>JBoss Application Server: Subsystem Artifact</name>
<packaging>jar</packaging>
<properties>
- <version.jboss.as>7.1.0.Final</version.jboss.as>
+ <version.jboss.as>7.1.1.Final</version.jboss.as>
<version.junit>4.8.2</version.junit>
<module.name>${module}</module.name>
</properties>
View
31 ...system-archetype/src/main/java/com/mycompany/subsystem/extension/SubsystemDefinition.java
@@ -0,0 +1,31 @@
+package com.mycompany.subsystem.extension;
+
+import org.jboss.as.controller.SimpleResourceDefinition;
+import org.jboss.as.controller.registry.ManagementResourceRegistration;
+
+/**
+ * @author <a href="mailto:tcerar@redhat.com">Tomaz Cerar</a>
+ */
+public class SubsystemDefinition extends SimpleResourceDefinition {
+ public static final SubsystemDefinition INSTANCE = new SubsystemDefinition();
+
+ private SubsystemDefinition() {
+ super(SubsystemExtension.SUBSYSTEM_PATH,
+ SubsystemExtension.getResourceDescriptionResolver(null),
+ //We always need to add an 'add' operation
+ SubsystemAdd.INSTANCE,
+ //Every resource that is added, normally needs a remove operation
+ SubsystemRemove.INSTANCE);
+ }
+
+ @Override
+ public void registerOperations(ManagementResourceRegistration resourceRegistration) {
+ super.registerOperations(resourceRegistration);
+ //you can register aditional operations here
+ }
+
+ @Override
+ public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
+ //you can register attributes here
+ }
+}
View
93 ...bsystem-archetype/src/main/java/com/mycompany/subsystem/extension/SubsystemExtension.java
@@ -1,26 +1,11 @@
package com.mycompany.subsystem.extension;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
-
-import java.util.List;
-import java.util.Locale;
-
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-
import org.jboss.as.controller.Extension;
import org.jboss.as.controller.ExtensionContext;
-import org.jboss.as.controller.OperationContext;
-import org.jboss.as.controller.OperationFailedException;
-import org.jboss.as.controller.OperationStepHandler;
+import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SubsystemRegistration;
-import org.jboss.as.controller.descriptions.DescriptionProvider;
-import org.jboss.as.controller.descriptions.common.CommonDescriptions;
+import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver;
+import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler;
import org.jboss.as.controller.parsing.ExtensionParsingContext;
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
@@ -32,38 +17,56 @@
import org.jboss.staxmapper.XMLExtendedStreamReader;
import org.jboss.staxmapper.XMLExtendedStreamWriter;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import java.util.List;
+
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
+
/**
- *
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
*/
public class SubsystemExtension implements Extension {
- /** The name space used for the {@code substystem} element */
+ /**
+ * The name space used for the {@code substystem} element
+ */
public static final String NAMESPACE = "urn:mycompany:mysubsystem:1.0";
- /** The name of our subsystem within the model. */
+ /**
+ * The name of our subsystem within the model.
+ */
public static final String SUBSYSTEM_NAME = "mysubsystem";
- /** The parser used for parsing our subsystem */
+ /**
+ * The parser used for parsing our subsystem
+ */
private final SubsystemParser parser = new SubsystemParser();
+ protected static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME);
+ private static final String RESOURCE_NAME = SubsystemExtension.class.getPackage().getName() + ".LocalDescriptions";
+
+ static StandardResourceDescriptionResolver getResourceDescriptionResolver(final String keyPrefix) {
+ String prefix = SUBSYSTEM_NAME + (keyPrefix == null ? "" : "." + keyPrefix);
+ return new StandardResourceDescriptionResolver(prefix, RESOURCE_NAME, SubsystemExtension.class.getClassLoader(), true, false);
+ }
+
@Override
public void initializeParsers(ExtensionParsingContext context) {
- context.setSubsystemXmlMapping(NAMESPACE, parser);
+ context.setSubsystemXmlMapping(SUBSYSTEM_NAME, NAMESPACE, parser);
}
@Override
public void initialize(ExtensionContext context) {
- final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME);
- final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(SubsystemProviders.SUBSYSTEM);
- //We always need to add an 'add' operation
- registration.registerOperationHandler(ADD, SubsystemAdd.INSTANCE, SubsystemProviders.SUBSYSTEM_ADD, false);
- //Every resource that is added, normally needs a remove operation
- registration.registerOperationHandler(REMOVE, SubsystemRemove.INSTANCE, SubsystemProviders.SUBSYSTEM_REMOVE, false);
- //We always need to add a 'describe' operation
- registration.registerOperationHandler(DESCRIBE, SubsystemDescribeHandler.INSTANCE, SubsystemDescribeHandler.INSTANCE, false, OperationEntry.EntryType.PRIVATE);
+ final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, 1, 0);
+ final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(SubsystemDefinition.INSTANCE);
+ registration.registerOperationHandler(DESCRIBE, GenericSubsystemDescribeHandler.INSTANCE, GenericSubsystemDescribeHandler.INSTANCE, false, OperationEntry.EntryType.PRIVATE);
subsystem.registerXMLElementWriter(parser);
}
@@ -80,14 +83,18 @@ private static ModelNode createAddSubsystemOperation() {
*/
private static class SubsystemParser implements XMLStreamConstants, XMLElementReader<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> {
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override
public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
context.startSubsystemElement(SubsystemExtension.NAMESPACE, false);
writer.writeEndElement();
}
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
// Require no content
@@ -96,24 +103,4 @@ public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) th
}
}
-
- /**
- * Recreate the steps to put the subsystem in the same state it was in.
- * This is used in domain mode to query the profile being used, in order to
- * get the steps needed to create the servers
- */
- private static class SubsystemDescribeHandler implements OperationStepHandler, DescriptionProvider {
- static final SubsystemDescribeHandler INSTANCE = new SubsystemDescribeHandler();
-
- public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
- context.getResult().add(createAddSubsystemOperation());
- context.completeStep();
- }
-
- @Override
- public ModelNode getModelDescription(Locale locale) {
- return CommonDescriptions.getSubsystemDescribeOperation(locale);
- }
- }
-
}
View
71 ...bsystem-archetype/src/main/java/com/mycompany/subsystem/extension/SubsystemProviders.java
@@ -1,71 +0,0 @@
-package com.mycompany.subsystem.extension;
-
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HEAD_COMMENT_ALLOWED;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAMESPACE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_NAME;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.TAIL_COMMENT_ALLOWED;
-
-import java.util.Locale;
-
-import org.jboss.as.controller.descriptions.DescriptionProvider;
-import org.jboss.dmr.ModelNode;
-
-/**
- * Contains the description providers. The description providers are what print out the
- * information when you execute the {@code read-resource-description} operation.
- *
- * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
- */
-class SubsystemProviders {
-
- /**
- * Used to create the description of the subsystem
- */
- public static DescriptionProvider SUBSYSTEM = new DescriptionProvider() {
- public ModelNode getModelDescription(Locale locale) {
- //The locale is passed in so you can internationalize the strings used in the descriptions
-
- final ModelNode subsystem = new ModelNode();
- subsystem.get(DESCRIPTION).set("This is my subsystem");
- subsystem.get(HEAD_COMMENT_ALLOWED).set(true);
- subsystem.get(TAIL_COMMENT_ALLOWED).set(true);
- subsystem.get(NAMESPACE).set(SubsystemExtension.NAMESPACE);
-
- return subsystem;
- }
- };
-
- /**
- * Used to create the description of the subsystem add method
- */
- public static DescriptionProvider SUBSYSTEM_ADD = new DescriptionProvider() {
- public ModelNode getModelDescription(Locale locale) {
- //The locale is passed in so you can internationalize the strings used in the descriptions
-
- final ModelNode subsystem = new ModelNode();
- subsystem.get(OPERATION_NAME).set(ADD);
- subsystem.get(DESCRIPTION).set("Adds my subsystem");
-
- return subsystem;
- }
- };
-
- /**
- * Used to create the description of the subsystem remove method
- */
- public static DescriptionProvider SUBSYSTEM_REMOVE = new DescriptionProvider() {
- public ModelNode getModelDescription(Locale locale) {
- //The locale is passed in so you can internationalize the strings used in the descriptions
-
- final ModelNode subsystem = new ModelNode();
- subsystem.get(OPERATION_NAME).set(REMOVE);
- subsystem.get(DESCRIPTION).set("Removes my subsystem");
-
- return subsystem;
- }
- };
-
-}
View
3 ...chetype/src/main/resources/com/mycompany/subsystem/extension/LocalDescriptions.properties
@@ -0,0 +1,3 @@
+mysubsystem=My subsystem
+mysubsystem.add=Operation Adds subsystem
+mysubsystem.remove=Operation Removes subsystem
View
126 ...m-archetype/src/test/java/com/mycompany/subsystem/extension/SubsystemParsingTestCase.java
@@ -1,139 +1,25 @@
package com.mycompany.subsystem.extension;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
-
-import java.util.List;
-
-import junit.framework.Assert;
-
-import org.jboss.as.controller.PathAddress;
-import org.jboss.as.controller.PathElement;
-import org.jboss.as.subsystem.test.AbstractSubsystemTest;
-import org.jboss.as.subsystem.test.KernelServices;
-import org.jboss.dmr.ModelNode;
-import org.junit.Test;
+import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
+import java.io.IOException;
/**
- *
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
*/
-public class SubsystemParsingTestCase extends AbstractSubsystemTest {
+public class SubsystemParsingTestCase extends AbstractSubsystemBaseTest {
public SubsystemParsingTestCase() {
super(SubsystemExtension.SUBSYSTEM_NAME, new SubsystemExtension());
}
- /**
- * Tests that the xml is parsed into the correct operations
- */
- @Test
- public void testParseSubsystem() throws Exception {
- //Parse the subsystem xml into operations
- String subsystemXml =
- "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
- "</subsystem>";
- List<ModelNode> operations = super.parse(subsystemXml);
-
- ///Check that we have the expected number of operations
- Assert.assertEquals(1, operations.size());
- //Check that each operation has the correct content
- ModelNode addSubsystem = operations.get(0);
- Assert.assertEquals(ADD, addSubsystem.get(OP).asString());
- PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
- Assert.assertEquals(1, addr.size());
- PathElement element = addr.getElement(0);
- Assert.assertEquals(SUBSYSTEM, element.getKey());
- Assert.assertEquals(SubsystemExtension.SUBSYSTEM_NAME, element.getValue());
- }
-
- /**
- * Test that the model created from the xml looks as expected
- */
- @Test
- public void testInstallIntoController() throws Exception {
- //Parse the subsystem xml and install into the controller
- String subsystemXml =
- "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
+ @Override
+ protected String getSubsystemXml() throws IOException {
+ return "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
"</subsystem>";
- KernelServices services = super.installInController(subsystemXml);
-
- //Read the whole model and make sure it looks as expected
- ModelNode model = services.readWholeModel();
- Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(SubsystemExtension.SUBSYSTEM_NAME));
}
- /**
- * Starts a controller with a given subsystem xml and then checks that a second
- * controller started with the xml marshalled from the first one results in the same model
- */
- @Test
- public void testParseAndMarshalModel() throws Exception {
- //Parse the subsystem xml and install into the first controller
- String subsystemXml =
- "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
- "</subsystem>";
- KernelServices servicesA = super.installInController(subsystemXml);
- //Get the model and the persisted xml from the first controller
- ModelNode modelA = servicesA.readWholeModel();
- String marshalled = servicesA.getPersistedSubsystemXml();
- //Install the persisted xml from the first controller into a second controller
- KernelServices servicesB = super.installInController(marshalled);
- ModelNode modelB = servicesB.readWholeModel();
-
- //Make sure the models from the two controllers are identical
- super.compare(modelA, modelB);
- }
-
- /**
- * Starts a controller with the given subsystem xml and then checks that a second
- * controller started with the operations from its describe action results in the same model
- */
- @Test
- public void testDescribeHandler() throws Exception {
- //Parse the subsystem xml and install into the first controller
- String subsystemXml =
- "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
- "</subsystem>";
- KernelServices servicesA = super.installInController(subsystemXml);
- //Get the model and the describe operations from the first controller
- ModelNode modelA = servicesA.readWholeModel();
- ModelNode describeOp = new ModelNode();
- describeOp.get(OP).set(DESCRIBE);
- describeOp.get(OP_ADDR).set(
- PathAddress.pathAddress(
- PathElement.pathElement(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME)).toModelNode());
- List<ModelNode> operations = super.checkResultAndGetContents(servicesA.executeOperation(describeOp)).asList();
-
-
- //Install the describe options from the first controller into a second controller
- KernelServices servicesB = super.installInController(operations);
- ModelNode modelB = servicesB.readWholeModel();
-
- //Make sure the models from the two controllers are identical
- super.compare(modelA, modelB);
- }
-
- /**
- * Tests that the subsystem can be removed
- */
- @Test
- public void testSubsystemRemoval() throws Exception {
- //Parse the subsystem xml and install into the first controller
- String subsystemXml =
- "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
- "</subsystem>";
- KernelServices services = super.installInController(subsystemXml);
- //Checks that the subsystem was removed from the model
- super.assertRemoveSubsystemResources(services);
-
- //TODO Chek that any services that were installed were removed here
- }
}
View
2 jboss-as-subsystem-example/pom.xml
@@ -36,7 +36,7 @@
<packaging>jar</packaging>
<properties>
- <version.jboss.as>7.1.0.Final</version.jboss.as>
+ <version.jboss.as>7.1.1.Final</version.jboss.as>
<version.junit>4.8.2</version.junit>
<module.name>com.acme.corp.tracker</module.name>
</properties>
View
4 jboss-as-subsystem-example/src/main/java/com/acme/corp/tracker/extension/SubsystemAdd.java
@@ -31,9 +31,7 @@ private SubsystemAdd() {
/** {@inheritDoc} */
@Override
protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
- log.info("Populating the model");
- //Initialize the 'type' child node
- model.get("type").setEmptyObject();
+
}
/** {@inheritDoc} */
View
214 ...s-subsystem-example/src/main/java/com/acme/corp/tracker/extension/SubsystemExtension.java
@@ -1,214 +0,0 @@
-package com.acme.corp.tracker.extension;
-
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-
-import org.jboss.as.controller.Extension;
-import org.jboss.as.controller.ExtensionContext;
-import org.jboss.as.controller.OperationContext;
-import org.jboss.as.controller.OperationFailedException;
-import org.jboss.as.controller.OperationStepHandler;
-import org.jboss.as.controller.PathAddress;
-import org.jboss.as.controller.PathElement;
-import org.jboss.as.controller.SubsystemRegistration;
-import org.jboss.as.controller.descriptions.DescriptionProvider;
-import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
-import org.jboss.as.controller.descriptions.common.CommonDescriptions;
-import org.jboss.as.controller.parsing.ExtensionParsingContext;
-import org.jboss.as.controller.parsing.ParseUtils;
-import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
-import org.jboss.as.controller.registry.AttributeAccess.Storage;
-import org.jboss.as.controller.registry.ManagementResourceRegistration;
-import org.jboss.as.controller.registry.OperationEntry;
-import org.jboss.dmr.ModelNode;
-import org.jboss.dmr.Property;
-import org.jboss.staxmapper.XMLElementReader;
-import org.jboss.staxmapper.XMLElementWriter;
-import org.jboss.staxmapper.XMLExtendedStreamReader;
-import org.jboss.staxmapper.XMLExtendedStreamWriter;
-
-
-/**
- *
- * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
- */
-public class SubsystemExtension implements Extension {
-
- /** The name space used for the {@code subsystem} element */
- public static final String NAMESPACE = "urn:com.acme.corp.tracker:1.0";
-
- /** The name of our subsystem within the model. */
- public static final String SUBSYSTEM_NAME = "tracker";
-
- /** The parser used for parsing our subsystem */
- private final SubsystemParser parser = new SubsystemParser();
-
- @Override
- public void initializeParsers(ExtensionParsingContext context) {
- context.setSubsystemXmlMapping(NAMESPACE, parser);
- }
-
- @Override
- public void initialize(ExtensionContext context) {
- final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME);
- final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(SubsystemProviders.SUBSYSTEM);
- //We always need to add an 'add' operation
- registration.registerOperationHandler(ADD, SubsystemAdd.INSTANCE, SubsystemProviders.SUBSYSTEM_ADD, false);
- //Every resource that is added, normally needs a remove operation
- registration.registerOperationHandler(REMOVE, SubsystemRemove.INSTANCE, SubsystemProviders.SUBSYSTEM_REMOVE, false);
- //We always need to add a 'describe' operation
- registration.registerOperationHandler(DESCRIBE, SubsystemDescribeHandler.INSTANCE, SubsystemDescribeHandler.INSTANCE, false, OperationEntry.EntryType.PRIVATE);
-
- //Add the type child
- ManagementResourceRegistration typeChild = registration.registerSubModel(PathElement.pathElement("type"), SubsystemProviders.TYPE_CHILD);
- typeChild.registerOperationHandler(ModelDescriptionConstants.ADD, TypeAddHandler.INSTANCE, TypeAddHandler.INSTANCE);
- typeChild.registerOperationHandler(ModelDescriptionConstants.REMOVE, TypeRemoveHandler.INSTANCE, TypeRemoveHandler.INSTANCE);
- typeChild.registerReadWriteAttribute("tick", null, TrackerTickHandler.INSTANCE, Storage.CONFIGURATION);
-
- subsystem.registerXMLElementWriter(parser);
- }
-
- private static ModelNode createAddSubsystemOperation() {
- final ModelNode subsystem = new ModelNode();
- subsystem.get(OP).set(ADD);
- subsystem.get(OP_ADDR).add(SUBSYSTEM, SUBSYSTEM_NAME);
- return subsystem;
- }
-
- /**
- * The subsystem parser, which uses stax to read and write to and from xml
- */
- private static class SubsystemParser implements XMLStreamConstants, XMLElementReader<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> {
-
- /** {@inheritDoc} */
- @Override
- public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
- // Require no attributes
- ParseUtils.requireNoAttributes(reader);
-
- //Add the main subsystem 'add' operation
- list.add(createAddSubsystemOperation());
-
- //Read the children
- while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
- if (!reader.getLocalName().equals("deployment-types")) {
- throw ParseUtils.unexpectedElement(reader);
- }
- while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
- if (reader.isStartElement()) {
- readDeploymentType(reader, list);
- }
- }
- }
- }
-
- private void readDeploymentType(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
- if (!reader.getLocalName().equals("deployment-type")) {
- throw ParseUtils.unexpectedElement(reader);
- }
- String suffix = null;
- Long tick = null;
- for (int i = 0 ; i < reader.getAttributeCount() ; i++) {
- String attr = reader.getAttributeLocalName(i);
- if (attr.equals("tick")){
- tick = Long.valueOf(reader.getAttributeValue(i));
- } else if (attr.equals("suffix")){
- suffix = reader.getAttributeValue(i);
- } else {
- throw ParseUtils.unexpectedAttribute(reader, i);
- }
- }
- ParseUtils.requireNoContent(reader);
- if (suffix == null) {
- throw ParseUtils.missingRequiredElement(reader, Collections.singleton("suffix"));
- }
-
- //Add the 'add' operation for each 'type' child
- ModelNode addType = new ModelNode();
- addType.get(OP).set(ModelDescriptionConstants.ADD);
- PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME), PathElement.pathElement("type", suffix));
- addType.get(OP_ADDR).set(addr.toModelNode());
- if (tick != null) {
- addType.get("tick").set(tick);
- }
- list.add(addType);
- }
-
- /** {@inheritDoc} */
- @Override
- public void writeContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException {
-
- //Write out the main subsystem element
- context.startSubsystemElement(SubsystemExtension.NAMESPACE, false);
-
- writer.writeStartElement("deployment-types");
-
- ModelNode node = context.getModelNode();
- ModelNode type = node.get("type");
- for (Property property : type.asPropertyList()) {
-
- //write each child element to xml
- writer.writeStartElement("deployment-type");
- writer.writeAttribute("suffix", property.getName());
- ModelNode entry = property.getValue();
- if (entry.hasDefined("tick")) {
- writer.writeAttribute("tick", entry.get("tick").asString());
- }
- writer.writeEndElement();
- }
-
- //End deployment-types
- writer.writeEndElement();
- //End subsystem
- writer.writeEndElement();
- }
- }
-
-
- /**
- * Recreate the steps to put the subsystem in the same state it was in.
- * This is used in domain mode to query the profile being used, in order to
- * get the steps needed to create the servers
- */
- private static class SubsystemDescribeHandler implements OperationStepHandler, DescriptionProvider {
- static final SubsystemDescribeHandler INSTANCE = new SubsystemDescribeHandler();
-
- public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
- //Add the main operation
- context.getResult().add(createAddSubsystemOperation());
-
- //Add the operations to create each child
-
- ModelNode node = context.readModel(PathAddress.EMPTY_ADDRESS);
- for (Property property : node.get("type").asPropertyList()) {
-
- ModelNode addType = new ModelNode();
- addType.get(OP).set(ModelDescriptionConstants.ADD);
- PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME), PathElement.pathElement("type", property.getName()));
- addType.get(OP_ADDR).set(addr.toModelNode());
- if (property.getValue().hasDefined("tick")) {
- addType.get("tick").set(property.getValue().get("tick").asLong());
- }
- context.getResult().add(addType);
- }
- context.completeStep();
- }
-
- @Override
- public ModelNode getModelDescription(Locale locale) {
- return CommonDescriptions.getSubsystemDescribeOperation(locale);
- }
- }
-
-}
View
103 ...s-subsystem-example/src/main/java/com/acme/corp/tracker/extension/SubsystemProviders.java
@@ -1,103 +0,0 @@
-package com.acme.corp.tracker.extension;
-
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ATTRIBUTES;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CHILDREN;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEFAULT;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HEAD_COMMENT_ALLOWED;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MAX_OCCURS;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MIN_OCCURS;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MODEL_DESCRIPTION;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAMESPACE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_NAME;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REQUIRED;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.TAIL_COMMENT_ALLOWED;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.TYPE;
-
-import java.util.Locale;
-
-import org.jboss.as.controller.descriptions.DescriptionProvider;
-import org.jboss.dmr.ModelNode;
-import org.jboss.dmr.ModelType;
-
-/**
- * Contains the description providers. The description providers are what print out the
- * information when you execute the {@code read-resource-description} operation.
- *
- * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
- */
-class SubsystemProviders {
-
- /**
- * Used to create the description of the subsystem
- */
- public static DescriptionProvider SUBSYSTEM = new DescriptionProvider() {
- public ModelNode getModelDescription(Locale locale) {
- //The locale is passed in so you can internationalize the strings used in the descriptions
-
- final ModelNode subsystem = new ModelNode();
- //Change the description
- subsystem.get(DESCRIPTION).set("This subsystem tracks deployments of a given type");
- subsystem.get(HEAD_COMMENT_ALLOWED).set(true);
- subsystem.get(TAIL_COMMENT_ALLOWED).set(true);
- subsystem.get(NAMESPACE).set(SubsystemExtension.NAMESPACE);
-
- //Add information about the 'type' child
- subsystem.get(CHILDREN, "type", DESCRIPTION).set("Deployment types that should be tracked");
- subsystem.get(CHILDREN, "type", MIN_OCCURS).set(0);
- subsystem.get(CHILDREN, "type", MAX_OCCURS).set(Integer.MAX_VALUE);
- subsystem.get(CHILDREN, "type", MODEL_DESCRIPTION);
-
- return subsystem;
- }
- };
-
- /**
- * Used to create the description of the subsystem add method
- */
- public static DescriptionProvider SUBSYSTEM_ADD = new DescriptionProvider() {
- public ModelNode getModelDescription(Locale locale) {
- //The locale is passed in so you can internationalize the strings used in the descriptions
-
- final ModelNode subsystem = new ModelNode();
- subsystem.get(OPERATION_NAME).set(ADD);
- subsystem.get(DESCRIPTION).set("Adds the tracker subsystem");
-
- return subsystem;
- }
- };
-
- /**
- * Used to create the description of the subsystem remove method
- */
- public static DescriptionProvider SUBSYSTEM_REMOVE = new DescriptionProvider() {
- public ModelNode getModelDescription(Locale locale) {
- //The locale is passed in so you can internationalize the strings used in the descriptions
-
- final ModelNode subsystem = new ModelNode();
- subsystem.get(OPERATION_NAME).set(REMOVE);
- subsystem.get(DESCRIPTION).set("Removes the tracker subsystem");
-
- return subsystem;
- }
- };
-
- /**
- * Used to create the description of the {@code type} child
- */
- public static DescriptionProvider TYPE_CHILD = new DescriptionProvider() {
- @Override
- public ModelNode getModelDescription(Locale locale) {
- ModelNode node = new ModelNode();
- node.get(DESCRIPTION).set("Contains information about a tracked deployment type");
- node.get(ATTRIBUTES, "tick", DESCRIPTION).set("How often in milliseconds to output the information about the tracked deployments");
- node.get(ATTRIBUTES, "tick", TYPE).set(ModelType.LONG);
- node.get(ATTRIBUTES, "tick", REQUIRED).set(true);
- node.get(ATTRIBUTES, "tick", DEFAULT).set(10000);
- return node;
- }
- };
-
-}
View
173 ...-as-subsystem-example/src/main/java/com/acme/corp/tracker/extension/TrackerExtension.java
@@ -0,0 +1,173 @@
+package com.acme.corp.tracker.extension;
+
+import org.jboss.as.controller.Extension;
+import org.jboss.as.controller.ExtensionContext;
+import org.jboss.as.controller.PathAddress;
+import org.jboss.as.controller.PathElement;
+import org.jboss.as.controller.SubsystemRegistration;
+import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
+import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver;
+import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler;
+import org.jboss.as.controller.parsing.ExtensionParsingContext;
+import org.jboss.as.controller.parsing.ParseUtils;
+import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
+import org.jboss.as.controller.registry.ManagementResourceRegistration;
+import org.jboss.as.controller.registry.OperationEntry;
+import org.jboss.dmr.ModelNode;
+import org.jboss.dmr.Property;
+import org.jboss.staxmapper.XMLElementReader;
+import org.jboss.staxmapper.XMLElementWriter;
+import org.jboss.staxmapper.XMLExtendedStreamReader;
+import org.jboss.staxmapper.XMLExtendedStreamWriter;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import java.util.Collections;
+import java.util.List;
+
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
+
+
+/**
+ * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
+ */
+public class TrackerExtension implements Extension {
+
+ /**
+ * The name space used for the {@code subsystem} element
+ */
+ public static final String NAMESPACE = "urn:com.acme.corp.tracker:1.0";
+
+ /**
+ * The name of our subsystem within the model.
+ */
+ public static final String SUBSYSTEM_NAME = "tracker";
+
+ /**
+ * The parser used for parsing our subsystem
+ */
+ private final SubsystemParser parser = new SubsystemParser();
+
+ private static final String RESOURCE_NAME = TrackerExtension.class.getPackage().getName() + ".LocalDescriptions";
+
+ protected static final String TYPE = "type";
+ protected static final String TICK = "tick";
+ protected static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME);
+ protected static final PathElement TYPE_PATH = PathElement.pathElement(TYPE);
+
+ static StandardResourceDescriptionResolver getResourceDescriptionResolver(final String keyPrefix) {
+ String prefix = SUBSYSTEM_NAME + (keyPrefix == null ? "" : "." + keyPrefix);
+ return new StandardResourceDescriptionResolver(prefix, RESOURCE_NAME, TrackerExtension.class.getClassLoader(), true, false);
+ }
+
+ @Override
+ public void initializeParsers(ExtensionParsingContext context) {
+ context.setSubsystemXmlMapping(SUBSYSTEM_NAME, NAMESPACE, parser);
+ }
+
+ @Override
+ public void initialize(ExtensionContext context) {
+ final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, 1, 0);
+ final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(TrackerSubsystemDefinition.INSTANCE);
+
+
+ //Add the type child
+ ManagementResourceRegistration typeChild = registration.registerSubModel(TypeDefinition.INSTANCE);
+ subsystem.registerXMLElementWriter(parser);
+ }
+
+
+ /**
+ * The subsystem parser, which uses stax to read and write to and from xml
+ */
+ private static class SubsystemParser implements XMLStreamConstants, XMLElementReader<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
+ // Require no attributes
+ ParseUtils.requireNoAttributes(reader);
+
+ //Add the main subsystem 'add' operation
+ final ModelNode subsystem = new ModelNode();
+ subsystem.get(OP).set(ADD);
+ subsystem.get(OP_ADDR).set(PathAddress.pathAddress(SUBSYSTEM_PATH).toModelNode());
+ list.add(subsystem);
+
+ //Read the children
+ while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
+ if (!reader.getLocalName().equals("deployment-types")) {
+ throw ParseUtils.unexpectedElement(reader);
+ }
+ while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
+ if (reader.isStartElement()) {
+ readDeploymentType(reader, list);
+ }
+ }
+ }
+ }
+
+ private void readDeploymentType(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
+ if (!reader.getLocalName().equals("deployment-type")) {
+ throw ParseUtils.unexpectedElement(reader);
+ }
+ ModelNode addTypeOperation = new ModelNode();
+ addTypeOperation.get(OP).set(ModelDescriptionConstants.ADD);
+
+ String suffix = null;
+ for (int i = 0; i < reader.getAttributeCount(); i++) {
+ String attr = reader.getAttributeLocalName(i);
+ String value = reader.getAttributeValue(i);
+ if (attr.equals("tick")) {
+ TypeDefinition.TICK.parseAndSetParameter(value, addTypeOperation, reader);
+ } else if (attr.equals("suffix")) {
+ suffix = value;
+ } else {
+ throw ParseUtils.unexpectedAttribute(reader, i);
+ }
+ }
+ ParseUtils.requireNoContent(reader);
+ if (suffix == null) {
+ throw ParseUtils.missingRequiredElement(reader, Collections.singleton("suffix"));
+ }
+
+ //Add the 'add' operation for each 'type' child
+ PathAddress addr = PathAddress.pathAddress(SUBSYSTEM_PATH, PathElement.pathElement(TYPE, suffix));
+ addTypeOperation.get(OP_ADDR).set(addr.toModelNode());
+ list.add(addTypeOperation);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void writeContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException {
+ //Write out the main subsystem element
+ context.startSubsystemElement(TrackerExtension.NAMESPACE, false);
+ writer.writeStartElement("deployment-types");
+ ModelNode node = context.getModelNode();
+ ModelNode type = node.get(TYPE);
+ for (Property property : type.asPropertyList()) {
+
+ //write each child element to xml
+ writer.writeStartElement("deployment-type");
+ writer.writeAttribute("suffix", property.getName());
+ ModelNode entry = property.getValue();
+ TypeDefinition.TICK.marshallAsAttribute(entry, true, writer);
+ writer.writeEndElement();
+ }
+ //End deployment-types
+ writer.writeEndElement();
+ //End subsystem
+ writer.writeEndElement();
+ }
+ }
+
+
+}
View
13 jboss-as-subsystem-example/src/main/java/com/acme/corp/tracker/extension/TrackerService.java
@@ -1,21 +1,20 @@
package com.acme.corp.tracker.extension;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
-
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+
/**
- *
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
*/
-public class TrackerService implements Service<TrackerService>{
+public class TrackerService implements Service<TrackerService> {
private AtomicLong tick = new AtomicLong(10000);
View
36 ...tem-example/src/main/java/com/acme/corp/tracker/extension/TrackerSubsystemDefinition.java
@@ -0,0 +1,36 @@
+package com.acme.corp.tracker.extension;
+
+import org.jboss.as.controller.SimpleResourceDefinition;
+import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler;
+import org.jboss.as.controller.registry.ManagementResourceRegistration;
+import org.jboss.as.controller.registry.OperationEntry;
+
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
+
+/**
+ * @author <a href="tcerar@redhat.com">Tomaz Cerar</a>
+ */
+public class TrackerSubsystemDefinition extends SimpleResourceDefinition {
+
+ public static final TrackerSubsystemDefinition INSTANCE = new TrackerSubsystemDefinition();
+
+ private TrackerSubsystemDefinition() {
+ super(TrackerExtension.SUBSYSTEM_PATH,
+ TrackerExtension.getResourceDescriptionResolver(null),
+ //We always need to add an 'add' operation
+ SubsystemAdd.INSTANCE,
+ //Every resource that is added, normally needs a remove operation
+ SubsystemRemove.INSTANCE);
+ }
+
+ /**
+ * {@inheritDoc}
+ * Registers an add operation handler or a remove operation handler if one was provided to the constructor.
+ */
+ @Override
+ public void registerOperations(ManagementResourceRegistration resourceRegistration) {
+ super.registerOperations(resourceRegistration);
+ //We always need to add a 'describe' operation
+ resourceRegistration.registerOperationHandler(DESCRIBE, GenericSubsystemDescribeHandler.INSTANCE, GenericSubsystemDescribeHandler.INSTANCE, false, OperationEntry.EntryType.PRIVATE);
+ }
+}
View
62 ...s-subsystem-example/src/main/java/com/acme/corp/tracker/extension/TrackerTickHandler.java
@@ -1,5 +1,6 @@
package com.acme.corp.tracker.extension;
+import org.jboss.as.controller.AbstractWriteAttributeHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationContext.Stage;
import org.jboss.as.controller.OperationFailedException;
@@ -9,33 +10,56 @@
import org.jboss.dmr.ModelNode;
/**
- *
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
*/
-class TrackerTickHandler implements OperationStepHandler {
+class TrackerTickHandler extends AbstractWriteAttributeHandler<Void> {
public static final TrackerTickHandler INSTANCE = new TrackerTickHandler();
private TrackerTickHandler() {
}
- @Override
- public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
- //Update the model
- final String suffix = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();
- final long tick = operation.require("value").asLong();
- ModelNode node = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel();
- node.get("tick").set(tick);
+ /**
+ * Hook to allow subclasses to make runtime changes to effect the attribute value change.
+ *
+ * @param context the context of the operation
+ * @param operation the operation
+ * @param attributeName the name of the attribute being modified
+ * @param resolvedValue the new value for the attribute, after {@link ModelNode#resolve()} has been called on it
+ * @param currentValue the existing value for the attribute
+ * @param handbackHolder holder for an arbitrary object to pass to
+ * {@link #revertUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, Object)} if
+ * the operation needs to be rolled back
+ *
+ * @return {@code true} if the server requires restart to effect the attribute
+ * value change; {@code false} if not
+ */
- //Add a step to perform the runtime update
- context.addStep(new OperationStepHandler() {
- @Override
- public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
- TrackerService service = (TrackerService)context.getServiceRegistry(true).getRequiredService(TrackerService.createServiceName(suffix)).getValue();
- service.setTick(tick);
- context.completeStep();
- }
- }, Stage.RUNTIME);
- context.completeStep();
+ protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName,
+ ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> handbackHolder) throws OperationFailedException{
+ if (attributeName.equals(TrackerExtension.TICK)){
+ final String suffix = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();
+ TrackerService service = (TrackerService) context.getServiceRegistry(true).getRequiredService(TrackerService.createServiceName(suffix)).getValue();
+ service.setTick(currentValue.asLong());
+ context.completeStep();
+ }
+
+ return false;
+ }
+/**
+ * Hook to allow subclasses to revert runtime changes made in
+ * {@link #applyUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, HandbackHolder)}.
+ *
+ * @param context the context of the operation
+ * @param operation the operation
+ * @param attributeName the name of the attribute being modified
+ * @param valueToRestore the previous value for the attribute, before this operation was executed
+ * @param valueToRevert the new value for the attribute that should be reverted
+ * @param handback an object, if any, passed in to the {@code handbackHolder} by the {@code applyUpdateToRuntime}
+ * implementation
+ */
+ protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName,
+ ModelNode valueToRestore, ModelNode valueToRevert, Void handback) {
+ // no-op
}
}
View
31 ...orp/tracker/extension/TypeAddHandler.java → .../acme/corp/tracker/extension/TypeAdd.java
@@ -1,5 +1,6 @@
package com.acme.corp.tracker.extension;
+import static com.acme.corp.tracker.extension.TypeDefinition.TICK;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEFAULT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION;
@@ -28,42 +29,26 @@
*
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
*/
-class TypeAddHandler extends AbstractAddStepHandler implements DescriptionProvider {
+class TypeAdd extends AbstractAddStepHandler {
- public static final TypeAddHandler INSTANCE = new TypeAddHandler();
+ public static final TypeAdd INSTANCE = new TypeAdd();
- private TypeAddHandler() {
- }
-
- @Override
- public ModelNode getModelDescription(Locale locale) {
- ModelNode node = new ModelNode();
- node.get(OPERATION_NAME).set(ADD);
- node.get(DESCRIPTION).set("Adds a tracked deployment type");
- node.get(REQUEST_PROPERTIES, "tick", DESCRIPTION).set("How often to output information about a tracked deployment");
- node.get(REQUEST_PROPERTIES, "tick", TYPE).set(ModelType.LONG);
- node.get(REQUEST_PROPERTIES, "tick", REQUIRED).set(false);
- node.get(REQUEST_PROPERTIES, "tick", DEFAULT).set(10000);
- return node;
+ private TypeAdd() {
}
+
@Override
protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
- //The default value is 10000 if it has not been specified
- long tick = 10000;
- //Read the value from the operation
- if (operation.hasDefined("tick")) {
- tick = operation.get("tick").asLong();
- }
- model.get("tick").set(tick);
+ TICK.validateAndSet(operation,model);
}
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model,
ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers)
throws OperationFailedException {
String suffix = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();
- TrackerService service = new TrackerService(suffix, model.get("tick").asLong());
+ long tick = TICK.resolveModelAttribute(context,model).asLong();
+ TrackerService service = new TrackerService(suffix, tick);
ServiceName name = TrackerService.createServiceName(suffix);
ServiceController<TrackerService> controller = context.getServiceTarget()
.addService(name, service)
View
44 jboss-as-subsystem-example/src/main/java/com/acme/corp/tracker/extension/TypeDefinition.java
@@ -0,0 +1,44 @@
+package com.acme.corp.tracker.extension;
+
+import org.jboss.as.controller.SimpleAttributeDefinition;
+import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
+import org.jboss.as.controller.SimpleResourceDefinition;
+import org.jboss.as.controller.operations.validation.ModelTypeValidator;
+import org.jboss.as.controller.registry.AttributeAccess;
+import org.jboss.as.controller.registry.ManagementResourceRegistration;
+import org.jboss.dmr.ModelNode;
+import org.jboss.dmr.ModelType;
+
+import static com.acme.corp.tracker.extension.TrackerExtension.TYPE;
+import static com.acme.corp.tracker.extension.TrackerExtension.TYPE_PATH;
+
+/**
+ * @author <a href="tcerar@redhat.com">Tomaz Cerar</a>
+ */
+public class TypeDefinition extends SimpleResourceDefinition {
+ public static final TypeDefinition INSTANCE = new TypeDefinition();
+
+ protected static final SimpleAttributeDefinition TICK =
+ new SimpleAttributeDefinitionBuilder(TrackerExtension.TICK, ModelType.LONG)
+ .setAllowExpression(true)
+ .setXmlName(TrackerExtension.TICK)
+ .setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
+ .setDefaultValue(new ModelNode(1000))
+ .setAllowNull(false)
+ .build();
+
+
+ private TypeDefinition() {
+ super(TYPE_PATH,
+ TrackerExtension.getResourceDescriptionResolver(TYPE),
+ //We always need to add an 'add' operation
+ TypeAdd.INSTANCE,
+ //Every resource that is added, normally needs a remove operation
+ TypeRemove.INSTANCE);
+ }
+
+ @Override
+ public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
+ resourceRegistration.registerReadWriteAttribute(TICK, null, TrackerTickHandler.INSTANCE);
+ }
+}
View
14 .../tracker/extension/TypeRemoveHandler.java → ...me/corp/tracker/extension/TypeRemove.java
@@ -19,19 +19,11 @@
*
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
*/
-class TypeRemoveHandler extends AbstractRemoveStepHandler implements DescriptionProvider {
+class TypeRemove extends AbstractRemoveStepHandler{
- public static final TypeRemoveHandler INSTANCE = new TypeRemoveHandler();
+ public static final TypeRemove INSTANCE = new TypeRemove();
- private TypeRemoveHandler() {
- }
-
- @Override
- public ModelNode getModelDescription(Locale locale) {
- ModelNode node = new ModelNode();
- node.get(OPERATION_NAME).set(REMOVE);
- node.get(DESCRIPTION).set("Removes a tracked deployment type");
- return node;
+ private TypeRemove() {
}
@Override
View
2 ...-subsystem-example/src/main/resources/META-INF/services/org.jboss.as.controller.Extension
@@ -1 +1 @@
-com.acme.corp.tracker.extension.SubsystemExtension
+com.acme.corp.tracker.extension.TrackerExtension
View
7 ...m-example/src/main/resources/com/acme/corp/tracker/extension/LocalDescriptions.properties
@@ -0,0 +1,7 @@
+tracker=Acme Tracker subsystem
+tracker.add=Operation Adds tracker subsystem
+tracker.remove=Operation Removes tracker subsystem
+tracker.type=Deployment type
+tracker.type.add=Operation Adds tracker subsystem
+tracker.type.remove=Operation Removes tracker subsystem
+tracker.type.tick=Tick attribute
View
20 jboss-as-subsystem-example/src/main/resources/schema/jboss-as-mysubsystem_1_0.xsd
@@ -0,0 +1,20 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="urn:com.acme.corp.tracker:1.0"
+ xmlns="urn:com.acme.corp.tracker:1.0"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified"
+ version="1.0">
+
+ <!-- The subsystem root element -->
+ <xs:element name="subsystem" type="subsystemType"/>
+
+ <xs:complexType name="subsystemType">
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+ <xs:element name="deploymemt-type" type="deployment-typeType"/>
+ </xs:choice>
+ </xs:complexType>
+ <xs:complexType name="deployment-typeType">
+ <xs:attribute name="suffix" use="required"/>
+ <xs:attribute name="tick" type="xs:long" use="optional" default="10000"/>
+ </xs:complexType>
+</xs:schema>
View
24 jboss-as-subsystem-example/src/main/resources/schema/mysubsystem.xsd
@@ -1,24 +0,0 @@
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
- targetNamespace="urn:com.acme.corp.tracker:1.0"
- xmlns="urn:com.acme.corp.tracker:1.0"
- elementFormDefault="qualified"
- attributeFormDefault="unqualified"
- version="1.0">
-
- <!-- The subsystem root element -->
- <xs:element name="subsystem" type="subsystemType"/>
- <xs:complexType name="subsystemType">
- <xs:all>
- <xs:element name="deployment-types" type="deploymemt-typesType">
- </xs:all>
- </xs:complexType>
- <xs:complexType name="subsystemType">
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="deploymemt-type" type="deployment-typeType"/>
- </xs:choice>
- </xs:complexType>
- <xs:complexType name="deploymemt-typeType">
- <xs:attribute name="suffix" use="required"/>
- <xs:attribute name="tick" type="xs:long" use="optional" default="10000"/>
- </xs:complexType>
-</xs:schema>
View
233 ...ystem-example/src/test/java/com/acme/corp/tracker/extension/SubsystemParsingTestCase.java
@@ -1,241 +1,22 @@
package com.acme.corp.tracker.extension;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION;
-
-import java.util.List;
-
-import junit.framework.Assert;
-
-import org.jboss.as.controller.PathAddress;
-import org.jboss.as.controller.PathElement;
-import org.jboss.as.subsystem.test.AbstractSubsystemTest;
-import org.jboss.as.subsystem.test.KernelServices;
-import org.jboss.dmr.ModelNode;
-import org.junit.Test;
+import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
+import java.io.IOException;
/**
- *
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
*/
-public class SubsystemParsingTestCase extends AbstractSubsystemTest {
+public class SubsystemParsingTestCase extends AbstractSubsystemBaseTest {
public SubsystemParsingTestCase() {
- super(SubsystemExtension.SUBSYSTEM_NAME, new SubsystemExtension());
- }
-
- /**
- * Tests that the xml is parsed into the correct operations
- */
- @Test
- public void testParseSubsystem() throws Exception {
- //Parse the subsystem xml into operations
- String subsystemXml =
- "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
- " <deployment-types>" +
- " <deployment-type suffix=\"tst\" tick=\"12345\"/>" +
- " </deployment-types>" +
- "</subsystem>";
- List<ModelNode> operations = super.parse(subsystemXml);
-
- ///Check that we have the expected number of operations
- Assert.assertEquals(2, operations.size());
-
- //Check that each operation has the correct content
- //The add subsystem operation will happen first
- ModelNode addSubsystem = operations.get(0);
- Assert.assertEquals(ADD, addSubsystem.get(OP).asString());
- PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
- Assert.assertEquals(1, addr.size());
- PathElement element = addr.getElement(0);
- Assert.assertEquals(SUBSYSTEM, element.getKey());
- Assert.assertEquals(SubsystemExtension.SUBSYSTEM_NAME, element.getValue());
-
- //Then we will get the add type operation
- ModelNode addType = operations.get(1);
- Assert.assertEquals(ADD, addType.get(OP).asString());
- Assert.assertEquals(12345, addType.get("tick").asLong());
- addr = PathAddress.pathAddress(addType.get(OP_ADDR));
- Assert.assertEquals(2, addr.size());
- element = addr.getElement(0);
- Assert.assertEquals(SUBSYSTEM, element.getKey());
- Assert.assertEquals(SubsystemExtension.SUBSYSTEM_NAME, element.getValue());
- element = addr.getElement(1);
- Assert.assertEquals("type", element.getKey());
- Assert.assertEquals("tst", element.getValue());
- }
-
- /**
- * Test that the model created from the xml looks as expected
- */
- @Test
- public void testInstallIntoController() throws Exception {
- //Parse the subsystem xml and install into the controller
- String subsystemXml =
- "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
- " <deployment-types>" +
- " <deployment-type suffix=\"tst\" tick=\"12345\"/>" +
- " </deployment-types>" +
- "</subsystem>";
- KernelServices services = super.installInController(subsystemXml);
-
- //Read the whole model and make sure it looks as expected
- ModelNode model = services.readWholeModel();
- //Useful for debugging :-)
- //System.out.println(model);
- Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(SubsystemExtension.SUBSYSTEM_NAME));
- Assert.assertTrue(model.get(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME).hasDefined("type"));
- Assert.assertTrue(model.get(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME, "type").hasDefined("tst"));
- Assert.assertTrue(model.get(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME, "type", "tst").hasDefined("tick"));
- Assert.assertEquals(12345, model.get(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME, "type", "tst", "tick").asLong());
- }
-
- /**
- * Starts a controller with a given subsystem xml and then checks that a second
- * controller started with the xml marshalled from the first one results in the same model
- */
- @Test
- public void testParseAndMarshalModel() throws Exception {
- //Parse the subsystem xml and install into the first controller
- String subsystemXml =
- "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
- " <deployment-types>" +
- " <deployment-type suffix=\"tst\" tick=\"12345\"/>" +
- " </deployment-types>" +
- "</subsystem>";
- KernelServices servicesA = super.installInController(subsystemXml);
- //Get the model and the persisted xml from the first controller
- ModelNode modelA = servicesA.readWholeModel();
- String marshalled = servicesA.getPersistedSubsystemXml();
-
- //Install the persisted xml from the first controller into a second controller
- KernelServices servicesB = super.installInController(marshalled);
- ModelNode modelB = servicesB.readWholeModel();
-
- //Make sure the models from the two controllers are identical
- super.compare(modelA, modelB);
- }
-
- /**
- * Starts a controller with the given subsystem xml and then checks that a second
- * controller started with the operations from its describe action results in the same model
- */
- @Test
- public void testDescribeHandler() throws Exception {
- //Parse the subsystem xml and install into the first controller
- String subsystemXml =
- "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
- "</subsystem>";
- KernelServices servicesA = super.installInController(subsystemXml);
- //Get the model and the describe operations from the first controller
- ModelNode modelA = servicesA.readWholeModel();
- ModelNode describeOp = new ModelNode();
- describeOp.get(OP).set(DESCRIBE);
- describeOp.get(OP_ADDR).set(
- PathAddress.pathAddress(
- PathElement.pathElement(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME)).toModelNode());
- List<ModelNode> operations = super.checkResultAndGetContents(servicesA.executeOperation(describeOp)).asList();
-
- //Install the describe options from the first controller into a second controller
- KernelServices servicesB = super.installInController(operations);
- ModelNode modelB = servicesB.readWholeModel();
-
- //Make sure the models from the two controllers are identical
- super.compare(modelA, modelB);
-
- }
-
- /**
- * Tests that the subsystem can be removed
- */
- @Test
- public void testSubsystemRemoval() throws Exception {
- //Parse the subsystem xml and install into the first controller
- String subsystemXml =
- "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
- " <deployment-types>" +
- " <deployment-type suffix=\"tst\" tick=\"12345\"/>" +
- " </deployment-types>" +
- "</subsystem>";
- KernelServices services = super.installInController(subsystemXml);
-
- //Sanity check to test the service for 'tst' was there
- services.getContainer().getRequiredService(TrackerService.createServiceName("tst"));
-
- //Checks that the subsystem was removed from the model
- super.assertRemoveSubsystemResources(services);
-
- //Check that any services that were installed were removed here
- try {
- services.getContainer().getRequiredService(TrackerService.createServiceName("tst"));
- Assert.fail("Should have removed services");
- } catch (Exception expected) {
- }
+ super(TrackerExtension.SUBSYSTEM_NAME, new TrackerExtension());
}
- @Test
- public void testExecuteOperations() throws Exception {
- String subsystemXml =
- "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
- " <deployment-types>" +
- " <deployment-type suffix=\"tst\" tick=\"12345\"/>" +
- " </deployment-types>" +
- "</subsystem>";
- KernelServices services = super.installInController(subsystemXml);
-
- //Add another type
- PathAddress fooTypeAddr = PathAddress.pathAddress(
- PathElement.pathElement(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME),
- PathElement.pathElement("type", "foo"));
- ModelNode addOp = new ModelNode();
- addOp.get(OP).set(ADD);
- addOp.get(OP_ADDR).set(fooTypeAddr.toModelNode());
- addOp.get("tick").set(1000);
- ModelNode result = services.executeOperation(addOp);
- Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
-
-
- ModelNode model = services.readWholeModel();
- Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(SubsystemExtension.SUBSYSTEM_NAME));
- Assert.assertTrue(model.get(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME).hasDefined("type"));
- Assert.assertTrue(model.get(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME, "type").hasDefined("tst"));
- Assert.assertTrue(model.get(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME, "type", "tst").hasDefined("tick"));
- Assert.assertEquals(12345, model.get(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME, "type", "tst", "tick").asLong());
-
- Assert.assertTrue(model.get(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME, "type").hasDefined("foo"));
- Assert.assertTrue(model.get(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME, "type", "foo").hasDefined("tick"));
- Assert.assertEquals(1000, model.get(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME, "type", "foo", "tick").asLong());
-
- //Call write-attribute
- ModelNode writeOp = new ModelNode();
- writeOp.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
- writeOp.get(OP_ADDR).set(fooTypeAddr.toModelNode());
- writeOp.get(NAME).set("tick");
- writeOp.get(VALUE).set(3456);
- result = services.executeOperation(writeOp);
- Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
-
- //Check that write attribute took effect, this time by calling read-attribute instead of reading the whole model
- ModelNode readOp = new ModelNode();
- readOp.get(OP).set(READ_ATTRIBUTE_OPERATION);
- readOp.get(OP_ADDR).set(fooTypeAddr.toModelNode());
- readOp.get(NAME).set("tick");
- result = services.executeOperation(readOp);
- Assert.assertEquals(3456, checkResultAndGetContents(result).asLong());
-
- TrackerService service = (TrackerService)services.getContainer().getService(TrackerService.createServiceName("foo")).getValue();
- Assert.assertEquals(3456, service.getTick());
+ @Override
+ protected String getSubsystemXml() throws IOException {
+ return readResource("subsystem.xml");
}
}
View
5 jboss-as-subsystem-example/src/test/resources/com/acme/corp/tracker/extension/subsystem.xml
@@ -0,0 +1,5 @@
+<subsystem xmlns="urn:com.acme.corp.tracker:1.0">
+ <deployment-types>
+ <deployment-type suffix="tst" tick="12345"/>
+ </deployment-types>
+</subsystem>

0 comments on commit 0361b92

Please sign in to comment.
Something went wrong with that request. Please try again.