org.jboss.as.controller.Extension Java Examples

The following examples show how to use org.jboss.as.controller.Extension. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceActivatorDeploymentUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void createServiceActivatorListenerArchiveForModule(File destination, String targetName, Class listenerClass) throws IOException {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class);
    archive.addClass(JMXNotificationsService.class);
    archive.addClass(listenerClass);
    archive.addClass(JMXControlledStateNotificationListenerExtension.class);
    archive.addClass(EmptySubsystemParser.class);
    archive.addAsServiceProvider(Extension.class, JMXControlledStateNotificationListenerExtension.class);
    StringBuilder sb = new StringBuilder();
    sb.append(ServiceActivatorDeployment.LISTENER_CLASS_NAME);
    sb.append('=');
    sb.append(listenerClass.getName());
    sb.append("\n");
    sb.append(ServiceActivatorDeployment.LISTENER_OBJECT_NAME);
    sb.append('=');
    sb.append(targetName);
    sb.append("\n");
    sb.append("keep.after.stop=true\n");
    archive.addAsResource(new StringAsset(sb.toString()), JMXNotificationsService.PROPERTIES_RESOURCE);
    archive.as(ZipExporter.class).exportTo(destination);
}
 
Example #2
Source File: SubsystemTestDelegate.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Output the model to xml
 *
 * @param model the model to marshall
 * @return the xml
 */
String outputModel(ModelNode model) throws Exception {

    StringConfigurationPersister persister = new StringConfigurationPersister(Collections.emptyList(), testParser, true);

    // Use ProcessType.HOST_CONTROLLER for this ExtensionRegistry so we don't need to provide
    // a PathManager via the ExtensionContext. All we need the Extension to do here is register the xml writers
    ExtensionRegistry outputExtensionRegistry = new ExtensionRegistry(ProcessType.HOST_CONTROLLER, new RunningModeControl(RunningMode.NORMAL), null, null, null, RuntimeHostControllerInfoAccessor.SERVER);
    outputExtensionRegistry.setWriterRegistry(persister);


    Extension extension = mainExtension.getClass().newInstance();
    extension.initialize(outputExtensionRegistry.getExtensionContext("Test", MOCK_RESOURCE_REG, ExtensionRegistryType.SLAVE));

    ConfigurationPersister.PersistenceResource resource = persister.store(model, Collections.emptySet());
    resource.commit();
    return persister.getMarshalled();
}
 
Example #3
Source File: DeferredExtensionContext.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private XMLStreamException loadModule(final String moduleName, final XMLMapper xmlMapper) throws XMLStreamException {
    // Register element handlers for this extension
    try {
        final Module module = moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName));
        boolean initialized = false;
        for (final Extension extension : module.loadService(Extension.class)) {
            ClassLoader oldTccl = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(extension.getClass());
            try {
                extensionRegistry.initializeParsers(extension, moduleName, xmlMapper);
            } finally {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
            }
            if (!initialized) {
                initialized = true;
            }
        }
        if (!initialized) {
            throw ControllerLogger.ROOT_LOGGER.notFound("META-INF/services/", Extension.class.getName(), module.getName());
        }
        return null;
    } catch (final ModuleLoadException e) {
        throw ControllerLogger.ROOT_LOGGER.failedToLoadModule(e);
    }
}
 
Example #4
Source File: CustomVaultInModuleTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void createTestModule() throws Exception {
    File moduleXml = new File(CustomSecurityVault.class.getResource(CustomVaultInModuleTestCase.class.getSimpleName() + "-module.xml").toURI());
    testModule = new TestModule(MODULE_NAME, moduleXml);

    JavaArchive archive = testModule.addResource("test-custom-vault-in-module.jar")
            .addClass(CustomSecurityVault.class)
            .addClass(TestVaultExtension.class)
            .addClass(TestVaultParser.class)
            .addClass(TestVaultRemoveHandler.class)
            .addClass(TestVaultResolveExpressionHandler.class)
            .addClass(TestVaultSubsystemResourceDescription.class);

    ArchivePath path = ArchivePaths.create("/");
    path = ArchivePaths.create(path, "services");
    path = ArchivePaths.create(path, Extension.class.getName());
    archive.addAsManifestResource(CustomSecurityVault.class.getPackage(), Extension.class.getName(), path);
    testModule.create(true);
}
 
