Search in sources :

Example 16 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.

the class ProtocolMetricsHandler method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    String name = Operations.getAttributeName(operation);
    try {
        Protocol protocol = this.locator.findProtocol(context);
        if (protocol != null) {
            Attribute attribute = getAttribute(protocol.getClass(), name);
            if (attribute != null) {
                FieldType type = FieldType.valueOf(attribute.getType());
                try {
                    ModelNode result = new ModelNode();
                    Object value = attribute.read(protocol);
                    if (value != null) {
                        type.setValue(result, value);
                    }
                    context.getResult().set(result);
                } catch (Exception e) {
                    context.getFailureDescription().set(JGroupsLogger.ROOT_LOGGER.privilegedAccessExceptionForAttribute(name));
                }
            } else {
                context.getFailureDescription().set(JGroupsLogger.ROOT_LOGGER.unknownMetric(name));
            }
        }
    } catch (ClassNotFoundException | ModuleLoadException e) {
        context.getFailureDescription().set(e.getLocalizedMessage());
    } finally {
        context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ManagedAttribute(org.jgroups.annotations.ManagedAttribute) AccessibleObject(java.lang.reflect.AccessibleObject) Protocol(org.jgroups.stack.Protocol) ModelNode(org.jboss.dmr.ModelNode) PrivilegedActionException(java.security.PrivilegedActionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModuleLoadException(org.jboss.modules.ModuleLoadException)

Example 17 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.

the class JdbcDriverAdd method performRuntime.

protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final ModelNode address = operation.require(OP_ADDR);
    final String driverName = PathAddress.pathAddress(address).getLastElement().getValue();
    if (operation.get(DRIVER_NAME.getName()).isDefined() && !driverName.equals(operation.get(DRIVER_NAME.getName()).asString())) {
        throw ConnectorLogger.ROOT_LOGGER.driverNameAndResourceNameNotEquals(operation.get(DRIVER_NAME.getName()).asString(), driverName);
    }
    String moduleName = DRIVER_MODULE_NAME.resolveModelAttribute(context, model).asString();
    final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? DRIVER_MAJOR_VERSION.resolveModelAttribute(context, model).asInt() : null;
    final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? DRIVER_MINOR_VERSION.resolveModelAttribute(context, model).asInt() : null;
    final String driverClassName = model.hasDefined(DRIVER_CLASS_NAME.getName()) ? DRIVER_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
    final String dataSourceClassName = model.hasDefined(DRIVER_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
    final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_XA_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
    final ServiceTarget target = context.getServiceTarget();
    final ModuleIdentifier moduleId;
    final Module module;
    String slot = model.hasDefined(MODULE_SLOT.getName()) ? MODULE_SLOT.resolveModelAttribute(context, model).asString() : null;
    try {
        moduleId = ModuleIdentifier.create(moduleName, slot);
        module = Module.getCallerModuleLoader().loadModule(moduleId);
    } catch (ModuleLoadException e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName), e);
    }
    if (driverClassName == null) {
        final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
        boolean driverLoaded = false;
        if (serviceLoader != null) {
            for (Driver driver : serviceLoader) {
                startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
                driverLoaded = true;
                // w/ explicit declaration of driver-class attribute
                break;
            }
        }
        if (!driverLoaded)
            SUBSYSTEM_DATASOURCES_LOGGER.cannotFindDriverClassName(driverName);
    } else {
        try {
            final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName).asSubclass(Driver.class);
            final Constructor<? extends Driver> constructor = driverClass.getConstructor();
            final Driver driver = constructor.newInstance();
            startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
        } catch (Exception e) {
            SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
            throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.cannotInstantiateDriverClass(driverClassName));
        }
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ServiceTarget(org.jboss.msc.service.ServiceTarget) OperationFailedException(org.jboss.as.controller.OperationFailedException) InstalledDriver(org.jboss.as.connector.services.driver.InstalledDriver) Driver(java.sql.Driver) ModuleLoadException(org.jboss.modules.ModuleLoadException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) ModelNode(org.jboss.dmr.ModelNode) Module(org.jboss.modules.Module)

Example 18 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.

the class JdbcDriverRemove method recoverServices.

protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) {
    final String driverName = model.require(DRIVER_NAME.getName()).asString();
    final String moduleName = model.require(DRIVER_MODULE_NAME.getName()).asString();
    final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? model.get(DRIVER_MAJOR_VERSION.getName()).asInt() : null;
    final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? model.get(DRIVER_MINOR_VERSION.getName()).asInt() : null;
    final String driverClassName = model.hasDefined(DRIVER_CLASS_NAME.getName()) ? model.get(DRIVER_CLASS_NAME.getName()).asString() : null;
    final String dataSourceClassName = model.hasDefined(DRIVER_DATASOURCE_CLASS_NAME.getName()) ? model.get(DRIVER_DATASOURCE_CLASS_NAME.getName()).asString() : null;
    final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? model.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).asString() : null;
    final ServiceTarget target = context.getServiceTarget();
    final ModuleIdentifier moduleId;
    final Module module;
    try {
        moduleId = ModuleIdentifier.fromString(moduleName);
        module = Module.getCallerModuleLoader().loadModule(moduleId);
    } catch (ModuleLoadException e) {
        context.getFailureDescription().set(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName));
        return;
    }
    if (driverClassName == null) {
        final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
        if (serviceLoader != null)
            for (Driver driver : serviceLoader) {
                startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
            }
    } else {
        try {
            final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName).asSubclass(Driver.class);
            final Constructor<? extends Driver> constructor = driverClass.getConstructor();
            final Driver driver = constructor.newInstance();
            startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
        } catch (Exception e) {
            SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
        }
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ServiceTarget(org.jboss.msc.service.ServiceTarget) Driver(java.sql.Driver) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModuleLoadException(org.jboss.modules.ModuleLoadException)

Aggregations

ModuleLoadException (org.jboss.modules.ModuleLoadException)18 Module (org.jboss.modules.Module)11 ModuleIdentifier (org.jboss.modules.ModuleIdentifier)6 IOException (java.io.IOException)4 OperationFailedException (org.jboss.as.controller.OperationFailedException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)3 WarMetaData (org.jboss.as.web.common.WarMetaData)3 ModuleClassLoader (org.jboss.modules.ModuleClassLoader)3 InputStream (java.io.InputStream)2 URL (java.net.URL)2 Driver (java.sql.Driver)2 HashSet (java.util.HashSet)2 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)2 ModelNode (org.jboss.dmr.ModelNode)2 TldMetaData (org.jboss.metadata.web.spec.TldMetaData)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 VirtualFile (org.jboss.vfs.VirtualFile)2