Presentation by Tomaz Cerar (Red Hat), delivered at the London JBoss User Group event on the 12th of February 2014.
Watch the video here: http://www.youtube.com/watch?v=eu9K5NLUKBI
Join London JBUG: http://www.c2b2.co.uk/jbug
11. Domain model definition
• Attributes
• Resources
• Resource tree
– PathElement
– Single target (key=value)
– Multi target (key=*)
• Resolvers & multi language support
12. Operation handlers
• Defines operations on resources
• Execution stage
– MODEL
– RUNTIME
– VERIFY
– DOMAIN
– DONE
• Can be chained
13. Resource handlers
• Every resource needs add & remove
• In MODEL phase
– validate and set model
• In RUNTIME phase
– Add services
– Add deployment processors
14. Deployment manager
• Deployment repository
• Defines deployment phases
• Provides deployment processor
infrastructure
• Can be used via
– Domain management
– Deployment scanner
15. Deployment processor
• Hooks into deployment lifecycle
• Can modify deployment behavior
• Can define new deployment type
16. Extension point
•
•
•
•
•
Loaded via Service Loader
Can define many subsystems
Packaged as JBoss Module
Referenced in configuration
Can provide any new functionality
20. Extension class
public class SDDExtension implements Extension {
@Override
public void initializeParsers(ExtensionParsingContext context) {
}
@Override
public void initialize(ExtensionContext context) {
}
}
21. Service Loader entry
• Point it to implementation class
– org.wildfly.extension.sdd.SDDExtension
22. Define root model
public class SDDRootResource extends PersistentResourceDefinition {
static final SDDRootResource INSTANCE = new SDDRootResource();
private SDDRootResource() {
super(SDDExtension.SUBSYSTEM_PATH,
SDDExtension.getResolver(),
new SDDSubsystemAdd(),
ReloadRequiredRemoveStepHandler.INSTANCE);
}
@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
super.registerOperations(resourceRegistration);
resourceRegistration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION,
GenericSubsystemDescribeHandler.INSTANCE, false);
}
}
24. Define namespace
enum Namespace {
// must be first
UNKNOWN(null),
SDD_1_0("urn:wildfly:domain:sdd:1.0");
/**
* The current namespace version.
*/
public static final Namespace CURRENT = SDD_1_0;
private final String name;
}
Namespace(final String name) {
this.name = name;
}
28. Making it all work
@Override
public void initializeParsers(ExtensionParsingContext context) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.SDD_1_0.getUriString(),
SDDSubsystemParser.INSTANCE);
}
@Override
public void initialize(ExtensionContext context) {
final SubsystemRegistration subsystem =
context.registerSubsystem(SUBSYSTEM_NAME, 1, 0, 0);
final ManagementResourceRegistration registration =
subsystem.registerSubsystemModel(SDDRootResource.INSTANCE);
}
subsystem.registerXMLElementWriter(SDDSubsystemParser.INSTANCE);
32. How to test it?
• Test harness enables you to test
– xml parser
– model consistency
– MSC services
– Compatibility (transformers)
– Localization resources
–…
33. public class SDDSubsystemTestCase extends
AbstractSubsystemBaseTest {
public SDDSubsystemTestCase() {
super(SDDExtension.SUBSYSTEM_NAME, new SDDExtension());
}
}
@Override
protected String getSubsystemXml() throws IOException {
return readResource("sdd-1.0.xml");
}
36. Silly deployment detector
• Idea come from forums
• Should be able to detect
– Redundant JARs
– Blacklisted jars
– Bundling provided classes/packages
– Common xml misconfigurations
–…
37. Black listed jar detector
• You configure blacklisted jar names
• Subsystem warns you if they are found
38. What we need
• Domain model
• XML parser to handle new model
• Deployment processor
39. Model definition
class JarBlackListResourceDefinition extends SimpleResourceDefinition {
static final JarBlackListResourceDefinition INSTANCE = new JarBlackListResourceDefinition();
private static final StringListAttributeDefinition JAR_NAMES =
new StringListAttributeDefinition.Builder("jar-names")
.setAllowNull(false)
.setXmlName("jars")
.build();
private JarBlackListResourceDefinition() {
super(SDDExtension.JAR_BLACKLIST_PATH,
SDDExtension.getResolver(),
new JarBlackListAdd(),
ReloadRequiredRemoveStepHandler.INSTANCE);
}
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
resourceRegistration.registerReadWriteAttribute(JAR_NAMES, null, new
ReloadRequiredWriteAttributeHandler(JAR_NAMES));
}