Example #5
Source File: DuplicateExtCommandTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void createTestModule() throws Exception {
    final File moduleXml = new File(DuplicateExtCommandTestCase.class.getResource(DuplicateExtCommandTestCase.class.getSimpleName() + "-module.xml").toURI());
    testModule = new TestModule(MODULE_NAME, moduleXml);

    final JavaArchive archive = testModule.addResource("test-cli-duplicate-commands-module.jar")
            .addClass(DuplicateExtCommandHandler.class)
            .addClass(DuplicateExtCommandHandlerProvider.class)
            .addClass(DuplicateExtCommandsExtension.class)
            .addClass(CliExtCommandsParser.class)
            .addClass(DuplicateExtCommand.class)
            .addClass(DuplicateExtCommandSubsystemResourceDescription.class);

    ArchivePath services = ArchivePaths.create("/");
    services = ArchivePaths.create(services, "services");

    final ArchivePath extService = ArchivePaths.create(services, Extension.class.getName());
    archive.addAsManifestResource(getResource(DuplicateExtCommandsExtension.class), extService);

    final ArchivePath cliCmdService = ArchivePaths.create(services, CommandHandlerProvider.class.getName());
    archive.addAsManifestResource(getResource(DuplicateExtCommandHandlerProvider.class), cliCmdService);

    final ArchivePath cliAeshCmdService = ArchivePaths.create(services, Command.class.getName());
    archive.addAsManifestResource(getResource(DuplicateExtCommand.class), cliAeshCmdService);
    testModule.create(true);
}
 
Example #6
Source File: ExtensionUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void createExtensionModule(File extensionModuleRoot, Class<? extends Extension> extension, Package... additionalPackages) throws IOException {
    deleteRecursively(extensionModuleRoot.toPath());

    if (extensionModuleRoot.exists() && !extensionModuleRoot.isDirectory()) {
        throw new IllegalArgumentException(extensionModuleRoot + " already exists and is not a directory");
    }
    File file = new File(extensionModuleRoot, "main");
    if (!file.mkdirs() && !file.exists()) {
        throw new IllegalArgumentException("Could not create " + file);
    }
    final InputStream is = createResourceRoot(extension, additionalPackages).exportAsInputStream();
    try {
        copyFile(new File(file, JAR_NAME), is);
    } finally {
        IoUtils.safeClose(is);
    }

    URL url = extension.getResource("module.xml");
    if (url == null) {
        throw new IllegalStateException("Could not find module.xml");
    }
    copyFile(new File(file, "module.xml"), url.openStream());
}
 
Example #7
Source File: ExtensionUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static StreamExporter createResourceRoot(Class<? extends Extension> extension, Package... additionalPackages) throws IOException {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class);
    storePackage(extension.getPackage(), extension.getClassLoader(), archive);
    if (additionalPackages != null) {
        for (Package pkg : additionalPackages) {
            storePackage(pkg, extension.getClassLoader(), archive);
        }
    }

    archive.addAsServiceProvider(Extension.class, extension);
    return archive.as(ZipExporter.class);
}
 
Example #8
Source File: TestModelControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static TestModelControllerService create(final Extension mainExtension, final ControllerInitializer controllerInitializer,
                                         final AdditionalInitialization additionalInit, final ExtensionRegistry extensionRegistry,
                                         final StringConfigurationPersister persister, final ModelTestOperationValidatorFilter validateOpsFilter,
                                         final boolean registerTransformers, CapabilityRegistry capabilityRegistry) {
    return new TestModelControllerService(mainExtension, controllerInitializer, additionalInit,
            new RunningModeControl(additionalInit.getRunningMode()), extensionRegistry, persister, validateOpsFilter,
            registerTransformers,capabilityRegistry);
}
 
