Search in sources :

Example 41 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 (ModuleNotFoundException e) {
        context.getFailureDescription().set(ConnectorLogger.ROOT_LOGGER.missingDependencyInModuleDriver(moduleName, e.getMessage()));
        return;
    } 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) ModuleNotFoundException(org.jboss.modules.ModuleNotFoundException) ServiceTarget(org.jboss.msc.service.ServiceTarget) Driver(java.sql.Driver) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module) ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleNotFoundException(org.jboss.modules.ModuleNotFoundException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 42 with ModuleLoadException

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

the class GetDataSourceClassInfoOperationHandler method findPropsFromCls.

private static ModelNode findPropsFromCls(ServiceModuleLoader serviceModuleLoader, ModuleIdentifier mid, String clsName) throws OperationFailedException {
    Class<?> cls = null;
    if (mid != null) {
        try {
            cls = Class.forName(clsName, true, serviceModuleLoader.loadModule(mid.toString()).getClassLoader());
        } catch (ModuleLoadException | ClassNotFoundException e) {
            throw ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(clsName, e);
        }
    }
    if (cls == null) {
        try {
            cls = Class.forName(clsName);
        } catch (ClassNotFoundException e) {
            throw ConnectorLogger.SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(clsName, e);
        }
    }
    Map<String, Type> methodsMap = new TreeMap<>();
    for (Method method : possiblePropsSetters(cls)) {
        methodsMap.putIfAbsent(deCapitalize(method.getName().substring(3)), method.getParameterTypes()[0]);
    }
    final ModelNode result = new ModelNode();
    for (Map.Entry<String, Type> prop : methodsMap.entrySet()) {
        result.get(prop.getKey()).set(prop.getValue().getTypeName());
    }
    return result;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) Type(java.lang.reflect.Type) Method(java.lang.reflect.Method) TreeMap(java.util.TreeMap) ModelNode(org.jboss.dmr.ModelNode) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 43 with ModuleLoadException

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

the class MicroProfileReactiveMessagingExtension method initialize.

@Override
public void initialize(ExtensionContext extensionContext) {
    // Initialize the Netty logger factory or we get horrible stack traces
    ClassLoader cl = WildFlySecurityManager.getClassLoaderPrivileged(this.getClass());
    if (cl instanceof ModuleClassLoader) {
        ModuleLoader loader = ((ModuleClassLoader) cl).getModule().getModuleLoader();
        try {
            Module module = loader.loadModule("io.netty");
            InternalLoggerFactory.setDefaultFactory(JdkLoggerFactory.INSTANCE);
        } catch (ModuleLoadException e) {
        // The netty module is not there so don't do anything
        }
    }
    final SubsystemRegistration sr = extensionContext.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION);
    sr.registerXMLElementWriter(CURRENT_PARSER);
    final ManagementResourceRegistration root = sr.registerSubsystemModel(new MicroProfileReactiveMessagingSubsystemDefinition());
    root.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE, false);
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleLoader(org.jboss.modules.ModuleLoader) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) Module(org.jboss.modules.Module) SubsystemRegistration(org.jboss.as.controller.SubsystemRegistration)

Example 44 with ModuleLoadException

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

the class ModClusterSubsystemServiceHandler method addLoadMetrics.

