Skip to content

Commit

Permalink
WFLY-10634 mod_cluster custom load metric classes are loaded from the…
Browse files Browse the repository at this point in the history
… subsystem classloader
  • Loading branch information
rhusar committed Aug 15, 2018
1 parent 3e1eb87 commit 96903d6
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 9 deletions.
Expand Up @@ -41,6 +41,7 @@
<module name="org.jboss.mod_cluster.container.spi"/> <module name="org.jboss.mod_cluster.container.spi"/>
<module name="org.jboss.mod_cluster.core"/> <module name="org.jboss.mod_cluster.core"/>
<module name="org.jboss.mod_cluster.load.spi"/> <module name="org.jboss.mod_cluster.load.spi"/>
<module name="org.jboss.modules"/>
<module name="org.jboss.msc"/> <module name="org.jboss.msc"/>
<module name="org.jboss.staxmapper"/> <module name="org.jboss.staxmapper"/>
<module name="org.wildfly.clustering.service"/> <module name="org.wildfly.clustering.service"/>
Expand Down
Expand Up @@ -22,15 +22,21 @@


package org.wildfly.extension.mod_cluster; package org.wildfly.extension.mod_cluster;


import java.util.function.UnaryOperator;

import org.jboss.as.clustering.controller.ChildResourceDefinition; import org.jboss.as.clustering.controller.ChildResourceDefinition;
import org.jboss.as.clustering.controller.ReloadRequiredResourceRegistration; import org.jboss.as.clustering.controller.ReloadRequiredResourceRegistration;
import org.jboss.as.clustering.controller.ResourceDescriptor; import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.validation.ModuleIdentifierValidatorBuilder;
import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.PathElement; import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.transform.description.DiscardAttributeChecker;
import org.jboss.as.controller.transform.description.RejectAttributeChecker;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType; import org.jboss.dmr.ModelType;
import org.wildfly.extension.mod_cluster.LoadMetricResourceDefinition.SharedAttribute; import org.wildfly.extension.mod_cluster.LoadMetricResourceDefinition.SharedAttribute;


Expand All @@ -45,26 +51,39 @@ static PathElement pathElement(String loadMetric) {
return PathElement.pathElement("custom-load-metric", loadMetric); return PathElement.pathElement("custom-load-metric", loadMetric);
} }


enum Attribute implements org.jboss.as.clustering.controller.Attribute { enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> {
CLASS("class", ModelType.STRING), CLASS("class", ModelType.STRING),
// TODO WFLY-10634 mod_cluster should allow to specify module to load custom metric from MODULE("module", ModelType.STRING) {
//MODULE("module"), @Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder
.setDefaultValue(new ModelNode("org.wildfly.extension.mod_cluster"))
.setRequired(false)
.setValidator(new ModuleIdentifierValidatorBuilder().configure(builder).build())
;
}
},
; ;


private final AttributeDefinition definition; private final AttributeDefinition definition;


Attribute(String name, ModelType type) { Attribute(String name, ModelType type) {
this.definition = new SimpleAttributeDefinitionBuilder(name, type) this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type)
.setAllowExpression(true) .setAllowExpression(true)
.setRequired(true) .setRequired(true)
.setRestartAllServices() .setRestartAllServices()
.build(); ).build();
} }


@Override @Override
public AttributeDefinition getDefinition() { public AttributeDefinition getDefinition() {
return this.definition; return this.definition;
} }

@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder;
}
} }


CustomLoadMetricResourceDefinition() { CustomLoadMetricResourceDefinition() {
Expand All @@ -85,7 +104,14 @@ public ManagementResourceRegistration register(ManagementResourceRegistration pa
return registration; return registration;
} }


static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder builder) { static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
// Nothing to transform ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);

if (ModClusterModel.VERSION_6_0_0.requiresTransformation(version)) {
builder.getAttributeBuilder()
.setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(Attribute.MODULE.getDefinition().getDefaultValue()), Attribute.MODULE.getDefinition())
.addRejectCheck(new RejectAttributeChecker.SimpleAcceptAttributeChecker(Attribute.MODULE.getDefinition().getDefaultValue()), Attribute.MODULE.getDefinition())
.end();
}
} }
} }
Expand Up @@ -197,4 +197,7 @@ interface ModClusterLogger extends BasicLogger {
@Message(id = 22, value = "Legacy operations cannot be used with multiple proxy configurations. Use non-deprecated operations at the correct proxy address.") @Message(id = 22, value = "Legacy operations cannot be used with multiple proxy configurations. Use non-deprecated operations at the correct proxy address.")
String legacyOperationsWithMultipleProxies(); String legacyOperationsWithMultipleProxies();


@LogMessage(level = ERROR)
@Message(id = 23, value = "Error loading module '%s' to load custom metric from.")
void errorLoadingModuleForCustomMetric(String moduleName, @Cause Throwable cause);
} }
Expand Up @@ -39,15 +39,20 @@
import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.registry.Resource; import org.jboss.as.controller.registry.Resource;
import org.jboss.as.server.Services;
import org.jboss.as.server.moduleservice.ServiceModuleLoader;
import org.jboss.common.beans.property.BeanUtils; import org.jboss.common.beans.property.BeanUtils;
import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property; import org.jboss.dmr.Property;
import org.jboss.modcluster.load.LoadBalanceFactorProvider; import org.jboss.modcluster.load.LoadBalanceFactorProvider;
import org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider; import org.jboss.modcluster.load.impl.DynamicLoadBalanceFactorProvider;
import org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProvider; import org.jboss.modcluster.load.impl.SimpleLoadBalanceFactorProvider;
import org.jboss.modcluster.load.metric.LoadMetric; import org.jboss.modcluster.load.metric.LoadMetric;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleLoadException;
import org.jboss.msc.service.ServiceController.Mode; import org.jboss.msc.service.ServiceController.Mode;
import org.jboss.msc.service.ServiceTarget; import org.jboss.msc.service.ServiceTarget;
import org.wildfly.clustering.service.ActiveServiceSupplier;


