use of org.jboss.modcluster.load.metric.LoadMetric in project wildfly by wildfly.
the class ModClusterSubsystemAdd method performBoottime.
@Override
public void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
ServiceTarget target = context.getServiceTarget();
final ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
final ModelNode modelConfig = fullModel.get(ModClusterConfigResourceDefinition.PATH.getKeyValuePair());
ModClusterConfigurationServiceBuilder configurationBuilder = new ModClusterConfigurationServiceBuilder();
configurationBuilder.configure(context, modelConfig).build(target).install();
// Construct LoadBalanceFactorProvider and call pluggable boot time handlers.
Set<LoadMetric> metrics = new HashSet<>();
final LoadBalanceFactorProvider loadProvider = getModClusterLoadProvider(metrics, context, modelConfig);
for (BoottimeHandlerProvider handler : ServiceLoader.load(BoottimeHandlerProvider.class, BoottimeHandlerProvider.class.getClassLoader())) {
handler.performBoottime(metrics, context, operation, modelConfig);
}
final String connector = CONNECTOR.resolveModelAttribute(context, modelConfig).asString();
final int statusInterval = STATUS_INTERVAL.resolveModelAttribute(context, modelConfig).asInt();
InjectedValue<ModClusterConfiguration> modClusterConfiguration = new InjectedValue<>();
ContainerEventHandlerService service = new ContainerEventHandlerService(modClusterConfiguration, loadProvider);
// Install the main service
new AsynchronousServiceBuilder<>(ContainerEventHandlerService.SERVICE_NAME, service).build(target).addDependency(configurationBuilder.getServiceName(), ModClusterConfiguration.class, modClusterConfiguration).setInitialMode(Mode.ACTIVE).install();
// Install services for web container integration
for (ContainerEventHandlerAdapterBuilder adapterBuilder : ServiceLoader.load(ContainerEventHandlerAdapterBuilder.class, ContainerEventHandlerAdapterBuilder.class.getClassLoader())) {
adapterBuilder.build(target, connector, statusInterval).setInitialMode(Mode.PASSIVE).install();
}
}
use of org.jboss.modcluster.load.metric.LoadMetric in project wildfly by wildfly.
the class ModClusterSubsystemAdd method addLoadMetrics.
private void addLoadMetrics(Set<LoadMetric> metrics, ModelNode nodes, final OperationContext context) throws OperationFailedException {
for (Property p : nodes.asPropertyList()) {
ModelNode node = p.getValue();
double capacity = CAPACITY.resolveModelAttribute(context, node).asDouble();
int weight = WEIGHT.resolveModelAttribute(context, node).asInt();
Map<String, String> propertyMap = PROPERTY.unwrap(context, node);
Class<? extends LoadMetric> loadMetricClass = null;
if (node.hasDefined(CommonAttributes.TYPE)) {
String type = 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 = CustomLoadMetricDefinition.CLASS.resolveModelAttribute(context, node).asString();
try {
loadMetricClass = this.getClass().getClassLoader().loadClass(className).asSubclass(LoadMetric.class);
} catch (ClassNotFoundException e) {
ROOT_LOGGER.errorAddingMetrics(e);
}
}
if (loadMetricClass != null) {
try {
LoadMetric metric = loadMetricClass.newInstance();
metric.setCapacity(capacity);
metric.setWeight(weight);
// Apply Java Bean properties if any are set
if (propertyMap != null && !propertyMap.isEmpty()) {
Properties props = new Properties();
props.putAll(propertyMap);
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);
}
}
}
}
Aggregations