Example #9
Source File: TestModelControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected TestModelControllerService(final Extension mainExtension, final ControllerInitializer controllerInitializer,
                                     final AdditionalInitialization additionalInit, final RunningModeControl runningModeControl,
                                     final ExtensionRegistry extensionRegistry, final StringConfigurationPersister persister,
                                     final ModelTestOperationValidatorFilter validateOpsFilter, final boolean registerTransformers, CapabilityRegistry capabilityRegistry) {
    super(additionalInit.getProcessType(), runningModeControl, extensionRegistry.getTransformerRegistry(), persister, validateOpsFilter,
            new SimpleResourceDefinition(null, NonResolvingResourceDescriptionResolver.INSTANCE) , new ControlledProcessState(true),capabilityRegistry);
    this.mainExtension = mainExtension;
    this.additionalInit = additionalInit;
    this.controllerInitializer = controllerInitializer;
    this.extensionRegistry = extensionRegistry;
    this.runningModeControl = runningModeControl;
    this.registerTransformers = registerTransformers;

}
 
Example #10
Source File: TestModelControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected TestModelControllerService(final Extension mainExtension, final ControllerInitializer controllerInitializer,
                                     final AdditionalInitialization additionalInit, final RunningModeControl runningModeControl,
                                     final ExtensionRegistry extensionRegistry, final StringConfigurationPersister persister,
                                     final ModelTestOperationValidatorFilter validateOpsFilter, final boolean registerTransformers) {
    super(additionalInit.getProcessType(), runningModeControl, extensionRegistry.getTransformerRegistry(), persister, validateOpsFilter,
            new SimpleResourceDefinition(null, NonResolvingResourceDescriptionResolver.INSTANCE) , new ControlledProcessState(true), Controller90x.INSTANCE);
    this.mainExtension = mainExtension;
    this.additionalInit = additionalInit;
    this.controllerInitializer = controllerInitializer;
    this.extensionRegistry = extensionRegistry;
    this.runningModeControl = runningModeControl;
    this.registerTransformers = registerTransformers;

}
 
Example #11
Source File: ChildFirstClassLoaderKernelServicesFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static KernelServices create(String mainSubsystemName, String extensionClassName, AdditionalInitialization additionalInit, ModelTestOperationValidatorFilter validateOpsFilter,
        List<ModelNode> bootOperations, ModelVersion legacyModelVersion, boolean persistXml) throws Exception {
    Extension extension = (Extension) Class.forName(extensionClassName).newInstance();

    ExtensionRegistry extensionRegistry = new ExtensionRegistry(ProcessType.DOMAIN_SERVER, new RunningModeControl(RunningMode.ADMIN_ONLY));
    ModelTestParser testParser = new TestParser(mainSubsystemName, extensionRegistry);

    //TODO this should get serialized properly
    if (additionalInit == null) {
        additionalInit = AdditionalInitialization.MANAGEMENT;
    }
    return AbstractKernelServicesImpl.create(null, mainSubsystemName, additionalInit, validateOpsFilter,
            extensionRegistry, bootOperations, testParser, extension, legacyModelVersion, false, persistXml);
}
 
Example #12
Source File: RemotingSubsystemTestUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static void registerIOExtension(ExtensionRegistry extensionRegistry, ManagementResourceRegistration rootRegistration) {
    ManagementResourceRegistration extReg = rootRegistration.registerSubModel(new SimpleResourceDefinition(PathElement.pathElement(EXTENSION, "org.wildfly.extension.io"),
            NonResolvingResourceDescriptionResolver.INSTANCE, new ModelOnlyAddStepHandler(), ModelOnlyRemoveStepHandler.INSTANCE));
    extReg.registerReadOnlyAttribute(new SimpleAttributeDefinitionBuilder("module", ModelType.STRING).build(), null);

    Extension ioe = new IOExtension();
    ioe.initialize(extensionRegistry.getExtensionContext("org.wildfly.extension.io", rootRegistration, ExtensionRegistryType.MASTER));

}
 