private void addLoadMetrics(Set<LoadMetric> metrics, ModelNode nodes, final OperationContext context) throws OperationFailedException {
    for (Property property1 : nodes.asPropertyList()) {
        ModelNode node = property1.getValue();
        double capacity = LoadMetricResourceDefinition.SharedAttribute.CAPACITY.resolveModelAttribute(context, node).asDouble();
        int weight = LoadMetricResourceDefinition.SharedAttribute.WEIGHT.resolveModelAttribute(context, node).asInt();
        Class<? extends LoadMetric> loadMetricClass = null;
        if (node.hasDefined(LoadMetricResourceDefinition.Attribute.TYPE.getName())) {
            String type = LoadMetricResourceDefinition.Attribute.TYPE.resolveModelAttribute(context, node).asString();
            // MODCLUSTER-288 Metric "mem" has been dropped, keep it in the model for versions prior to 8.0
            if (type.equals("mem")) {
                ROOT_LOGGER.unsupportedMetric(type);
                continue;
            }
            LoadMetricEnum metric = LoadMetricEnum.forType(type);
            loadMetricClass = (metric != null) ? metric.getLoadMetricClass() : null;
        } else {
            String className = CustomLoadMetricResourceDefinition.Attribute.CLASS.resolveModelAttribute(context, node).asString();
            String moduleName = CustomLoadMetricResourceDefinition.Attribute.MODULE.resolveModelAttribute(context, node).asString();
            try {
                Module module = Module.getContextModuleLoader().loadModule(moduleName);
                loadMetricClass = module.getClassLoader().loadClass(className).asSubclass(LoadMetric.class);
            } catch (ModuleLoadException e) {
                ROOT_LOGGER.errorLoadingModuleForCustomMetric(moduleName, e);
            } catch (ClassNotFoundException e) {
                ROOT_LOGGER.errorAddingMetrics(e);
            }
        }
        if (loadMetricClass != null) {
            try {
                LoadMetric metric = loadMetricClass.newInstance();
                metric.setCapacity(capacity);
                metric.setWeight(weight);
                Properties props = new Properties();
                for (Property property : LoadMetricResourceDefinition.SharedAttribute.PROPERTY.resolveModelAttribute(context, node).asPropertyListOrEmpty()) {
                    props.put(property.getName(), property.getValue().asString());
                }
                // Apply Java Bean properties if any are set
                if (!props.isEmpty()) {
                    try {
                        BeanUtils.mapJavaBeanProperties(metric, props, true);
                    } catch (Exception ex) {
                        ROOT_LOGGER.errorApplyingMetricProperties(ex, loadMetricClass.getCanonicalName());
                        // Do not add this incomplete metric.
                        continue;
                    }
                }
                metrics.add(metric);
            } catch (InstantiationException | IllegalAccessException e) {
                ROOT_LOGGER.errorAddingMetrics(e);
            }
        }
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) Properties(java.util.Properties) ModuleLoadException(org.jboss.modules.ModuleLoadException) OperationFailedException(org.jboss.as.controller.OperationFailedException) LoadMetric(org.jboss.modcluster.load.metric.LoadMetric) ModelNode(org.jboss.dmr.ModelNode) Module(org.jboss.modules.Module) Property(org.jboss.dmr.Property)

Example 45 with ModuleLoadException

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

the class TranslatorCustomizer method loadTranslators.

@SuppressWarnings("rawtypes")
private void loadTranslators(String moduleName) {
    ClassLoader translatorLoader = this.getClass().getClassLoader();
    try {
        final Module module = Module.getBootModuleLoader().loadModule(moduleName);
        if (module != null) {
            translatorLoader = module.getClassLoader();
            final ServiceLoader<ExecutionFactory> serviceLoader = ServiceLoader.load(ExecutionFactory.class, translatorLoader);
            if (serviceLoader != null) {
                for (ExecutionFactory ef : serviceLoader) {
                    Translator t = ef.getClass().getAnnotation(Translator.class);
                    fraction.translator(t.name(), x -> x.module(moduleName));
                }
            }
        }
    } catch (ModuleLoadException e) {
    // no-op
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) Translator(org.teiid.translator.Translator) ExecutionFactory(org.teiid.translator.ExecutionFactory) Module(org.jboss.modules.Module)

Aggregations

ModuleLoadException (org.jboss.modules.ModuleLoadException)62 Module (org.jboss.modules.Module)30 IOException (java.io.IOException)17 ModuleIdentifier (org.jboss.modules.ModuleIdentifier)13 ModuleSpec (org.jboss.modules.ModuleSpec)12 ModuleLoader (org.jboss.modules.ModuleLoader)10 Test (org.junit.Test)9 URL (java.net.URL)8 File (java.io.File)7 InputStream (java.io.InputStream)7 ArrayList (java.util.ArrayList)7 ModuleClassLoader (org.jboss.modules.ModuleClassLoader)7 HashSet (java.util.HashSet)6 OperationFailedException (org.jboss.as.controller.OperationFailedException)6 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)6 ModelNode (org.jboss.dmr.ModelNode)6 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)5 TldMetaData (org.jboss.metadata.web.spec.TldMetaData)5 ModuleNotFoundException (org.jboss.modules.ModuleNotFoundException)5 HashMap (java.util.HashMap)4