/** /**
* Resource service handler implementation that handles installation of mod_cluster services. Since mod_cluster requires certain * Resource service handler implementation that handles installation of mod_cluster services. Since mod_cluster requires certain
Expand Down Expand Up @@ -155,8 +160,15 @@ private void addLoadMetrics(Set<LoadMetric> metrics, ModelNode nodes, final Oper
loadMetricClass = (metric != null) ? metric.getLoadMetricClass() : null; loadMetricClass = (metric != null) ? metric.getLoadMetricClass() : null;
} else { } else {
String className = CustomLoadMetricResourceDefinition.Attribute.CLASS.resolveModelAttribute(context, node).asString(); String className = CustomLoadMetricResourceDefinition.Attribute.CLASS.resolveModelAttribute(context, node).asString();
String moduleName = CustomLoadMetricResourceDefinition.Attribute.MODULE.resolveModelAttribute(context, node).asString();

ServiceModuleLoader serviceModuleLoader = new ActiveServiceSupplier<ServiceModuleLoader>(context.getServiceRegistry(false), Services.JBOSS_SERVICE_MODULE_LOADER).get();

try { try {
loadMetricClass = this.getClass().getClassLoader().loadClass(className).asSubclass(LoadMetric.class); Module module = serviceModuleLoader.loadModule(moduleName);
loadMetricClass = module.getClassLoader().loadClass(className).asSubclass(LoadMetric.class);
} catch (ModuleLoadException e) {
ROOT_LOGGER.errorLoadingModuleForCustomMetric(moduleName, e);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
ROOT_LOGGER.errorAddingMetrics(e); ROOT_LOGGER.errorAddingMetrics(e);
} }
Expand Down
Expand Up @@ -86,7 +86,6 @@ public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder b
.setRequired(false) .setRequired(false)
.setDefaultValue(defaultValue) .setDefaultValue(defaultValue)
.setRestartAllServices() .setRestartAllServices()
.setAlternatives()
).build(); ).build();
} }


Expand Down
Expand Up @@ -53,6 +53,7 @@ modcluster.load-metric.add=Add a load metric to the set of load metrics to calcu
modcluster.load-metric.remove=Remove a load metric from the set of load metrics to calculate the load factor from. modcluster.load-metric.remove=Remove a load metric from the set of load metrics to calculate the load factor from.
modcluster.load-metric.type=Type of a built-in load metric from the enumerated values. modcluster.load-metric.type=Type of a built-in load metric from the enumerated values.
modcluster.load-metric.class=Class name to use to construct a load metric from. modcluster.load-metric.class=Class name to use to construct a load metric from.
modcluster.load-metric.module=Module name to load the load metric class from.
modcluster.load-metric.weight=Number indicating the significance of a metric with respect to the other metrics. For example, a metric of weight 2 will have twice the impact on the overall load factor than a metric of weight 1. modcluster.load-metric.weight=Number indicating the significance of a metric with respect to the other metrics. For example, a metric of weight 2 will have twice the impact on the overall load factor than a metric of weight 1.
modcluster.load-metric.capacity=Maximum capacity of the metric used to normalize the load values from a metric which require explicit capacity. modcluster.load-metric.capacity=Maximum capacity of the metric used to normalize the load values from a metric which require explicit capacity.
modcluster.load-metric.property=Properties to apply on a loaded metric instance. modcluster.load-metric.property=Properties to apply on a loaded metric instance.
Expand Down
Expand Up @@ -369,6 +369,13 @@
</xs:documentation> </xs:documentation>
</xs:annotation> </xs:annotation>
</xs:attribute> </xs:attribute>
<xs:attribute name="module" type="xs:string">
<xs:annotation>
<xs:documentation>
Module name from which to load the load metric class.
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:extension> </xs:extension>
</xs:complexContent> </xs:complexContent>
</xs:complexType> </xs:complexType>
Expand Down

0 comments on commit 96903d6

Please sign in to comment.