Example #13
Source File: ApplyExtensionsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void initializeExtension(String module, ManagementResourceRegistration rootRegistration) throws OperationFailedException {
    try {
        for (final Extension extension : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(module), Extension.class)) {
            ClassLoader oldTccl = SecurityActions.setThreadContextClassLoader(extension.getClass());
            try {
                extension.initializeParsers(extensionRegistry.getExtensionParsingContext(module, null));
                extension.initialize(extensionRegistry.getExtensionContext(module, rootRegistration, ExtensionRegistryType.SLAVE));
            } finally {
                SecurityActions.setThreadContextClassLoader(oldTccl);
            }
        }
    } catch (ModuleLoadException e) {
        throw DomainControllerLogger.ROOT_LOGGER.failedToLoadModule(e, module);
    }
}
 
Example #14
Source File: ExtensionSetup.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static StreamExporter createResourceRoot(Class<? extends Extension> extension, Package... additionalPackages) throws IOException {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class);
    archive.addPackage(extension.getPackage());
    if (additionalPackages != null) {
        for (Package pkg : additionalPackages) {
            archive.addPackage(pkg);
        }
    }
    archive.addAsServiceProvider(Extension.class, extension);
    return archive.as(ZipExporter.class);
}
 
Example #15
Source File: CliExtCommandsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void createTestModule() throws Exception {
    final File moduleXml = new File(CliExtCommandsTestCase.class.getResource(CliExtCommandsTestCase.class.getSimpleName() + "-module.xml").toURI());
    testModule = new TestModule(MODULE_NAME, moduleXml);
    final JavaArchive archive = testModule.addResource("test-cli-ext-commands-module.jar")
            .addClass(CliExtCommandHandler.class)
            .addClass(CliExtCommand.class)
            .addClass(CliExtCommandHandlerProvider.class)
            .addClass(CliExtCommandsExtension.class)
            .addClass(CliExtCommandsParser.class)
            .addClass(CliExtCommandsSubsystemResourceDescription.class);

    ArchivePath services = ArchivePaths.create("/");
    services = ArchivePaths.create(services, "services");

    ArchivePath help = ArchivePaths.create("/");
    help = ArchivePaths.create(help, "help");

    final ArchivePath extService = ArchivePaths.create(services, Extension.class.getName());
    archive.addAsManifestResource(CliExtCommandHandler.class.getPackage(), Extension.class.getName(), extService);

    final ArchivePath cliCmdService = ArchivePaths.create(services, CommandHandlerProvider.class.getName());
    archive.addAsManifestResource(CliExtCommandHandler.class.getPackage(), CommandHandlerProvider.class.getName(), cliCmdService);

    final ArchivePath cliAeshCmdService = ArchivePaths.create(services, Command.class.getName());
    archive.addAsManifestResource(CliExtCommand.class.getPackage(), Command.class.getName(), cliAeshCmdService);

    final ArchivePath helpService = ArchivePaths.create(help, CliExtCommandHandler.NAME + ".txt");
    archive.addAsResource(CliExtCommandHandler.class.getPackage(), CliExtCommandHandler.NAME + ".txt", helpService);

    final ArchivePath help2Service = ArchivePaths.create("/"
            + CliExtCommand.class.getPackage().getName().replaceAll("\\.", "/"), "command_resources.properties");
    archive.addAsResource(CliExtCommand.class.getPackage(), "command_resources.properties", help2Service);

    testModule.create(true);
}
 
Example #16
Source File: ExtensionSetup.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static StreamExporter createResourceRoot(Class<? extends Extension> extension, Package... additionalPackages) throws IOException {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class);
    archive.addPackage(extension.getPackage());
    if (additionalPackages != null) {
        for (Package pkg : additionalPackages) {
            archive.addPackage(pkg);
        }
    }
    archive.addAsServiceProvider(Extension.class, extension);
    return archive.as(ZipExporter.class);
}
 
Example #17
Source File: StandaloneXMLParserProducer.java    From thorntail with Apache License 2.0 4 votes vote down vote up
private void add(Extension ext) {
    ParsingContext ctx = new ParsingContext();
    ext.initializeParsers(ctx);
}
 
Example #18
Source File: ModelControllerMBeanTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public MBeanInfoAdditionalInitialization(ProcessType processType, Extension extension) {
    super(processType);
    this.extension = extension;
}
 
