Your SlideShare is downloading. ×
0
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Extending WildFly
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Extending WildFly

1,891

Published on

Presentation by Tomaz Cerar (Red Hat), delivered at the London JBoss User Group event on the 12th of February 2014. …

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

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,891
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
27
Comments
0
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Extending WildFly Tomaž Cerar, Red Hat
  • 2. Agenda • • • • • What are extensions WildFly core Write simple extension Silly deployment detector Demo
  • 3. What are extensions? • Entry point for extending WildFly • Can provide – new deployment types – new model – services – resources
  • 4. WILDFLY CORE
  • 5. WildFly core • Really small (< 15 mb) • Consists of – JBoss Modules – Modular Service Controller (MSC) – Domain management (CLI, rest) – Deployment manager – Logging
  • 6. JBoss Modules • Modular class loader • Isolated class loader • Can be a set of many resources (jars)
  • 7. Domain management • Manages configuration • Backbone for all extensions • Accessible via – Extensions – CLI – Admin console – DMR clients –…
  • 8. MSC • • • • Truly concurrent service container Handles service dependencies Handles lifecycle “real” functionality should be in services
  • 9. DMR • • • • Detyped Model Representation JSON like Internal format for all operations Internal model (ModelNode)
  • 10. Domain model definition • Attributes • Resources • Resource tree – PathElement – Single target (key=value) – Multi target (key=*) • Resolvers & multi language support
  • 11. Operation handlers • Defines operations on resources • Execution stage – MODEL – RUNTIME – VERIFY – DOMAIN – DONE • Can be chained
  • 12. Resource handlers • Every resource needs add & remove • In MODEL phase – validate and set model • In RUNTIME phase – Add services – Add deployment processors
  • 13. Deployment manager • Deployment repository • Defines deployment phases • Provides deployment processor infrastructure • Can be used via – Domain management – Deployment scanner
  • 14. Deployment processor • Hooks into deployment lifecycle • Can modify deployment behavior • Can define new deployment type
  • 15. Extension point • • • • • Loaded via Service Loader Can define many subsystems Packaged as JBoss Module Referenced in configuration Can provide any new functionality
  • 16. Extension loading standalone.xml <extension module="org.wildfly.extension.sdd"/> ServiceLoader org.jboss.as.controller.Extension org.wildfly.extension.sdd.SDDExtension
  • 17. WRITE SIMPLE EXTENSION
  • 18. Building blocks • • • • • Define Extension point Define Root Model Define Add handler Define XML parser Define XML marshaller
  • 19. Extension class public class SDDExtension implements Extension { @Override public void initializeParsers(ExtensionParsingContext context) { } @Override public void initialize(ExtensionContext context) { } }
  • 20. Service Loader entry • Point it to implementation class – org.wildfly.extension.sdd.SDDExtension
  • 21. 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); } }
  • 22. Define root add handler public class SDDSubsystemAdd extends AbstractBoottimeAddStepHandler { { @Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException } model.setEmptyObject();
  • 23. 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; }
  • 24. Define XML model <subsystem xmlns="urn:wildfly:domain:sdd:1.0"/>
  • 25. Define parser class SDDSubsystemParser implements XMLStreamConstants, XMLElementReader<List<ModelNode>> { static final PersistentResourceXMLDescription xmlDescription = builder(SDDRootResource.INSTANCE).build(); @Override public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException { xmlDescription.parse(reader, PathAddress.EMPTY_ADDRESS, list); } }
  • 26. Define marshaller public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException { } context.startSubsystemElement(Namespace.CURRENT.getUriString(), false); writer.writeEndElement();
  • 27. 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);
  • 28. Module definition <module xmlns="urn:jboss:module:1.1" name="org.wildfly.extension.sdd"> <resources> <resource-root path="wildfly-sdd-1.0.0.Alpha1-SNAPSHOT.jar"/> </resources> <dependencies> <module name="javax.annotation.api"/> <module name="javax.api"/> <module name="org.jboss.jandex"/> <module name="org.jboss.staxmapper"/> <module name="org.jboss.as.controller"/> <module name="org.jboss.as.server"/> <module name="org.jboss.modules"/> <module name="org.jboss.msc"/> <module name="org.jboss.vfs"/> <module name="org.jboss.logging"/> </dependencies> </module>
  • 29. Module layout
  • 30. What does it do? Nothing!
  • 31. How to test it? • Test harness enables you to test – xml parser – model consistency – MSC services – Compatibility (transformers) – Localization resources –…
  • 32. 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"); }
  • 33. SILLY DEPLOYMENT DETECTOR
  • 34. Let’s have subsystem that will detect common problems in deployments.
  • 35. Silly deployment detector • Idea come from forums • Should be able to detect – Redundant JARs – Blacklisted jars – Bundling provided classes/packages – Common xml misconfigurations –…
  • 36. Black listed jar detector • You configure blacklisted jar names • Subsystem warns you if they are found
  • 37. What we need • Domain model • XML parser to handle new model • Deployment processor
  • 38. 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)); }
  • 39. XML <subsystem xmlns="urn:wildfly:domain:sdd:1.0"> <blacklist jars="mail-*.jar,activation*.jar,javassist-*.jar,jgroups-*.jar,jboss-logging-*.jar"/> </subsystem>
  • 40. Deployment processor • Needs to check all jars in deployment • Compare them with blacklist
  • 41. Demo
  • 42. • https://github.com/ctomc/wildfly-sdd • https://github.com/wildfly/wildfly • http://www.wildfly.org/
  • 43. Questions?

×