Example #19
Source File: SubsystemTestDelegate.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
Extension getMainExtension() {
    return mainExtension;
}
 
Example #20
Source File: AbstractSubsystemBaseTest.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public AbstractSubsystemBaseTest(final String mainSubsystemName, final Extension mainExtension, final Comparator<PathAddress> removeOrderComparator) {
    super(mainSubsystemName, mainExtension, removeOrderComparator);
}
 
Example #21
Source File: AbstractSubsystemBaseTest.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public AbstractSubsystemBaseTest(final String mainSubsystemName, final Extension mainExtension) {
    super(mainSubsystemName, mainExtension);
}
 
Example #22
Source File: ExtensionUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void createExtensionModule(File extensionModuleRoot, Class<? extends Extension> extension) throws IOException {
    createExtensionModule(extensionModuleRoot, extension, new Package[0]);
}
 
Example #23
Source File: ExtensionUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void createExtensionModule(String extensionName, Class<? extends Extension> extension, Package... additionalPackages) throws IOException {
    createExtensionModule(getExtensionModuleRoot(extensionName), extension, additionalPackages);
}
 
Example #24
Source File: AbstractSubsystemTest.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected Extension getMainExtension() {
    return delegate.getMainExtension();
}
 
Example #25
Source File: AbstractSubsystemTest.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@SuppressWarnings("deprecation")
protected AbstractSubsystemTest(final String mainSubsystemName, final Extension mainExtension, final Comparator<PathAddress> removeOrderComparator) {
    this.delegate = new SubsystemTestDelegate(this.getClass(), mainSubsystemName, mainExtension, removeOrderComparator);
}
 
Example #26
Source File: AbstractSubsystemTest.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected AbstractSubsystemTest(final String mainSubsystemName, final Extension mainExtension) {
    this(mainSubsystemName, mainExtension, null);
}
 
Example #27
Source File: TestParserUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Builder(Extension extension, String subsystemName, String subsystemXml) {
    this.extension = extension;
    this.subsystemName = subsystemName;
    this.subsystemXml = subsystemXml;
}
 
Example #28
Source File: ExtensionUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void createExtensionModule(String extensionName, Class<? extends Extension> extension) throws IOException {
    createExtensionModule(getExtensionModuleRoot(extensionName), extension);
}
 
Example #29
Source File: SubsystemTestDelegate.java    From wildfly-core with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Creates a new delegate.
 *
 * @param testClass             the test class
 * @param mainSubsystemName     the name of the subsystem
 * @param mainExtension         the extension to test
 * @param removeOrderComparator a comparator to sort addresses when removing the subsystem, {@code null} if order
 *                              doesn't matter
 */
SubsystemTestDelegate(final Class<?> testClass, final String mainSubsystemName, final Extension mainExtension, final Comparator<PathAddress> removeOrderComparator) {
    this.testClass = testClass;
    this.mainSubsystemName = mainSubsystemName;
    this.mainExtension = mainExtension;
    this.removeOrderComparator = removeOrderComparator;
}
 
Example #30
Source File: ExtensionRegistry.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Ask the given {@code extension} to
 * {@link Extension#initializeParsers(ExtensionParsingContext) initialize its parsers}. Should be used in
 * preference to calling {@link #getExtensionParsingContext(String, XMLMapper)} and passing the returned
 * value to {@code Extension#initializeParsers(context)} as this method allows the registry to take
 * additional action when the extension is done.
 *
 * @param extension  the extension. Cannot be {@code null}
 * @param moduleName the name of the extension's module. Cannot be {@code null}
 * @param xmlMapper  the {@link XMLMapper} handling the extension parsing. Can be {@code null} if there won't
 *                   be any actual parsing (e.g. in a slave Host Controller or in a server in a managed domain)
 */
public final void initializeParsers(final Extension extension, final String moduleName, final XMLMapper xmlMapper) {
    ExtensionParsingContextImpl parsingContext = new ExtensionParsingContextImpl(moduleName, xmlMapper);
    extension.initializeParsers(parsingContext);
    parsingContext.attemptCurrentParserInitialization();
}